summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI/src/com/android
diff options
context:
space:
mode:
authorAdrian Roos <roosa@google.com>2014-07-17 18:27:38 +0200
committerAdrian Roos <roosa@google.com>2014-07-17 18:31:22 +0200
commite9c7d431da85b5bc03ecaa964d7a491b01466a99 (patch)
tree5ddbffcc63f517dd7b2c28174789b6717faa52f2 /packages/SystemUI/src/com/android
parent9d32507a8608f82d430fcaf1de0eb81de93dcdea (diff)
downloadframeworks_base-e9c7d431da85b5bc03ecaa964d7a491b01466a99.zip
frameworks_base-e9c7d431da85b5bc03ecaa964d7a491b01466a99.tar.gz
frameworks_base-e9c7d431da85b5bc03ecaa964d7a491b01466a99.tar.bz2
QS Guest fixes
- Fixes NPE when guest has not been created yet - Reloads pictures only when they changed - Adds "Exit guest" affordance Bug: 16363920 Bug: 15759638 Change-Id: I99ff1c4be06fee96c5169fd7c2d31b1b13f7a389
Diffstat (limited to 'packages/SystemUI/src/com/android')
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailView.java8
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java80
2 files changed, 70 insertions, 18 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailView.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailView.java
index 3c647ed..67eef56 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailView.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailView.java
@@ -81,13 +81,7 @@ public class UserDetailView extends GridView {
UserSwitcherController.UserRecord item = getItem(position);
UserDetailItemView v = UserDetailItemView.convertOrInflate(
mContext, convertView, parent);
- String name;
- if (item.isGuest) {
- name = mContext.getString(
- item.info == null ? R.string.guest_new_guest : R.string.guest_nickname);
- } else {
- name = item.info.name;
- }
+ String name = getName(mContext, item);
if (item.picture == null) {
v.bind(name, mContext.getDrawable(R.drawable.ic_account_circle_qs));
} else {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java
index 4640067..7cc8ed5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java
@@ -30,8 +30,10 @@ import android.content.pm.UserInfo;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.RemoteException;
+import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
+import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManagerGlobal;
@@ -64,15 +66,37 @@ public class UserSwitcherController {
filter.addAction(Intent.ACTION_USER_REMOVED);
filter.addAction(Intent.ACTION_USER_INFO_CHANGED);
filter.addAction(Intent.ACTION_USER_SWITCHED);
- mContext.registerReceiver(mReceiver, filter);
- refreshUsers();
+ filter.addAction(Intent.ACTION_USER_STOPPING);
+ mContext.registerReceiverAsUser(mReceiver, UserHandle.OWNER, filter,
+ null /* permission */, null /* scheduler */);
+ refreshUsers(UserHandle.USER_NULL);
}
- private void refreshUsers() {
- new AsyncTask<Void, Void, ArrayList<UserRecord>>() {
+ /**
+ * Refreshes users from UserManager.
+ *
+ * The pictures are only loaded if they have not been loaded yet.
+ *
+ * @param forcePictureLoadForId forces the picture of the given user to be reloaded.
+ */
+ private void refreshUsers(int forcePictureLoadForId) {
+
+ SparseArray<Bitmap> bitmaps = new SparseArray<>(mUsers.size());
+ final int N = mUsers.size();
+ for (int i = 0; i < N; i++) {
+ UserRecord r = mUsers.get(i);
+ if (r == null || r.info == null
+ || r.info.id == forcePictureLoadForId || r.picture == null) {
+ continue;
+ }
+ bitmaps.put(r.info.id, r.picture);
+ }
+ new AsyncTask<SparseArray<Bitmap>, Void, ArrayList<UserRecord>>() {
+ @SuppressWarnings("unchecked")
@Override
- protected ArrayList<UserRecord> doInBackground(Void... params) {
+ protected ArrayList<UserRecord> doInBackground(SparseArray<Bitmap>... params) {
+ final SparseArray<Bitmap> bitmaps = params[0];
List<UserInfo> infos = mUserManager.getUsers(true);
if (infos == null) {
return null;
@@ -87,8 +111,11 @@ public class UserSwitcherController {
guestRecord = new UserRecord(info, null /* picture */,
true /* isGuest */, isCurrent);
} else if (!info.isManagedProfile()) {
- records.add(new UserRecord(info, mUserManager.getUserIcon(info.id),
- false /* isGuest */, isCurrent));
+ Bitmap picture = bitmaps.get(info.id);
+ if (picture == null) {
+ picture = mUserManager.getUserIcon(info.id);
+ }
+ records.add(new UserRecord(info, picture, false /* isGuest */, isCurrent));
}
}
@@ -109,7 +136,7 @@ public class UserSwitcherController {
notifyAdapters();
}
}
- }.execute((Void[])null);
+ }.execute((SparseArray)bitmaps);
}
private void notifyAdapters() {
@@ -134,9 +161,16 @@ public class UserSwitcherController {
}
if (ActivityManager.getCurrentUser() == id) {
+ if (record.isGuest) {
+ exitGuest(id);
+ }
return;
}
+ switchToUserId(id);
+ }
+
+ private void switchToUserId(int id) {
try {
WindowManagerGlobal.getWindowManagerService().lockNow(null);
ActivityManagerNative.getDefault().switchUser(id);
@@ -145,6 +179,12 @@ public class UserSwitcherController {
}
}
+ private void exitGuest(int id) {
+ // TODO: show confirmation dialog
+ switchToUserId(UserHandle.USER_OWNER);
+ mUserManager.removeUser(id);
+ }
+
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -153,15 +193,20 @@ public class UserSwitcherController {
final int N = mUsers.size();
for (int i = 0; i < N; i++) {
UserRecord record = mUsers.get(i);
+ if (record.info == null) continue;
boolean shouldBeCurrent = record.info.id == currentId;
if (record.isCurrent != shouldBeCurrent) {
mUsers.set(i, record.copyWithIsCurrent(shouldBeCurrent));
}
}
notifyAdapters();
- } else {
- refreshUsers();
}
+ int forcePictureLoadForId = UserHandle.USER_NULL;
+ if (Intent.ACTION_USER_INFO_CHANGED.equals(intent.getAction())) {
+ forcePictureLoadForId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
+ UserHandle.USER_NULL);
+ }
+ refreshUsers(forcePictureLoadForId);
}
};
@@ -195,12 +240,25 @@ public class UserSwitcherController {
@Override
public long getItemId(int position) {
- return mController.mUsers.get(position).info.id;
+ return position;
}
public void switchTo(UserRecord record) {
mController.switchTo(record);
}
+
+ public String getName(Context context, UserRecord item) {
+ if (item.isGuest) {
+ if (item.isCurrent) {
+ return context.getString(R.string.guest_exit_guest);
+ } else {
+ return context.getString(
+ item.info == null ? R.string.guest_new_guest : R.string.guest_nickname);
+ }
+ } else {
+ return item.info.name;
+ }
+ }
}
public static final class UserRecord {