summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author menghanli <menghanli@google.com> 2022-10-26 15:09:04 +0800
committer menghanli <menghanli@google.com> 2022-12-29 05:56:56 +0800
commit98254a9f9477988d353adfa1aafd88235ef37595 (patch)
tree0b26240d9f215ab54cfc001a285d5d7730a1918a
parent61e599eaaa1aebd9ce40a3ae2a5bef77235e2e86 (diff)
Move some RestrictedLockUtils out of SettingLib
Ref ag/4891733 to move ACTION_SHOW_RESTRICTED_SETTING_DIALOG to RestrictedLockUtilsSettingLib. It allows mainline module and //frameworks/base/core/java to use the action. Bug: 254223085 Test: Built Change-Id: Ib364d8c14a7cae9c27b34b8df28e9dbdb4fda378
-rw-r--r--core/api/system-current.txt1
-rw-r--r--core/java/android/provider/Settings.java1
-rw-r--r--packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java64
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java22
4 files changed, 49 insertions, 39 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 5f4c19beb3b5..3d06d2bd9d0b 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -10965,6 +10965,7 @@ package android.provider {
field public static final String ACTION_NOTIFICATION_POLICY_ACCESS_DETAIL_SETTINGS = "android.settings.NOTIFICATION_POLICY_ACCESS_DETAIL_SETTINGS";
field public static final String ACTION_REQUEST_ENABLE_CONTENT_CAPTURE = "android.settings.REQUEST_ENABLE_CONTENT_CAPTURE";
field public static final String ACTION_SHOW_ADMIN_SUPPORT_DETAILS = "android.settings.SHOW_ADMIN_SUPPORT_DETAILS";
+ field public static final String ACTION_SHOW_RESTRICTED_SETTING_DIALOG = "android.settings.SHOW_RESTRICTED_SETTING_DIALOG";
field public static final String ACTION_TETHER_PROVISIONING_UI = "android.settings.TETHER_PROVISIONING_UI";
field public static final String ACTION_TETHER_SETTINGS = "android.settings.TETHER_SETTINGS";
field public static final String ACTION_TETHER_UNSUPPORTED_CARRIER_UI = "android.settings.TETHER_UNSUPPORTED_CARRIER_UI";
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index b236d6632961..6414c7123ecb 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -2501,6 +2501,7 @@ public final class Settings {
*
* @hide
*/
+ @SystemApi
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_SHOW_RESTRICTED_SETTING_DIALOG =
"android.settings.SHOW_RESTRICTED_SETTING_DIALOG";
diff --git a/packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java b/packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java
index 80f02b4ac0ee..96a11eeb3b78 100644
--- a/packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java
+++ b/packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java
@@ -37,7 +37,7 @@ import java.util.Objects;
*/
public class RestrictedLockUtils {
/**
- * Get EnforcedAdmin from DevicePolicyManager
+ * Gets EnforcedAdmin from DevicePolicyManager
*/
@RequiresApi(Build.VERSION_CODES.M)
public static EnforcedAdmin getProfileOrDeviceOwner(Context context, UserHandle user) {
@@ -45,7 +45,7 @@ public class RestrictedLockUtils {
}
/**
- * Get EnforcedAdmin from DevicePolicyManager
+ * Gets EnforcedAdmin from DevicePolicyManager
*/
@RequiresApi(Build.VERSION_CODES.M)
public static EnforcedAdmin getProfileOrDeviceOwner(
@@ -81,7 +81,7 @@ public class RestrictedLockUtils {
}
/**
- * Send the intent to trigger the {@code android.settings.ShowAdminSupportDetailsDialog}.
+ * Sends the intent to trigger the {@code android.settings.ShowAdminSupportDetailsDialog}.
*/
@RequiresApi(Build.VERSION_CODES.M)
public static void sendShowAdminSupportDetailsIntent(Context context, EnforcedAdmin admin) {
@@ -97,6 +97,9 @@ public class RestrictedLockUtils {
context.startActivityAsUser(intent, UserHandle.of(targetUserId));
}
+ /**
+ * Gets the intent to trigger the {@code android.settings.ShowAdminSupportDetailsDialog}.
+ */
public static Intent getShowAdminSupportDetailsIntent(Context context, EnforcedAdmin admin) {
final Intent intent = new Intent(Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS);
if (admin != null) {
@@ -109,7 +112,27 @@ public class RestrictedLockUtils {
}
/**
- * Check if current user is profile or not
+ * Shows restricted setting dialog.
+ */
+ @RequiresApi(Build.VERSION_CODES.TIRAMISU)
+ public static void sendShowRestrictedSettingDialogIntent(Context context,
+ String packageName, int uid) {
+ final Intent intent = getShowRestrictedSettingsIntent(packageName, uid);
+ context.startActivity(intent);
+ }
+
+ /**
+ * Gets restricted settings dialog intent.
+ */
+ private static Intent getShowRestrictedSettingsIntent(String packageName, int uid) {
+ final Intent intent = new Intent(Settings.ACTION_SHOW_RESTRICTED_SETTING_DIALOG);
+ intent.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName);
+ intent.putExtra(Intent.EXTRA_UID, uid);
+ return intent;
+ }
+
+ /**
+ * Checks if current user is profile or not
*/
@RequiresApi(Build.VERSION_CODES.M)
public static boolean isCurrentUserOrProfile(Context context, int userId) {
@@ -117,6 +140,9 @@ public class RestrictedLockUtils {
return um.getUserProfiles().contains(UserHandle.of(userId));
}
+ /**
+ * A admin for the restriction enforced.
+ */
public static class EnforcedAdmin {
@Nullable
public ComponentName component = null;
@@ -129,12 +155,17 @@ public class RestrictedLockUtils {
@Nullable
public UserHandle user = null;
- // We use this to represent the case where a policy is enforced by multiple admins.
- public final static EnforcedAdmin MULTIPLE_ENFORCED_ADMIN = new EnforcedAdmin();
+ /**
+ * We use this to represent the case where a policy is enforced by multiple admins.
+ */
+ public static final EnforcedAdmin MULTIPLE_ENFORCED_ADMIN = new EnforcedAdmin();
+ /**
+ * The restriction enforced by admin with restriction.
+ */
public static EnforcedAdmin createDefaultEnforcedAdminWithRestriction(
String enforcedRestriction) {
- EnforcedAdmin enforcedAdmin = new EnforcedAdmin();
+ final EnforcedAdmin enforcedAdmin = new EnforcedAdmin();
enforcedAdmin.enforcedRestriction = enforcedRestriction;
return enforcedAdmin;
}
@@ -159,8 +190,7 @@ public class RestrictedLockUtils {
this.user = other.user;
}
- public EnforcedAdmin() {
- }
+ public EnforcedAdmin() {}
/**
* Combines two {@link EnforcedAdmin} into one: if one of them is null, then just return
@@ -189,9 +219,9 @@ public class RestrictedLockUtils {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
EnforcedAdmin that = (EnforcedAdmin) o;
- return Objects.equals(user, that.user) &&
- Objects.equals(component, that.component) &&
- Objects.equals(enforcedRestriction, that.enforcedRestriction);
+ return Objects.equals(user, that.user)
+ && Objects.equals(component, that.component)
+ && Objects.equals(enforcedRestriction, that.enforcedRestriction);
}
@Override
@@ -201,11 +231,11 @@ public class RestrictedLockUtils {
@Override
public String toString() {
- return "EnforcedAdmin{" +
- "component=" + component +
- ", enforcedRestriction='" + enforcedRestriction +
- ", user=" + user +
- '}';
+ return "EnforcedAdmin{"
+ + "component=" + component
+ + ", enforcedRestriction='" + enforcedRestriction
+ + ", user=" + user
+ + '}';
}
}
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java b/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java
index 5610ac4b9c42..78b78101e64e 100644
--- a/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java
+++ b/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java
@@ -27,7 +27,6 @@ import android.app.AppGlobals;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
-import android.content.Intent;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
@@ -37,7 +36,6 @@ import android.os.Build;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
-import android.provider.Settings;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
@@ -754,26 +752,6 @@ public class RestrictedLockUtilsInternal extends RestrictedLockUtils {
}
/**
- * Show restricted setting dialog.
- */
- @RequiresApi(Build.VERSION_CODES.TIRAMISU)
- public static void sendShowRestrictedSettingDialogIntent(Context context,
- String packageName, int uid) {
- final Intent intent = getShowRestrictedSettingsIntent(packageName, uid);
- context.startActivity(intent);
- }
-
- /**
- * Get restricted settings dialog intent.
- */
- private static Intent getShowRestrictedSettingsIntent(String packageName, int uid) {
- final Intent intent = new Intent(Settings.ACTION_SHOW_RESTRICTED_SETTING_DIALOG);
- intent.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName);
- intent.putExtra(Intent.EXTRA_UID, uid);
- return intent;
- }
-
- /**
* Static {@link LockPatternUtils} and {@link DevicePolicyManager} wrapper for testing purposes.
* {@link LockPatternUtils} is an internal API not supported by robolectric.
* {@link DevicePolicyManager} has a {@code getProfileParent} not yet suppored by robolectric.