Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f8fb7b24 authored by Jacky Kao's avatar Jacky Kao
Browse files

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 1aa113d8)
parent 25546c38
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -9725,6 +9725,12 @@ public final class Settings {
        public static final String ACCESSIBILITY_MAGNIFICATION_MODE =
                "accessibility_magnification_mode";
        /**
         * Magnification mode value that is a default value for the magnification logging feature.
         * @hide
         */
        public static final int ACCESSIBILITY_MAGNIFICATION_MODE_NONE = 0x0;
        /**
         * Magnification mode value that magnifies whole display.
         * @hide
+11 −0
Original line number Diff line number Diff line
@@ -133,6 +133,17 @@ public final class AccessibilityStatsLogUtils {
                duration);
    }

    /**
     * Logs the activated mode of the magnification when the IME window is shown on the screen.
     * Calls this when the magnification is enabled and the IME window is shown on the screen.
     *
     * @param mode The activated magnification mode.
     */
    public static void logMagnificationModeWithImeOn(int mode) {
        FrameworkStatsLog.write(FrameworkStatsLog.MAGNIFICATION_MODE_WITH_IME_ON_REPORTED,
                convertToLoggingMagnificationMode(mode));
    }

    private static int convertToLoggingShortcutType(@ShortcutType int shortcutType) {
        switch (shortcutType) {
            case ACCESSIBILITY_BUTTON:
+33 −9
Original line number Diff line number Diff line
@@ -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);
    }
}
+56 −1
Original line number Diff line number Diff line
@@ -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}.
     *
+27 −1
Original line number Diff line number Diff line
@@ -514,6 +514,18 @@ final class AccessibilityController {
        }
    }

    void onImeSurfaceShownChanged(WindowState windowState, boolean shown) {
        if (mAccessibilityTracing.isEnabled()) {
            mAccessibilityTracing.logState(TAG + ".onImeSurfaceShownChanged",
                    "windowState=" + windowState + "; shown=" + shown);
        }
        final int displayId = windowState.getDisplayId();
        final DisplayMagnifier displayMagnifier = mDisplayMagnifiers.get(displayId);
        if (displayMagnifier != null) {
            displayMagnifier.onImeSurfaceShownChanged(shown);
        }
    }

    private static void populateTransformationMatrix(WindowState windowState,
            Matrix outMatrix) {
        windowState.getTransformationMatrix(sTempFloats, outMatrix);
@@ -766,6 +778,15 @@ final class AccessibilityController {
            }
        }

        void onImeSurfaceShownChanged(boolean shown) {
            if (mAccessibilityTracing.isEnabled()) {
                mAccessibilityTracing.logState(
                        LOG_TAG + ".onImeSurfaceShownChanged", "shown=" + shown);
            }
            mHandler.obtainMessage(MyHandler.MESSAGE_NOTIFY_IME_WINDOW_VISIBILITY_CHANGED,
                    shown ? 1 : 0, 0).sendToTarget();
        }

        MagnificationSpec getMagnificationSpecForWindow(WindowState windowState) {
            if (mAccessibilityTracing.isEnabled()) {
                mAccessibilityTracing.logState(LOG_TAG + ".getMagnificationSpecForWindow",
@@ -1337,6 +1358,7 @@ final class AccessibilityController {
            public static final int MESSAGE_NOTIFY_USER_CONTEXT_CHANGED = 3;
            public static final int MESSAGE_NOTIFY_ROTATION_CHANGED = 4;
            public static final int MESSAGE_SHOW_MAGNIFIED_REGION_BOUNDS_IF_NEEDED = 5;
            public static final int MESSAGE_NOTIFY_IME_WINDOW_VISIBILITY_CHANGED = 6;

            MyHandler(Looper looper) {
                super(looper);
@@ -1380,6 +1402,11 @@ final class AccessibilityController {
                            }
                        }
                    } break;

                    case MESSAGE_NOTIFY_IME_WINDOW_VISIBILITY_CHANGED: {
                        final boolean shown = message.arg1 == 1;
                        mCallbacks.onImeWindowVisibilityChanged(shown);
                    } break;
                }
            }
        }
@@ -2123,5 +2150,4 @@ final class AccessibilityController {
            }
        }
    }

}
Loading