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

Commit 4d83e26c authored by Svet Ganov's avatar Svet Ganov Committed by android-build-merger
Browse files

Merge "Notify all running users for global settings change" into pi-dev

am: 8a696e9e

Change-Id: I706b6983ce8a8e1212a8e13f78c0c5ee4418d1bd
parents 3f65260b 8a696e9e
Loading
Loading
Loading
Loading
+46 −30
Original line number Diff line number Diff line
@@ -2750,14 +2750,21 @@ public class SettingsProvider extends ContentProvider {
        }

        private void notifyForSettingsChange(int key, String name) {
            final int userId = getUserIdFromKey(key);
            Uri uri = getNotificationUriFor(key, name);

            // Increment the generation first, so observers always see the new value
            mGenerationRegistry.incrementGeneration(key);

            if (isGlobalSettingsKey(key)) {
                if (Global.LOCATION_GLOBAL_KILL_SWITCH.equals(name)) {
                    // When the global kill switch is updated, send the
                    // change notification for the location setting.
                    notifyLocationChangeForRunningUsers();
                }
                notifyGlobalSettingChangeForRunningUsers(key, name);
            } else {
                final int userId = getUserIdFromKey(key);
                final Uri uri = getNotificationUriFor(key, name);
                mHandler.obtainMessage(MyHandler.MSG_NOTIFY_URI_CHANGED,
                        userId, 0, uri).sendToTarget();

                if (isSecureSettingsKey(key)) {
                    maybeNotifyProfiles(getTypeFromKey(key), userId, uri, name,
                            sSecureCloneToManagedSettings);
@@ -2767,14 +2774,10 @@ public class SettingsProvider extends ContentProvider {
                    maybeNotifyProfiles(getTypeFromKey(key), userId, uri, name,
                            sSystemCloneToManagedSettings);
                }
            }

            // Always notify that our data changed
            mHandler.obtainMessage(MyHandler.MSG_NOTIFY_DATA_CHANGED).sendToTarget();

            // When the global kill switch is updated, send the change notification for
            // the location setting.
            if (isGlobalSettingsKey(key) && Global.LOCATION_GLOBAL_KILL_SWITCH.equals(name)) {
                notifyLocationChangeForRunningUsers();
            }
        }

        private void maybeNotifyProfiles(int type, int userId, Uri uri, String name,
@@ -2783,14 +2786,28 @@ public class SettingsProvider extends ContentProvider {
                for (int profileId : mUserManager.getProfileIdsWithDisabled(userId)) {
                    // the notification for userId has already been sent.
                    if (profileId != userId) {
                        mHandler.obtainMessage(MyHandler.MSG_NOTIFY_URI_CHANGED,
                                profileId, 0, uri).sendToTarget();
                        final int key = makeKey(type, profileId);
                        // Increment the generation first, so observers always see the new value
                        mGenerationRegistry.incrementGeneration(key);

                        mHandler.obtainMessage(MyHandler.MSG_NOTIFY_DATA_CHANGED).sendToTarget();
                        mHandler.obtainMessage(MyHandler.MSG_NOTIFY_URI_CHANGED,
                                profileId, 0, uri).sendToTarget();
                    }
                }
            }
        }

        private void notifyGlobalSettingChangeForRunningUsers(int key, String name) {
            // Important: No need to update generation for each user as there
            // is a singleton generation entry for the global settings which
            // is already incremented be the caller.
            final Uri uri = getNotificationUriFor(key, name);
            final List<UserInfo> users = mUserManager.getUsers(/*excludeDying*/ true);
            for (int i = 0; i < users.size(); i++) {
                final int userId = users.get(i).id;
                if (mUserManager.isUserRunning(UserHandle.of(userId))) {
                    mHandler.obtainMessage(MyHandler.MSG_NOTIFY_URI_CHANGED,
                            userId, 0, uri).sendToTarget();
                }
            }
        }

@@ -2800,16 +2817,15 @@ public class SettingsProvider extends ContentProvider {
            for (int i = 0; i < users.size(); i++) {
                final int userId = users.get(i).id;

                // Do we have to increment the generation for users that are not running?
                // Yeah let's assume so...
                final int key = makeKey(SETTINGS_TYPE_SECURE, userId);
                mGenerationRegistry.incrementGeneration(key);

                if (!mUserManager.isUserRunning(UserHandle.of(userId))) {
                    continue;
                }
                final Uri uri = getNotificationUriFor(key, Secure.LOCATION_PROVIDERS_ALLOWED);

                // Increment the generation first, so observers always see the new value
                final int key = makeKey(SETTINGS_TYPE_SECURE, userId);
                mGenerationRegistry.incrementGeneration(key);

                final Uri uri = getNotificationUriFor(key, Secure.LOCATION_PROVIDERS_ALLOWED);
                mHandler.obtainMessage(MyHandler.MSG_NOTIFY_URI_CHANGED,
                        userId, 0, uri).sendToTarget();
            }