Skip to content

Commit 36e614c

Browse files
committed
Screen magnification should disengage on screen off.
1. When the screen goes off the user will be in a completely different context upon turning the screen on. Therefore, if magnification auto update is enabled magnification will be disengaged on screen off. bug:7139088 Change-Id: I790cfa5b3cf31d34e95fc9548e6246a84096c37b
1 parent 86fe9e1 commit 36e614c

File tree

1 file changed

+63
-8
lines changed

1 file changed

+63
-8
lines changed

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

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
import android.animation.ObjectAnimator;
2222
import android.animation.TypeEvaluator;
2323
import android.animation.ValueAnimator;
24+
import android.content.BroadcastReceiver;
2425
import android.content.Context;
26+
import android.content.Intent;
27+
import android.content.IntentFilter;
2528
import android.graphics.Canvas;
2629
import android.graphics.Color;
2730
import android.graphics.PixelFormat;
@@ -144,6 +147,7 @@ public final class ScreenMagnifier implements EventStreamTransformation {
144147

145148
private final MagnificationController mMagnificationController;
146149
private final DisplayContentObserver mDisplayContentObserver;
150+
private final ScreenStateObserver mScreenStateObserver;
147151
private final Viewport mViewport;
148152

149153
private final int mTapTimeSlop = ViewConfiguration.getTapTimeout();
@@ -187,6 +191,8 @@ public ScreenMagnifier(Context context) {
187191
mDisplayContentObserver = new DisplayContentObserver(mContext, mViewport,
188192
mMagnificationController, mWindowManagerService, mDisplayProvider,
189193
mLongAnimationDuration, mWindowAnimationScale);
194+
mScreenStateObserver = new ScreenStateObserver(mContext, mViewport,
195+
mMagnificationController);
190196

191197
mGestureDetector = new GestureDetector(context);
192198

@@ -247,6 +253,7 @@ public void onDestroy() {
247253
mViewport.setFrameShown(false, true);
248254
mDisplayProvider.destroy();
249255
mDisplayContentObserver.destroy();
256+
mScreenStateObserver.destroy();
250257
}
251258

252259
private void handleMotionEventStateDelegating(MotionEvent event, int policyFlags) {
@@ -786,6 +793,12 @@ private float getPersistedScale() {
786793
DEFAULT_MAGNIFICATION_SCALE);
787794
}
788795

796+
private static boolean isScreenMagnificationAutoUpdateEnabled(Context context) {
797+
return (Settings.Secure.getInt(context.getContentResolver(),
798+
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_AUTO_UPDATE,
799+
DEFAULT_SCREEN_MAGNIFICATION_AUTO_UPDATE) == 1);
800+
}
801+
789802
private static final class MotionEventInfo {
790803

791804
private static final int MAX_POOL_SIZE = 10;
@@ -844,6 +857,54 @@ private void clear() {
844857
}
845858
}
846859

860+
private static final class ScreenStateObserver extends BroadcastReceiver {
861+
862+
private static final int MESSAGE_ON_SCREEN_STATE_CHANGE = 1;
863+
864+
private final Handler mHandler = new Handler() {
865+
@Override
866+
public void handleMessage(Message message) {
867+
switch (message.what) {
868+
case MESSAGE_ON_SCREEN_STATE_CHANGE: {
869+
String action = (String) message.obj;
870+
handleOnScreenStateChange(action);
871+
} break;
872+
}
873+
}
874+
};
875+
876+
private final Context mContext;
877+
private final Viewport mViewport;
878+
private final MagnificationController mMagnificationController;
879+
880+
public ScreenStateObserver(Context context, Viewport viewport,
881+
MagnificationController magnificationController) {
882+
mContext = context;
883+
mViewport = viewport;
884+
mMagnificationController = magnificationController;
885+
mContext.registerReceiver(this, new IntentFilter(Intent.ACTION_SCREEN_OFF));
886+
}
887+
888+
public void destroy() {
889+
mContext.unregisterReceiver(this);
890+
}
891+
892+
@Override
893+
public void onReceive(Context context, Intent intent) {
894+
mHandler.obtainMessage(MESSAGE_ON_SCREEN_STATE_CHANGE,
895+
intent.getAction()).sendToTarget();
896+
}
897+
898+
private void handleOnScreenStateChange(String action) {
899+
if (action.equals(Intent.ACTION_SCREEN_OFF)
900+
&& mMagnificationController.isMagnifying()
901+
&& isScreenMagnificationAutoUpdateEnabled(mContext)) {
902+
mMagnificationController.reset(false);
903+
mViewport.setFrameShown(false, false);
904+
}
905+
}
906+
}
907+
847908
private static final class DisplayContentObserver {
848909

849910
private static final int MESSAGE_SHOW_VIEWPORT_FRAME = 1;
@@ -972,7 +1033,7 @@ private void handleOnWindowTransition(int transition, WindowInfo info) {
9721033
switch (transition) {
9731034
case WindowManagerPolicy.TRANSIT_ENTER:
9741035
case WindowManagerPolicy.TRANSIT_SHOW: {
975-
if (!magnifying || !screenMagnificationAutoUpdateEnabled(mContext)) {
1036+
if (!magnifying || !isScreenMagnificationAutoUpdateEnabled(mContext)) {
9761037
break;
9771038
}
9781039
final int type = info.type;
@@ -1060,18 +1121,12 @@ private void ensureRectangleInMagnifiedRegionBounds(Rect magnifiedRegionBounds,
10601121

10611122
private void resetMagnificationIfNeeded() {
10621123
if (mMagnificationController.isMagnifying()
1063-
&& screenMagnificationAutoUpdateEnabled(mContext)) {
1124+
&& isScreenMagnificationAutoUpdateEnabled(mContext)) {
10641125
mMagnificationController.reset(true);
10651126
mViewport.setFrameShown(false, true);
10661127
}
10671128
}
10681129

1069-
private boolean screenMagnificationAutoUpdateEnabled(Context context) {
1070-
return (Settings.Secure.getInt(context.getContentResolver(),
1071-
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_AUTO_UPDATE,
1072-
DEFAULT_SCREEN_MAGNIFICATION_AUTO_UPDATE) == 1);
1073-
}
1074-
10751130
private String windowTransitionToString(int transition) {
10761131
switch (transition) {
10771132
case WindowManagerPolicy.TRANSIT_UNSET: {

0 commit comments

Comments
 (0)