diff options
| author | 2024-01-03 11:54:21 -0600 | |
|---|---|---|
| committer | 2024-01-08 11:01:56 -0600 | |
| commit | a8f1519667b2eea7c23fb41eeaa527f9597a8ad9 (patch) | |
| tree | df472b348f853a98b52c52881460af363139d46b | |
| parent | 8382b02270e9f219a5a39c499fc27b5742b6a029 (diff) | |
Disable metered data usage user control for dlc and kiosk apps
Test: atest com.android.settingslib.RestrictedLockUtilsTest
Bug: 317264735
Bug: 317265503
Change-Id: Ie2bcc500d1f9c9ecfbce9357382b33f6b333b5e0
| -rw-r--r-- | packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java | 27 | 
1 files changed, 22 insertions, 5 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java b/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java index 8e5396fef744..d9024575f247 100644 --- a/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java +++ b/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java @@ -19,6 +19,7 @@ package com.android.settingslib;  import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_FEATURES_NONE;  import static android.app.admin.DevicePolicyManager.MTE_NOT_CONTROLLED_BY_POLICY;  import static android.app.admin.DevicePolicyManager.PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER; +import static android.app.role.RoleManager.ROLE_FINANCED_DEVICE_KIOSK;  import static com.android.settingslib.Utils.getColorAttrDefaultColor; @@ -27,6 +28,7 @@ import android.annotation.UserIdInt;  import android.app.AppGlobals;  import android.app.AppOpsManager;  import android.app.admin.DevicePolicyManager; +import android.app.role.RoleManager;  import android.content.ComponentName;  import android.content.Context;  import android.content.Intent; @@ -70,6 +72,10 @@ public class RestrictedLockUtilsInternal extends RestrictedLockUtils {      private static final boolean DEBUG = Log.isLoggable(LOG_TAG, Log.DEBUG);      private static final Set<String> ECM_KEYS = new ArraySet<>(); +    // TODO(b/281701062): reference role name from role manager once its exposed. +    private static final String ROLE_DEVICE_LOCK_CONTROLLER = +            "android.app.role.SYSTEM_FINANCED_DEVICE_CONTROLLER"; +      static {          if (android.security.Flags.extendEcmToAllSettings()) {              ECM_KEYS.add(AppOpsManager.OPSTR_SYSTEM_ALERT_WINDOW); @@ -476,16 +482,27 @@ public class RestrictedLockUtilsInternal extends RestrictedLockUtils {      }      /** -     * Check if {@param packageName} is restricted by the profile or device owner from using -     * metered data. +     * Check if user control over metered data usage of {@code packageName} is disabled by the +     * profile or device owner.       *       * @return EnforcedAdmin object containing the enforced admin component and admin user details, -     * or {@code null} if the {@param packageName} is not restricted. +     * or {@code null} if the user control is not disabled.       */ -    public static EnforcedAdmin checkIfMeteredDataRestricted(Context context, +    public static EnforcedAdmin checkIfMeteredDataUsageUserControlDisabled(Context context,              String packageName, int userId) { +        RoleManager roleManager = context.getSystemService(RoleManager.class); +        UserHandle userHandle = getUserHandleOf(userId); +        if (roleManager.getRoleHoldersAsUser(ROLE_FINANCED_DEVICE_KIOSK, userHandle) +                .contains(packageName) +                || roleManager.getRoleHoldersAsUser(ROLE_DEVICE_LOCK_CONTROLLER, userHandle) +                .contains(packageName)) { +            // There is no actual device admin for a financed device, but metered data usage +            // control should still be disabled for both controller and kiosk apps. +            return new EnforcedAdmin(); +        } +          final EnforcedAdmin enforcedAdmin = getProfileOrDeviceOwner(context, -                getUserHandleOf(userId)); +                userHandle);          if (enforcedAdmin == null) {              return null;          }  |