diff options
| author | 2024-02-22 15:31:07 +0000 | |
|---|---|---|
| committer | 2024-02-22 15:31:07 +0000 | |
| commit | df46e86c3e49fd1bd26de608a5d5ff5aeaa752cd (patch) | |
| tree | 11c9a8170a323d720f04a8b9c079659c3562bae8 | |
| parent | 1a4620a9f9c7a35efe6740f79c3c63bd185bad58 (diff) | |
Fix an issue for work profiles (or any profile with a shared UI).
If a profile shares its UI with another profile then the launcher runs
on a different userId, this caused some checks to fail.
Removed one useless check about package name and adjusted the second to
consider the profile parent instead if it exists.
Bug: N/A (just found it)
Test: manually (this wasn't caught by CTS tests because in tests we have to set
the default launcher manually first in the test itself)
Change-Id: I5f09f90a0807efb1f49d82e4326ade026748f2c4
| -rw-r--r-- | services/core/java/com/android/server/pm/PackageArchiver.java | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/services/core/java/com/android/server/pm/PackageArchiver.java b/services/core/java/com/android/server/pm/PackageArchiver.java index dc97e5fa92af..6b63901b4d70 100644 --- a/services/core/java/com/android/server/pm/PackageArchiver.java +++ b/services/core/java/com/android/server/pm/PackageArchiver.java @@ -62,6 +62,7 @@ import android.content.pm.PackageInstaller; import android.content.pm.PackageManager; import android.content.pm.ParceledListSlice; import android.content.pm.ResolveInfo; +import android.content.pm.UserInfo; import android.content.pm.VersionedPackage; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -85,6 +86,7 @@ import android.os.RemoteException; import android.os.SELinux; import android.os.SystemProperties; import android.os.UserHandle; +import android.os.UserManager; import android.text.TextUtils; import android.util.ExceptionUtils; import android.util.Pair; @@ -163,6 +165,9 @@ public class PackageArchiver { @Nullable private AppOpsManager mAppOpsManager; + @Nullable + private UserManager mUserManager; + /* IntentSender store that maps key: {userId, appPackageName} to respective existing attached unarchival intent sender. */ private final Map<Pair<Integer, String>, IntentSender> mLauncherIntentSenders; @@ -272,12 +277,8 @@ public class PackageArchiver { Slog.e(TAG, "callerPackageName cannot be null for unarchival!"); return START_CLASS_NOT_FOUND; } - if (!isCallingPackageValid(callerPackageName, callingUid, userId)) { - // Return early as the calling UID does not match caller package's UID. - return START_CLASS_NOT_FOUND; - } - String currentLauncherPackageName = getCurrentLauncherPackageName(userId); + String currentLauncherPackageName = getCurrentLauncherPackageName(getParentUserId(userId)); if ((currentLauncherPackageName == null || !callerPackageName.equals( currentLauncherPackageName)) && callingUid != Process.SHELL_UID) { // TODO(b/311619990): Remove dependency on SHELL_UID for testing @@ -312,6 +313,13 @@ public class PackageArchiver { return START_ABORTED; } + // Profiles share their UI and default apps, so we have to get the profile parent before + // fetching the default launcher. + private int getParentUserId(int userId) { + UserInfo profileParent = getUserManager().getProfileParent(userId); + return profileParent == null ? userId : profileParent.id; + } + /** * Returns true if the componentName targeted by the intent corresponds to that of an archived * app. @@ -1120,6 +1128,13 @@ public class PackageArchiver { return mAppOpsManager; } + private UserManager getUserManager() { + if (mUserManager == null) { + mUserManager = mContext.getSystemService(UserManager.class); + } + return mUserManager; + } + private void storeArchiveState(String packageName, ArchiveState archiveState, int userId) throws PackageManager.NameNotFoundException { synchronized (mPm.mLock) { |