diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index 96757bba510de..3f9629c81ff41 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -2216,9 +2216,7 @@ public class DevicePolicyManager { * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} */ public boolean resetPassword(String password, int flags) { - if (mParentInstance) { - throw new SecurityException("Reset password does not work across profiles."); - } + throwIfParentInstance("resetPassword"); if (mService != null) { try { return mService.resetPassword(password, flags); @@ -2355,6 +2353,7 @@ public class DevicePolicyManager { * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} */ public void wipeData(int flags) { + throwIfParentInstance("wipeData"); if (mService != null) { try { mService.wipeData(flags); @@ -2388,6 +2387,7 @@ public class DevicePolicyManager { */ public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, List exclusionList ) { + throwIfParentInstance("setGlobalProxy"); if (proxySpec == null) { throw new NullPointerException(); } @@ -2453,6 +2453,7 @@ public class DevicePolicyManager { */ public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo proxyInfo) { + throwIfParentInstance("setRecommendedGlobalProxy"); if (mService != null) { try { mService.setRecommendedGlobalProxy(admin, proxyInfo); @@ -2603,6 +2604,7 @@ public class DevicePolicyManager { * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE} */ public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { + throwIfParentInstance("setStorageEncryption"); if (mService != null) { try { return mService.setStorageEncryption(admin, encrypt); @@ -2623,6 +2625,7 @@ public class DevicePolicyManager { * @return true if the admin(s) are requesting encryption, false if not. */ public boolean getStorageEncryption(@Nullable ComponentName admin) { + throwIfParentInstance("getStorageEncryption"); if (mService != null) { try { return mService.getStorageEncryption(admin, myUserId()); @@ -2718,6 +2721,7 @@ public class DevicePolicyManager { * owner. */ public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { + throwIfParentInstance("installCaCert"); if (mService != null) { try { return mService.installCaCert(admin, certBuffer); @@ -2738,6 +2742,7 @@ public class DevicePolicyManager { * owner. */ public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { + throwIfParentInstance("uninstallCaCert"); if (mService != null) { try { final String alias = getCaCertAlias(certBuffer); @@ -2763,6 +2768,7 @@ public class DevicePolicyManager { */ public List getInstalledCaCerts(@Nullable ComponentName admin) { List certs = new ArrayList(); + throwIfParentInstance("getInstalledCaCerts"); if (mService != null) { try { mService.enforceCanManageCaCerts(admin); @@ -2791,6 +2797,7 @@ public class DevicePolicyManager { * owner. */ public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { + throwIfParentInstance("uninstallAllUserCaCerts"); if (mService != null) { try { mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases() @@ -2811,6 +2818,7 @@ public class DevicePolicyManager { * owner. */ public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { + throwIfParentInstance("hasCaCertInstalled"); if (mService != null) { try { mService.enforceCanManageCaCerts(admin); @@ -2879,6 +2887,7 @@ public class DevicePolicyManager { */ public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) { + throwIfParentInstance("installKeyPair"); try { final byte[] pemCert = Credentials.convertToPem(certs[0]); byte[] pemChain = null; @@ -2911,6 +2920,7 @@ public class DevicePolicyManager { * owner. */ public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { + throwIfParentInstance("removeKeyPair"); try { return mService.removeKeyPair(admin, alias); } catch (RemoteException e) { @@ -2951,6 +2961,7 @@ public class DevicePolicyManager { */ public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String installerPackage) throws SecurityException { + throwIfParentInstance("setCertInstallerPackage"); if (mService != null) { try { mService.setCertInstallerPackage(admin, installerPackage); @@ -2970,6 +2981,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or a profile owner. */ public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException { + throwIfParentInstance("getCertInstallerPackage"); if (mService != null) { try { return mService.getCertInstallerPackage(admin); @@ -3000,6 +3012,7 @@ public class DevicePolicyManager { */ public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage) throws NameNotFoundException, UnsupportedOperationException { + throwIfParentInstance("setAlwaysOnVpnPackage"); if (mService != null) { try { if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage)) { @@ -3021,6 +3034,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or a profile owner. */ public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { + throwIfParentInstance("getAlwaysOnVpnPackage"); if (mService != null) { try { return mService.getAlwaysOnVpnPackage(admin); @@ -3048,6 +3062,7 @@ public class DevicePolicyManager { * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}. */ public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { + throwIfParentInstance("setCameraDisabled"); if (mService != null) { try { mService.setCameraDisabled(admin, disabled); @@ -3064,6 +3079,7 @@ public class DevicePolicyManager { * have disabled the camera */ public boolean getCameraDisabled(@Nullable ComponentName admin) { + throwIfParentInstance("getCameraDisabled"); return getCameraDisabled(admin, myUserId()); } @@ -3093,6 +3109,7 @@ public class DevicePolicyManager { * than the one managed by the device owner. */ public boolean requestBugreport(@NonNull ComponentName admin) { + throwIfParentInstance("requestBugreport"); if (mService != null) { try { return mService.requestBugreport(admin); @@ -3131,6 +3148,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { + throwIfParentInstance("setScreenCaptureDisabled"); if (mService != null) { try { mService.setScreenCaptureDisabled(admin, disabled); @@ -3147,6 +3165,7 @@ public class DevicePolicyManager { * have disabled screen capture. */ public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { + throwIfParentInstance("getScreenCaptureDisabled"); return getScreenCaptureDisabled(admin, myUserId()); } @@ -3176,6 +3195,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device owner. */ public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { + throwIfParentInstance("setAutoTimeRequired"); if (mService != null) { try { mService.setAutoTimeRequired(admin, required); @@ -3189,6 +3209,7 @@ public class DevicePolicyManager { * @return true if auto time is required. */ public boolean getAutoTimeRequired() { + throwIfParentInstance("getAutoTimeRequired"); if (mService != null) { try { return mService.getAutoTimeRequired(); @@ -3215,6 +3236,7 @@ public class DevicePolicyManager { */ public void setForceEphemeralUsers( @NonNull ComponentName admin, boolean forceEphemeralUsers) { + throwIfParentInstance("setForceEphemeralUsers"); if (mService != null) { try { mService.setForceEphemeralUsers(admin, forceEphemeralUsers); @@ -3230,6 +3252,7 @@ public class DevicePolicyManager { * @hide */ public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { + throwIfParentInstance("getForceEphemeralUsers"); if (mService != null) { try { return mService.getForceEphemeralUsers(admin); @@ -3517,6 +3540,7 @@ public class DevicePolicyManager { * @return whether or not the package is registered as the device owner app. */ public boolean isDeviceOwnerApp(String packageName) { + throwIfParentInstance("isDeviceOwnerApp"); return isDeviceOwnerAppOnCallingUser(packageName); } @@ -3614,6 +3638,7 @@ public class DevicePolicyManager { * does not own the current device owner component. */ public void clearDeviceOwnerApp(String packageName) { + throwIfParentInstance("clearDeviceOwnerApp"); if (mService != null) { try { mService.clearDeviceOwner(packageName); @@ -3731,6 +3756,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not an active profile owner. */ public void clearProfileOwner(@NonNull ComponentName admin) { + throwIfParentInstance("clearProfileOwner"); if (mService != null) { try { mService.clearProfileOwner(admin); @@ -3804,6 +3830,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device owner. */ public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) { + throwIfParentInstance("setDeviceOwnerLockScreenInfo"); if (mService != null) { try { mService.setDeviceOwnerLockScreenInfo(admin, info); @@ -3817,6 +3844,7 @@ public class DevicePolicyManager { * @return The device owner information. If it is not set returns {@code null}. */ public CharSequence getDeviceOwnerLockScreenInfo() { + throwIfParentInstance("getDeviceOwnerLockScreenInfo"); if (mService != null) { try { return mService.getDeviceOwnerLockScreenInfo(); @@ -3848,6 +3876,7 @@ public class DevicePolicyManager { */ public String[] setPackagesSuspended(@NonNull ComponentName admin, String[] packageNames, boolean suspended) { + throwIfParentInstance("setPackagesSuspended"); if (mService != null) { try { return mService.setPackagesSuspended(admin, packageNames, suspended); @@ -3870,6 +3899,7 @@ public class DevicePolicyManager { */ public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName) throws NameNotFoundException { + throwIfParentInstance("isPackageSuspended"); if (mService != null) { try { return mService.isPackageSuspended(admin, packageName); @@ -3891,6 +3921,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a profile owner. */ public void setProfileEnabled(@NonNull ComponentName admin) { + throwIfParentInstance("setProfileEnabled"); if (mService != null) { try { mService.setProfileEnabled(admin); @@ -3912,6 +3943,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public void setProfileName(@NonNull ComponentName admin, String profileName) { + throwIfParentInstance("setProfileName"); if (mService != null) { try { mService.setProfileName(admin, profileName); @@ -3930,6 +3962,7 @@ public class DevicePolicyManager { * @return Whether or not the package is registered as the profile owner. */ public boolean isProfileOwnerApp(String packageName) { + throwIfParentInstance("isProfileOwnerApp"); if (mService != null) { try { ComponentName profileOwner = mService.getProfileOwner(myUserId()); @@ -4024,6 +4057,7 @@ public class DevicePolicyManager { */ public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, @NonNull ComponentName activity) { + throwIfParentInstance("addPersistentPreferredActivity"); if (mService != null) { try { mService.addPersistentPreferredActivity(admin, filter, activity); @@ -4046,6 +4080,7 @@ public class DevicePolicyManager { */ public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, String packageName) { + throwIfParentInstance("clearPackagePersistentPreferredActivities"); if (mService != null) { try { mService.clearPackagePersistentPreferredActivities(admin, packageName); @@ -4074,6 +4109,7 @@ public class DevicePolicyManager { */ public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, @Nullable String packageName) throws NameNotFoundException { + throwIfParentInstance("setApplicationRestrictionsManagingPackage"); if (mService != null) { try { if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) { @@ -4095,6 +4131,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) { + throwIfParentInstance("getApplicationRestrictionsManagingPackage"); if (mService != null) { try { return mService.getApplicationRestrictionsManagingPackage(admin); @@ -4114,6 +4151,7 @@ public class DevicePolicyManager { * that method. */ public boolean isCallerApplicationRestrictionsManagingPackage() { + throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage"); if (mService != null) { try { return mService.isCallerApplicationRestrictionsManagingPackage(); @@ -4159,6 +4197,7 @@ public class DevicePolicyManager { */ public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, Bundle settings) { + throwIfParentInstance("setApplicationRestrictions"); if (mService != null) { try { mService.setApplicationRestrictions(admin, packageName, settings); @@ -4257,6 +4296,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { + throwIfParentInstance("setCrossProfileCallerIdDisabled"); if (mService != null) { try { mService.setCrossProfileCallerIdDisabled(admin, disabled); @@ -4277,6 +4317,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { + throwIfParentInstance("getCrossProfileCallerIdDisabled"); if (mService != null) { try { return mService.getCrossProfileCallerIdDisabled(admin); @@ -4317,6 +4358,7 @@ public class DevicePolicyManager { */ public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, boolean disabled) { + throwIfParentInstance("setCrossProfileContactsSearchDisabled"); if (mService != null) { try { mService.setCrossProfileContactsSearchDisabled(admin, disabled); @@ -4337,6 +4379,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { + throwIfParentInstance("getCrossProfileContactsSearchDisabled"); if (mService != null) { try { return mService.getCrossProfileContactsSearchDisabled(admin); @@ -4407,6 +4450,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { + throwIfParentInstance("setBluetoothContactSharingDisabled"); if (mService != null) { try { mService.setBluetoothContactSharingDisabled(admin, disabled); @@ -4429,6 +4473,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { + throwIfParentInstance("getBluetoothContactSharingDisabled"); if (mService != null) { try { return mService.getBluetoothContactSharingDisabled(admin); @@ -4472,6 +4517,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { + throwIfParentInstance("addCrossProfileIntentFilter"); if (mService != null) { try { mService.addCrossProfileIntentFilter(admin, filter, flags); @@ -4490,6 +4536,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { + throwIfParentInstance("clearCrossProfileIntentFilters"); if (mService != null) { try { mService.clearCrossProfileIntentFilters(admin); @@ -4519,6 +4566,7 @@ public class DevicePolicyManager { */ public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, List packageNames) { + throwIfParentInstance("setPermittedAccessibilityServices"); if (mService != null) { try { return mService.setPermittedAccessibilityServices(admin, packageNames); @@ -4540,6 +4588,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public List getPermittedAccessibilityServices(@NonNull ComponentName admin) { + throwIfParentInstance("getPermittedAccessibilityServices"); if (mService != null) { try { return mService.getPermittedAccessibilityServices(admin); @@ -4617,6 +4666,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public boolean setPermittedInputMethods(@NonNull ComponentName admin, List packageNames) { + throwIfParentInstance("setPermittedInputMethods"); if (mService != null) { try { return mService.setPermittedInputMethods(admin, packageNames); @@ -4639,6 +4689,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public List getPermittedInputMethods(@NonNull ComponentName admin) { + throwIfParentInstance("getPermittedInputMethods"); if (mService != null) { try { return mService.getPermittedInputMethods(admin); @@ -4834,6 +4885,7 @@ public class DevicePolicyManager { public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name, @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, int flags) { + throwIfParentInstance("createAndManageUser"); try { return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); } catch (RemoteException re) { @@ -4851,6 +4903,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device owner. */ public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { + throwIfParentInstance("removeUser"); try { return mService.removeUser(admin, userHandle); } catch (RemoteException re) { @@ -4868,6 +4921,7 @@ public class DevicePolicyManager { * @see Intent#ACTION_USER_FOREGROUND */ public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { + throwIfParentInstance("switchUser"); try { return mService.switchUser(admin, userHandle); } catch (RemoteException re) { @@ -4893,6 +4947,7 @@ public class DevicePolicyManager { * @see {@link #setApplicationRestrictionsManagingPackage} */ public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) { + throwIfParentInstance("getApplicationRestrictions"); if (mService != null) { try { return mService.getApplicationRestrictions(admin, packageName); @@ -4915,6 +4970,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public void addUserRestriction(@NonNull ComponentName admin, String key) { + throwIfParentInstance("addUserRestriction"); if (mService != null) { try { mService.setUserRestriction(admin, key, true); @@ -4936,6 +4992,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public void clearUserRestriction(@NonNull ComponentName admin, String key) { + throwIfParentInstance("clearUserRestriction"); if (mService != null) { try { mService.setUserRestriction(admin, key, false); @@ -4957,6 +5014,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public Bundle getUserRestrictions(@NonNull ComponentName admin) { + throwIfParentInstance("getUserRestrictions"); Bundle ret = null; if (mService != null) { try { @@ -5001,6 +5059,7 @@ public class DevicePolicyManager { */ public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, boolean hidden) { + throwIfParentInstance("setApplicationHidden"); if (mService != null) { try { return mService.setApplicationHidden(admin, packageName, hidden); @@ -5020,6 +5079,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { + throwIfParentInstance("isApplicationHidden"); if (mService != null) { try { return mService.isApplicationHidden(admin, packageName); @@ -5039,6 +5099,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public void enableSystemApp(@NonNull ComponentName admin, String packageName) { + throwIfParentInstance("enableSystemApp"); if (mService != null) { try { mService.enableSystemApp(admin, packageName); @@ -5059,6 +5120,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { + throwIfParentInstance("enableSystemApp"); if (mService != null) { try { return mService.enableSystemAppWithIntent(admin, intent); @@ -5091,6 +5153,7 @@ public class DevicePolicyManager { */ public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, boolean disabled) { + throwIfParentInstance("setAccountManagementDisabled"); if (mService != null) { try { mService.setAccountManagementDisabled(admin, accountType, disabled); @@ -5111,6 +5174,7 @@ public class DevicePolicyManager { * @see #setAccountManagementDisabled */ public String[] getAccountTypesWithManagementDisabled() { + throwIfParentInstance("getAccountTypesWithManagementDisabled"); return getAccountTypesWithManagementDisabledAsUser(myUserId()); } @@ -5148,6 +5212,7 @@ public class DevicePolicyManager { */ public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages) throws SecurityException { + throwIfParentInstance("setLockTaskPackages"); if (mService != null) { try { mService.setLockTaskPackages(admin, packages); @@ -5164,6 +5229,7 @@ public class DevicePolicyManager { * @hide */ public String[] getLockTaskPackages(@NonNull ComponentName admin) { + throwIfParentInstance("getLockTaskPackages"); if (mService != null) { try { return mService.getLockTaskPackages(admin); @@ -5180,6 +5246,7 @@ public class DevicePolicyManager { * @param pkg The package to check */ public boolean isLockTaskPermitted(String pkg) { + throwIfParentInstance("isLockTaskPermitted"); if (mService != null) { try { return mService.isLockTaskPermitted(pkg); @@ -5228,6 +5295,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device owner. */ public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { + throwIfParentInstance("setGlobalSetting"); if (mService != null) { try { mService.setGlobalSetting(admin, setting, value); @@ -5260,6 +5328,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { + throwIfParentInstance("setSecureSetting"); if (mService != null) { try { mService.setSecureSetting(admin, setting, value); @@ -5283,6 +5352,7 @@ public class DevicePolicyManager { */ public void setRestrictionsProvider(@NonNull ComponentName admin, @Nullable ComponentName provider) { + throwIfParentInstance("setRestrictionsProvider"); if (mService != null) { try { mService.setRestrictionsProvider(admin, provider); @@ -5300,6 +5370,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { + throwIfParentInstance("setMasterVolumeMuted"); if (mService != null) { try { mService.setMasterVolumeMuted(admin, on); @@ -5317,6 +5388,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { + throwIfParentInstance("isMasterVolumeMuted"); if (mService != null) { try { return mService.isMasterVolumeMuted(admin); @@ -5337,6 +5409,7 @@ public class DevicePolicyManager { */ public void setUninstallBlocked(@NonNull ComponentName admin, String packageName, boolean uninstallBlocked) { + throwIfParentInstance("setUninstallBlocked"); if (mService != null) { try { mService.setUninstallBlocked(admin, packageName, uninstallBlocked); @@ -5362,6 +5435,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { + throwIfParentInstance("isUninstallBlocked"); if (mService != null) { try { return mService.isUninstallBlocked(admin, packageName); @@ -5389,6 +5463,7 @@ public class DevicePolicyManager { * @see #getCrossProfileWidgetProviders(android.content.ComponentName) */ public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { + throwIfParentInstance("addCrossProfileWidgetProvider"); if (mService != null) { try { return mService.addCrossProfileWidgetProvider(admin, packageName); @@ -5416,6 +5491,7 @@ public class DevicePolicyManager { */ public boolean removeCrossProfileWidgetProvider( @NonNull ComponentName admin, String packageName) { + throwIfParentInstance("removeCrossProfileWidgetProvider"); if (mService != null) { try { return mService.removeCrossProfileWidgetProvider(admin, packageName); @@ -5437,6 +5513,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a profile owner. */ public List getCrossProfileWidgetProviders(@NonNull ComponentName admin) { + throwIfParentInstance("getCrossProfileWidgetProviders"); if (mService != null) { try { List providers = mService.getCrossProfileWidgetProviders(admin); @@ -5458,6 +5535,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device or profile owner. */ public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { + throwIfParentInstance("setUserIcon"); try { mService.setUserIcon(admin, icon); } catch (RemoteException re) { @@ -5477,6 +5555,7 @@ public class DevicePolicyManager { * @see SystemUpdatePolicy */ public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { + throwIfParentInstance("setSystemUpdatePolicy"); if (mService != null) { try { mService.setSystemUpdatePolicy(admin, policy); @@ -5492,6 +5571,7 @@ public class DevicePolicyManager { * @return The current policy object, or {@code null} if no policy is set. */ public SystemUpdatePolicy getSystemUpdatePolicy() { + throwIfParentInstance("getSystemUpdatePolicy"); if (mService != null) { try { return mService.getSystemUpdatePolicy(); @@ -5517,6 +5597,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device owner. */ public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { + throwIfParentInstance("setKeyguardDisabled"); try { return mService.setKeyguardDisabled(admin, disabled); } catch (RemoteException re) { @@ -5535,6 +5616,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device owner. */ public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { + throwIfParentInstance("setStatusBarDisabled"); try { return mService.setStatusBarDisabled(admin, disabled); } catch (RemoteException re) { @@ -5580,6 +5662,7 @@ public class DevicePolicyManager { * @see #setPermissionGrantState */ public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { + throwIfParentInstance("setPermissionPolicy"); try { mService.setPermissionPolicy(admin, policy); } catch (RemoteException re) { @@ -5594,6 +5677,7 @@ public class DevicePolicyManager { * @return the current policy for future permission requests. */ public int getPermissionPolicy(ComponentName admin) { + throwIfParentInstance("getPermissionPolicy"); try { return mService.getPermissionPolicy(admin); } catch (RemoteException re) { @@ -5630,6 +5714,7 @@ public class DevicePolicyManager { */ public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, String permission, int grantState) { + throwIfParentInstance("setPermissionGrantState"); try { return mService.setPermissionGrantState(admin, packageName, permission, grantState); } catch (RemoteException re) { @@ -5658,6 +5743,7 @@ public class DevicePolicyManager { */ public int getPermissionGrantState(@NonNull ComponentName admin, String packageName, String permission) { + throwIfParentInstance("getPermissionGrantState"); try { return mService.getPermissionGrantState(admin, packageName, permission); } catch (RemoteException re) { @@ -5673,6 +5759,7 @@ public class DevicePolicyManager { * @throws IllegalArgumentException if the supplied action is not valid. */ public boolean isProvisioningAllowed(String action) { + throwIfParentInstance("isProvisioningAllowed"); try { return mService.isProvisioningAllowed(action); } catch (RemoteException re) { @@ -5688,6 +5775,7 @@ public class DevicePolicyManager { * @return if this user is a managed profile of another user. */ public boolean isManagedProfile(@NonNull ComponentName admin) { + throwIfParentInstance("isManagedProfile"); try { return mService.isManagedProfile(admin); } catch (RemoteException re) { @@ -5721,6 +5809,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device owner. */ public String getWifiMacAddress(@NonNull ComponentName admin) { + throwIfParentInstance("getWifiMacAddress"); try { return mService.getWifiMacAddress(admin); } catch (RemoteException re) { @@ -5737,6 +5826,7 @@ public class DevicePolicyManager { * @see TelephonyManager#CALL_STATE_IDLE */ public void reboot(@NonNull ComponentName admin) { + throwIfParentInstance("reboot"); try { mService.reboot(admin); } catch (RemoteException re) { @@ -5763,6 +5853,7 @@ public class DevicePolicyManager { */ public void setShortSupportMessage(@NonNull ComponentName admin, @Nullable String message) { + throwIfParentInstance("setShortSupportMessage"); if (mService != null) { try { mService.setShortSupportMessage(admin, message); @@ -5781,6 +5872,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not an active administrator. */ public String getShortSupportMessage(@NonNull ComponentName admin) { + throwIfParentInstance("getShortSupportMessage"); if (mService != null) { try { return mService.getShortSupportMessage(admin); @@ -5807,6 +5899,7 @@ public class DevicePolicyManager { */ public void setLongSupportMessage(@NonNull ComponentName admin, @Nullable String message) { + throwIfParentInstance("setLongSupportMessage"); if (mService != null) { try { mService.setLongSupportMessage(admin, message); @@ -5825,6 +5918,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not an active administrator. */ public String getLongSupportMessage(@NonNull ComponentName admin) { + throwIfParentInstance("getLongSupportMessage"); if (mService != null) { try { return mService.getLongSupportMessage(admin); @@ -5921,6 +6015,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a profile owner. */ public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { + throwIfParentInstance("getParentProfileInstance"); try { if (!mService.isManagedProfile(admin)) { throw new SecurityException("The current user does not have a parent profile."); @@ -5947,6 +6042,7 @@ public class DevicePolicyManager { * @see #retrieveSecurityLogs */ public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { + throwIfParentInstance("setSecurityLoggingEnabled"); try { mService.setSecurityLoggingEnabled(admin, enabled); } catch (RemoteException re) { @@ -5965,6 +6061,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device owner. */ public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) { + throwIfParentInstance("isSecurityLoggingEnabled"); try { return mService.isSecurityLoggingEnabled(admin); } catch (RemoteException re) { @@ -5988,6 +6085,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device owner. */ public List retrieveSecurityLogs(@NonNull ComponentName admin) { + throwIfParentInstance("retrieveSecurityLogs"); try { ParceledListSlice list = mService.retrieveSecurityLogs(admin); if (list != null) { @@ -6033,6 +6131,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a device owner. */ public List retrievePreRebootSecurityLogs(@NonNull ComponentName admin) { + throwIfParentInstance("retrievePreRebootSecurityLogs"); try { ParceledListSlice list = mService.retrievePreRebootSecurityLogs(admin); return list.getList(); @@ -6054,6 +6153,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a profile owner. */ public void setOrganizationColor(@NonNull ComponentName admin, int color) { + throwIfParentInstance("setOrganizationColor"); try { mService.setOrganizationColor(admin, color); } catch (RemoteException re) { @@ -6089,6 +6189,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a profile owner. */ public int getOrganizationColor(@NonNull ComponentName admin) { + throwIfParentInstance("getOrganizationColor"); try { return mService.getOrganizationColor(admin); } catch (RemoteException re) { @@ -6124,6 +6225,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a profile owner. */ public void setOrganizationName(@NonNull ComponentName admin, @Nullable String title) { + throwIfParentInstance("setOrganizationName"); try { mService.setOrganizationName(admin, title); } catch (RemoteException re) { @@ -6140,6 +6242,7 @@ public class DevicePolicyManager { * @throws SecurityException if {@code admin} is not a profile owner. */ public String getOrganizationName(@NonNull ComponentName admin) { + throwIfParentInstance("getOrganizationName"); try { return mService.getOrganizationName(admin); } catch (RemoteException re) { @@ -6265,4 +6368,10 @@ public class DevicePolicyManager { throw re.rethrowFromSystemServer(); } } + + private void throwIfParentInstance(String functionName) { + if (mParentInstance) { + throw new SecurityException(functionName + " cannot be called on the parent instance"); + } + } }