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

This commit is contained in:
Amith Yamasani
2012-10-16 21:41:27 -07:00
committed by Android (Google) Code Review
4 changed files with 51 additions and 20 deletions

View File

@@ -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);
}
/**
@@ -203,7 +201,7 @@ class AppWidgetService extends IAppWidgetService.Stub
synchronized (mAppWidgetServices) {
AppWidgetServiceImpl impl = mAppWidgetServices.get(userId);
mAppWidgetServices.remove(userId);
if (impl == null) {
AppWidgetServiceImpl.getSettingsFile(userId).delete();
} else {
@@ -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++) {

View File

@@ -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();
}

View File

@@ -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) {
wallpaper.wallpaperObserver.stopWatching();
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);

View File

@@ -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;