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.
--- /dev/null
+# 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)
+++ /dev/null
-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)
+++ /dev/null
-<?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>
+++ /dev/null
-<?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>
+++ /dev/null
-/*
- * 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);
- }
- }
-}
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.
/*
* 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.
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;
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) {
/*
* 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;
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;
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";
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();
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);