diff options
author | Fyodor Kupolov <fkupolov@google.com> | 2015-04-14 17:43:43 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-04-14 17:43:45 +0000 |
commit | a08c444d1ded190a4d2189b9fa697b0ffba1f4b4 (patch) | |
tree | 0c04c5fa3dc7b858dcf541c23ecc9333571c1dce /packages/SystemUI/src/com/android/systemui/statusbar | |
parent | 80003c6e9e89e86bec5e42328d126f5837ba06fd (diff) | |
parent | f4d6ad26636760163083ae84c40d5b19cb6650f6 (diff) | |
download | frameworks_base-a08c444d1ded190a4d2189b9fa697b0ffba1f4b4.zip frameworks_base-a08c444d1ded190a4d2189b9fa697b0ffba1f4b4.tar.gz frameworks_base-a08c444d1ded190a4d2189b9fa697b0ffba1f4b4.tar.bz2 |
Merge "Display a notification for a new guest"
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/statusbar')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java | 39 |
1 files changed, 39 insertions, 0 deletions
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 4ac41a1..194bcfa 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java @@ -19,6 +19,9 @@ package com.android.systemui.statusbar.policy; import android.app.ActivityManager; import android.app.ActivityManagerNative; import android.app.Dialog; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; @@ -63,6 +66,7 @@ public class UserSwitcherController { private static final boolean DEBUG = false; private static final String SIMPLE_USER_SWITCHER_GLOBAL_SETTING = "lockscreenSimpleUserSwitcher"; + private static final String ACTION_REMOVE_GUEST = "com.android.systemui.REMOVE_GUEST"; private final Context mContext; private final UserManager mUserManager; @@ -89,6 +93,7 @@ public class UserSwitcherController { filter.addAction(Intent.ACTION_USER_INFO_CHANGED); filter.addAction(Intent.ACTION_USER_SWITCHED); filter.addAction(Intent.ACTION_USER_STOPPING); + filter.addAction(ACTION_REMOVE_GUEST); mContext.registerReceiverAsUser(mReceiver, UserHandle.OWNER, filter, null /* permission */, null /* scheduler */); @@ -296,6 +301,22 @@ public class UserSwitcherController { Log.v(TAG, "Broadcast: a=" + intent.getAction() + " user=" + intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1)); } + if (ACTION_REMOVE_GUEST.equals(intent.getAction())) { + int currentUser = ActivityManager.getCurrentUser(); + UserInfo userInfo = mUserManager.getUserInfo(currentUser); + if (userInfo != null && userInfo.isGuest()) { + showExitGuestDialog(currentUser); + } + return; + } + if (Intent.ACTION_USER_ADDED.equals(intent.getAction())) { + final int currentId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1); + UserInfo userInfo = mUserManager.getUserInfo(currentId); + if (userInfo != null && userInfo.isGuest()) { + showGuestNotification(currentId); + } + } + if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { if (mExitGuestDialog != null && mExitGuestDialog.isShowing()) { mExitGuestDialog.cancel(); @@ -329,6 +350,24 @@ public class UserSwitcherController { } refreshUsers(forcePictureLoadForId); } + + private void showGuestNotification(int guestUserId) { + PendingIntent removeGuestPI = PendingIntent.getBroadcastAsUser(mContext, + 0, new Intent(ACTION_REMOVE_GUEST), 0, UserHandle.OWNER); + Notification notification = new Notification.Builder(mContext) + .setVisibility(Notification.VISIBILITY_SECRET) + .setPriority(Notification.PRIORITY_MIN) + .setSmallIcon(R.drawable.ic_person) + .setContentTitle(mContext.getString(R.string.guest_notification_title)) + .setContentText(mContext.getString(R.string.guest_notification_text)) + .setShowWhen(false) + .addAction(R.drawable.ic_delete, + mContext.getString(R.string.guest_notification_remove_action), + removeGuestPI) + .build(); + NotificationManager.from(mContext).notifyAsUser(null, 0, notification, + new UserHandle(guestUserId)); + } }; private final ContentObserver mSettingsObserver = new ContentObserver(new Handler()) { |