Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.settings.users; |
| 18 | |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame] | 19 | import java.util.ArrayList; |
| 20 | import java.util.HashMap; |
| 21 | import java.util.List; |
| 22 | |
Amith Yamasani | 233592b | 2013-03-01 17:05:23 -0800 | [diff] [blame] | 23 | import android.accounts.Account; |
| 24 | import android.accounts.AccountManager; |
Amith Yamasani | f162efe | 2013-04-29 10:43:05 -0700 | [diff] [blame] | 25 | import android.app.Activity; |
Amith Yamasani | ae47ef4 | 2012-09-16 17:53:35 -0700 | [diff] [blame] | 26 | import android.app.ActivityManagerNative; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 27 | import android.app.AlertDialog; |
| 28 | import android.app.Dialog; |
Amith Yamasani | f162efe | 2013-04-29 10:43:05 -0700 | [diff] [blame] | 29 | import android.app.admin.DevicePolicyManager; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 30 | import android.content.BroadcastReceiver; |
Amith Yamasani | 3263039 | 2012-08-10 19:31:39 -0700 | [diff] [blame] | 31 | import android.content.Context; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 32 | import android.content.DialogInterface; |
| 33 | import android.content.Intent; |
| 34 | import android.content.IntentFilter; |
Svetoslav Ganov | 263f744 | 2012-09-25 16:11:16 -0700 | [diff] [blame] | 35 | import android.content.SharedPreferences; |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 36 | import android.content.pm.UserInfo; |
Amith Yamasani | 5cdc937 | 2012-11-14 16:23:40 -0800 | [diff] [blame] | 37 | import android.content.res.Resources; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 38 | import android.graphics.Bitmap; |
| 39 | import android.graphics.BitmapFactory; |
Amith Yamasani | 48fa857 | 2012-04-17 17:12:01 -0700 | [diff] [blame] | 40 | import android.graphics.drawable.Drawable; |
Amith Yamasani | 32dccbc | 2012-09-13 18:06:49 -0700 | [diff] [blame] | 41 | import android.os.AsyncTask; |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 43 | import android.os.Handler; |
| 44 | import android.os.Message; |
Amith Yamasani | ae47ef4 | 2012-09-16 17:53:35 -0700 | [diff] [blame] | 45 | import android.os.RemoteException; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 46 | import android.os.UserHandle; |
Amith Yamasani | 3263039 | 2012-08-10 19:31:39 -0700 | [diff] [blame] | 47 | import android.os.UserManager; |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 48 | import android.preference.Preference; |
| 49 | import android.preference.Preference.OnPreferenceClickListener; |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 50 | import android.preference.PreferenceGroup; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 51 | import android.provider.ContactsContract; |
| 52 | import android.provider.ContactsContract.Contacts; |
Amith Yamasani | 1bad714 | 2013-04-22 13:37:58 -0700 | [diff] [blame] | 53 | import android.provider.Settings.Secure; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 54 | import android.util.Log; |
Amith Yamasani | f34a85d | 2012-09-17 18:31:45 -0700 | [diff] [blame] | 55 | import android.util.SparseArray; |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 56 | import android.view.Menu; |
| 57 | import android.view.MenuInflater; |
| 58 | import android.view.MenuItem; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 59 | import android.view.View; |
| 60 | import android.view.View.OnClickListener; |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 61 | import android.widget.SimpleAdapter; |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 62 | |
Amith Yamasani | f162efe | 2013-04-29 10:43:05 -0700 | [diff] [blame] | 63 | import com.android.internal.widget.LockPatternUtils; |
| 64 | import com.android.settings.ChooseLockGeneric; |
Amith Yamasani | d4abdd2 | 2013-04-17 18:27:01 -0700 | [diff] [blame] | 65 | import com.android.settings.OwnerInfoSettings; |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 66 | import com.android.settings.R; |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 67 | import com.android.settings.SelectableEditTextPreference; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 68 | import com.android.settings.SettingsActivity; |
Julia Reynolds | b9195d2 | 2014-06-11 16:18:16 -0400 | [diff] [blame] | 69 | import com.android.settings.SettingsPreferenceFragment; |
Amith Yamasani | ae47ef4 | 2012-09-16 17:53:35 -0700 | [diff] [blame] | 70 | import com.android.settings.Utils; |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 71 | |
Julia Reynolds | b9195d2 | 2014-06-11 16:18:16 -0400 | [diff] [blame] | 72 | public class UserSettings extends SettingsPreferenceFragment |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 73 | implements OnPreferenceClickListener, OnClickListener, DialogInterface.OnDismissListener, |
| 74 | Preference.OnPreferenceChangeListener { |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 75 | |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 76 | private static final String TAG = "UserSettings"; |
| 77 | |
Amith Yamasani | c861cf8 | 2012-10-02 14:51:46 -0700 | [diff] [blame] | 78 | /** UserId of the user being removed */ |
| 79 | private static final String SAVE_REMOVING_USER = "removing_user"; |
| 80 | /** UserId of the user that was just added */ |
| 81 | private static final String SAVE_ADDING_USER = "adding_user"; |
| 82 | |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 83 | private static final String KEY_USER_LIST = "user_list"; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 84 | private static final String KEY_USER_ME = "user_me"; |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 85 | private static final String KEY_ADD_USER = "user_add"; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 86 | |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 87 | private static final int MENU_REMOVE_USER = Menu.FIRST; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 88 | |
| 89 | private static final int DIALOG_CONFIRM_REMOVE = 1; |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 90 | private static final int DIALOG_ADD_USER = 2; |
| 91 | private static final int DIALOG_SETUP_USER = 3; |
| 92 | private static final int DIALOG_SETUP_PROFILE = 4; |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 93 | private static final int DIALOG_USER_CANNOT_MANAGE = 5; |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 94 | private static final int DIALOG_CHOOSE_USER_TYPE = 6; |
Amith Yamasani | f162efe | 2013-04-29 10:43:05 -0700 | [diff] [blame] | 95 | private static final int DIALOG_NEED_LOCKSCREEN = 7; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 96 | |
| 97 | private static final int MESSAGE_UPDATE_LIST = 1; |
Amith Yamasani | ae47ef4 | 2012-09-16 17:53:35 -0700 | [diff] [blame] | 98 | private static final int MESSAGE_SETUP_USER = 2; |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 99 | private static final int MESSAGE_CONFIG_USER = 3; |
| 100 | |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 101 | private static final int USER_TYPE_USER = 1; |
| 102 | private static final int USER_TYPE_RESTRICTED_PROFILE = 2; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 103 | |
Amith Yamasani | f162efe | 2013-04-29 10:43:05 -0700 | [diff] [blame] | 104 | private static final int REQUEST_CHOOSE_LOCK = 10; |
| 105 | |
Svetoslav Ganov | 263f744 | 2012-09-25 16:11:16 -0700 | [diff] [blame] | 106 | private static final String KEY_ADD_USER_LONG_MESSAGE_DISPLAYED = |
| 107 | "key_add_user_long_message_displayed"; |
| 108 | |
Amith Yamasani | 233592b | 2013-03-01 17:05:23 -0800 | [diff] [blame] | 109 | static final int[] USER_DRAWABLES = { |
Amith Yamasani | 95dc473 | 2012-10-02 21:10:48 -0700 | [diff] [blame] | 110 | R.drawable.avatar_default_1, |
| 111 | R.drawable.avatar_default_2, |
| 112 | R.drawable.avatar_default_3, |
| 113 | R.drawable.avatar_default_4, |
| 114 | R.drawable.avatar_default_5, |
| 115 | R.drawable.avatar_default_6, |
| 116 | R.drawable.avatar_default_7, |
| 117 | R.drawable.avatar_default_8 |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 120 | private static final String KEY_TITLE = "title"; |
| 121 | private static final String KEY_SUMMARY = "summary"; |
| 122 | |
| 123 | private PreferenceGroup mUserListCategory; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 124 | private Preference mMePreference; |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 125 | private SelectableEditTextPreference mNicknamePreference; |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 126 | private Preference mAddUser; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 127 | private int mRemovingUserId = -1; |
Amith Yamasani | ae47ef4 | 2012-09-16 17:53:35 -0700 | [diff] [blame] | 128 | private int mAddedUserId = 0; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 129 | private boolean mAddingUser; |
Amith Yamasani | 32dccbc | 2012-09-13 18:06:49 -0700 | [diff] [blame] | 130 | private boolean mProfileExists; |
Amith Yamasani | cfb8d7f | 2014-03-26 14:46:47 -0700 | [diff] [blame] | 131 | private boolean mEnabled = true; |
Amith Yamasani | 0e43d32 | 2014-05-07 10:19:34 -0700 | [diff] [blame] | 132 | private boolean mCanAddRestrictedProfile = true; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 133 | |
| 134 | private final Object mUserLock = new Object(); |
| 135 | private UserManager mUserManager; |
Amith Yamasani | 864e3b7 | 2013-03-27 12:27:01 -0700 | [diff] [blame] | 136 | private SparseArray<Bitmap> mUserIcons = new SparseArray<Bitmap>(); |
Amith Yamasani | 8666b9e | 2012-09-27 14:50:13 -0700 | [diff] [blame] | 137 | private boolean mIsOwner = UserHandle.myUserId() == UserHandle.USER_OWNER; |
Amith Yamasani | 9e6ac3d | 2014-06-30 15:31:37 +0530 | [diff] [blame] | 138 | private boolean mIsGuest; |
Amith Yamasani | 8666b9e | 2012-09-27 14:50:13 -0700 | [diff] [blame] | 139 | |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 140 | private Handler mHandler = new Handler() { |
| 141 | @Override |
| 142 | public void handleMessage(Message msg) { |
| 143 | switch (msg.what) { |
| 144 | case MESSAGE_UPDATE_LIST: |
| 145 | updateUserList(); |
| 146 | break; |
Amith Yamasani | ae47ef4 | 2012-09-16 17:53:35 -0700 | [diff] [blame] | 147 | case MESSAGE_SETUP_USER: |
| 148 | onUserCreated(msg.arg1); |
| 149 | break; |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 150 | case MESSAGE_CONFIG_USER: |
| 151 | onManageUserClicked(msg.arg1, true); |
| 152 | break; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | }; |
| 156 | |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 157 | private BroadcastReceiver mUserChangeReceiver = new BroadcastReceiver() { |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 158 | @Override |
| 159 | public void onReceive(Context context, Intent intent) { |
Amith Yamasani | f34a85d | 2012-09-17 18:31:45 -0700 | [diff] [blame] | 160 | if (intent.getAction().equals(Intent.ACTION_USER_REMOVED)) { |
| 161 | mRemovingUserId = -1; |
| 162 | } else if (intent.getAction().equals(Intent.ACTION_USER_INFO_CHANGED)) { |
| 163 | int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1); |
| 164 | if (userHandle != -1) { |
| 165 | mUserIcons.remove(userHandle); |
| 166 | } |
| 167 | } |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 168 | mHandler.sendEmptyMessage(MESSAGE_UPDATE_LIST); |
| 169 | } |
| 170 | }; |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 171 | |
| 172 | @Override |
| 173 | public void onCreate(Bundle icicle) { |
| 174 | super.onCreate(icicle); |
Amith Yamasani | 8666b9e | 2012-09-27 14:50:13 -0700 | [diff] [blame] | 175 | |
Amith Yamasani | c861cf8 | 2012-10-02 14:51:46 -0700 | [diff] [blame] | 176 | if (icicle != null) { |
| 177 | if (icicle.containsKey(SAVE_ADDING_USER)) { |
| 178 | mAddedUserId = icicle.getInt(SAVE_ADDING_USER); |
| 179 | } |
| 180 | if (icicle.containsKey(SAVE_REMOVING_USER)) { |
| 181 | mRemovingUserId = icicle.getInt(SAVE_REMOVING_USER); |
| 182 | } |
| 183 | } |
Amith Yamasani | 0e43d32 | 2014-05-07 10:19:34 -0700 | [diff] [blame] | 184 | final Context context = getActivity(); |
| 185 | mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); |
Amith Yamasani | 4093e40 | 2014-06-06 14:31:37 -0700 | [diff] [blame] | 186 | boolean hasMultipleUsers = mUserManager.getUserCount() > 1; |
| 187 | if ((!UserManager.supportsMultipleUsers() && !hasMultipleUsers) |
| 188 | || Utils.isMonkeyRunning()) { |
Amith Yamasani | cfb8d7f | 2014-03-26 14:46:47 -0700 | [diff] [blame] | 189 | mEnabled = false; |
| 190 | return; |
| 191 | } |
Amith Yamasani | 0e43d32 | 2014-05-07 10:19:34 -0700 | [diff] [blame] | 192 | |
Amith Yamasani | 9e6ac3d | 2014-06-30 15:31:37 +0530 | [diff] [blame] | 193 | final int myUserId = UserHandle.myUserId(); |
| 194 | mIsGuest = mUserManager.getUserInfo(myUserId).isGuest(); |
| 195 | |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 196 | addPreferencesFromResource(R.xml.user_settings); |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 197 | mUserListCategory = (PreferenceGroup) findPreference(KEY_USER_LIST); |
Amith Yamasani | 9e6ac3d | 2014-06-30 15:31:37 +0530 | [diff] [blame] | 198 | mMePreference = new UserPreference(context, null, myUserId, |
Amith Yamasani | d4abdd2 | 2013-04-17 18:27:01 -0700 | [diff] [blame] | 199 | mUserManager.isLinkedUser() ? null : this, null); |
| 200 | mMePreference.setKey(KEY_USER_ME); |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 201 | mMePreference.setOnPreferenceClickListener(this); |
Amith Yamasani | d4abdd2 | 2013-04-17 18:27:01 -0700 | [diff] [blame] | 202 | if (mIsOwner) { |
| 203 | mMePreference.setSummary(R.string.user_owner); |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 204 | } |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 205 | mAddUser = findPreference(KEY_ADD_USER); |
Amith Yamasani | 4093e40 | 2014-06-06 14:31:37 -0700 | [diff] [blame] | 206 | if (!mIsOwner || UserManager.getMaxSupportedUsers() < 2 |
Julia Reynolds | b9195d2 | 2014-06-11 16:18:16 -0400 | [diff] [blame] | 207 | || !UserManager.supportsMultipleUsers() |
| 208 | || mUserManager.hasUserRestriction(UserManager.DISALLOW_ADD_USER)) { |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 209 | removePreference(KEY_ADD_USER); |
Amith Yamasani | 0e43d32 | 2014-05-07 10:19:34 -0700 | [diff] [blame] | 210 | } else { |
| 211 | mAddUser.setOnPreferenceClickListener(this); |
| 212 | DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService( |
| 213 | Context.DEVICE_POLICY_SERVICE); |
Amith Yamasani | 51c6dac | 2014-07-02 00:06:37 +0530 | [diff] [blame^] | 214 | // No restricted profiles for tablets with a device owner, or phones. |
| 215 | if (dpm.getDeviceOwner() != null || Utils.isVoiceCapable(context)) { |
Amith Yamasani | 0e43d32 | 2014-05-07 10:19:34 -0700 | [diff] [blame] | 216 | mCanAddRestrictedProfile = false; |
| 217 | mAddUser.setTitle(R.string.user_add_user_menu); |
| 218 | } |
Amith Yamasani | 233592b | 2013-03-01 17:05:23 -0800 | [diff] [blame] | 219 | } |
Amith Yamasani | 32dccbc | 2012-09-13 18:06:49 -0700 | [diff] [blame] | 220 | loadProfile(); |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 221 | setHasOptionsMenu(true); |
Amith Yamasani | f34a85d | 2012-09-17 18:31:45 -0700 | [diff] [blame] | 222 | IntentFilter filter = new IntentFilter(Intent.ACTION_USER_REMOVED); |
| 223 | filter.addAction(Intent.ACTION_USER_INFO_CHANGED); |
Amith Yamasani | 9e6ac3d | 2014-06-30 15:31:37 +0530 | [diff] [blame] | 224 | context.registerReceiverAsUser(mUserChangeReceiver, UserHandle.ALL, filter, null, |
Amith Yamasani | f34a85d | 2012-09-17 18:31:45 -0700 | [diff] [blame] | 225 | mHandler); |
Amith Yamasani | 0ca80fe | 2013-06-03 16:41:03 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | @Override |
| 229 | public void onResume() { |
| 230 | super.onResume(); |
Amith Yamasani | cfb8d7f | 2014-03-26 14:46:47 -0700 | [diff] [blame] | 231 | |
| 232 | if (!mEnabled) return; |
| 233 | |
Amith Yamasani | 0ca80fe | 2013-06-03 16:41:03 -0700 | [diff] [blame] | 234 | loadProfile(); |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 235 | updateUserList(); |
| 236 | } |
| 237 | |
| 238 | @Override |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 239 | public void onDestroy() { |
| 240 | super.onDestroy(); |
Amith Yamasani | cfb8d7f | 2014-03-26 14:46:47 -0700 | [diff] [blame] | 241 | |
| 242 | if (!mEnabled) return; |
| 243 | |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 244 | getActivity().unregisterReceiver(mUserChangeReceiver); |
| 245 | } |
| 246 | |
| 247 | @Override |
Amith Yamasani | c861cf8 | 2012-10-02 14:51:46 -0700 | [diff] [blame] | 248 | public void onSaveInstanceState(Bundle outState) { |
| 249 | super.onSaveInstanceState(outState); |
| 250 | |
| 251 | outState.putInt(SAVE_ADDING_USER, mAddedUserId); |
| 252 | outState.putInt(SAVE_REMOVING_USER, mRemovingUserId); |
| 253 | } |
| 254 | |
| 255 | @Override |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 256 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { |
Emily Bernier | 11bd33a | 2013-04-11 16:24:56 -0400 | [diff] [blame] | 257 | UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE); |
| 258 | if (!mIsOwner && !um.hasUserRestriction(UserManager.DISALLOW_REMOVE_USER)) { |
Amith Yamasani | 1a634d3 | 2012-09-27 23:01:35 -0700 | [diff] [blame] | 259 | String nickname = mUserManager.getUserName(); |
| 260 | MenuItem removeThisUser = menu.add(0, MENU_REMOVE_USER, 0, |
| 261 | getResources().getString(R.string.user_remove_user_menu, nickname)); |
| 262 | removeThisUser.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 263 | } |
Amith Yamasani | 38223dc | 2012-09-18 09:51:07 -0700 | [diff] [blame] | 264 | super.onCreateOptionsMenu(menu, inflater); |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | @Override |
| 268 | public boolean onOptionsItemSelected(MenuItem item) { |
| 269 | final int itemId = item.getItemId(); |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 270 | if (itemId == MENU_REMOVE_USER) { |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 271 | onRemoveUserClicked(UserHandle.myUserId()); |
| 272 | return true; |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 273 | } else { |
| 274 | return super.onOptionsItemSelected(item); |
| 275 | } |
| 276 | } |
| 277 | |
Amith Yamasani | 32dccbc | 2012-09-13 18:06:49 -0700 | [diff] [blame] | 278 | private void loadProfile() { |
| 279 | mProfileExists = false; |
| 280 | new AsyncTask<Void, Void, String>() { |
| 281 | @Override |
| 282 | protected void onPostExecute(String result) { |
| 283 | finishLoadProfile(result); |
| 284 | } |
| 285 | |
| 286 | @Override |
| 287 | protected String doInBackground(Void... values) { |
| 288 | UserInfo user = mUserManager.getUserInfo(UserHandle.myUserId()); |
| 289 | if (user.iconPath == null || user.iconPath.equals("")) { |
| 290 | assignProfilePhoto(user); |
| 291 | } |
| 292 | String profileName = getProfileName(); |
Amith Yamasani | d4abdd2 | 2013-04-17 18:27:01 -0700 | [diff] [blame] | 293 | if (profileName == null) { |
| 294 | profileName = user.name; |
| 295 | } |
Amith Yamasani | 32dccbc | 2012-09-13 18:06:49 -0700 | [diff] [blame] | 296 | return profileName; |
| 297 | } |
| 298 | }.execute(); |
| 299 | } |
| 300 | |
| 301 | private void finishLoadProfile(String profileName) { |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 302 | if (getActivity() == null) return; |
| 303 | mMePreference.setTitle(getString(R.string.user_you, profileName)); |
Amith Yamasani | f34a85d | 2012-09-17 18:31:45 -0700 | [diff] [blame] | 304 | int myUserId = UserHandle.myUserId(); |
| 305 | Bitmap b = mUserManager.getUserIcon(myUserId); |
| 306 | if (b != null) { |
Amith Yamasani | 864e3b7 | 2013-03-27 12:27:01 -0700 | [diff] [blame] | 307 | mMePreference.setIcon(encircle(b)); |
| 308 | mUserIcons.put(myUserId, b); |
Amith Yamasani | f34a85d | 2012-09-17 18:31:45 -0700 | [diff] [blame] | 309 | } |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Amith Yamasani | f162efe | 2013-04-29 10:43:05 -0700 | [diff] [blame] | 312 | private boolean hasLockscreenSecurity() { |
| 313 | LockPatternUtils lpu = new LockPatternUtils(getActivity()); |
| 314 | return lpu.isLockPasswordEnabled() || lpu.isLockPatternEnabled(); |
| 315 | } |
| 316 | |
| 317 | private void launchChooseLockscreen() { |
| 318 | Intent chooseLockIntent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD); |
| 319 | chooseLockIntent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.MINIMUM_QUALITY_KEY, |
| 320 | DevicePolicyManager.PASSWORD_QUALITY_SOMETHING); |
| 321 | startActivityForResult(chooseLockIntent, REQUEST_CHOOSE_LOCK); |
| 322 | } |
| 323 | |
| 324 | @Override |
| 325 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 326 | super.onActivityResult(requestCode, resultCode, data); |
| 327 | |
| 328 | if (requestCode == REQUEST_CHOOSE_LOCK) { |
| 329 | if (resultCode != Activity.RESULT_CANCELED && hasLockscreenSecurity()) { |
| 330 | addUserNow(USER_TYPE_RESTRICTED_PROFILE); |
Amith Yamasani | f162efe | 2013-04-29 10:43:05 -0700 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | } |
| 334 | |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 335 | private void onAddUserClicked(int userType) { |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 336 | synchronized (mUserLock) { |
| 337 | if (mRemovingUserId == -1 && !mAddingUser) { |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 338 | switch (userType) { |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 339 | case USER_TYPE_USER: |
| 340 | showDialog(DIALOG_ADD_USER); |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 341 | break; |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 342 | case USER_TYPE_RESTRICTED_PROFILE: |
Amith Yamasani | f162efe | 2013-04-29 10:43:05 -0700 | [diff] [blame] | 343 | if (hasLockscreenSecurity()) { |
| 344 | addUserNow(USER_TYPE_RESTRICTED_PROFILE); |
| 345 | } else { |
| 346 | showDialog(DIALOG_NEED_LOCKSCREEN); |
| 347 | } |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 348 | break; |
| 349 | } |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | private void onRemoveUserClicked(int userId) { |
| 355 | synchronized (mUserLock) { |
| 356 | if (mRemovingUserId == -1 && !mAddingUser) { |
| 357 | mRemovingUserId = userId; |
| 358 | showDialog(DIALOG_CONFIRM_REMOVE); |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 363 | private UserInfo createLimitedUser() { |
| 364 | UserInfo newUserInfo = mUserManager.createUser( |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 365 | getResources().getString(R.string.user_new_profile_name), |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 366 | UserInfo.FLAG_RESTRICTED); |
| 367 | int userId = newUserInfo.id; |
| 368 | UserHandle user = new UserHandle(userId); |
| 369 | mUserManager.setUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS, true, user); |
Amith Yamasani | 1bad714 | 2013-04-22 13:37:58 -0700 | [diff] [blame] | 370 | mUserManager.setUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, true, user); |
Tom O'Neill | dad115e | 2014-03-04 10:59:29 -0800 | [diff] [blame] | 371 | Secure.putIntForUser(getContentResolver(), |
| 372 | Secure.LOCATION_MODE, Secure.LOCATION_MODE_OFF, userId); |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 373 | Bitmap bitmap = BitmapFactory.decodeResource(getResources(), |
| 374 | UserSettings.USER_DRAWABLES[ |
| 375 | userId % UserSettings.USER_DRAWABLES.length]); |
| 376 | mUserManager.setUserIcon(userId, bitmap); |
| 377 | // Add shared accounts |
| 378 | AccountManager am = AccountManager.get(getActivity()); |
| 379 | Account [] accounts = am.getAccounts(); |
| 380 | if (accounts != null) { |
| 381 | for (Account account : accounts) { |
| 382 | am.addSharedAccount(account, user); |
| 383 | } |
| 384 | } |
| 385 | return newUserInfo; |
| 386 | } |
| 387 | |
| 388 | private UserInfo createTrustedUser() { |
| 389 | UserInfo newUserInfo = mUserManager.createUser( |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 390 | getResources().getString(R.string.user_new_user_name), 0); |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 391 | if (newUserInfo != null) { |
| 392 | assignDefaultPhoto(newUserInfo); |
| 393 | } |
| 394 | return newUserInfo; |
| 395 | } |
| 396 | |
| 397 | private void onManageUserClicked(int userId, boolean newUser) { |
Amith Yamasani | 9e6ac3d | 2014-06-30 15:31:37 +0530 | [diff] [blame] | 398 | if (userId == UserPreference.USERID_GUEST_DEFAULTS) { |
| 399 | Bundle extras = new Bundle(); |
| 400 | extras.putBoolean(UserDetailsSettings.EXTRA_USER_GUEST, true); |
| 401 | ((SettingsActivity) getActivity()).startPreferencePanel( |
| 402 | UserDetailsSettings.class.getName(), |
| 403 | extras, R.string.user_guest, null, null, 0); |
| 404 | return; |
| 405 | } |
Amith Yamasani | d4abdd2 | 2013-04-17 18:27:01 -0700 | [diff] [blame] | 406 | UserInfo info = mUserManager.getUserInfo(userId); |
| 407 | if (info.isRestricted() && mIsOwner) { |
| 408 | Bundle extras = new Bundle(); |
Amith Yamasani | 0ca80fe | 2013-06-03 16:41:03 -0700 | [diff] [blame] | 409 | extras.putInt(RestrictedProfileSettings.EXTRA_USER_ID, userId); |
| 410 | extras.putBoolean(RestrictedProfileSettings.EXTRA_NEW_USER, newUser); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 411 | ((SettingsActivity) getActivity()).startPreferencePanel( |
Amith Yamasani | 0ca80fe | 2013-06-03 16:41:03 -0700 | [diff] [blame] | 412 | RestrictedProfileSettings.class.getName(), |
Amith Yamasani | 7c4dfcc | 2013-05-22 12:51:30 -0700 | [diff] [blame] | 413 | extras, R.string.user_restrictions_title, null, |
Amith Yamasani | d4abdd2 | 2013-04-17 18:27:01 -0700 | [diff] [blame] | 414 | null, 0); |
| 415 | } else if (info.id == UserHandle.myUserId()) { |
| 416 | // Jump to owner info panel |
| 417 | Bundle extras = new Bundle(); |
Amith Yamasani | b017171 | 2013-04-28 22:13:22 -0700 | [diff] [blame] | 418 | if (!info.isRestricted()) { |
| 419 | extras.putBoolean(OwnerInfoSettings.EXTRA_SHOW_NICKNAME, true); |
| 420 | } |
| 421 | int titleResId = info.id == UserHandle.USER_OWNER ? R.string.owner_info_settings_title |
| 422 | : (info.isRestricted() ? R.string.profile_info_settings_title |
| 423 | : R.string.user_info_settings_title); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 424 | ((SettingsActivity) getActivity()).startPreferencePanel( |
Amith Yamasani | d4abdd2 | 2013-04-17 18:27:01 -0700 | [diff] [blame] | 425 | OwnerInfoSettings.class.getName(), |
Amith Yamasani | b017171 | 2013-04-28 22:13:22 -0700 | [diff] [blame] | 426 | extras, titleResId, null, null, 0); |
Amith Yamasani | 9e6ac3d | 2014-06-30 15:31:37 +0530 | [diff] [blame] | 427 | } else if (mIsOwner) { |
| 428 | Bundle extras = new Bundle(); |
| 429 | extras.putInt(UserDetailsSettings.EXTRA_USER_ID, userId); |
| 430 | ((SettingsActivity) getActivity()).startPreferencePanel( |
| 431 | UserDetailsSettings.class.getName(), |
Amith Yamasani | 51c6dac | 2014-07-02 00:06:37 +0530 | [diff] [blame^] | 432 | extras, |
| 433 | -1, /* No title res id */ |
| 434 | info.name, /* title */ |
| 435 | null, /* resultTo */ |
| 436 | 0 /* resultRequestCode */); |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 437 | } |
Amith Yamasani | 233592b | 2013-03-01 17:05:23 -0800 | [diff] [blame] | 438 | } |
| 439 | |
Amith Yamasani | ae47ef4 | 2012-09-16 17:53:35 -0700 | [diff] [blame] | 440 | private void onUserCreated(int userId) { |
| 441 | mAddedUserId = userId; |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 442 | if (mUserManager.getUserInfo(userId).isRestricted()) { |
| 443 | showDialog(DIALOG_SETUP_PROFILE); |
| 444 | } else { |
| 445 | showDialog(DIALOG_SETUP_USER); |
| 446 | } |
Amith Yamasani | ae47ef4 | 2012-09-16 17:53:35 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 449 | @Override |
Amith Yamasani | c861cf8 | 2012-10-02 14:51:46 -0700 | [diff] [blame] | 450 | public void onDialogShowing() { |
| 451 | super.onDialogShowing(); |
| 452 | |
| 453 | setOnDismissListener(this); |
| 454 | } |
| 455 | |
| 456 | @Override |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 457 | public Dialog onCreateDialog(int dialogId) { |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 458 | Context context = getActivity(); |
| 459 | if (context == null) return null; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 460 | switch (dialogId) { |
Amith Yamasani | c861cf8 | 2012-10-02 14:51:46 -0700 | [diff] [blame] | 461 | case DIALOG_CONFIRM_REMOVE: { |
Amith Yamasani | 9e6ac3d | 2014-06-30 15:31:37 +0530 | [diff] [blame] | 462 | Dialog dlg = |
Amith Yamasani | 51c6dac | 2014-07-02 00:06:37 +0530 | [diff] [blame^] | 463 | Utils.createRemoveConfirmationDialog(getActivity(), mRemovingUserId, |
Amith Yamasani | 9e6ac3d | 2014-06-30 15:31:37 +0530 | [diff] [blame] | 464 | new DialogInterface.OnClickListener() { |
| 465 | public void onClick(DialogInterface dialog, int which) { |
| 466 | removeUserNow(); |
| 467 | } |
| 468 | } |
| 469 | ); |
Amith Yamasani | c861cf8 | 2012-10-02 14:51:46 -0700 | [diff] [blame] | 470 | return dlg; |
| 471 | } |
Amith Yamasani | 1a634d3 | 2012-09-27 23:01:35 -0700 | [diff] [blame] | 472 | case DIALOG_USER_CANNOT_MANAGE: |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 473 | return new AlertDialog.Builder(context) |
Amith Yamasani | 1a634d3 | 2012-09-27 23:01:35 -0700 | [diff] [blame] | 474 | .setMessage(R.string.user_cannot_manage_message) |
| 475 | .setPositiveButton(android.R.string.ok, null) |
| 476 | .create(); |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 477 | case DIALOG_ADD_USER: { |
Svetoslav Ganov | 263f744 | 2012-09-25 16:11:16 -0700 | [diff] [blame] | 478 | final SharedPreferences preferences = getActivity().getPreferences( |
| 479 | Context.MODE_PRIVATE); |
| 480 | final boolean longMessageDisplayed = preferences.getBoolean( |
| 481 | KEY_ADD_USER_LONG_MESSAGE_DISPLAYED, false); |
| 482 | final int messageResId = longMessageDisplayed |
| 483 | ? R.string.user_add_user_message_short |
| 484 | : R.string.user_add_user_message_long; |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 485 | final int userType = dialogId == DIALOG_ADD_USER |
| 486 | ? USER_TYPE_USER : USER_TYPE_RESTRICTED_PROFILE; |
| 487 | Dialog dlg = new AlertDialog.Builder(context) |
| 488 | .setTitle(R.string.user_add_user_title) |
| 489 | .setMessage(messageResId) |
| 490 | .setPositiveButton(android.R.string.ok, |
| 491 | new DialogInterface.OnClickListener() { |
| 492 | public void onClick(DialogInterface dialog, int which) { |
| 493 | addUserNow(userType); |
| 494 | if (!longMessageDisplayed) { |
| 495 | preferences.edit().putBoolean( |
| 496 | KEY_ADD_USER_LONG_MESSAGE_DISPLAYED, true).apply(); |
| 497 | } |
Svetoslav Ganov | 263f744 | 2012-09-25 16:11:16 -0700 | [diff] [blame] | 498 | } |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 499 | }) |
| 500 | .setNegativeButton(android.R.string.cancel, null) |
| 501 | .create(); |
Amith Yamasani | c861cf8 | 2012-10-02 14:51:46 -0700 | [diff] [blame] | 502 | return dlg; |
| 503 | } |
| 504 | case DIALOG_SETUP_USER: { |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 505 | Dialog dlg = new AlertDialog.Builder(context) |
| 506 | .setTitle(R.string.user_setup_dialog_title) |
| 507 | .setMessage(R.string.user_setup_dialog_message) |
| 508 | .setPositiveButton(R.string.user_setup_button_setup_now, |
| 509 | new DialogInterface.OnClickListener() { |
| 510 | public void onClick(DialogInterface dialog, int which) { |
| 511 | switchUserNow(mAddedUserId); |
| 512 | } |
| 513 | }) |
| 514 | .setNegativeButton(R.string.user_setup_button_setup_later, null) |
| 515 | .create(); |
| 516 | return dlg; |
| 517 | } |
| 518 | case DIALOG_SETUP_PROFILE: { |
| 519 | Dialog dlg = new AlertDialog.Builder(context) |
| 520 | .setMessage(R.string.user_setup_profile_dialog_message) |
| 521 | .setPositiveButton(android.R.string.ok, |
| 522 | new DialogInterface.OnClickListener() { |
| 523 | public void onClick(DialogInterface dialog, int which) { |
| 524 | switchUserNow(mAddedUserId); |
| 525 | } |
| 526 | }) |
| 527 | .setNegativeButton(android.R.string.cancel, null) |
| 528 | .create(); |
| 529 | return dlg; |
| 530 | } |
| 531 | case DIALOG_CHOOSE_USER_TYPE: { |
| 532 | List<HashMap<String, String>> data = new ArrayList<HashMap<String,String>>(); |
| 533 | HashMap<String,String> addUserItem = new HashMap<String,String>(); |
| 534 | addUserItem.put(KEY_TITLE, getString(R.string.user_add_user_item_title)); |
| 535 | addUserItem.put(KEY_SUMMARY, getString(R.string.user_add_user_item_summary)); |
| 536 | HashMap<String,String> addProfileItem = new HashMap<String,String>(); |
| 537 | addProfileItem.put(KEY_TITLE, getString(R.string.user_add_profile_item_title)); |
| 538 | addProfileItem.put(KEY_SUMMARY, getString(R.string.user_add_profile_item_summary)); |
| 539 | data.add(addUserItem); |
| 540 | data.add(addProfileItem); |
| 541 | Dialog dlg = new AlertDialog.Builder(context) |
| 542 | .setTitle(R.string.user_add_user_type_title) |
| 543 | .setAdapter(new SimpleAdapter(context, data, R.layout.two_line_list_item, |
| 544 | new String[] {KEY_TITLE, KEY_SUMMARY}, |
| 545 | new int[] {R.id.title, R.id.summary}), |
| 546 | new DialogInterface.OnClickListener() { |
| 547 | public void onClick(DialogInterface dialog, int which) { |
| 548 | onAddUserClicked(which == 0 |
| 549 | ? USER_TYPE_USER |
| 550 | : USER_TYPE_RESTRICTED_PROFILE); |
| 551 | } |
| 552 | }) |
| 553 | .create(); |
Amith Yamasani | c861cf8 | 2012-10-02 14:51:46 -0700 | [diff] [blame] | 554 | return dlg; |
| 555 | } |
Amith Yamasani | f162efe | 2013-04-29 10:43:05 -0700 | [diff] [blame] | 556 | case DIALOG_NEED_LOCKSCREEN: { |
| 557 | Dialog dlg = new AlertDialog.Builder(context) |
| 558 | .setMessage(R.string.user_need_lock_message) |
| 559 | .setPositiveButton(R.string.user_set_lock_button, |
| 560 | new DialogInterface.OnClickListener() { |
| 561 | @Override |
| 562 | public void onClick(DialogInterface dialog, int which) { |
| 563 | launchChooseLockscreen(); |
| 564 | } |
| 565 | }) |
| 566 | .setNegativeButton(android.R.string.cancel, null) |
| 567 | .create(); |
| 568 | return dlg; |
| 569 | } |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 570 | default: |
| 571 | return null; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | private void removeUserNow() { |
| 576 | if (mRemovingUserId == UserHandle.myUserId()) { |
| 577 | removeThisUser(); |
| 578 | } else { |
| 579 | new Thread() { |
| 580 | public void run() { |
| 581 | synchronized (mUserLock) { |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 582 | mUserManager.removeUser(mRemovingUserId); |
| 583 | mHandler.sendEmptyMessage(MESSAGE_UPDATE_LIST); |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 584 | } |
| 585 | } |
| 586 | }.start(); |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | private void removeThisUser() { |
Amith Yamasani | ae47ef4 | 2012-09-16 17:53:35 -0700 | [diff] [blame] | 591 | try { |
| 592 | ActivityManagerNative.getDefault().switchUser(UserHandle.USER_OWNER); |
| 593 | ((UserManager) getActivity().getSystemService(Context.USER_SERVICE)) |
| 594 | .removeUser(UserHandle.myUserId()); |
| 595 | } catch (RemoteException re) { |
| 596 | Log.e(TAG, "Unable to remove self user"); |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 600 | private void addUserNow(final int userType) { |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 601 | synchronized (mUserLock) { |
| 602 | mAddingUser = true; |
Amith Yamasani | a98c402 | 2013-04-19 15:27:52 -0700 | [diff] [blame] | 603 | //updateUserList(); |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 604 | new Thread() { |
| 605 | public void run() { |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 606 | UserInfo user = null; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 607 | // Could take a few seconds |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 608 | if (userType == USER_TYPE_USER) { |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 609 | user = createTrustedUser(); |
| 610 | } else { |
| 611 | user = createLimitedUser(); |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 612 | } |
| 613 | synchronized (mUserLock) { |
| 614 | mAddingUser = false; |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 615 | if (userType == USER_TYPE_USER) { |
Amith Yamasani | a98c402 | 2013-04-19 15:27:52 -0700 | [diff] [blame] | 616 | mHandler.sendEmptyMessage(MESSAGE_UPDATE_LIST); |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 617 | mHandler.sendMessage(mHandler.obtainMessage( |
| 618 | MESSAGE_SETUP_USER, user.id, user.serialNumber)); |
| 619 | } else { |
| 620 | mHandler.sendMessage(mHandler.obtainMessage( |
| 621 | MESSAGE_CONFIG_USER, user.id, user.serialNumber)); |
| 622 | } |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 623 | } |
| 624 | } |
| 625 | }.start(); |
| 626 | } |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Amith Yamasani | ae47ef4 | 2012-09-16 17:53:35 -0700 | [diff] [blame] | 629 | private void switchUserNow(int userId) { |
| 630 | try { |
| 631 | ActivityManagerNative.getDefault().switchUser(userId); |
| 632 | } catch (RemoteException re) { |
| 633 | // Nothing to do |
| 634 | } |
| 635 | } |
| 636 | |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 637 | private void updateUserList() { |
Amith Yamasani | f34a85d | 2012-09-17 18:31:45 -0700 | [diff] [blame] | 638 | if (getActivity() == null) return; |
Amith Yamasani | e278eda | 2012-09-20 22:44:48 -0700 | [diff] [blame] | 639 | List<UserInfo> users = mUserManager.getUsers(true); |
Amith Yamasani | 9e6ac3d | 2014-06-30 15:31:37 +0530 | [diff] [blame] | 640 | final Context context = getActivity(); |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 641 | |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 642 | mUserListCategory.removeAll(); |
| 643 | mUserListCategory.setOrderingAsAdded(false); |
| 644 | mUserListCategory.addPreference(mMePreference); |
Amith Yamasani | d4abdd2 | 2013-04-17 18:27:01 -0700 | [diff] [blame] | 645 | |
Amith Yamasani | 9e6ac3d | 2014-06-30 15:31:37 +0530 | [diff] [blame] | 646 | final boolean voiceCapable = Utils.isVoiceCapable(context); |
Amith Yamasani | f34a85d | 2012-09-17 18:31:45 -0700 | [diff] [blame] | 647 | final ArrayList<Integer> missingIcons = new ArrayList<Integer>(); |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 648 | for (UserInfo user : users) { |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 649 | Preference pref; |
Amith Yamasani | c861cf8 | 2012-10-02 14:51:46 -0700 | [diff] [blame] | 650 | if (user.id == UserHandle.myUserId()) { |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 651 | pref = mMePreference; |
Amith Yamasani | 9e6ac3d | 2014-06-30 15:31:37 +0530 | [diff] [blame] | 652 | } else if (user.isGuest()) { |
| 653 | // Skip over Guest. We add generic Guest settings after this loop |
| 654 | continue; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 655 | } else { |
Amith Yamasani | 9e6ac3d | 2014-06-30 15:31:37 +0530 | [diff] [blame] | 656 | // With Telephony: |
| 657 | // Secondary user: Settings |
| 658 | // Guest: Settings |
| 659 | // Restricted Profile: There is no Restricted Profile |
| 660 | // Without Telephony: |
| 661 | // Secondary user: Delete |
| 662 | // Guest: Nothing |
| 663 | // Restricted Profile: Settings |
| 664 | final boolean showSettings = mIsOwner && (voiceCapable || user.isRestricted()); |
| 665 | final boolean showDelete = mIsOwner |
| 666 | && (!voiceCapable && !user.isRestricted() && !user.isGuest()); |
| 667 | pref = new UserPreference(context, null, user.id, |
| 668 | showSettings ? this : null, |
| 669 | showDelete ? this : null); |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 670 | pref.setOnPreferenceClickListener(this); |
| 671 | pref.setKey("id=" + user.id); |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 672 | mUserListCategory.addPreference(pref); |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 673 | if (user.id == UserHandle.USER_OWNER) { |
| 674 | pref.setSummary(R.string.user_owner); |
| 675 | } |
| 676 | pref.setTitle(user.name); |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 677 | } |
| 678 | if (!isInitialized(user)) { |
Alexandra Gherghina | 423bafc | 2014-04-23 10:56:37 +0000 | [diff] [blame] | 679 | if (user.isRestricted()) { |
| 680 | pref.setSummary(R.string.user_summary_restricted_not_set_up); |
| 681 | } else if (user.isManagedProfile()) { |
| 682 | pref.setSummary(R.string.user_summary_managed_profile_not_set_up); |
| 683 | } else { |
| 684 | pref.setSummary(R.string.user_summary_not_set_up); |
| 685 | } |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 686 | } else if (user.isRestricted()) { |
| 687 | pref.setSummary(R.string.user_summary_restricted_profile); |
Alexandra Gherghina | 423bafc | 2014-04-23 10:56:37 +0000 | [diff] [blame] | 688 | } else if (user.isManagedProfile()) { |
Alexandra Gherghina | 312c457 | 2014-04-28 13:59:39 +0100 | [diff] [blame] | 689 | if (user.isEnabled()) { |
Alexandra Gherghina | 423bafc | 2014-04-23 10:56:37 +0000 | [diff] [blame] | 690 | pref.setSummary(R.string.user_summary_managed_profile); |
| 691 | } else { |
| 692 | pref.setSummary(R.string.user_summary_managed_profile_not_enabled); |
| 693 | } |
Amith Yamasani | 48fa857 | 2012-04-17 17:12:01 -0700 | [diff] [blame] | 694 | } |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 695 | if (user.iconPath != null) { |
Amith Yamasani | f34a85d | 2012-09-17 18:31:45 -0700 | [diff] [blame] | 696 | if (mUserIcons.get(user.id) == null) { |
| 697 | missingIcons.add(user.id); |
Amith Yamasani | 0ca80fe | 2013-06-03 16:41:03 -0700 | [diff] [blame] | 698 | pref.setIcon(encircle(R.drawable.avatar_default_1)); |
Amith Yamasani | f34a85d | 2012-09-17 18:31:45 -0700 | [diff] [blame] | 699 | } else { |
| 700 | setPhotoId(pref, user); |
| 701 | } |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | // Add a temporary entry for the user being created |
| 705 | if (mAddingUser) { |
| 706 | Preference pref = new UserPreference(getActivity(), null, UserPreference.USERID_UNKNOWN, |
Amith Yamasani | d4abdd2 | 2013-04-17 18:27:01 -0700 | [diff] [blame] | 707 | null, null); |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 708 | pref.setEnabled(false); |
| 709 | pref.setTitle(R.string.user_new_user_name); |
Amith Yamasani | 0ca80fe | 2013-06-03 16:41:03 -0700 | [diff] [blame] | 710 | pref.setIcon(encircle(R.drawable.avatar_default_1)); |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 711 | mUserListCategory.addPreference(pref); |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 712 | } |
Amith Yamasani | 9e6ac3d | 2014-06-30 15:31:37 +0530 | [diff] [blame] | 713 | |
| 714 | if (!mIsGuest) { |
| 715 | // Add a virtual Guest user for guest defaults |
| 716 | Preference pref = new UserPreference(getActivity(), null, |
| 717 | UserPreference.USERID_GUEST_DEFAULTS, mIsOwner ? this : null, null); |
| 718 | pref.setTitle(R.string.user_guest); |
| 719 | pref.setIcon(encircle(R.drawable.ic_settings_accounts)); |
| 720 | pref.setOnPreferenceClickListener(this); |
| 721 | mUserListCategory.addPreference(pref); |
| 722 | } |
| 723 | |
Amith Yamasani | 6be075d | 2012-09-11 11:01:35 -0700 | [diff] [blame] | 724 | getActivity().invalidateOptionsMenu(); |
Amith Yamasani | f34a85d | 2012-09-17 18:31:45 -0700 | [diff] [blame] | 725 | |
| 726 | // Load the icons |
| 727 | if (missingIcons.size() > 0) { |
| 728 | loadIconsAsync(missingIcons); |
| 729 | } |
Amith Yamasani | 864e3b7 | 2013-03-27 12:27:01 -0700 | [diff] [blame] | 730 | boolean moreUsers = mUserManager.getMaxSupportedUsers() > users.size(); |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 731 | mAddUser.setEnabled(moreUsers); |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 732 | } |
| 733 | |
Amith Yamasani | f34a85d | 2012-09-17 18:31:45 -0700 | [diff] [blame] | 734 | private void loadIconsAsync(List<Integer> missingIcons) { |
Amith Yamasani | 5cdc937 | 2012-11-14 16:23:40 -0800 | [diff] [blame] | 735 | final Resources resources = getResources(); |
Amith Yamasani | f34a85d | 2012-09-17 18:31:45 -0700 | [diff] [blame] | 736 | new AsyncTask<List<Integer>, Void, Void>() { |
| 737 | @Override |
| 738 | protected void onPostExecute(Void result) { |
| 739 | updateUserList(); |
| 740 | } |
| 741 | |
| 742 | @Override |
| 743 | protected Void doInBackground(List<Integer>... values) { |
Amith Yamasani | f34a85d | 2012-09-17 18:31:45 -0700 | [diff] [blame] | 744 | for (int userId : values[0]) { |
| 745 | Bitmap bitmap = mUserManager.getUserIcon(userId); |
Amith Yamasani | 864e3b7 | 2013-03-27 12:27:01 -0700 | [diff] [blame] | 746 | mUserIcons.append(userId, bitmap); |
Amith Yamasani | f34a85d | 2012-09-17 18:31:45 -0700 | [diff] [blame] | 747 | } |
| 748 | return null; |
| 749 | } |
| 750 | }.execute(missingIcons); |
Amith Yamasani | f34a85d | 2012-09-17 18:31:45 -0700 | [diff] [blame] | 751 | } |
Amith Yamasani | 5cdc937 | 2012-11-14 16:23:40 -0800 | [diff] [blame] | 752 | |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 753 | private void assignProfilePhoto(final UserInfo user) { |
Amith Yamasani | ae47ef4 | 2012-09-16 17:53:35 -0700 | [diff] [blame] | 754 | if (!Utils.copyMeProfilePhoto(getActivity(), user)) { |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 755 | assignDefaultPhoto(user); |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 756 | } |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | private String getProfileName() { |
Amith Yamasani | 8d40fac | 2012-10-23 15:36:16 -0700 | [diff] [blame] | 760 | String name = Utils.getMeProfileName(getActivity(), true); |
Amith Yamasani | ae47ef4 | 2012-09-16 17:53:35 -0700 | [diff] [blame] | 761 | if (name != null) { |
| 762 | mProfileExists = true; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 763 | } |
Amith Yamasani | ae47ef4 | 2012-09-16 17:53:35 -0700 | [diff] [blame] | 764 | return name; |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | private void assignDefaultPhoto(UserInfo user) { |
| 768 | Bitmap bitmap = BitmapFactory.decodeResource(getResources(), |
| 769 | USER_DRAWABLES[user.id % USER_DRAWABLES.length]); |
Amith Yamasani | f34a85d | 2012-09-17 18:31:45 -0700 | [diff] [blame] | 770 | mUserManager.setUserIcon(user.id, bitmap); |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | private void setPhotoId(Preference pref, UserInfo user) { |
Amith Yamasani | d4abdd2 | 2013-04-17 18:27:01 -0700 | [diff] [blame] | 774 | Bitmap bitmap = mUserIcons.get(user.id); |
Amith Yamasani | 864e3b7 | 2013-03-27 12:27:01 -0700 | [diff] [blame] | 775 | if (bitmap != null) { |
| 776 | pref.setIcon(encircle(bitmap)); |
Amith Yamasani | e940dac | 2012-09-17 10:21:27 -0700 | [diff] [blame] | 777 | } |
Amith Yamasani | 48fa857 | 2012-04-17 17:12:01 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 780 | private void setUserName(String name) { |
| 781 | mUserManager.setUserName(UserHandle.myUserId(), name); |
| 782 | mNicknamePreference.setSummary(name); |
Amith Yamasani | 1a634d3 | 2012-09-27 23:01:35 -0700 | [diff] [blame] | 783 | getActivity().invalidateOptionsMenu(); |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 784 | } |
| 785 | |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 786 | @Override |
| 787 | public boolean onPreferenceClick(Preference pref) { |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 788 | if (pref == mMePreference) { |
Amith Yamasani | 32dccbc | 2012-09-13 18:06:49 -0700 | [diff] [blame] | 789 | Intent editProfile; |
| 790 | if (!mProfileExists) { |
| 791 | editProfile = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI); |
| 792 | // TODO: Make this a proper API |
| 793 | editProfile.putExtra("newLocalProfile", true); |
| 794 | } else { |
| 795 | editProfile = new Intent(Intent.ACTION_EDIT, ContactsContract.Profile.CONTENT_URI); |
| 796 | } |
Amith Yamasani | 43db526 | 2012-09-11 17:04:10 -0700 | [diff] [blame] | 797 | // To make sure that it returns back here when done |
| 798 | // TODO: Make this a proper API |
| 799 | editProfile.putExtra("finishActivityOnSaveCompleted", true); |
Amith Yamasani | d4abdd2 | 2013-04-17 18:27:01 -0700 | [diff] [blame] | 800 | |
| 801 | // If this is a limited user, launch the user info settings instead of profile editor |
| 802 | if (mUserManager.isLinkedUser()) { |
| 803 | onManageUserClicked(UserHandle.myUserId(), false); |
| 804 | } else { |
| 805 | startActivity(editProfile); |
| 806 | } |
Amith Yamasani | 1a634d3 | 2012-09-27 23:01:35 -0700 | [diff] [blame] | 807 | } else if (pref instanceof UserPreference) { |
| 808 | int userId = ((UserPreference) pref).getUserId(); |
Amith Yamasani | 9e6ac3d | 2014-06-30 15:31:37 +0530 | [diff] [blame] | 809 | if (userId == UserPreference.USERID_GUEST_DEFAULTS) { |
| 810 | createAndSwitchToGuestUser(); |
Amith Yamasani | 1a634d3 | 2012-09-27 23:01:35 -0700 | [diff] [blame] | 811 | } else { |
Amith Yamasani | 9e6ac3d | 2014-06-30 15:31:37 +0530 | [diff] [blame] | 812 | // Get the latest status of the user |
| 813 | UserInfo user = mUserManager.getUserInfo(userId); |
Amith Yamasani | 1a634d3 | 2012-09-27 23:01:35 -0700 | [diff] [blame] | 814 | if (!isInitialized(user)) { |
| 815 | mHandler.sendMessage(mHandler.obtainMessage( |
| 816 | MESSAGE_SETUP_USER, user.id, user.serialNumber)); |
Amith Yamasani | 9e6ac3d | 2014-06-30 15:31:37 +0530 | [diff] [blame] | 817 | } else if (!user.isManagedProfile()) { |
| 818 | switchUserNow(userId); |
Amith Yamasani | 1a634d3 | 2012-09-27 23:01:35 -0700 | [diff] [blame] | 819 | } |
| 820 | } |
Amith Yamasani | fc8a383 | 2013-04-23 11:44:59 -0700 | [diff] [blame] | 821 | } else if (pref == mAddUser) { |
Amith Yamasani | 0e43d32 | 2014-05-07 10:19:34 -0700 | [diff] [blame] | 822 | // If we allow both types, show a picker, otherwise directly go to |
| 823 | // flow for full user. |
| 824 | if (mCanAddRestrictedProfile) { |
| 825 | showDialog(DIALOG_CHOOSE_USER_TYPE); |
| 826 | } else { |
| 827 | onAddUserClicked(USER_TYPE_USER); |
| 828 | } |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 829 | } |
| 830 | return false; |
| 831 | } |
| 832 | |
Amith Yamasani | 9e6ac3d | 2014-06-30 15:31:37 +0530 | [diff] [blame] | 833 | private void createAndSwitchToGuestUser() { |
| 834 | List<UserInfo> users = mUserManager.getUsers(); |
| 835 | for (UserInfo user : users) { |
| 836 | if (user.isGuest()) { |
| 837 | switchUserNow(user.id); |
| 838 | return; |
| 839 | } |
| 840 | } |
| 841 | // No guest user. Create one. |
| 842 | UserInfo guestUser = mUserManager.createGuest(getActivity(), |
| 843 | getResources().getString(R.string.user_guest)); |
| 844 | if (guestUser != null) { |
| 845 | switchUserNow(guestUser.id); |
| 846 | } |
| 847 | } |
| 848 | |
Amith Yamasani | 1a634d3 | 2012-09-27 23:01:35 -0700 | [diff] [blame] | 849 | private boolean isInitialized(UserInfo user) { |
| 850 | return (user.flags & UserInfo.FLAG_INITIALIZED) != 0; |
| 851 | } |
| 852 | |
Amith Yamasani | 864e3b7 | 2013-03-27 12:27:01 -0700 | [diff] [blame] | 853 | private Drawable encircle(int iconResId) { |
| 854 | Bitmap icon = BitmapFactory.decodeResource(getResources(), iconResId); |
| 855 | return encircle(icon); |
| 856 | } |
| 857 | |
| 858 | private Drawable encircle(Bitmap icon) { |
| 859 | Drawable circled = CircleFramedDrawable.getInstance(getActivity(), icon); |
| 860 | return circled; |
| 861 | } |
| 862 | |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 863 | @Override |
| 864 | public void onClick(View v) { |
| 865 | if (v.getTag() instanceof UserPreference) { |
| 866 | int userId = ((UserPreference) v.getTag()).getUserId(); |
Amith Yamasani | 233592b | 2013-03-01 17:05:23 -0800 | [diff] [blame] | 867 | switch (v.getId()) { |
| 868 | case UserPreference.DELETE_ID: |
Maggie Benthall | 4453496 | 2013-08-29 10:49:13 -0400 | [diff] [blame] | 869 | onRemoveUserClicked(userId); |
Amith Yamasani | 233592b | 2013-03-01 17:05:23 -0800 | [diff] [blame] | 870 | break; |
| 871 | case UserPreference.SETTINGS_ID: |
Amith Yamasani | cc39569 | 2013-04-11 18:21:07 -0700 | [diff] [blame] | 872 | onManageUserClicked(userId, false); |
Amith Yamasani | 233592b | 2013-03-01 17:05:23 -0800 | [diff] [blame] | 873 | break; |
| 874 | } |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 875 | } |
| 876 | } |
| 877 | |
| 878 | @Override |
| 879 | public void onDismiss(DialogInterface dialog) { |
| 880 | synchronized (mUserLock) { |
| 881 | mAddingUser = false; |
| 882 | mRemovingUserId = -1; |
Amith Yamasani | c861cf8 | 2012-10-02 14:51:46 -0700 | [diff] [blame] | 883 | updateUserList(); |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 884 | } |
| 885 | } |
| 886 | |
| 887 | @Override |
| 888 | public boolean onPreferenceChange(Preference preference, Object newValue) { |
| 889 | if (preference == mNicknamePreference) { |
| 890 | String value = (String) newValue; |
| 891 | if (preference == mNicknamePreference && value != null |
| 892 | && value.length() > 0) { |
| 893 | setUserName(value); |
| 894 | } |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 895 | return true; |
| 896 | } |
| 897 | return false; |
| 898 | } |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 899 | |
Amith Yamasani | 38223dc | 2012-09-18 09:51:07 -0700 | [diff] [blame] | 900 | @Override |
| 901 | public int getHelpResource() { |
| 902 | return R.string.help_url_users; |
| 903 | } |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 904 | } |