OSDN Git Service

AnalyticsService: report the build info in power events android-x86-7.1-r1 android-x86-7.1-r2 android-x86-7.1-r3
authorChih-Wei Huang <cwhuang@linux.org.tw>
Thu, 19 Oct 2017 03:46:48 +0000 (11:46 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 27 Oct 2017 02:35:11 +0000 (10:35 +0800)
Set buind info to the label of power events so we can know
what the build is in Google Analytics.

Service/src/org/android_x86/analytics/AnalyticsService.java
Service/src/org/android_x86/analytics/Util.java

index 6886e63..563d25c 100644 (file)
@@ -205,10 +205,18 @@ public class AnalyticsService extends ImmortalIntentService {
         return nowSeconds - latestChangeTime;
     }
 
+    private void sendPowerEvent(String event, long time, long powerOnNotSleep) {
+        LogHelper.LogBuilder builder = mLogHelper.newEventBuilder(EVENT_CATEGORY_POWER,
+                event, Util.BuildUtil.getProductVersion(), time);
+        if (powerOnNotSleep != -1) {
+            builder.setPower(powerOnNotSleep);
+        }
+        builder.send();
+    }
+
     private void onBootCompleted(Intent data) {
         long bootTime = SystemClock.elapsedRealtime() / MS_IN_SECOND;
-        mLogHelper.newEventBuilder(EVENT_CATEGORY_POWER, EVENT_BOOT_COMPLETED, null, bootTime)
-                .send();
+        sendPowerEvent(EVENT_BOOT_COMPLETED, bootTime, -1);
 
         if (SystemProperties.getBoolean("persist.sys.hw_statistics", true)) {
             new HardwareCollector(this).uploadHardwareInfo();
@@ -231,25 +239,17 @@ public class AnalyticsService extends ImmortalIntentService {
             Log.w(TAG, "onShutdown, cannot get data");
             return;
         }
-        mLogHelper.newEventBuilder(
-                EVENT_CATEGORY_POWER, EVENT_SHUTDOWN, null, powerOnIncludeSleep)
-                .setPower(powerOnNotSleep)
-                .send();
+        sendPowerEvent(EVENT_SHUTDOWN, powerOnIncludeSleep, powerOnNotSleep);
     }
 
     private void onScreenOn(Intent data) {
         Long screenOffDuration = getDurationAndSaveScreenChangeTime();
-
-        mLogHelper.newEventBuilder(
-                EVENT_CATEGORY_POWER, EVENT_SCREEN_ON, null, screenOffDuration)
-                .send();
+        sendPowerEvent(EVENT_SCREEN_ON, screenOffDuration, -1);
     }
 
     private void onScreenOff(Intent data) {
         Long screenOnDuration = getDurationAndSaveScreenChangeTime();
-        mLogHelper.newEventBuilder(
-                EVENT_CATEGORY_POWER, EVENT_SCREEN_OFF, null, screenOnDuration)
-                .send();
+        sendPowerEvent(EVENT_SCREEN_OFF, screenOnDuration, -1);
     }
 
     private static final String MAIN_THREAD = "main";
index e8d6f54..13d2385 100644 (file)
@@ -147,6 +147,13 @@ public class Util {
             }
             return Build.VERSION.RELEASE + '-' + Build.VERSION.INCREMENTAL;
         }
+
+        /**
+         * Gets product version.
+         */
+        public static String getProductVersion() {
+            return Build.PRODUCT + ' ' + Build.VERSION.RELEASE + ' ' + Build.ID;
+        }
     }
 
     /* --- IOUtil --- */