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

Commit ccb215c9 authored by Adnan Begovic's avatar Adnan Begovic
Browse files

SettingsProvider: Migrate STATS_COLLECTION to secure.

  Migrate STATS_COLLECTION to secure from system table while
  retaining the user preference. Moving it to secure allows us
  to do per-user settings.

Change-Id: Ia55fdd8c6db418c4eaebf17a54b765d25a878471
parent 3440a671
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -1239,6 +1239,7 @@ public final class Settings {
            MOVED_TO_SECURE.add(Secure.WIFI_WATCHDOG_PING_COUNT);
            MOVED_TO_SECURE.add(Secure.WIFI_WATCHDOG_PING_DELAY_MS);
            MOVED_TO_SECURE.add(Secure.WIFI_WATCHDOG_PING_TIMEOUT_MS);
            MOVED_TO_SECURE.add(Secure.STATS_COLLECTION);

            // At one time in System, then Global, but now back in Secure
            MOVED_TO_SECURE.add(Secure.INSTALL_NON_MARKET_APPS);
@@ -5428,6 +5429,12 @@ public final class Settings {
         */
        public static final String DEVELOPMENT_SHORTCUT = "development_shortcut";

        /**
         * Global stats collection
         * @hide
         */
        public static final String STATS_COLLECTION = "stats_collection";


        /**
         * This are the settings to be backed up.
+3 −0
Original line number Diff line number Diff line
@@ -215,4 +215,7 @@
    <!-- Default for Settings.System.STATUS_BAR_NOTIF_COUNT. -->
    <integer name="def_notif_count">0</integer>

    <!-- Default for Settings.Secure.STATS_COLLECTION. -->
    <bool name="def_cm_stats_collection">false</bool>

</resources>
+49 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.content.pm.PackageManager;
import android.content.res.XmlResourceParser;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteStatement;
import android.media.AudioManager;
@@ -71,7 +72,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
    // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
    // is properly propagated through your change.  Not doing so will result in a loss of user
    // settings.
    private static final int DATABASE_VERSION = 114;
    private static final int DATABASE_VERSION = 115;

    private Context mContext;
    private int mUserHandle;
@@ -1819,6 +1820,50 @@ public class DatabaseHelper extends SQLiteOpenHelper {
            upgradeVersion = 114;
        }

        if (upgradeVersion < 115) {
            db.beginTransaction();
            SQLiteStatement stmt = null;
            Cursor c = null;
            try {
                // The STATS_COLLECTION setting is becoming per-user rather
                // than device-system.
                try {
                    c = db.rawQuery("SELECT stats_collection from " + TABLE_SYSTEM, null);
                    // if this row exists, then we do work
                    if (c != null) {
                        if (c.moveToNext()) {
                            // The row exists so we can migrate the
                            // entry from there to the secure table, preserving its value.
                            String[] settingToSecure = {
                                    Settings.Secure.STATS_COLLECTION
                            };
                            moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE,
                                    settingToSecure, true);
                        }
                    } else {
                        // Otherwise our dbs don't have STATS_COLLECTION in secure so institute the
                        // default.
                        stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
                                + " VALUES(?,?);");
                        loadBooleanSetting(stmt, Settings.Secure.STATS_COLLECTION,
                                R.bool.def_cm_stats_collection);
                    }
                } catch (SQLiteException ex) {
                    // This is bad, just bump the version and add the setting to secure
                    stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
                            + " VALUES(?,?);");
                    loadBooleanSetting(stmt, Settings.Secure.STATS_COLLECTION,
                            R.bool.def_cm_stats_collection);
                }
                db.setTransactionSuccessful();
            } finally {
                if (c != null) c.close();
                db.endTransaction();
                if (stmt != null) stmt.close();
            }
            upgradeVersion = 115;
        }

        // *** Remember to update DATABASE_VERSION above!

        if (upgradeVersion != currentVersion) {
@@ -2436,6 +2481,9 @@ public class DatabaseHelper extends SQLiteOpenHelper {

            loadIntegerSetting(stmt, Settings.Secure.SLEEP_TIMEOUT,
                    R.integer.def_sleep_timeout);

            loadBooleanSetting(stmt, Settings.Secure.STATS_COLLECTION,
                    R.bool.def_cm_stats_collection);
        } finally {
            if (stmt != null) stmt.close();
        }