Clearing obsolete cloneUserId from CloneBackend.

When cloned user is removed from device, the previous clonedUserId
present with the CloneBackend instance becomes obsolete, and does
not update to reflect the new clonedUserId, when the cloned user is
re-created.
To fix this we set cloneUserId to -1 when cloned user is removed,
causing CloneBackend#installCloneApp to update clonedUserId when
the cloned profile is re-created.

Bug: 280431074, 275062025
Test: Manual by flashing the local build.
Change-Id: If0d7960998865b4081502e84d0d4125b3b05c69c
This commit is contained in:
Himanshu Gupta
2023-05-16 14:25:55 +01:00
parent 6814775fea
commit d9f60d9a1a
3 changed files with 21 additions and 2 deletions

View File

@@ -923,10 +923,15 @@ public class ManageApplications extends InstrumentedFragment
}
IUserManager um = IUserManager.Stub.asInterface(
ServiceManager.getService(Context.USER_SERVICE));
CloneBackend cloneBackend = CloneBackend.getInstance(getContext());
try {
// Warning: This removes all the data, media & images present in cloned user.
um.removeUser(clonedUserId);
mApplications.rebuild();
if (um.removeUser(clonedUserId)) {
cloneBackend.resetCloneUserId();
mApplications.rebuild();
} else if (ManageApplications.DEBUG) {
Log.e(TAG, "Failed to remove cloned user");
}
} catch (RemoteException e) {
Log.e(TAG, "Failed to remove cloned apps", e);
Toast.makeText(getContext(),