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

Commit e0c84cd8 authored by Eduard Dumitrescul's avatar Eduard Dumitrescul
Browse files

Disable USB debugging for device owner restriction

In an HSUM device running in single user mode,
disable globally after a device owner sets the
DISALLOW_DEBUGGING_FEATURES restriction.
Before this, USB debugging was disabled only when
the system user set the restriction.

Bug: 404545075
Test: TestDPC - Disallow debugging features
Flag: EXEMPT BUGFIX
Change-Id: I140444380aa759eebf5c9397085d68db89344487
parent d5437349
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.AppGlobals;
import android.app.admin.DevicePolicyManagerInternal;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -683,9 +684,7 @@ public class UserRestrictionsUtils {
                    break;
                case UserManager.DISALLOW_DEBUGGING_FEATURES:
                    if (newValue) {
                        // Only disable adb if changing for system user, since it is global
                        // TODO: should this be admin user?
                        if (userId == UserHandle.USER_SYSTEM) {
                        if (userId == UserHandle.USER_SYSTEM || isDeviceOwner(userId)) {
                            android.provider.Settings.Global.putStringForUser(cr,
                                    android.provider.Settings.Global.ADB_ENABLED, "0",
                                    userId);
@@ -968,4 +967,10 @@ public class UserRestrictionsUtils {
        return (newValue || UserManager.get(context).hasUserRestriction(userRestriction,
                UserHandle.of(userId))) ? 0 : 1;
    }

    private static boolean isDeviceOwner(int userId) {
        DevicePolicyManagerInternal dpm = LocalServices.getService(
                DevicePolicyManagerInternal.class);
        return dpm.getDeviceOwnerUserId() == userId;
    }
}