From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: flawedworld Date: Wed, 1 Sep 2021 20:36:10 +0000 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 d7f32ee3194..d723977899f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -7088,6 +7088,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 9280ff11632..d0a055fae29 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; } @@ -203,6 +230,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment mPhonePref = findPreference(KEY_ENABLE_TELEPHONY); mRemoveUserPref = findPreference(KEY_REMOVE_USER); mAppAndContentAccessPref = findPreference(KEY_APP_AND_CONTENT_ACCESS); + mInstallAppsPref = findPreference(KEY_DISALLOW_INSTALL_APPS); mSwitchUserPref.setTitle( context.getString(com.android.settingslib.R.string.user_switch_to_user, @@ -220,6 +248,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment removePreference(KEY_ENABLE_TELEPHONY); removePreference(KEY_REMOVE_USER); removePreference(KEY_APP_AND_CONTENT_ACCESS); + removePreference(KEY_DISALLOW_INSTALL_APPS); } else { if (!Utils.isVoiceCapable(context)) { // no telephony removePreference(KEY_ENABLE_TELEPHONY); @@ -244,10 +273,13 @@ public class UserDetailsSettings extends SettingsPreferenceFragment mPhonePref.setChecked( !mDefaultGuestRestrictions.getBoolean(UserManager.DISALLOW_OUTGOING_CALLS)); mRemoveUserPref.setTitle(R.string.user_exit_guest_title); + removePreference(KEY_DISALLOW_INSTALL_APPS); } else { mPhonePref.setChecked(!mUserManager.hasUserRestriction( UserManager.DISALLOW_OUTGOING_CALLS, new UserHandle(userId))); mRemoveUserPref.setTitle(R.string.user_remove_user); + mInstallAppsPref.setChecked(mUserManager.hasUserRestriction( + UserManager.DISALLOW_INSTALL_APPS, new UserHandle(userId))); } if (RestrictedLockUtilsInternal.hasBaseUserRestriction(context, UserManager.DISALLOW_REMOVE_USER, UserHandle.myUserId())) { @@ -257,6 +289,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment mRemoveUserPref.setOnPreferenceClickListener(this); mPhonePref.setOnPreferenceChangeListener(this); mAppAndContentAccessPref.setOnPreferenceClickListener(this); + mInstallAppsPref.setOnPreferenceChangeListener(this); } }