summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/cmstats
diff options
context:
space:
mode:
authorSteve Kondik <shade@chemlab.org>2013-04-03 08:12:24 -0700
committerSteve Kondik <shade@chemlab.org>2013-04-03 08:14:24 -0700
commite25e5b9e5f7c50c93a97a7b9714ac66f46237a5a (patch)
tree4d03077840176f7e7a617fa3855286c2e4cda94e /src/com/android/settings/cmstats
parent1d73371aae563e08270cf178b5dc80b7262e00da (diff)
downloadpackages_apps_settings-e25e5b9e5f7c50c93a97a7b9714ac66f46237a5a.zip
packages_apps_settings-e25e5b9e5f7c50c93a97a7b9714ac66f46237a5a.tar.gz
packages_apps_settings-e25e5b9e5f7c50c93a97a7b9714ac66f46237a5a.tar.bz2
Restore the opt-out for stats.
* Apparently this is a bigger issue for a small number of extremely vocal users. We should respect their wishes, no matter how off-base their claims are in this context. Change-Id: I9eef9a65260ec4e360d398f80d610a198c09c915
Diffstat (limited to 'src/com/android/settings/cmstats')
-rw-r--r--src/com/android/settings/cmstats/AnonymousStats.java138
-rw-r--r--src/com/android/settings/cmstats/PreviewData.java76
-rw-r--r--src/com/android/settings/cmstats/ReportingService.java65
-rw-r--r--src/com/android/settings/cmstats/ReportingServiceManager.java22
4 files changed, 274 insertions, 27 deletions
diff --git a/src/com/android/settings/cmstats/AnonymousStats.java b/src/com/android/settings/cmstats/AnonymousStats.java
new file mode 100644
index 0000000..0e1bc8e
--- /dev/null
+++ b/src/com/android/settings/cmstats/AnonymousStats.java
@@ -0,0 +1,138 @@
+/*
+ * 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 com.android.settings.cmstats;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.net.Uri;
+import android.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference;
+import android.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+
+public class AnonymousStats extends SettingsPreferenceFragment
+ implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
+ Preference.OnPreferenceChangeListener {
+
+ private static final String VIEW_STATS = "pref_view_stats";
+
+ protected static final String ANONYMOUS_OPT_IN = "pref_anonymous_opt_in";
+
+ protected static final String ANONYMOUS_FIRST_BOOT = "pref_anonymous_first_boot";
+
+ protected static final String ANONYMOUS_LAST_CHECKED = "pref_anonymous_checked_in";
+
+ protected static final String ANONYMOUS_ALARM_SET = "pref_anonymous_alarm_set";
+
+ private CheckBoxPreference mEnableReporting;
+
+ private Preference mViewStats;
+
+ private Dialog mOkDialog;
+
+ private boolean mOkClicked;
+
+ private SharedPreferences mPrefs;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ if (getPreferenceManager() != null) {
+ addPreferencesFromResource(R.xml.anonymous_stats);
+ PreferenceScreen prefSet = getPreferenceScreen();
+ mPrefs = getActivity().getSharedPreferences("CMStats", 0);
+ mEnableReporting = (CheckBoxPreference) prefSet.findPreference(ANONYMOUS_OPT_IN);
+ mViewStats = (Preference) prefSet.findPreference(VIEW_STATS);
+ boolean firstBoot = mPrefs.getBoolean(ANONYMOUS_FIRST_BOOT, true);
+ if (mEnableReporting.isChecked() && firstBoot) {
+ mPrefs.edit().putBoolean(ANONYMOUS_FIRST_BOOT, false).apply();
+ ReportingServiceManager.launchService(getActivity());
+ }
+ NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+ nm.cancel(1);
+ }
+ }
+
+ @Override
+ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+ if (preference == mEnableReporting) {
+ if (mEnableReporting.isChecked()) {
+ // Display the confirmation dialog
+ mOkClicked = false;
+ if (mOkDialog != null) {
+ mOkDialog.dismiss();
+ mOkDialog = null;
+ }
+ mOkDialog = new AlertDialog.Builder(getActivity()).setMessage(
+ getActivity().getResources().getString(R.string.anonymous_statistics_warning))
+ .setTitle(R.string.anonymous_statistics_warning_title)
+ .setIconAttribute(android.R.attr.alertDialogIcon)
+ .setPositiveButton(android.R.string.yes, this)
+ .setNeutralButton(getString(R.string.anonymous_learn_more), this)
+ .setNegativeButton(android.R.string.no, this)
+ .show();
+ mOkDialog.setOnDismissListener(this);
+ } else {
+ // Disable reporting
+ mPrefs.edit().putBoolean(ANONYMOUS_OPT_IN, false).apply();
+ }
+ } else if (preference == mViewStats) {
+ // Display the stats page
+ Uri uri = Uri.parse("http://stats.cyanogenmod.com");
+ startActivity(new Intent(Intent.ACTION_VIEW, uri));
+ } else {
+ // If we didn't handle it, let preferences handle it.
+ return super.onPreferenceTreeClick(preferenceScreen, preference);
+ }
+ return true;
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ return false;
+ }
+
+ @Override
+ public void onDismiss(DialogInterface dialog) {
+ if (!mOkClicked) {
+ mEnableReporting.setChecked(false);
+ }
+ }
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (which == DialogInterface.BUTTON_POSITIVE) {
+ mOkClicked = true;
+ mPrefs.edit().putBoolean(ANONYMOUS_OPT_IN, true).apply();
+ ReportingServiceManager.launchService(getActivity());
+ } else if (which == DialogInterface.BUTTON_NEGATIVE){
+ mEnableReporting.setChecked(false);
+ } else {
+ Uri uri = Uri.parse("http://www.cyanogenmod.com/blog/cmstats-what-it-is-and-why-you-should-opt-in");
+ startActivity(new Intent(Intent.ACTION_VIEW, uri));
+ }
+ }
+
+}
diff --git a/src/com/android/settings/cmstats/PreviewData.java b/src/com/android/settings/cmstats/PreviewData.java
new file mode 100644
index 0000000..c8b18ba
--- /dev/null
+++ b/src/com/android/settings/cmstats/PreviewData.java
@@ -0,0 +1,76 @@
+/*
+ * 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 com.android.settings.cmstats;
+
+import android.os.Bundle;
+import android.preference.Preference;
+import android.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+
+public class PreviewData extends SettingsPreferenceFragment
+ implements Preference.OnPreferenceChangeListener{
+
+ 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";
+
+ private Preference mId;
+
+ private Preference mDevice;
+
+ private Preference mVersion;
+
+ private Preference mCountry;
+
+ private Preference mCarrier;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ if (getPreferenceManager() != null) {
+
+ addPreferencesFromResource(R.xml.preview_data);
+ PreferenceScreen prefSet = getPreferenceScreen();
+
+ mId = (Preference) prefSet.findPreference(UNIQUE_ID);
+ mDevice = (Preference) prefSet.findPreference(DEVICE);
+ mVersion = (Preference) prefSet.findPreference(VERSION);
+ mCountry = (Preference) prefSet.findPreference(COUNTRY);
+ mCarrier = (Preference) prefSet.findPreference(CARRIER);
+
+ mId.setSummary(Utilities.getUniqueID(getActivity().getApplicationContext()));
+ mDevice.setSummary(Utilities.getDevice());
+ mVersion.setSummary(Utilities.getModVersion());
+ mCountry.setSummary(Utilities.getCountryCode(getActivity().getApplicationContext()));
+ mCarrier.setSummary(Utilities.getCarrier(getActivity().getApplicationContext()));
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ return false;
+ }
+}
diff --git a/src/com/android/settings/cmstats/ReportingService.java b/src/com/android/settings/cmstats/ReportingService.java
index 465eaa1..e141694 100644
--- a/src/com/android/settings/cmstats/ReportingService.java
+++ b/src/com/android/settings/cmstats/ReportingService.java
@@ -16,10 +16,8 @@
package com.android.settings.cmstats;
-import android.app.Service;
-import android.content.Intent;
-import android.os.IBinder;
-import android.util.Log;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
@@ -28,8 +26,18 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
-import java.util.ArrayList;
-import java.util.List;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.Service;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.os.IBinder;
+import android.util.Log;
+
+import com.android.settings.R;
+import com.android.settings.Settings;
import com.google.analytics.tracking.android.GoogleAnalytics;
import com.google.analytics.tracking.android.Tracker;
@@ -39,25 +47,26 @@ import com.android.settings.R;
public class ReportingService extends Service {
protected static final String TAG = "CMStats";
- protected static final String ANONYMOUS_LAST_CHECKED = "pref_anonymous_checked_in";
-
- protected static final String ANONYMOUS_ALARM_SET = "pref_anonymous_alarm_set";
-
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- Log.d(TAG, "Sending anonymous statistics data..");
- Thread thread = new Thread() {
- @Override
- public void run() {
- report();
- }
- };
- thread.start();
+ public int onStartCommand (Intent intent, int flags, int startId) {
+ if (intent.getBooleanExtra("firstBoot", false)) {
+ promptUser();
+ Log.d(TAG, "Prompting user for opt-in.");
+ } else {
+ Log.d(TAG, "User has opted in -- reporting.");
+ Thread thread = new Thread() {
+ @Override
+ public void run() {
+ report();
+ }
+ };
+ thread.start();
+ }
return Service.START_REDELIVER_INTENT;
}
@@ -108,7 +117,7 @@ public class ReportingService extends Service {
kv.add(new BasicNameValuePair("device_carrier_id", deviceCarrierId));
httppost.setEntity(new UrlEncodedFormEntity(kv));
httpclient.execute(httppost);
- getSharedPreferences("CMStats", 0).edit().putLong(ANONYMOUS_LAST_CHECKED,
+ getSharedPreferences("CMStats", 0).edit().putLong(AnonymousStats.ANONYMOUS_LAST_CHECKED,
System.currentTimeMillis()).apply();
} catch (Exception e) {
Log.e(TAG, "Got Exception", e);
@@ -116,4 +125,20 @@ public class ReportingService extends Service {
ReportingServiceManager.setAlarm(this);
stopSelf();
}
+
+ private void promptUser() {
+ NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+ Intent nI = new Intent();
+ nI.setComponent(new ComponentName(getPackageName(),Settings.AnonymousStatsActivity.class.getName()));
+ PendingIntent pI = PendingIntent.getActivity(this, 0, nI, 0);
+ Notification.Builder builder = new Notification.Builder(this)
+ .setSmallIcon(R.drawable.ic_cm_stats_notif)
+ .setAutoCancel(true)
+ .setTicker(getString(R.string.anonymous_statistics_title))
+ .setContentIntent(pI)
+ .setWhen(0)
+ .setContentTitle(getString(R.string.anonymous_statistics_title))
+ .setContentText(getString(R.string.anonymous_notification_desc));
+ nm.notify(1, builder.getNotification());
+ }
}
diff --git a/src/com/android/settings/cmstats/ReportingServiceManager.java b/src/com/android/settings/cmstats/ReportingServiceManager.java
index 120d7d1..41f563d 100644
--- a/src/com/android/settings/cmstats/ReportingServiceManager.java
+++ b/src/com/android/settings/cmstats/ReportingServiceManager.java
@@ -43,8 +43,13 @@ public class ReportingServiceManager extends BroadcastReceiver {
protected static void setAlarm (Context ctx) {
SharedPreferences prefs = ctx.getSharedPreferences("CMStats", 0);
- prefs.edit().putBoolean(ReportingService.ANONYMOUS_ALARM_SET, false).apply();
- long lastSynced = prefs.getLong(ReportingService.ANONYMOUS_LAST_CHECKED, 0);
+ prefs.edit().putBoolean(AnonymousStats.ANONYMOUS_ALARM_SET, false).apply();
+ boolean optedIn = prefs.getBoolean(AnonymousStats.ANONYMOUS_OPT_IN, true);
+ boolean firstBoot = prefs.getBoolean(AnonymousStats.ANONYMOUS_FIRST_BOOT, true);
+ if (!optedIn || firstBoot) {
+ return;
+ }
+ long lastSynced = prefs.getLong(AnonymousStats.ANONYMOUS_LAST_CHECKED, 0);
if (lastSynced == 0) {
return;
}
@@ -54,7 +59,7 @@ public class ReportingServiceManager extends BroadcastReceiver {
AlarmManager alarmManager = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeLeft, PendingIntent.getBroadcast(ctx, 0, sIntent, 0));
Log.d(ReportingService.TAG, "Next sync attempt in : " + timeLeft / dMill + " days");
- prefs.edit().putBoolean(ReportingService.ANONYMOUS_ALARM_SET, true).apply();
+ prefs.edit().putBoolean(AnonymousStats.ANONYMOUS_ALARM_SET, true).apply();
}
public static void launchService (Context ctx) {
@@ -62,8 +67,10 @@ public class ReportingServiceManager extends BroadcastReceiver {
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
SharedPreferences prefs = ctx.getSharedPreferences("CMStats", 0);
- long lastSynced = prefs.getLong(ReportingService.ANONYMOUS_LAST_CHECKED, 0);
- boolean alarmSet = prefs.getBoolean(ReportingService.ANONYMOUS_ALARM_SET, false);
+ long lastSynced = prefs.getLong(AnonymousStats.ANONYMOUS_LAST_CHECKED, 0);
+ boolean firstBoot = prefs.getBoolean(AnonymousStats.ANONYMOUS_FIRST_BOOT, true);
+ boolean optedIn = prefs.getBoolean(AnonymousStats.ANONYMOUS_OPT_IN, true);
+ boolean alarmSet = prefs.getBoolean(AnonymousStats.ANONYMOUS_ALARM_SET, false);
if (alarmSet) {
return;
}
@@ -73,11 +80,12 @@ public class ReportingServiceManager extends BroadcastReceiver {
} else if (System.currentTimeMillis() - lastSynced >= tFrame) {
shouldSync = true;
}
- if (shouldSync) {
+ if ((shouldSync && optedIn) || firstBoot) {
Intent sIntent = new Intent();
sIntent.setComponent(new ComponentName(ctx.getPackageName(), ReportingService.class.getName()));
+ sIntent.putExtra("firstBoot", firstBoot);
ctx.startService(sIntent);
- } else {
+ } else if (optedIn) {
setAlarm(ctx);
}
}