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:
committed by
Android (Google) Code Review
commit
6a5db66e52
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user