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

Commit d9f60d9a authored by Himanshu Gupta's avatar Himanshu Gupta
Browse files

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
parent 6814775f
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -58,6 +58,11 @@ public class AppStateClonedAppsBridge extends AppStateBaseBridge{
            mCloneProfileApps = mContext.getPackageManager()
            mCloneProfileApps = mContext.getPackageManager()
                    .getInstalledPackagesAsUser(GET_ACTIVITIES,
                    .getInstalledPackagesAsUser(GET_ACTIVITIES,
                            mCloneUserId).stream().map(x -> x.packageName).toList();
                            mCloneUserId).stream().map(x -> x.packageName).toList();
        } else if (!mCloneProfileApps.isEmpty()) {
            // In case we remove clone profile (mCloneUserId becomes -1), the bridge state should
            // reflect the same by setting cloneProfileApps as empty, without building the entire
            // page.
            mCloneProfileApps = new ArrayList<>();
        }
        }


        final List<ApplicationsState.AppEntry> allApps = mAppSession.getAllApps();
        final List<ApplicationsState.AppEntry> allApps = mAppSession.getAllApps();
+9 −0
Original line number Original line Diff line number Diff line
@@ -165,4 +165,13 @@ public class CloneBackend {
    public int getCloneUserId() {
    public int getCloneUserId() {
        return mCloneUserId;
        return mCloneUserId;
    }
    }

    /**
     * Resets {@link #mCloneUserId} to -1.
     * Typically called after the cloneUser is removed, so that the obsolete clonedUserId present
     * with the CloneBackend instance can be cleared.
     */
    public void resetCloneUserId() {
        mCloneUserId = -1;
    }
}
}
+7 −2
Original line number Original line Diff line number Diff line
@@ -923,10 +923,15 @@ public class ManageApplications extends InstrumentedFragment
            }
            }
            IUserManager um = IUserManager.Stub.asInterface(
            IUserManager um = IUserManager.Stub.asInterface(
                    ServiceManager.getService(Context.USER_SERVICE));
                    ServiceManager.getService(Context.USER_SERVICE));
            CloneBackend cloneBackend = CloneBackend.getInstance(getContext());
            try {
            try {
                // Warning: This removes all the data, media & images present in cloned user.
                // Warning: This removes all the data, media & images present in cloned user.
                um.removeUser(clonedUserId);
                if (um.removeUser(clonedUserId)) {
                    cloneBackend.resetCloneUserId();
                    mApplications.rebuild();
                    mApplications.rebuild();
                } else if (ManageApplications.DEBUG) {
                    Log.e(TAG, "Failed to remove cloned user");
                }
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.e(TAG, "Failed to remove cloned apps", e);
                Log.e(TAG, "Failed to remove cloned apps", e);
                Toast.makeText(getContext(),
                Toast.makeText(getContext(),