From c979c465278c6258a9346b7d4b36a9514eafead9 Mon Sep 17 00:00:00 2001 From: Tetiana Meronyk Date: Mon, 12 Dec 2022 01:25:20 +0000 Subject: [PATCH] Add restriction to prevent a user being made an admin Bug: 261700461 Test: manual Change-Id: I075c5d92665db13cdc4a575daf88848f5a4f5161 --- core/api/current.txt | 1 + core/java/android/os/UserManager.java | 18 ++++++++++++++++++ .../server/pm/UserRestrictionsUtils.java | 1 + 3 files changed, 20 insertions(+) diff --git a/core/api/current.txt b/core/api/current.txt index 5878fc5c35315..ef3f5da73ed7a 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -33245,6 +33245,7 @@ package android.os { field public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features"; field public static final String DISALLOW_FACTORY_RESET = "no_factory_reset"; field public static final String DISALLOW_FUN = "no_fun"; + field public static final String DISALLOW_GRANT_ADMIN = "no_grant_admin"; field public static final String DISALLOW_INSTALL_APPS = "no_install_apps"; field public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources"; field public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY = "no_install_unknown_sources_globally"; diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java index b016c7815ae7f..8bfe6b5b1ca25 100644 --- a/core/java/android/os/UserManager.java +++ b/core/java/android/os/UserManager.java @@ -322,6 +322,24 @@ public class UserManager { */ public static final String DISALLOW_WIFI_TETHERING = "no_wifi_tethering"; + /** + * Specifies if a user is disallowed from being granted admin privileges. + * + *

This restriction limits ability of other admin users to grant admin + * privileges to selected user. + * + *

This restriction has no effect in a mode that does not allow multiple admins. + * + *

The default value is false. + * + *

Key for user restrictions. + *

Type: Boolean + * @see DevicePolicyManager#addUserRestriction(ComponentName, String) + * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) + * @see #getUserRestrictions() + */ + public static final String DISALLOW_GRANT_ADMIN = "no_grant_admin"; + /** * Specifies if users are disallowed from sharing Wi-Fi for admin configured networks. * diff --git a/services/core/java/com/android/server/pm/UserRestrictionsUtils.java b/services/core/java/com/android/server/pm/UserRestrictionsUtils.java index 214fd617c9991..3f2083f1c857e 100644 --- a/services/core/java/com/android/server/pm/UserRestrictionsUtils.java +++ b/services/core/java/com/android/server/pm/UserRestrictionsUtils.java @@ -145,6 +145,7 @@ public class UserRestrictionsUtils { UserManager.DISALLOW_CAMERA_TOGGLE, UserManager.DISALLOW_CHANGE_WIFI_STATE, UserManager.DISALLOW_WIFI_TETHERING, + UserManager.DISALLOW_GRANT_ADMIN, UserManager.DISALLOW_SHARING_ADMIN_CONFIGURED_WIFI, UserManager.DISALLOW_WIFI_DIRECT, UserManager.DISALLOW_ADD_WIFI_CONFIG,