Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6988c60f authored by Adnan's avatar Adnan Committed by Steve Kondik
Browse files

Settings: Migrate stats opt out to global settings.

Control newly introduced global setting

Change-Id: Iea22206cd8ac8bf7d45e4b7dabfb9f0d1e602e0e
parent 81409443
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;


import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;

+15 −5
Original line number Diff line number Diff line
@@ -19,12 +19,12 @@ package com.android.settings.cmstats;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.provider.Settings;
import android.util.Log;

public class ReportingServiceManager extends BroadcastReceiver {
@@ -43,8 +43,10 @@ public class ReportingServiceManager extends BroadcastReceiver {

    public static void setAlarm(Context context, long millisFromNow) {
        SharedPreferences prefs = AnonymousStats.getPreferences(context);
        boolean optedIn = prefs.getBoolean(AnonymousStats.ANONYMOUS_OPT_IN, true);
        if (!optedIn) {
        if (prefs.contains(AnonymousStats.ANONYMOUS_OPT_IN)) {
            migrate(context, prefs);
        }
        if (!Utilities.isStatsCollectionEnabled(context)) {
            return;
        }

@@ -80,10 +82,11 @@ public class ReportingServiceManager extends BroadcastReceiver {
        }

        SharedPreferences prefs = AnonymousStats.getPreferences(context);
        boolean optedIn = prefs.getBoolean(AnonymousStats.ANONYMOUS_OPT_IN, true);
        if (!optedIn) {

        if (!Utilities.isStatsCollectionEnabled(context)) {
            return;
        }

        long lastSynced = prefs.getLong(AnonymousStats.ANONYMOUS_LAST_CHECKED, 0);
        if (lastSynced == 0) {
            setAlarm(context, 0);
@@ -100,4 +103,11 @@ public class ReportingServiceManager extends BroadcastReceiver {
        intent.setClass(context, ReportingService.class);
        context.startService(intent);
    }

    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();
    }

}
+21 −0
Original line number Diff line number Diff line
@@ -75,4 +75,25 @@ public class Utilities {
            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 Settings.System.getInt(context.getContentResolver(),
                Settings.System.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;
        Settings.System.putInt(context.getContentResolver(),
                Settings.System.STATS_COLLECTION, enable);
    }
}