Use UserManager instead of PackageManager for user management
Show Accounts in secondary settings Move Users & restrictions to Device section Change-Id: Idcd7ed44801fe92c847cff81d11f3d6f6d06ba81
This commit is contained in:
@@ -19,7 +19,8 @@
|
|||||||
|
|
||||||
|
|
||||||
<!-- WIRELESS and NETWORKS -->
|
<!-- WIRELESS and NETWORKS -->
|
||||||
<header android:title="@string/header_category_wireless_networks" />
|
<header android:id="@+id/wireless_section"
|
||||||
|
android:title="@string/header_category_wireless_networks" />
|
||||||
|
|
||||||
<!-- Wifi -->
|
<!-- Wifi -->
|
||||||
<header
|
<header
|
||||||
@@ -58,7 +59,8 @@
|
|||||||
android:icon="@drawable/empty_icon" />
|
android:icon="@drawable/empty_icon" />
|
||||||
|
|
||||||
<!-- DEVICE -->
|
<!-- DEVICE -->
|
||||||
<header android:title="@string/header_category_device" />
|
<header android:id="@+id/device_section"
|
||||||
|
android:title="@string/header_category_device" />
|
||||||
|
|
||||||
<!-- Sound -->
|
<!-- Sound -->
|
||||||
<header
|
<header
|
||||||
@@ -95,6 +97,13 @@
|
|||||||
android:title="@string/applications_settings"
|
android:title="@string/applications_settings"
|
||||||
android:id="@+id/application_settings" />
|
android:id="@+id/application_settings" />
|
||||||
|
|
||||||
|
<!-- Manage users -->
|
||||||
|
<header
|
||||||
|
android:fragment="com.android.settings.users.UserSettings"
|
||||||
|
android:icon="@drawable/ic_settings_sync"
|
||||||
|
android:title="@string/user_settings_title"
|
||||||
|
android:id="@+id/user_settings" />
|
||||||
|
|
||||||
<!-- Manufacturer hook -->
|
<!-- Manufacturer hook -->
|
||||||
<header
|
<header
|
||||||
android:fragment="com.android.settings.WirelessSettings"
|
android:fragment="com.android.settings.WirelessSettings"
|
||||||
@@ -104,7 +113,8 @@
|
|||||||
|
|
||||||
|
|
||||||
<!-- PERSONAL -->
|
<!-- PERSONAL -->
|
||||||
<header android:title="@string/header_category_personal" />
|
<header android:id="@+id/personal_section"
|
||||||
|
android:title="@string/header_category_personal" />
|
||||||
|
|
||||||
<!-- Location -->
|
<!-- Location -->
|
||||||
<header
|
<header
|
||||||
@@ -139,13 +149,6 @@
|
|||||||
android:id="@+id/account_settings"
|
android:id="@+id/account_settings"
|
||||||
android:title="@string/account_settings" />
|
android:title="@string/account_settings" />
|
||||||
|
|
||||||
<!-- Manage users -->
|
|
||||||
<header
|
|
||||||
android:fragment="com.android.settings.users.UserSettings"
|
|
||||||
android:icon="@drawable/ic_settings_sync"
|
|
||||||
android:title="@string/user_settings_title"
|
|
||||||
android:id="@+id/user_settings" />
|
|
||||||
|
|
||||||
<header
|
<header
|
||||||
android:id="@+id/account_add"
|
android:id="@+id/account_add"
|
||||||
android:title="@string/add_account_label"
|
android:title="@string/add_account_label"
|
||||||
@@ -155,7 +158,8 @@
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<!-- SYSTEM -->
|
<!-- SYSTEM -->
|
||||||
<header android:title="@string/header_category_system" />
|
<header android:id="@+id/system_section"
|
||||||
|
android:title="@string/header_category_system" />
|
||||||
|
|
||||||
<!-- Dock -->
|
<!-- Dock -->
|
||||||
<header
|
<header
|
||||||
|
@@ -96,12 +96,17 @@ public class Settings extends PreferenceActivity
|
|||||||
|
|
||||||
// Show only these settings for restricted users
|
// Show only these settings for restricted users
|
||||||
private int[] SETTINGS_FOR_RESTRICTED = {
|
private int[] SETTINGS_FOR_RESTRICTED = {
|
||||||
|
R.id.wireless_section,
|
||||||
R.id.wifi_settings,
|
R.id.wifi_settings,
|
||||||
R.id.bluetooth_settings,
|
R.id.bluetooth_settings,
|
||||||
|
R.id.device_section,
|
||||||
R.id.sound_settings,
|
R.id.sound_settings,
|
||||||
R.id.display_settings,
|
R.id.display_settings,
|
||||||
|
R.id.personal_section,
|
||||||
R.id.security_settings,
|
R.id.security_settings,
|
||||||
R.id.account_settings,
|
R.id.account_settings,
|
||||||
|
R.id.account_add,
|
||||||
|
R.id.system_section,
|
||||||
R.id.about_settings
|
R.id.about_settings
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -19,6 +19,7 @@ package com.android.settings.users;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
@@ -35,6 +36,7 @@ import android.os.Bundle;
|
|||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
|
import android.os.UserManager;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
@@ -91,6 +93,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
private IPackageManager mIPm;
|
private IPackageManager mIPm;
|
||||||
private PackageManager mPm;
|
private PackageManager mPm;
|
||||||
|
private UserManager mUm;
|
||||||
private int mUserId;
|
private int mUserId;
|
||||||
private boolean mNewUser;
|
private boolean mNewUser;
|
||||||
|
|
||||||
@@ -102,12 +105,10 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
|||||||
mNewUser = args == null || args.getInt(EXTRA_USER_ID, -1) == -1;
|
mNewUser = args == null || args.getInt(EXTRA_USER_ID, -1) == -1;
|
||||||
mUserId = mNewUser ? -1 : args.getInt(EXTRA_USER_ID, -1);
|
mUserId = mNewUser ? -1 : args.getInt(EXTRA_USER_ID, -1);
|
||||||
mIPm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
|
mIPm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
|
||||||
|
mUm = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
||||||
|
|
||||||
if (mUserId == -1) {
|
if (mUserId == -1) {
|
||||||
try {
|
mUserId = mUm.createUser(getString(R.string.user_new_user_name), 0).id;
|
||||||
mUserId = mIPm.createUser(getString(R.string.user_new_user_name), 0).id;
|
|
||||||
} catch (RemoteException re) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mSystemAppGroup = (PreferenceGroup) findPreference(KEY_SYSTEM_APPS);
|
mSystemAppGroup = (PreferenceGroup) findPreference(KEY_SYSTEM_APPS);
|
||||||
mInstalledAppGroup = (PreferenceGroup) findPreference(KEY_INSTALLED_APPS);
|
mInstalledAppGroup = (PreferenceGroup) findPreference(KEY_INSTALLED_APPS);
|
||||||
@@ -161,7 +162,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initExistingUser() {
|
private void initExistingUser() {
|
||||||
List<UserInfo> users = mPm.getUsers();
|
List<UserInfo> users = mUm.getUsers();
|
||||||
UserInfo foundUser = null;
|
UserInfo foundUser = null;
|
||||||
for (UserInfo user : users) {
|
for (UserInfo user : users) {
|
||||||
if (user.id == mUserId) {
|
if (user.id == mUserId) {
|
||||||
@@ -193,12 +194,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void removeUserNow() {
|
private void removeUserNow() {
|
||||||
try {
|
mUm.removeUser(mUserId);
|
||||||
mIPm.removeUser(mUserId);
|
|
||||||
} catch (RemoteException re) {
|
|
||||||
// Couldn't remove user. Shouldn't happen
|
|
||||||
Log.e(TAG, "Couldn't remove user " + mUserId + "\n" + re);
|
|
||||||
}
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,12 +272,8 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
|||||||
if (TextUtils.isEmpty(name)) {
|
if (TextUtils.isEmpty(name)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
mUm.setUserName(mUserId, (String) newValue);
|
||||||
mIPm.setUserName(mUserId, (String) newValue);
|
mNamePref.setSummary((String) newValue);
|
||||||
mNamePref.setSummary((String) newValue);
|
|
||||||
} catch (RemoteException re) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -354,17 +346,14 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void saveCroppedImage(Intent data) {
|
private void saveCroppedImage(Intent data) {
|
||||||
try {
|
if (data.hasExtra("data")) {
|
||||||
if (data.hasExtra("data")) {
|
Bitmap bitmap = (Bitmap) data.getParcelableExtra("data");
|
||||||
Bitmap bitmap = (Bitmap) data.getParcelableExtra("data");
|
ParcelFileDescriptor fd = mUm.setUserIcon(mUserId);
|
||||||
ParcelFileDescriptor fd = mIPm.setUserIcon(mUserId);
|
if (fd != null) {
|
||||||
if (fd != null) {
|
bitmap.compress(CompressFormat.PNG, 100,
|
||||||
bitmap.compress(CompressFormat.PNG, 100,
|
new ParcelFileDescriptor.AutoCloseOutputStream(fd));
|
||||||
new ParcelFileDescriptor.AutoCloseOutputStream(fd));
|
setPhotoId(mUm.getUserInfo(mUserId).iconPath);
|
||||||
setPhotoId(mPm.getUser(mUserId).iconPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (RemoteException re) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,9 +16,11 @@
|
|||||||
|
|
||||||
package com.android.settings.users;
|
package com.android.settings.users;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.UserManager;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.Preference.OnPreferenceClickListener;
|
import android.preference.Preference.OnPreferenceClickListener;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
@@ -80,7 +82,8 @@ public class UserSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateUserList() {
|
private void updateUserList() {
|
||||||
List<UserInfo> users = getActivity().getPackageManager().getUsers();
|
List<UserInfo> users = ((UserManager) getActivity().getSystemService(Context.USER_SERVICE))
|
||||||
|
.getUsers();
|
||||||
|
|
||||||
mUserListCategory.removeAll();
|
mUserListCategory.removeAll();
|
||||||
for (UserInfo user : users) {
|
for (UserInfo user : users) {
|
||||||
|
Reference in New Issue
Block a user