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

Commit 805d7ce0 authored by Jakob Schneider's avatar Jakob Schneider Committed by Android (Google) Code Review
Browse files

Merge "Fix crash that happens if you call archive twice." into main

parents 9d708f7e 6ceba535
Loading
Loading
Loading
Loading
+12 −3
Original line number Original line Diff line number Diff line
@@ -323,6 +323,7 @@ public class PackageArchiver {
        PackageStateInternal ps = getPackageState(packageName, snapshot,
        PackageStateInternal ps = getPackageState(packageName, snapshot,
                Binder.getCallingUid(), userId);
                Binder.getCallingUid(), userId);
        verifyNotSystemApp(ps.getFlags());
        verifyNotSystemApp(ps.getFlags());
        verifyInstalled(ps, userId);
        String responsibleInstallerPackage = getResponsibleInstallerPackage(ps);
        String responsibleInstallerPackage = getResponsibleInstallerPackage(ps);
        verifyInstaller(responsibleInstallerPackage, userId);
        verifyInstaller(responsibleInstallerPackage, userId);
        ApplicationInfo installerInfo = snapshot.getApplicationInfo(
        ApplicationInfo installerInfo = snapshot.getApplicationInfo(
@@ -476,6 +477,14 @@ public class PackageArchiver {
        }
        }
    }
    }


    private void verifyInstalled(PackageStateInternal ps, int userId)
            throws PackageManager.NameNotFoundException {
        if (!ps.getUserStateOrDefault(userId).isInstalled()) {
            throw new PackageManager.NameNotFoundException(
                    TextUtils.formatSimple("%s is not installed.", ps.getPackageName()));
        }
    }

    /**
    /**
     * Returns true if the app is archivable.
     * Returns true if the app is archivable.
     */
     */
@@ -519,11 +528,11 @@ public class PackageArchiver {
    /**
    /**
     * Returns true if user has opted the app out of archiving through system settings.
     * Returns true if user has opted the app out of archiving through system settings.
     */
     */
    // TODO(b/304256918) Switch this to a separate OP code for archiving.
    private boolean isAppOptedOutOfArchiving(String packageName, int uid) {
    private boolean isAppOptedOutOfArchiving(String packageName, int uid) {
        return Binder.withCleanCallingIdentity(() ->
        return Binder.withCleanCallingIdentity(() ->
                getAppOpsManager().checkOp(AppOpsManager.OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED,
                getAppOpsManager().checkOpNoThrow(
                        uid, packageName) == MODE_IGNORED);
                        AppOpsManager.OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED, uid, packageName)
                        == MODE_IGNORED);
    }
    }


    private void verifyOptOutStatus(String packageName, int uid)
    private void verifyOptOutStatus(String packageName, int uid)
+2 −2
Original line number Original line Diff line number Diff line
@@ -345,7 +345,7 @@ public class PackageArchiverTest {


    @Test
    @Test
    public void archiveApp_appOptedOutOfArchiving() {
    public void archiveApp_appOptedOutOfArchiving() {
        when(mAppOpsManager.checkOp(
        when(mAppOpsManager.checkOpNoThrow(
                eq(AppOpsManager.OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED),
                eq(AppOpsManager.OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED),
                anyInt(), eq(PACKAGE))).thenReturn(MODE_IGNORED);
                anyInt(), eq(PACKAGE))).thenReturn(MODE_IGNORED);


@@ -432,7 +432,7 @@ public class PackageArchiverTest {
    @Test
    @Test
    public void isAppArchivable_appOptedOutOfArchiving()
    public void isAppArchivable_appOptedOutOfArchiving()
            throws PackageManager.NameNotFoundException {
            throws PackageManager.NameNotFoundException {
        when(mAppOpsManager.checkOp(
        when(mAppOpsManager.checkOpNoThrow(
                eq(AppOpsManager.OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED),
                eq(AppOpsManager.OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED),
                anyInt(), eq(PACKAGE))).thenReturn(MODE_IGNORED);
                anyInt(), eq(PACKAGE))).thenReturn(MODE_IGNORED);