Logs magnification feature behavior. (2/2).

Uses the atom MagnificationModeWithImeOnReported in westworld to log
the activated mode when the IME window is shown on the screen.

Adding a new callback API in the MagnificationCallback to monitor the
IME window visibility changes. The A11y framework registers the
callback when the magnification is enabled. It logs the related
data when it receives the IME window visibility changes through
this callback and the magnification is in the activation.

Bug: 154021596
Test: a11y CTS & unit tests
Test: make statsd_testdrive && ./out/host/linux-x86/bin/statsd_testdrive 346
Merged-In: I49b02e00d5a1131b388eeb923440f59a2b4f81a6
Change-Id: I49b02e00d5a1131b388eeb923440f59a2b4f81a6
(cherry picked from commit 1aa113d8dd)
This commit is contained in:
Jacky Kao
2021-01-26 10:16:39 +08:00
parent 25546c3867
commit f8fb7b24bc
10 changed files with 203 additions and 21 deletions

View File

@@ -79,7 +79,7 @@ public class FullScreenMagnificationController {
private final ScreenStateObserver mScreenStateObserver;
private final MagnificationRequestObserver mMagnificationRequestObserver;
private final MagnificationInfoChangedCallback mMagnificationInfoChangedCallback;
private int mUserId;
@@ -284,6 +284,14 @@ public class FullScreenMagnificationController {
mControllerCtx.getHandler().sendMessage(m);
}
@Override
public void onImeWindowVisibilityChanged(boolean shown) {
final Message m = PooledLambda.obtainMessage(
FullScreenMagnificationController::notifyImeWindowVisibilityChanged,
FullScreenMagnificationController.this, shown);
mControllerCtx.getHandler().sendMessage(m);
}
/**
* Update our copy of the current magnification region
*
@@ -329,7 +337,7 @@ public class FullScreenMagnificationController {
final boolean lastMagnificationActivated = mMagnificationActivated;
mMagnificationActivated = spec.scale > 1.0f;
if (mMagnificationActivated != lastMagnificationActivated) {
mMagnificationRequestObserver.onFullScreenMagnificationActivationState(
mMagnificationInfoChangedCallback.onFullScreenMagnificationActivationState(
mMagnificationActivated);
}
}
@@ -498,7 +506,7 @@ public class FullScreenMagnificationController {
sendSpecToAnimation(mCurrentMagnificationSpec, animationCallback);
if (isMagnifying() && (id != INVALID_ID)) {
mIdOfLastServiceToMagnify = id;
mMagnificationRequestObserver.onRequestMagnificationSpec(mDisplayId,
mMagnificationInfoChangedCallback.onRequestMagnificationSpec(mDisplayId,
mIdOfLastServiceToMagnify);
}
return changed;
@@ -631,12 +639,12 @@ public class FullScreenMagnificationController {
*/
public FullScreenMagnificationController(@NonNull Context context,
@NonNull AccessibilityManagerService ams, @NonNull Object lock,
@NonNull MagnificationRequestObserver magnificationRequestObserver) {
@NonNull MagnificationInfoChangedCallback magnificationInfoChangedCallback) {
this(new ControllerContext(context, ams,
LocalServices.getService(WindowManagerInternal.class),
new Handler(context.getMainLooper()),
context.getResources().getInteger(R.integer.config_longAnimTime)), lock,
magnificationRequestObserver);
magnificationInfoChangedCallback);
}
/**
@@ -645,12 +653,12 @@ public class FullScreenMagnificationController {
@VisibleForTesting
public FullScreenMagnificationController(@NonNull ControllerContext ctx,
@NonNull Object lock,
@NonNull MagnificationRequestObserver magnificationRequestObserver) {
@NonNull MagnificationInfoChangedCallback magnificationInfoChangedCallback) {
mControllerCtx = ctx;
mLock = lock;
mMainThreadId = mControllerCtx.getContext().getMainLooper().getThread().getId();
mScreenStateObserver = new ScreenStateObserver(mControllerCtx.getContext(), this);
mMagnificationRequestObserver = magnificationRequestObserver;
mMagnificationInfoChangedCallback = magnificationInfoChangedCallback;
}
/**
@@ -1167,6 +1175,16 @@ public class FullScreenMagnificationController {
}
}
/**
* Notifies that the IME window visibility changed.
*
* @param shown {@code true} means the IME window shows on the screen. Otherwise it's
* hidden.
*/
void notifyImeWindowVisibilityChanged(boolean shown) {
mMagnificationInfoChangedCallback.onImeWindowVisibilityChanged(shown);
}
/**
* Returns {@code true} if the magnifiable regions of the display is forced to be shown.
*
@@ -1528,7 +1546,7 @@ public class FullScreenMagnificationController {
return animate ? STUB_ANIMATION_CALLBACK : null;
}
interface MagnificationRequestObserver {
interface MagnificationInfoChangedCallback {
/**
* Called when the {@link MagnificationSpec} is changed with non-default
@@ -1545,7 +1563,13 @@ public class FullScreenMagnificationController {
*
* @param activated {@code true} if the magnification is activated, otherwise {@code false}.
*/
@GuardedBy("mLock")
void onFullScreenMagnificationActivationState(boolean activated);
/**
* Called when the IME window visibility changed.
* @param shown {@code true} means the IME window shows on the screen. Otherwise it's
* hidden.
*/
void onImeWindowVisibilityChanged(boolean shown);
}
}

View File

@@ -18,6 +18,7 @@ package com.android.server.accessibility.magnification;
import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_ALL;
import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN;
import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_NONE;
import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW;
import android.annotation.NonNull;
@@ -33,6 +34,7 @@ import android.util.SparseArray;
import android.view.accessibility.MagnificationAnimationCallback;
import com.android.internal.accessibility.util.AccessibilityStatsLogUtils;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.accessibility.AccessibilityManagerService;
@@ -58,7 +60,7 @@ import com.android.server.accessibility.AccessibilityManagerService;
*/
public class MagnificationController implements WindowMagnificationManager.Callback,
MagnificationGestureHandler.Callback,
FullScreenMagnificationController.MagnificationRequestObserver {
FullScreenMagnificationController.MagnificationInfoChangedCallback {
private static final boolean DEBUG = false;
private static final String TAG = "MagnificationController";
@@ -73,6 +75,10 @@ public class MagnificationController implements WindowMagnificationManager.Callb
private WindowMagnificationManager mWindowMagnificationMgr;
private int mMagnificationCapabilities = ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN;
@GuardedBy("mLock")
private int mActivatedMode = ACCESSIBILITY_MAGNIFICATION_MODE_NONE;
@GuardedBy("mLock")
private boolean mImeWindowVisible = false;
private long mWindowModeEnabledTime = 0;
private long mFullScreenModeEnabledTime = 0;
@@ -216,9 +222,18 @@ public class MagnificationController implements WindowMagnificationManager.Callb
public void onWindowMagnificationActivationState(boolean activated) {
if (activated) {
mWindowModeEnabledTime = SystemClock.uptimeMillis();
synchronized (mLock) {
mActivatedMode = ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW;
}
logMagnificationModeWithImeOnIfNeeded();
} else {
logMagnificationUsageState(ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW,
SystemClock.uptimeMillis() - mWindowModeEnabledTime);
synchronized (mLock) {
mActivatedMode = ACCESSIBILITY_MAGNIFICATION_MODE_NONE;
}
}
}
@@ -226,12 +241,29 @@ public class MagnificationController implements WindowMagnificationManager.Callb
public void onFullScreenMagnificationActivationState(boolean activated) {
if (activated) {
mFullScreenModeEnabledTime = SystemClock.uptimeMillis();
synchronized (mLock) {
mActivatedMode = ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN;
}
logMagnificationModeWithImeOnIfNeeded();
} else {
logMagnificationUsageState(ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN,
SystemClock.uptimeMillis() - mFullScreenModeEnabledTime);
synchronized (mLock) {
mActivatedMode = ACCESSIBILITY_MAGNIFICATION_MODE_NONE;
}
}
}
@Override
public void onImeWindowVisibilityChanged(boolean shown) {
synchronized (mLock) {
mImeWindowVisible = shown;
}
logMagnificationModeWithImeOnIfNeeded();
}
/**
* Wrapper method of logging the magnification activated mode and its duration of the usage
* when the magnification is disabled.
@@ -244,6 +276,17 @@ public class MagnificationController implements WindowMagnificationManager.Callb
AccessibilityStatsLogUtils.logMagnificationUsageState(mode, duration);
}
/**
* Wrapper method of logging the activated mode of the magnification when the IME window
* is shown on the screen.
*
* @param mode The activated magnification mode.
*/
@VisibleForTesting
public void logMagnificationModeWithIme(int mode) {
AccessibilityStatsLogUtils.logMagnificationModeWithImeOn(mode);
}
/**
* Updates the active user ID of {@link FullScreenMagnificationController} and {@link
* WindowMagnificationManager}.
@@ -295,6 +338,18 @@ public class MagnificationController implements WindowMagnificationManager.Callb
}
}
private void logMagnificationModeWithImeOnIfNeeded() {
final int mode;
synchronized (mLock) {
if (!mImeWindowVisible || mActivatedMode == ACCESSIBILITY_MAGNIFICATION_MODE_NONE) {
return;
}
mode = mActivatedMode;
}
logMagnificationModeWithIme(mode);
}
/**
* Getter of {@link FullScreenMagnificationController}.
*