OSDN Git Service

AnalyticsService: combine two services
authorChih-Wei Huang <cwhuang@linux.org.tw>
Wed, 18 Oct 2017 10:33:13 +0000 (18:33 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Thu, 19 Oct 2017 03:10:37 +0000 (11:10 +0800)
The functionality of HardwareCollectorService is very simple.
It's unnecessary to make it as a separate service.

Just merge it into the AnalyticsService to save resources.

CleanSpec.mk [new file with mode: 0644]
HardwareCollector/Android.mk [deleted file]
HardwareCollector/AndroidManifest.xml [deleted file]
HardwareCollector/res/values/strings.xml [deleted file]
HardwareCollector/src/org/android_x86/hardwarecollector/BootCompletedReceiver.java [deleted file]
NOTICE
Service/src/org/android_x86/analytics/AnalyticsService.java
Service/src/org/android_x86/analytics/HardwareCollector.java [moved from HardwareCollector/src/org/android_x86/hardwarecollector/HardwareCollectorService.java with 91% similarity]

diff --git a/CleanSpec.mk b/CleanSpec.mk
new file mode 100644 (file)
index 0000000..be7ccfd
--- /dev/null
@@ -0,0 +1,3 @@
+# Clean up HardwareCollector which is being removed.
+$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/HardwareCollector_intermediates)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/priv-app/HardwareCollector)
diff --git a/HardwareCollector/Android.mk b/HardwareCollector/Android.mk
deleted file mode 100644 (file)
index 1eedd46..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := optional
-LOCAL_STATIC_JAVA_LIBRARIES := analytics-utils
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_PACKAGE_NAME := HardwareCollector
-LOCAL_CERTIFICATE := platform
-LOCAL_PRIVILEGED_MODULE := true
-
-include $(BUILD_PACKAGE)
diff --git a/HardwareCollector/AndroidManifest.xml b/HardwareCollector/AndroidManifest.xml
deleted file mode 100644 (file)
index cf01a73..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 Jide Technology Ltd.
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-          package="org.android_x86.hardwarecollector">
-
-    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
-    <uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" />
-    <uses-permission android:name="android.permission.RESTART_PACKAGES"/>
-    <application android:label="@string/app_name">
-        <service android:name=".HardwareCollectorService"
-                 android:exported="true"/>
-        <receiver android:name=".BootCompletedReceiver">
-            <intent-filter>
-                <action android:name="android.intent.action.BOOT_COMPLETED" />
-            </intent-filter>
-        </receiver>
-    </application>
-</manifest>
diff --git a/HardwareCollector/res/values/strings.xml b/HardwareCollector/res/values/strings.xml
deleted file mode 100644 (file)
index 3041a40..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 Jide Technology Ltd.
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<resources>
-    <string name="app_name">HardwareCollector</string>
-</resources>
diff --git a/HardwareCollector/src/org/android_x86/hardwarecollector/BootCompletedReceiver.java b/HardwareCollector/src/org/android_x86/hardwarecollector/BootCompletedReceiver.java
deleted file mode 100644 (file)
index 3991e98..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2016 Jide Technology Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.android_x86.hardwarecollector;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.os.SystemProperties;
-
-public class BootCompletedReceiver extends BroadcastReceiver {
-    @Override
-    public void onReceive(Context context, Intent data) {
-        if (SystemProperties.getBoolean("persist.sys.hw_statistics", true)) {
-            String action = data.getAction();
-            Intent startIntent = new Intent(context, HardwareCollectorService.class);
-            startIntent.setAction(action);
-            context.startService(startIntent);
-        }
-    }
-}
diff --git a/NOTICE b/NOTICE
index 691f73c..3404c65 100644 (file)
--- a/NOTICE
+++ b/NOTICE
@@ -1,4 +1,5 @@
    Copyright (C) 2016 Jide Technology Ltd.
+   Copyright (C) 2017 Android-x86 Open Source Project
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
index 680b4f3..8b25b1a 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright 2016 Jide Technology Ltd.
+ * Copyright 2017 Android-x86 Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -30,6 +31,7 @@ import android.os.SystemProperties;
 import android.util.Log;
 import org.android_x86.analytics.AnalyticsHelper;
 import org.android_x86.analytics.GeneralLogs;
+import org.android_x86.analytics.HardwareCollector;
 import org.android_x86.analytics.ImmortalIntentService;
 
 import java.util.HashMap;
@@ -207,6 +209,10 @@ public class AnalyticsService extends ImmortalIntentService {
         long bootTime = SystemClock.elapsedRealtime() / MS_IN_SECOND;
         mLogHelper.newEventBuilder(EVENT_CATEGORY_POWER, EVENT_BOOT_COMPLETED, null, bootTime)
                 .send();
+
+        if (SystemProperties.getBoolean("persist.sys.hw_statistics", true)) {
+            new HardwareCollector(this).uploadHardwareInfo();
+        }
     }
 
     private void onShutdown(Intent data) {
@@ -1,5 +1,6 @@
 /*
  * Copyright 2016 Jide Technology Ltd.
+ * Copyright 2017 Android-x86 Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.android_x86.hardwarecollector;
+package org.android_x86.analytics;
 
-import org.android_x86.analytics.AnalyticsHelper;
-import org.android_x86.analytics.GeneralLogs;
-
-import android.app.IntentService;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
@@ -31,8 +28,6 @@ import android.system.Os;
 import android.util.Log;
 import android.view.InputDevice;
 
-import org.json.JSONObject;
-
 import javax.microedition.khronos.egl.EGL10;
 import javax.microedition.khronos.egl.EGLConfig;
 import javax.microedition.khronos.egl.EGLContext;
@@ -45,8 +40,12 @@ import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
 
-public class HardwareCollectorService extends IntentService {
-    private static final String TAG = "HardwareCollectorService";
+import org.android_x86.analytics.AnalyticsHelper;
+import org.android_x86.analytics.GeneralLogs;
+import org.json.JSONObject;
+
+public class HardwareCollector {
+    private static final String TAG = "HardwareCollector";
 
     private static final String GA_CATEGORY = "hardware_info";
     private static final String GA_ACTION_GPU_RENDERER = "gpu_renderer";
@@ -69,27 +68,12 @@ public class HardwareCollectorService extends IntentService {
     private File mInfoFile;
     private JSONObject mInfoJson;
 
-    public HardwareCollectorService() {
-        super("HardwareCollectorService");
-    }
-
-    @Override
-    public void onCreate() {
-        super.onCreate();
-        mContext = getBaseContext();
-        mInfoFile = new File(getApplicationContext().getFilesDir(), LAST_INFO_FILE_NAME);
-    }
-
-    @Override
-    protected void onHandleIntent(Intent intent) {
-        String action = intent.getAction();
-        Log.i(TAG, "handle intent:" + intent);
-        if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
-            uploadHardwareInfo();
-        }
+    public HardwareCollector(Context context) {
+        mContext = context;
+        mInfoFile = new File(context.getFilesDir(), LAST_INFO_FILE_NAME);
     }
 
-    private void uploadHardwareInfo() {
+    public void uploadHardwareInfo() {
         getLastInfo();
         collectOpenGLInfo();
         collectCPUInfo();
@@ -169,7 +153,7 @@ public class HardwareCollectorService extends IntentService {
         IntentFilter filter = new IntentFilter();
         filter.addAction(Intent.ACTION_BATTERY_CHANGED);
         Intent batteryIntent = mContext.registerReceiver(null, filter);
-        String label = batteryIntent.getBooleanExtra("present", false) ?
+        String label = (batteryIntent != null && batteryIntent.getBooleanExtra("present", false)) ?
                 GA_LABEL_HAS_BATTERY : GA_LABEL_NO_BATTERY;
         AnalyticsHelper.CustomEvent customEvent = AnalyticsHelper.newSystemCoreEvent(
                                     mContext, GA_CATEGORY, GA_ACTION_HAS_BATTERY);