From 96061e70de8c070d587266a4dabc565f3cb26773 Mon Sep 17 00:00:00 2001 From: Jakob Schneider Date: Mon, 3 Jul 2023 18:06:57 +0100 Subject: [PATCH] Remove check to verify if the caller is the installer. In later stages of the design we decided that the API will also be open to other callers. Test: ArchiveManagerTest Bug: 291060290 Change-Id: I0c69c855cdc7682a6b80485e1e65e5f5eb73deb5 --- .../com/android/server/pm/ArchiveManager.java | 21 ++++-------- .../android/server/pm/ArchiveManagerTest.java | 32 ++++--------------- 2 files changed, 13 insertions(+), 40 deletions(-) diff --git a/services/core/java/com/android/server/pm/ArchiveManager.java b/services/core/java/com/android/server/pm/ArchiveManager.java index 99479f0885778..54352060cd385 100644 --- a/services/core/java/com/android/server/pm/ArchiveManager.java +++ b/services/core/java/com/android/server/pm/ArchiveManager.java @@ -77,9 +77,8 @@ final class ArchiveManager { snapshot.enforceCrossUserPermission(callingUid, userId, true, true, "archiveApp"); verifyCaller(callerPackageName, callingPackageName); - PackageStateInternal ps = getPackageState(packageName, snapshot, callingUid, user); - verifyInstallOwnership(packageName, callingPackageName, ps.getInstallSource()); + verifyInstaller(packageName, ps.getInstallSource()); List mainActivities = getLauncherApps().getActivityList( ps.getPackageName(), @@ -125,7 +124,7 @@ final class ArchiveManager { Path.of("/TODO"), null); activityInfos.add(activityInfo); } - // TODO(b/278553670) Adapt installer check verifyInstallOwnership and check for null there + InstallSource installSource = ps.getInstallSource(); String installerPackageName = installSource.mUpdateOwnerPackageName != null ? installSource.mUpdateOwnerPackageName : installSource.mInstallerPackageName; @@ -159,19 +158,13 @@ final class ArchiveManager { } } - private static void verifyInstallOwnership(String packageName, String callingPackageName, - InstallSource installSource) { - if (!TextUtils.equals(installSource.mInstallerPackageName, - callingPackageName)) { + private static void verifyInstaller(String packageName, InstallSource installSource) { + // TODO(b/291060290) Verify installer supports unarchiving + if (installSource.mUpdateOwnerPackageName == null + && installSource.mInstallerPackageName == null) { throw new SecurityException( - TextUtils.formatSimple("Caller is not the installer of record for %s.", + TextUtils.formatSimple("No installer found to archive app %s.", packageName)); } - String updateOwnerPackageName = installSource.mUpdateOwnerPackageName; - if (updateOwnerPackageName != null - && !TextUtils.equals(updateOwnerPackageName, callingPackageName)) { - throw new SecurityException( - TextUtils.formatSimple("Caller is not the update owner for %s.", packageName)); - } } } diff --git a/services/tests/mockingservicestests/src/com/android/server/pm/ArchiveManagerTest.java b/services/tests/mockingservicestests/src/com/android/server/pm/ArchiveManagerTest.java index 7b1654549841c..a8b0a7b5633da 100644 --- a/services/tests/mockingservicestests/src/com/android/server/pm/ArchiveManagerTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/pm/ArchiveManagerTest.java @@ -40,6 +40,7 @@ import android.os.Build; import android.os.Process; import android.os.UserHandle; import android.platform.test.annotations.Presubmit; +import android.text.TextUtils; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; @@ -169,14 +170,14 @@ public class ArchiveManagerTest { } @Test - public void archiveApp_callerNotInstallerOfRecord() { + public void archiveApp_noInstallerFound() { InstallSource otherInstallSource = InstallSource.create( CALLER_PACKAGE, CALLER_PACKAGE, - /* installerPackageName= */ "different", + /* installerPackageName= */ null, Binder.getCallingUid(), - CALLER_PACKAGE, + /* updateOwnerPackageName= */ null, /* installerAttributionTag= */ null, /* packageSource= */ 0); when(mPackageState.getInstallSource()).thenReturn(otherInstallSource); @@ -187,29 +188,8 @@ public class ArchiveManagerTest { mIntentSender) ); assertThat(e).hasMessageThat().isEqualTo( - String.format("Caller is not the installer of record for %s.", PACKAGE)); - } - - @Test - public void archiveApp_callerNotUpdateOwner() { - InstallSource otherInstallSource = - InstallSource.create( - CALLER_PACKAGE, - CALLER_PACKAGE, - CALLER_PACKAGE, - Binder.getCallingUid(), - /* updateOwnerPackageName= */ "different", - /* installerAttributionTag= */ null, - /* packageSource= */ 0); - when(mPackageState.getInstallSource()).thenReturn(otherInstallSource); - - Exception e = assertThrows( - SecurityException.class, - () -> mArchiveManager.archiveApp(PACKAGE, CALLER_PACKAGE, UserHandle.CURRENT, - mIntentSender) - ); - assertThat(e).hasMessageThat().isEqualTo( - String.format("Caller is not the update owner for %s.", PACKAGE)); + TextUtils.formatSimple("No installer found to archive app %s.", + PACKAGE)); } @Test