From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: flawedworld 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 index 77aafa7622..f301adc9e4 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -8017,6 +8017,8 @@ Turn on phone calls Turn on phone calls & SMS + + Disallow installing apps Delete user 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" /> + 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; } @@ -273,6 +300,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment 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, @@ -291,6 +319,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment 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); @@ -324,11 +353,14 @@ public class UserDetailsSettings extends SettingsPreferenceFragment 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())) { @@ -339,6 +371,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment mPhonePref.setOnPreferenceChangeListener(this); mAppAndContentAccessPref.setOnPreferenceClickListener(this); mAppCopyingPref.setOnPreferenceClickListener(this); + mInstallAppsPref.setOnPreferenceChangeListener(this); } }