diff options
author | Koushik Dutta <koushd@gmail.com> | 2013-04-14 16:11:20 -0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2013-04-16 14:05:35 -0700 |
commit | b7ba9af273b8022f80c5e081f790532869071f01 (patch) | |
tree | 93928570c48f36f6f330251401bc0bba3977d5c6 /src | |
parent | b608d71ea4d0e65d32bf1ce6fd5e34dc37040b51 (diff) | |
download | packages_apps_Settings-b7ba9af273b8022f80c5e081f790532869071f01.zip packages_apps_Settings-b7ba9af273b8022f80c5e081f790532869071f01.tar.gz packages_apps_Settings-b7ba9af273b8022f80c5e081f790532869071f01.tar.bz2 |
CMStats changes.
Remove the notification on boot. Users are thinking they need to opt out to get rid of the notification.
The setting to opt-out still exists in the Settings app.
If the user does not opt out within 'tFrame' time (1 day), the checkin service will now run; prior
to this, the checkin service would not run until the next reboot. That next reboot could occur within a
few minutes (startup crash, which then automatically checks in before the user has a chance to opt out)
or even the possibility of never. This is unpredictable and buggy.
Change the checkin frequency from 7 days to 1 day.
Change-Id: I66a26a6c200710146c0de3832253417fae557e52
Diffstat (limited to 'src')
3 files changed, 16 insertions, 46 deletions
diff --git a/src/com/android/settings/cmstats/AnonymousStats.java b/src/com/android/settings/cmstats/AnonymousStats.java index 0e1bc8e..9294e5d 100644 --- a/src/com/android/settings/cmstats/AnonymousStats.java +++ b/src/com/android/settings/cmstats/AnonymousStats.java @@ -40,8 +40,6 @@ public class AnonymousStats extends SettingsPreferenceFragment 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"; @@ -65,13 +63,6 @@ public class AnonymousStats extends SettingsPreferenceFragment 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); } } diff --git a/src/com/android/settings/cmstats/ReportingService.java b/src/com/android/settings/cmstats/ReportingService.java index e141694..98f9ef4 100644 --- a/src/com/android/settings/cmstats/ReportingService.java +++ b/src/com/android/settings/cmstats/ReportingService.java @@ -54,19 +54,14 @@ public class ReportingService extends Service { @Override 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(); - } + Log.d(TAG, "User has opted in -- reporting."); + Thread thread = new Thread() { + @Override + public void run() { + report(); + } + }; + thread.start(); return Service.START_REDELIVER_INTENT; } @@ -125,20 +120,4 @@ 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 41f563d..3a065ff 100644 --- a/src/com/android/settings/cmstats/ReportingServiceManager.java +++ b/src/com/android/settings/cmstats/ReportingServiceManager.java @@ -29,8 +29,8 @@ import android.util.Log; public class ReportingServiceManager extends BroadcastReceiver { - public static final long dMill = 24 * 60 * 60 * 1000; - public static final long tFrame = 7 * dMill; + public static final long dMill = 24L * 60L * 60L * 1000L; + public static final long tFrame = 1L * dMill; @Override public void onReceive(Context ctx, Intent intent) { @@ -45,13 +45,15 @@ public class ReportingServiceManager extends BroadcastReceiver { SharedPreferences prefs = ctx.getSharedPreferences("CMStats", 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) { + if (!optedIn) { return; } long lastSynced = prefs.getLong(AnonymousStats.ANONYMOUS_LAST_CHECKED, 0); if (lastSynced == 0) { - return; + // never synced, so let's fake out that the last sync was just now. + // this will allow the user tFrame time to opt out before it will start + // sending up anonymous stats. + lastSynced = System.currentTimeMillis(); } long timeLeft = (lastSynced + tFrame) - System.currentTimeMillis(); Intent sIntent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION); @@ -68,7 +70,6 @@ public class ReportingServiceManager extends BroadcastReceiver { if (networkInfo != null && networkInfo.isConnected()) { SharedPreferences prefs = ctx.getSharedPreferences("CMStats", 0); 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) { @@ -80,10 +81,9 @@ public class ReportingServiceManager extends BroadcastReceiver { } else if (System.currentTimeMillis() - lastSynced >= tFrame) { shouldSync = true; } - if ((shouldSync && optedIn) || firstBoot) { + if (shouldSync && optedIn) { Intent sIntent = new Intent(); sIntent.setComponent(new ComponentName(ctx.getPackageName(), ReportingService.class.getName())); - sIntent.putExtra("firstBoot", firstBoot); ctx.startService(sIntent); } else if (optedIn) { setAlarm(ctx); |