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

Commit 60843fbc authored by Justin Ghan's avatar Justin Ghan
Browse files

Handwriting delegate API changes

Per API feedback, updating handwriting delegate APIs to behave as
standard setters and getters. Removing requirement to call APIs in a
specific order, and removing side effects of setting default allowed
packages.

Bug: 266834695
Bug: 228100684
Test: atest android.view.stylus.HandwritingInitiatorTest
Test: atest android.view.inputmethod.cts.StylusHandwritingTest
Change-Id: I4ff7d53168d1fe25198a2d24faa3e45af108f989
parent 42139e0e
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -51992,8 +51992,8 @@ package android.view {
    method @Nullable public CharSequence getAccessibilityPaneTitle();
    method @IdRes public int getAccessibilityTraversalAfter();
    method @IdRes public int getAccessibilityTraversalBefore();
    method @NonNull public String getAllowedHandwritingDelegatePackageName();
    method @NonNull public String getAllowedHandwritingDelegatorPackageName();
    method @Nullable public String getAllowedHandwritingDelegatePackageName();
    method @Nullable public String getAllowedHandwritingDelegatorPackageName();
    method public float getAlpha();
    method public android.view.animation.Animation getAnimation();
    method @Nullable public android.graphics.Matrix getAnimationMatrix();
@@ -52376,8 +52376,8 @@ package android.view {
    method public void setAccessibilityTraversalBefore(@IdRes int);
    method public void setActivated(boolean);
    method public void setAllowClickWhenDisabled(boolean);
    method public void setAllowedHandwritingDelegatePackage(@NonNull String);
    method public void setAllowedHandwritingDelegatorPackage(@NonNull String);
    method public void setAllowedHandwritingDelegatePackage(@Nullable String);
    method public void setAllowedHandwritingDelegatorPackage(@Nullable String);
    method public void setAlpha(@FloatRange(from=0.0, to=1.0) float);
    method public void setAnimation(android.view.animation.Animation);
    method public void setAnimationMatrix(@Nullable android.graphics.Matrix);
+12 −4
Original line number Diff line number Diff line
@@ -172,9 +172,13 @@ public class HandwritingInitiator {
                        if (candidateView == getConnectedView()) {
                            startHandwriting(candidateView);
                        } else if (candidateView.getHandwritingDelegatorCallback() != null) {
                            String delegatePackageName =
                                    candidateView.getAllowedHandwritingDelegatePackageName();
                            if (delegatePackageName == null) {
                                delegatePackageName = candidateView.getContext().getOpPackageName();
                            }
                            mImm.prepareStylusHandwritingDelegation(
                                    candidateView,
                                    candidateView.getAllowedHandwritingDelegatePackageName());
                                    candidateView, delegatePackageName);
                            candidateView.getHandwritingDelegatorCallback().run();
                        } else {
                            if (candidateView.getRevealOnFocusHint()) {
@@ -299,8 +303,12 @@ public class HandwritingInitiator {
     */
    @VisibleForTesting
    public boolean tryAcceptStylusHandwritingDelegation(@NonNull View view) {
        if (mImm.acceptStylusHandwritingDelegation(
                view, view.getAllowedHandwritingDelegatorPackageName())) {
        String delegatorPackageName =
                view.getAllowedHandwritingDelegatorPackageName();
        if (delegatorPackageName == null) {
            delegatorPackageName = view.getContext().getOpPackageName();
        }
        if (mImm.acceptStylusHandwritingDelegation(view, delegatorPackageName)) {
            if (mState != null) {
                mState.mHasInitiatedHandwriting = true;
                mState.mShouldInitHandwriting = false;
+26 −51
Original line number Diff line number Diff line
@@ -12437,11 +12437,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    public void setHandwritingDelegatorCallback(@Nullable Runnable callback) {
        mHandwritingDelegatorCallback = callback;
        if (callback != null) {
            // By default, the delegate must be from the same package as the delegator view.
            mAllowedHandwritingDelegatePackageName = mContext.getOpPackageName();
            setHandwritingArea(new Rect(0, 0, getWidth(), getHeight()));
        } else {
            mAllowedHandwritingDelegatePackageName = null;
        }
    }
@@ -12460,8 +12456,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * view from the specified package. If this method is not called, delegators may only be used to
     * initiate handwriting mode for a delegate editor view from the same package as the delegator
     * view. This method allows specifying a different trusted package which may contain a delegate
     * editor view linked to this delegator view. This should be called after {@link
     * #setHandwritingDelegatorCallback}.
     * editor view linked to this delegator view.
     *
     * <p>This method has no effect unless {@link #setHandwritingDelegatorCallback} is also called
     * to configure this view to act as a handwriting delegator.
     *
     * <p>If this method is called on the delegator view, then {@link
     * #setAllowedHandwritingDelegatorPackage} should also be called on the delegate editor view.
@@ -12479,33 +12477,23 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * delegateEditorView.setAllowedHandwritingDelegatorPackage(package1);</pre>
     *
     * @param allowedPackageName the package name of a delegate editor view linked to this delegator
     *     view
     * @throws IllegalStateException If the view has not been configured as a handwriting delegator
     *     using {@link #setHandwritingDelegatorCallback}.
     *     view, or {@code null} to restore the default behavior of only allowing delegate editor
     *     views from the same package as this delegator view
     */
    public void setAllowedHandwritingDelegatePackage(@NonNull String allowedPackageName) {
        if (mHandwritingDelegatorCallback == null) {
            throw new IllegalStateException("This view is not a handwriting delegator.");
        }
    public void setAllowedHandwritingDelegatePackage(@Nullable String allowedPackageName) {
        mAllowedHandwritingDelegatePackageName = allowedPackageName;
    }
    /**
     * Returns the allowed package for delegate editor views for which this view may act as a
     * handwriting delegator. If {@link #setAllowedHandwritingDelegatePackage} has not been called,
     * this will return this view's package name, since by default delegators may only be used to
     * initiate handwriting mode for a delegate editor view from the same package as the delegator
     * view. This will return a different allowed package if set by {@link
     * #setAllowedHandwritingDelegatePackage}.
     *
     * @throws IllegalStateException If the view has not been configured as a handwriting delegator
     *     using {@link #setHandwritingDelegatorCallback}.
     * handwriting delegator, as set by {@link #setAllowedHandwritingDelegatePackage}. If {@link
     * #setAllowedHandwritingDelegatePackage} has not been called, or called with {@code null}
     * argument, this will return {@code null}, meaning that this delegator view may only be used to
     * initiate handwriting mode for a delegate editor view from the same package as this delegator
     * view.
     */
    @NonNull
    @Nullable
    public String getAllowedHandwritingDelegatePackageName() {
        if (mHandwritingDelegatorCallback == null) {
            throw new IllegalStateException("This view is not a handwriting delegator.");
        }
        return mAllowedHandwritingDelegatePackageName;
    }
@@ -12519,12 +12507,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    public void setIsHandwritingDelegate(boolean isHandwritingDelegate) {
        mIsHandwritingDelegate = isHandwritingDelegate;
        if (mIsHandwritingDelegate) {
            // By default, the delegator must be from the same package as the delegate view.
            mAllowedHandwritingDelegatorPackageName = mContext.getOpPackageName();
        } else {
            mAllowedHandwritingDelegatePackageName = null;
        }
    }
    /**
@@ -12537,41 +12519,34 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    /**
     * Specifies that a view from the specified package may act as a handwriting delegator for this
     * delegate editor view. If this method is not called, only views from the same package as the
     * delegate editor view. If this method is not called, only views from the same package as this
     * delegate editor view may act as a handwriting delegator. This method allows specifying a
     * different trusted package which may contain a delegator view linked to this delegate editor
     * view. This should be called after {@link #setIsHandwritingDelegate}.
     * view.
     *
     * <p>This method has no effect unless {@link #setIsHandwritingDelegate} is also called to
     * configure this view to act as a handwriting delegate.
     *
     * <p>If this method is called on the delegate editor view, then {@link
     * #setAllowedHandwritingDelegatePackage} should also be called on the delegator view.
     *
     * @param allowedPackageName the package name of a delegator view linked to this delegate editor
     *     view
     * @throws IllegalStateException If the view has not been configured as a handwriting delegate
     *     using {@link #setIsHandwritingDelegate}.
     *     view, or {@code null} to restore the default behavior of only allowing delegator views
     *     from the same package as this delegate editor view
     */
    public void setAllowedHandwritingDelegatorPackage(@NonNull String allowedPackageName) {
        if (!mIsHandwritingDelegate) {
            throw new IllegalStateException("This view is not a handwriting delegate.");
        }
    public void setAllowedHandwritingDelegatorPackage(@Nullable String allowedPackageName) {
        mAllowedHandwritingDelegatorPackageName = allowedPackageName;
    }
    /**
     * Returns the allowed package for views which may act as a handwriting delegator for this
     * delegate editor view. If {@link #setAllowedHandwritingDelegatorPackage} has not been called,
     * this will return this view's package name, since by default only views from the same package
     * as the delegator editor view may act as a handwriting delegator. This will return a different
     * allowed package if set by {@link #setAllowedHandwritingDelegatorPackage}.
     *
     * @throws IllegalStateException If the view has not been configured as a handwriting delegate
     *     using {@link #setIsHandwritingDelegate}.
     * delegate editor view, as set by {@link #setAllowedHandwritingDelegatorPackage}. If {@link
     * #setAllowedHandwritingDelegatorPackage} has not been called, or called with {@code null}
     * argument, this will return {@code null}, meaning that only views from the same package as
     * this delegator editor view may act as a handwriting delegator.
     */
    @NonNull
    @Nullable
    public String getAllowedHandwritingDelegatorPackageName() {
        if (!mIsHandwritingDelegate) {
            throw new IllegalStateException("This view is not a handwriting delegate.");
        }
        return mAllowedHandwritingDelegatorPackageName;
    }