summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/users
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2013-04-12 17:58:03 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-04-12 17:58:03 +0000
commit35f02378710a0fd33bf62d2d10e0c655fe07d519 (patch)
tree35e6fb36ed5831d6628a6a075dc0ab17d628e220 /src/com/android/settings/users
parenta2e64ac8151bafc1f89a6aaa0fa53f049fba21ba (diff)
parentcc395695fc869dc8ef8e3c74622f71ef8a421d44 (diff)
downloadpackages_apps_Settings-35f02378710a0fd33bf62d2d10e0c655fe07d519.tar.gz
packages_apps_Settings-35f02378710a0fd33bf62d2d10e0c655fe07d519.tar.bz2
packages_apps_Settings-35f02378710a0fd33bf62d2d10e0c655fe07d519.zip
Merge "Embed the app restrictions fragment in the dual-pane settings." into jb-mr2-dev
Diffstat (limited to 'src/com/android/settings/users')
-rw-r--r--src/com/android/settings/users/AppRestrictionsFragment.java72
-rw-r--r--src/com/android/settings/users/UserRestrictionsActivity.java141
-rw-r--r--src/com/android/settings/users/UserSettings.java123
3 files changed, 147 insertions, 189 deletions
diff --git a/src/com/android/settings/users/AppRestrictionsFragment.java b/src/com/android/settings/users/AppRestrictionsFragment.java
index 6ea583ee7..5e2868e63 100644
--- a/src/com/android/settings/users/AppRestrictionsFragment.java
+++ b/src/com/android/settings/users/AppRestrictionsFragment.java
@@ -16,6 +16,7 @@
package com.android.settings.users;
+import android.app.Activity;
import android.app.AppGlobals;
import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
@@ -37,6 +38,7 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.os.RemoteException;
+import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.preference.CheckBoxPreference;
@@ -71,6 +73,7 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
@@ -95,9 +98,17 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
private static final int MAX_APP_RESTRICTIONS = 100;
private static final String DELIMITER = ";";
+
+ /** Key for extra passed in from calling fragment for the userId of the user being edited */
+ public static final String EXTRA_USER_ID = "user_id";
+
+ /** Key for extra passed in from calling fragment to indicate if this is a newly created user */
+ public static final String EXTRA_NEW_USER = "new_user";
+
HashMap<String,Boolean> mSelectedPackages = new HashMap<String,Boolean>();
private boolean mFirstTime = true;
private boolean mNewUser;
+ private boolean mAppListChanged;
private int mCustomRequestCode;
private HashMap<Integer, AppRestrictionsPreference> mCustomRequestMap =
@@ -117,16 +128,6 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
}
}
- public static class Activity extends PreferenceActivity {
- @Override
- public Intent getIntent() {
- Intent modIntent = new Intent(super.getIntent());
- modIntent.putExtra(EXTRA_SHOW_FRAGMENT, AppRestrictionsFragment.class.getName());
- modIntent.putExtra(EXTRA_NO_HEADERS, true);
- return modIntent;
- }
- }
-
static class AppRestrictionsPreference extends SwitchPreference {
private boolean hasSettings;
private OnClickListener listener;
@@ -206,6 +207,17 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
+ if (icicle != null) {
+ mNewUser = icicle.getBoolean(EXTRA_NEW_USER, false);
+ mUser = new UserHandle(icicle.getInt(EXTRA_USER_ID));
+ } else {
+ Bundle args = getArguments();
+
+ if (args.containsKey(EXTRA_USER_ID)) {
+ mUser = new UserHandle(args.getInt(EXTRA_USER_ID));
+ }
+ mNewUser = args.getBoolean(EXTRA_NEW_USER, false);
+ }
mUserManager = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
addPreferencesFromResource(R.xml.app_restrictions);
mAppList = getPreferenceScreen();
@@ -218,13 +230,16 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
setHasOptionsMenu(true);
}
- void setUser(UserHandle user, boolean newUser) {
- mUser = user;
- mNewUser = newUser;
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putBoolean(EXTRA_NEW_USER, mNewUser);
+ outState.putInt(EXTRA_USER_ID, mUser.getIdentifier());
}
public void onResume() {
super.onResume();
+ mAppListChanged = false;
if (mFirstTime) {
mFirstTime = false;
populateApps();
@@ -238,6 +253,34 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
mUserPreference.setText(info.name);
}
+ public void onPause() {
+ super.onPause();
+ if (mAppListChanged) {
+ updateUserAppList();
+ }
+ }
+
+ private void updateUserAppList() {
+ IPackageManager ipm = IPackageManager.Stub.asInterface(
+ ServiceManager.getService("package"));
+ for (Map.Entry<String,Boolean> entry : mSelectedPackages.entrySet()) {
+ if (entry.getValue()) {
+ // Enable selected apps
+ try {
+ ipm.installExistingPackageAsUser(entry.getKey(), mUser.getIdentifier());
+ } catch (RemoteException re) {
+ }
+ } else {
+ // Blacklist all other apps, system or downloaded
+ try {
+ ipm.deletePackageAsUser(entry.getKey(), null, mUser.getIdentifier(),
+ PackageManager.DELETE_SYSTEM_APP);
+ } catch (RemoteException re) {
+ }
+ }
+ }
+ }
+
private void addSystemApps(List<SelectableAppInfo> visibleApps, Intent intent) {
final PackageManager pm = getActivity().getPackageManager();
List<ResolveInfo> launchableApps = pm.queryIntentActivities(intent, 0);
@@ -383,6 +426,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
p.setOrder(MAX_APP_RESTRICTIONS * (i + 2));
}
mSelectedPackages.put(packageName, p.isChecked());
+ mAppListChanged = true;
i++;
}
}
@@ -437,6 +481,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
pref.setChecked(!pref.isChecked());
mSelectedPackages.put(pref.getKey().substring(PKG_PREFIX.length()),
pref.isChecked());
+ mAppListChanged = true;
updateAllEntries(pref.getKey(), pref.isChecked());
}
}
@@ -689,6 +734,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
arp.setChecked(!arp.isChecked());
mSelectedPackages.put(arp.getKey().substring(PKG_PREFIX.length()), arp.isChecked());
updateAllEntries(arp.getKey(), arp.isChecked());
+ mAppListChanged = true;
}
return true;
}
diff --git a/src/com/android/settings/users/UserRestrictionsActivity.java b/src/com/android/settings/users/UserRestrictionsActivity.java
deleted file mode 100644
index 1a90a8179..000000000
--- a/src/com/android/settings/users/UserRestrictionsActivity.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.users;
-
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.app.Activity;
-import android.content.Context;
-import android.content.pm.IPackageManager;
-import android.content.pm.PackageManager;
-import android.content.pm.UserInfo;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.os.Bundle;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-
-import com.android.settings.R;
-
-import java.util.Map;
-
-public class UserRestrictionsActivity extends Activity implements OnClickListener {
-
- private static final String TAG = UserRestrictionsActivity.class.getSimpleName();
-
- static final String EXTRA_USER_NAME = "user_name";
- static final String EXTRA_USER_ID = "user_id";
- static final String EXTRA_ACCOUNTS = "accounts";
-
- private Button mFinishButton;
- private Button mBackButton;
- private AppRestrictionsFragment mAppsFragment;
- private UserInfo mUserInfo;
- private boolean mNewUser;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.user_limits);
-
- mBackButton = (Button) findViewById(R.id.back_button);
- if (mBackButton != null) {
- mBackButton.setOnClickListener(this);
- }
- mFinishButton = (Button) findViewById(R.id.next_button);
- if (mFinishButton != null) {
- mFinishButton.setOnClickListener(this);
- }
- mAppsFragment = (AppRestrictionsFragment)
- getFragmentManager().findFragmentById(R.id.user_limits_fragment);
-
- UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
- String name = getIntent().getStringExtra(EXTRA_USER_NAME);
- int userId = getIntent().getIntExtra(EXTRA_USER_ID, -1);
- // Create the user so we have an id
- if (userId == -1) {
- mNewUser = true;
- mUserInfo = um.createUser(name, UserInfo.FLAG_RESTRICTED);
- um.setUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS, true,
- new UserHandle(mUserInfo.id));
-
- Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
- UserSettings.USER_DRAWABLES[
- mUserInfo.id % UserSettings.USER_DRAWABLES.length]);
- um.setUserIcon(mUserInfo.id, bitmap);
- } else {
- mUserInfo = um.getUserInfo(userId);
- }
- if (mAppsFragment != null) {
- mAppsFragment.setUser(new UserHandle(mUserInfo.id), mNewUser);
- }
- }
-
- @Override
- public void onClick(View v) {
- if (v == mFinishButton) {
- if (mNewUser) {
- AccountManager am = AccountManager.get(this);
- Account [] accounts = am.getAccounts();
- if (accounts != null) {
- for (Account account : accounts) {
- am.addSharedAccount(account,
- new UserHandle(mUserInfo.id));
- }
- }
- }
-
- IPackageManager ipm = IPackageManager.Stub.asInterface(
- ServiceManager.getService("package"));
- for (Map.Entry<String,Boolean> entry : mAppsFragment.mSelectedPackages.entrySet()) {
- if (entry.getValue()) {
- // Enable selected apps
- try {
- ipm.installExistingPackageAsUser(entry.getKey(), mUserInfo.id);
- } catch (RemoteException re) {
- }
- } else {
- // Blacklist all other apps, system or downloaded
- try {
- ipm.deletePackageAsUser(entry.getKey(), null, mUserInfo.id,
- PackageManager.DELETE_SYSTEM_APP);
- } catch (RemoteException re) {
- }
- }
- }
- setResult(RESULT_OK);
- mUserInfo = null;
- finish();
- }
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
-
- if (mUserInfo != null && mNewUser) {
- UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
- um.removeUser(mUserInfo.id);
- }
- }
-}
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index 58301840c..1c557a2c8 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -42,6 +42,7 @@ import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.preference.Preference;
+import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceGroup;
@@ -83,16 +84,20 @@ public class UserSettings extends SettingsPreferenceFragment
private static final String KEY_ADD_RESTRICTED_USER = "user_add_restricted";
private static final String KEY_ADD_TRUSTED_USER = "user_add_trusted";
- private static final int MENU_ADD_USER = Menu.FIRST;
- private static final int MENU_REMOVE_USER = Menu.FIRST+1;
+ private static final int MENU_REMOVE_USER = Menu.FIRST;
private static final int DIALOG_CONFIRM_REMOVE = 1;
- private static final int DIALOG_ADD_USER = 2;
- private static final int DIALOG_SETUP_USER = 3;
- private static final int DIALOG_USER_CANNOT_MANAGE = 4;
+ private static final int DIALOG_ADD_USER_TRUSTED = 2;
+ private static final int DIALOG_ADD_USER_LIMITED = 3;
+ private static final int DIALOG_SETUP_USER = 4;
+ private static final int DIALOG_USER_CANNOT_MANAGE = 5;
private static final int MESSAGE_UPDATE_LIST = 1;
private static final int MESSAGE_SETUP_USER = 2;
+ private static final int MESSAGE_CONFIG_USER = 3;
+
+ private static final int USER_TYPE_TRUSTED = 1;
+ private static final int USER_TYPE_LIMITED = 2;
private static final String KEY_ADD_USER_LONG_MESSAGE_DISPLAYED =
"key_add_user_long_message_displayed";
@@ -135,6 +140,9 @@ public class UserSettings extends SettingsPreferenceFragment
case MESSAGE_SETUP_USER:
onUserCreated(msg.arg1);
break;
+ case MESSAGE_CONFIG_USER:
+ onManageUserClicked(msg.arg1, true);
+ break;
}
}
};
@@ -237,10 +245,7 @@ public class UserSettings extends SettingsPreferenceFragment
@Override
public boolean onOptionsItemSelected(MenuItem item) {
final int itemId = item.getItemId();
- if (itemId == MENU_ADD_USER) {
- onAddUserClicked();
- return true;
- } else if (itemId == MENU_REMOVE_USER) {
+ if (itemId == MENU_REMOVE_USER) {
onRemoveUserClicked(UserHandle.myUserId());
return true;
} else {
@@ -278,10 +283,17 @@ public class UserSettings extends SettingsPreferenceFragment
}
}
- private void onAddUserClicked() {
+ private void onAddUserClicked(int userType) {
synchronized (mUserLock) {
if (mRemovingUserId == -1 && !mAddingUser) {
- showDialog(DIALOG_ADD_USER);
+ switch (userType) {
+ case USER_TYPE_TRUSTED:
+ showDialog(DIALOG_ADD_USER_TRUSTED);
+ break;
+ case USER_TYPE_LIMITED:
+ showDialog(DIALOG_ADD_USER_LIMITED);
+ break;
+ }
}
}
}
@@ -295,11 +307,50 @@ public class UserSettings extends SettingsPreferenceFragment
}
}
- private void onManageUserClicked(int userId) {
- Intent appsChooser = new Intent();
- appsChooser.setClass(getActivity(), UserRestrictionsActivity.class);
- appsChooser.putExtra(UserRestrictionsActivity.EXTRA_USER_ID, userId);
- startActivity(appsChooser);
+ private UserInfo createLimitedUser() {
+ UserInfo newUserInfo = mUserManager.createUser(
+ getResources().getString(R.string.user_new_user_name),
+ UserInfo.FLAG_RESTRICTED);
+ int userId = newUserInfo.id;
+ UserHandle user = new UserHandle(userId);
+ mUserManager.setUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS, true, user);
+
+ Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
+ UserSettings.USER_DRAWABLES[
+ userId % UserSettings.USER_DRAWABLES.length]);
+ mUserManager.setUserIcon(userId, bitmap);
+ // Add shared accounts
+ AccountManager am = AccountManager.get(getActivity());
+ Account [] accounts = am.getAccounts();
+ if (accounts != null) {
+ for (Account account : accounts) {
+ am.addSharedAccount(account, user);
+ }
+ }
+ return newUserInfo;
+ }
+
+ private UserInfo createTrustedUser() {
+ UserInfo newUserInfo = mUserManager.createUser(
+ getActivity().getResources().getString(R.string.user_new_user_name), 0);
+ if (newUserInfo != null) {
+ assignDefaultPhoto(newUserInfo);
+ }
+ return newUserInfo;
+ }
+
+ private void onManageUserClicked(int userId, boolean newUser) {
+ Bundle extras = new Bundle();
+ extras.putInt(AppRestrictionsFragment.EXTRA_USER_ID, userId);
+ extras.putBoolean(AppRestrictionsFragment.EXTRA_NEW_USER, newUser);
+ String title = getResources().getString(R.string.user_new_user_name);
+ if (userId > UserHandle.USER_OWNER) {
+ title = mUserManager.getUserInfo(userId).name;
+ }
+ ((PreferenceActivity) getActivity()).startPreferencePanel(
+ AppRestrictionsFragment.class.getName(),
+ extras, 0, title,
+ null, 0);
}
private void onUserCreated(int userId) {
@@ -340,7 +391,8 @@ public class UserSettings extends SettingsPreferenceFragment
.setMessage(R.string.user_cannot_manage_message)
.setPositiveButton(android.R.string.ok, null)
.create();
- case DIALOG_ADD_USER: {
+ case DIALOG_ADD_USER_TRUSTED:
+ case DIALOG_ADD_USER_LIMITED: {
final SharedPreferences preferences = getActivity().getPreferences(
Context.MODE_PRIVATE);
final boolean longMessageDisplayed = preferences.getBoolean(
@@ -348,13 +400,15 @@ public class UserSettings extends SettingsPreferenceFragment
final int messageResId = longMessageDisplayed
? R.string.user_add_user_message_short
: R.string.user_add_user_message_long;
+ final int userType = dialogId == DIALOG_ADD_USER_TRUSTED
+ ? USER_TYPE_TRUSTED : USER_TYPE_LIMITED;
Dialog dlg = new AlertDialog.Builder(getActivity())
.setTitle(R.string.user_add_user_title)
.setMessage(messageResId)
.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
- addUserNow();
+ addUserNow(userType);
if (!longMessageDisplayed) {
preferences.edit().putBoolean(KEY_ADD_USER_LONG_MESSAGE_DISPLAYED,
true).commit();
@@ -409,23 +463,29 @@ public class UserSettings extends SettingsPreferenceFragment
}
}
- private void addUserNow() {
+ private void addUserNow(final int userType) {
synchronized (mUserLock) {
mAddingUser = true;
updateUserList();
new Thread() {
public void run() {
+ UserInfo user = null;
// Could take a few seconds
- UserInfo user = mUserManager.createUser(
- getActivity().getResources().getString(R.string.user_new_user_name), 0);
- if (user != null) {
- assignDefaultPhoto(user);
+ if (userType == USER_TYPE_TRUSTED) {
+ user = createTrustedUser();
+ } else {
+ user = createLimitedUser();
}
synchronized (mUserLock) {
mAddingUser = false;
mHandler.sendEmptyMessage(MESSAGE_UPDATE_LIST);
- mHandler.sendMessage(mHandler.obtainMessage(
- MESSAGE_SETUP_USER, user.id, user.serialNumber));
+ if (userType == USER_TYPE_TRUSTED) {
+ mHandler.sendMessage(mHandler.obtainMessage(
+ MESSAGE_SETUP_USER, user.id, user.serialNumber));
+ } else {
+ mHandler.sendMessage(mHandler.obtainMessage(
+ MESSAGE_CONFIG_USER, user.id, user.serialNumber));
+ }
}
}
}.start();
@@ -589,16 +649,9 @@ public class UserSettings extends SettingsPreferenceFragment
}
}
} else if (pref == mAddTrustedUser) {
- onAddUserClicked();
+ onAddUserClicked(USER_TYPE_TRUSTED);
} else if (pref == mAddRestrictedUser) {
- Account[] accounts = ((AccountManager) getSystemService(Context.ACCOUNT_SERVICE))
- .getAccounts();
- Intent intent = new Intent(getActivity(), UserRestrictionsActivity.class);
- intent.putExtra(UserRestrictionsActivity.EXTRA_USER_NAME,
- getResources().getString(R.string.user_new_user_name));
- intent.putExtra(UserRestrictionsActivity.EXTRA_ACCOUNTS,
- accounts);
- startActivity(intent);
+ onAddUserClicked(USER_TYPE_LIMITED);
}
return false;
}
@@ -626,7 +679,7 @@ public class UserSettings extends SettingsPreferenceFragment
onRemoveUserClicked(userId);
break;
case UserPreference.SETTINGS_ID:
- onManageUserClicked(userId);
+ onManageUserClicked(userId, false);
break;
}
}