Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a8f15196 authored by Zhen Zhang's avatar Zhen Zhang
Browse files

Disable metered data usage user control for dlc and kiosk apps

Test: atest com.android.settingslib.RestrictedLockUtilsTest
Bug: 317264735
Bug: 317265503
Change-Id: Ie2bcc500d1f9c9ecfbce9357382b33f6b333b5e0
parent 8382b022
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -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;
        }