blob: 4b060a0dc615c5bca4dbb0c0b8a70441db90a981 [file] [log] [blame]
Amith Yamasanib810a0d2012-03-25 10:12:26 -07001/*
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
17package com.android.settings.users;
18
Amith Yamasanif162efe2013-04-29 10:43:05 -070019import android.app.Activity;
Amith Yamasaniae47ef42012-09-16 17:53:35 -070020import android.app.ActivityManagerNative;
Amith Yamasanidc6bfa62012-09-06 18:04:06 -070021import android.app.AlertDialog;
22import android.app.Dialog;
Amith Yamasanif162efe2013-04-29 10:43:05 -070023import android.app.admin.DevicePolicyManager;
Amith Yamasanidc6bfa62012-09-06 18:04:06 -070024import android.content.BroadcastReceiver;
Amith Yamasani32630392012-08-10 19:31:39 -070025import android.content.Context;
Amith Yamasanidc6bfa62012-09-06 18:04:06 -070026import android.content.DialogInterface;
27import android.content.Intent;
28import android.content.IntentFilter;
Svetoslav Ganov263f7442012-09-25 16:11:16 -070029import android.content.SharedPreferences;
mariagpuyol60435fc2016-01-28 14:58:03 -080030import android.content.pm.ResolveInfo;
Amith Yamasanib810a0d2012-03-25 10:12:26 -070031import android.content.pm.UserInfo;
Amith Yamasani5cdc9372012-11-14 16:23:40 -080032import android.content.res.Resources;
Amith Yamasanidc6bfa62012-09-06 18:04:06 -070033import android.graphics.Bitmap;
Amith Yamasani48fa8572012-04-17 17:12:01 -070034import android.graphics.drawable.Drawable;
Amith Yamasani32dccbc2012-09-13 18:06:49 -070035import android.os.AsyncTask;
Amith Yamasanib810a0d2012-03-25 10:12:26 -070036import android.os.Bundle;
Amith Yamasanidc6bfa62012-09-06 18:04:06 -070037import android.os.Handler;
38import android.os.Message;
Amith Yamasaniae47ef42012-09-16 17:53:35 -070039import android.os.RemoteException;
Amith Yamasanidc6bfa62012-09-06 18:04:06 -070040import android.os.UserHandle;
Amith Yamasani32630392012-08-10 19:31:39 -070041import android.os.UserManager;
Amith Yamasani247520c2014-07-25 12:52:29 -070042import android.provider.Settings;
Jason Monk39b46742015-09-10 15:52:51 -040043import android.support.v7.preference.Preference;
44import android.support.v7.preference.Preference.OnPreferenceClickListener;
45import android.support.v7.preference.PreferenceGroup;
46import android.support.v7.preference.PreferenceScreen;
Amith Yamasanidc6bfa62012-09-06 18:04:06 -070047import android.util.Log;
Amith Yamasanif34a85d2012-09-17 18:31:45 -070048import android.util.SparseArray;
Amith Yamasanib810a0d2012-03-25 10:12:26 -070049import android.view.Menu;
50import android.view.MenuInflater;
51import android.view.MenuItem;
Amith Yamasanidc6bfa62012-09-06 18:04:06 -070052import android.view.View;
53import android.view.View.OnClickListener;
Amith Yamasanifc8a3832013-04-23 11:44:59 -070054import android.widget.SimpleAdapter;
Amith Yamasanib810a0d2012-03-25 10:12:26 -070055
Chris Wren9d1bfd12016-01-26 18:04:01 -050056import com.android.internal.logging.MetricsProto.MetricsEvent;
Amith Yamasanif162efe2013-04-29 10:43:05 -070057import com.android.internal.widget.LockPatternUtils;
58import com.android.settings.ChooseLockGeneric;
Sudheer Shanka682a9162016-01-13 22:10:18 +000059import com.android.settings.DimmableIconPreference;
Amith Yamasanid4abdd22013-04-17 18:27:01 -070060import com.android.settings.OwnerInfoSettings;
Amith Yamasanib810a0d2012-03-25 10:12:26 -070061import com.android.settings.R;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080062import com.android.settings.SettingsActivity;
Julia Reynoldsb9195d22014-06-11 16:18:16 -040063import com.android.settings.SettingsPreferenceFragment;
Amith Yamasaniae47ef42012-09-16 17:53:35 -070064import com.android.settings.Utils;
Jason Monk9d80eea2015-11-20 14:27:51 -050065import com.android.settings.dashboard.SummaryLoader;
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -070066import com.android.settings.search.BaseSearchIndexProvider;
67import com.android.settings.search.Indexable;
68import com.android.settings.search.SearchIndexableRaw;
Sudheer Shanka682a9162016-01-13 22:10:18 +000069import com.android.settingslib.RestrictedLockUtils;
70import com.android.settingslib.RestrictedSwitchPreference;
Wei Liu6e58d512015-08-24 17:29:04 -070071import com.android.settingslib.drawable.CircleFramedDrawable;
Amith Yamasanib810a0d2012-03-25 10:12:26 -070072
Alexandra Gherghinabc6e78f2014-09-03 10:22:09 +010073import java.util.ArrayList;
Fyodor Kupolov55145092014-12-08 14:15:36 -080074import java.util.Collections;
Alexandra Gherghinabc6e78f2014-09-03 10:22:09 +010075import java.util.HashMap;
76import java.util.List;
77
Sudheer Shanka682a9162016-01-13 22:10:18 +000078import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
79
Amith Yamasaniee398742014-07-24 14:13:36 -070080/**
81 * Screen that manages the list of users on the device.
82 * Guest user is an always visible entry, even if the guest is not currently
83 * active/created. It is meant for controlling properties of a guest user.
84 *
85 * The first one is always the current user.
86 * Owner is the primary user.
87 */
Julia Reynoldsb9195d22014-06-11 16:18:16 -040088public class UserSettings extends SettingsPreferenceFragment
Amith Yamasanidc6bfa62012-09-06 18:04:06 -070089 implements OnPreferenceClickListener, OnClickListener, DialogInterface.OnDismissListener,
Amith Yamasaniee398742014-07-24 14:13:36 -070090 Preference.OnPreferenceChangeListener,
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -070091 EditUserInfoController.OnContentChangedCallback, Indexable {
Amith Yamasanib810a0d2012-03-25 10:12:26 -070092
Amith Yamasanidc6bfa62012-09-06 18:04:06 -070093 private static final String TAG = "UserSettings";
94
Amith Yamasanic861cf82012-10-02 14:51:46 -070095 /** UserId of the user being removed */
96 private static final String SAVE_REMOVING_USER = "removing_user";
97 /** UserId of the user that was just added */
98 private static final String SAVE_ADDING_USER = "adding_user";
99
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700100 private static final String KEY_USER_LIST = "user_list";
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700101 private static final String KEY_USER_ME = "user_me";
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700102 private static final String KEY_ADD_USER = "user_add";
mariagpuyol60435fc2016-01-28 14:58:03 -0800103 private static final String KEY_EMERGENCY_INFO = "emergency_info";
mariagpuyol60435fc2016-01-28 14:58:03 -0800104
105 private static final String ACTION_EDIT_EMERGENCY_INFO = "android.settings.EDIT_EMERGENGY_INFO";
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700106
Amith Yamasanicc395692013-04-11 18:21:07 -0700107 private static final int MENU_REMOVE_USER = Menu.FIRST;
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700108
109 private static final int DIALOG_CONFIRM_REMOVE = 1;
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700110 private static final int DIALOG_ADD_USER = 2;
111 private static final int DIALOG_SETUP_USER = 3;
112 private static final int DIALOG_SETUP_PROFILE = 4;
Amith Yamasanicc395692013-04-11 18:21:07 -0700113 private static final int DIALOG_USER_CANNOT_MANAGE = 5;
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700114 private static final int DIALOG_CHOOSE_USER_TYPE = 6;
Amith Yamasanif162efe2013-04-29 10:43:05 -0700115 private static final int DIALOG_NEED_LOCKSCREEN = 7;
Amith Yamasanic16b73e2014-07-17 19:13:51 -0700116 private static final int DIALOG_CONFIRM_EXIT_GUEST = 8;
Amith Yamasaniee398742014-07-24 14:13:36 -0700117 private static final int DIALOG_USER_PROFILE_EDITOR = 9;
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700118
119 private static final int MESSAGE_UPDATE_LIST = 1;
Amith Yamasaniae47ef42012-09-16 17:53:35 -0700120 private static final int MESSAGE_SETUP_USER = 2;
Amith Yamasanicc395692013-04-11 18:21:07 -0700121 private static final int MESSAGE_CONFIG_USER = 3;
122
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700123 private static final int USER_TYPE_USER = 1;
124 private static final int USER_TYPE_RESTRICTED_PROFILE = 2;
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700125
Amith Yamasanif162efe2013-04-29 10:43:05 -0700126 private static final int REQUEST_CHOOSE_LOCK = 10;
127
Svetoslav Ganov263f7442012-09-25 16:11:16 -0700128 private static final String KEY_ADD_USER_LONG_MESSAGE_DISPLAYED =
129 "key_add_user_long_message_displayed";
130
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700131 private static final String KEY_TITLE = "title";
132 private static final String KEY_SUMMARY = "summary";
133
134 private PreferenceGroup mUserListCategory;
Fyodor Kupolov55145092014-12-08 14:15:36 -0800135 private UserPreference mMePreference;
Sudheer Shanka682a9162016-01-13 22:10:18 +0000136 private DimmableIconPreference mAddUser;
Fyodor Kupolov8ba52d62016-01-05 14:30:03 -0800137 private PreferenceGroup mLockScreenSettings;
Sudheer Shanka682a9162016-01-13 22:10:18 +0000138 private RestrictedSwitchPreference mAddUserWhenLocked;
mariagpuyol60435fc2016-01-28 14:58:03 -0800139 private Preference mEmergencyInfoPreference;
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700140 private int mRemovingUserId = -1;
Amith Yamasaniae47ef42012-09-16 17:53:35 -0700141 private int mAddedUserId = 0;
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700142 private boolean mAddingUser;
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -0700143 private UserCapabilities mUserCaps;
Fyodor Kupolov8c9120b2016-03-07 11:49:35 -0800144 private boolean mShouldUpdateUserList = true;
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700145 private final Object mUserLock = new Object();
146 private UserManager mUserManager;
Amith Yamasani864e3b72013-03-27 12:27:01 -0700147 private SparseArray<Bitmap> mUserIcons = new SparseArray<Bitmap>();
Amith Yamasani8666b9e2012-09-27 14:50:13 -0700148
Amith Yamasaniee398742014-07-24 14:13:36 -0700149 private EditUserInfoController mEditUserInfoController =
150 new EditUserInfoController();
151
Amith Yamasanic16b73e2014-07-17 19:13:51 -0700152 // A place to cache the generated default avatar
Alexandra Gherghinabc6e78f2014-09-03 10:22:09 +0100153 private Drawable mDefaultIconDrawable;
Amith Yamasanic16b73e2014-07-17 19:13:51 -0700154
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700155 private Handler mHandler = new Handler() {
156 @Override
157 public void handleMessage(Message msg) {
158 switch (msg.what) {
159 case MESSAGE_UPDATE_LIST:
160 updateUserList();
161 break;
Amith Yamasaniae47ef42012-09-16 17:53:35 -0700162 case MESSAGE_SETUP_USER:
163 onUserCreated(msg.arg1);
164 break;
Amith Yamasanicc395692013-04-11 18:21:07 -0700165 case MESSAGE_CONFIG_USER:
166 onManageUserClicked(msg.arg1, true);
167 break;
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700168 }
169 }
170 };
171
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700172 private BroadcastReceiver mUserChangeReceiver = new BroadcastReceiver() {
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700173 @Override
174 public void onReceive(Context context, Intent intent) {
Amith Yamasanif34a85d2012-09-17 18:31:45 -0700175 if (intent.getAction().equals(Intent.ACTION_USER_REMOVED)) {
176 mRemovingUserId = -1;
177 } else if (intent.getAction().equals(Intent.ACTION_USER_INFO_CHANGED)) {
178 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
179 if (userHandle != -1) {
180 mUserIcons.remove(userHandle);
181 }
182 }
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700183 mHandler.sendEmptyMessage(MESSAGE_UPDATE_LIST);
184 }
185 };
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700186
187 @Override
Chris Wren8a963ba2015-03-20 10:29:14 -0400188 protected int getMetricsCategory() {
Chris Wren9d1bfd12016-01-26 18:04:01 -0500189 return MetricsEvent.USER;
Chris Wren8a963ba2015-03-20 10:29:14 -0400190 }
191
192 @Override
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700193 public void onCreate(Bundle icicle) {
194 super.onCreate(icicle);
Amith Yamasani8666b9e2012-09-27 14:50:13 -0700195
Amith Yamasanic861cf82012-10-02 14:51:46 -0700196 if (icicle != null) {
197 if (icicle.containsKey(SAVE_ADDING_USER)) {
198 mAddedUserId = icicle.getInt(SAVE_ADDING_USER);
199 }
200 if (icicle.containsKey(SAVE_REMOVING_USER)) {
201 mRemovingUserId = icicle.getInt(SAVE_REMOVING_USER);
202 }
Amith Yamasaniee398742014-07-24 14:13:36 -0700203 mEditUserInfoController.onRestoreInstanceState(icicle);
Amith Yamasanic861cf82012-10-02 14:51:46 -0700204 }
Amith Yamasani0e43d322014-05-07 10:19:34 -0700205 final Context context = getActivity();
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -0700206 mUserCaps = UserCapabilities.create(context);
Amith Yamasani0e43d322014-05-07 10:19:34 -0700207 mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -0700208 if (!mUserCaps.mEnabled) {
Amith Yamasanicfb8d7f2014-03-26 14:46:47 -0700209 return;
210 }
Amith Yamasani0e43d322014-05-07 10:19:34 -0700211
Amith Yamasani9e6ac3d2014-06-30 15:31:37 +0530212 final int myUserId = UserHandle.myUserId();
Amith Yamasani9e6ac3d2014-06-30 15:31:37 +0530213
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700214 addPreferencesFromResource(R.xml.user_settings);
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700215 mUserListCategory = (PreferenceGroup) findPreference(KEY_USER_LIST);
Jason Monk39b46742015-09-10 15:52:51 -0400216 mMePreference = new UserPreference(getPrefContext(), null /* attrs */, myUserId,
Amith Yamasaniee398742014-07-24 14:13:36 -0700217 null /* settings icon handler */,
Amith Yamasanic16b73e2014-07-17 19:13:51 -0700218 null /* delete icon handler */);
Amith Yamasanid4abdd22013-04-17 18:27:01 -0700219 mMePreference.setKey(KEY_USER_ME);
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700220 mMePreference.setOnPreferenceClickListener(this);
Xiaohui Chen64f530c2015-06-24 12:35:07 -0700221 if (mUserCaps.mIsAdmin) {
222 mMePreference.setSummary(R.string.user_admin);
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700223 }
Sudheer Shanka682a9162016-01-13 22:10:18 +0000224 mAddUser = (DimmableIconPreference) findPreference(KEY_ADD_USER);
Fyodor Kupolov55145092014-12-08 14:15:36 -0800225 // Determine if add user/profile button should be visible
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -0700226 if (mUserCaps.mCanAddUser) {
Amith Yamasani0e43d322014-05-07 10:19:34 -0700227 mAddUser.setOnPreferenceClickListener(this);
Fyodor Kupolov55145092014-12-08 14:15:36 -0800228 // change label to only mention user, if restricted profiles are not supported
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -0700229 if (!mUserCaps.mCanAddRestrictedProfile) {
Amith Yamasani0e43d322014-05-07 10:19:34 -0700230 mAddUser.setTitle(R.string.user_add_user_menu);
231 }
Amith Yamasani233592b2013-03-01 17:05:23 -0800232 }
Fyodor Kupolov8ba52d62016-01-05 14:30:03 -0800233 mLockScreenSettings = (PreferenceGroup) findPreference("lock_screen_settings");
Sudheer Shanka682a9162016-01-13 22:10:18 +0000234 mAddUserWhenLocked = (RestrictedSwitchPreference) findPreference("add_users_when_locked");
mariagpuyol60435fc2016-01-28 14:58:03 -0800235 mEmergencyInfoPreference = findPreference(KEY_EMERGENCY_INFO);
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700236 setHasOptionsMenu(true);
Amith Yamasanif34a85d2012-09-17 18:31:45 -0700237 IntentFilter filter = new IntentFilter(Intent.ACTION_USER_REMOVED);
238 filter.addAction(Intent.ACTION_USER_INFO_CHANGED);
Fyodor Kupolov8c9120b2016-03-07 11:49:35 -0800239 context.registerReceiverAsUser(mUserChangeReceiver, UserHandle.ALL, filter, null, mHandler);
240 loadProfile();
241 updateUserList();
242 mShouldUpdateUserList = false;
Amith Yamasani0ca80fe2013-06-03 16:41:03 -0700243 }
244
245 @Override
246 public void onResume() {
247 super.onResume();
Amith Yamasanicfb8d7f2014-03-26 14:46:47 -0700248
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -0700249 if (!mUserCaps.mEnabled) return;
Amith Yamasanicfb8d7f2014-03-26 14:46:47 -0700250
Fyodor Kupolov8c9120b2016-03-07 11:49:35 -0800251 if (mShouldUpdateUserList) {
252 loadProfile();
253 updateUserList();
254 }
255 }
256
257 @Override
258 public void onPause() {
259 mShouldUpdateUserList = true;
260 super.onPause();
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700261 }
262
263 @Override
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700264 public void onDestroy() {
265 super.onDestroy();
Amith Yamasanicfb8d7f2014-03-26 14:46:47 -0700266
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -0700267 if (!mUserCaps.mEnabled) return;
Amith Yamasanicfb8d7f2014-03-26 14:46:47 -0700268
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700269 getActivity().unregisterReceiver(mUserChangeReceiver);
270 }
271
272 @Override
Amith Yamasanic861cf82012-10-02 14:51:46 -0700273 public void onSaveInstanceState(Bundle outState) {
274 super.onSaveInstanceState(outState);
Amith Yamasaniee398742014-07-24 14:13:36 -0700275 mEditUserInfoController.onSaveInstanceState(outState);
Amith Yamasanic861cf82012-10-02 14:51:46 -0700276 outState.putInt(SAVE_ADDING_USER, mAddedUserId);
277 outState.putInt(SAVE_REMOVING_USER, mRemovingUserId);
278 }
279
280 @Override
Amith Yamasaniee398742014-07-24 14:13:36 -0700281 public void startActivityForResult(Intent intent, int requestCode) {
282 mEditUserInfoController.startingActivityForResult();
283 super.startActivityForResult(intent, requestCode);
284 }
285
286 @Override
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700287 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
Amith Yamasani247520c2014-07-25 12:52:29 -0700288 int pos = 0;
Fyodor Kupolov52ae0532016-02-24 15:54:10 -0800289 UserManager um = getContext().getSystemService(UserManager.class);
290 boolean allowRemoveUser = !um.hasUserRestriction(UserManager.DISALLOW_REMOVE_USER);
291 boolean canSwitchUsers = um.canSwitchUsers();
292 if (!mUserCaps.mIsAdmin && allowRemoveUser && canSwitchUsers) {
Amith Yamasani1a634d32012-09-27 23:01:35 -0700293 String nickname = mUserManager.getUserName();
Amith Yamasani247520c2014-07-25 12:52:29 -0700294 MenuItem removeThisUser = menu.add(0, MENU_REMOVE_USER, pos++,
Amith Yamasani1a634d32012-09-27 23:01:35 -0700295 getResources().getString(R.string.user_remove_user_menu, nickname));
296 removeThisUser.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700297 }
Amith Yamasani38223dc2012-09-18 09:51:07 -0700298 super.onCreateOptionsMenu(menu, inflater);
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700299 }
300
301 @Override
302 public boolean onOptionsItemSelected(MenuItem item) {
303 final int itemId = item.getItemId();
Amith Yamasanicc395692013-04-11 18:21:07 -0700304 if (itemId == MENU_REMOVE_USER) {
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700305 onRemoveUserClicked(UserHandle.myUserId());
306 return true;
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700307 } else {
308 return super.onOptionsItemSelected(item);
309 }
310 }
311
Amith Yamasanic16b73e2014-07-17 19:13:51 -0700312 /**
313 * Loads profile information for the current user.
314 */
Amith Yamasani32dccbc2012-09-13 18:06:49 -0700315 private void loadProfile() {
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -0700316 if (mUserCaps.mIsGuest) {
Amith Yamasanic16b73e2014-07-17 19:13:51 -0700317 // No need to load profile information
Alexandra Gherghinabc6e78f2014-09-03 10:22:09 +0100318 mMePreference.setIcon(getEncircledDefaultIcon());
Amith Yamasanic16b73e2014-07-17 19:13:51 -0700319 mMePreference.setTitle(R.string.user_exit_guest_title);
320 return;
321 }
322
Amith Yamasani32dccbc2012-09-13 18:06:49 -0700323 new AsyncTask<Void, Void, String>() {
324 @Override
325 protected void onPostExecute(String result) {
326 finishLoadProfile(result);
327 }
328
329 @Override
330 protected String doInBackground(Void... values) {
331 UserInfo user = mUserManager.getUserInfo(UserHandle.myUserId());
332 if (user.iconPath == null || user.iconPath.equals("")) {
333 assignProfilePhoto(user);
334 }
Amith Yamasani2d578ce2014-07-25 09:37:33 -0700335 return user.name;
Amith Yamasani32dccbc2012-09-13 18:06:49 -0700336 }
337 }.execute();
338 }
339
340 private void finishLoadProfile(String profileName) {
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700341 if (getActivity() == null) return;
342 mMePreference.setTitle(getString(R.string.user_you, profileName));
Amith Yamasanif34a85d2012-09-17 18:31:45 -0700343 int myUserId = UserHandle.myUserId();
344 Bitmap b = mUserManager.getUserIcon(myUserId);
345 if (b != null) {
Amith Yamasani864e3b72013-03-27 12:27:01 -0700346 mMePreference.setIcon(encircle(b));
347 mUserIcons.put(myUserId, b);
Amith Yamasanif34a85d2012-09-17 18:31:45 -0700348 }
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700349 }
350
Amith Yamasanif162efe2013-04-29 10:43:05 -0700351 private boolean hasLockscreenSecurity() {
352 LockPatternUtils lpu = new LockPatternUtils(getActivity());
Adrian Roos54375882015-04-16 17:11:22 -0700353 return lpu.isSecure(UserHandle.myUserId());
Amith Yamasanif162efe2013-04-29 10:43:05 -0700354 }
355
356 private void launchChooseLockscreen() {
357 Intent chooseLockIntent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
358 chooseLockIntent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.MINIMUM_QUALITY_KEY,
359 DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
360 startActivityForResult(chooseLockIntent, REQUEST_CHOOSE_LOCK);
361 }
362
363 @Override
364 public void onActivityResult(int requestCode, int resultCode, Intent data) {
365 super.onActivityResult(requestCode, resultCode, data);
366
367 if (requestCode == REQUEST_CHOOSE_LOCK) {
368 if (resultCode != Activity.RESULT_CANCELED && hasLockscreenSecurity()) {
369 addUserNow(USER_TYPE_RESTRICTED_PROFILE);
Amith Yamasanif162efe2013-04-29 10:43:05 -0700370 }
Amith Yamasaniee398742014-07-24 14:13:36 -0700371 } else {
372 mEditUserInfoController.onActivityResult(requestCode, resultCode, data);
Amith Yamasanif162efe2013-04-29 10:43:05 -0700373 }
374 }
375
Amith Yamasanicc395692013-04-11 18:21:07 -0700376 private void onAddUserClicked(int userType) {
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700377 synchronized (mUserLock) {
378 if (mRemovingUserId == -1 && !mAddingUser) {
Amith Yamasanicc395692013-04-11 18:21:07 -0700379 switch (userType) {
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700380 case USER_TYPE_USER:
381 showDialog(DIALOG_ADD_USER);
Amith Yamasanicc395692013-04-11 18:21:07 -0700382 break;
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700383 case USER_TYPE_RESTRICTED_PROFILE:
Amith Yamasanif162efe2013-04-29 10:43:05 -0700384 if (hasLockscreenSecurity()) {
385 addUserNow(USER_TYPE_RESTRICTED_PROFILE);
386 } else {
387 showDialog(DIALOG_NEED_LOCKSCREEN);
388 }
Amith Yamasanicc395692013-04-11 18:21:07 -0700389 break;
390 }
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700391 }
392 }
393 }
394
395 private void onRemoveUserClicked(int userId) {
396 synchronized (mUserLock) {
397 if (mRemovingUserId == -1 && !mAddingUser) {
398 mRemovingUserId = userId;
399 showDialog(DIALOG_CONFIRM_REMOVE);
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700400 }
401 }
402 }
403
Fyodor Kupolov9938f6f2015-08-26 17:24:09 -0700404 private UserInfo createRestrictedProfile() {
405 UserInfo newUserInfo = mUserManager.createRestrictedProfile(
406 getResources().getString(R.string.user_new_profile_name));
Alexandra Gherghinabc6e78f2014-09-03 10:22:09 +0100407 assignDefaultPhoto(newUserInfo);
Amith Yamasanicc395692013-04-11 18:21:07 -0700408 return newUserInfo;
409 }
410
411 private UserInfo createTrustedUser() {
Xiaohui Chen8ae46802015-07-16 14:31:41 -0700412 UserInfo newUserInfo = mUserManager.createUser(
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700413 getResources().getString(R.string.user_new_user_name), 0);
Amith Yamasanicc395692013-04-11 18:21:07 -0700414 if (newUserInfo != null) {
415 assignDefaultPhoto(newUserInfo);
416 }
417 return newUserInfo;
418 }
419
420 private void onManageUserClicked(int userId, boolean newUser) {
Amith Yamasani9e6ac3d2014-06-30 15:31:37 +0530421 if (userId == UserPreference.USERID_GUEST_DEFAULTS) {
422 Bundle extras = new Bundle();
423 extras.putBoolean(UserDetailsSettings.EXTRA_USER_GUEST, true);
424 ((SettingsActivity) getActivity()).startPreferencePanel(
425 UserDetailsSettings.class.getName(),
426 extras, R.string.user_guest, null, null, 0);
427 return;
428 }
Amith Yamasanid4abdd22013-04-17 18:27:01 -0700429 UserInfo info = mUserManager.getUserInfo(userId);
Xiaohui Chen64f530c2015-06-24 12:35:07 -0700430 if (info.isRestricted() && mUserCaps.mIsAdmin) {
Amith Yamasanid4abdd22013-04-17 18:27:01 -0700431 Bundle extras = new Bundle();
Amith Yamasani0ca80fe2013-06-03 16:41:03 -0700432 extras.putInt(RestrictedProfileSettings.EXTRA_USER_ID, userId);
433 extras.putBoolean(RestrictedProfileSettings.EXTRA_NEW_USER, newUser);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800434 ((SettingsActivity) getActivity()).startPreferencePanel(
Amith Yamasani0ca80fe2013-06-03 16:41:03 -0700435 RestrictedProfileSettings.class.getName(),
Amith Yamasani7c4dfcc2013-05-22 12:51:30 -0700436 extras, R.string.user_restrictions_title, null,
Amith Yamasanid4abdd22013-04-17 18:27:01 -0700437 null, 0);
438 } else if (info.id == UserHandle.myUserId()) {
439 // Jump to owner info panel
Jason Monk3bcd76c2015-04-21 11:20:20 -0400440 OwnerInfoSettings.show(this);
Xiaohui Chen64f530c2015-06-24 12:35:07 -0700441 } else if (mUserCaps.mIsAdmin) {
Amith Yamasani9e6ac3d2014-06-30 15:31:37 +0530442 Bundle extras = new Bundle();
443 extras.putInt(UserDetailsSettings.EXTRA_USER_ID, userId);
444 ((SettingsActivity) getActivity()).startPreferencePanel(
445 UserDetailsSettings.class.getName(),
Amith Yamasani51c6dac2014-07-02 00:06:37 +0530446 extras,
447 -1, /* No title res id */
448 info.name, /* title */
449 null, /* resultTo */
450 0 /* resultRequestCode */);
Amith Yamasanicc395692013-04-11 18:21:07 -0700451 }
Amith Yamasani233592b2013-03-01 17:05:23 -0800452 }
453
Amith Yamasaniae47ef42012-09-16 17:53:35 -0700454 private void onUserCreated(int userId) {
455 mAddedUserId = userId;
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700456 if (mUserManager.getUserInfo(userId).isRestricted()) {
457 showDialog(DIALOG_SETUP_PROFILE);
458 } else {
459 showDialog(DIALOG_SETUP_USER);
460 }
Amith Yamasaniae47ef42012-09-16 17:53:35 -0700461 }
462
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700463 @Override
Amith Yamasanic861cf82012-10-02 14:51:46 -0700464 public void onDialogShowing() {
465 super.onDialogShowing();
466
467 setOnDismissListener(this);
468 }
469
470 @Override
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700471 public Dialog onCreateDialog(int dialogId) {
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700472 Context context = getActivity();
473 if (context == null) return null;
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700474 switch (dialogId) {
Amith Yamasanic861cf82012-10-02 14:51:46 -0700475 case DIALOG_CONFIRM_REMOVE: {
Amith Yamasani9e6ac3d2014-06-30 15:31:37 +0530476 Dialog dlg =
Fyodor Kupolovdbbd4fc2014-12-29 13:40:27 -0800477 UserDialogs.createRemoveDialog(getActivity(), mRemovingUserId,
Amith Yamasani9e6ac3d2014-06-30 15:31:37 +0530478 new DialogInterface.OnClickListener() {
479 public void onClick(DialogInterface dialog, int which) {
480 removeUserNow();
481 }
482 }
483 );
Amith Yamasanic861cf82012-10-02 14:51:46 -0700484 return dlg;
485 }
Amith Yamasani1a634d32012-09-27 23:01:35 -0700486 case DIALOG_USER_CANNOT_MANAGE:
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700487 return new AlertDialog.Builder(context)
Amith Yamasani1a634d32012-09-27 23:01:35 -0700488 .setMessage(R.string.user_cannot_manage_message)
489 .setPositiveButton(android.R.string.ok, null)
490 .create();
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700491 case DIALOG_ADD_USER: {
Svetoslav Ganov263f7442012-09-25 16:11:16 -0700492 final SharedPreferences preferences = getActivity().getPreferences(
493 Context.MODE_PRIVATE);
494 final boolean longMessageDisplayed = preferences.getBoolean(
495 KEY_ADD_USER_LONG_MESSAGE_DISPLAYED, false);
496 final int messageResId = longMessageDisplayed
497 ? R.string.user_add_user_message_short
498 : R.string.user_add_user_message_long;
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700499 final int userType = dialogId == DIALOG_ADD_USER
500 ? USER_TYPE_USER : USER_TYPE_RESTRICTED_PROFILE;
501 Dialog dlg = new AlertDialog.Builder(context)
502 .setTitle(R.string.user_add_user_title)
503 .setMessage(messageResId)
504 .setPositiveButton(android.R.string.ok,
505 new DialogInterface.OnClickListener() {
506 public void onClick(DialogInterface dialog, int which) {
507 addUserNow(userType);
508 if (!longMessageDisplayed) {
509 preferences.edit().putBoolean(
510 KEY_ADD_USER_LONG_MESSAGE_DISPLAYED, true).apply();
511 }
Svetoslav Ganov263f7442012-09-25 16:11:16 -0700512 }
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700513 })
514 .setNegativeButton(android.R.string.cancel, null)
515 .create();
Amith Yamasanic861cf82012-10-02 14:51:46 -0700516 return dlg;
517 }
518 case DIALOG_SETUP_USER: {
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700519 Dialog dlg = new AlertDialog.Builder(context)
520 .setTitle(R.string.user_setup_dialog_title)
521 .setMessage(R.string.user_setup_dialog_message)
522 .setPositiveButton(R.string.user_setup_button_setup_now,
523 new DialogInterface.OnClickListener() {
524 public void onClick(DialogInterface dialog, int which) {
525 switchUserNow(mAddedUserId);
526 }
527 })
528 .setNegativeButton(R.string.user_setup_button_setup_later, null)
529 .create();
530 return dlg;
531 }
532 case DIALOG_SETUP_PROFILE: {
533 Dialog dlg = new AlertDialog.Builder(context)
534 .setMessage(R.string.user_setup_profile_dialog_message)
535 .setPositiveButton(android.R.string.ok,
536 new DialogInterface.OnClickListener() {
537 public void onClick(DialogInterface dialog, int which) {
538 switchUserNow(mAddedUserId);
539 }
540 })
541 .setNegativeButton(android.R.string.cancel, null)
542 .create();
543 return dlg;
544 }
545 case DIALOG_CHOOSE_USER_TYPE: {
546 List<HashMap<String, String>> data = new ArrayList<HashMap<String,String>>();
547 HashMap<String,String> addUserItem = new HashMap<String,String>();
548 addUserItem.put(KEY_TITLE, getString(R.string.user_add_user_item_title));
549 addUserItem.put(KEY_SUMMARY, getString(R.string.user_add_user_item_summary));
550 HashMap<String,String> addProfileItem = new HashMap<String,String>();
551 addProfileItem.put(KEY_TITLE, getString(R.string.user_add_profile_item_title));
552 addProfileItem.put(KEY_SUMMARY, getString(R.string.user_add_profile_item_summary));
553 data.add(addUserItem);
554 data.add(addProfileItem);
Amith Yamasanif3db0212014-12-02 17:21:23 -0800555 AlertDialog.Builder builder = new AlertDialog.Builder(context);
556 SimpleAdapter adapter = new SimpleAdapter(builder.getContext(),
557 data, R.layout.two_line_list_item,
558 new String[] {KEY_TITLE, KEY_SUMMARY},
559 new int[] {R.id.title, R.id.summary});
560 builder.setTitle(R.string.user_add_user_type_title);
561 builder.setAdapter(adapter,
562 new DialogInterface.OnClickListener() {
563 @Override
564 public void onClick(DialogInterface dialog, int which) {
565 onAddUserClicked(which == 0
566 ? USER_TYPE_USER
567 : USER_TYPE_RESTRICTED_PROFILE);
568 }
569 });
570 return builder.create();
Amith Yamasanic861cf82012-10-02 14:51:46 -0700571 }
Amith Yamasanif162efe2013-04-29 10:43:05 -0700572 case DIALOG_NEED_LOCKSCREEN: {
573 Dialog dlg = new AlertDialog.Builder(context)
574 .setMessage(R.string.user_need_lock_message)
575 .setPositiveButton(R.string.user_set_lock_button,
576 new DialogInterface.OnClickListener() {
577 @Override
578 public void onClick(DialogInterface dialog, int which) {
579 launchChooseLockscreen();
580 }
581 })
582 .setNegativeButton(android.R.string.cancel, null)
583 .create();
584 return dlg;
585 }
Amith Yamasanic16b73e2014-07-17 19:13:51 -0700586 case DIALOG_CONFIRM_EXIT_GUEST: {
587 Dialog dlg = new AlertDialog.Builder(context)
588 .setTitle(R.string.user_exit_guest_confirm_title)
589 .setMessage(R.string.user_exit_guest_confirm_message)
Amith Yamasani94c01812014-08-18 16:42:43 -0700590 .setPositiveButton(R.string.user_exit_guest_dialog_remove,
Amith Yamasanic16b73e2014-07-17 19:13:51 -0700591 new DialogInterface.OnClickListener() {
592 @Override
593 public void onClick(DialogInterface dialog, int which) {
594 exitGuest();
595 }
596 })
Amith Yamasani94c01812014-08-18 16:42:43 -0700597 .setNegativeButton(android.R.string.cancel, null)
Amith Yamasanic16b73e2014-07-17 19:13:51 -0700598 .create();
599 return dlg;
600 }
Amith Yamasaniee398742014-07-24 14:13:36 -0700601 case DIALOG_USER_PROFILE_EDITOR: {
602 Dialog dlg = mEditUserInfoController.createDialog(
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -0700603 this,
Amith Yamasaniee398742014-07-24 14:13:36 -0700604 mMePreference.getIcon(),
605 mMePreference.getTitle(),
606 R.string.profile_info_settings_title,
607 this /* callback */,
608 android.os.Process.myUserHandle());
609 return dlg;
610 }
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700611 default:
612 return null;
613 }
614 }
615
mariagpuyol60435fc2016-01-28 14:58:03 -0800616 private boolean emergencyInfoActivityPresent() {
617 Intent intent = new Intent(ACTION_EDIT_EMERGENCY_INFO).setPackage("com.android.emergency");
618 List<ResolveInfo> infos = getContext().getPackageManager().queryIntentActivities(intent, 0);
619 if (infos == null || infos.isEmpty()) {
620 return false;
621 }
622 return true;
623 }
624
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700625 private void removeUserNow() {
626 if (mRemovingUserId == UserHandle.myUserId()) {
627 removeThisUser();
628 } else {
629 new Thread() {
630 public void run() {
631 synchronized (mUserLock) {
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700632 mUserManager.removeUser(mRemovingUserId);
633 mHandler.sendEmptyMessage(MESSAGE_UPDATE_LIST);
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700634 }
635 }
636 }.start();
637 }
638 }
639
640 private void removeThisUser() {
Fyodor Kupolov52ae0532016-02-24 15:54:10 -0800641 if (!mUserManager.canSwitchUsers()) {
642 Log.w(TAG, "Cannot remove current user when switching is disabled");
643 return;
644 }
Amith Yamasaniae47ef42012-09-16 17:53:35 -0700645 try {
Xiaohui Chen64f530c2015-06-24 12:35:07 -0700646 ActivityManagerNative.getDefault().switchUser(UserHandle.USER_SYSTEM);
Fyodor Kupolov52ae0532016-02-24 15:54:10 -0800647 getContext().getSystemService(UserManager.class).removeUser(UserHandle.myUserId());
Amith Yamasaniae47ef42012-09-16 17:53:35 -0700648 } catch (RemoteException re) {
649 Log.e(TAG, "Unable to remove self user");
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700650 }
651 }
652
Amith Yamasanicc395692013-04-11 18:21:07 -0700653 private void addUserNow(final int userType) {
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700654 synchronized (mUserLock) {
655 mAddingUser = true;
Amith Yamasania98c4022013-04-19 15:27:52 -0700656 //updateUserList();
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700657 new Thread() {
658 public void run() {
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -0700659 UserInfo user;
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700660 // Could take a few seconds
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700661 if (userType == USER_TYPE_USER) {
Amith Yamasanicc395692013-04-11 18:21:07 -0700662 user = createTrustedUser();
663 } else {
Fyodor Kupolov9938f6f2015-08-26 17:24:09 -0700664 user = createRestrictedProfile();
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700665 }
666 synchronized (mUserLock) {
667 mAddingUser = false;
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700668 if (userType == USER_TYPE_USER) {
Amith Yamasania98c4022013-04-19 15:27:52 -0700669 mHandler.sendEmptyMessage(MESSAGE_UPDATE_LIST);
Amith Yamasanicc395692013-04-11 18:21:07 -0700670 mHandler.sendMessage(mHandler.obtainMessage(
671 MESSAGE_SETUP_USER, user.id, user.serialNumber));
672 } else {
673 mHandler.sendMessage(mHandler.obtainMessage(
674 MESSAGE_CONFIG_USER, user.id, user.serialNumber));
675 }
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700676 }
677 }
678 }.start();
679 }
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700680 }
681
Amith Yamasaniae47ef42012-09-16 17:53:35 -0700682 private void switchUserNow(int userId) {
683 try {
684 ActivityManagerNative.getDefault().switchUser(userId);
685 } catch (RemoteException re) {
686 // Nothing to do
687 }
688 }
689
Amith Yamasanic16b73e2014-07-17 19:13:51 -0700690 /**
691 * Erase the current user (guest) and switch to another user.
692 */
693 private void exitGuest() {
694 // Just to be safe
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -0700695 if (!mUserCaps.mIsGuest) {
Amith Yamasanic16b73e2014-07-17 19:13:51 -0700696 return;
697 }
698 removeThisUser();
699 }
700
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700701 private void updateUserList() {
Amith Yamasanif34a85d2012-09-17 18:31:45 -0700702 if (getActivity() == null) return;
Amith Yamasanie278eda2012-09-20 22:44:48 -0700703 List<UserInfo> users = mUserManager.getUsers(true);
Amith Yamasani9e6ac3d2014-06-30 15:31:37 +0530704 final Context context = getActivity();
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700705
Amith Yamasani9e6ac3d2014-06-30 15:31:37 +0530706 final boolean voiceCapable = Utils.isVoiceCapable(context);
Fyodor Kupolov55145092014-12-08 14:15:36 -0800707 final ArrayList<Integer> missingIcons = new ArrayList<>();
708 final ArrayList<UserPreference> userPreferences = new ArrayList<>();
709 userPreferences.add(mMePreference);
710
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700711 for (UserInfo user : users) {
Xiaohui Chen148ef772015-07-16 10:06:03 -0700712 if (!user.supportsSwitchToByUser()) {
713 // Only users that can be switched to should show up here.
714 // e.g. Managed profiles appear under Accounts Settings instead
Alexandra Gherghina83adb562014-07-31 19:30:41 +0100715 continue;
716 }
Fyodor Kupolov55145092014-12-08 14:15:36 -0800717 UserPreference pref;
Amith Yamasanic861cf82012-10-02 14:51:46 -0700718 if (user.id == UserHandle.myUserId()) {
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700719 pref = mMePreference;
Amith Yamasani9e6ac3d2014-06-30 15:31:37 +0530720 } else if (user.isGuest()) {
721 // Skip over Guest. We add generic Guest settings after this loop
722 continue;
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700723 } else {
Amith Yamasani9e6ac3d2014-06-30 15:31:37 +0530724 // With Telephony:
725 // Secondary user: Settings
726 // Guest: Settings
727 // Restricted Profile: There is no Restricted Profile
728 // Without Telephony:
729 // Secondary user: Delete
730 // Guest: Nothing
731 // Restricted Profile: Settings
Xiaohui Chen64f530c2015-06-24 12:35:07 -0700732 final boolean showSettings = mUserCaps.mIsAdmin
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -0700733 && (voiceCapable || user.isRestricted());
Xiaohui Chen64f530c2015-06-24 12:35:07 -0700734 final boolean showDelete = mUserCaps.mIsAdmin
Amith Yamasani9e6ac3d2014-06-30 15:31:37 +0530735 && (!voiceCapable && !user.isRestricted() && !user.isGuest());
Jason Monk39b46742015-09-10 15:52:51 -0400736 pref = new UserPreference(getPrefContext(), null, user.id,
Amith Yamasani9e6ac3d2014-06-30 15:31:37 +0530737 showSettings ? this : null,
738 showDelete ? this : null);
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700739 pref.setOnPreferenceClickListener(this);
740 pref.setKey("id=" + user.id);
Fyodor Kupolov55145092014-12-08 14:15:36 -0800741 userPreferences.add(pref);
Xiaohui Chen64f530c2015-06-24 12:35:07 -0700742 if (user.isAdmin()) {
743 pref.setSummary(R.string.user_admin);
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700744 }
745 pref.setTitle(user.name);
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700746 }
747 if (!isInitialized(user)) {
Alexandra Gherghina423bafc2014-04-23 10:56:37 +0000748 if (user.isRestricted()) {
749 pref.setSummary(R.string.user_summary_restricted_not_set_up);
Alexandra Gherghina423bafc2014-04-23 10:56:37 +0000750 } else {
751 pref.setSummary(R.string.user_summary_not_set_up);
752 }
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700753 } else if (user.isRestricted()) {
754 pref.setSummary(R.string.user_summary_restricted_profile);
Amith Yamasani48fa8572012-04-17 17:12:01 -0700755 }
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700756 if (user.iconPath != null) {
Amith Yamasanif34a85d2012-09-17 18:31:45 -0700757 if (mUserIcons.get(user.id) == null) {
Alexandra Gherghinabc6e78f2014-09-03 10:22:09 +0100758 // Icon not loaded yet, print a placeholder
Amith Yamasanif34a85d2012-09-17 18:31:45 -0700759 missingIcons.add(user.id);
Alexandra Gherghinabc6e78f2014-09-03 10:22:09 +0100760 pref.setIcon(getEncircledDefaultIcon());
Amith Yamasanif34a85d2012-09-17 18:31:45 -0700761 } else {
762 setPhotoId(pref, user);
763 }
Amith Yamasanif2663ab2014-08-11 17:17:29 -0700764 } else {
Alexandra Gherghinabc6e78f2014-09-03 10:22:09 +0100765 // Icon not available yet, print a placeholder
766 pref.setIcon(getEncircledDefaultIcon());
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700767 }
768 }
Amith Yamasani247520c2014-07-25 12:52:29 -0700769
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700770 // Add a temporary entry for the user being created
771 if (mAddingUser) {
Jason Monk39b46742015-09-10 15:52:51 -0400772 UserPreference pref = new UserPreference(getPrefContext(), null,
Fyodor Kupolov55145092014-12-08 14:15:36 -0800773 UserPreference.USERID_UNKNOWN, null, null);
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700774 pref.setEnabled(false);
775 pref.setTitle(R.string.user_new_user_name);
Alexandra Gherghinabc6e78f2014-09-03 10:22:09 +0100776 pref.setIcon(getEncircledDefaultIcon());
Fyodor Kupolov55145092014-12-08 14:15:36 -0800777 userPreferences.add(pref);
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700778 }
Amith Yamasani9e6ac3d2014-06-30 15:31:37 +0530779
Fyodor Kupolov889bc3d2016-01-29 17:29:54 -0800780 // Check if Guest tile should be added.
Sudheer Shanka29737ad2016-02-11 17:17:21 +0000781 if (!mUserCaps.mIsGuest && (mUserCaps.mCanAddGuest ||
782 mUserCaps.mDisallowAddUserSetByAdmin)) {
783 // Add a virtual Guest user for guest defaults
Jason Monk39b46742015-09-10 15:52:51 -0400784 UserPreference pref = new UserPreference(getPrefContext(), null,
Fyodor Kupolov55145092014-12-08 14:15:36 -0800785 UserPreference.USERID_GUEST_DEFAULTS,
Xiaohui Chen64f530c2015-06-24 12:35:07 -0700786 mUserCaps.mIsAdmin && voiceCapable? this : null /* settings icon handler */,
Fyodor Kupolov55145092014-12-08 14:15:36 -0800787 null /* delete icon handler */);
788 pref.setTitle(R.string.user_guest);
789 pref.setIcon(getEncircledDefaultIcon());
Fyodor Kupolov55145092014-12-08 14:15:36 -0800790 userPreferences.add(pref);
Sudheer Shanka682a9162016-01-13 22:10:18 +0000791 pref.setDisabledByAdmin(
792 mUserCaps.mDisallowAddUser ? mUserCaps.mEnforcedAdmin : null);
Fyodor Kupolov55145092014-12-08 14:15:36 -0800793 }
794
795 // Sort list of users by serialNum
796 Collections.sort(userPreferences, UserPreference.SERIAL_NUMBER_COMPARATOR);
797
798 getActivity().invalidateOptionsMenu();
799
800 // Load the icons
801 if (missingIcons.size() > 0) {
802 loadIconsAsync(missingIcons);
803 }
804
805 PreferenceScreen preferenceScreen = getPreferenceScreen();
806 preferenceScreen.removeAll();
807
808 // If profiles are supported, userPreferences will be added to the category labeled
809 // "User & Profiles", otherwise the category is skipped and elements are added directly
810 // to preferenceScreen
811 PreferenceGroup groupToAddUsers;
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -0700812 if (mUserCaps.mCanAddRestrictedProfile) {
Fyodor Kupolov55145092014-12-08 14:15:36 -0800813 mUserListCategory.removeAll();
814 mUserListCategory.setOrder(Preference.DEFAULT_ORDER);
815 preferenceScreen.addPreference(mUserListCategory);
816 groupToAddUsers = mUserListCategory;
817 } else {
818 groupToAddUsers = preferenceScreen;
819 }
820 for (UserPreference userPreference : userPreferences) {
821 userPreference.setOrder(Preference.DEFAULT_ORDER);
822 groupToAddUsers.addPreference(userPreference);
823 }
824
825 // Append Add user to the end of the list
Sudheer Shanka29737ad2016-02-11 17:17:21 +0000826 if (mUserCaps.mCanAddUser || mUserCaps.mDisallowAddUserSetByAdmin) {
Fyodor Kupolov55145092014-12-08 14:15:36 -0800827 boolean moreUsers = mUserManager.canAddMoreUsers();
Fyodor Kupolov55145092014-12-08 14:15:36 -0800828 mAddUser.setOrder(Preference.DEFAULT_ORDER);
829 preferenceScreen.addPreference(mAddUser);
Fyodor Kupolova7a7bfe2015-05-08 15:54:38 -0700830 mAddUser.setEnabled(moreUsers);
831 if (!moreUsers) {
832 mAddUser.setSummary(getString(R.string.user_add_max_count, getMaxRealUsers()));
833 } else {
834 mAddUser.setSummary(null);
835 }
Sudheer Shanka682a9162016-01-13 22:10:18 +0000836 if (mAddUser.isEnabled()) {
837 mAddUser.setDisabledByAdmin(
838 mUserCaps.mDisallowAddUser ? mUserCaps.mEnforcedAdmin : null);
839 }
Fyodor Kupolov55145092014-12-08 14:15:36 -0800840 }
Sudheer Shanka29737ad2016-02-11 17:17:21 +0000841 if (mUserCaps.mIsAdmin &&
842 (!mUserCaps.mDisallowAddUser || mUserCaps.mDisallowAddUserSetByAdmin)) {
Fyodor Kupolov8ba52d62016-01-05 14:30:03 -0800843 mLockScreenSettings.setOrder(Preference.DEFAULT_ORDER);
844 preferenceScreen.addPreference(mLockScreenSettings);
845 mAddUserWhenLocked.setChecked(Settings.Global.getInt(getContentResolver(),
846 Settings.Global.ADD_USERS_WHEN_LOCKED, 0) == 1);
847 mAddUserWhenLocked.setOnPreferenceChangeListener(this);
Sudheer Shanka682a9162016-01-13 22:10:18 +0000848 mAddUserWhenLocked.setDisabledByAdmin(
849 mUserCaps.mDisallowAddUser ? mUserCaps.mEnforcedAdmin : null);
Fyodor Kupolov8ba52d62016-01-05 14:30:03 -0800850 }
mariagpuyolfe19bc32016-02-17 19:23:24 -0800851
852 if (emergencyInfoActivityPresent()) {
853 mEmergencyInfoPreference.setOnPreferenceClickListener(this);
854 mEmergencyInfoPreference.setOrder(Preference.DEFAULT_ORDER);
855 preferenceScreen.addPreference(mEmergencyInfoPreference);
856 }
Fyodor Kupolov55145092014-12-08 14:15:36 -0800857 }
858
Fyodor Kupolova7a7bfe2015-05-08 15:54:38 -0700859 private int getMaxRealUsers() {
860 // guest is not counted against getMaxSupportedUsers() number
861 final int maxUsersAndGuest = UserManager.getMaxSupportedUsers() + 1;
862 final List<UserInfo> users = mUserManager.getUsers();
863 // managed profiles are counted against getMaxSupportedUsers()
864 int managedProfiles = 0;
865 for (UserInfo user : users) {
866 if (user.isManagedProfile()) {
867 managedProfiles++;
868 }
869 }
870 return maxUsersAndGuest - managedProfiles;
871 }
872
Amith Yamasanif34a85d2012-09-17 18:31:45 -0700873 private void loadIconsAsync(List<Integer> missingIcons) {
874 new AsyncTask<List<Integer>, Void, Void>() {
875 @Override
876 protected void onPostExecute(Void result) {
877 updateUserList();
878 }
879
880 @Override
881 protected Void doInBackground(List<Integer>... values) {
Amith Yamasanif34a85d2012-09-17 18:31:45 -0700882 for (int userId : values[0]) {
883 Bitmap bitmap = mUserManager.getUserIcon(userId);
Amith Yamasanif2663ab2014-08-11 17:17:29 -0700884 if (bitmap == null) {
Zoltan Szatmary-Bane5814ff2014-12-19 16:27:45 +0000885 bitmap = Utils.getDefaultUserIconAsBitmap(userId);
Amith Yamasanif2663ab2014-08-11 17:17:29 -0700886 }
Amith Yamasani864e3b72013-03-27 12:27:01 -0700887 mUserIcons.append(userId, bitmap);
Amith Yamasanif34a85d2012-09-17 18:31:45 -0700888 }
889 return null;
890 }
891 }.execute(missingIcons);
Amith Yamasanif34a85d2012-09-17 18:31:45 -0700892 }
Amith Yamasani5cdc9372012-11-14 16:23:40 -0800893
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700894 private void assignProfilePhoto(final UserInfo user) {
Amith Yamasaniae47ef42012-09-16 17:53:35 -0700895 if (!Utils.copyMeProfilePhoto(getActivity(), user)) {
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700896 assignDefaultPhoto(user);
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700897 }
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700898 }
899
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700900 private void assignDefaultPhoto(UserInfo user) {
Zoltan Szatmary-Bane5814ff2014-12-19 16:27:45 +0000901 Bitmap bitmap = Utils.getDefaultUserIconAsBitmap(user.id);
Amith Yamasanif34a85d2012-09-17 18:31:45 -0700902 mUserManager.setUserIcon(user.id, bitmap);
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700903 }
904
Alexandra Gherghinabc6e78f2014-09-03 10:22:09 +0100905 private Drawable getEncircledDefaultIcon() {
906 if (mDefaultIconDrawable == null) {
Zoltan Szatmary-Bane5814ff2014-12-19 16:27:45 +0000907 mDefaultIconDrawable = encircle(Utils.getDefaultUserIconAsBitmap(UserHandle.USER_NULL));
Amith Yamasanic16b73e2014-07-17 19:13:51 -0700908 }
Alexandra Gherghinabc6e78f2014-09-03 10:22:09 +0100909 return mDefaultIconDrawable;
Amith Yamasanic16b73e2014-07-17 19:13:51 -0700910 }
911
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700912 private void setPhotoId(Preference pref, UserInfo user) {
Amith Yamasanid4abdd22013-04-17 18:27:01 -0700913 Bitmap bitmap = mUserIcons.get(user.id);
Amith Yamasani864e3b72013-03-27 12:27:01 -0700914 if (bitmap != null) {
915 pref.setIcon(encircle(bitmap));
Amith Yamasanie940dac2012-09-17 10:21:27 -0700916 }
Amith Yamasani48fa8572012-04-17 17:12:01 -0700917 }
918
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700919 @Override
920 public boolean onPreferenceClick(Preference pref) {
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700921 if (pref == mMePreference) {
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -0700922 if (mUserCaps.mIsGuest) {
Amith Yamasanic16b73e2014-07-17 19:13:51 -0700923 showDialog(DIALOG_CONFIRM_EXIT_GUEST);
924 return true;
925 }
Amith Yamasanid4abdd22013-04-17 18:27:01 -0700926 // If this is a limited user, launch the user info settings instead of profile editor
927 if (mUserManager.isLinkedUser()) {
928 onManageUserClicked(UserHandle.myUserId(), false);
929 } else {
Amith Yamasaniee398742014-07-24 14:13:36 -0700930 showDialog(DIALOG_USER_PROFILE_EDITOR);
Amith Yamasanid4abdd22013-04-17 18:27:01 -0700931 }
Amith Yamasani1a634d32012-09-27 23:01:35 -0700932 } else if (pref instanceof UserPreference) {
933 int userId = ((UserPreference) pref).getUserId();
Fyodor Kupolov889bc3d2016-01-29 17:29:54 -0800934 // Get the latest status of the user
935 UserInfo user = mUserManager.getUserInfo(userId);
936 if (!isInitialized(user)) {
937 mHandler.sendMessage(mHandler.obtainMessage(
938 MESSAGE_SETUP_USER, user.id, user.serialNumber));
Amith Yamasani1a634d32012-09-27 23:01:35 -0700939 }
Amith Yamasanifc8a3832013-04-23 11:44:59 -0700940 } else if (pref == mAddUser) {
Amith Yamasani0e43d322014-05-07 10:19:34 -0700941 // If we allow both types, show a picker, otherwise directly go to
942 // flow for full user.
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -0700943 if (mUserCaps.mCanAddRestrictedProfile) {
Amith Yamasani0e43d322014-05-07 10:19:34 -0700944 showDialog(DIALOG_CHOOSE_USER_TYPE);
945 } else {
946 onAddUserClicked(USER_TYPE_USER);
947 }
mariagpuyol60435fc2016-01-28 14:58:03 -0800948 } else if (pref == mEmergencyInfoPreference) {
949 Intent intent = new Intent(ACTION_EDIT_EMERGENCY_INFO);
950 startActivity(intent);
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700951 }
952 return false;
953 }
954
Amith Yamasani1a634d32012-09-27 23:01:35 -0700955 private boolean isInitialized(UserInfo user) {
956 return (user.flags & UserInfo.FLAG_INITIALIZED) != 0;
957 }
958
Amith Yamasani864e3b72013-03-27 12:27:01 -0700959 private Drawable encircle(Bitmap icon) {
960 Drawable circled = CircleFramedDrawable.getInstance(getActivity(), icon);
961 return circled;
962 }
963
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700964 @Override
965 public void onClick(View v) {
966 if (v.getTag() instanceof UserPreference) {
967 int userId = ((UserPreference) v.getTag()).getUserId();
Amith Yamasani233592b2013-03-01 17:05:23 -0800968 switch (v.getId()) {
969 case UserPreference.DELETE_ID:
Maggie Benthall44534962013-08-29 10:49:13 -0400970 onRemoveUserClicked(userId);
Amith Yamasani233592b2013-03-01 17:05:23 -0800971 break;
972 case UserPreference.SETTINGS_ID:
Amith Yamasanicc395692013-04-11 18:21:07 -0700973 onManageUserClicked(userId, false);
Amith Yamasani233592b2013-03-01 17:05:23 -0800974 break;
975 }
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700976 }
977 }
978
979 @Override
980 public void onDismiss(DialogInterface dialog) {
981 synchronized (mUserLock) {
982 mAddingUser = false;
983 mRemovingUserId = -1;
Amith Yamasanic861cf82012-10-02 14:51:46 -0700984 updateUserList();
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700985 }
986 }
987
988 @Override
989 public boolean onPreferenceChange(Preference preference, Object newValue) {
Fyodor Kupolov8ba52d62016-01-05 14:30:03 -0800990 if (preference == mAddUserWhenLocked) {
991 Boolean value = (Boolean) newValue;
992 Settings.Global.putInt(getContentResolver(), Settings.Global.ADD_USERS_WHEN_LOCKED,
993 value != null && value ? 1 : 0);
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700994 return true;
995 }
Fyodor Kupolov8ba52d62016-01-05 14:30:03 -0800996
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700997 return false;
998 }
Amith Yamasanidc6bfa62012-09-06 18:04:06 -0700999
Amith Yamasani38223dc2012-09-18 09:51:07 -07001000 @Override
1001 public int getHelpResource() {
1002 return R.string.help_url_users;
1003 }
Amith Yamasaniee398742014-07-24 14:13:36 -07001004
1005 @Override
1006 public void onPhotoChanged(Drawable photo) {
1007 mMePreference.setIcon(photo);
1008 }
1009
1010 @Override
1011 public void onLabelChanged(CharSequence label) {
1012 mMePreference.setTitle(label);
1013 }
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -07001014
1015 private static class UserCapabilities {
1016 boolean mEnabled = true;
1017 boolean mCanAddUser = true;
1018 boolean mCanAddRestrictedProfile = true;
Xiaohui Chen64f530c2015-06-24 12:35:07 -07001019 boolean mIsAdmin;
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -07001020 boolean mIsGuest;
Fyodor Kupolov097936a2015-05-21 18:31:45 -07001021 boolean mCanAddGuest;
Fyodor Kupolov8ba52d62016-01-05 14:30:03 -08001022 boolean mDisallowAddUser;
Sudheer Shanka29737ad2016-02-11 17:17:21 +00001023 boolean mDisallowAddUserSetByAdmin;
Sudheer Shanka682a9162016-01-13 22:10:18 +00001024 EnforcedAdmin mEnforcedAdmin;
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -07001025
Xiaohui Chen64f530c2015-06-24 12:35:07 -07001026 private UserCapabilities() {}
1027
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -07001028 public static UserCapabilities create(Context context) {
1029 UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
1030 UserCapabilities caps = new UserCapabilities();
1031 if (!UserManager.supportsMultipleUsers() || Utils.isMonkeyRunning()) {
1032 caps.mEnabled = false;
1033 return caps;
1034 }
1035
Xiaohui Chen64f530c2015-06-24 12:35:07 -07001036 final UserInfo myUserInfo = userManager.getUserInfo(UserHandle.myUserId());
1037 caps.mIsGuest = myUserInfo.isGuest();
1038 caps.mIsAdmin = myUserInfo.isAdmin();
Sudheer Shanka682a9162016-01-13 22:10:18 +00001039 caps.mEnforcedAdmin = RestrictedLockUtils.checkIfRestrictionEnforced(context,
1040 UserManager.DISALLOW_ADD_USER, UserHandle.myUserId());
Sudheer Shanka29737ad2016-02-11 17:17:21 +00001041 final boolean hasBaseUserRestriction = RestrictedLockUtils.hasBaseUserRestriction(
1042 context, UserManager.DISALLOW_ADD_USER, UserHandle.myUserId());
1043 caps.mDisallowAddUserSetByAdmin =
1044 caps.mEnforcedAdmin != null && !hasBaseUserRestriction;
1045 caps.mDisallowAddUser =
1046 (caps.mEnforcedAdmin != null || hasBaseUserRestriction);
Xiaohui Chen64f530c2015-06-24 12:35:07 -07001047 if (!caps.mIsAdmin || UserManager.getMaxSupportedUsers() < 2
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -07001048 || !UserManager.supportsMultipleUsers()
Fyodor Kupolov8ba52d62016-01-05 14:30:03 -08001049 || caps.mDisallowAddUser) {
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -07001050 caps.mCanAddUser = false;
1051 }
1052 DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
1053 Context.DEVICE_POLICY_SERVICE);
1054 // No restricted profiles for tablets with a device owner, or phones.
Makoto Onuki4cfe39f2015-11-19 13:47:55 -08001055 if (dpm.isDeviceManaged() || Utils.isVoiceCapable(context)) {
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -07001056 caps.mCanAddRestrictedProfile = false;
1057 }
Fyodor Kupolov097936a2015-05-21 18:31:45 -07001058
Xiaohui Chen64f530c2015-06-24 12:35:07 -07001059 final boolean canAddUsersWhenLocked = caps.mIsAdmin || Settings.Global.getInt(
Fyodor Kupolov097936a2015-05-21 18:31:45 -07001060 context.getContentResolver(), Settings.Global.ADD_USERS_WHEN_LOCKED, 0) == 1;
Fyodor Kupolov8ba52d62016-01-05 14:30:03 -08001061 caps.mCanAddGuest = !caps.mIsGuest && !caps.mDisallowAddUser && canAddUsersWhenLocked;
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -07001062 return caps;
1063 }
1064
1065 @Override
1066 public String toString() {
1067 return "UserCapabilities{" +
1068 "mEnabled=" + mEnabled +
1069 ", mCanAddUser=" + mCanAddUser +
1070 ", mCanAddRestrictedProfile=" + mCanAddRestrictedProfile +
Xiaohui Chen64f530c2015-06-24 12:35:07 -07001071 ", mIsAdmin=" + mIsAdmin +
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -07001072 ", mIsGuest=" + mIsGuest +
Sudheer Shanka682a9162016-01-13 22:10:18 +00001073 ", mCanAddGuest=" + mCanAddGuest +
1074 ", mDisallowAddUser=" + mDisallowAddUser +
1075 ", mEnforcedAdmin=" + mEnforcedAdmin +
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -07001076 '}';
1077 }
1078 }
1079
Jason Monk9d80eea2015-11-20 14:27:51 -05001080 private static class SummaryProvider implements SummaryLoader.SummaryProvider {
1081
1082 private final Context mContext;
1083 private final SummaryLoader mSummaryLoader;
1084
1085 public SummaryProvider(Context context, SummaryLoader summaryLoader) {
1086 mContext = context;
1087 mSummaryLoader = summaryLoader;
1088 }
1089
1090 @Override
1091 public void setListening(boolean listening) {
1092 if (listening) {
1093 UserInfo info = mContext.getSystemService(UserManager.class).getUserInfo(
1094 UserHandle.myUserId());
1095 mSummaryLoader.setSummary(this, mContext.getString(R.string.user_summary,
1096 info.name));
1097 }
1098 }
1099 }
1100
1101 public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
1102 = new SummaryLoader.SummaryProviderFactory() {
1103 @Override
1104 public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
1105 SummaryLoader summaryLoader) {
1106 return new SummaryProvider(activity, summaryLoader);
1107 }
1108 };
1109
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -07001110 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
1111 new BaseSearchIndexProvider() {
1112 @Override
1113 public List<SearchIndexableRaw> getRawDataToIndex(Context context,
1114 boolean enabled) {
1115 final List<SearchIndexableRaw> result = new ArrayList<>();
1116 final UserCapabilities userCaps = UserCapabilities.create(context);
1117 if (!userCaps.mEnabled) {
1118 return result;
1119 }
1120 final Resources res = context.getResources();
1121 SearchIndexableRaw data = new SearchIndexableRaw(context);
1122 data.title = res.getString(R.string.user_settings_title);
1123 data.screenTitle = res.getString(R.string.user_settings_title);
1124 result.add(data);
1125
Sudheer Shanka29737ad2016-02-11 17:17:21 +00001126 if (userCaps.mCanAddUser || userCaps.mDisallowAddUserSetByAdmin) {
Fyodor Kupolovc9a95ef2015-05-15 17:16:15 -07001127 data = new SearchIndexableRaw(context);
1128 data.title = res.getString(userCaps.mCanAddRestrictedProfile ?
1129 R.string.user_add_user_or_profile_menu
1130 : R.string.user_add_user_menu);
1131 data.screenTitle = res.getString(R.string.user_settings_title);
1132 result.add(data);
1133 }
1134 return result;
1135 }
1136 };
1137
Amith Yamasanib810a0d2012-03-25 10:12:26 -07001138}