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

Commit 3727bef8 authored by Amith Yamasani's avatar Amith Yamasani Committed by Android Git Automerger
Browse files

am b6c171b1: Merge "Do cleanup when Stopping users" into jb-mr1-dev

* commit 'b6c171b1':
  Do cleanup when Stopping users
parents f094d963 b6c171b1
Loading
Loading
Loading
Loading
+20 −14
Original line number Diff line number Diff line
@@ -98,21 +98,19 @@ class AppWidgetService extends IAppWidgetService.Stub

        IntentFilter userFilter = new IntentFilter();
        userFilter.addAction(Intent.ACTION_USER_REMOVED);
        userFilter.addAction(Intent.ACTION_USER_STOPPING);
        mContext.registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                onUserRemoved(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1));
                if (Intent.ACTION_USER_REMOVED.equals(intent.getAction())) {
                    onUserRemoved(intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
                            UserHandle.USER_NULL));
                } else if (Intent.ACTION_USER_STOPPING.equals(intent.getAction())) {
                    onUserStopping(intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
                            UserHandle.USER_NULL));
                }
        }, userFilter);

        IntentFilter userStopFilter = new IntentFilter();
        userStopFilter.addAction(Intent.ACTION_USER_STOPPED);
        mContext.registerReceiverAsUser(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                onUserStopped(getSendingUserId());
            }
        }, UserHandle.ALL, userFilter, null, null);
        }, userFilter);
    }

    /**
@@ -212,7 +210,15 @@ class AppWidgetService extends IAppWidgetService.Stub
        }
    }

    public void onUserStopped(int userId) {
    public void onUserStopping(int userId) {
        if (userId < 1) return;
        synchronized (mAppWidgetServices) {
            AppWidgetServiceImpl impl = mAppWidgetServices.get(userId);
            if (impl != null) {
                mAppWidgetServices.remove(userId);
                impl.onUserStopping();
            }
        }
    }

    private AppWidgetServiceImpl getImplForUser(int userId) {
@@ -324,11 +330,11 @@ class AppWidgetService extends IAppWidgetService.Stub
            String action = intent.getAction();
            // Slog.d(TAG, "received " + action);
            if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
                int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
                int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
                if (userId >= 0) {
                    getImplForUser(userId).sendInitialBroadcasts();
                } else {
                    Slog.w(TAG, "Not user handle supplied in " + intent);
                    Slog.w(TAG, "Incorrect user handle supplied in " + intent);
                }
            } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
                for (int i = 0; i < mAppWidgetServices.size(); i++) {
+4 −1
Original line number Diff line number Diff line
@@ -1778,13 +1778,16 @@ class AppWidgetServiceImpl {
        return new AtomicFile(settingsFile);
    }

    void onUserRemoved() {
    void onUserStopping() {
        // prune the ones we don't want to keep
        int N = mInstalledProviders.size();
        for (int i = N - 1; i >= 0; i--) {
            Provider p = mInstalledProviders.get(i);
            cancelBroadcasts(p);
        }
    }

    void onUserRemoved() {
        getSettingsFile(mUserId).delete();
    }

+20 −3
Original line number Diff line number Diff line
@@ -458,15 +458,21 @@ class WallpaperManagerService extends IWallpaperManager.Stub {

        IntentFilter userFilter = new IntentFilter();
        userFilter.addAction(Intent.ACTION_USER_REMOVED);
        userFilter.addAction(Intent.ACTION_USER_STOPPING);
        mContext.registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
                if (Intent.ACTION_USER_REMOVED.equals(action)) {
                    removeUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
                    onRemoveUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
                            UserHandle.USER_NULL));
                } else if (Intent.ACTION_USER_STOPPING.equals(action)) {
                    onStoppingUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
                            UserHandle.USER_NULL));
                }
            }
        }, userFilter);

        try {
            ActivityManagerNative.getDefault().registerUserSwitchObserver(
                    new IUserSwitchObserver.Stub() {
@@ -491,13 +497,24 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
        }
    }

    void removeUser(int userId) {
    void onStoppingUser(int userId) {
        if (userId < 1) return;
        synchronized (mLock) {
            WallpaperData wallpaper = mWallpaperMap.get(userId);
            if (wallpaper != null) {
                if (wallpaper.wallpaperObserver != null) {
                    wallpaper.wallpaperObserver.stopWatching();
                    wallpaper.wallpaperObserver = null;
                }
                mWallpaperMap.remove(userId);
            }
        }
    }

    void onRemoveUser(int userId) {
        if (userId < 1) return;
        synchronized (mLock) {
            onStoppingUser(userId);
            File wallpaperFile = new File(getWallpaperDir(userId), WALLPAPER);
            wallpaperFile.delete();
            File wallpaperInfoFile = new File(getWallpaperDir(userId), WALLPAPER_INFO);
+7 −2
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@ public class UserManagerService extends IUserManager.Stub {
                        -1, -1);
                mUserListFile = new File(mUsersDir, USER_LIST_FILENAME);
                readUserListLocked();
                // Prune out any partially created users.
                // Prune out any partially created/partially removed users.
                ArrayList<UserInfo> partials = new ArrayList<UserInfo>();
                for (int i = 0; i < mUsers.size(); i++) {
                    UserInfo ui = mUsers.valueAt(i);
@@ -459,7 +459,7 @@ public class UserManagerService extends IUserManager.Stub {
    private void fallbackToSingleUserLocked() {
        // Create the primary user
        UserInfo primary = new UserInfo(0, "Primary", null,
                UserInfo.FLAG_ADMIN | UserInfo.FLAG_PRIMARY);
                UserInfo.FLAG_ADMIN | UserInfo.FLAG_PRIMARY | UserInfo.FLAG_INITIALIZED);
        mUsers.put(0, primary);
        mNextSerialNumber = MIN_USER_ID;
        updateUserIdsLocked();
@@ -703,6 +703,11 @@ public class UserManagerService extends IUserManager.Stub {
                return false;
            }
            mRemovingUserIds.add(userHandle);
            // Set this to a partially created user, so that the user will be purged
            // on next startup, in case the runtime stops now before stopping and
            // removing the user completely.
            user.partial = true;
            writeUserLocked(user);
        }

        int res;