summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Sudheer Shanka <sudheersai@google.com> 2016-01-18 17:24:19 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2016-01-18 17:24:19 +0000
commitba4a49800ebb45d144efc9288672400e346408da (patch)
treed1f9218eac9a44c1c74eca9fbdd7c0281a120914
parent8b15c9c565f998cadd7ae0692af509c4d061317e (diff)
parent20e22960cbbe990d74269dbd38a87e9ffe31b838 (diff)
Merge "Remove spacing when removing padlock and add more util methods."
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtils.java101
1 files changed, 101 insertions, 0 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtils.java b/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtils.java
index d8c21af3ddfb..da716f53ef75 100644
--- a/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtils.java
@@ -148,6 +148,104 @@ public class RestrictedLockUtils {
}
/**
+ * Check if account management for a specific type of account is disabled by admin.
+ * Only a profile or device owner can disable account management. So, we check if account
+ * management is disabled and return profile or device owner on the calling user.
+ *
+ * @return EnforcedAdmin Object containing the enforced admin component and admin user details,
+ * or {@code null} if the account management is not disabled.
+ */
+ public static EnforcedAdmin checkIfAccountManagementDisabled(Context context,
+ String accountType) {
+ if (accountType == null) {
+ return null;
+ }
+ DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
+ Context.DEVICE_POLICY_SERVICE);
+ boolean isAccountTypeDisabled = false;
+ String[] disabledTypes = dpm.getAccountTypesWithManagementDisabled();
+ for (String type : disabledTypes) {
+ if (accountType.equals(type)) {
+ isAccountTypeDisabled = true;
+ break;
+ }
+ }
+ if (!isAccountTypeDisabled) {
+ return null;
+ }
+ return getProfileOrDeviceOwnerOnCallingUser(context);
+ }
+
+ /**
+ * Checks if {@link android.app.admin.DevicePolicyManager#setAutoTimeRequired} is enforced
+ * on the device.
+ *
+ * @return EnforcedAdmin Object containing the device owner component and
+ * userId the device owner is running as, or {@code null} setAutoTimeRequired is not enforced.
+ */
+ public static EnforcedAdmin checkIfAutoTimeRequired(Context context) {
+ DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
+ Context.DEVICE_POLICY_SERVICE);
+ if (dpm.getAutoTimeRequired()) {
+ return null;
+ }
+ ComponentName adminComponent = dpm.getDeviceOwnerComponentOnCallingUser();
+ return new EnforcedAdmin(adminComponent, UserHandle.myUserId());
+ }
+
+ /**
+ * Checks if an admin has enforced minimum password quality requirements on the device.
+ *
+ * @return EnforcedAdmin Object containing the enforced admin component and admin user details,
+ * or {@code null} if no quality requirements are set. If the requirements are set by
+ * multiple device admins, then the admin component will be set to {@code null} and userId to
+ * {@link UserHandle#USER_NULL}.
+ *
+ */
+ public static EnforcedAdmin checkIfPasswordQualityIsSet(Context context) {
+ final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
+ Context.DEVICE_POLICY_SERVICE);
+ boolean isDisabledByMultipleAdmins = false;
+ ComponentName adminComponent = null;
+ List<ComponentName> admins = dpm.getActiveAdmins();
+ int quality;
+ for (ComponentName admin : admins) {
+ quality = dpm.getPasswordQuality(admin);
+ if (quality >= DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
+ if (adminComponent == null) {
+ adminComponent = admin;
+ } else {
+ isDisabledByMultipleAdmins = true;
+ break;
+ }
+ }
+ }
+ EnforcedAdmin enforcedAdmin = null;
+ if (adminComponent != null) {
+ if (!isDisabledByMultipleAdmins) {
+ enforcedAdmin = new EnforcedAdmin(adminComponent, UserHandle.myUserId());
+ } else {
+ enforcedAdmin = new EnforcedAdmin();
+ }
+ }
+ return enforcedAdmin;
+ }
+
+ public static EnforcedAdmin getProfileOrDeviceOwnerOnCallingUser(Context context) {
+ final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
+ Context.DEVICE_POLICY_SERVICE);
+ ComponentName adminComponent = dpm.getDeviceOwnerComponentOnCallingUser();
+ if (adminComponent != null) {
+ return new EnforcedAdmin(adminComponent, UserHandle.myUserId());
+ }
+ adminComponent = dpm.getProfileOwner();
+ if (adminComponent != null) {
+ return new EnforcedAdmin(adminComponent, UserHandle.myUserId());
+ }
+ return null;
+ }
+
+ /**
* Set the menu item as disabled by admin by adding a restricted padlock at the end of the
* text and set the click listener which will send an intent to show the admin support details
* dialog.
@@ -178,7 +276,10 @@ public class RestrictedLockUtils {
RestrictedLockImageSpan[] imageSpans = sb.getSpans(length - 1, length,
RestrictedLockImageSpan.class);
for (ImageSpan span : imageSpans) {
+ final int start = sb.getSpanStart(span);
+ final int end = sb.getSpanEnd(span);
sb.removeSpan(span);
+ sb.delete(start, end);
}
ForegroundColorSpan[] colorSpans = sb.getSpans(0, length, ForegroundColorSpan.class);
for (ForegroundColorSpan span : colorSpans) {