diff options
author | Fyodor Kupolov <fkupolov@google.com> | 2015-02-19 22:53:24 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-02-19 22:53:26 +0000 |
commit | fcc87275e3f6e6e84ca0677e3422c602686eef36 (patch) | |
tree | 427648f7e03071a52ec7ebfd000778aa6dbb28c1 /services/devicepolicy | |
parent | 96fb6d811fef5cd88aab2ede4712abe2b6b14075 (diff) | |
parent | 22029f0a50f8bb08902054123153a215906483d5 (diff) | |
download | frameworks_base-fcc87275e3f6e6e84ca0677e3422c602686eef36.zip frameworks_base-fcc87275e3f6e6e84ca0677e3422c602686eef36.tar.gz frameworks_base-fcc87275e3f6e6e84ca0677e3422c602686eef36.tar.bz2 |
Merge "Code cleanup"
Diffstat (limited to 'services/devicepolicy')
-rw-r--r-- | services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java | 240 |
1 files changed, 58 insertions, 182 deletions
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 7ff7827..8170835 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -100,6 +100,7 @@ import com.android.internal.R; import com.android.internal.os.storage.ExternalStorageFormatter; import com.android.internal.util.FastXmlSerializer; import com.android.internal.util.JournaledFile; +import com.android.internal.util.Preconditions; import com.android.internal.util.XmlUtils; import com.android.internal.widget.LockPatternUtils; import com.android.server.LocalServices; @@ -1920,13 +1921,11 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); validateQualityConstant(quality); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } ActiveAdmin ap = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); if (ap.passwordQuality != quality) { @@ -1969,11 +1968,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } ActiveAdmin ap = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); if (ap.minimumPasswordLength != length) { @@ -2016,11 +2013,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } ActiveAdmin ap = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); if (ap.passwordHistoryLength != length) { @@ -2063,14 +2058,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(who, "ComponentName is null"); + Preconditions.checkArgumentNonnegative(timeout, "Timeout must be >= 0 ms"); final int userHandle = UserHandle.getCallingUserId(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } - if (timeout < 0) { - throw new IllegalArgumentException("Timeout must be >= 0 ms"); - } ActiveAdmin ap = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_EXPIRE_PASSWORD); // Calling this API automatically bumps the expiration date @@ -2232,11 +2223,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } ActiveAdmin ap = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); if (ap.minimumPasswordUpperCase != length) { @@ -2276,11 +2265,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } public void setPasswordMinimumLowerCase(ComponentName who, int length) { + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } ActiveAdmin ap = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); if (ap.minimumPasswordLowerCase != length) { @@ -2323,11 +2310,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } ActiveAdmin ap = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); if (ap.minimumPasswordLetters != length) { @@ -2370,11 +2355,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } ActiveAdmin ap = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); if (ap.minimumPasswordNumeric != length) { @@ -2417,11 +2400,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } ActiveAdmin ap = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); if (ap.minimumPasswordSymbols != length) { @@ -2464,11 +2445,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } ActiveAdmin ap = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); if (ap.minimumPasswordNonLetter != length) { @@ -2561,11 +2540,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } // This API can only be called by an active device admin, // so try to retrieve it to check that the caller is one. getActiveAdminForCallerLocked(who, @@ -2772,11 +2749,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } ActiveAdmin ap = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_FORCE_LOCK); if (ap.maximumTimeToUnlock != timeMs) { @@ -2955,9 +2930,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public boolean installKeyPair(ComponentName who, byte[] privKey, byte[] cert, String alias) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } + Preconditions.checkNotNull(who, "ComponentName is null"); synchronized (this) { getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); } @@ -3297,9 +3270,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { return null; } synchronized(this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } + Preconditions.checkNotNull(who, "ComponentName is null"); // Only check if owner has set global proxy. We don't allow other users to set it. DevicePolicyData policy = getUserData(UserHandle.USER_OWNER); @@ -3435,12 +3406,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED; } + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (this) { // Check for permissions - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } // Only owner can set storage encryption if (userHandle != UserHandle.USER_OWNER || UserHandle.getCallingUserId() != UserHandle.USER_OWNER) { @@ -3571,11 +3540,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } ActiveAdmin ap = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); if (ap.disableScreenCapture != disabled) { @@ -3630,11 +3597,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } ActiveAdmin admin = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER); if (admin.requireAutoTime != required) { @@ -3682,11 +3647,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } ActiveAdmin ap = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DISABLE_CAMERA); if (ap.disableCamera != disabled) { @@ -3731,12 +3694,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); enforceNotManagedProfile(userHandle, "disable keyguard features"); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } ActiveAdmin ap = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DISABLE_KEYGUARD_FEATURES); if (ap.disabledKeyguardFeatures != which) { @@ -3880,9 +3841,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public void clearDeviceOwner(String packageName) { - if (packageName == null) { - throw new NullPointerException("packageName is null"); - } + Preconditions.checkNotNull(packageName, "packageName is null"); try { int uid = mContext.getPackageManager().getPackageUid(packageName, 0); if (uid != Binder.getCallingUid()) { @@ -4007,12 +3966,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (this) { - // Check for permissions - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } // Check if this is the profile owner who is calling getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); int userId = UserHandle.getCallingUserId(); @@ -4034,12 +3990,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public void setProfileName(ComponentName who, String profileName) { + Preconditions.checkNotNull(who, "ComponentName is null"); int userId = UserHandle.getCallingUserId(); - - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } - // Check if this is the profile owner (includes device owner). getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -4215,12 +4167,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public void addPersistentPreferredActivity(ComponentName who, IntentFilter filter, ComponentName activity) { + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); - synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); IPackageManager pm = AppGlobals.getPackageManager(); @@ -4237,12 +4186,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public void clearPackagePersistentPreferredActivities(ComponentName who, String packageName) { + Preconditions.checkNotNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); - synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); IPackageManager pm = AppGlobals.getPackageManager(); @@ -4259,12 +4205,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public void setApplicationRestrictions(ComponentName who, String packageName, Bundle settings) { + Preconditions.checkNotNull(who, "ComponentName is null"); final UserHandle userHandle = new UserHandle(UserHandle.getCallingUserId()); - synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); long id = Binder.clearCallingIdentity(); @@ -4281,15 +4224,11 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(admin, "admin is null"); + Preconditions.checkNotNull(agent, "agent is null"); final int userHandle = UserHandle.getCallingUserId(); enforceNotManagedProfile(userHandle, "set trust agent configuration"); synchronized (this) { - if (admin == null) { - throw new NullPointerException("admin is null"); - } - if (agent == null) { - throw new NullPointerException("agent is null"); - } ActiveAdmin ap = getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_DISABLE_KEYGUARD_FEATURES); ap.trustAgentInfos.put(agent.flattenToString(), new TrustAgentInfo(args)); @@ -4303,10 +4242,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return null; } + Preconditions.checkNotNull(agent, "agent null"); enforceCrossUserPermission(userHandle); - if (agent == null) { - throw new NullPointerException("agent is null"); - } synchronized (this) { final String componentName = agent.flattenToString(); @@ -4359,10 +4296,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public void setRestrictionsProvider(ComponentName who, ComponentName permissionProvider) { + Preconditions.checkNotNull(who, "ComponentName is null"); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); int userHandle = UserHandle.getCallingUserId(); @@ -4384,11 +4319,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } public void addCrossProfileIntentFilter(ComponentName who, IntentFilter filter, int flags) { + Preconditions.checkNotNull(who, "ComponentName is null"); int callingUserId = UserHandle.getCallingUserId(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); IPackageManager pm = AppGlobals.getPackageManager(); @@ -4411,11 +4344,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } public void clearCrossProfileIntentFilters(ComponentName who) { + Preconditions.checkNotNull(who, "ComponentName is null"); int callingUserId = UserHandle.getCallingUserId(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); IPackageManager pm = AppGlobals.getPackageManager(); long id = Binder.clearCallingIdentity(); @@ -4485,9 +4416,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return false; } - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } + Preconditions.checkNotNull(who, "ComponentName is null"); if (packageList != null) { int userId = UserHandle.getCallingUserId(); @@ -4532,10 +4461,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return null; } - - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } + Preconditions.checkNotNull(who, "ComponentName is null"); synchronized (this) { ActiveAdmin admin = getActiveAdminForCallerLocked(who, @@ -4640,9 +4566,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return false; } - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } + Preconditions.checkNotNull(who, "ComponentName is null"); // TODO When InputMethodManager supports per user calls remove // this restriction. @@ -4685,10 +4609,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return null; } - - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } + Preconditions.checkNotNull(who, "ComponentName is null"); synchronized (this) { ActiveAdmin admin = getActiveAdminForCallerLocked(who, @@ -4761,10 +4682,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public UserHandle createUser(ComponentName who, String name) { + Preconditions.checkNotNull(who, "ComponentName is null"); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER); long id = Binder.clearCallingIdentity(); @@ -4815,10 +4734,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public boolean removeUser(ComponentName who, UserHandle userHandle) { + Preconditions.checkNotNull(who, "ComponentName is null"); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER); long id = Binder.clearCallingIdentity(); @@ -4832,10 +4749,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public boolean switchUser(ComponentName who, UserHandle userHandle) { + Preconditions.checkNotNull(who, "ComponentName is null"); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER); long id = Binder.clearCallingIdentity(); @@ -4856,12 +4771,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public Bundle getApplicationRestrictions(ComponentName who, String packageName) { + Preconditions.checkNotNull(who, "ComponentName is null"); final UserHandle userHandle = new UserHandle(UserHandle.getCallingUserId()); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); long id = Binder.clearCallingIdentity(); @@ -4875,12 +4788,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public void setUserRestriction(ComponentName who, String key, boolean enabled) { + Preconditions.checkNotNull(who, "ComponentName is null"); final UserHandle user = new UserHandle(UserHandle.getCallingUserId()); final int userHandle = user.getIdentifier(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } ActiveAdmin activeAdmin = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); boolean isDeviceOwner = isDeviceOwner(activeAdmin.info.getPackageName()); @@ -4982,11 +4893,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public boolean setApplicationHidden(ComponentName who, String packageName, boolean hidden) { + Preconditions.checkNotNull(who, "ComponentName is null"); int callingUserId = UserHandle.getCallingUserId(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); long id = Binder.clearCallingIdentity(); @@ -5005,11 +4914,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public boolean isApplicationHidden(ComponentName who, String packageName) { + Preconditions.checkNotNull(who, "ComponentName is null"); int callingUserId = UserHandle.getCallingUserId(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); long id = Binder.clearCallingIdentity(); @@ -5028,11 +4935,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public void enableSystemApp(ComponentName who, String packageName) { + Preconditions.checkNotNull(who, "ComponentName is null"); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } - // This API can only be called by an active device admin, // so try to retrieve it to check that the caller is one. getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -5073,11 +4977,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public int enableSystemAppWithIntent(ComponentName who, Intent intent) { + Preconditions.checkNotNull(who, "ComponentName is null"); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } - // This API can only be called by an active device admin, // so try to retrieve it to check that the caller is one. getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -5144,10 +5045,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(who, "ComponentName is null"); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } ActiveAdmin ap = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); if (disabled) { @@ -5185,12 +5084,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public void setUninstallBlocked(ComponentName who, String packageName, boolean uninstallBlocked) { + Preconditions.checkNotNull(who, "ComponentName is null"); final int userId = UserHandle.getCallingUserId(); - synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); long id = Binder.clearCallingIdentity(); @@ -5237,10 +5133,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return; } + Preconditions.checkNotNull(who, "ComponentName is null"); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } ActiveAdmin admin = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); if (admin.disableCallerId != disabled) { @@ -5255,12 +5149,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!mHasFeature) { return false; } - + Preconditions.checkNotNull(who, "ComponentName is null"); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } - ActiveAdmin admin = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); return admin.disableCallerId; @@ -5281,13 +5171,11 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { * Sets which packages may enter lock task mode. * * This function can only be called by the device owner. - * @param components The list of components allowed to enter lock task mode. + * @param packages The list of packages allowed to enter lock task mode. */ public void setLockTaskPackages(ComponentName who, String[] packages) throws SecurityException { + Preconditions.checkNotNull(who, "ComponentName is null"); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER); int userHandle = Binder.getCallingUserHandle().getIdentifier(); @@ -5309,15 +5197,13 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { * This function returns the list of components allowed to start the task lock mode. */ public String[] getLockTaskPackages(ComponentName who) { + Preconditions.checkNotNull(who, "ComponentName is null"); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER); int userHandle = Binder.getCallingUserHandle().getIdentifier(); DevicePolicyData policy = getUserData(userHandle); - return policy.mLockTaskPackages.toArray(new String[0]); + return policy.mLockTaskPackages.toArray(new String[policy.mLockTaskPackages.size()]); } } @@ -5373,11 +5259,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public void setGlobalSetting(ComponentName who, String setting, String value) { final ContentResolver contentResolver = mContext.getContentResolver(); + Preconditions.checkNotNull(who, "ComponentName is null"); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER); if (!GLOBAL_SETTINGS_WHITELIST.contains(setting)) { @@ -5396,13 +5280,11 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public void setSecureSetting(ComponentName who, String setting, String value) { + Preconditions.checkNotNull(who, "ComponentName is null"); int callingUserId = UserHandle.getCallingUserId(); final ContentResolver contentResolver = mContext.getContentResolver(); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } ActiveAdmin activeAdmin = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -5427,10 +5309,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public void setMasterVolumeMuted(ComponentName who, boolean on) { + Preconditions.checkNotNull(who, "ComponentName is null"); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); IAudioService iAudioService = IAudioService.Stub.asInterface( @@ -5447,12 +5327,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public boolean isMasterVolumeMuted(ComponentName who) { - final ContentResolver contentResolver = mContext.getContentResolver(); - + Preconditions.checkNotNull(who, "ComponentName is null"); synchronized (this) { - if (who == null) { - throw new NullPointerException("ComponentName is null"); - } getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); AudioManager audioManager = |