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

Commit 52e5701e authored by Dan Sandler's avatar Dan Sandler
Browse files

Move LOCK_SCREEN_SHOW_NOTIFICATIONS to per-user Settings.Secure.

Bug: 15331132
Change-Id: Ia80ccb2cfdf60116bd50601e60ff131619eafcc5
parent ea844f92
Loading
Loading
Loading
Loading
+7 −9
Original line number Original line Diff line number Diff line
@@ -4721,6 +4721,13 @@ public final class Settings {
         */
         */
        public static final String UNSAFE_VOLUME_MUSIC_ACTIVE_MS = "unsafe_volume_music_active_ms";
        public static final String UNSAFE_VOLUME_MUSIC_ACTIVE_MS = "unsafe_volume_music_active_ms";


        /**
         * This preference enables notification display on the lockscreen.
         * @hide
         */
        public static final String LOCK_SCREEN_SHOW_NOTIFICATIONS =
                "lock_screen_show_notifications";

        /**
        /**
         * This are the settings to be backed up.
         * This are the settings to be backed up.
         *
         *
@@ -6365,15 +6372,6 @@ public final class Settings {
         */
         */
        public static final String POLICY_CONTROL = "policy_control";
        public static final String POLICY_CONTROL = "policy_control";



        /**
         * This preference enables notification display even over a securely
         * locked screen.
         * @hide
         */
        public static final String LOCK_SCREEN_SHOW_NOTIFICATIONS =
                "lock_screen_show_notifications";

        /**
        /**
         * Defines global zen mode.  ZEN_MODE_OFF, ZEN_MODE_IMPORTANT_INTERRUPTIONS,
         * Defines global zen mode.  ZEN_MODE_OFF, ZEN_MODE_IMPORTANT_INTERRUPTIONS,
         * or ZEN_MODE_NO_INTERRUPTIONS.
         * or ZEN_MODE_NO_INTERRUPTIONS.
+1 −1
Original line number Original line Diff line number Diff line
@@ -183,7 +183,7 @@
    <!-- Default for Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE -->
    <!-- Default for Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE -->
    <integer name="def_wifi_scan_always_available">0</integer>
    <integer name="def_wifi_scan_always_available">0</integer>


    <!-- Default for Settings.Global.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1==on -->
    <!-- Default for Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1==on -->
    <integer name="def_lock_screen_show_notifications">1</integer>
    <integer name="def_lock_screen_show_notifications">1</integer>


    <!-- Default for Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED, 1==on -->
    <!-- Default for Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED, 1==on -->
+37 −38
Original line number Original line Diff line number Diff line
@@ -70,7 +70,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
    // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
    // 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
    // is properly propagated through your change.  Not doing so will result in a loss of user
    // settings.
    // settings.
    private static final int DATABASE_VERSION = 105;
    private static final int DATABASE_VERSION = 106;


    private Context mContext;
    private Context mContext;
    private int mUserHandle;
    private int mUserHandle;
@@ -1558,54 +1558,25 @@ public class DatabaseHelper extends SQLiteOpenHelper {
        }
        }


        if (upgradeVersion == 98) {
        if (upgradeVersion == 98) {
            if (mUserHandle == UserHandle.USER_OWNER) {
            // no-op; LOCK_SCREEN_SHOW_NOTIFICATIONS now handled in version 106
                db.beginTransaction();
                SQLiteStatement stmt = null;
                try {
                    stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
                            + " VALUES(?,?);");
                    loadIntegerSetting(stmt, Settings.Global.LOCK_SCREEN_SHOW_NOTIFICATIONS,
                            R.integer.def_lock_screen_show_notifications);
                    db.setTransactionSuccessful();
                } finally {
                    db.endTransaction();
                    if (stmt != null) stmt.close();
                }
            }
            upgradeVersion = 99;
            upgradeVersion = 99;
        }
        }


        if (upgradeVersion == 99) {
        if (upgradeVersion == 99) {
            if (mUserHandle == UserHandle.USER_OWNER) {
            // no-op; HEADS_UP_NOTIFICATIONS_ENABLED now handled in version 100
                db.beginTransaction();
                SQLiteStatement stmt = null;
                try {
                    stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
                            + " VALUES(?,?);");
                    loadIntegerSetting(stmt, Global.HEADS_UP_NOTIFICATIONS_ENABLED,
                            R.integer.def_heads_up_enabled);
                    db.setTransactionSuccessful();
                } finally {
                    db.endTransaction();
                    if (stmt != null) stmt.close();
                }
            }
            upgradeVersion = 100;
            upgradeVersion = 100;
        }
        }

        if (upgradeVersion == 100) {
        if (upgradeVersion == 100) {
           // Catch devices that were initialized to version 100 and missed these in onCreate()
            // note: LOCK_SCREEN_SHOW_NOTIFICATIONS now handled in version 106
            if (mUserHandle == UserHandle.USER_OWNER) {
            if (mUserHandle == UserHandle.USER_OWNER) {
                db.beginTransaction();
                db.beginTransaction();
                SQLiteStatement stmt = null;
                SQLiteStatement stmt = null;
                try {
                try {
                    stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)"
                    stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
                            + " VALUES(?,?);");
                            + " VALUES(?,?);");
                    loadIntegerSetting(stmt, Settings.Global.LOCK_SCREEN_SHOW_NOTIFICATIONS,
                            R.integer.def_lock_screen_show_notifications);

                    loadIntegerSetting(stmt, Global.HEADS_UP_NOTIFICATIONS_ENABLED,
                    loadIntegerSetting(stmt, Global.HEADS_UP_NOTIFICATIONS_ENABLED,
                            R.integer.def_heads_up_enabled);
                            R.integer.def_heads_up_enabled);

                    db.setTransactionSuccessful();
                    db.setTransactionSuccessful();
                } finally {
                } finally {
                    db.endTransaction();
                    db.endTransaction();
@@ -1695,6 +1666,34 @@ public class DatabaseHelper extends SQLiteOpenHelper {
            upgradeVersion = 105;
            upgradeVersion = 105;
        }
        }


        if (upgradeVersion < 106) {
            // LOCK_SCREEN_SHOW_NOTIFICATIONS is now per-user.
            db.beginTransaction();
            SQLiteStatement stmt = null;
            try {
                stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
                        + " VALUES(?,?);");
                loadBooleanSetting(stmt, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
                        R.bool.def_guest_user_enabled);
                if (mUserHandle == UserHandle.USER_OWNER) {
                    final int oldShow = getIntValueFromTable(db,
                            TABLE_GLOBAL, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, -1);
                    if (oldShow >= 0) {
                        // overwrite the default with whatever you had
                        loadSetting(stmt, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, oldShow);
                        final SQLiteStatement deleteStmt
                                = db.compileStatement("DELETE FROM global WHERE name=?");
                        deleteStmt.bindString(1, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS);
                        deleteStmt.execute();
                    }
                }
                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
                if (stmt != null) stmt.close();
            }
            upgradeVersion = 106;
        }
        // *** Remember to update DATABASE_VERSION above!
        // *** Remember to update DATABASE_VERSION above!


        if (upgradeVersion != currentVersion) {
        if (upgradeVersion != currentVersion) {
@@ -2260,6 +2259,9 @@ public class DatabaseHelper extends SQLiteOpenHelper {
            loadBooleanSetting(stmt, Settings.Secure.WAKE_GESTURE_ENABLED,
            loadBooleanSetting(stmt, Settings.Secure.WAKE_GESTURE_ENABLED,
                    R.bool.def_wake_gesture_enabled);
                    R.bool.def_wake_gesture_enabled);


            loadIntegerSetting(stmt, Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
                    R.integer.def_lock_screen_show_notifications);

        } finally {
        } finally {
            if (stmt != null) stmt.close();
            if (stmt != null) stmt.close();
        }
        }
@@ -2420,9 +2422,6 @@ public class DatabaseHelper extends SQLiteOpenHelper {
            loadIntegerSetting(stmt, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE,
            loadIntegerSetting(stmt, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE,
                    R.integer.def_wifi_scan_always_available);
                    R.integer.def_wifi_scan_always_available);


            loadIntegerSetting(stmt, Settings.Global.LOCK_SCREEN_SHOW_NOTIFICATIONS,
                    R.integer.def_lock_screen_show_notifications);

            loadIntegerSetting(stmt, Global.HEADS_UP_NOTIFICATIONS_ENABLED,
            loadIntegerSetting(stmt, Global.HEADS_UP_NOTIFICATIONS_ENABLED,
                    R.integer.def_heads_up_enabled);
                    R.integer.def_heads_up_enabled);


+21 −5
Original line number Original line Diff line number Diff line
@@ -220,9 +220,8 @@ public abstract class BaseStatusBar extends SystemUI implements
            final int mode = Settings.Global.getInt(mContext.getContentResolver(),
            final int mode = Settings.Global.getInt(mContext.getContentResolver(),
                    Settings.Global.ZEN_MODE, Settings.Global.ZEN_MODE_OFF);
                    Settings.Global.ZEN_MODE, Settings.Global.ZEN_MODE_OFF);
            setZenMode(mode);
            setZenMode(mode);
            final boolean show = Settings.Global.getInt(mContext.getContentResolver(),

                    Settings.Global.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1) != 0;
            updateLockscreenNotificationSetting();
            mShowLockscreenNotifications = show;
        }
        }
    };
    };


@@ -289,6 +288,9 @@ public abstract class BaseStatusBar extends SystemUI implements
                mCurrentUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
                mCurrentUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
                updateCurrentProfilesCache();
                updateCurrentProfilesCache();
                if (true) Log.v(TAG, "userId " + mCurrentUserId + " is in the house");
                if (true) Log.v(TAG, "userId " + mCurrentUserId + " is in the house");

                updateLockscreenNotificationSetting();

                userSwitched(mCurrentUserId);
                userSwitched(mCurrentUserId);
            } else if (Intent.ACTION_USER_ADDED.equals(action)) {
            } else if (Intent.ACTION_USER_ADDED.equals(action)) {
                updateCurrentProfilesCache();
                updateCurrentProfilesCache();
@@ -387,8 +389,9 @@ public abstract class BaseStatusBar extends SystemUI implements
                Settings.Global.getUriFor(Settings.Global.ZEN_MODE), false,
                Settings.Global.getUriFor(Settings.Global.ZEN_MODE), false,
                mSettingsObserver);
                mSettingsObserver);
        mContext.getContentResolver().registerContentObserver(
        mContext.getContentResolver().registerContentObserver(
                Settings.Global.getUriFor(Settings.Global.LOCK_SCREEN_SHOW_NOTIFICATIONS), false,
                Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS), false,
                mSettingsObserver);
                mSettingsObserver,
                UserHandle.USER_ALL);


        mContext.getContentResolver().registerContentObserver(
        mContext.getContentResolver().registerContentObserver(
                Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS),
                Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS),
@@ -1424,6 +1427,19 @@ public abstract class BaseStatusBar extends SystemUI implements
        updateNotifications();
        updateNotifications();
    }
    }


    // extended in PhoneStatusBar
    protected void setShowLockscreenNotifications(boolean show) {
        mShowLockscreenNotifications = show;
    }

    private void updateLockscreenNotificationSetting() {
        final boolean show = Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
                1,
                mCurrentUserId) != 0;
        setShowLockscreenNotifications(show);
    }

    protected abstract void haltTicker();
    protected abstract void haltTicker();
    protected abstract void setAreThereNotifications();
    protected abstract void setAreThereNotifications();
    protected abstract void updateNotifications();
    protected abstract void updateNotifications();