summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/users
diff options
context:
space:
mode:
authorAndras Kloczl <andraskloczl@google.com>2020-05-20 19:49:53 +0100
committerAndras Kloczl <andraskloczl@google.com>2020-06-09 23:06:00 +0000
commit4e2a0717c96d0448a26ad0985815291fbd089a02 (patch)
treec198fcb94580b73ca9d055f358c54a7e4f2751d9 /src/com/android/settings/users
parent03b20f864a3e5e349c5f7fc7c7c4a5109515130a (diff)
downloadpackages_apps_Settings-4e2a0717c96d0448a26ad0985815291fbd089a02.tar.gz
packages_apps_Settings-4e2a0717c96d0448a26ad0985815291fbd089a02.tar.bz2
packages_apps_Settings-4e2a0717c96d0448a26ad0985815291fbd089a02.zip
Change user setup prompt dialog showing logic
- Extract user setup prompt dialog creation logic - Move user setup prompt dialog showing to UserDetailsSettings - Rename user click and creation related methods to improve readability - Set "disabled by admin" for switch pref when switch is disabled - Cleanup UserSettings and UserDetailsSettings onPreferenceClick - After a guest is created the details page opens instead of switching Test: Manual test and robo tests with this command: make -j64 RunSettingsRoboTests Demo: http://shortn/_ACYsnbIKO9 Bug: 156867277 Change-Id: Ifa0cdefcd49d5b865e940a7cc332136ed26ecf57
Diffstat (limited to 'src/com/android/settings/users')
-rw-r--r--src/com/android/settings/users/UserDetailsSettings.java48
-rw-r--r--src/com/android/settings/users/UserDialogs.java17
-rw-r--r--src/com/android/settings/users/UserSettings.java144
3 files changed, 88 insertions, 121 deletions
diff --git a/src/com/android/settings/users/UserDetailsSettings.java b/src/com/android/settings/users/UserDetailsSettings.java
index c7cf90d725..897b3c7b83 100644
--- a/src/com/android/settings/users/UserDetailsSettings.java
+++ b/src/com/android/settings/users/UserDetailsSettings.java
@@ -39,6 +39,7 @@ import com.android.settings.Utils;
import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtilsInternal;
+import com.android.settingslib.RestrictedPreference;
import java.util.List;
@@ -65,10 +66,13 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
private static final int DIALOG_CONFIRM_REMOVE = 1;
private static final int DIALOG_CONFIRM_ENABLE_CALLING = 2;
private static final int DIALOG_CONFIRM_ENABLE_CALLING_AND_SMS = 3;
+ private static final int DIALOG_SETUP_USER = 4;
private UserManager mUserManager;
+ private UserCapabilities mUserCaps;
+
@VisibleForTesting
- Preference mSwitchUserPref;
+ RestrictedPreference mSwitchUserPref;
private SwitchPreference mPhonePref;
@VisibleForTesting
Preference mAppAndContentAccessPref;
@@ -90,6 +94,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
final Context context = getActivity();
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
+ mUserCaps = UserCapabilities.create(context);
addPreferencesFromResource(R.xml.user_details_settings);
initialize(context, getArguments());
@@ -106,15 +111,20 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
if (preference == mRemoveUserPref) {
if (canDeleteUser()) {
showDialog(DIALOG_CONFIRM_REMOVE);
+ return true;
}
- return true;
} else if (preference == mSwitchUserPref) {
if (canSwitchUserNow()) {
- switchUser();
+ if (shouldShowSetupPromptDialog()) {
+ showDialog(DIALOG_SETUP_USER);
+ } else {
+ switchUser();
+ }
+ return true;
}
- return true;
} else if (preference == mAppAndContentAccessPref) {
openAppAndContentAccessScreen(false);
+ return true;
}
return false;
}
@@ -139,6 +149,8 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
return SettingsEnums.DIALOG_USER_ENABLE_CALLING;
case DIALOG_CONFIRM_ENABLE_CALLING_AND_SMS:
return SettingsEnums.DIALOG_USER_ENABLE_CALLING_AND_SMS;
+ case DIALOG_SETUP_USER:
+ return SettingsEnums.DIALOG_USER_SETUP;
default:
return 0;
}
@@ -160,6 +172,13 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
case DIALOG_CONFIRM_ENABLE_CALLING_AND_SMS:
return UserDialogs.createEnablePhoneCallsAndSmsDialog(getActivity(),
(dialog, which) -> enableCallsAndSms(true));
+ case DIALOG_SETUP_USER:
+ return UserDialogs.createSetupUserDialog(getActivity(),
+ (dialog, which) -> {
+ if (canSwitchUserNow()) {
+ switchUser();
+ }
+ });
}
throw new IllegalArgumentException("Unsupported dialogId " + dialogId);
}
@@ -188,7 +207,14 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
mSwitchUserPref.setTitle(
context.getString(com.android.settingslib.R.string.user_switch_to_user,
mUserInfo.name));
- mSwitchUserPref.setOnPreferenceClickListener(this);
+
+ if (mUserCaps.mDisallowSwitchUser) {
+ mSwitchUserPref.setDisabledByAdmin(RestrictedLockUtilsInternal.getDeviceOwner(context));
+ } else {
+ mSwitchUserPref.setDisabledByAdmin(null);
+ mSwitchUserPref.setSelectable(true);
+ mSwitchUserPref.setOnPreferenceClickListener(this);
+ }
if (!mUserManager.isAdminUser()) { // non admin users can't remove users and allow calls
removePreference(KEY_ENABLE_TELEPHONY);
@@ -321,4 +347,16 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
.setSourceMetricsCategory(getMetricsCategory())
.launch();
}
+
+ private boolean isSecondaryUser(UserInfo user) {
+ return UserManager.USER_TYPE_FULL_SECONDARY.equals(user.userType);
+ }
+
+ private boolean shouldShowSetupPromptDialog() {
+ // TODO: FLAG_INITIALIZED is set when a user is switched to for the first time,
+ // but what we would really need here is a flag that shows if the setup process was
+ // completed. After the user cancels the setup process, mUserInfo.isInitialized() will
+ // return true so there will be no setup prompt dialog shown to the user anymore.
+ return isSecondaryUser(mUserInfo) && !mUserInfo.isInitialized();
+ }
}
diff --git a/src/com/android/settings/users/UserDialogs.java b/src/com/android/settings/users/UserDialogs.java
index 2361e449a7..0fb96369ef 100644
--- a/src/com/android/settings/users/UserDialogs.java
+++ b/src/com/android/settings/users/UserDialogs.java
@@ -138,4 +138,21 @@ public final class UserDialogs {
.setNegativeButton(android.R.string.cancel, null)
.create();
}
+
+ /**
+ * Creates a dialog to confirm that the user is ok to start setting up a new user.
+ *
+ * @param onConfirmListener Callback object for positive action
+ */
+ public static Dialog createSetupUserDialog(Context context,
+ DialogInterface.OnClickListener onConfirmListener) {
+ return new AlertDialog.Builder(context)
+ .setTitle(com.android.settingslib.R.string.user_setup_dialog_title)
+ .setMessage(com.android.settingslib.R.string.user_setup_dialog_message)
+ .setPositiveButton(com.android.settingslib.R.string.user_setup_button_setup_now,
+ onConfirmListener)
+ .setNegativeButton(com.android.settingslib.R.string.user_setup_button_setup_later,
+ null)
+ .create();
+ }
}
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index 719ed4aa92..910917a3ad 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -102,8 +102,6 @@ public class UserSettings extends SettingsPreferenceFragment
/** UserId of the user being removed */
private static final String SAVE_REMOVING_USER = "removing_user";
- /** UserId of the user that was just added */
- private static final String SAVE_ADDING_USER = "adding_user";
private static final String KEY_USER_LIST = "user_list";
private static final String KEY_USER_ME = "user_me";
@@ -119,8 +117,7 @@ public class UserSettings extends SettingsPreferenceFragment
private static final int DIALOG_CONFIRM_REMOVE = 1;
private static final int DIALOG_ADD_USER = 2;
- private static final int DIALOG_SETUP_USER = 3;
- private static final int DIALOG_SETUP_PROFILE = 4;
+ // Dialogs with id 3 and 4 got removed
private static final int DIALOG_USER_CANNOT_MANAGE = 5;
private static final int DIALOG_CHOOSE_USER_TYPE = 6;
private static final int DIALOG_NEED_LOCKSCREEN = 7;
@@ -130,8 +127,7 @@ public class UserSettings extends SettingsPreferenceFragment
private static final int DIALOG_USER_PROFILE_EDITOR_ADD_RESTRICTED_PROFILE = 11;
private static final int MESSAGE_UPDATE_LIST = 1;
- private static final int MESSAGE_SETUP_USER = 2;
- private static final int MESSAGE_CONFIG_USER = 3;
+ private static final int MESSAGE_USER_CREATED = 2;
private static final int USER_TYPE_USER = 1;
private static final int USER_TYPE_RESTRICTED_PROFILE = 2;
@@ -160,7 +156,6 @@ public class UserSettings extends SettingsPreferenceFragment
@VisibleForTesting
SparseArray<Bitmap> mUserIcons = new SparseArray<>();
private int mRemovingUserId = -1;
- private int mAddedUserId = 0;
private boolean mAddingUser;
private String mAddingUserName;
private UserCapabilities mUserCaps;
@@ -187,12 +182,9 @@ public class UserSettings extends SettingsPreferenceFragment
case MESSAGE_UPDATE_LIST:
updateUserList();
break;
- case MESSAGE_SETUP_USER:
+ case MESSAGE_USER_CREATED:
onUserCreated(msg.arg1);
break;
- case MESSAGE_CONFIG_USER:
- onManageUserClicked(msg.arg1, true);
- break;
}
}
};
@@ -254,9 +246,6 @@ public class UserSettings extends SettingsPreferenceFragment
.setOnPreferenceChangeListener(mAddUserWhenLockedPreferenceController);
if (icicle != null) {
- if (icicle.containsKey(SAVE_ADDING_USER)) {
- mAddedUserId = icicle.getInt(SAVE_ADDING_USER);
- }
if (icicle.containsKey(SAVE_REMOVING_USER)) {
mRemovingUserId = icicle.getInt(SAVE_REMOVING_USER);
}
@@ -334,7 +323,6 @@ public class UserSettings extends SettingsPreferenceFragment
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mEditUserInfoController.onSaveInstanceState(outState);
- outState.putInt(SAVE_ADDING_USER, mAddedUserId);
outState.putInt(SAVE_REMOVING_USER, mRemovingUserId);
}
@@ -482,37 +470,22 @@ public class UserSettings extends SettingsPreferenceFragment
}
}
- private void onManageUserClicked(int userId, boolean newUser) {
+ private void onUserCreated(int userId) {
mAddingUser = false;
UserInfo userInfo = mUserManager.getUserInfo(userId);
- if (userId == UserHandle.myUserId()) {
- // Jump to owner info panel
- OwnerInfoSettings.show(this);
- } else {
- Bundle extras = new Bundle();
- extras.putInt(UserDetailsSettings.EXTRA_USER_ID, userId);
- extras.putBoolean(AppRestrictionsFragment.EXTRA_NEW_USER, newUser);
- new SubSettingLauncher(getContext())
- .setDestination(UserDetailsSettings.class.getName())
- .setArguments(extras)
- .setTitleText(userInfo.name)
- .setSourceMetricsCategory(getMetricsCategory())
- .launch();
- }
+ openUserDetails(userInfo, true);
}
- private void onUserCreated(int userId) {
- mAddedUserId = userId;
- mAddingUser = false;
- if (!isResumed()) {
- Log.w(TAG, "Cannot show dialog after onPause");
- return;
- }
- if (mUserManager.getUserInfo(userId).isRestricted()) {
- showDialog(DIALOG_SETUP_PROFILE);
- } else {
- showDialog(DIALOG_SETUP_USER);
- }
+ private void openUserDetails(UserInfo userInfo, boolean newUser) {
+ Bundle extras = new Bundle();
+ extras.putInt(UserDetailsSettings.EXTRA_USER_ID, userInfo.id);
+ extras.putBoolean(AppRestrictionsFragment.EXTRA_NEW_USER, newUser);
+ new SubSettingLauncher(getContext())
+ .setDestination(UserDetailsSettings.class.getName())
+ .setArguments(extras)
+ .setTitleText(userInfo.name)
+ .setSourceMetricsCategory(getMetricsCategory())
+ .launch();
}
@Override
@@ -571,37 +544,6 @@ public class UserSettings extends SettingsPreferenceFragment
.create();
return dlg;
}
- case DIALOG_SETUP_USER: {
- Dialog dlg = new AlertDialog.Builder(context)
- .setTitle(com.android.settingslib.R.string.user_setup_dialog_title)
- .setMessage(com.android.settingslib.R.string.user_setup_dialog_message)
- .setPositiveButton(
- com.android.settingslib.R.string.user_setup_button_setup_now,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- switchUserNow(mAddedUserId);
- }
- })
- .setNegativeButton(
- com.android.settingslib.R.string.user_setup_button_setup_later,
- null)
- .create();
- return dlg;
- }
- case DIALOG_SETUP_PROFILE: {
- Dialog dlg = new AlertDialog.Builder(context)
- .setMessage(
- com.android.settingslib.R.string.user_setup_profile_dialog_message)
- .setPositiveButton(android.R.string.ok,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- switchUserNow(mAddedUserId);
- }
- })
- .setNegativeButton(android.R.string.cancel, null)
- .create();
- return dlg;
- }
case DIALOG_CHOOSE_USER_TYPE: {
List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
HashMap<String, String> addUserItem = new HashMap<String, String>();
@@ -764,10 +706,6 @@ public class UserSettings extends SettingsPreferenceFragment
return SettingsEnums.DIALOG_USER_CANNOT_MANAGE;
case DIALOG_ADD_USER:
return SettingsEnums.DIALOG_USER_ADD;
- case DIALOG_SETUP_USER:
- return SettingsEnums.DIALOG_USER_SETUP;
- case DIALOG_SETUP_PROFILE:
- return SettingsEnums.DIALOG_USER_SETUP_PROFILE;
case DIALOG_CHOOSE_USER_TYPE:
return SettingsEnums.DIALOG_USER_CHOOSE_TYPE;
case DIALOG_NEED_LOCKSCREEN:
@@ -853,16 +791,11 @@ public class UserSettings extends SettingsPreferenceFragment
if (userType == USER_TYPE_USER) {
mHandler.sendEmptyMessage(MESSAGE_UPDATE_LIST);
- // Skip setting up user which results in user switching when the
- // restriction is set.
- if (!mUserCaps.mDisallowSwitchUser) {
- mHandler.sendMessage(mHandler.obtainMessage(
- MESSAGE_SETUP_USER, user.id, user.serialNumber));
- }
- } else {
- mHandler.sendMessage(mHandler.obtainMessage(
- MESSAGE_CONFIG_USER, user.id, user.serialNumber));
}
+
+ mHandler.sendMessage(mHandler.obtainMessage(
+ MESSAGE_USER_CREATED, user.id, user.serialNumber));
+
mPendingUserIcon = null;
mPendingUserName = null;
}
@@ -870,18 +803,6 @@ public class UserSettings extends SettingsPreferenceFragment
});
}
- private void switchUserNow(int userId) {
- if (!canSwitchUserNow()) {
- return;
- }
-
- try {
- ActivityManager.getService().switchUser(userId);
- } catch (RemoteException re) {
- Log.e(TAG, "Error while switching to other user.");
- }
- }
-
/**
* Erase the current user (guest) and switch to another user.
*/
@@ -1125,21 +1046,14 @@ public class UserSettings extends SettingsPreferenceFragment
if (pref == mMePreference) {
if (isCurrentUserGuest()) {
showDialog(DIALOG_CONFIRM_EXIT_GUEST);
- return true;
- }
- showDialog(DIALOG_USER_PROFILE_EDITOR);
- } else if (pref instanceof UserPreference) {
- int userId = ((UserPreference) pref).getUserId();
- // Get the latest status of the user
- UserInfo user = mUserManager.getUserInfo(userId);
- if (!user.isInitialized() && isSecondaryUser(user)) {
- // for uninitialized secondary users we should show a prompt dialog before
- // starting the setup
- mHandler.sendMessage(mHandler.obtainMessage(
- MESSAGE_SETUP_USER, user.id, user.serialNumber));
} else {
- onManageUserClicked(userId, false);
+ showDialog(DIALOG_USER_PROFILE_EDITOR);
}
+ return true;
+ } else if (pref instanceof UserPreference) {
+ UserInfo userInfo = mUserManager.getUserInfo(((UserPreference) pref).getUserId());
+ openUserDetails(userInfo, false);
+ return true;
} else if (pref == mAddUser) {
// If we allow both types, show a picker, otherwise directly go to
// flow for full user.
@@ -1148,10 +1062,12 @@ public class UserSettings extends SettingsPreferenceFragment
} else {
onAddUserClicked(USER_TYPE_USER);
}
+ return true;
} else if (pref == mAddGuest) {
UserInfo guest = mUserManager.createGuest(
getContext(), getString(com.android.settingslib.R.string.user_guest));
- switchUserNow(guest.id);
+ openUserDetails(guest, true);
+ return true;
}
return false;
}
@@ -1265,8 +1181,4 @@ public class UserSettings extends SettingsPreferenceFragment
return niks;
}
};
-
- private boolean isSecondaryUser(UserInfo user) {
- return UserManager.USER_TYPE_FULL_SECONDARY.equals(user.userType);
- }
}