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

Commit a81b98f1 authored by Eduard Dumitrescul's avatar Eduard Dumitrescul Committed by Android (Google) Code Review
Browse files

Merge "Disable USB debugging for device owner restriction" into main

parents 503385c4 e0c84cd8
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;
    }
}