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

Commit df46e86c authored by Jakob Schneider's avatar Jakob Schneider
Browse files

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
parent 1a4620a9
Loading
Loading
Loading
Loading
+20 −5
Original line number Diff line number Diff line
@@ -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) {