Merge "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." into main

This commit is contained in:
Jakob Schneider
2023-07-19 10:39:44 +00:00
committed by Android (Google) Code Review
2 changed files with 13 additions and 40 deletions

View File

@@ -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<LauncherActivityInfo> 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));
}
}
}

View File

@@ -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