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

Commit 3a5489c6 authored by Minche Li's avatar Minche Li Committed by Android (Google) Code Review
Browse files

Merge "MagnificationProcessor uses MagnificationConfig to control the specified magnifier"

parents ea628fc3 1a07e0db
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -3255,6 +3255,28 @@ package android.accessibilityservice {
    method public boolean willContinue();
  }
  public final class MagnificationConfig implements android.os.Parcelable {
    method public int describeContents();
    method public float getCenterX();
    method public float getCenterY();
    method public int getMode();
    method public float getScale();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.accessibilityservice.MagnificationConfig> CREATOR;
    field public static final int DEFAULT_MODE = 0; // 0x0
    field public static final int FULLSCREEN_MODE = 1; // 0x1
    field public static final int WINDOW_MODE = 2; // 0x2
  }
  public static final class MagnificationConfig.Builder {
    ctor public MagnificationConfig.Builder();
    method @NonNull public android.accessibilityservice.MagnificationConfig build();
    method @NonNull public android.accessibilityservice.MagnificationConfig.Builder setCenterX(float);
    method @NonNull public android.accessibilityservice.MagnificationConfig.Builder setCenterY(float);
    method @NonNull public android.accessibilityservice.MagnificationConfig.Builder setMode(int);
    method @NonNull public android.accessibilityservice.MagnificationConfig.Builder setScale(float);
  }
  public final class TouchInteractionController {
    method public int getDisplayId();
    method public int getMaxPointerCount();
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.accessibilityservice;

parcelable MagnificationConfig;
+250 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.accessibilityservice;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.os.Parcel;
import android.os.Parcelable;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * This class describes the magnification config for {@link AccessibilityService} to control the
 * magnification.
 *
 * <p>
 * When the magnification config uses {@link #DEFAULT_MODE},
 * {@link AccessibilityService} will be able to control the activated magnifier on the display.
 * If there is no magnifier activated, it controls the last-activated magnification mode.
 * If there is no magnifier activated before, it controls full-screen magnifier by default.
 * </p>
 *
 * <p>
 * When the magnification config uses {@link #FULLSCREEN_MODE}. {@link AccessibilityService} will
 * be able to control full-screen magnifier on the display.
 * </p>
 *
 * <p>
 * When the magnification config uses {@link #WINDOW_MODE}. {@link AccessibilityService} will be
 * able to control the activated window magnifier on the display.
 * </p>
 *
 * <p>
 * If the other magnification configs, scale centerX and centerY, are not set by the
 * {@link Builder}, the configs should be current values or default values. And the center
 * position ordinarily is the center of the screen.
 * </p>
 */
public final class MagnificationConfig implements Parcelable {

    /** The controlling magnification mode. It controls the activated magnifier. */
    public static final int DEFAULT_MODE = 0;
    /** The controlling magnification mode. It controls fullscreen magnifier. */
    public static final int FULLSCREEN_MODE = 1;
    /** The controlling magnification mode. It controls window magnifier. */
    public static final int WINDOW_MODE = 2;

    @IntDef(prefix = {"MAGNIFICATION_MODE"}, value = {
            DEFAULT_MODE,
            FULLSCREEN_MODE,
            WINDOW_MODE,
    })
    @Retention(RetentionPolicy.SOURCE)
    @interface MAGNIFICATION_MODE {
    }

    private int mMode = DEFAULT_MODE;
    private float mScale = Float.NaN;
    private float mCenterX = Float.NaN;
    private float mCenterY = Float.NaN;

    private MagnificationConfig() {
        /* do nothing */
    }

    private MagnificationConfig(@NonNull Parcel parcel) {
        mMode = parcel.readInt();
        mScale = parcel.readFloat();
        mCenterX = parcel.readFloat();
        mCenterY = parcel.readFloat();
    }

    /**
     * Returns the magnification mode that is the current activated mode or the controlling mode of
     * the config.
     *
     * @return The magnification mode
     */
    public int getMode() {
        return mMode;
    }

    /**
     * Returns the magnification scale of the controlling magnifier
     *
     * @return the scale If the controlling magnifier is not activated, it returns 1 by default
     */
    public float getScale() {
        return mScale;
    }

    /**
     * Returns the screen-relative X coordinate of the center of the magnification viewport.
     *
     * @return the X coordinate. If the controlling magnifier is {@link #WINDOW_MODE} but not
     * enabled, it returns {@link Float#NaN}. If the controlling magnifier is {@link
     * #FULLSCREEN_MODE} but not enabled, it returns 0
     */
    public float getCenterX() {
        return mCenterX;
    }

    /**
     * Returns the screen-relative Y coordinate of the center of the magnification viewport.
     *
     * @return the Y coordinate If the controlling magnifier is {@link #WINDOW_MODE} but not
     * enabled, it returns {@link Float#NaN}. If the controlling magnifier is {@link
     * #FULLSCREEN_MODE} but not enabled, it returns 0
     */
    public float getCenterY() {
        return mCenterY;
    }

    @NonNull
    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder("MagnificationConfig[");
        stringBuilder.append("mode: ").append(getMode());
        stringBuilder.append(", ");
        stringBuilder.append("scale: ").append(getScale());
        stringBuilder.append(", ");
        stringBuilder.append("centerX: ").append(getCenterX());
        stringBuilder.append(", ");
        stringBuilder.append("centerY: ").append(getCenterY());
        stringBuilder.append("] ");
        return stringBuilder.toString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(@NonNull Parcel parcel, int flags) {
        parcel.writeInt(mMode);
        parcel.writeFloat(mScale);
        parcel.writeFloat(mCenterX);
        parcel.writeFloat(mCenterY);
    }

    /**
     * Builder for creating {@link MagnificationConfig} objects.
     */
    public static final class Builder {

        private int mMode = DEFAULT_MODE;
        private float mScale = Float.NaN;
        private float mCenterX = Float.NaN;
        private float mCenterY = Float.NaN;

        /**
         * Creates a new Builder.
         */
        public Builder() {
        }

        /**
         * Sets the magnification mode.
         *
         * @param mode The magnification mode
         * @return This builder
         */
        @NonNull
        public MagnificationConfig.Builder setMode(@MAGNIFICATION_MODE int mode) {
            mMode = mode;
            return this;
        }

        /**
         * Sets the magnification scale.
         *
         * @param scale The magnification scale
         * @return This builder
         */
        @NonNull
        public MagnificationConfig.Builder setScale(float scale) {
            mScale = scale;
            return this;
        }

        /**
         * Sets the X coordinate of the center of the magnification viewport.
         *
         * @param centerX the screen-relative X coordinate around which to
         *                center and scale, or {@link Float#NaN} to leave unchanged
         * @return This builder
         */
        @NonNull
        public MagnificationConfig.Builder setCenterX(float centerX) {
            mCenterX = centerX;
            return this;
        }

        /**
         * Sets the Y coordinate of the center of the magnification viewport.
         *
         * @param centerY the screen-relative Y coordinate around which to
         *                center and scale, or {@link Float#NaN} to leave unchanged
         * @return This builder
         */
        @NonNull
        public MagnificationConfig.Builder setCenterY(float centerY) {
            mCenterY = centerY;
            return this;
        }

        /**
         * Builds and returns a {@link MagnificationConfig}
         */
        @NonNull
        public MagnificationConfig build() {
            MagnificationConfig magnificationConfig = new MagnificationConfig();
            magnificationConfig.mMode = mMode;
            magnificationConfig.mScale = mScale;
            magnificationConfig.mCenterX = mCenterX;
            magnificationConfig.mCenterY = mCenterY;
            return magnificationConfig;
        }
    }

    /**
     * @see Parcelable.Creator
     */
    public static final @NonNull Parcelable.Creator<MagnificationConfig> CREATOR =
            new Parcelable.Creator<MagnificationConfig>() {
                public MagnificationConfig createFromParcel(Parcel parcel) {
                    return new MagnificationConfig(parcel);
                }

                public MagnificationConfig[] newArray(int size) {
                    return new MagnificationConfig[size];
                }
            };
}
+7 −2
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.accessibilityservice.AccessibilityServiceInfo;
import android.accessibilityservice.AccessibilityTrace;
import android.accessibilityservice.IAccessibilityServiceClient;
import android.accessibilityservice.IAccessibilityServiceConnection;
import android.accessibilityservice.MagnificationConfig;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.PendingIntent;
@@ -1101,8 +1102,12 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
            try {
                MagnificationProcessor magnificationProcessor =
                        mSystemSupport.getMagnificationProcessor();
                return magnificationProcessor
                        .setScaleAndCenter(displayId, scale, centerX, centerY, animate, mId);
                final MagnificationConfig config = new MagnificationConfig.Builder()
                        .setScale(scale)
                        .setCenterX(centerX)
                        .setCenterY(centerY).build();
                return magnificationProcessor.setMagnificationConfig(displayId, config, animate,
                        mId);
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
+24 −1
Original line number Diff line number Diff line
@@ -84,6 +84,8 @@ public class MagnificationController implements WindowMagnificationManager.Callb

    @GuardedBy("mLock")
    private int mActivatedMode = ACCESSIBILITY_MAGNIFICATION_MODE_NONE;
    @GuardedBy("mLock")
    private int mLastActivatedMode = ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN;
    // Track the active user to reset the magnification and get the associated user settings.
    private @UserIdInt int mUserId = UserHandle.USER_SYSTEM;
    @GuardedBy("mLock")
@@ -239,6 +241,7 @@ public class MagnificationController implements WindowMagnificationManager.Callb

            synchronized (mLock) {
                mActivatedMode = ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW;
                mLastActivatedMode = mActivatedMode;
            }
            logMagnificationModeWithImeOnIfNeeded();
            disableFullScreenMagnificationIfNeeded(displayId);
@@ -276,6 +279,7 @@ public class MagnificationController implements WindowMagnificationManager.Callb

            synchronized (mLock) {
                mActivatedMode = ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN;
                mLastActivatedMode = mActivatedMode;
            }
            logMagnificationModeWithImeOnIfNeeded();
        } else {
@@ -297,6 +301,16 @@ public class MagnificationController implements WindowMagnificationManager.Callb
        logMagnificationModeWithImeOnIfNeeded();
    }

    /**
     * Returns the last activated magnification mode. If there is no activated magnifier before, it
     * returns fullscreen mode by default.
     */
    public int getLastActivatedMode() {
        synchronized (mLock) {
            return mLastActivatedMode;
        }
    }

    /**
     * Wrapper method of logging the magnification activated mode and its duration of the usage
     * when the magnification is disabled.
@@ -336,6 +350,7 @@ public class MagnificationController implements WindowMagnificationManager.Callb
        synchronized (mLock) {
            fullMagnificationController = mFullScreenMagnificationController;
            windowMagnificationManager = mWindowMagnificationMgr;
            mLastActivatedMode = ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN;
        }

        mScaleProvider.onUserChanged(userId);
@@ -462,7 +477,15 @@ public class MagnificationController implements WindowMagnificationManager.Callb
        return mTempPoint;
    }

    private boolean isActivated(int displayId, int mode) {
    /**
     * Return {@code true} if the specified magnification mode on the given display is activated
     * or not.
     *
     * @param displayId The logical displayId.
     * @param mode It's either ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN or
     * ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW.
     */
    public boolean isActivated(int displayId, int mode) {
        boolean isActivated = false;
        if (mode == ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN) {
            synchronized (mLock) {
Loading