packages/services/Analytics
Revision | 844ae049e1baea4aab77f39f6ce435bd883f1b71 (tree) |
---|---|
Time | 2017-10-27 11:35:11 |
Author | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
AnalyticsService: report the build info in power events
Set buind info to the label of power events so we can know
what the build is in Google Analytics.
@@ -205,10 +205,18 @@ public class AnalyticsService extends ImmortalIntentService { | ||
205 | 205 | return nowSeconds - latestChangeTime; |
206 | 206 | } |
207 | 207 | |
208 | + private void sendPowerEvent(String event, long time, long powerOnNotSleep) { | |
209 | + LogHelper.LogBuilder builder = mLogHelper.newEventBuilder(EVENT_CATEGORY_POWER, | |
210 | + event, Util.BuildUtil.getProductVersion(), time); | |
211 | + if (powerOnNotSleep != -1) { | |
212 | + builder.setPower(powerOnNotSleep); | |
213 | + } | |
214 | + builder.send(); | |
215 | + } | |
216 | + | |
208 | 217 | private void onBootCompleted(Intent data) { |
209 | 218 | long bootTime = SystemClock.elapsedRealtime() / MS_IN_SECOND; |
210 | - mLogHelper.newEventBuilder(EVENT_CATEGORY_POWER, EVENT_BOOT_COMPLETED, null, bootTime) | |
211 | - .send(); | |
219 | + sendPowerEvent(EVENT_BOOT_COMPLETED, bootTime, -1); | |
212 | 220 | |
213 | 221 | if (SystemProperties.getBoolean("persist.sys.hw_statistics", true)) { |
214 | 222 | new HardwareCollector(this).uploadHardwareInfo(); |
@@ -231,25 +239,17 @@ public class AnalyticsService extends ImmortalIntentService { | ||
231 | 239 | Log.w(TAG, "onShutdown, cannot get data"); |
232 | 240 | return; |
233 | 241 | } |
234 | - mLogHelper.newEventBuilder( | |
235 | - EVENT_CATEGORY_POWER, EVENT_SHUTDOWN, null, powerOnIncludeSleep) | |
236 | - .setPower(powerOnNotSleep) | |
237 | - .send(); | |
242 | + sendPowerEvent(EVENT_SHUTDOWN, powerOnIncludeSleep, powerOnNotSleep); | |
238 | 243 | } |
239 | 244 | |
240 | 245 | private void onScreenOn(Intent data) { |
241 | 246 | Long screenOffDuration = getDurationAndSaveScreenChangeTime(); |
242 | - | |
243 | - mLogHelper.newEventBuilder( | |
244 | - EVENT_CATEGORY_POWER, EVENT_SCREEN_ON, null, screenOffDuration) | |
245 | - .send(); | |
247 | + sendPowerEvent(EVENT_SCREEN_ON, screenOffDuration, -1); | |
246 | 248 | } |
247 | 249 | |
248 | 250 | private void onScreenOff(Intent data) { |
249 | 251 | Long screenOnDuration = getDurationAndSaveScreenChangeTime(); |
250 | - mLogHelper.newEventBuilder( | |
251 | - EVENT_CATEGORY_POWER, EVENT_SCREEN_OFF, null, screenOnDuration) | |
252 | - .send(); | |
252 | + sendPowerEvent(EVENT_SCREEN_OFF, screenOnDuration, -1); | |
253 | 253 | } |
254 | 254 | |
255 | 255 | private static final String MAIN_THREAD = "main"; |
@@ -147,6 +147,13 @@ public class Util { | ||
147 | 147 | } |
148 | 148 | return Build.VERSION.RELEASE + '-' + Build.VERSION.INCREMENTAL; |
149 | 149 | } |
150 | + | |
151 | + /** | |
152 | + * Gets product version. | |
153 | + */ | |
154 | + public static String getProductVersion() { | |
155 | + return Build.PRODUCT + ' ' + Build.VERSION.RELEASE + ' ' + Build.ID; | |
156 | + } | |
150 | 157 | } |
151 | 158 | |
152 | 159 | /* --- IOUtil --- */ |