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

Commit 8a696e9e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

parents ecd47095 945864c7
Loading
Loading
Loading
Loading
+46 −30
Original line number Original line Diff line number Diff line
@@ -2750,14 +2750,21 @@ public class SettingsProvider extends ContentProvider {
        }
        }


        private void notifyForSettingsChange(int key, String name) {
        private void notifyForSettingsChange(int key, String name) {
            final int userId = getUserIdFromKey(key);
            // Increment the generation first, so observers always see the new value
            Uri uri = getNotificationUriFor(key, name);

            mGenerationRegistry.incrementGeneration(key);
            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,
                mHandler.obtainMessage(MyHandler.MSG_NOTIFY_URI_CHANGED,
                        userId, 0, uri).sendToTarget();
                        userId, 0, uri).sendToTarget();

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


            // Always notify that our data changed
            mHandler.obtainMessage(MyHandler.MSG_NOTIFY_DATA_CHANGED).sendToTarget();
            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,
        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)) {
                for (int profileId : mUserManager.getProfileIdsWithDisabled(userId)) {
                    // the notification for userId has already been sent.
                    // the notification for userId has already been sent.
                    if (profileId != userId) {
                    if (profileId != userId) {
                        mHandler.obtainMessage(MyHandler.MSG_NOTIFY_URI_CHANGED,
                                profileId, 0, uri).sendToTarget();
                        final int key = makeKey(type, profileId);
                        final int key = makeKey(type, profileId);
                        // Increment the generation first, so observers always see the new value
                        mGenerationRegistry.incrementGeneration(key);
                        mGenerationRegistry.incrementGeneration(key);

                        mHandler.obtainMessage(MyHandler.MSG_NOTIFY_URI_CHANGED,
                        mHandler.obtainMessage(MyHandler.MSG_NOTIFY_DATA_CHANGED).sendToTarget();
                                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++) {
            for (int i = 0; i < users.size(); i++) {
                final int userId = users.get(i).id;
                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))) {
                if (!mUserManager.isUserRunning(UserHandle.of(userId))) {
                    continue;
                    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,
                mHandler.obtainMessage(MyHandler.MSG_NOTIFY_URI_CHANGED,
                        userId, 0, uri).sendToTarget();
                        userId, 0, uri).sendToTarget();
            }
            }