Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.settingslib; |
| 18 | |
Sudheer Shanka | 7664cba | 2016-01-15 11:39:04 +0000 | [diff] [blame] | 19 | import android.app.AppGlobals; |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 20 | import android.app.admin.DevicePolicyManager; |
| 21 | import android.content.ComponentName; |
| 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
Sudheer Shanka | 7664cba | 2016-01-15 11:39:04 +0000 | [diff] [blame] | 24 | import android.content.pm.IPackageManager; |
Sudheer Shanka | 45e298f | 2016-01-14 18:41:14 +0000 | [diff] [blame] | 25 | import android.content.pm.UserInfo; |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 26 | import android.graphics.drawable.Drawable; |
| 27 | import android.os.Bundle; |
Sudheer Shanka | 7664cba | 2016-01-15 11:39:04 +0000 | [diff] [blame] | 28 | import android.os.RemoteException; |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 29 | import android.os.UserHandle; |
Sudheer Shanka | 7664cba | 2016-01-15 11:39:04 +0000 | [diff] [blame] | 30 | import android.os.UserManager; |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 31 | import android.provider.Settings; |
| 32 | import android.text.Spanned; |
| 33 | import android.text.SpannableStringBuilder; |
| 34 | import android.text.style.ForegroundColorSpan; |
| 35 | import android.text.style.ImageSpan; |
| 36 | import android.view.MenuItem; |
| 37 | import android.widget.TextView; |
| 38 | |
Sudheer Shanka | 45e298f | 2016-01-14 18:41:14 +0000 | [diff] [blame] | 39 | import com.android.internal.widget.LockPatternUtils; |
| 40 | |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 41 | import java.util.List; |
| 42 | |
| 43 | /** |
| 44 | * Utility class to host methods usable in adding a restricted padlock icon and showing admin |
| 45 | * support message dialog. |
| 46 | */ |
| 47 | public class RestrictedLockUtils { |
| 48 | /** |
| 49 | * @return drawables for displaying with settings that are locked by a device admin. |
| 50 | */ |
| 51 | public static Drawable getRestrictedPadlock(Context context) { |
Sudheer Shanka | 40400a6 | 2016-02-23 11:42:11 +0000 | [diff] [blame] | 52 | Drawable restrictedPadlock = context.getDrawable(R.drawable.ic_info); |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 53 | final int iconSize = context.getResources().getDimensionPixelSize( |
Sudheer Shanka | 40400a6 | 2016-02-23 11:42:11 +0000 | [diff] [blame] | 54 | R.dimen.restricted_icon_size); |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 55 | restrictedPadlock.setBounds(0, 0, iconSize, iconSize); |
| 56 | return restrictedPadlock; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Checks if a restriction is enforced on a user and returns the enforced admin and |
| 61 | * admin userId. |
| 62 | * |
| 63 | * @param userRestriction Restriction to check |
| 64 | * @param userId User which we need to check if restriction is enforced on. |
Sudheer Shanka | 45e298f | 2016-01-14 18:41:14 +0000 | [diff] [blame] | 65 | * @return EnforcedAdmin Object containing the enforced admin component and admin user details, |
| 66 | * or {@code null} If the restriction is not set. If the restriction is set by both device owner |
| 67 | * and profile owner, then the admin component will be set to {@code null} and userId to |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 68 | * {@link UserHandle#USER_NULL}. |
| 69 | */ |
| 70 | public static EnforcedAdmin checkIfRestrictionEnforced(Context context, |
| 71 | String userRestriction, int userId) { |
| 72 | DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService( |
| 73 | Context.DEVICE_POLICY_SERVICE); |
Sudheer Shanka | c6108710 | 2016-01-26 14:00:16 +0000 | [diff] [blame] | 74 | if (dpm == null) { |
| 75 | return null; |
| 76 | } |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 77 | ComponentName deviceOwner = dpm.getDeviceOwnerComponentOnAnyUser(); |
| 78 | int deviceOwnerUserId = dpm.getDeviceOwnerUserId(); |
| 79 | boolean enforcedByDeviceOwner = false; |
| 80 | if (deviceOwner != null && deviceOwnerUserId != UserHandle.USER_NULL) { |
| 81 | Bundle enforcedRestrictions = dpm.getUserRestrictions(deviceOwner, deviceOwnerUserId); |
| 82 | if (enforcedRestrictions != null |
| 83 | && enforcedRestrictions.getBoolean(userRestriction, false)) { |
| 84 | enforcedByDeviceOwner = true; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | ComponentName profileOwner = null; |
| 89 | boolean enforcedByProfileOwner = false; |
| 90 | if (userId != UserHandle.USER_NULL) { |
| 91 | profileOwner = dpm.getProfileOwnerAsUser(userId); |
| 92 | if (profileOwner != null) { |
| 93 | Bundle enforcedRestrictions = dpm.getUserRestrictions(profileOwner, userId); |
| 94 | if (enforcedRestrictions != null |
| 95 | && enforcedRestrictions.getBoolean(userRestriction, false)) { |
| 96 | enforcedByProfileOwner = true; |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | if (!enforcedByDeviceOwner && !enforcedByProfileOwner) { |
| 102 | return null; |
| 103 | } |
| 104 | |
| 105 | EnforcedAdmin admin = null; |
| 106 | if (enforcedByDeviceOwner && enforcedByProfileOwner) { |
| 107 | admin = new EnforcedAdmin(); |
| 108 | } else if (enforcedByDeviceOwner) { |
| 109 | admin = new EnforcedAdmin(deviceOwner, deviceOwnerUserId); |
| 110 | } else { |
| 111 | admin = new EnforcedAdmin(profileOwner, userId); |
| 112 | } |
| 113 | return admin; |
| 114 | } |
| 115 | |
Sudheer Shanka | a8fbbb3 | 2016-02-11 17:17:57 +0000 | [diff] [blame] | 116 | public static boolean hasBaseUserRestriction(Context context, |
| 117 | String userRestriction, int userId) { |
| 118 | UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); |
| 119 | return um.hasBaseUserRestriction(userRestriction, UserHandle.of(userId)); |
| 120 | } |
| 121 | |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 122 | /** |
Sudheer Shanka | 39cef94 | 2016-01-22 20:48:04 +0000 | [diff] [blame] | 123 | * Checks if keyguard features are disabled by policy. |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 124 | * |
Sudheer Shanka | 39cef94 | 2016-01-22 20:48:04 +0000 | [diff] [blame] | 125 | * @param keyguardFeatures Could be any of keyguard features that can be |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 126 | * disabled by {@link android.app.admin.DevicePolicyManager#setKeyguardDisabledFeatures}. |
Sudheer Shanka | 45e298f | 2016-01-14 18:41:14 +0000 | [diff] [blame] | 127 | * @return EnforcedAdmin Object containing the enforced admin component and admin user details, |
| 128 | * or {@code null} If the notification features are not disabled. If the restriction is set by |
| 129 | * multiple admins, then the admin component will be set to {@code null} and userId to |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 130 | * {@link UserHandle#USER_NULL}. |
| 131 | */ |
Sudheer Shanka | 39cef94 | 2016-01-22 20:48:04 +0000 | [diff] [blame] | 132 | public static EnforcedAdmin checkIfKeyguardFeaturesDisabled(Context context, |
Clara Bayarri | 6b6c5a2 | 2016-01-28 11:33:25 +0000 | [diff] [blame] | 133 | int keyguardFeatures, int userId) { |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 134 | final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService( |
| 135 | Context.DEVICE_POLICY_SERVICE); |
Sudheer Shanka | c6108710 | 2016-01-26 14:00:16 +0000 | [diff] [blame] | 136 | if (dpm == null) { |
| 137 | return null; |
| 138 | } |
Sudheer Shanka | 39cef94 | 2016-01-22 20:48:04 +0000 | [diff] [blame] | 139 | final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); |
| 140 | LockPatternUtils lockPatternUtils = new LockPatternUtils(context); |
| 141 | EnforcedAdmin enforcedAdmin = null; |
Sudheer Shanka | 39cef94 | 2016-01-22 20:48:04 +0000 | [diff] [blame] | 142 | if (um.getUserInfo(userId).isManagedProfile()) { |
| 143 | final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userId); |
| 144 | if (admins == null) { |
| 145 | return null; |
| 146 | } |
Ruben Brunk | 7427213 | 2016-01-20 21:59:09 -0800 | [diff] [blame] | 147 | for (ComponentName admin : admins) { |
Sudheer Shanka | 39cef94 | 2016-01-22 20:48:04 +0000 | [diff] [blame] | 148 | if ((dpm.getKeyguardDisabledFeatures(admin, userId) & keyguardFeatures) != 0) { |
| 149 | if (enforcedAdmin == null) { |
| 150 | enforcedAdmin = new EnforcedAdmin(admin, userId); |
Ruben Brunk | 7427213 | 2016-01-20 21:59:09 -0800 | [diff] [blame] | 151 | } else { |
Sudheer Shanka | 39cef94 | 2016-01-22 20:48:04 +0000 | [diff] [blame] | 152 | return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN; |
Ruben Brunk | 7427213 | 2016-01-20 21:59:09 -0800 | [diff] [blame] | 153 | } |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 154 | } |
| 155 | } |
Sudheer Shanka | 39cef94 | 2016-01-22 20:48:04 +0000 | [diff] [blame] | 156 | } else { |
| 157 | // Consider all admins for this user and the profiles that are visible from this |
| 158 | // user that do not use a separate work challenge. |
| 159 | for (UserInfo userInfo : um.getProfiles(userId)) { |
| 160 | final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userInfo.id); |
| 161 | if (admins == null) { |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 162 | continue; |
Sudheer Shanka | 39cef94 | 2016-01-22 20:48:04 +0000 | [diff] [blame] | 163 | } |
| 164 | final boolean isSeparateProfileChallengeEnabled = |
| 165 | lockPatternUtils.isSeparateProfileChallengeEnabled(userInfo.id); |
| 166 | for (ComponentName admin : admins) { |
| 167 | if (!isSeparateProfileChallengeEnabled) { |
| 168 | if ((dpm.getKeyguardDisabledFeatures(admin, userInfo.id) |
| 169 | & keyguardFeatures) != 0) { |
| 170 | if (enforcedAdmin == null) { |
| 171 | enforcedAdmin = new EnforcedAdmin(admin, userInfo.id); |
| 172 | } else { |
| 173 | return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN; |
| 174 | } |
| 175 | // This same admins could have set policies both on the managed profile |
| 176 | // and on the parent. So, if the admin has set the policy on the |
| 177 | // managed profile here, we don't need to further check if that admin |
| 178 | // has set policy on the parent admin. |
| 179 | continue; |
| 180 | } |
| 181 | } |
| 182 | if (userInfo.isManagedProfile()) { |
| 183 | // If userInfo.id is a managed profile, we also need to look at |
| 184 | // the policies set on the parent. |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 185 | DevicePolicyManager parentDpm = dpm.getParentProfileInstance(userInfo); |
Sudheer Shanka | 39cef94 | 2016-01-22 20:48:04 +0000 | [diff] [blame] | 186 | if ((parentDpm.getKeyguardDisabledFeatures(admin, userInfo.id) |
| 187 | & keyguardFeatures) != 0) { |
| 188 | if (enforcedAdmin == null) { |
| 189 | enforcedAdmin = new EnforcedAdmin(admin, userInfo.id); |
| 190 | } else { |
| 191 | return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN; |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | } |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | return enforcedAdmin; |
| 199 | } |
| 200 | |
Sudheer Shanka | 7664cba | 2016-01-15 11:39:04 +0000 | [diff] [blame] | 201 | public static EnforcedAdmin checkIfUninstallBlocked(Context context, |
| 202 | String packageName, int userId) { |
| 203 | EnforcedAdmin allAppsControlDisallowedAdmin = checkIfRestrictionEnforced(context, |
| 204 | UserManager.DISALLOW_APPS_CONTROL, userId); |
| 205 | if (allAppsControlDisallowedAdmin != null) { |
| 206 | return allAppsControlDisallowedAdmin; |
| 207 | } |
| 208 | EnforcedAdmin allAppsUninstallDisallowedAdmin = checkIfRestrictionEnforced(context, |
| 209 | UserManager.DISALLOW_UNINSTALL_APPS, userId); |
| 210 | if (allAppsUninstallDisallowedAdmin != null) { |
| 211 | return allAppsUninstallDisallowedAdmin; |
| 212 | } |
| 213 | IPackageManager ipm = AppGlobals.getPackageManager(); |
| 214 | try { |
| 215 | if (ipm.getBlockUninstallForUser(packageName, userId)) { |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 216 | return getProfileOrDeviceOwner(context, userId); |
Sudheer Shanka | 7664cba | 2016-01-15 11:39:04 +0000 | [diff] [blame] | 217 | } |
| 218 | } catch (RemoteException e) { |
| 219 | // Nothing to do |
| 220 | } |
| 221 | return null; |
| 222 | } |
| 223 | |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 224 | /** |
Andrei Stingaceanu | 44af482 | 2016-01-28 20:03:41 +0000 | [diff] [blame] | 225 | * Check if an application is suspended. |
| 226 | * |
| 227 | * @return EnforcedAdmin Object containing the enforced admin component and admin user details, |
| 228 | * or {@code null} if the application is not suspended. |
| 229 | */ |
| 230 | public static EnforcedAdmin checkIfApplicationIsSuspended(Context context, String packageName, |
| 231 | int userId) { |
| 232 | IPackageManager ipm = AppGlobals.getPackageManager(); |
| 233 | try { |
Andrei Stingaceanu | 355b232 | 2016-02-12 16:43:51 +0000 | [diff] [blame] | 234 | if (ipm.isPackageSuspendedForUser(packageName, userId)) { |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 235 | return getProfileOrDeviceOwner(context, userId); |
Andrei Stingaceanu | 44af482 | 2016-01-28 20:03:41 +0000 | [diff] [blame] | 236 | } |
| 237 | } catch (RemoteException e) { |
| 238 | // Nothing to do |
| 239 | } |
| 240 | return null; |
| 241 | } |
| 242 | |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 243 | public static EnforcedAdmin checkIfInputMethodDisallowed(Context context, |
| 244 | String packageName, int userId) { |
| 245 | DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService( |
| 246 | Context.DEVICE_POLICY_SERVICE); |
| 247 | if (dpm == null) { |
| 248 | return null; |
| 249 | } |
| 250 | EnforcedAdmin admin = getProfileOrDeviceOwner(context, userId); |
| 251 | boolean permitted = true; |
| 252 | if (admin != null) { |
| 253 | permitted = dpm.isInputMethodPermittedByAdmin(admin.component, |
| 254 | packageName, userId); |
| 255 | } |
| 256 | int managedProfileId = getManagedProfileId(context, userId); |
| 257 | EnforcedAdmin profileAdmin = getProfileOrDeviceOwner(context, managedProfileId); |
| 258 | boolean permittedByProfileAdmin = true; |
| 259 | if (profileAdmin != null) { |
| 260 | permittedByProfileAdmin = dpm.isInputMethodPermittedByAdmin(profileAdmin.component, |
| 261 | packageName, managedProfileId); |
| 262 | } |
| 263 | if (!permitted && !permittedByProfileAdmin) { |
| 264 | return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN; |
| 265 | } else if (!permitted) { |
| 266 | return admin; |
| 267 | } else if (!permittedByProfileAdmin) { |
| 268 | return profileAdmin; |
| 269 | } |
| 270 | return null; |
| 271 | } |
| 272 | |
| 273 | public static EnforcedAdmin checkIfAccessibilityServiceDisallowed(Context context, |
| 274 | String packageName, int userId) { |
| 275 | DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService( |
| 276 | Context.DEVICE_POLICY_SERVICE); |
| 277 | if (dpm == null) { |
| 278 | return null; |
| 279 | } |
| 280 | EnforcedAdmin admin = getProfileOrDeviceOwner(context, userId); |
| 281 | boolean permitted = true; |
| 282 | if (admin != null) { |
| 283 | permitted = dpm.isAccessibilityServicePermittedByAdmin(admin.component, |
| 284 | packageName, userId); |
| 285 | } |
| 286 | int managedProfileId = getManagedProfileId(context, userId); |
| 287 | EnforcedAdmin profileAdmin = getProfileOrDeviceOwner(context, managedProfileId); |
| 288 | boolean permittedByProfileAdmin = true; |
| 289 | if (profileAdmin != null) { |
| 290 | permittedByProfileAdmin = dpm.isAccessibilityServicePermittedByAdmin( |
| 291 | profileAdmin.component, packageName, managedProfileId); |
| 292 | } |
| 293 | if (!permitted && !permittedByProfileAdmin) { |
| 294 | return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN; |
| 295 | } else if (!permitted) { |
| 296 | return admin; |
| 297 | } else if (!permittedByProfileAdmin) { |
| 298 | return profileAdmin; |
| 299 | } |
| 300 | return null; |
| 301 | } |
| 302 | |
| 303 | private static int getManagedProfileId(Context context, int userId) { |
| 304 | UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); |
| 305 | List<UserInfo> userProfiles = um.getProfiles(userId); |
| 306 | for (UserInfo uInfo : userProfiles) { |
| 307 | if (uInfo.id == userId) { |
| 308 | continue; |
| 309 | } |
| 310 | if (uInfo.isManagedProfile()) { |
| 311 | return uInfo.id; |
| 312 | } |
| 313 | } |
| 314 | return UserHandle.USER_NULL; |
| 315 | } |
| 316 | |
Andrei Stingaceanu | 44af482 | 2016-01-28 20:03:41 +0000 | [diff] [blame] | 317 | /** |
Sudheer Shanka | 20e2296 | 2016-01-18 11:22:45 +0000 | [diff] [blame] | 318 | * Check if account management for a specific type of account is disabled by admin. |
| 319 | * Only a profile or device owner can disable account management. So, we check if account |
| 320 | * management is disabled and return profile or device owner on the calling user. |
| 321 | * |
| 322 | * @return EnforcedAdmin Object containing the enforced admin component and admin user details, |
| 323 | * or {@code null} if the account management is not disabled. |
| 324 | */ |
| 325 | public static EnforcedAdmin checkIfAccountManagementDisabled(Context context, |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 326 | String accountType, int userId) { |
Sudheer Shanka | 20e2296 | 2016-01-18 11:22:45 +0000 | [diff] [blame] | 327 | if (accountType == null) { |
| 328 | return null; |
| 329 | } |
| 330 | DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService( |
| 331 | Context.DEVICE_POLICY_SERVICE); |
Sudheer Shanka | c6108710 | 2016-01-26 14:00:16 +0000 | [diff] [blame] | 332 | if (dpm == null) { |
| 333 | return null; |
| 334 | } |
Sudheer Shanka | 20e2296 | 2016-01-18 11:22:45 +0000 | [diff] [blame] | 335 | boolean isAccountTypeDisabled = false; |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 336 | String[] disabledTypes = dpm.getAccountTypesWithManagementDisabledAsUser(userId); |
Sudheer Shanka | 20e2296 | 2016-01-18 11:22:45 +0000 | [diff] [blame] | 337 | for (String type : disabledTypes) { |
| 338 | if (accountType.equals(type)) { |
| 339 | isAccountTypeDisabled = true; |
| 340 | break; |
| 341 | } |
| 342 | } |
| 343 | if (!isAccountTypeDisabled) { |
| 344 | return null; |
| 345 | } |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 346 | return getProfileOrDeviceOwner(context, userId); |
Sudheer Shanka | 20e2296 | 2016-01-18 11:22:45 +0000 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | /** |
| 350 | * Checks if {@link android.app.admin.DevicePolicyManager#setAutoTimeRequired} is enforced |
| 351 | * on the device. |
| 352 | * |
| 353 | * @return EnforcedAdmin Object containing the device owner component and |
| 354 | * userId the device owner is running as, or {@code null} setAutoTimeRequired is not enforced. |
| 355 | */ |
| 356 | public static EnforcedAdmin checkIfAutoTimeRequired(Context context) { |
| 357 | DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService( |
| 358 | Context.DEVICE_POLICY_SERVICE); |
Sudheer Shanka | c6108710 | 2016-01-26 14:00:16 +0000 | [diff] [blame] | 359 | if (dpm == null || !dpm.getAutoTimeRequired()) { |
Sudheer Shanka | 20e2296 | 2016-01-18 11:22:45 +0000 | [diff] [blame] | 360 | return null; |
| 361 | } |
| 362 | ComponentName adminComponent = dpm.getDeviceOwnerComponentOnCallingUser(); |
| 363 | return new EnforcedAdmin(adminComponent, UserHandle.myUserId()); |
| 364 | } |
| 365 | |
| 366 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 367 | * Checks if an admin has enforced minimum password quality requirements on the given user. |
Sudheer Shanka | 20e2296 | 2016-01-18 11:22:45 +0000 | [diff] [blame] | 368 | * |
| 369 | * @return EnforcedAdmin Object containing the enforced admin component and admin user details, |
| 370 | * or {@code null} if no quality requirements are set. If the requirements are set by |
| 371 | * multiple device admins, then the admin component will be set to {@code null} and userId to |
| 372 | * {@link UserHandle#USER_NULL}. |
| 373 | * |
| 374 | */ |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 375 | public static EnforcedAdmin checkIfPasswordQualityIsSet(Context context, int userId) { |
Sudheer Shanka | 20e2296 | 2016-01-18 11:22:45 +0000 | [diff] [blame] | 376 | final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService( |
| 377 | Context.DEVICE_POLICY_SERVICE); |
Sudheer Shanka | c6108710 | 2016-01-26 14:00:16 +0000 | [diff] [blame] | 378 | if (dpm == null) { |
| 379 | return null; |
| 380 | } |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 381 | |
| 382 | LockPatternUtils lockPatternUtils = new LockPatternUtils(context); |
| 383 | EnforcedAdmin enforcedAdmin = null; |
| 384 | if (lockPatternUtils.isSeparateProfileChallengeEnabled(userId)) { |
| 385 | // userId is managed profile and has a separate challenge, only consider |
| 386 | // the admins in that user. |
| 387 | final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userId); |
| 388 | if (admins == null) { |
| 389 | return null; |
| 390 | } |
Sudheer Shanka | 0fa7412 | 2016-01-21 13:47:51 +0000 | [diff] [blame] | 391 | for (ComponentName admin : admins) { |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 392 | if (dpm.getPasswordQuality(admin, userId) |
| 393 | > DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { |
| 394 | if (enforcedAdmin == null) { |
| 395 | enforcedAdmin = new EnforcedAdmin(admin, userId); |
Sudheer Shanka | 0fa7412 | 2016-01-21 13:47:51 +0000 | [diff] [blame] | 396 | } else { |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 397 | return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN; |
Sudheer Shanka | 0fa7412 | 2016-01-21 13:47:51 +0000 | [diff] [blame] | 398 | } |
Sudheer Shanka | 20e2296 | 2016-01-18 11:22:45 +0000 | [diff] [blame] | 399 | } |
| 400 | } |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 401 | } else { |
| 402 | // Return all admins for this user and the profiles that are visible from this |
| 403 | // user that do not use a separate work challenge. |
| 404 | final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); |
| 405 | for (UserInfo userInfo : um.getProfiles(userId)) { |
| 406 | final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userInfo.id); |
| 407 | if (admins == null) { |
| 408 | continue; |
| 409 | } |
| 410 | final boolean isSeparateProfileChallengeEnabled = |
| 411 | lockPatternUtils.isSeparateProfileChallengeEnabled(userInfo.id); |
| 412 | for (ComponentName admin : admins) { |
| 413 | if (!isSeparateProfileChallengeEnabled) { |
| 414 | if (dpm.getPasswordQuality(admin, userInfo.id) |
| 415 | > DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { |
| 416 | if (enforcedAdmin == null) { |
| 417 | enforcedAdmin = new EnforcedAdmin(admin, userInfo.id); |
| 418 | } else { |
| 419 | return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN; |
| 420 | } |
| 421 | // This same admins could have set policies both on the managed profile |
| 422 | // and on the parent. So, if the admin has set the policy on the |
| 423 | // managed profile here, we don't need to further check if that admin |
| 424 | // has set policy on the parent admin. |
| 425 | continue; |
| 426 | } |
| 427 | } |
| 428 | if (userInfo.isManagedProfile()) { |
| 429 | // If userInfo.id is a managed profile, we also need to look at |
| 430 | // the policies set on the parent. |
| 431 | DevicePolicyManager parentDpm = dpm.getParentProfileInstance(userInfo); |
| 432 | if (parentDpm.getPasswordQuality(admin, userInfo.id) |
| 433 | > DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { |
| 434 | if (enforcedAdmin == null) { |
| 435 | enforcedAdmin = new EnforcedAdmin(admin, userInfo.id); |
| 436 | } else { |
| 437 | return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN; |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | } |
Sudheer Shanka | 20e2296 | 2016-01-18 11:22:45 +0000 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | return enforcedAdmin; |
| 445 | } |
| 446 | |
Sudheer Shanka | 45e298f | 2016-01-14 18:41:14 +0000 | [diff] [blame] | 447 | /** |
| 448 | * Checks if any admin has set maximum time to lock. |
| 449 | * |
| 450 | * @return EnforcedAdmin Object containing the enforced admin component and admin user details, |
| 451 | * or {@code null} if no admin has set this restriction. If multiple admins has set this, then |
| 452 | * the admin component will be set to {@code null} and userId to {@link UserHandle#USER_NULL} |
| 453 | */ |
| 454 | public static EnforcedAdmin checkIfMaximumTimeToLockIsSet(Context context) { |
| 455 | final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService( |
| 456 | Context.DEVICE_POLICY_SERVICE); |
| 457 | LockPatternUtils lockPatternUtils = new LockPatternUtils(context); |
| 458 | EnforcedAdmin enforcedAdmin = null; |
| 459 | final int userId = UserHandle.myUserId(); |
| 460 | if (lockPatternUtils.isSeparateProfileChallengeEnabled(userId)) { |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 461 | // userId is managed profile and has a separate challenge, only consider |
| 462 | // the admins in that user. |
Sudheer Shanka | 45e298f | 2016-01-14 18:41:14 +0000 | [diff] [blame] | 463 | final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userId); |
| 464 | if (admins == null) { |
| 465 | return null; |
| 466 | } |
| 467 | for (ComponentName admin : admins) { |
| 468 | if (dpm.getMaximumTimeToLock(admin, userId) > 0) { |
| 469 | if (enforcedAdmin == null) { |
| 470 | enforcedAdmin = new EnforcedAdmin(admin, userId); |
| 471 | } else { |
| 472 | return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN; |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | } else { |
| 477 | // Return all admins for this user and the profiles that are visible from this |
| 478 | // user that do not use a separate work challenge. |
| 479 | final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); |
| 480 | for (UserInfo userInfo : um.getProfiles(userId)) { |
| 481 | final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userInfo.id); |
| 482 | if (admins == null) { |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 483 | continue; |
Sudheer Shanka | 45e298f | 2016-01-14 18:41:14 +0000 | [diff] [blame] | 484 | } |
Sudheer Shanka | 39cef94 | 2016-01-22 20:48:04 +0000 | [diff] [blame] | 485 | final boolean isSeparateProfileChallengeEnabled = |
| 486 | lockPatternUtils.isSeparateProfileChallengeEnabled(userInfo.id); |
Sudheer Shanka | 45e298f | 2016-01-14 18:41:14 +0000 | [diff] [blame] | 487 | for (ComponentName admin : admins) { |
Sudheer Shanka | 39cef94 | 2016-01-22 20:48:04 +0000 | [diff] [blame] | 488 | if (!isSeparateProfileChallengeEnabled) { |
Sudheer Shanka | 45e298f | 2016-01-14 18:41:14 +0000 | [diff] [blame] | 489 | if (dpm.getMaximumTimeToLock(admin, userInfo.id) > 0) { |
| 490 | if (enforcedAdmin == null) { |
| 491 | enforcedAdmin = new EnforcedAdmin(admin, userInfo.id); |
| 492 | } else { |
| 493 | return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN; |
| 494 | } |
| 495 | // This same admins could have set policies both on the managed profile |
| 496 | // and on the parent. So, if the admin has set the policy on the |
| 497 | // managed profile here, we don't need to further check if that admin |
| 498 | // has set policy on the parent admin. |
| 499 | continue; |
| 500 | } |
| 501 | } |
| 502 | if (userInfo.isManagedProfile()) { |
| 503 | // If userInfo.id is a managed profile, we also need to look at |
| 504 | // the policies set on the parent. |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 505 | DevicePolicyManager parentDpm = dpm.getParentProfileInstance(userInfo); |
Sudheer Shanka | 45e298f | 2016-01-14 18:41:14 +0000 | [diff] [blame] | 506 | if (parentDpm.getMaximumTimeToLock(admin, userInfo.id) > 0) { |
| 507 | if (enforcedAdmin == null) { |
| 508 | enforcedAdmin = new EnforcedAdmin(admin, userInfo.id); |
| 509 | } else { |
| 510 | return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN; |
| 511 | } |
| 512 | } |
| 513 | } |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | return enforcedAdmin; |
| 518 | } |
| 519 | |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 520 | public static EnforcedAdmin getProfileOrDeviceOwner(Context context, int userId) { |
| 521 | if (userId == UserHandle.USER_NULL) { |
| 522 | return null; |
| 523 | } |
Sudheer Shanka | 20e2296 | 2016-01-18 11:22:45 +0000 | [diff] [blame] | 524 | final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService( |
| 525 | Context.DEVICE_POLICY_SERVICE); |
Sudheer Shanka | c6108710 | 2016-01-26 14:00:16 +0000 | [diff] [blame] | 526 | if (dpm == null) { |
| 527 | return null; |
| 528 | } |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 529 | ComponentName adminComponent = dpm.getProfileOwnerAsUser(userId); |
Sudheer Shanka | 20e2296 | 2016-01-18 11:22:45 +0000 | [diff] [blame] | 530 | if (adminComponent != null) { |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 531 | return new EnforcedAdmin(adminComponent, userId); |
Sudheer Shanka | 20e2296 | 2016-01-18 11:22:45 +0000 | [diff] [blame] | 532 | } |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 533 | if (dpm.getDeviceOwnerUserId() == userId) { |
| 534 | adminComponent = dpm.getDeviceOwnerComponentOnAnyUser(); |
| 535 | if (adminComponent != null) { |
| 536 | return new EnforcedAdmin(adminComponent, userId); |
| 537 | } |
Sudheer Shanka | 20e2296 | 2016-01-18 11:22:45 +0000 | [diff] [blame] | 538 | } |
| 539 | return null; |
| 540 | } |
| 541 | |
Sudheer Shanka | 1d0169b | 2016-02-03 00:25:50 +0000 | [diff] [blame] | 542 | public static EnforcedAdmin getDeviceOwner(Context context) { |
| 543 | final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService( |
| 544 | Context.DEVICE_POLICY_SERVICE); |
| 545 | if (dpm == null) { |
| 546 | return null; |
| 547 | } |
| 548 | ComponentName adminComponent = dpm.getDeviceOwnerComponentOnAnyUser(); |
| 549 | if (adminComponent != null) { |
| 550 | return new EnforcedAdmin(adminComponent, dpm.getDeviceOwnerUserId()); |
| 551 | } |
| 552 | return null; |
| 553 | } |
| 554 | |
Sudheer Shanka | 20e2296 | 2016-01-18 11:22:45 +0000 | [diff] [blame] | 555 | /** |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 556 | * Set the menu item as disabled by admin by adding a restricted padlock at the end of the |
| 557 | * text and set the click listener which will send an intent to show the admin support details |
Sudheer Shanka | 7664cba | 2016-01-15 11:39:04 +0000 | [diff] [blame] | 558 | * dialog. If the admin is null, remove the padlock and disabled color span. When the admin is |
| 559 | * null, we also set the OnMenuItemClickListener to null, so if you want to set a custom |
| 560 | * OnMenuItemClickListener, set it after calling this method. |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 561 | */ |
| 562 | public static void setMenuItemAsDisabledByAdmin(final Context context, |
| 563 | final MenuItem item, final EnforcedAdmin admin) { |
| 564 | SpannableStringBuilder sb = new SpannableStringBuilder(item.getTitle()); |
| 565 | removeExistingRestrictedSpans(sb); |
| 566 | |
Sudheer Shanka | 7664cba | 2016-01-15 11:39:04 +0000 | [diff] [blame] | 567 | if (admin != null) { |
| 568 | final int disabledColor = context.getColor(R.color.disabled_text_color); |
| 569 | sb.setSpan(new ForegroundColorSpan(disabledColor), 0, sb.length(), |
| 570 | Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| 571 | ImageSpan image = new RestrictedLockImageSpan(context); |
| 572 | sb.append(" ", image, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 573 | |
Sudheer Shanka | 7664cba | 2016-01-15 11:39:04 +0000 | [diff] [blame] | 574 | item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { |
| 575 | @Override |
| 576 | public boolean onMenuItemClick(MenuItem item) { |
| 577 | sendShowAdminSupportDetailsIntent(context, admin); |
| 578 | return true; |
| 579 | } |
| 580 | }); |
| 581 | } else { |
| 582 | item.setOnMenuItemClickListener(null); |
| 583 | } |
| 584 | item.setTitle(sb); |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | private static void removeExistingRestrictedSpans(SpannableStringBuilder sb) { |
| 588 | final int length = sb.length(); |
| 589 | RestrictedLockImageSpan[] imageSpans = sb.getSpans(length - 1, length, |
| 590 | RestrictedLockImageSpan.class); |
| 591 | for (ImageSpan span : imageSpans) { |
Sudheer Shanka | 20e2296 | 2016-01-18 11:22:45 +0000 | [diff] [blame] | 592 | final int start = sb.getSpanStart(span); |
| 593 | final int end = sb.getSpanEnd(span); |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 594 | sb.removeSpan(span); |
Sudheer Shanka | 20e2296 | 2016-01-18 11:22:45 +0000 | [diff] [blame] | 595 | sb.delete(start, end); |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 596 | } |
| 597 | ForegroundColorSpan[] colorSpans = sb.getSpans(0, length, ForegroundColorSpan.class); |
| 598 | for (ForegroundColorSpan span : colorSpans) { |
| 599 | sb.removeSpan(span); |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | /** |
| 604 | * Send the intent to trigger the {@link android.settings.ShowAdminSupportDetailsDialog}. |
| 605 | */ |
| 606 | public static void sendShowAdminSupportDetailsIntent(Context context, EnforcedAdmin admin) { |
Sudheer Shanka | 1c7cda8 | 2015-12-31 14:46:02 +0000 | [diff] [blame] | 607 | final Intent intent = getShowAdminSupportDetailsIntent(context, admin); |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 608 | int adminUserId = UserHandle.myUserId(); |
Sudheer Shanka | 1c7cda8 | 2015-12-31 14:46:02 +0000 | [diff] [blame] | 609 | if (admin.userId != UserHandle.USER_NULL) { |
| 610 | adminUserId = admin.userId; |
| 611 | } |
| 612 | context.startActivityAsUser(intent, new UserHandle(adminUserId)); |
| 613 | } |
| 614 | |
| 615 | public static Intent getShowAdminSupportDetailsIntent(Context context, EnforcedAdmin admin) { |
| 616 | final Intent intent = new Intent(Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS); |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 617 | if (admin != null) { |
| 618 | if (admin.component != null) { |
| 619 | intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, admin.component); |
| 620 | } |
Sudheer Shanka | 1c7cda8 | 2015-12-31 14:46:02 +0000 | [diff] [blame] | 621 | int adminUserId = UserHandle.myUserId(); |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 622 | if (admin.userId != UserHandle.USER_NULL) { |
| 623 | adminUserId = admin.userId; |
| 624 | } |
| 625 | intent.putExtra(Intent.EXTRA_USER_ID, adminUserId); |
| 626 | } |
Sudheer Shanka | 1c7cda8 | 2015-12-31 14:46:02 +0000 | [diff] [blame] | 627 | return intent; |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | public static void setTextViewPadlock(Context context, |
| 631 | TextView textView, boolean showPadlock) { |
| 632 | final SpannableStringBuilder sb = new SpannableStringBuilder(textView.getText()); |
| 633 | removeExistingRestrictedSpans(sb); |
| 634 | if (showPadlock) { |
| 635 | final ImageSpan image = new RestrictedLockImageSpan(context); |
| 636 | sb.append(" ", image, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| 637 | } |
| 638 | textView.setText(sb); |
| 639 | } |
| 640 | |
Sudheer Shanka | 9f77a71 | 2016-01-12 19:38:53 +0000 | [diff] [blame] | 641 | /** |
| 642 | * Takes a {@link android.widget.TextView} and applies an alpha so that the text looks like |
| 643 | * disabled and appends a padlock to the text. This assumes that there are no |
| 644 | * ForegroundColorSpans and RestrictedLockImageSpans used on the TextView. |
| 645 | */ |
| 646 | public static void setTextViewAsDisabledByAdmin(Context context, |
| 647 | TextView textView, boolean disabled) { |
| 648 | final SpannableStringBuilder sb = new SpannableStringBuilder(textView.getText()); |
| 649 | removeExistingRestrictedSpans(sb); |
| 650 | if (disabled) { |
| 651 | final int disabledColor = context.getColor(R.color.disabled_text_color); |
| 652 | sb.setSpan(new ForegroundColorSpan(disabledColor), 0, sb.length(), |
| 653 | Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
Sudheer Shanka | f271fd5 | 2016-03-07 13:13:22 -0800 | [diff] [blame] | 654 | textView.setCompoundDrawables(null, null, getRestrictedPadlock(context), null); |
| 655 | textView.setCompoundDrawablePadding(context.getResources().getDimensionPixelSize( |
| 656 | R.dimen.restricted_icon_padding)); |
| 657 | } else { |
| 658 | textView.setCompoundDrawables(null, null, null, null); |
Sudheer Shanka | 9f77a71 | 2016-01-12 19:38:53 +0000 | [diff] [blame] | 659 | } |
| 660 | textView.setText(sb); |
| 661 | } |
| 662 | |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 663 | public static class EnforcedAdmin { |
| 664 | public ComponentName component = null; |
| 665 | public int userId = UserHandle.USER_NULL; |
| 666 | |
Sudheer Shanka | 45e298f | 2016-01-14 18:41:14 +0000 | [diff] [blame] | 667 | // We use this to represent the case where a policy is enforced by multiple admins. |
| 668 | public final static EnforcedAdmin MULTIPLE_ENFORCED_ADMIN = new EnforcedAdmin(); |
| 669 | |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 670 | public EnforcedAdmin(ComponentName component, int userId) { |
| 671 | this.component = component; |
| 672 | this.userId = userId; |
| 673 | } |
| 674 | |
Sudheer Shanka | 1c09db2 | 2016-01-18 11:18:35 +0000 | [diff] [blame] | 675 | public EnforcedAdmin(EnforcedAdmin other) { |
| 676 | if (other == null) { |
| 677 | throw new IllegalArgumentException(); |
| 678 | } |
| 679 | this.component = other.component; |
| 680 | this.userId = other.userId; |
| 681 | } |
| 682 | |
| 683 | public EnforcedAdmin() {} |
| 684 | |
Sudheer Shanka | 1c7cda8 | 2015-12-31 14:46:02 +0000 | [diff] [blame] | 685 | @Override |
| 686 | public boolean equals(Object object) { |
| 687 | if (object == this) return true; |
| 688 | if (!(object instanceof EnforcedAdmin)) return false; |
| 689 | EnforcedAdmin other = (EnforcedAdmin) object; |
| 690 | if (userId != other.userId) { |
| 691 | return false; |
| 692 | } |
| 693 | if ((component == null && other == null) || |
| 694 | (component != null && component.equals(other))) { |
| 695 | return true; |
| 696 | } |
| 697 | return false; |
| 698 | } |
| 699 | |
| 700 | @Override |
| 701 | public String toString() { |
| 702 | return "EnforcedAdmin{component=" + component + ",userId=" + userId + "}"; |
| 703 | } |
| 704 | |
| 705 | public void copyTo(EnforcedAdmin other) { |
| 706 | if (other == null) { |
Sudheer Shanka | 1c09db2 | 2016-01-18 11:18:35 +0000 | [diff] [blame] | 707 | throw new IllegalArgumentException(); |
Sudheer Shanka | 1c7cda8 | 2015-12-31 14:46:02 +0000 | [diff] [blame] | 708 | } |
| 709 | other.component = component; |
| 710 | other.userId = userId; |
| 711 | } |
Sudheer Shanka | 7ff866d | 2016-01-12 17:22:06 +0000 | [diff] [blame] | 712 | } |
Ruben Brunk | 7427213 | 2016-01-20 21:59:09 -0800 | [diff] [blame] | 713 | } |