Merge "Handwriting delegate API changes" into udc-dev am: 1902d032a1

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21652490

Change-Id: Id6e9e307086ddee5b3356afd5908360ff49edaab
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Justin Ghan
2023-03-01 22:36:30 +00:00
committed by Automerger Merge Worker
3 changed files with 42 additions and 59 deletions

View File

@@ -52022,8 +52022,8 @@ package android.view {
method @Nullable public CharSequence getAccessibilityPaneTitle(); method @Nullable public CharSequence getAccessibilityPaneTitle();
method @IdRes public int getAccessibilityTraversalAfter(); method @IdRes public int getAccessibilityTraversalAfter();
method @IdRes public int getAccessibilityTraversalBefore(); method @IdRes public int getAccessibilityTraversalBefore();
method @NonNull public String getAllowedHandwritingDelegatePackageName(); method @Nullable public String getAllowedHandwritingDelegatePackageName();
method @NonNull public String getAllowedHandwritingDelegatorPackageName(); method @Nullable public String getAllowedHandwritingDelegatorPackageName();
method public float getAlpha(); method public float getAlpha();
method public android.view.animation.Animation getAnimation(); method public android.view.animation.Animation getAnimation();
method @Nullable public android.graphics.Matrix getAnimationMatrix(); method @Nullable public android.graphics.Matrix getAnimationMatrix();
@@ -52406,8 +52406,8 @@ package android.view {
method public void setAccessibilityTraversalBefore(@IdRes int); method public void setAccessibilityTraversalBefore(@IdRes int);
method public void setActivated(boolean); method public void setActivated(boolean);
method public void setAllowClickWhenDisabled(boolean); method public void setAllowClickWhenDisabled(boolean);
method public void setAllowedHandwritingDelegatePackage(@NonNull String); method public void setAllowedHandwritingDelegatePackage(@Nullable String);
method public void setAllowedHandwritingDelegatorPackage(@NonNull String); method public void setAllowedHandwritingDelegatorPackage(@Nullable String);
method public void setAlpha(@FloatRange(from=0.0, to=1.0) float); method public void setAlpha(@FloatRange(from=0.0, to=1.0) float);
method public void setAnimation(android.view.animation.Animation); method public void setAnimation(android.view.animation.Animation);
method public void setAnimationMatrix(@Nullable android.graphics.Matrix); method public void setAnimationMatrix(@Nullable android.graphics.Matrix);

View File

@@ -172,9 +172,13 @@ public class HandwritingInitiator {
if (candidateView == getConnectedView()) { if (candidateView == getConnectedView()) {
startHandwriting(candidateView); startHandwriting(candidateView);
} else if (candidateView.getHandwritingDelegatorCallback() != null) { } else if (candidateView.getHandwritingDelegatorCallback() != null) {
String delegatePackageName =
candidateView.getAllowedHandwritingDelegatePackageName();
if (delegatePackageName == null) {
delegatePackageName = candidateView.getContext().getOpPackageName();
}
mImm.prepareStylusHandwritingDelegation( mImm.prepareStylusHandwritingDelegation(
candidateView, candidateView, delegatePackageName);
candidateView.getAllowedHandwritingDelegatePackageName());
candidateView.getHandwritingDelegatorCallback().run(); candidateView.getHandwritingDelegatorCallback().run();
} else { } else {
if (candidateView.getRevealOnFocusHint()) { if (candidateView.getRevealOnFocusHint()) {
@@ -299,8 +303,12 @@ public class HandwritingInitiator {
*/ */
@VisibleForTesting @VisibleForTesting
public boolean tryAcceptStylusHandwritingDelegation(@NonNull View view) { public boolean tryAcceptStylusHandwritingDelegation(@NonNull View view) {
if (mImm.acceptStylusHandwritingDelegation( String delegatorPackageName =
view, view.getAllowedHandwritingDelegatorPackageName())) { view.getAllowedHandwritingDelegatorPackageName();
if (delegatorPackageName == null) {
delegatorPackageName = view.getContext().getOpPackageName();
}
if (mImm.acceptStylusHandwritingDelegation(view, delegatorPackageName)) {
if (mState != null) { if (mState != null) {
mState.mHasInitiatedHandwriting = true; mState.mHasInitiatedHandwriting = true;
mState.mShouldInitHandwriting = false; mState.mShouldInitHandwriting = false;

View File

@@ -12437,11 +12437,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
public void setHandwritingDelegatorCallback(@Nullable Runnable callback) { public void setHandwritingDelegatorCallback(@Nullable Runnable callback) {
mHandwritingDelegatorCallback = callback; mHandwritingDelegatorCallback = callback;
if (callback != null) { 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())); 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 * 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 * 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 * 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 * editor view linked to this delegator view.
* #setHandwritingDelegatorCallback}. *
* <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 * <p>If this method is called on the delegator view, then {@link
* #setAllowedHandwritingDelegatorPackage} should also be called on the delegate editor view. * #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> * delegateEditorView.setAllowedHandwritingDelegatorPackage(package1);</pre>
* *
* @param allowedPackageName the package name of a delegate editor view linked to this delegator * @param allowedPackageName the package name of a delegate editor view linked to this delegator
* view * view, or {@code null} to restore the default behavior of only allowing delegate editor
* @throws IllegalStateException If the view has not been configured as a handwriting delegator * views from the same package as this delegator view
* using {@link #setHandwritingDelegatorCallback}.
*/ */
public void setAllowedHandwritingDelegatePackage(@NonNull String allowedPackageName) { public void setAllowedHandwritingDelegatePackage(@Nullable String allowedPackageName) {
if (mHandwritingDelegatorCallback == null) {
throw new IllegalStateException("This view is not a handwriting delegator.");
}
mAllowedHandwritingDelegatePackageName = allowedPackageName; mAllowedHandwritingDelegatePackageName = allowedPackageName;
} }
/** /**
* Returns the allowed package for delegate editor views for which this view may act as a * 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, * handwriting delegator, as set by {@link #setAllowedHandwritingDelegatePackage}. If {@link
* this will return this view's package name, since by default delegators may only be used to * #setAllowedHandwritingDelegatePackage} has not been called, or called with {@code null}
* initiate handwriting mode for a delegate editor view from the same package as the delegator * argument, this will return {@code null}, meaning that this delegator view may only be used to
* view. This will return a different allowed package if set by {@link * initiate handwriting mode for a delegate editor view from the same package as this delegator
* #setAllowedHandwritingDelegatePackage}. * view.
*
* @throws IllegalStateException If the view has not been configured as a handwriting delegator
* using {@link #setHandwritingDelegatorCallback}.
*/ */
@NonNull @Nullable
public String getAllowedHandwritingDelegatePackageName() { public String getAllowedHandwritingDelegatePackageName() {
if (mHandwritingDelegatorCallback == null) {
throw new IllegalStateException("This view is not a handwriting delegator.");
}
return mAllowedHandwritingDelegatePackageName; return mAllowedHandwritingDelegatePackageName;
} }
@@ -12519,12 +12507,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*/ */
public void setIsHandwritingDelegate(boolean isHandwritingDelegate) { public void setIsHandwritingDelegate(boolean isHandwritingDelegate) {
mIsHandwritingDelegate = 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 * 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 * 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 * 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 * <p>If this method is called on the delegate editor view, then {@link
* #setAllowedHandwritingDelegatePackage} should also be called on the delegator view. * #setAllowedHandwritingDelegatePackage} should also be called on the delegator view.
* *
* @param allowedPackageName the package name of a delegator view linked to this delegate editor * @param allowedPackageName the package name of a delegator view linked to this delegate editor
* view * view, or {@code null} to restore the default behavior of only allowing delegator views
* @throws IllegalStateException If the view has not been configured as a handwriting delegate * from the same package as this delegate editor view
* using {@link #setIsHandwritingDelegate}.
*/ */
public void setAllowedHandwritingDelegatorPackage(@NonNull String allowedPackageName) { public void setAllowedHandwritingDelegatorPackage(@Nullable String allowedPackageName) {
if (!mIsHandwritingDelegate) {
throw new IllegalStateException("This view is not a handwriting delegate.");
}
mAllowedHandwritingDelegatorPackageName = allowedPackageName; mAllowedHandwritingDelegatorPackageName = allowedPackageName;
} }
/** /**
* Returns the allowed package for views which may act as a handwriting delegator for this * 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, * delegate editor view, as set by {@link #setAllowedHandwritingDelegatorPackage}. If {@link
* this will return this view's package name, since by default only views from the same package * #setAllowedHandwritingDelegatorPackage} has not been called, or called with {@code null}
* as the delegator editor view may act as a handwriting delegator. This will return a different * argument, this will return {@code null}, meaning that only views from the same package as
* allowed package if set by {@link #setAllowedHandwritingDelegatorPackage}. * this delegator editor view may act as a handwriting delegator.
*
* @throws IllegalStateException If the view has not been configured as a handwriting delegate
* using {@link #setIsHandwritingDelegate}.
*/ */
@NonNull @Nullable
public String getAllowedHandwritingDelegatorPackageName() { public String getAllowedHandwritingDelegatorPackageName() {
if (!mIsHandwritingDelegate) {
throw new IllegalStateException("This view is not a handwriting delegate.");
}
return mAllowedHandwritingDelegatorPackageName; return mAllowedHandwritingDelegatorPackageName;
} }