Separate default pointer for mouse and stylus (frameworks/base part)

PointerIcon.TYPE_NOT_SPECIFIED will be used for requesting default
pointer.

For the type, MouseCursorController will decide whether to show mouse or
stylus icon, based on the active source.

Need complement: the resource for default stylus icon should be added.

Test: Manual Test(hover pointer on handwriting area)
Bug: b/215436642
Change-Id: I6a337cb69bea57427f676e561900802270d206ae
diff --git a/libs/input/MouseCursorController.cpp b/libs/input/MouseCursorController.cpp
index a835167..24cfc9d 100644
--- a/libs/input/MouseCursorController.cpp
+++ b/libs/input/MouseCursorController.cpp
@@ -38,6 +38,8 @@
       : mContext(context) {
     std::scoped_lock lock(mLock);
 
+    mLocked.stylusHoverMode = false;
+
     mLocked.animationFrameIndex = 0;
     mLocked.lastFrameUpdatedTime = 0;
 
@@ -47,7 +49,8 @@
     mLocked.pointerAlpha = 0.0f; // pointer is initially faded
     mLocked.pointerSprite = mContext.getSpriteController()->createSprite();
     mLocked.updatePointerIcon = false;
-    mLocked.requestedPointerType = mContext.getPolicy()->getDefaultPointerIconId();
+    mLocked.requestedPointerType = PointerIconStyle::TYPE_NOT_SPECIFIED;
+    mLocked.resolvedPointerType = PointerIconStyle::TYPE_NOT_SPECIFIED;
 
     mLocked.resourcesLoaded = false;
 
@@ -184,6 +187,15 @@
     }
 }
 
+void MouseCursorController::setStylusHoverMode(bool stylusHoverMode) {
+    std::scoped_lock lock(mLock);
+
+    if (mLocked.stylusHoverMode != stylusHoverMode) {
+        mLocked.stylusHoverMode = stylusHoverMode;
+        mLocked.updatePointerIcon = true;
+    }
+}
+
 void MouseCursorController::reloadPointerResources(bool getAdditionalMouseResources) {
     std::scoped_lock lock(mLock);
 
@@ -339,7 +351,7 @@
 
 bool MouseCursorController::doBitmapAnimationLocked(nsecs_t timestamp) REQUIRES(mLock) {
     std::map<PointerIconStyle, PointerAnimation>::const_iterator iter =
-            mLocked.animationResources.find(mLocked.requestedPointerType);
+            mLocked.animationResources.find(mLocked.resolvedPointerType);
     if (iter == mLocked.animationResources.end()) {
         return false;
     }
@@ -381,14 +393,23 @@
     }
 
     if (mLocked.updatePointerIcon) {
-        if (mLocked.requestedPointerType == mContext.getPolicy()->getDefaultPointerIconId()) {
+        mLocked.resolvedPointerType = mLocked.requestedPointerType;
+        const PointerIconStyle defaultPointerIconId =
+                mContext.getPolicy()->getDefaultPointerIconId();
+        if (mLocked.resolvedPointerType == PointerIconStyle::TYPE_NOT_SPECIFIED) {
+            mLocked.resolvedPointerType = mLocked.stylusHoverMode
+                    ? mContext.getPolicy()->getDefaultStylusIconId()
+                    : defaultPointerIconId;
+        }
+
+        if (mLocked.resolvedPointerType == defaultPointerIconId) {
             mLocked.pointerSprite->setIcon(mLocked.pointerIcon);
         } else {
             std::map<PointerIconStyle, SpriteIcon>::const_iterator iter =
-                    mLocked.additionalMouseResources.find(mLocked.requestedPointerType);
+                    mLocked.additionalMouseResources.find(mLocked.resolvedPointerType);
             if (iter != mLocked.additionalMouseResources.end()) {
                 std::map<PointerIconStyle, PointerAnimation>::const_iterator anim_iter =
-                        mLocked.animationResources.find(mLocked.requestedPointerType);
+                        mLocked.animationResources.find(mLocked.resolvedPointerType);
                 if (anim_iter != mLocked.animationResources.end()) {
                     mLocked.animationFrameIndex = 0;
                     mLocked.lastFrameUpdatedTime = systemTime(SYSTEM_TIME_MONOTONIC);
@@ -396,7 +417,7 @@
                 }
                 mLocked.pointerSprite->setIcon(iter->second);
             } else {
-                ALOGW("Can't find the resource for icon id %d", mLocked.requestedPointerType);
+                ALOGW("Can't find the resource for icon id %d", mLocked.resolvedPointerType);
                 mLocked.pointerSprite->setIcon(mLocked.pointerIcon);
             }
         }