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

Commit 6ceba535 authored by Jakob Schneider's avatar Jakob Schneider
Browse files

Fix crash that happens if you call archive twice.

Also remove outdated TODO: We'll re-use the existing OP_CODE because
it's bad practice to have 2 OP_CODES that are controlled by the same
switch in settings. If they ever become out of sync the UI cannot handle
the state.

Bug: 314770049
Test: verified fix manually
Change-Id: I6a658a4c583c951795daf1f9a2cd9e7d26c3f44a
parent d31ed40a
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
@@ -343,7 +343,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);


@@ -430,7 +430,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);