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 406165be65..3cad5ba33b 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -7741,6 +7741,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 9280ff1163..d0a055fae2 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; } @@ -241,6 +268,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, @@ -258,6 +286,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); @@ -288,10 +317,13 @@ public class UserDetailsSettings extends SettingsPreferenceFragment if (mGuestUserAutoCreated) { mRemoveUserPref.setEnabled((mUserInfo.flags & UserInfo.FLAG_INITIALIZED) != 0); } + 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())) { @@ -301,6 +333,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment mRemoveUserPref.setOnPreferenceClickListener(this); mPhonePref.setOnPreferenceChangeListener(this); mAppAndContentAccessPref.setOnPreferenceClickListener(this); + mInstallAppsPref.setOnPreferenceChangeListener(this); } }