Merge "Move some RestrictedLockUtils out of SettingLib"

This commit is contained in:
TreeHugger Robot
2023-01-09 23:18:01 +00:00
committed by Android (Google) Code Review
4 changed files with 49 additions and 39 deletions

View File

@@ -10981,6 +10981,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";

View File

@@ -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";

View File

@@ -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
+ '}';
}
}
}

View File

@@ -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;
@@ -753,26 +751,6 @@ public class RestrictedLockUtilsInternal extends RestrictedLockUtils {
return RestrictedLockUtils.getProfileOrDeviceOwner(context, UserHandle.of(profileId));
}
/**
* 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.