Loading services/core/java/com/android/server/pm/PackageArchiver.java +12 −3 Original line number Original line Diff line number Diff line Loading @@ -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( Loading Loading @@ -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. */ */ Loading Loading @@ -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) Loading services/tests/mockingservicestests/src/com/android/server/pm/PackageArchiverTest.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -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); Loading Loading @@ -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); Loading Loading
services/core/java/com/android/server/pm/PackageArchiver.java +12 −3 Original line number Original line Diff line number Diff line Loading @@ -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( Loading Loading @@ -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. */ */ Loading Loading @@ -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) Loading
services/tests/mockingservicestests/src/com/android/server/pm/PackageArchiverTest.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -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); Loading Loading @@ -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); Loading