diff options
author | 2024-05-05 19:17:05 +0800 | |
---|---|---|
committer | 2024-05-09 11:55:45 -0700 | |
commit | 0defadf2c5504374d0e0377aa9accd33907d53cd (patch) | |
tree | b09624bed4cc227a32ab61fe0e305fcc252c9555 | |
parent | 119272db6ddba3b4751aa77d81c90eae7c99d5f9 (diff) |
Use a strongly typed LogicalDisplayId for displayId(1/n)
Currently, we use int32_t for displayId, which is not a safe type, and
it may also lead to misdefinition of types. Here, we introduce
LogicalDisplayId as a strong type for displayId and move all contents
of constants.h into LogicalDisplayId.h.
Bug: 339106983
Test: atest inputflinger_tests
Test: atest InputTests
Test: presubmit
Change-Id: I1c348d7f08524471391b21eaba938501506a7772
Signed-off-by: Linnan Li <lilinnan@xiaomi.corp-partner.google.com>
22 files changed, 179 insertions, 153 deletions
diff --git a/core/jni/android_hardware_display_DisplayViewport.cpp b/core/jni/android_hardware_display_DisplayViewport.cpp index 7f630cb27972..5d7b33e89d19 100644 --- a/core/jni/android_hardware_display_DisplayViewport.cpp +++ b/core/jni/android_hardware_display_DisplayViewport.cpp @@ -59,7 +59,8 @@ status_t android_hardware_display_DisplayViewport_toNative(JNIEnv* env, jobject static const jclass intClass = FindClassOrDie(env, "java/lang/Integer"); static const jmethodID byteValue = env->GetMethodID(intClass, "byteValue", "()B"); - viewport->displayId = env->GetIntField(viewportObj, gDisplayViewportClassInfo.displayId); + viewport->displayId = ui::LogicalDisplayId{ + env->GetIntField(viewportObj, gDisplayViewportClassInfo.displayId)}; viewport->isActive = env->GetBooleanField(viewportObj, gDisplayViewportClassInfo.isActive); jint orientation = env->GetIntField(viewportObj, gDisplayViewportClassInfo.orientation); viewport->orientation = static_cast<ui::Rotation>(orientation); diff --git a/core/jni/android_hardware_input_InputWindowHandle.cpp b/core/jni/android_hardware_input_InputWindowHandle.cpp index bed776836043..69f633420a0d 100644 --- a/core/jni/android_hardware_input_InputWindowHandle.cpp +++ b/core/jni/android_hardware_input_InputWindowHandle.cpp @@ -165,8 +165,8 @@ bool NativeInputWindowHandle::updateInfo() { mInfo.ownerUid = gui::Uid{ static_cast<uid_t>(env->GetIntField(obj, gInputWindowHandleClassInfo.ownerUid))}; mInfo.packageName = getStringField(env, obj, gInputWindowHandleClassInfo.packageName, "<null>"); - mInfo.displayId = env->GetIntField(obj, - gInputWindowHandleClassInfo.displayId); + mInfo.displayId = + ui::LogicalDisplayId{env->GetIntField(obj, gInputWindowHandleClassInfo.displayId)}; jobject inputApplicationHandleObj = env->GetObjectField(obj, gInputWindowHandleClassInfo.inputApplicationHandle); diff --git a/core/jni/android_view_KeyEvent.cpp b/core/jni/android_view_KeyEvent.cpp index ca8752f93e11..06e0d2d3ceaa 100644 --- a/core/jni/android_view_KeyEvent.cpp +++ b/core/jni/android_view_KeyEvent.cpp @@ -135,8 +135,8 @@ KeyEvent android_view_KeyEvent_obtainAsCopy(JNIEnv* env, jobject eventObj) { jlong eventTime = env->GetLongField(eventObj, gKeyEventClassInfo.mEventTime); KeyEvent event; - event.initialize(id, deviceId, source, displayId, *hmac, action, flags, keyCode, scanCode, - metaState, repeatCount, downTime, eventTime); + event.initialize(id, deviceId, source, ui::LogicalDisplayId{displayId}, *hmac, action, flags, + keyCode, scanCode, metaState, repeatCount, downTime, eventTime); return event; } diff --git a/core/jni/android_view_MotionEvent.cpp b/core/jni/android_view_MotionEvent.cpp index 3e3af40a6530..f914bee8da1b 100644 --- a/core/jni/android_view_MotionEvent.cpp +++ b/core/jni/android_view_MotionEvent.cpp @@ -22,7 +22,6 @@ #include <android_runtime/AndroidRuntime.h> #include <android_runtime/Log.h> #include <attestation/HmacKeyManager.h> -#include <gui/constants.h> #include <input/Input.h> #include <log/log.h> #include <nativehelper/JNIHelp.h> @@ -367,8 +366,8 @@ static jlong android_view_MotionEvent_nativeInitialize( ui::Transform transform; transform.set(xOffset, yOffset); ui::Transform identityTransform; - event->initialize(InputEvent::nextId(), deviceId, source, displayId, INVALID_HMAC, action, 0, - flags, edgeFlags, metaState, buttonState, + event->initialize(InputEvent::nextId(), deviceId, source, ui::LogicalDisplayId{displayId}, + INVALID_HMAC, action, 0, flags, edgeFlags, metaState, buttonState, static_cast<MotionClassification>(classification), transform, xPrecision, yPrecision, AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, downTimeNanos, @@ -646,13 +645,13 @@ static void android_view_MotionEvent_nativeSetSource(CRITICAL_JNI_PARAMS_COMMA j static jint android_view_MotionEvent_nativeGetDisplayId(CRITICAL_JNI_PARAMS_COMMA jlong nativePtr) { MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); - return event->getDisplayId(); + return static_cast<jint>(event->getDisplayId().val()); } static void android_view_MotionEvent_nativeSetDisplayId(CRITICAL_JNI_PARAMS_COMMA jlong nativePtr, jint displayId) { MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); - return event->setDisplayId(displayId); + event->setDisplayId(ui::LogicalDisplayId{displayId}); } static jint android_view_MotionEvent_nativeGetAction(CRITICAL_JNI_PARAMS_COMMA jlong nativePtr) { diff --git a/core/jni/android_window_WindowInfosListener.cpp b/core/jni/android_window_WindowInfosListener.cpp index bc69d1e67668..c39d5e20aa1c 100644 --- a/core/jni/android_window_WindowInfosListener.cpp +++ b/core/jni/android_window_WindowInfosListener.cpp @@ -60,7 +60,7 @@ jobject fromDisplayInfo(JNIEnv* env, gui::DisplayInfo displayInfo) { } ScopedLocalRef<jobject> matrixObj(env, AMatrix_newInstance(env, transformValues)); return env->NewObject(gDisplayInfoClassInfo.clazz, gDisplayInfoClassInfo.ctor, - displayInfo.displayId, displayInfo.logicalWidth, + displayInfo.displayId.val(), displayInfo.logicalWidth, displayInfo.logicalHeight, matrixObj.get()); } diff --git a/core/jni/platform/host/HostRuntime.cpp b/core/jni/platform/host/HostRuntime.cpp index 043385513027..bf2fddab3d41 100644 --- a/core/jni/platform/host/HostRuntime.cpp +++ b/core/jni/platform/host/HostRuntime.cpp @@ -329,7 +329,8 @@ static void init_keyboard(JNIEnv* env, const vector<string>& keyboardPaths) { InputDeviceInfo info = InputDeviceInfo(); info.initialize(keyboardId, 0, 0, InputDeviceIdentifier(), - "keyboard " + std::to_string(keyboardId), true, false, 0); + "keyboard " + std::to_string(keyboardId), true, false, + ui::ADISPLAY_ID_DEFAULT); info.setKeyboardType(AINPUT_KEYBOARD_TYPE_ALPHABETIC); info.setKeyCharacterMap(*charMap); diff --git a/libs/input/MouseCursorController.cpp b/libs/input/MouseCursorController.cpp index 6a465442c2b4..5cf5a1d00815 100644 --- a/libs/input/MouseCursorController.cpp +++ b/libs/input/MouseCursorController.cpp @@ -117,7 +117,7 @@ FloatPoint MouseCursorController::getPosition() const { return {mLocked.pointerX, mLocked.pointerY}; } -int32_t MouseCursorController::getDisplayId() const { +ui::LogicalDisplayId MouseCursorController::getDisplayId() const { std::scoped_lock lock(mLock); return mLocked.viewport.displayId; } @@ -467,10 +467,10 @@ void MouseCursorController::startAnimationLocked() REQUIRES(mLock) { std::function<bool(nsecs_t)> func = std::bind(&MouseCursorController::doAnimations, this, _1); /* - * Using -1 for displayId here to avoid removing the callback + * Using ui::ADISPLAY_ID_NONE for displayId here to avoid removing the callback * if a TouchSpotController with the same display is removed. */ - mContext.addAnimationCallback(-1, func); + mContext.addAnimationCallback(ui::ADISPLAY_ID_NONE, func); } } // namespace android diff --git a/libs/input/MouseCursorController.h b/libs/input/MouseCursorController.h index 00dc0854440e..dc7e8ca16c8a 100644 --- a/libs/input/MouseCursorController.h +++ b/libs/input/MouseCursorController.h @@ -47,7 +47,7 @@ public: void move(float deltaX, float deltaY); void setPosition(float x, float y); FloatPoint getPosition() const; - int32_t getDisplayId() const; + ui::LogicalDisplayId getDisplayId() const; void fade(PointerControllerInterface::Transition transition); void unfade(PointerControllerInterface::Transition transition); void setDisplayViewport(const DisplayViewport& viewport, bool getAdditionalMouseResources); diff --git a/libs/input/PointerController.cpp b/libs/input/PointerController.cpp index f97992f7c9d1..cca1b07c3118 100644 --- a/libs/input/PointerController.cpp +++ b/libs/input/PointerController.cpp @@ -142,7 +142,7 @@ std::optional<FloatRect> PointerController::getBounds() const { } void PointerController::move(float deltaX, float deltaY) { - const int32_t displayId = mCursorController.getDisplayId(); + const ui::LogicalDisplayId displayId = mCursorController.getDisplayId(); vec2 transformed; { std::scoped_lock lock(getLock()); @@ -153,7 +153,7 @@ void PointerController::move(float deltaX, float deltaY) { } void PointerController::setPosition(float x, float y) { - const int32_t displayId = mCursorController.getDisplayId(); + const ui::LogicalDisplayId displayId = mCursorController.getDisplayId(); vec2 transformed; { std::scoped_lock lock(getLock()); @@ -164,7 +164,7 @@ void PointerController::setPosition(float x, float y) { } FloatPoint PointerController::getPosition() const { - const int32_t displayId = mCursorController.getDisplayId(); + const ui::LogicalDisplayId displayId = mCursorController.getDisplayId(); const auto p = mCursorController.getPosition(); { std::scoped_lock lock(getLock()); @@ -173,7 +173,7 @@ FloatPoint PointerController::getPosition() const { } } -int32_t PointerController::getDisplayId() const { +ui::LogicalDisplayId PointerController::getDisplayId() const { return mCursorController.getDisplayId(); } @@ -202,7 +202,7 @@ void PointerController::setPresentation(Presentation presentation) { } void PointerController::setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, - BitSet32 spotIdBits, int32_t displayId) { + BitSet32 spotIdBits, ui::LogicalDisplayId displayId) { std::scoped_lock lock(getLock()); std::array<PointerCoords, MAX_POINTERS> outSpotCoords{}; const ui::Transform& transform = getTransformForDisplayLocked(displayId); @@ -286,7 +286,7 @@ void PointerController::setCustomPointerIcon(const SpriteIcon& icon) { mCursorController.setCustomPointerIcon(icon); } -void PointerController::setSkipScreenshot(int32_t displayId, bool skip) { +void PointerController::setSkipScreenshot(ui::LogicalDisplayId displayId, bool skip) { std::scoped_lock lock(getLock()); if (skip) { mLocked.displaysToSkipScreenshot.insert(displayId); @@ -300,14 +300,14 @@ void PointerController::doInactivityTimeout() { } void PointerController::onDisplayViewportsUpdated(const std::vector<DisplayViewport>& viewports) { - std::unordered_set<int32_t> displayIdSet; + std::unordered_set<ui::LogicalDisplayId> displayIdSet; for (const DisplayViewport& viewport : viewports) { displayIdSet.insert(viewport.displayId); } std::scoped_lock lock(getLock()); for (auto it = mLocked.spotControllers.begin(); it != mLocked.spotControllers.end();) { - int32_t displayId = it->first; + ui::LogicalDisplayId displayId = it->first; if (!displayIdSet.count(displayId)) { /* * Ensures that an in-progress animation won't dereference @@ -326,7 +326,8 @@ void PointerController::onDisplayInfosChangedLocked( mLocked.mDisplayInfos = displayInfo; } -const ui::Transform& PointerController::getTransformForDisplayLocked(int displayId) const { +const ui::Transform& PointerController::getTransformForDisplayLocked( + ui::LogicalDisplayId displayId) const { const auto& di = mLocked.mDisplayInfos; auto it = std::find_if(di.begin(), di.end(), [displayId](const gui::DisplayInfo& info) { return info.displayId == displayId; @@ -339,7 +340,8 @@ std::string PointerController::dump() { std::scoped_lock lock(getLock()); dump += StringPrintf(INDENT2 "Presentation: %s\n", ftl::enum_string(mLocked.presentation).c_str()); - dump += StringPrintf(INDENT2 "Pointer Display ID: %" PRIu32 "\n", mLocked.pointerDisplayId); + dump += StringPrintf(INDENT2 "Pointer Display ID: %s\n", + mLocked.pointerDisplayId.toString().c_str()); dump += StringPrintf(INDENT2 "Viewports:\n"); for (const auto& info : mLocked.mDisplayInfos) { info.dump(dump, INDENT3); diff --git a/libs/input/PointerController.h b/libs/input/PointerController.h index eaf34d527396..70e5c2455d81 100644 --- a/libs/input/PointerController.h +++ b/libs/input/PointerController.h @@ -55,18 +55,18 @@ public: void move(float deltaX, float deltaY) override; void setPosition(float x, float y) override; FloatPoint getPosition() const override; - int32_t getDisplayId() const override; + ui::LogicalDisplayId getDisplayId() const override; void fade(Transition transition) override; void unfade(Transition transition) override; void setDisplayViewport(const DisplayViewport& viewport) override; void setPresentation(Presentation presentation) override; void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, - BitSet32 spotIdBits, int32_t displayId) override; + BitSet32 spotIdBits, ui::LogicalDisplayId displayId) override; void clearSpots() override; void updatePointerIcon(PointerIconStyle iconId) override; void setCustomPointerIcon(const SpriteIcon& icon) override; - void setSkipScreenshot(int32_t displayId, bool skip) override; + void setSkipScreenshot(ui::LogicalDisplayId displayId, bool skip) override; virtual void setInactivityTimeout(InactivityTimeout inactivityTimeout); void doInactivityTimeout(); @@ -109,11 +109,11 @@ private: struct Locked { Presentation presentation; - int32_t pointerDisplayId = ADISPLAY_ID_NONE; + ui::LogicalDisplayId pointerDisplayId = ui::ADISPLAY_ID_NONE; std::vector<gui::DisplayInfo> mDisplayInfos; - std::unordered_map<int32_t /* displayId */, TouchSpotController> spotControllers; - std::unordered_set<int32_t /* displayId */> displaysToSkipScreenshot; + std::unordered_map<ui::LogicalDisplayId, TouchSpotController> spotControllers; + std::unordered_set<ui::LogicalDisplayId> displaysToSkipScreenshot; } mLocked GUARDED_BY(getLock()); class DisplayInfoListener : public gui::WindowInfosListener { @@ -132,7 +132,8 @@ private: sp<DisplayInfoListener> mDisplayInfoListener; const WindowListenerUnregisterConsumer mUnregisterWindowInfosListener; - const ui::Transform& getTransformForDisplayLocked(int displayId) const REQUIRES(getLock()); + const ui::Transform& getTransformForDisplayLocked(ui::LogicalDisplayId displayId) const + REQUIRES(getLock()); void clearSpotsLocked() REQUIRES(getLock()); }; @@ -148,7 +149,7 @@ public: void setPresentation(Presentation) override { LOG_ALWAYS_FATAL("Should not be called"); } - void setSpots(const PointerCoords*, const uint32_t*, BitSet32, int32_t) override { + void setSpots(const PointerCoords*, const uint32_t*, BitSet32, ui::LogicalDisplayId) override { LOG_ALWAYS_FATAL("Should not be called"); } void clearSpots() override { @@ -176,7 +177,7 @@ public: FloatPoint getPosition() const override { LOG_ALWAYS_FATAL("Should not be called"); } - int32_t getDisplayId() const override { + ui::LogicalDisplayId getDisplayId() const override { LOG_ALWAYS_FATAL("Should not be called"); } void fade(Transition) override { @@ -212,7 +213,7 @@ public: void setPresentation(Presentation) override { LOG_ALWAYS_FATAL("Should not be called"); } - void setSpots(const PointerCoords*, const uint32_t*, BitSet32, int32_t) override { + void setSpots(const PointerCoords*, const uint32_t*, BitSet32, ui::LogicalDisplayId) override { LOG_ALWAYS_FATAL("Should not be called"); } void clearSpots() override { diff --git a/libs/input/PointerControllerContext.cpp b/libs/input/PointerControllerContext.cpp index 15c35176afce..747eb8e5ad1b 100644 --- a/libs/input/PointerControllerContext.cpp +++ b/libs/input/PointerControllerContext.cpp @@ -138,12 +138,12 @@ int PointerControllerContext::LooperCallback::handleEvent(int /* fd */, int even return 1; // keep the callback } -void PointerControllerContext::addAnimationCallback(int32_t displayId, +void PointerControllerContext::addAnimationCallback(ui::LogicalDisplayId displayId, std::function<bool(nsecs_t)> callback) { mAnimator.addCallback(displayId, callback); } -void PointerControllerContext::removeAnimationCallback(int32_t displayId) { +void PointerControllerContext::removeAnimationCallback(ui::LogicalDisplayId displayId) { mAnimator.removeCallback(displayId); } @@ -161,14 +161,14 @@ void PointerControllerContext::PointerAnimator::initializeDisplayEventReceiver() } } -void PointerControllerContext::PointerAnimator::addCallback(int32_t displayId, +void PointerControllerContext::PointerAnimator::addCallback(ui::LogicalDisplayId displayId, std::function<bool(nsecs_t)> callback) { std::scoped_lock lock(mLock); mLocked.callbacks[displayId] = callback; startAnimationLocked(); } -void PointerControllerContext::PointerAnimator::removeCallback(int32_t displayId) { +void PointerControllerContext::PointerAnimator::removeCallback(ui::LogicalDisplayId displayId) { std::scoped_lock lock(mLock); auto it = mLocked.callbacks.find(displayId); if (it == mLocked.callbacks.end()) { diff --git a/libs/input/PointerControllerContext.h b/libs/input/PointerControllerContext.h index e893c49d80e5..d42214883d3a 100644 --- a/libs/input/PointerControllerContext.h +++ b/libs/input/PointerControllerContext.h @@ -72,12 +72,13 @@ protected: virtual ~PointerControllerPolicyInterface() {} public: - virtual void loadPointerIcon(SpriteIcon* icon, int32_t displayId) = 0; - virtual void loadPointerResources(PointerResources* outResources, int32_t displayId) = 0; + virtual void loadPointerIcon(SpriteIcon* icon, ui::LogicalDisplayId displayId) = 0; + virtual void loadPointerResources(PointerResources* outResources, + ui::LogicalDisplayId displayId) = 0; virtual void loadAdditionalMouseResources( std::map<PointerIconStyle, SpriteIcon>* outResources, std::map<PointerIconStyle, PointerAnimation>* outAnimationResources, - int32_t displayId) = 0; + ui::LogicalDisplayId displayId) = 0; virtual PointerIconStyle getDefaultPointerIconId() = 0; virtual PointerIconStyle getDefaultStylusIconId() = 0; virtual PointerIconStyle getCustomPointerIconId() = 0; @@ -102,7 +103,7 @@ public: nsecs_t getAnimationTime(); - void clearSpotsByDisplay(int32_t displayId); + void clearSpotsByDisplay(ui::LogicalDisplayId displayId); void setHandlerController(std::shared_ptr<PointerController> controller); void setCallbackController(std::shared_ptr<PointerController> controller); @@ -112,8 +113,9 @@ public: void handleDisplayEvents(); - void addAnimationCallback(int32_t displayId, std::function<bool(nsecs_t)> callback); - void removeAnimationCallback(int32_t displayId); + void addAnimationCallback(ui::LogicalDisplayId displayId, + std::function<bool(nsecs_t)> callback); + void removeAnimationCallback(ui::LogicalDisplayId displayId); class MessageHandler : public virtual android::MessageHandler { public: @@ -136,8 +138,8 @@ private: public: PointerAnimator(PointerControllerContext& context); - void addCallback(int32_t displayId, std::function<bool(nsecs_t)> callback); - void removeCallback(int32_t displayId); + void addCallback(ui::LogicalDisplayId displayId, std::function<bool(nsecs_t)> callback); + void removeCallback(ui::LogicalDisplayId displayId); void handleVsyncEvents(); nsecs_t getAnimationTimeLocked(); @@ -148,7 +150,7 @@ private: bool animationPending{false}; nsecs_t animationTime{systemTime(SYSTEM_TIME_MONOTONIC)}; - std::unordered_map<int32_t, std::function<bool(nsecs_t)>> callbacks; + std::unordered_map<ui::LogicalDisplayId, std::function<bool(nsecs_t)>> callbacks; } mLocked GUARDED_BY(mLock); DisplayEventReceiver mDisplayEventReceiver; diff --git a/libs/input/SpriteController.cpp b/libs/input/SpriteController.cpp index 0baa9291f54d..af499390d390 100644 --- a/libs/input/SpriteController.cpp +++ b/libs/input/SpriteController.cpp @@ -19,9 +19,9 @@ #include "SpriteController.h" -#include <log/log.h> -#include <utils/String8.h> +#include <android-base/logging.h> #include <gui/Surface.h> +#include <utils/String8.h> namespace android { @@ -340,13 +340,14 @@ void SpriteController::ensureSurfaceComposerClient() { } } -sp<SurfaceControl> SpriteController::obtainSurface(int32_t width, int32_t height, int32_t displayId, +sp<SurfaceControl> SpriteController::obtainSurface(int32_t width, int32_t height, + ui::LogicalDisplayId displayId, bool hideOnMirrored) { ensureSurfaceComposerClient(); const sp<SurfaceControl> parent = mParentSurfaceProvider(displayId); if (parent == nullptr) { - ALOGE("Failed to get the parent surface for pointers on display %d", displayId); + LOG(ERROR) << "Failed to get the parent surface for pointers on display " << displayId; } int32_t createFlags = ISurfaceComposerClient::eHidden | ISurfaceComposerClient::eCursorWindow; @@ -475,7 +476,7 @@ void SpriteController::SpriteImpl::setTransformationMatrix( } } -void SpriteController::SpriteImpl::setDisplayId(int32_t displayId) { +void SpriteController::SpriteImpl::setDisplayId(ui::LogicalDisplayId displayId) { AutoMutex _l(mController.mLock); if (mLocked.state.displayId != displayId) { diff --git a/libs/input/SpriteController.h b/libs/input/SpriteController.h index fdb15506fd0c..070c90c372ff 100644 --- a/libs/input/SpriteController.h +++ b/libs/input/SpriteController.h @@ -95,7 +95,7 @@ public: virtual void setTransformationMatrix(const SpriteTransformationMatrix& matrix) = 0; /* Sets the id of the display where the sprite should be shown. */ - virtual void setDisplayId(int32_t displayId) = 0; + virtual void setDisplayId(ui::LogicalDisplayId displayId) = 0; /* Sets the flag to hide sprite on mirrored displays. * This will add ISurfaceComposerClient::eSkipScreenshot flag to the sprite. */ @@ -115,7 +115,7 @@ public: */ class SpriteController { public: - using ParentSurfaceProvider = std::function<sp<SurfaceControl>(int /*displayId*/)>; + using ParentSurfaceProvider = std::function<sp<SurfaceControl>(ui::LogicalDisplayId)>; SpriteController(const sp<Looper>& looper, int32_t overlayLayer, ParentSurfaceProvider parent); SpriteController(const SpriteController&) = delete; SpriteController& operator=(const SpriteController&) = delete; @@ -174,7 +174,7 @@ private: int32_t layer{0}; float alpha{1.0f}; SpriteTransformationMatrix transformationMatrix; - int32_t displayId{ADISPLAY_ID_DEFAULT}; + ui::LogicalDisplayId displayId{ui::ADISPLAY_ID_DEFAULT}; sp<SurfaceControl> surfaceControl; int32_t surfaceWidth{0}; @@ -208,7 +208,7 @@ private: virtual void setLayer(int32_t layer); virtual void setAlpha(float alpha); virtual void setTransformationMatrix(const SpriteTransformationMatrix& matrix); - virtual void setDisplayId(int32_t displayId); + virtual void setDisplayId(ui::LogicalDisplayId displayId); virtual void setSkipScreenshot(bool skip); inline const SpriteState& getStateLocked() const { @@ -273,7 +273,7 @@ private: void doDisposeSurfaces(); void ensureSurfaceComposerClient(); - sp<SurfaceControl> obtainSurface(int32_t width, int32_t height, int32_t displayId, + sp<SurfaceControl> obtainSurface(int32_t width, int32_t height, ui::LogicalDisplayId displayId, bool hideOnMirrored); }; diff --git a/libs/input/TouchSpotController.cpp b/libs/input/TouchSpotController.cpp index 530d54129791..7462481f8779 100644 --- a/libs/input/TouchSpotController.cpp +++ b/libs/input/TouchSpotController.cpp @@ -40,7 +40,7 @@ namespace android { // --- Spot --- void TouchSpotController::Spot::updateSprite(const SpriteIcon* icon, float newX, float newY, - int32_t displayId, bool skipScreenshot) { + ui::LogicalDisplayId displayId, bool skipScreenshot) { sprite->setLayer(Sprite::BASE_LAYER_SPOT + id); sprite->setAlpha(alpha); sprite->setTransformationMatrix(SpriteTransformationMatrix(scale, 0.0f, 0.0f, scale)); @@ -69,7 +69,8 @@ void TouchSpotController::Spot::dump(std::string& out, const char* prefix) const // --- TouchSpotController --- -TouchSpotController::TouchSpotController(int32_t displayId, PointerControllerContext& context) +TouchSpotController::TouchSpotController(ui::LogicalDisplayId displayId, + PointerControllerContext& context) : mDisplayId(displayId), mContext(context) { mContext.getPolicy()->loadPointerResources(&mResources, mDisplayId); } @@ -94,7 +95,7 @@ void TouchSpotController::setSpots(const PointerCoords* spotCoords, const uint32 const PointerCoords& c = spotCoords[spotIdToIndex[id]]; ALOGD(" spot %d: position=(%0.3f, %0.3f), pressure=%0.3f, displayId=%" PRId32 ".", id, c.getAxisValue(AMOTION_EVENT_AXIS_X), c.getAxisValue(AMOTION_EVENT_AXIS_Y), - c.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), mDisplayId); + c.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), mDisplayId.id); } #endif @@ -274,7 +275,7 @@ void TouchSpotController::dump(std::string& out, const char* prefix) const { out += prefix; out += "SpotController:\n"; out += prefix; - StringAppendF(&out, INDENT "DisplayId: %" PRId32 "\n", mDisplayId); + StringAppendF(&out, INDENT "DisplayId: %s\n", mDisplayId.toString().c_str()); std::scoped_lock lock(mLock); out += prefix; StringAppendF(&out, INDENT "Animating: %s\n", toString(mLocked.animating)); diff --git a/libs/input/TouchSpotController.h b/libs/input/TouchSpotController.h index 608653c6a2e7..ac37fa430249 100644 --- a/libs/input/TouchSpotController.h +++ b/libs/input/TouchSpotController.h @@ -29,7 +29,7 @@ namespace android { */ class TouchSpotController { public: - TouchSpotController(int32_t displayId, PointerControllerContext& context); + TouchSpotController(ui::LogicalDisplayId displayId, PointerControllerContext& context); ~TouchSpotController(); void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, BitSet32 spotIdBits, bool skipScreenshot); @@ -59,7 +59,7 @@ private: y(0.0f), mLastIcon(nullptr) {} - void updateSprite(const SpriteIcon* icon, float x, float y, int32_t displayId, + void updateSprite(const SpriteIcon* icon, float x, float y, ui::LogicalDisplayId displayId, bool skipScreenshot); void dump(std::string& out, const char* prefix = "") const; @@ -67,7 +67,7 @@ private: const SpriteIcon* mLastIcon; }; - int32_t mDisplayId; + ui::LogicalDisplayId mDisplayId; mutable std::mutex mLock; diff --git a/libs/input/tests/PointerController_test.cpp b/libs/input/tests/PointerController_test.cpp index 3bc0e24b6e2e..7a133801f514 100644 --- a/libs/input/tests/PointerController_test.cpp +++ b/libs/input/tests/PointerController_test.cpp @@ -52,12 +52,13 @@ std::pair<float, float> getHotSpotCoordinatesForType(int32_t type) { class MockPointerControllerPolicyInterface : public PointerControllerPolicyInterface { public: - virtual void loadPointerIcon(SpriteIcon* icon, int32_t displayId) override; - virtual void loadPointerResources(PointerResources* outResources, int32_t displayId) override; + virtual void loadPointerIcon(SpriteIcon* icon, ui::LogicalDisplayId displayId) override; + virtual void loadPointerResources(PointerResources* outResources, + ui::LogicalDisplayId displayId) override; virtual void loadAdditionalMouseResources( std::map<PointerIconStyle, SpriteIcon>* outResources, std::map<PointerIconStyle, PointerAnimation>* outAnimationResources, - int32_t displayId) override; + ui::LogicalDisplayId displayId) override; virtual PointerIconStyle getDefaultPointerIconId() override; virtual PointerIconStyle getDefaultStylusIconId() override; virtual PointerIconStyle getCustomPointerIconId() override; @@ -73,13 +74,13 @@ private: bool additionalMouseResourcesLoaded{false}; }; -void MockPointerControllerPolicyInterface::loadPointerIcon(SpriteIcon* icon, int32_t) { +void MockPointerControllerPolicyInterface::loadPointerIcon(SpriteIcon* icon, ui::LogicalDisplayId) { loadPointerIconForType(icon, CURSOR_TYPE_DEFAULT); pointerIconLoaded = true; } void MockPointerControllerPolicyInterface::loadPointerResources(PointerResources* outResources, - int32_t) { + ui::LogicalDisplayId) { loadPointerIconForType(&outResources->spotHover, CURSOR_TYPE_HOVER); loadPointerIconForType(&outResources->spotTouch, CURSOR_TYPE_TOUCH); loadPointerIconForType(&outResources->spotAnchor, CURSOR_TYPE_ANCHOR); @@ -88,7 +89,7 @@ void MockPointerControllerPolicyInterface::loadPointerResources(PointerResources void MockPointerControllerPolicyInterface::loadAdditionalMouseResources( std::map<PointerIconStyle, SpriteIcon>* outResources, - std::map<PointerIconStyle, PointerAnimation>* outAnimationResources, int32_t) { + std::map<PointerIconStyle, PointerAnimation>* outAnimationResources, ui::LogicalDisplayId) { SpriteIcon icon; PointerAnimation anim; @@ -165,7 +166,7 @@ protected: PointerControllerTest(); ~PointerControllerTest(); - void ensureDisplayViewportIsSet(int32_t displayId = ADISPLAY_ID_DEFAULT); + void ensureDisplayViewportIsSet(ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_DEFAULT); sp<MockSprite> mPointerSprite; sp<MockPointerControllerPolicyInterface> mPolicy; @@ -204,7 +205,7 @@ PointerControllerTest::~PointerControllerTest() { mThread.join(); } -void PointerControllerTest::ensureDisplayViewportIsSet(int32_t displayId) { +void PointerControllerTest::ensureDisplayViewportIsSet(ui::LogicalDisplayId displayId) { DisplayViewport viewport; viewport.displayId = displayId; viewport.logicalRight = 1600; @@ -334,23 +335,23 @@ TEST_F(PointerControllerTest, updatesSkipScreenshotFlagForTouchSpots) { // Update spots to sync state with sprite mPointerController->setSpots(&testSpotCoords, testIdToIndex.cbegin(), testIdBits, - ADISPLAY_ID_DEFAULT); + ui::ADISPLAY_ID_DEFAULT); testing::Mock::VerifyAndClearExpectations(testSpotSprite.get()); // Marking the display to skip screenshot should update sprite as well - mPointerController->setSkipScreenshot(ADISPLAY_ID_DEFAULT, true); + mPointerController->setSkipScreenshot(ui::ADISPLAY_ID_DEFAULT, true); EXPECT_CALL(*testSpotSprite, setSkipScreenshot).With(testing::Args<0>(true)); // Update spots to sync state with sprite mPointerController->setSpots(&testSpotCoords, testIdToIndex.cbegin(), testIdBits, - ADISPLAY_ID_DEFAULT); + ui::ADISPLAY_ID_DEFAULT); testing::Mock::VerifyAndClearExpectations(testSpotSprite.get()); // Reset flag and verify again - mPointerController->setSkipScreenshot(ADISPLAY_ID_DEFAULT, false); + mPointerController->setSkipScreenshot(ui::ADISPLAY_ID_DEFAULT, false); EXPECT_CALL(*testSpotSprite, setSkipScreenshot).With(testing::Args<0>(false)); mPointerController->setSpots(&testSpotCoords, testIdToIndex.cbegin(), testIdBits, - ADISPLAY_ID_DEFAULT); + ui::ADISPLAY_ID_DEFAULT); testing::Mock::VerifyAndClearExpectations(testSpotSprite.get()); } diff --git a/libs/input/tests/mocks/MockSprite.h b/libs/input/tests/mocks/MockSprite.h index 0867221d9eed..21628fb9f72c 100644 --- a/libs/input/tests/mocks/MockSprite.h +++ b/libs/input/tests/mocks/MockSprite.h @@ -33,7 +33,7 @@ public: MOCK_METHOD(void, setLayer, (int32_t), (override)); MOCK_METHOD(void, setAlpha, (float), (override)); MOCK_METHOD(void, setTransformationMatrix, (const SpriteTransformationMatrix&), (override)); - MOCK_METHOD(void, setDisplayId, (int32_t), (override)); + MOCK_METHOD(void, setDisplayId, (ui::LogicalDisplayId), (override)); MOCK_METHOD(void, setSkipScreenshot, (bool), (override)); }; diff --git a/libs/input/tests/mocks/MockSpriteController.h b/libs/input/tests/mocks/MockSpriteController.h index 62f1d65e77a5..9ef6b7c3b480 100644 --- a/libs/input/tests/mocks/MockSpriteController.h +++ b/libs/input/tests/mocks/MockSpriteController.h @@ -27,7 +27,7 @@ class MockSpriteController : public SpriteController { public: MockSpriteController(sp<Looper> looper) - : SpriteController(looper, 0, [](int) { return nullptr; }) {} + : SpriteController(looper, 0, [](ui::LogicalDisplayId) { return nullptr; }) {} ~MockSpriteController() {} MOCK_METHOD(sp<Sprite>, createSprite, (), (override)); diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp index fac08eb78726..7ef49c488435 100644 --- a/services/core/jni/com_android_server_input_InputManagerService.cpp +++ b/services/core/jni/com_android_server_input_InputManagerService.cpp @@ -272,22 +272,23 @@ public: void setDisplayViewports(JNIEnv* env, jobjectArray viewportObjArray); base::Result<std::unique_ptr<InputChannel>> createInputChannel(const std::string& name); - base::Result<std::unique_ptr<InputChannel>> createInputMonitor(int32_t displayId, + base::Result<std::unique_ptr<InputChannel>> createInputMonitor(ui::LogicalDisplayId displayId, const std::string& name, gui::Pid pid); status_t removeInputChannel(const sp<IBinder>& connectionToken); status_t pilferPointers(const sp<IBinder>& token); - void displayRemoved(JNIEnv* env, int32_t displayId); - void setFocusedApplication(JNIEnv* env, int32_t displayId, jobject applicationHandleObj); - void setFocusedDisplay(int32_t displayId); + void displayRemoved(JNIEnv* env, ui::LogicalDisplayId displayId); + void setFocusedApplication(JNIEnv* env, ui::LogicalDisplayId displayId, + jobject applicationHandleObj); + void setFocusedDisplay(ui::LogicalDisplayId displayId); void setMinTimeBetweenUserActivityPokes(int64_t intervalMillis); void setInputDispatchMode(bool enabled, bool frozen); void setSystemUiLightsOut(bool lightsOut); - void setPointerDisplayId(int32_t displayId); + void setPointerDisplayId(ui::LogicalDisplayId displayId); int32_t getMousePointerSpeed(); void setPointerSpeed(int32_t speed); - void setMousePointerAccelerationEnabled(int32_t displayId, bool enabled); + void setMousePointerAccelerationEnabled(ui::LogicalDisplayId displayId, bool enabled); void setTouchpadPointerSpeed(int32_t speed); void setTouchpadNaturalScrollingEnabled(bool enabled); void setTouchpadTapToClickEnabled(bool enabled); @@ -300,13 +301,13 @@ public: void reloadPointerIcons(); void requestPointerCapture(const sp<IBinder>& windowToken, bool enabled); bool setPointerIcon(std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon, - int32_t displayId, DeviceId deviceId, int32_t pointerId, + ui::LogicalDisplayId displayId, DeviceId deviceId, int32_t pointerId, const sp<IBinder>& inputToken); - void setPointerIconVisibility(int32_t displayId, bool visible); + void setPointerIconVisibility(ui::LogicalDisplayId displayId, bool visible); void setMotionClassifierEnabled(bool enabled); std::optional<std::string> getBluetoothAddress(int32_t deviceId); void setStylusButtonMotionEventsEnabled(bool enabled); - FloatPoint getMouseCursorPosition(int32_t displayId); + FloatPoint getMouseCursorPosition(ui::LogicalDisplayId displayId); void setStylusPointerIconEnabled(bool enabled); void setInputMethodConnectionIsActive(bool isActive); @@ -325,7 +326,7 @@ public: void notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) override; bool isInputMethodConnectionActive() override; std::optional<DisplayViewport> getPointerViewportForAssociatedDisplay( - int32_t associatedDisplayId) override; + ui::LogicalDisplayId associatedDisplayId) override; /* --- InputDispatcherPolicyInterface implementation --- */ @@ -348,13 +349,15 @@ public: void notifyVibratorState(int32_t deviceId, bool isOn) override; bool filterInputEvent(const InputEvent& inputEvent, uint32_t policyFlags) override; void interceptKeyBeforeQueueing(const KeyEvent& keyEvent, uint32_t& policyFlags) override; - void interceptMotionBeforeQueueing(int32_t displayId, uint32_t source, int32_t action, - nsecs_t when, uint32_t& policyFlags) override; + void interceptMotionBeforeQueueing(ui::LogicalDisplayId displayId, uint32_t source, + int32_t action, nsecs_t when, + uint32_t& policyFlags) override; nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>& token, const KeyEvent& keyEvent, uint32_t policyFlags) override; std::optional<KeyEvent> dispatchUnhandledKey(const sp<IBinder>& token, const KeyEvent& keyEvent, uint32_t policyFlags) override; - void pokeUserActivity(nsecs_t eventTime, int32_t eventType, int32_t displayId) override; + void pokeUserActivity(nsecs_t eventTime, int32_t eventType, + ui::LogicalDisplayId displayId) override; void onPointerDownOutsideFocus(const sp<IBinder>& touchedToken) override; void setPointerCapture(const PointerCaptureRequest& request) override; void notifyDropWindow(const sp<IBinder>& token, float x, float y) override; @@ -363,11 +366,13 @@ public: /* --- PointerControllerPolicyInterface implementation --- */ - virtual void loadPointerIcon(SpriteIcon* icon, int32_t displayId); - virtual void loadPointerResources(PointerResources* outResources, int32_t displayId); + virtual void loadPointerIcon(SpriteIcon* icon, ui::LogicalDisplayId displayId); + virtual void loadPointerResources(PointerResources* outResources, + ui::LogicalDisplayId displayId); virtual void loadAdditionalMouseResources( std::map<PointerIconStyle, SpriteIcon>* outResources, - std::map<PointerIconStyle, PointerAnimation>* outAnimationResources, int32_t displayId); + std::map<PointerIconStyle, PointerAnimation>* outAnimationResources, + ui::LogicalDisplayId displayId); virtual PointerIconStyle getDefaultPointerIconId(); virtual PointerIconStyle getDefaultStylusIconId(); virtual PointerIconStyle getCustomPointerIconId(); @@ -375,7 +380,8 @@ public: /* --- PointerChoreographerPolicyInterface implementation --- */ std::shared_ptr<PointerControllerInterface> createPointerController( PointerControllerInterface::ControllerType type) override; - void notifyPointerDisplayIdChanged(int32_t displayId, const FloatPoint& position) override; + void notifyPointerDisplayIdChanged(ui::LogicalDisplayId displayId, + const FloatPoint& position) override; /* --- InputFilterPolicyInterface implementation --- */ void notifyStickyModifierStateChanged(uint32_t modifierState, @@ -399,7 +405,7 @@ private: int32_t pointerSpeed{0}; // Displays on which its associated mice will have pointer acceleration disabled. - std::set<int32_t> displaysWithMousePointerAccelerationDisabled{}; + std::set<ui::LogicalDisplayId> displaysWithMousePointerAccelerationDisabled{}; // True if pointer gestures are enabled. bool pointerGesturesEnabled{true}; @@ -417,7 +423,7 @@ private: std::set<int32_t> disabledInputDevices{}; // Associated Pointer controller display. - int32_t pointerDisplayId{ADISPLAY_ID_DEFAULT}; + ui::LogicalDisplayId pointerDisplayId{ui::ADISPLAY_ID_DEFAULT}; // True if stylus button reporting through motion events is enabled. bool stylusButtonMotionEventsEnabled{true}; @@ -450,7 +456,7 @@ private: void updateInactivityTimeoutLocked(); void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags); void ensureSpriteControllerLocked(); - sp<SurfaceControl> getParentSurfaceForPointers(int displayId); + sp<SurfaceControl> getParentSurfaceForPointers(ui::LogicalDisplayId displayId); static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName); template <typename T> std::unordered_map<std::string, T> readMapFromInterleavedJavaArray( @@ -459,7 +465,7 @@ private: void forEachPointerControllerLocked(std::function<void(PointerController&)> apply) REQUIRES(mLock); - PointerIcon loadPointerIcon(JNIEnv* env, int32_t displayId, PointerIconStyle type); + PointerIcon loadPointerIcon(JNIEnv* env, ui::LogicalDisplayId displayId, PointerIconStyle type); static inline JNIEnv* jniEnv() { return AndroidRuntime::getJNIEnv(); } }; @@ -490,7 +496,9 @@ void NativeInputManager::dump(std::string& dump) { toString(mLocked.systemUiLightsOut)); dump += StringPrintf(INDENT "Pointer Speed: %" PRId32 "\n", mLocked.pointerSpeed); dump += StringPrintf(INDENT "Display with Mouse Pointer Acceleration Disabled: %s\n", - dumpSet(mLocked.displaysWithMousePointerAccelerationDisabled).c_str()); + dumpSet(mLocked.displaysWithMousePointerAccelerationDisabled, + streamableToString) + .c_str()); dump += StringPrintf(INDENT "Pointer Gestures Enabled: %s\n", toString(mLocked.pointerGesturesEnabled)); dump += StringPrintf(INDENT "Pointer Capture: %s, seq=%" PRIu32 "\n", @@ -552,7 +560,7 @@ base::Result<std::unique_ptr<InputChannel>> NativeInputManager::createInputChann } base::Result<std::unique_ptr<InputChannel>> NativeInputManager::createInputMonitor( - int32_t displayId, const std::string& name, gui::Pid pid) { + ui::LogicalDisplayId displayId, const std::string& name, gui::Pid pid) { ATRACE_CALL(); return mInputManager->getDispatcher().createInputMonitor(displayId, name, pid); } @@ -735,7 +743,7 @@ void NativeInputManager::forEachPointerControllerLocked( } } -PointerIcon NativeInputManager::loadPointerIcon(JNIEnv* env, int32_t displayId, +PointerIcon NativeInputManager::loadPointerIcon(JNIEnv* env, ui::LogicalDisplayId displayId, PointerIconStyle type) { if (type == PointerIconStyle::TYPE_CUSTOM) { LOG(FATAL) << __func__ << ": Cannot load non-system icon type"; @@ -766,7 +774,7 @@ std::shared_ptr<PointerControllerInterface> NativeInputManager::createPointerCon return pc; } -void NativeInputManager::notifyPointerDisplayIdChanged(int32_t pointerDisplayId, +void NativeInputManager::notifyPointerDisplayIdChanged(ui::LogicalDisplayId pointerDisplayId, const FloatPoint& position) { // Notify the Reader so that devices can be reconfigured. { // acquire lock @@ -775,7 +783,7 @@ void NativeInputManager::notifyPointerDisplayIdChanged(int32_t pointerDisplayId, return; } mLocked.pointerDisplayId = pointerDisplayId; - ALOGI("%s: pointer displayId set to: %d", __func__, pointerDisplayId); + ALOGI("%s: pointer displayId set to: %s", __func__, pointerDisplayId.toString().c_str()); } // release lock mInputManager->getReader().requestRefreshConfiguration( InputReaderConfiguration::Change::DISPLAY_INFO); @@ -795,7 +803,7 @@ void NativeInputManager::notifyStickyModifierStateChanged(uint32_t modifierState checkAndClearExceptionFromCallback(env, "notifyStickyModifierStateChanged"); } -sp<SurfaceControl> NativeInputManager::getParentSurfaceForPointers(int displayId) { +sp<SurfaceControl> NativeInputManager::getParentSurfaceForPointers(ui::LogicalDisplayId displayId) { JNIEnv* env = jniEnv(); jlong nativeSurfaceControlPtr = env->CallLongMethod(mServiceObj, gServiceClassInfo.getParentSurfaceForPointers, @@ -817,9 +825,10 @@ void NativeInputManager::ensureSpriteControllerLocked() REQUIRES(mLock) { layer = -1; } mLocked.spriteController = - std::make_shared<SpriteController>(mLooper, layer, [this](int displayId) { - return getParentSurfaceForPointers(displayId); - }); + std::make_shared<SpriteController>(mLooper, layer, + [this](ui::LogicalDisplayId displayId) { + return getParentSurfaceForPointers(displayId); + }); // The SpriteController needs to be shared pointer because the handler callback needs to hold // a weak reference so that we can avoid racy conditions when the controller is being destroyed. mLocked.spriteController->setHandlerController(mLocked.spriteController); @@ -1021,8 +1030,7 @@ void NativeInputManager::notifyInputChannelBroken(const sp<IBinder>& token) { jobject tokenObj = javaObjectForIBinder(env, token); if (tokenObj) { - env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken, - tokenObj); + env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken, tokenObj); checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken"); } } @@ -1108,12 +1116,12 @@ void NativeInputManager::notifyVibratorState(int32_t deviceId, bool isOn) { checkAndClearExceptionFromCallback(env, "notifyVibratorState"); } -void NativeInputManager::displayRemoved(JNIEnv* env, int32_t displayId) { +void NativeInputManager::displayRemoved(JNIEnv* env, ui::LogicalDisplayId displayId) { mInputManager->getDispatcher().displayRemoved(displayId); } -void NativeInputManager::setFocusedApplication(JNIEnv* env, int32_t displayId, - jobject applicationHandleObj) { +void NativeInputManager::setFocusedApplication(JNIEnv* env, ui::LogicalDisplayId displayId, + jobject applicationHandleObj) { if (!applicationHandleObj) { return; } @@ -1123,7 +1131,7 @@ void NativeInputManager::setFocusedApplication(JNIEnv* env, int32_t displayId, mInputManager->getDispatcher().setFocusedApplication(displayId, applicationHandle); } -void NativeInputManager::setFocusedDisplay(int32_t displayId) { +void NativeInputManager::setFocusedDisplay(ui::LogicalDisplayId displayId) { mInputManager->getDispatcher().setFocusedDisplay(displayId); } @@ -1151,7 +1159,7 @@ void NativeInputManager::updateInactivityTimeoutLocked() REQUIRES(mLock) { }); } -void NativeInputManager::setPointerDisplayId(int32_t displayId) { +void NativeInputManager::setPointerDisplayId(ui::LogicalDisplayId displayId) { mInputManager->getChoreographer().setDefaultMouseDisplayId(displayId); } @@ -1176,7 +1184,8 @@ void NativeInputManager::setPointerSpeed(int32_t speed) { InputReaderConfiguration::Change::POINTER_SPEED); } -void NativeInputManager::setMousePointerAccelerationEnabled(int32_t displayId, bool enabled) { +void NativeInputManager::setMousePointerAccelerationEnabled(ui::LogicalDisplayId displayId, + bool enabled) { { // acquire lock std::scoped_lock _l(mLock); @@ -1186,8 +1195,8 @@ void NativeInputManager::setMousePointerAccelerationEnabled(int32_t displayId, b return; } - ALOGI("Setting mouse pointer acceleration to %s on display %d", toString(enabled), - displayId); + ALOGI("Setting mouse pointer acceleration to %s on display %s", toString(enabled), + displayId.toString().c_str()); if (enabled) { mLocked.displaysWithMousePointerAccelerationDisabled.erase(displayId); } else { @@ -1326,8 +1335,9 @@ void NativeInputManager::reloadPointerIcons() { } bool NativeInputManager::setPointerIcon( - std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon, int32_t displayId, - DeviceId deviceId, int32_t pointerId, const sp<IBinder>& inputToken) { + std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon, + ui::LogicalDisplayId displayId, DeviceId deviceId, int32_t pointerId, + const sp<IBinder>& inputToken) { if (!mInputManager->getDispatcher().isPointerInWindow(inputToken, displayId, deviceId, pointerId)) { LOG(WARNING) << "Attempted to change the pointer icon for deviceId " << deviceId @@ -1339,7 +1349,7 @@ bool NativeInputManager::setPointerIcon( return mInputManager->getChoreographer().setPointerIcon(std::move(icon), displayId, deviceId); } -void NativeInputManager::setPointerIconVisibility(int32_t displayId, bool visible) { +void NativeInputManager::setPointerIconVisibility(ui::LogicalDisplayId displayId, bool visible) { mInputManager->getChoreographer().setPointerIconVisibility(displayId, visible); } @@ -1394,7 +1404,7 @@ bool NativeInputManager::isInputMethodConnectionActive() { } std::optional<DisplayViewport> NativeInputManager::getPointerViewportForAssociatedDisplay( - int32_t associatedDisplayId) { + ui::LogicalDisplayId associatedDisplayId) { return mInputManager->getChoreographer().getViewportForPointerDevice(associatedDisplayId); } @@ -1469,9 +1479,9 @@ void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent& keyEvent, handleInterceptActions(wmActions, when, /*byref*/ policyFlags); } -void NativeInputManager::interceptMotionBeforeQueueing(int32_t displayId, uint32_t source, - int32_t action, nsecs_t when, - uint32_t& policyFlags) { +void NativeInputManager::interceptMotionBeforeQueueing(ui::LogicalDisplayId displayId, + uint32_t source, int32_t action, + nsecs_t when, uint32_t& policyFlags) { ATRACE_CALL(); // Policy: // - Ignore untrusted events and pass them along. @@ -1590,7 +1600,8 @@ std::optional<KeyEvent> NativeInputManager::dispatchUnhandledKey(const sp<IBinde return fallbackEvent; } -void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType, int32_t displayId) { +void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType, + ui::LogicalDisplayId displayId) { ATRACE_CALL(); android_server_PowerManagerService_userActivity(eventTime, eventType, displayId); } @@ -1621,13 +1632,14 @@ void NativeInputManager::setPointerCapture(const PointerCaptureRequest& request) InputReaderConfiguration::Change::POINTER_CAPTURE); } -void NativeInputManager::loadPointerIcon(SpriteIcon* icon, int32_t displayId) { +void NativeInputManager::loadPointerIcon(SpriteIcon* icon, ui::LogicalDisplayId displayId) { ATRACE_CALL(); JNIEnv* env = jniEnv(); *icon = toSpriteIcon(loadPointerIcon(env, displayId, PointerIconStyle::TYPE_ARROW)); } -void NativeInputManager::loadPointerResources(PointerResources* outResources, int32_t displayId) { +void NativeInputManager::loadPointerResources(PointerResources* outResources, + ui::LogicalDisplayId displayId) { ATRACE_CALL(); JNIEnv* env = jniEnv(); @@ -1641,7 +1653,8 @@ void NativeInputManager::loadPointerResources(PointerResources* outResources, in void NativeInputManager::loadAdditionalMouseResources( std::map<PointerIconStyle, SpriteIcon>* outResources, - std::map<PointerIconStyle, PointerAnimation>* outAnimationResources, int32_t displayId) { + std::map<PointerIconStyle, PointerAnimation>* outAnimationResources, + ui::LogicalDisplayId displayId) { ATRACE_CALL(); JNIEnv* env = jniEnv(); @@ -1708,7 +1721,7 @@ void NativeInputManager::setStylusButtonMotionEventsEnabled(bool enabled) { InputReaderConfiguration::Change::STYLUS_BUTTON_REPORTING); } -FloatPoint NativeInputManager::getMouseCursorPosition(int32_t displayId) { +FloatPoint NativeInputManager::getMouseCursorPosition(ui::LogicalDisplayId displayId) { return mInputManager->getChoreographer().getMouseCursorPosition(displayId); } @@ -1874,7 +1887,7 @@ static jobject nativeCreateInputMonitor(JNIEnv* env, jobject nativeImplObj, jint jstring nameObj, jint pid) { NativeInputManager* im = getNativeInputManager(env, nativeImplObj); - if (displayId == ADISPLAY_ID_NONE) { + if (displayId == ui::ADISPLAY_ID_NONE.val()) { std::string message = "InputChannel used as a monitor must be associated with a display"; jniThrowRuntimeException(env, message.c_str()); return nullptr; @@ -1884,7 +1897,7 @@ static jobject nativeCreateInputMonitor(JNIEnv* env, jobject nativeImplObj, jint std::string name = nameChars.c_str(); base::Result<std::unique_ptr<InputChannel>> inputChannel = - im->createInputMonitor(displayId, name, gui::Pid{pid}); + im->createInputMonitor(ui::LogicalDisplayId{displayId}, name, gui::Pid{pid}); if (!inputChannel.ok()) { std::string message = inputChannel.error().message(); @@ -1931,7 +1944,8 @@ static jboolean nativeSetInTouchMode(JNIEnv* env, jobject nativeImplObj, jboolea return im->getInputManager()->getDispatcher().setInTouchMode(inTouchMode, gui::Pid{pid}, gui::Uid{static_cast<uid_t>(uid)}, - hasPermission, displayId); + hasPermission, + ui::LogicalDisplayId{displayId}); } static void nativeSetMaximumObscuringOpacityForTouch(JNIEnv* env, jobject nativeImplObj, @@ -2023,20 +2037,20 @@ static void nativeToggleCapsLock(JNIEnv* env, jobject nativeImplObj, jint device static void nativeDisplayRemoved(JNIEnv* env, jobject nativeImplObj, jint displayId) { NativeInputManager* im = getNativeInputManager(env, nativeImplObj); - im->displayRemoved(env, displayId); + im->displayRemoved(env, ui::LogicalDisplayId{displayId}); } static void nativeSetFocusedApplication(JNIEnv* env, jobject nativeImplObj, jint displayId, jobject applicationHandleObj) { NativeInputManager* im = getNativeInputManager(env, nativeImplObj); - im->setFocusedApplication(env, displayId, applicationHandleObj); + im->setFocusedApplication(env, ui::LogicalDisplayId{displayId}, applicationHandleObj); } static void nativeSetFocusedDisplay(JNIEnv* env, jobject nativeImplObj, jint displayId) { NativeInputManager* im = getNativeInputManager(env, nativeImplObj); - im->setFocusedDisplay(displayId); + im->setFocusedDisplay(ui::LogicalDisplayId{displayId}); } static void nativeSetUserActivityPokeInterval(JNIEnv* env, jobject nativeImplObj, @@ -2092,8 +2106,8 @@ static jboolean nativeTransferTouchOnDisplay(JNIEnv* env, jobject nativeImplObj, NativeInputManager* im = getNativeInputManager(env, nativeImplObj); if (im->getInputManager()->getDispatcher().transferTouchOnDisplay(destChannelToken, - static_cast<int32_t>( - displayId))) { + ui::LogicalDisplayId{ + displayId})) { return JNI_TRUE; } else { return JNI_FALSE; @@ -2116,7 +2130,7 @@ static void nativeSetMousePointerAccelerationEnabled(JNIEnv* env, jobject native jint displayId, jboolean enabled) { NativeInputManager* im = getNativeInputManager(env, nativeImplObj); - im->setMousePointerAccelerationEnabled(displayId, enabled); + im->setMousePointerAccelerationEnabled(ui::LogicalDisplayId{displayId}, enabled); } static void nativeSetTouchpadPointerSpeed(JNIEnv* env, jobject nativeImplObj, jint speed) { @@ -2494,7 +2508,7 @@ static bool nativeSetPointerIcon(JNIEnv* env, jobject nativeImplObj, jobject ico icon = pointerIcon.style; } - return im->setPointerIcon(std::move(icon), displayId, deviceId, pointerId, + return im->setPointerIcon(std::move(icon), ui::LogicalDisplayId{displayId}, deviceId, pointerId, ibinderForJavaObject(env, inputTokenObj)); } @@ -2502,13 +2516,14 @@ static void nativeSetPointerIconVisibility(JNIEnv* env, jobject nativeImplObj, j jboolean visible) { NativeInputManager* im = getNativeInputManager(env, nativeImplObj); - im->setPointerIconVisibility(displayId, visible); + im->setPointerIconVisibility(ui::LogicalDisplayId{displayId}, visible); } static jboolean nativeCanDispatchToDisplay(JNIEnv* env, jobject nativeImplObj, jint deviceId, jint displayId) { NativeInputManager* im = getNativeInputManager(env, nativeImplObj); - return im->getInputManager()->getReader().canDispatchToDisplay(deviceId, displayId); + return im->getInputManager()->getReader().canDispatchToDisplay(deviceId, + ui::LogicalDisplayId{displayId}); } static void nativeNotifyPortAssociationsChanged(JNIEnv* env, jobject nativeImplObj) { @@ -2520,8 +2535,9 @@ static void nativeNotifyPortAssociationsChanged(JNIEnv* env, jobject nativeImplO static void nativeSetDisplayEligibilityForPointerCapture(JNIEnv* env, jobject nativeImplObj, jint displayId, jboolean isEligible) { NativeInputManager* im = getNativeInputManager(env, nativeImplObj); - im->getInputManager()->getDispatcher().setDisplayEligibilityForPointerCapture(displayId, - isEligible); + im->getInputManager() + ->getDispatcher() + .setDisplayEligibilityForPointerCapture(ui::LogicalDisplayId{displayId}, isEligible); } static void nativeChangeUniqueIdAssociation(JNIEnv* env, jobject nativeImplObj) { @@ -2657,7 +2673,7 @@ static void nativeCancelCurrentTouch(JNIEnv* env, jobject nativeImplObj) { static void nativeSetPointerDisplayId(JNIEnv* env, jobject nativeImplObj, jint displayId) { NativeInputManager* im = getNativeInputManager(env, nativeImplObj); - im->setPointerDisplayId(displayId); + im->setPointerDisplayId(ui::LogicalDisplayId{displayId}); } static jstring nativeGetBluetoothAddress(JNIEnv* env, jobject nativeImplObj, jint deviceId) { @@ -2675,7 +2691,7 @@ static void nativeSetStylusButtonMotionEventsEnabled(JNIEnv* env, jobject native static jfloatArray nativeGetMouseCursorPosition(JNIEnv* env, jobject nativeImplObj, jint displayId) { NativeInputManager* im = getNativeInputManager(env, nativeImplObj); - const auto p = im->getMouseCursorPosition(displayId); + const auto p = im->getMouseCursorPosition(ui::LogicalDisplayId{displayId}); const std::array<float, 2> arr = {{p.x, p.y}}; jfloatArray outArr = env->NewFloatArray(2); env->SetFloatArrayRegion(outArr, 0, arr.size(), arr.data()); diff --git a/services/core/jni/com_android_server_power_PowerManagerService.cpp b/services/core/jni/com_android_server_power_PowerManagerService.cpp index d0b290c05ee9..073396848c55 100644 --- a/services/core/jni/com_android_server_power_PowerManagerService.cpp +++ b/services/core/jni/com_android_server_power_PowerManagerService.cpp @@ -99,7 +99,7 @@ static bool setPowerMode(Mode mode, bool enabled) { } void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t eventType, - int32_t displayId) { + ui::LogicalDisplayId displayId) { if (gPowerManagerServiceObj) { // Throttle calls into user activity by event type. // We're a little conservative about argument checking here in case the caller @@ -124,8 +124,8 @@ void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t JNIEnv* env = AndroidRuntime::getJNIEnv(); env->CallVoidMethod(gPowerManagerServiceObj, - gPowerManagerServiceClassInfo.userActivityFromNative, - nanoseconds_to_milliseconds(eventTime), eventType, displayId, 0); + gPowerManagerServiceClassInfo.userActivityFromNative, + nanoseconds_to_milliseconds(eventTime), eventType, displayId.val(), 0); checkAndClearExceptionFromCallback(env, "userActivityFromNative"); } } diff --git a/services/core/jni/com_android_server_power_PowerManagerService.h b/services/core/jni/com_android_server_power_PowerManagerService.h index 36aaceb029c7..ed7fa7c39bd3 100644 --- a/services/core/jni/com_android_server_power_PowerManagerService.h +++ b/services/core/jni/com_android_server_power_PowerManagerService.h @@ -19,6 +19,7 @@ #include <nativehelper/JNIHelp.h> #include <powermanager/PowerManager.h> +#include <ui/LogicalDisplayId.h> #include <utils/Timers.h> #include "jni.h" @@ -26,7 +27,7 @@ namespace android { extern void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t eventType, - int32_t displayId); + ui::LogicalDisplayId displayId); } // namespace android |