Skip to content

Commit 55468c6

Browse files
committed
Occasionally triple tap on the keyboard toggles screen magnification.
1. Sometimes unlocking the device when the IME is up and triple tapping on the keyboard toggles screen magnification. The core reason is that when the kayguard window is shown we hide all other windows and when it is hidden we show these windows. We did not notify the screen magnifier for windows being shown and hidden. Also when the windows are shown we may reassign layers to put the IME or the wallpaper in the right Z order. The screen magnifier is now notified upon such layer reassignment since window layers are used when computing the magnified region. bug:7351531 Change-Id: I0931f4ba6cfa565d8eb1e3c432268ba1818feea6
1 parent 7789c9b commit 55468c6

File tree

3 files changed

+61
-22
lines changed

3 files changed

+61
-22
lines changed

core/java/android/view/IDisplayContentChangeListener.aidl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ import android.graphics.Rect;
2828
oneway interface IDisplayContentChangeListener {
2929
void onWindowTransition(int displayId, int transition, in WindowInfo info);
3030
void onRectangleOnScreenRequested(int displayId, in Rect rectangle, boolean immediate);
31+
void onWindowLayersChanged(int displayId);
3132
void onRotationChanged(int rotation);
3233
}

services/java/com/android/server/accessibility/ScreenMagnifier.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@ private static final class DisplayContentObserver {
850850
private static final int MESSAGE_ON_RECTANGLE_ON_SCREEN_REQUESTED = 3;
851851
private static final int MESSAGE_ON_WINDOW_TRANSITION = 4;
852852
private static final int MESSAGE_ON_ROTATION_CHANGED = 5;
853+
private static final int MESSAGE_ON_WINDOW_LAYERS_CHANGED = 6;
853854

854855
private final Handler mHandler = new MyHandler();
855856

@@ -880,24 +881,8 @@ public DisplayContentObserver(Context context, Viewport viewport,
880881
mDisplayContentChangeListener = new IDisplayContentChangeListener.Stub() {
881882
@Override
882883
public void onWindowTransition(int displayId, int transition, WindowInfo info) {
883-
Message message = mHandler.obtainMessage(MESSAGE_ON_WINDOW_TRANSITION,
884-
transition, 0, WindowInfo.obtain(info));
885-
// TODO: This makes me quite unhappy but for the time being the
886-
// least risky fix for cases where the keyguard is removed but
887-
// the windows it force hides are not made visible yet. Hence,
888-
// we would compute the magnified frame before we have a stable
889-
// state. One more reason to move the magnified frame computation
890-
// in the window manager!
891-
if (info.type == WindowManager.LayoutParams.TYPE_KEYGUARD
892-
|| info.type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
893-
&& (transition == WindowManagerPolicy.TRANSIT_EXIT
894-
|| transition == WindowManagerPolicy.TRANSIT_HIDE)) {
895-
final long delay = (long) (2 * mLongAnimationDuration
896-
* mWindowAnimationScale);
897-
mHandler.sendMessageDelayed(message, delay);
898-
} else {
899-
message.sendToTarget();
900-
}
884+
mHandler.obtainMessage(MESSAGE_ON_WINDOW_TRANSITION,
885+
transition, 0, WindowInfo.obtain(info)).sendToTarget();
901886
}
902887

903888
@Override
@@ -917,6 +902,11 @@ public void onRotationChanged(int rotation) throws RemoteException {
917902
mHandler.obtainMessage(MESSAGE_ON_ROTATION_CHANGED, rotation, 0)
918903
.sendToTarget();
919904
}
905+
906+
@Override
907+
public void onWindowLayersChanged(int displayId) throws RemoteException {
908+
mHandler.sendEmptyMessage(MESSAGE_ON_WINDOW_LAYERS_CHANGED);
909+
}
920910
};
921911

922912
try {
@@ -1192,6 +1182,9 @@ public void handleMessage(Message message) {
11921182
final int rotation = message.arg1;
11931183
handleOnRotationChanged(rotation);
11941184
} break;
1185+
case MESSAGE_ON_WINDOW_LAYERS_CHANGED: {
1186+
mViewport.recomputeBounds(mMagnificationController.isMagnifying());
1187+
} break;
11951188
default: {
11961189
throw new IllegalArgumentException("Unknown message: " + action);
11971190
}

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

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6576,6 +6576,36 @@ private void handleNotifyRotationChanged(int displayId, int rotation) {
65766576
}
65776577
}
65786578

6579+
private void scheduleNotifyWindowLayersChangedIfNeededLocked(DisplayContent displayContent) {
6580+
if (displayContent.mDisplayContentChangeListeners != null
6581+
&& displayContent.mDisplayContentChangeListeners.getRegisteredCallbackCount() > 0) {
6582+
mH.obtainMessage(H.NOTIFY_WINDOW_LAYERS_CHANGED, displayContent) .sendToTarget();
6583+
}
6584+
}
6585+
6586+
private void handleNotifyWindowLayersChanged(DisplayContent displayContent) {
6587+
RemoteCallbackList<IDisplayContentChangeListener> callbacks = null;
6588+
synchronized (mWindowMap) {
6589+
callbacks = displayContent.mDisplayContentChangeListeners;
6590+
if (callbacks == null) {
6591+
return;
6592+
}
6593+
}
6594+
try {
6595+
final int watcherCount = callbacks.beginBroadcast();
6596+
for (int i = 0; i < watcherCount; i++) {
6597+
try {
6598+
callbacks.getBroadcastItem(i).onWindowLayersChanged(
6599+
displayContent.getDisplayId());
6600+
} catch (RemoteException re) {
6601+
/* ignore */
6602+
}
6603+
}
6604+
} finally {
6605+
callbacks.finishBroadcast();
6606+
}
6607+
}
6608+
65796609
public void addWindowChangeListener(WindowChangeListener listener) {
65806610
synchronized(mWindowMap) {
65816611
mWindowChangeListeners.add(listener);
@@ -7222,12 +7252,13 @@ final class H extends Handler {
72227252
public static final int NOTIFY_ROTATION_CHANGED = 28;
72237253
public static final int NOTIFY_WINDOW_TRANSITION = 29;
72247254
public static final int NOTIFY_RECTANGLE_ON_SCREEN_REQUESTED = 30;
7255+
public static final int NOTIFY_WINDOW_LAYERS_CHANGED = 31;
72257256

7226-
public static final int DO_DISPLAY_ADDED = 31;
7227-
public static final int DO_DISPLAY_REMOVED = 32;
7228-
public static final int DO_DISPLAY_CHANGED = 33;
7257+
public static final int DO_DISPLAY_ADDED = 32;
7258+
public static final int DO_DISPLAY_REMOVED = 33;
7259+
public static final int DO_DISPLAY_CHANGED = 34;
72297260

7230-
public static final int CLIENT_FREEZE_TIMEOUT = 34;
7261+
public static final int CLIENT_FREEZE_TIMEOUT = 35;
72317262

72327263
public static final int ANIMATOR_WHAT_OFFSET = 100000;
72337264
public static final int SET_TRANSPARENT_REGION = ANIMATOR_WHAT_OFFSET + 1;
@@ -7699,6 +7730,12 @@ public void handleMessage(Message msg) {
76997730
break;
77007731
}
77017732

7733+
case NOTIFY_WINDOW_LAYERS_CHANGED: {
7734+
DisplayContent displayContent = (DisplayContent) msg.obj;
7735+
handleNotifyWindowLayersChanged(displayContent);
7736+
break;
7737+
}
7738+
77027739
case DO_DISPLAY_ADDED:
77037740
synchronized (mWindowMap) {
77047741
handleDisplayAddedLocked(msg.arg1);
@@ -8075,6 +8112,8 @@ private final void assignLayersLocked(WindowList windows) {
80758112
Slog.v(TAG, "Assigning layers", here);
80768113
}
80778114

8115+
boolean anyLayerChanged = false;
8116+
80788117
for (i=0; i<N; i++) {
80798118
final WindowState w = windows.get(i);
80808119
final WindowStateAnimator winAnimator = w.mWinAnimator;
@@ -8090,6 +8129,7 @@ private final void assignLayersLocked(WindowList windows) {
80908129
}
80918130
if (w.mLayer != oldLayer) {
80928131
layerChanged = true;
8132+
anyLayerChanged = true;
80938133
}
80948134
oldLayer = winAnimator.mAnimLayer;
80958135
if (w.mTargetAppToken != null) {
@@ -8108,6 +8148,7 @@ private final void assignLayersLocked(WindowList windows) {
81088148
}
81098149
if (winAnimator.mAnimLayer != oldLayer) {
81108150
layerChanged = true;
8151+
anyLayerChanged = true;
81118152
}
81128153
if (layerChanged && mAnimator.isDimmingLocked(winAnimator)) {
81138154
// Force an animation pass just to update the mDimAnimator layer.
@@ -8122,6 +8163,10 @@ private final void assignLayersLocked(WindowList windows) {
81228163
//System.out.println(
81238164
// "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
81248165
}
8166+
8167+
if (anyLayerChanged) {
8168+
scheduleNotifyWindowLayersChangedIfNeededLocked(getDefaultDisplayContentLocked());
8169+
}
81258170
}
81268171

81278172
private boolean mInLayout = false;

0 commit comments

Comments
 (0)