GuestResumeSessionReceiverpublic class GuestResumeSessionReceiver extends android.content.BroadcastReceiver Manages notification when a guest session is resumed. |
Fields Summary |
---|
private static final String | TAG | private static final String | SETTING_GUEST_HAS_LOGGED_IN | private android.app.Dialog | mNewSessionDialog |
Methods Summary |
---|
private void | cancelDialog()
if (mNewSessionDialog != null && mNewSessionDialog.isShowing()) {
mNewSessionDialog.cancel();
mNewSessionDialog = null;
}
| public void | onReceive(android.content.Context context, android.content.Intent intent)
String action = intent.getAction();
if (Intent.ACTION_USER_SWITCHED.equals(action)) {
cancelDialog();
int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
if (userId == UserHandle.USER_NULL) {
Log.e(TAG, intent + " sent to " + TAG + " without EXTRA_USER_HANDLE");
return;
}
UserInfo currentUser;
try {
currentUser = ActivityManagerNative.getDefault().getCurrentUser();
} catch (RemoteException e) {
return;
}
if (!currentUser.isGuest()) {
return;
}
ContentResolver cr = context.getContentResolver();
int notFirstLogin = Settings.System.getIntForUser(
cr, SETTING_GUEST_HAS_LOGGED_IN, 0, userId);
if (notFirstLogin != 0) {
mNewSessionDialog = new ResetSessionDialog(context, userId);
mNewSessionDialog.show();
} else {
Settings.System.putIntForUser(
cr, SETTING_GUEST_HAS_LOGGED_IN, 1, userId);
}
}
| public void | register(android.content.Context context)
IntentFilter f = new IntentFilter(Intent.ACTION_USER_SWITCHED);
context.registerReceiverAsUser(this, UserHandle.OWNER,
f, null /* permission */, null /* scheduler */);
| private static void | wipeGuestSession(android.content.Context context, int userId)Wipes the guest session.
The guest must be the current user and its id must be {@param userId}.
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
UserInfo currentUser;
try {
currentUser = ActivityManagerNative.getDefault().getCurrentUser();
} catch (RemoteException e) {
Log.e(TAG, "Couldn't wipe session because ActivityManager is dead");
return;
}
if (currentUser.id != userId) {
Log.w(TAG, "User requesting to start a new session (" + userId + ")"
+ " is not current user (" + currentUser.id + ")");
return;
}
if (!currentUser.isGuest()) {
Log.w(TAG, "User requesting to start a new session (" + userId + ")"
+ " is not a guest");
return;
}
boolean marked = userManager.markGuestForDeletion(currentUser.id);
if (!marked) {
Log.w(TAG, "Couldn't mark the guest for deletion for user " + userId);
return;
}
UserInfo newGuest = userManager.createGuest(context, currentUser.name);
try {
if (newGuest == null) {
Log.e(TAG, "Could not create new guest, switching back to owner");
ActivityManagerNative.getDefault().switchUser(UserHandle.USER_OWNER);
userManager.removeUser(currentUser.id);
WindowManagerGlobal.getWindowManagerService().lockNow(null /* options */);
return;
}
ActivityManagerNative.getDefault().switchUser(newGuest.id);
userManager.removeUser(currentUser.id);
} catch (RemoteException e) {
Log.e(TAG, "Couldn't wipe session because ActivityManager or WindowManager is dead");
return;
}
|
|