Pointer Icon Refactor: Simplify tracking resolved pointer icon
There isn't a big benefit of tracking the pointer icon type and custom
icon individually in ViewRootImpl. It only adds complexity that is
already encapsulated in the PointerIcon class.
So we simplify the tracking logic by using a single mResolvedPointerIcon
member to track the resolved icon.
Bug: 293587049
Test: manual
Change-Id: I86e4929c01ed1322e8254c98bbf47949e8bc02ab
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 1530aa7..588a41d 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -826,11 +826,19 @@
* The resolved pointer icon type requested by this window.
* A null value indicates the resolved pointer icon has not yet been calculated.
*/
+ // TODO(b/293587049): Remove pointer icon tracking by type when refactor is complete.
@Nullable
private Integer mPointerIconType = null;
private PointerIcon mCustomPointerIcon = null;
/**
+ * The resolved pointer icon requested by this window.
+ * A null value indicates the resolved pointer icon has not yet been calculated.
+ */
+ @Nullable
+ private PointerIcon mResolvedPointerIcon = null;
+
+ /**
* see {@link #playSoundEffect(int)}
*/
AudioManager mAudioManager;
@@ -7399,12 +7407,14 @@
// Other apps or the window manager may change the icon type outside of
// this app, therefore the icon type has to be reset on enter/exit event.
mPointerIconType = null;
+ mResolvedPointerIcon = null;
}
if (action != MotionEvent.ACTION_HOVER_EXIT) {
// Resolve the pointer icon
if (!updatePointerIcon(event) && action == MotionEvent.ACTION_HOVER_MOVE) {
mPointerIconType = null;
+ mResolvedPointerIcon = null;
}
}
@@ -7459,6 +7469,7 @@
private void resetPointerIcon(MotionEvent event) {
mPointerIconType = null;
+ mResolvedPointerIcon = null;
updatePointerIcon(event);
}
@@ -7496,6 +7507,21 @@
pointerIcon = mView.onResolvePointerIcon(event, pointerIndex);
}
+ if (enablePointerChoreographer()) {
+ if (pointerIcon == null) {
+ pointerIcon = PointerIcon.getSystemIcon(mContext, PointerIcon.TYPE_NOT_SPECIFIED);
+ }
+ if (Objects.equals(mResolvedPointerIcon, pointerIcon)) {
+ return true;
+ }
+ mResolvedPointerIcon = pointerIcon;
+
+ InputManagerGlobal.getInstance()
+ .setPointerIcon(pointerIcon, event.getDisplayId(),
+ event.getDeviceId(), event.getPointerId(0), getInputToken());
+ return true;
+ }
+
final int pointerType = (pointerIcon != null) ?
pointerIcon.getType() : PointerIcon.TYPE_NOT_SPECIFIED;
@@ -7503,34 +7529,18 @@
mPointerIconType = pointerType;
mCustomPointerIcon = null;
if (mPointerIconType != PointerIcon.TYPE_CUSTOM) {
- if (enablePointerChoreographer()) {
- InputManagerGlobal
- .getInstance()
- .setPointerIcon(PointerIcon.getSystemIcon(mContext, pointerType),
- event.getDisplayId(), event.getDeviceId(),
- event.getPointerId(pointerIndex), getInputToken());
- } else {
- InputManagerGlobal
- .getInstance()
- .setPointerIconType(pointerType);
- }
+ InputManagerGlobal
+ .getInstance()
+ .setPointerIconType(pointerType);
return true;
}
}
if (mPointerIconType == PointerIcon.TYPE_CUSTOM &&
!pointerIcon.equals(mCustomPointerIcon)) {
mCustomPointerIcon = pointerIcon;
- if (enablePointerChoreographer()) {
- InputManagerGlobal
- .getInstance()
- .setPointerIcon(mCustomPointerIcon,
- event.getDisplayId(), event.getDeviceId(),
- event.getPointerId(pointerIndex), getInputToken());
- } else {
- InputManagerGlobal
- .getInstance()
- .setCustomPointerIcon(mCustomPointerIcon);
- }
+ InputManagerGlobal
+ .getInstance()
+ .setCustomPointerIcon(mCustomPointerIcon);
}
return true;
}