2022-10-15 07:53:14 -04:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: flawedworld <flawedworld@flawed.world>
|
|
|
|
Date: Wed, 1 Sep 2021 23:36:10 +0300
|
|
|
|
Subject: [PATCH] UserManager app installation restrictions
|
|
|
|
|
|
|
|
---
|
|
|
|
res/values/strings.xml | 2 +
|
|
|
|
res/xml/user_details_settings.xml | 4 ++
|
|
|
|
.../settings/users/UserDetailsSettings.java | 43 ++++++++++++++++---
|
|
|
|
3 files changed, 44 insertions(+), 5 deletions(-)
|
|
|
|
|
|
|
|
diff --git a/res/values/strings.xml b/res/values/strings.xml
|
2023-06-20 18:13:52 -04:00
|
|
|
index e090ad8a05..1a159aebe9 100644
|
2022-10-15 07:53:14 -04:00
|
|
|
--- a/res/values/strings.xml
|
|
|
|
+++ b/res/values/strings.xml
|
2023-06-20 18:13:52 -04:00
|
|
|
@@ -8090,6 +8090,8 @@
|
2022-10-15 07:53:14 -04:00
|
|
|
<string name="user_enable_calling">Turn on phone calls</string>
|
|
|
|
<!-- Title of preference to enable calling and SMS [CHAR LIMIT=45] -->
|
|
|
|
<string name="user_enable_calling_sms">Turn on phone calls & SMS</string>
|
|
|
|
+ <!-- Title of preference to disallow installing apps [CHAR LIMIT=45] -->
|
|
|
|
+ <string name="user_disallow_install_apps">Disallow installing apps</string>
|
|
|
|
<!-- Title of preference to remove the user [CHAR LIMIT=35] -->
|
|
|
|
<string name="user_remove_user">Delete user</string>
|
|
|
|
<!-- Title for confirmation of turning on calls [CHAR LIMIT=40] -->
|
|
|
|
diff --git a/res/xml/user_details_settings.xml b/res/xml/user_details_settings.xml
|
|
|
|
index 2301bac1d4..d2766360a0 100644
|
|
|
|
--- a/res/xml/user_details_settings.xml
|
|
|
|
+++ b/res/xml/user_details_settings.xml
|
|
|
|
@@ -29,6 +29,10 @@
|
|
|
|
android:key="app_and_content_access"
|
|
|
|
android:icon="@drawable/ic_lock_closed"
|
|
|
|
android:title="@string/user_restrictions_title" />
|
|
|
|
+ <SwitchPreference
|
|
|
|
+ android:icon="@drawable/ic_settings_install"
|
|
|
|
+ android:key="disallow_install_apps"
|
|
|
|
+ android:title="@string/user_disallow_install_apps" />
|
|
|
|
<com.android.settingslib.RestrictedPreference
|
|
|
|
android:key="app_copying"
|
|
|
|
android:icon="@drawable/ic_apps"
|
|
|
|
diff --git a/src/com/android/settings/users/UserDetailsSettings.java b/src/com/android/settings/users/UserDetailsSettings.java
|
2022-12-10 20:39:50 -05:00
|
|
|
index 3f51b83b9d..b6f87dcc11 100644
|
2022-10-15 07:53:14 -04:00
|
|
|
--- a/src/com/android/settings/users/UserDetailsSettings.java
|
|
|
|
+++ b/src/com/android/settings/users/UserDetailsSettings.java
|
|
|
|
@@ -64,6 +64,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
|
|
|
private static final String KEY_REMOVE_USER = "remove_user";
|
|
|
|
private static final String KEY_APP_AND_CONTENT_ACCESS = "app_and_content_access";
|
|
|
|
private static final String KEY_APP_COPYING = "app_copying";
|
|
|
|
+ private static final String KEY_DISALLOW_INSTALL_APPS = "disallow_install_apps";
|
|
|
|
|
|
|
|
/** Integer extra containing the userId to manage */
|
|
|
|
static final String EXTRA_USER_ID = "user_id";
|
2022-12-10 20:39:50 -05:00
|
|
|
@@ -93,6 +94,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
2022-10-15 07:53:14 -04:00
|
|
|
Preference mAppCopyingPref;
|
|
|
|
@VisibleForTesting
|
|
|
|
Preference mRemoveUserPref;
|
|
|
|
+ private SwitchPreference mInstallAppsPref;
|
|
|
|
|
|
|
|
@VisibleForTesting
|
|
|
|
/** The user being studied (not the user doing the studying). */
|
2022-12-10 20:39:50 -05:00
|
|
|
@@ -165,12 +167,37 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
2022-10-15 07:53:14 -04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
- if (Boolean.TRUE.equals(newValue)) {
|
|
|
|
- showDialog(mUserInfo.isGuest() ? DIALOG_CONFIRM_ENABLE_CALLING
|
|
|
|
- : DIALOG_CONFIRM_ENABLE_CALLING_AND_SMS);
|
|
|
|
- return false;
|
|
|
|
+ if (preference == mPhonePref) {
|
|
|
|
+ if (Boolean.TRUE.equals(newValue)) {
|
|
|
|
+ showDialog(mUserInfo.isGuest() ? DIALOG_CONFIRM_ENABLE_CALLING
|
|
|
|
+ : DIALOG_CONFIRM_ENABLE_CALLING_AND_SMS);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ enableCallsAndSms(false);
|
|
|
|
+ } else if (preference == mInstallAppsPref) {
|
|
|
|
+ if (mUserInfo.isGuest()) {
|
|
|
|
+ mDefaultGuestRestrictions.putBoolean(UserManager.DISALLOW_INSTALL_APPS, (Boolean) newValue);
|
|
|
|
+ mUserManager.setDefaultGuestRestrictions(mDefaultGuestRestrictions);
|
|
|
|
+
|
|
|
|
+ // Update the guest's restrictions, if there is a guest
|
|
|
|
+ // TODO: Maybe setDefaultGuestRestrictions() can internally just set the restrictions
|
|
|
|
+ // on any existing guest rather than do it here with multiple Binder calls.
|
|
|
|
+ List<UserInfo> users = mUserManager.getUsers(true);
|
|
|
|
+ for (UserInfo user: users) {
|
|
|
|
+ if (user.isGuest()) {
|
|
|
|
+ UserHandle userHandle = UserHandle.of(user.id);
|
|
|
|
+ for (String key : mDefaultGuestRestrictions.keySet()) {
|
|
|
|
+ mUserManager.setUserRestriction(
|
|
|
|
+ key, mDefaultGuestRestrictions.getBoolean(key), userHandle);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ UserHandle userHandle = UserHandle.of(mUserInfo.id);
|
|
|
|
+ mUserManager.setUserRestriction(UserManager.DISALLOW_INSTALL_APPS, (Boolean) newValue,
|
|
|
|
+ userHandle);
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
- enableCallsAndSms(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-12-10 20:39:50 -05:00
|
|
|
@@ -273,6 +300,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
2022-10-15 07:53:14 -04:00
|
|
|
mRemoveUserPref = findPreference(KEY_REMOVE_USER);
|
|
|
|
mAppAndContentAccessPref = findPreference(KEY_APP_AND_CONTENT_ACCESS);
|
|
|
|
mAppCopyingPref = findPreference(KEY_APP_COPYING);
|
|
|
|
+ mInstallAppsPref = findPreference(KEY_DISALLOW_INSTALL_APPS);
|
|
|
|
|
|
|
|
mSwitchUserPref.setTitle(
|
|
|
|
context.getString(com.android.settingslib.R.string.user_switch_to_user,
|
2022-12-10 20:39:50 -05:00
|
|
|
@@ -291,6 +319,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
2022-10-15 07:53:14 -04:00
|
|
|
removePreference(KEY_REMOVE_USER);
|
|
|
|
removePreference(KEY_APP_AND_CONTENT_ACCESS);
|
|
|
|
removePreference(KEY_APP_COPYING);
|
|
|
|
+ removePreference(KEY_DISALLOW_INSTALL_APPS);
|
|
|
|
} else {
|
|
|
|
if (!Utils.isVoiceCapable(context)) { // no telephony
|
|
|
|
removePreference(KEY_ENABLE_TELEPHONY);
|
2022-12-10 20:39:50 -05:00
|
|
|
@@ -324,11 +353,14 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
2022-10-15 07:53:14 -04:00
|
|
|
if (!SHOW_APP_COPYING_PREF) {
|
|
|
|
removePreference(KEY_APP_COPYING);
|
|
|
|
}
|
|
|
|
+ removePreference(KEY_DISALLOW_INSTALL_APPS);
|
|
|
|
} else {
|
|
|
|
mPhonePref.setChecked(!mUserManager.hasUserRestriction(
|
|
|
|
UserManager.DISALLOW_OUTGOING_CALLS, new UserHandle(userId)));
|
|
|
|
mRemoveUserPref.setTitle(R.string.user_remove_user);
|
|
|
|
removePreference(KEY_APP_COPYING);
|
|
|
|
+ mInstallAppsPref.setChecked(mUserManager.hasUserRestriction(
|
|
|
|
+ UserManager.DISALLOW_INSTALL_APPS, new UserHandle(userId)));
|
|
|
|
}
|
|
|
|
if (RestrictedLockUtilsInternal.hasBaseUserRestriction(context,
|
|
|
|
UserManager.DISALLOW_REMOVE_USER, UserHandle.myUserId())) {
|
2022-12-10 20:39:50 -05:00
|
|
|
@@ -339,6 +371,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
2022-10-15 07:53:14 -04:00
|
|
|
mPhonePref.setOnPreferenceChangeListener(this);
|
|
|
|
mAppAndContentAccessPref.setOnPreferenceClickListener(this);
|
|
|
|
mAppCopyingPref.setOnPreferenceClickListener(this);
|
|
|
|
+ mInstallAppsPref.setOnPreferenceChangeListener(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|