DivestOS/Patches/LineageOS-14.1/android_packages_apps_CMParts/0001-Remove_Analytics.patch

915 lines
36 KiB
Diff
Raw Normal View History

2017-01-17 23:17:50 +00:00
From 526dadc1170fb3deea60fd3d2e93ab62e54a00ab Mon Sep 17 00:00:00 2001
2016-12-27 18:37:38 +00:00
From: Tad <tad@spotco.us>
2017-01-17 23:17:50 +00:00
Date: Tue, 17 Jan 2017 18:04:09 -0500
2016-12-27 18:37:38 +00:00
Subject: [PATCH] Remove stats
2017-01-17 23:17:50 +00:00
Change-Id: If22fca4b2b641f8b68247ece20441b5cc7724709
2016-12-27 18:37:38 +00:00
---
2017-01-17 23:17:50 +00:00
AndroidManifest.xml | 25 ---
2016-12-27 18:37:38 +00:00
proguard.flags | 1 -
2017-01-17 23:17:50 +00:00
res/values/config.xml | 3 -
res/values/strings.xml | 22 ---
res/xml/anonymous_stats.xml | 32 ----
2016-12-27 18:37:38 +00:00
res/xml/parts_catalog.xml | 5 -
2017-01-17 23:17:50 +00:00
res/xml/preview_data.xml | 52 ------
2016-12-27 18:37:38 +00:00
res/xml/privacy_settings.xml | 8 -
2017-01-17 23:17:50 +00:00
.../cmparts/cmstats/AnonymousStats.java | 73 --------
.../cyanogenmod/cmparts/cmstats/PreviewData.java | 49 -----
.../cmparts/cmstats/ReportingService.java | 82 ---------
.../cmparts/cmstats/ReportingServiceManager.java | 109 -----------
.../cmparts/cmstats/StatsUploadJobService.java | 205 ---------------------
src/org/cyanogenmod/cmparts/cmstats/Utilities.java | 102 ----------
14 files changed, 768 deletions(-)
2016-12-27 18:37:38 +00:00
delete mode 100644 res/xml/anonymous_stats.xml
delete mode 100644 res/xml/preview_data.xml
delete mode 100644 src/org/cyanogenmod/cmparts/cmstats/AnonymousStats.java
delete mode 100644 src/org/cyanogenmod/cmparts/cmstats/PreviewData.java
delete mode 100644 src/org/cyanogenmod/cmparts/cmstats/ReportingService.java
delete mode 100644 src/org/cyanogenmod/cmparts/cmstats/ReportingServiceManager.java
delete mode 100644 src/org/cyanogenmod/cmparts/cmstats/StatsUploadJobService.java
delete mode 100644 src/org/cyanogenmod/cmparts/cmstats/Utilities.java
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
2017-01-17 23:17:50 +00:00
index d4f37a2..a574d98 100644
2016-12-27 18:37:38 +00:00
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
2017-01-17 23:17:50 +00:00
@@ -180,31 +180,6 @@
2016-12-27 18:37:38 +00:00
android:value="status_bar_settings" />
</activity-alias>
- <!-- Anonymous Statistics -->
- <receiver android:name=".cmstats.ReportingServiceManager"
- android:enabled="true"
- android:exported="false"
- android:label="ReportingServiceManager">
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED" />
- <action android:name="org.cyanogenmod.cmparts.action.TRIGGER_REPORT_METRICS" />
- </intent-filter>
- </receiver>
-
- <service android:label="ReportingService"
- android:enabled="true"
- android:exported="false"
- android:name=".cmstats.ReportingService">
- </service>
-
- <service android:name=".cmstats.StatsUploadJobService"
- android:permission="android.permission.BIND_JOB_SERVICE" />
-
- <service android:name=".cmstats.ReportingService"
- android:label="ReportingService"
- android:enabled="true"
- android:exported="false" />
-
<!-- Weather settings -->
<activity-alias
android:name=".weather.WeatherServiceSettings"
diff --git a/proguard.flags b/proguard.flags
index 581d61f..61c9254 100644
--- a/proguard.flags
+++ b/proguard.flags
@@ -3,7 +3,6 @@
-keep class org.cyanogenmod.cmparts.*Picker
-keep class org.cyanogenmod.cmparts.*Settings
--keep class org.cyanogenmod.cmparts.cmstats.*
-keep class org.cyanogenmod.cmparts.contributors.*
-keep class org.cyanogenmod.cmparts.hardware.*
-keep class org.cyanogenmod.cmparts.input.*
diff --git a/res/values/config.xml b/res/values/config.xml
2017-01-17 23:17:50 +00:00
index be0cc53..57ab696 100644
2016-12-27 18:37:38 +00:00
--- a/res/values/config.xml
+++ b/res/values/config.xml
2017-01-17 23:17:50 +00:00
@@ -17,9 +17,6 @@
2016-12-27 18:37:38 +00:00
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
2017-01-17 23:17:50 +00:00
- <!-- Metrics server endpoint -->
- <string name="stats_cm_url">https://stats.lineageos.org/api/v1/stats</string>
2016-12-27 18:37:38 +00:00
-
<!-- When true, weather options will be displayed in settings dashboard -->
<bool name="config_showWeatherMenu">true</bool>
diff --git a/res/values/strings.xml b/res/values/strings.xml
2017-01-17 23:17:50 +00:00
index 3037cdd..79988d6 100644
2016-12-27 18:37:38 +00:00
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -483,28 +483,6 @@
<b>Total commits:</b> <xliff:g id="total_commits">%2$s</xliff:g><br/><br/>
<b>Last update:</b> <xliff:g id="date">%3$s</xliff:g>]]></string>
- <!-- Anonymous Statistics #CM -->
- <!-- About device screen, list item title. Takes the user to the screen about opting in or out of anonymous statistics. -->
2017-01-17 23:17:50 +00:00
- <string name="anonymous_statistics_title">LineageOS statistics</string>
- <string name="anonymous_statistics_summary">Help make LineageOS better by opting into anonymous statistics reporting</string>
2016-12-27 18:37:38 +00:00
- <string name="anonymous_statistics_warning_title">About</string>
2017-01-17 23:17:50 +00:00
- <string name="anonymous_statistics_warning">Opting into LineageOS Statistics will allow non-personal data to be submitted to the
- developers of LineageOS to track unique installations across devices. The information submitted includes an unique identifier,
2016-12-27 18:37:38 +00:00
- which does not compromise your privacy or personal data. The data is submitted during each boot.\n\nFor an example of the data that is submitted, tap on Preview Data.</string>
- <string name="enable_reporting_title">Enable reporting</string>
- <string name="preview_data_title">Preview data</string>
- <string name="view_stats_title">View stats</string>
- <string name="anonymous_learn_more">Learn more</string>
-
- <!-- Anonymous Statistics - Preview -->
- <string name="preview_id_title">Unique ID</string>
- <string name="preview_device_title">Device</string>
- <string name="preview_version_title">Version</string>
- <string name="preview_country_title">Country</string>
- <string name="preview_carrier_title">Carrier</string>
- <string name="stats_collection_title">Stats collection</string>
- <string name="stats_collection_summary">When enabled, allows metrics collection</string>
-
<!-- Display : Rotation -->
<string name="accelerometer_title">Auto-rotate screen</string>
<string name="display_rotation_title">Rotation settings</string>
diff --git a/res/xml/anonymous_stats.xml b/res/xml/anonymous_stats.xml
deleted file mode 100644
index b29885c..0000000
--- a/res/xml/anonymous_stats.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2012 The CyanogenMod Project
-
- 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.
--->
-
-<PreferenceScreen
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:key="cmstats"
- android:title="@string/anonymous_statistics_title">
-
- <cyanogenmod.preference.CMSecureSettingSwitchPreference
- android:key="stats_collection"
- android:title="@string/stats_collection_title"
- android:summary="@string/stats_collection_summary"
- android:defaultValue="true" />
-
- <PreferenceScreen
- android:title="@string/preview_data_title"
- android:fragment="org.cyanogenmod.cmparts.cmstats.PreviewData" />
-
-</PreferenceScreen>
diff --git a/res/xml/parts_catalog.xml b/res/xml/parts_catalog.xml
index 07329d9..649e808 100644
--- a/res/xml/parts_catalog.xml
+++ b/res/xml/parts_catalog.xml
@@ -73,11 +73,6 @@
android:fragment="org.cyanogenmod.cmparts.statusbar.StatusBarSettings"
cm:xmlRes="@xml/status_bar_settings" />
- <part android:key="cmstats"
- android:title="@string/anonymous_statistics_title"
- android:fragment="org.cyanogenmod.cmparts.cmstats.AnonymousStats"
- cm:xmlRes="@xml/anonymous_stats" />
-
<part android:key="power_menu"
android:title="@string/power_menu_title"
android:fragment="org.cyanogenmod.cmparts.input.PowerMenuActions"
diff --git a/res/xml/preview_data.xml b/res/xml/preview_data.xml
deleted file mode 100644
index 025524c..0000000
--- a/res/xml/preview_data.xml
+++ /dev/null
@@ -1,52 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2012 The CyanogenMod Project
-
- 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.
--->
-
-<PreferenceScreen
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:title="@string/preview_data_title">
-
- <Preference
- android:key="preview_id"
- style="?android:preferenceInformationStyle"
- android:title="@string/preview_id_title"
- android:summary="%s" />
-
- <Preference
- android:key="preview_device"
- style="?android:preferenceInformationStyle"
- android:title="@string/preview_device_title"
- android:summary="%s" />
-
- <Preference
- android:key="preview_version"
- style="?android:preferenceInformationStyle"
- android:title="@string/preview_version_title"
- android:summary="%s" />
-
- <Preference
- android:key="preview_country"
- style="?android:preferenceInformationStyle"
- android:title="@string/preview_country_title"
- android:summary="%s" />
-
- <Preference
- android:key="preview_carrier"
- style="?android:preferenceInformationStyle"
- android:title="@string/preview_carrier_title"
- android:summary="%s" />
-
-</PreferenceScreen>
-
diff --git a/res/xml/privacy_settings.xml b/res/xml/privacy_settings.xml
index 5ae923a..45df2a1 100644
--- a/res/xml/privacy_settings.xml
+++ b/res/xml/privacy_settings.xml
@@ -36,12 +36,4 @@
android:targetClass="com.android.settings.applications.ProtectedAppsActivity" />
</Preference>
- <!-- Anonymous statistics - (CMStats) -->
- <PreferenceScreen
- android:key="cmstats"
- android:title="@string/anonymous_statistics_title"
- android:summary="@string/anonymous_statistics_summary"
- android:fragment="org.cyanogenmod.cmparts.cmstats.AnonymousStats" >
- </PreferenceScreen>
-
</PreferenceScreen>
diff --git a/src/org/cyanogenmod/cmparts/cmstats/AnonymousStats.java b/src/org/cyanogenmod/cmparts/cmstats/AnonymousStats.java
deleted file mode 100644
2017-01-17 23:17:50 +00:00
index 3a6669d..0000000
2016-12-27 18:37:38 +00:00
--- a/src/org/cyanogenmod/cmparts/cmstats/AnonymousStats.java
+++ /dev/null
2017-01-17 23:17:50 +00:00
@@ -1,73 +0,0 @@
2016-12-27 18:37:38 +00:00
-/*
- * Copyright (C) 2015 The CyanogenMod Project
- *
- * 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.cyanogenmod.cmparts.cmstats;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.os.Bundle;
-
-import org.cyanogenmod.cmparts.R;
-import org.cyanogenmod.cmparts.SettingsPreferenceFragment;
-
-public class AnonymousStats extends SettingsPreferenceFragment {
-
- private static final String PREF_FILE_NAME = "CMStats";
- /* package */ static final String ANONYMOUS_OPT_IN = "pref_anonymous_opt_in";
- /* package */ static final String ANONYMOUS_LAST_CHECKED = "pref_anonymous_checked_in";
-
- /* package */ static final String KEY_LAST_JOB_ID = "last_job_id";
- /* package */ static final int QUEUE_MAX_THRESHOLD = 1000;
-
- public static SharedPreferences getPreferences(Context context) {
- return context.getSharedPreferences(PREF_FILE_NAME, 0);
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.anonymous_stats);
- }
-
- public static void updateLastSynced(Context context) {
- getPreferences(context)
- .edit()
- .putLong(ANONYMOUS_LAST_CHECKED,System.currentTimeMillis())
- .commit();
- }
-
- private static int getLastJobId(Context context) {
- return getPreferences(context).getInt(KEY_LAST_JOB_ID, 0);
- }
-
- private static void setLastJobId(Context context, int id) {
- getPreferences(context)
- .edit()
- .putInt(KEY_LAST_JOB_ID, id)
- .commit();
- }
-
- public static int getNextJobId(Context context) {
- int lastId = getLastJobId(context);
- if (lastId >= QUEUE_MAX_THRESHOLD) {
- lastId = 1;
- } else {
- lastId += 1;
- }
- setLastJobId(context, lastId);
- return lastId;
- }
-}
diff --git a/src/org/cyanogenmod/cmparts/cmstats/PreviewData.java b/src/org/cyanogenmod/cmparts/cmstats/PreviewData.java
deleted file mode 100644
index a14f76b..0000000
--- a/src/org/cyanogenmod/cmparts/cmstats/PreviewData.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2012 The CyanogenMod Project
- *
- * 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.cyanogenmod.cmparts.cmstats;
-
-import android.content.Context;
-import android.os.Bundle;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceScreen;
-
-import org.cyanogenmod.cmparts.R;
-import org.cyanogenmod.cmparts.SettingsPreferenceFragment;
-
-public class PreviewData extends SettingsPreferenceFragment {
- private static final String UNIQUE_ID = "preview_id";
- private static final String DEVICE = "preview_device";
- private static final String VERSION = "preview_version";
- private static final String COUNTRY = "preview_country";
- private static final String CARRIER = "preview_carrier";
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- addPreferencesFromResource(R.xml.preview_data);
-
- final PreferenceScreen prefSet = getPreferenceScreen();
- final Context context = getActivity();
-
- prefSet.findPreference(UNIQUE_ID).setSummary(Utilities.getUniqueID(context));
- prefSet.findPreference(DEVICE).setSummary(Utilities.getDevice());
- prefSet.findPreference(VERSION).setSummary(Utilities.getModVersion());
- prefSet.findPreference(COUNTRY).setSummary(Utilities.getCountryCode(context));
- prefSet.findPreference(CARRIER).setSummary(Utilities.getCarrier(context));
- }
-}
diff --git a/src/org/cyanogenmod/cmparts/cmstats/ReportingService.java b/src/org/cyanogenmod/cmparts/cmstats/ReportingService.java
deleted file mode 100644
2017-01-17 23:17:50 +00:00
index d1cd8e6..0000000
2016-12-27 18:37:38 +00:00
--- a/src/org/cyanogenmod/cmparts/cmstats/ReportingService.java
+++ /dev/null
2017-01-17 23:17:50 +00:00
@@ -1,82 +0,0 @@
2016-12-27 18:37:38 +00:00
-/*
- * Copyright (C) 2015 The CyanogenMod Project
2017-01-17 23:17:50 +00:00
- * (C) 2017 The LineageOS Project
2016-12-27 18:37:38 +00:00
- *
- * 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.cyanogenmod.cmparts.cmstats;
-
-import android.app.IntentService;
-import android.app.job.JobInfo;
-import android.app.job.JobScheduler;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.os.PersistableBundle;
-import android.os.UserHandle;
-import android.util.Log;
-import cyanogenmod.providers.CMSettings;
-
-import java.util.List;
-
-public class ReportingService extends IntentService {
- /* package */ static final String TAG = "CMStats";
- private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
-
- public ReportingService() {
- super(ReportingService.class.getSimpleName());
- }
-
- @Override
- protected void onHandleIntent(Intent intent) {
- JobScheduler js = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
-
- String deviceId = Utilities.getUniqueID(getApplicationContext());
- String deviceName = Utilities.getDevice();
- String deviceVersion = Utilities.getModVersion();
- String deviceCountry = Utilities.getCountryCode(getApplicationContext());
- String deviceCarrier = Utilities.getCarrier(getApplicationContext());
- String deviceCarrierId = Utilities.getCarrierId(getApplicationContext());
-
- final int cmOrgJobId = AnonymousStats.getNextJobId(getApplicationContext());
-
2017-01-17 23:17:50 +00:00
- if (DEBUG) Log.d(TAG, "scheduling job id: " + cmOrgJobId);
2016-12-27 18:37:38 +00:00
-
2017-01-17 23:17:50 +00:00
- PersistableBundle cmBundle = new PersistableBundle();
- cmBundle.putString(StatsUploadJobService.KEY_DEVICE_NAME, deviceName);
- cmBundle.putString(StatsUploadJobService.KEY_UNIQUE_ID, deviceId);
- cmBundle.putString(StatsUploadJobService.KEY_VERSION, deviceVersion);
- cmBundle.putString(StatsUploadJobService.KEY_COUNTRY, deviceCountry);
- cmBundle.putString(StatsUploadJobService.KEY_CARRIER, deviceCarrier);
- cmBundle.putString(StatsUploadJobService.KEY_CARRIER_ID, deviceCarrierId);
- cmBundle.putLong(StatsUploadJobService.KEY_TIMESTAMP, System.currentTimeMillis());
2016-12-27 18:37:38 +00:00
-
- // set job types
- cmBundle.putInt(StatsUploadJobService.KEY_JOB_TYPE,
- StatsUploadJobService.JOB_TYPE_CMORG);
-
- // schedule cmorg stats upload
- js.schedule(new JobInfo.Builder(cmOrgJobId, new ComponentName(getPackageName(),
- StatsUploadJobService.class.getName()))
- .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
- .setMinimumLatency(1000)
- .setExtras(cmBundle)
- .setPersisted(true)
- .build());
-
- // reschedule
- AnonymousStats.updateLastSynced(this);
- ReportingServiceManager.setAlarm(this);
- }
-}
diff --git a/src/org/cyanogenmod/cmparts/cmstats/ReportingServiceManager.java b/src/org/cyanogenmod/cmparts/cmstats/ReportingServiceManager.java
deleted file mode 100644
2017-01-17 23:17:50 +00:00
index ef53a0a..0000000
2016-12-27 18:37:38 +00:00
--- a/src/org/cyanogenmod/cmparts/cmstats/ReportingServiceManager.java
+++ /dev/null
2017-01-17 23:17:50 +00:00
@@ -1,109 +0,0 @@
2016-12-27 18:37:38 +00:00
-/*
- * Copyright (C) 2012 The CyanogenMod Project
2017-01-17 23:17:50 +00:00
- * (C) 2017 The LineageOS Project
2016-12-27 18:37:38 +00:00
- *
- * 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.cyanogenmod.cmparts.cmstats;
-
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.app.job.JobScheduler;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.os.UserHandle;
-import android.util.Log;
-import cyanogenmod.providers.CMSettings;
-
-public class ReportingServiceManager extends BroadcastReceiver {
- private static final long MILLIS_PER_HOUR = 60L * 60L * 1000L;
- private static final long MILLIS_PER_DAY = 24L * MILLIS_PER_HOUR;
- private static final long UPDATE_INTERVAL = 1L * MILLIS_PER_DAY;
-
- private static final String TAG = ReportingServiceManager.class.getSimpleName();
-
- public static final String ACTION_LAUNCH_SERVICE =
- "org.cyanogenmod.cmparts.action.TRIGGER_REPORT_METRICS";
- public static final String EXTRA_FORCE = "force";
-
- @Override
- public void onReceive(Context context, Intent intent) {
- if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
- setAlarm(context);
- } else if (intent.getAction().equals(ACTION_LAUNCH_SERVICE)){
- launchService(context, intent.getBooleanExtra(EXTRA_FORCE, false));
- }
- }
-
- public static void setAlarm(Context context) {
- SharedPreferences prefs = AnonymousStats.getPreferences(context);
- if (prefs.contains(AnonymousStats.ANONYMOUS_OPT_IN)) {
- migrate(context, prefs);
- }
- if (!Utilities.isStatsCollectionEnabled(context)) {
- return;
- }
- long lastSynced = prefs.getLong(AnonymousStats.ANONYMOUS_LAST_CHECKED, 0);
- if (lastSynced == 0) {
- launchService(context, true); // service will reschedule the next alarm
- return;
- }
- long millisFromNow = (lastSynced + UPDATE_INTERVAL) - System.currentTimeMillis();
-
- Intent intent = new Intent(ACTION_LAUNCH_SERVICE);
- intent.setClass(context, ReportingServiceManager.class);
-
- AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
- alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + millisFromNow,
- PendingIntent.getBroadcast(context, 0, intent, 0));
- Log.d(TAG, "Next sync attempt in : "
- + (millisFromNow / MILLIS_PER_HOUR) + " hours");
- }
-
- public static void launchService(Context context, boolean force) {
- SharedPreferences prefs = AnonymousStats.getPreferences(context);
-
- if (!Utilities.isStatsCollectionEnabled(context)) {
- return;
- }
-
- if (!force) {
- long lastSynced = prefs.getLong(AnonymousStats.ANONYMOUS_LAST_CHECKED, 0);
- if (lastSynced == 0) {
- setAlarm(context);
- return;
- }
- long timeElapsed = System.currentTimeMillis() - lastSynced;
- if (timeElapsed < UPDATE_INTERVAL) {
- long timeLeft = UPDATE_INTERVAL - timeElapsed;
- Log.d(TAG, "Waiting for next sync : "
- + timeLeft / MILLIS_PER_HOUR + " hours");
- return;
- }
- }
-
- Intent intent = new Intent();
- intent.setClass(context, ReportingService.class);
- context.startServiceAsUser(intent, UserHandle.OWNER);
- }
-
- private static void migrate(Context context, SharedPreferences prefs) {
- Utilities.setStatsCollectionEnabled(context,
- prefs.getBoolean(AnonymousStats.ANONYMOUS_OPT_IN, true));
- prefs.edit().remove(AnonymousStats.ANONYMOUS_OPT_IN).commit();
- }
-
-}
diff --git a/src/org/cyanogenmod/cmparts/cmstats/StatsUploadJobService.java b/src/org/cyanogenmod/cmparts/cmstats/StatsUploadJobService.java
deleted file mode 100644
2017-01-17 23:17:50 +00:00
index 16f918b..0000000
2016-12-27 18:37:38 +00:00
--- a/src/org/cyanogenmod/cmparts/cmstats/StatsUploadJobService.java
+++ /dev/null
2017-01-17 23:17:50 +00:00
@@ -1,205 +0,0 @@
2016-12-27 18:37:38 +00:00
-/*
- * Copyright (C) 2015 The CyanogenMod Project
2017-01-17 23:17:50 +00:00
- * (C) 2017 The LineageOS project
2016-12-27 18:37:38 +00:00
- *
- * 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.cyanogenmod.cmparts.cmstats;
-
-import android.app.job.JobParameters;
-import android.app.job.JobService;
-import android.net.Uri;
-import android.os.AsyncTask;
-import android.os.PersistableBundle;
-import android.util.ArrayMap;
-import android.util.Log;
-import org.cyanogenmod.cmparts.R;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.Collections;
-import java.util.Map;
-
-public class StatsUploadJobService extends JobService {
-
- private static final String TAG = StatsUploadJobService.class.getSimpleName();
- private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
-
- public static final String KEY_JOB_TYPE = "job_type";
2017-01-17 23:17:50 +00:00
- public static final int JOB_TYPE_CMORG = 1;
2016-12-27 18:37:38 +00:00
-
- public static final String KEY_UNIQUE_ID = "uniqueId";
- public static final String KEY_DEVICE_NAME = "deviceName";
- public static final String KEY_VERSION = "version";
- public static final String KEY_COUNTRY = "country";
- public static final String KEY_CARRIER = "carrier";
- public static final String KEY_CARRIER_ID = "carrierId";
- public static final String KEY_TIMESTAMP = "timeStamp";
-
- private final Map<JobParameters, StatsUploadTask> mCurrentJobs
- = Collections.synchronizedMap(new ArrayMap<JobParameters, StatsUploadTask>());
-
- @Override
- public boolean onStartJob(JobParameters jobParameters) {
- if (DEBUG)
- Log.d(TAG, "onStartJob() called with " + "jobParameters = [" + jobParameters + "]");
2017-01-17 23:17:50 +00:00
-
- if (!Utilities.isStatsCollectionEnabled(this)) {
- return false;
- }
-
2016-12-27 18:37:38 +00:00
- final StatsUploadTask uploadTask = new StatsUploadTask(jobParameters);
- mCurrentJobs.put(jobParameters, uploadTask);
- uploadTask.execute((Void) null);
- return true;
- }
-
- @Override
- public boolean onStopJob(JobParameters jobParameters) {
- if (DEBUG)
- Log.d(TAG, "onStopJob() called with " + "jobParameters = [" + jobParameters + "]");
-
- final StatsUploadTask cancelledJob;
- cancelledJob = mCurrentJobs.remove(jobParameters);
-
- if (cancelledJob != null) {
- // cancel the ongoing background task
- cancelledJob.cancel(true);
- return true; // reschedule
- }
-
- return false;
- }
-
- private class StatsUploadTask extends AsyncTask<Void, Void, Boolean> {
-
- private JobParameters mJobParams;
-
- public StatsUploadTask(JobParameters jobParams) {
- this.mJobParams = jobParams;
- }
-
- @Override
- protected Boolean doInBackground(Void... params) {
-
- PersistableBundle extras = mJobParams.getExtras();
-
- String deviceId = extras.getString(KEY_UNIQUE_ID);
- String deviceName = extras.getString(KEY_DEVICE_NAME);
- String deviceVersion = extras.getString(KEY_VERSION);
- String deviceCountry = extras.getString(KEY_COUNTRY);
- String deviceCarrier = extras.getString(KEY_CARRIER);
- String deviceCarrierId = extras.getString(KEY_CARRIER_ID);
- long timeStamp = extras.getLong(KEY_TIMESTAMP);
-
- boolean success = false;
- int jobType = extras.getInt(KEY_JOB_TYPE, -1);
- if (!isCancelled()) {
- switch (jobType) {
- case JOB_TYPE_CMORG:
- try {
2017-01-17 23:17:50 +00:00
- JSONObject json = buildStatsRequest(deviceId, deviceName,
- deviceVersion, deviceCountry, deviceCarrier, deviceCarrierId);
- success = uploadToCM(json);
- } catch (IOException | JSONException e) {
- Log.e(TAG, "Could not upload stats checkin to community server", e);
2016-12-27 18:37:38 +00:00
- success = false;
- }
- break;
- }
- }
- if (DEBUG)
- Log.d(TAG, "job id " + mJobParams.getJobId() + ", has finished with success="
- + success);
- return success;
- }
-
- @Override
- protected void onPostExecute(Boolean success) {
- mCurrentJobs.remove(mJobParams);
- jobFinished(mJobParams, !success);
- }
- }
-
2017-01-17 23:17:50 +00:00
- private JSONObject buildStatsRequest(String deviceId, String deviceName, String deviceVersion,
- String deviceCountry, String deviceCarrier,
- String deviceCarrierId) throws JSONException {
- JSONObject request = new JSONObject();
- request.put("device_hash", deviceId);
- request.put("device_name", deviceName);
- request.put("device_version", deviceVersion);
- request.put("device_country", deviceCountry);
- request.put("device_carrier", deviceCarrier);
- request.put("device_carrier_id", deviceCarrierId);
- return request;
- }
2016-12-27 18:37:38 +00:00
-
2017-01-17 23:17:50 +00:00
- private boolean uploadToCM(JSONObject json) throws IOException {
- final Uri uri = Uri.parse(getString(R.string.stats_cm_url));
2016-12-27 18:37:38 +00:00
- URL url = new URL(uri.toString());
- HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
- try {
- urlConnection.setInstanceFollowRedirects(true);
- urlConnection.setDoOutput(true);
- urlConnection.setDoInput(true);
2017-01-17 23:17:50 +00:00
- urlConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
2016-12-27 18:37:38 +00:00
-
- OutputStream os = urlConnection.getOutputStream();
2017-01-17 23:17:50 +00:00
- os.write(json.toString().getBytes("UTF-8"));
2016-12-27 18:37:38 +00:00
- os.close();
-
- final int responseCode = urlConnection.getResponseCode();
2017-01-17 23:17:50 +00:00
- if (DEBUG) Log.d(TAG, "cm server response code=" + responseCode);
2016-12-27 18:37:38 +00:00
- final boolean success = responseCode == HttpURLConnection.HTTP_OK;
- if (!success) {
2017-01-17 23:17:50 +00:00
- Log.w(TAG, "failed sending, server returned: " + getResponse(urlConnection,
- !success));
2016-12-27 18:37:38 +00:00
- }
- return success;
- } finally {
- urlConnection.disconnect();
- }
-
- }
-
- private String getResponse(HttpURLConnection httpUrlConnection, boolean errorStream)
- throws IOException {
- InputStream responseStream = new BufferedInputStream(errorStream
- ? httpUrlConnection.getErrorStream()
- : httpUrlConnection.getInputStream());
-
- BufferedReader responseStreamReader = new BufferedReader(
- new InputStreamReader(responseStream));
- String line = "";
- StringBuilder stringBuilder = new StringBuilder();
- while ((line = responseStreamReader.readLine()) != null) {
- stringBuilder.append(line).append("\n");
- }
- responseStreamReader.close();
- responseStream.close();
-
- return stringBuilder.toString();
- }
-
-}
diff --git a/src/org/cyanogenmod/cmparts/cmstats/Utilities.java b/src/org/cyanogenmod/cmparts/cmstats/Utilities.java
deleted file mode 100644
2017-01-17 23:17:50 +00:00
index efb7379..0000000
2016-12-27 18:37:38 +00:00
--- a/src/org/cyanogenmod/cmparts/cmstats/Utilities.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright (C) 2012 The CyanogenMod Project
- *
- * 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.cyanogenmod.cmparts.cmstats;
-
-import android.content.Context;
-import android.os.Build;
-import android.os.SystemProperties;
-import android.provider.Settings;
-import android.telephony.TelephonyManager;
-import android.text.TextUtils;
-
-import cyanogenmod.providers.CMSettings;
-
-import java.math.BigInteger;
-import java.net.NetworkInterface;
-import java.security.MessageDigest;
-
-public class Utilities {
- public static String getUniqueID(Context context) {
- final String id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
- return digest(context.getPackageName() + id);
- }
-
- public static String getCarrier(Context context) {
- TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
- String carrier = tm.getNetworkOperatorName();
- if (TextUtils.isEmpty(carrier)) {
- carrier = "Unknown";
- }
- return carrier;
- }
-
- public static String getCarrierId(Context context) {
- TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
- String carrierId = tm.getNetworkOperator();
- if (TextUtils.isEmpty(carrierId)) {
- carrierId = "0";
- }
- return carrierId;
- }
-
- public static String getCountryCode(Context context) {
- TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
- String countryCode = tm.getNetworkCountryIso();
- if (TextUtils.isEmpty(countryCode)) {
- countryCode = "Unknown";
- }
- return countryCode;
- }
-
- public static String getDevice() {
- return SystemProperties.get("ro.cm.device", Build.PRODUCT);
- }
-
- public static String getModVersion() {
- return SystemProperties.get("ro.cm.version", Build.DISPLAY);
- }
-
- public static String digest(String input) {
- try {
2017-01-17 23:17:50 +00:00
- MessageDigest md = MessageDigest.getInstance("SHA-256");
2016-12-27 18:37:38 +00:00
- return new BigInteger(1, md.digest(input.getBytes())).toString(16).toUpperCase();
- } catch (Exception e) {
- return null;
- }
- }
-
- /**
- * Check to see if global stats are enabled.
- * @param context
- * @return Whether or not stats collection is enabled.
- */
- public static boolean isStatsCollectionEnabled(Context context) {
- return CMSettings.Secure.getInt(context.getContentResolver(),
- CMSettings.Secure.STATS_COLLECTION, 1) != 0;
- }
-
- /**
- * Enabled or disable stats collection
- * @param context
- * @param enabled Boolean that sets collection being enabled.
- */
- public static void setStatsCollectionEnabled(Context context, boolean enabled) {
- int enable = (enabled) ? 1 : 0;
- CMSettings.Secure.putInt(context.getContentResolver(),
- CMSettings.Secure.STATS_COLLECTION, enable);
- }
-}
--
2.9.3