Skip to content

Commit de1d96c

Browse files
Craig MautnerAndroid (Google) Code Review
authored andcommitted
Merge "Hide non user app windows from other users." into jb-mr1-dev
2 parents 23e2825 + 9dc52bc commit de1d96c

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

services/java/com/android/server/wm/WindowManagerService.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,25 @@ public void released() {
318318
final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
319319
@Override
320320
public void onReceive(Context context, Intent intent) {
321-
mPolicy.enableKeyguard(true);
322-
synchronized(mKeyguardTokenWatcher) {
323-
// lazily evaluate this next time we're asked to disable keyguard
324-
mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
325-
mKeyguardDisabled = false;
321+
final String action = intent.getAction();
322+
if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED.equals(action)) {
323+
mPolicy.enableKeyguard(true);
324+
synchronized(mKeyguardTokenWatcher) {
325+
// lazily evaluate this next time we're asked to disable keyguard
326+
mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
327+
mKeyguardDisabled = false;
328+
}
329+
} else if (Intent.ACTION_USER_SWITCHED.equals(action)) {
330+
final int newUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
331+
Slog.v(TAG, "Switching user from " + mCurrentUserId + " to " + newUserId);
332+
mCurrentUserId = newUserId;
326333
}
327334
}
328335
};
329336

337+
// Current user when multi-user is enabled. Don't show windows of non-current user.
338+
int mCurrentUserId;
339+
330340
final Context mContext;
331341

332342
final boolean mHaveInputMethods;
@@ -908,6 +918,8 @@ private WindowManagerService(Context context, PowerManagerService pm,
908918
// Track changes to DevicePolicyManager state so we can enable/disable keyguard.
909919
IntentFilter filter = new IntentFilter();
910920
filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
921+
// Track user switching.
922+
filter.addAction(Intent.ACTION_USER_SWITCHED);
911923
mContext.registerReceiver(mBroadcastReceiver, filter);
912924

913925
mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK

services/java/com/android/server/wm/WindowState.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
2323
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
2424
import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
25+
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
26+
import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
27+
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
2528

2629
import com.android.server.input.InputWindowHandle;
2730

@@ -34,6 +37,7 @@
3437
import android.graphics.Region;
3538
import android.os.IBinder;
3639
import android.os.RemoteException;
40+
import android.os.UserHandle;
3741
import android.util.Slog;
3842
import android.view.DisplayInfo;
3943
import android.view.Gravity;
@@ -257,13 +261,17 @@ final class WindowState implements WindowManagerPolicy.WindowState {
257261

258262
DisplayContent mDisplayContent;
259263

264+
// UserId of the owner. Don't display windows of non-current user.
265+
final int mOwnerUserId;
266+
260267
WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
261268
WindowState attachedWindow, int seq, WindowManager.LayoutParams a,
262269
int viewVisibility, final DisplayContent displayContent) {
263270
mService = service;
264271
mSession = s;
265272
mClient = c;
266273
mToken = token;
274+
mOwnerUserId = UserHandle.getUserId(s.mUid);
267275
mAttrs.copyFrom(a);
268276
mViewVisibility = viewVisibility;
269277
mDisplayContent = displayContent;
@@ -894,6 +902,11 @@ public boolean showLw(boolean doAnimation) {
894902
}
895903

896904
boolean showLw(boolean doAnimation, boolean requestAnim) {
905+
if (isOtherUsersAppWindow()) {
906+
Slog.w(TAG, "Current user " + mService.mCurrentUserId + " trying to display "
907+
+ this + ", type " + mAttrs.type + ", belonging to " + mOwnerUserId);
908+
return false;
909+
}
897910
if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
898911
// Already showing.
899912
return false;
@@ -970,6 +983,16 @@ public boolean isAlive() {
970983
return mClient.asBinder().isBinderAlive();
971984
}
972985

986+
boolean isOtherUsersAppWindow() {
987+
final int type = mAttrs.type;
988+
if ((mOwnerUserId != mService.mCurrentUserId)
989+
&& (type >= TYPE_BASE_APPLICATION) && (type <= LAST_APPLICATION_WINDOW)
990+
&& (type != TYPE_APPLICATION_STARTING)) {
991+
return true;
992+
}
993+
return false;
994+
}
995+
973996
private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
974997
outRegion.set(
975998
frame.left + inset.left, frame.top + inset.top,

services/java/com/android/server/wm/WindowStateAnimator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,11 @@ void setWallpaperOffset(int left, int top) {
12901290

12911291
// This must be called while inside a transaction.
12921292
boolean performShowLocked() {
1293+
if (mWin.isOtherUsersAppWindow()) {
1294+
Slog.w(TAG, "Current user " + mService.mCurrentUserId + " trying to display "
1295+
+ this + ", type " + mWin.mAttrs.type + ", belonging to " + mWin.mOwnerUserId);
1296+
return false;
1297+
}
12931298
if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
12941299
mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
12951300
RuntimeException e = null;

0 commit comments

Comments
 (0)