Loading core/java/android/app/admin/DevicePolicyManager.java +14 −7 Original line number Diff line number Diff line Loading @@ -7028,21 +7028,28 @@ public class DevicePolicyManager { } /** * Called by a device owner to set the default SMS application. * Must be called by a device owner or a profile owner of an organization-owned managed profile * to set the default SMS application. * <p> * The calling device admin must be a device owner. If it is not, a security exception will be * thrown. * This method can be called on the {@link DevicePolicyManager} instance, returned by * {@link #getParentProfileInstance(ComponentName)}, where the caller must be the profile owner * of an organization-owned managed profile and the package must be a pre-installed system * package. If called on the parent instance, then the default SMS application is set on the * personal profile. * * @param admin Which {@link DeviceAdminReceiver} this request is associated with. * @param packageName The name of the package to set as the default SMS application. * @throws SecurityException if {@code admin} is not a device owner. * @throws SecurityException if {@code admin} is not a device or profile owner or if * called on the parent profile and the {@code admin} is not a * profile owner of an organization-owned managed profile. * @throws IllegalArgumentException if called on the parent profile and the package * provided is not a pre-installed system package. */ public void setDefaultSmsApplication(@NonNull ComponentName admin, @NonNull String packageName) { throwIfParentInstance("setDefaultSmsApplication"); if (mService != null) { try { mService.setDefaultSmsApplication(admin, packageName); mService.setDefaultSmsApplication(admin, packageName, mParentInstance); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading core/java/android/app/admin/IDevicePolicyManager.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -202,7 +202,7 @@ interface IDevicePolicyManager { void addPersistentPreferredActivity(in ComponentName admin, in IntentFilter filter, in ComponentName activity); void clearPackagePersistentPreferredActivities(in ComponentName admin, String packageName); void setDefaultSmsApplication(in ComponentName admin, String packageName); void setDefaultSmsApplication(in ComponentName admin, String packageName, boolean parent); void setApplicationRestrictions(in ComponentName who, in String callerPackage, in String packageName, in Bundle settings); Bundle getApplicationRestrictions(in ComponentName who, in String callerPackage, in String packageName); Loading services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +16 −13 Original line number Diff line number Diff line Loading @@ -9553,9 +9553,19 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } @Override public void setDefaultSmsApplication(ComponentName admin, String packageName) { public void setDefaultSmsApplication(ComponentName admin, String packageName, boolean parent) { Objects.requireNonNull(admin, "ComponentName is null"); if (parent) { ActiveAdmin ap = getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_ORGANIZATION_OWNED_PROFILE_OWNER, parent); enforceProfileOwnerOfOrganizationOwnedDevice(ap); mInjector.binderWithCleanCallingIdentity(() -> enforcePackageIsSystemPackage( packageName, getProfileParentId(mInjector.userHandleGetCallingUserId()))); } else { enforceDeviceOwner(admin); } mInjector.binderWithCleanCallingIdentity(() -> SmsApplication.setDefaultApplication(packageName, mContext)); } Loading Loading @@ -10778,7 +10788,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { // API cannot be used to leak if certain non-system package exists in the person // profile. mInjector.binderWithCleanCallingIdentity(() -> enforcePackageIsSystemPackage(packageName, hidden, userId)); enforcePackageIsSystemPackage(packageName, userId)); } result = mInjector.binderWithCleanCallingIdentity(() -> mIPackageManager Loading Loading @@ -10811,7 +10821,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { DeviceAdminInfo.USES_POLICY_ORGANIZATION_OWNED_PROFILE_OWNER, parent); // Ensure the package provided is a system package. mInjector.binderWithCleanCallingIdentity(() -> enforcePackageIsSystemPackage(packageName, false, userId)); enforcePackageIsSystemPackage(packageName, userId)); } return mInjector.binderWithCleanCallingIdentity( Loading @@ -10819,16 +10829,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } } private void enforcePackageIsSystemPackage(String packageName, boolean hidden, int userId) private void enforcePackageIsSystemPackage(String packageName, int userId) throws RemoteException { int flags = PackageManager.MATCH_SYSTEM_ONLY; // If the package is currently hidden then it is considered uninstalled and // the MATCH_UNINSTALLED_PACKAGES flag has to be added. if (!hidden) { flags |= PackageManager.MATCH_UNINSTALLED_PACKAGES; } PackageInfo packageInfo = mIPackageManager.getPackageInfo(packageName, flags, userId); if (packageInfo == null || !packageInfo.applicationInfo.isSystemApp()) { if (!isSystemApp(mIPackageManager, packageName, userId)) { throw new IllegalArgumentException( "The provided package is not a system package"); } Loading services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +5 −9 Original line number Diff line number Diff line Loading @@ -2223,17 +2223,13 @@ public class DevicePolicyManagerTest extends DpmTestBase { String packageName = "com.google.android.test"; PackageInfo packageInfo = new PackageInfo(); packageInfo.applicationInfo = new ApplicationInfo(); packageInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM; ApplicationInfo applicationInfo = new ApplicationInfo(); applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM; when(getServices().userManager.getProfileParent(MANAGED_PROFILE_USER_ID)) .thenReturn(new UserInfo(UserHandle.USER_SYSTEM, "user system", 0)); when(getServices().ipackageManager.getPackageInfo(packageName, PackageManager.MATCH_SYSTEM_ONLY, UserHandle.USER_SYSTEM)).thenReturn( packageInfo); when(getServices().ipackageManager.getPackageInfo(packageName, PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.MATCH_SYSTEM_ONLY, UserHandle.USER_SYSTEM)).thenReturn(packageInfo); when(getServices().ipackageManager.getApplicationInfo(packageName, PackageManager.MATCH_UNINSTALLED_PACKAGES, UserHandle.USER_SYSTEM)).thenReturn( applicationInfo); parentDpm.setApplicationHidden(admin1, packageName, true); verify(getServices().ipackageManager).setApplicationHiddenSettingAsUser(packageName, Loading Loading
core/java/android/app/admin/DevicePolicyManager.java +14 −7 Original line number Diff line number Diff line Loading @@ -7028,21 +7028,28 @@ public class DevicePolicyManager { } /** * Called by a device owner to set the default SMS application. * Must be called by a device owner or a profile owner of an organization-owned managed profile * to set the default SMS application. * <p> * The calling device admin must be a device owner. If it is not, a security exception will be * thrown. * This method can be called on the {@link DevicePolicyManager} instance, returned by * {@link #getParentProfileInstance(ComponentName)}, where the caller must be the profile owner * of an organization-owned managed profile and the package must be a pre-installed system * package. If called on the parent instance, then the default SMS application is set on the * personal profile. * * @param admin Which {@link DeviceAdminReceiver} this request is associated with. * @param packageName The name of the package to set as the default SMS application. * @throws SecurityException if {@code admin} is not a device owner. * @throws SecurityException if {@code admin} is not a device or profile owner or if * called on the parent profile and the {@code admin} is not a * profile owner of an organization-owned managed profile. * @throws IllegalArgumentException if called on the parent profile and the package * provided is not a pre-installed system package. */ public void setDefaultSmsApplication(@NonNull ComponentName admin, @NonNull String packageName) { throwIfParentInstance("setDefaultSmsApplication"); if (mService != null) { try { mService.setDefaultSmsApplication(admin, packageName); mService.setDefaultSmsApplication(admin, packageName, mParentInstance); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading
core/java/android/app/admin/IDevicePolicyManager.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -202,7 +202,7 @@ interface IDevicePolicyManager { void addPersistentPreferredActivity(in ComponentName admin, in IntentFilter filter, in ComponentName activity); void clearPackagePersistentPreferredActivities(in ComponentName admin, String packageName); void setDefaultSmsApplication(in ComponentName admin, String packageName); void setDefaultSmsApplication(in ComponentName admin, String packageName, boolean parent); void setApplicationRestrictions(in ComponentName who, in String callerPackage, in String packageName, in Bundle settings); Bundle getApplicationRestrictions(in ComponentName who, in String callerPackage, in String packageName); Loading
services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +16 −13 Original line number Diff line number Diff line Loading @@ -9553,9 +9553,19 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } @Override public void setDefaultSmsApplication(ComponentName admin, String packageName) { public void setDefaultSmsApplication(ComponentName admin, String packageName, boolean parent) { Objects.requireNonNull(admin, "ComponentName is null"); if (parent) { ActiveAdmin ap = getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_ORGANIZATION_OWNED_PROFILE_OWNER, parent); enforceProfileOwnerOfOrganizationOwnedDevice(ap); mInjector.binderWithCleanCallingIdentity(() -> enforcePackageIsSystemPackage( packageName, getProfileParentId(mInjector.userHandleGetCallingUserId()))); } else { enforceDeviceOwner(admin); } mInjector.binderWithCleanCallingIdentity(() -> SmsApplication.setDefaultApplication(packageName, mContext)); } Loading Loading @@ -10778,7 +10788,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { // API cannot be used to leak if certain non-system package exists in the person // profile. mInjector.binderWithCleanCallingIdentity(() -> enforcePackageIsSystemPackage(packageName, hidden, userId)); enforcePackageIsSystemPackage(packageName, userId)); } result = mInjector.binderWithCleanCallingIdentity(() -> mIPackageManager Loading Loading @@ -10811,7 +10821,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { DeviceAdminInfo.USES_POLICY_ORGANIZATION_OWNED_PROFILE_OWNER, parent); // Ensure the package provided is a system package. mInjector.binderWithCleanCallingIdentity(() -> enforcePackageIsSystemPackage(packageName, false, userId)); enforcePackageIsSystemPackage(packageName, userId)); } return mInjector.binderWithCleanCallingIdentity( Loading @@ -10819,16 +10829,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } } private void enforcePackageIsSystemPackage(String packageName, boolean hidden, int userId) private void enforcePackageIsSystemPackage(String packageName, int userId) throws RemoteException { int flags = PackageManager.MATCH_SYSTEM_ONLY; // If the package is currently hidden then it is considered uninstalled and // the MATCH_UNINSTALLED_PACKAGES flag has to be added. if (!hidden) { flags |= PackageManager.MATCH_UNINSTALLED_PACKAGES; } PackageInfo packageInfo = mIPackageManager.getPackageInfo(packageName, flags, userId); if (packageInfo == null || !packageInfo.applicationInfo.isSystemApp()) { if (!isSystemApp(mIPackageManager, packageName, userId)) { throw new IllegalArgumentException( "The provided package is not a system package"); } Loading
services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +5 −9 Original line number Diff line number Diff line Loading @@ -2223,17 +2223,13 @@ public class DevicePolicyManagerTest extends DpmTestBase { String packageName = "com.google.android.test"; PackageInfo packageInfo = new PackageInfo(); packageInfo.applicationInfo = new ApplicationInfo(); packageInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM; ApplicationInfo applicationInfo = new ApplicationInfo(); applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM; when(getServices().userManager.getProfileParent(MANAGED_PROFILE_USER_ID)) .thenReturn(new UserInfo(UserHandle.USER_SYSTEM, "user system", 0)); when(getServices().ipackageManager.getPackageInfo(packageName, PackageManager.MATCH_SYSTEM_ONLY, UserHandle.USER_SYSTEM)).thenReturn( packageInfo); when(getServices().ipackageManager.getPackageInfo(packageName, PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.MATCH_SYSTEM_ONLY, UserHandle.USER_SYSTEM)).thenReturn(packageInfo); when(getServices().ipackageManager.getApplicationInfo(packageName, PackageManager.MATCH_UNINSTALLED_PACKAGES, UserHandle.USER_SYSTEM)).thenReturn( applicationInfo); parentDpm.setApplicationHidden(admin1, packageName, true); verify(getServices().ipackageManager).setApplicationHiddenSettingAsUser(packageName, Loading