diff options
140 files changed, 1853 insertions, 1914 deletions
diff --git a/cmds/cmd/fuzzer/Android.bp b/cmds/cmd/fuzzer/Android.bp index a65f6deb8a..faf461abc4 100644 --- a/cmds/cmd/fuzzer/Android.bp +++ b/cmds/cmd/fuzzer/Android.bp @@ -42,5 +42,13 @@ cc_fuzz { "android-media-fuzzing-reports@google.com", ], componentid: 155276, + hotlists: [ + "4593311", + ], + description: "The fuzzer targets the APIs of libcmd", + vector: "local_no_privileges_required", + service_privilege: "constrained", + users: "multi_user", + fuzzed_code_usage: "shipped", }, } diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index baf8e424c3..1403b77652 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -3361,8 +3361,7 @@ void Dumpstate::MaybeSnapshotUiTraces() { "WMShell", "protolog", "save-for-bugreport"}, CommandOptions::WithTimeout(10).Always().DropRoot().RedirectStderr().Build()); - // Currently WindowManagerService and InputMethodManagerSerivice support WinScope protocol. - for (const auto& service : {"input_method", "window"}) { + for (const auto& service : {"input_method", "window", "window shell"}) { RunCommand( // Empty name because it's not intended to be classified as a bugreport section. // Actual tracing files can be found in "/data/misc/wmtrace/" in the bugreport. diff --git a/cmds/servicemanager/Android.bp b/cmds/servicemanager/Android.bp index 1386660eb6..d73a30bf9b 100644 --- a/cmds/servicemanager/Android.bp +++ b/cmds/servicemanager/Android.bp @@ -72,6 +72,7 @@ cc_binary { cc_test { name: "servicemanager_test", + host_supported: true, test_suites: ["device-tests"], defaults: ["servicemanager_defaults"], srcs: [ diff --git a/cmds/servicemanager/ServiceManager.cpp b/cmds/servicemanager/ServiceManager.cpp index d4ce46686d..cc8ac0ab2e 100644 --- a/cmds/servicemanager/ServiceManager.cpp +++ b/cmds/servicemanager/ServiceManager.cpp @@ -337,26 +337,26 @@ Status ServiceManager::addService(const std::string& name, const sp<IBinder>& bi auto ctx = mAccess->getCallingContext(); if (multiuser_get_app_id(ctx.uid) >= AID_APP) { - return Status::fromExceptionCode(Status::EX_SECURITY, "App UIDs cannot add services"); + return Status::fromExceptionCode(Status::EX_SECURITY, "App UIDs cannot add services."); } if (!mAccess->canAdd(ctx, name)) { - return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denial"); + return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); } if (binder == nullptr) { - return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT, "Null binder"); + return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT, "Null binder."); } if (!isValidServiceName(name)) { ALOGE("Invalid service name: %s", name.c_str()); - return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT, "Invalid service name"); + return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT, "Invalid service name."); } #ifndef VENDORSERVICEMANAGER if (!meetsDeclarationRequirements(binder, name)) { // already logged - return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT, "VINTF declaration error"); + return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT, "VINTF declaration error."); } #endif // !VENDORSERVICEMANAGER @@ -368,7 +368,7 @@ Status ServiceManager::addService(const std::string& name, const sp<IBinder>& bi if (binder->remoteBinder() != nullptr && binder->linkToDeath(sp<ServiceManager>::fromExisting(this)) != OK) { ALOGE("Could not linkToDeath when adding %s", name.c_str()); - return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, "linkToDeath failure"); + return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, "Couldn't linkToDeath."); } auto it = mNameToService.find(name); @@ -422,7 +422,7 @@ Status ServiceManager::addService(const std::string& name, const sp<IBinder>& bi Status ServiceManager::listServices(int32_t dumpPriority, std::vector<std::string>* outList) { if (!mAccess->canList(mAccess->getCallingContext())) { - return Status::fromExceptionCode(Status::EX_SECURITY); + return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); } size_t toReserve = 0; @@ -466,18 +466,18 @@ Status ServiceManager::registerForNotifications( if (!isValidServiceName(name)) { ALOGE("Invalid service name: %s", name.c_str()); - return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT); + return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT, "Invalid service name."); } if (callback == nullptr) { - return Status::fromExceptionCode(Status::EX_NULL_POINTER); + return Status::fromExceptionCode(Status::EX_NULL_POINTER, "Null callback."); } if (OK != IInterface::asBinder(callback)->linkToDeath( sp<ServiceManager>::fromExisting(this))) { ALOGE("Could not linkToDeath when adding %s", name.c_str()); - return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); + return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, "Couldn't link to death."); } mNameToRegistrationCallback[name].push_back(callback); @@ -497,7 +497,7 @@ Status ServiceManager::unregisterForNotifications( auto ctx = mAccess->getCallingContext(); if (!mAccess->canFind(ctx, name)) { - return Status::fromExceptionCode(Status::EX_SECURITY); + return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); } bool found = false; @@ -509,7 +509,7 @@ Status ServiceManager::unregisterForNotifications( if (!found) { ALOGE("Trying to unregister callback, but none exists %s", name.c_str()); - return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); + return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, "Nothing to unregister."); } return Status::ok(); @@ -519,7 +519,7 @@ Status ServiceManager::isDeclared(const std::string& name, bool* outReturn) { auto ctx = mAccess->getCallingContext(); if (!mAccess->canFind(ctx, name)) { - return Status::fromExceptionCode(Status::EX_SECURITY); + return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); } *outReturn = false; @@ -547,7 +547,7 @@ binder::Status ServiceManager::getDeclaredInstances(const std::string& interface } if (outReturn->size() == 0 && allInstances.size() != 0) { - return Status::fromExceptionCode(Status::EX_SECURITY); + return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); } return Status::ok(); @@ -558,7 +558,7 @@ Status ServiceManager::updatableViaApex(const std::string& name, auto ctx = mAccess->getCallingContext(); if (!mAccess->canFind(ctx, name)) { - return Status::fromExceptionCode(Status::EX_SECURITY); + return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); } *outReturn = std::nullopt; @@ -587,7 +587,7 @@ Status ServiceManager::getUpdatableNames([[maybe_unused]] const std::string& ape } if (outReturn->size() == 0 && apexUpdatableInstances.size() != 0) { - return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denial"); + return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); } return Status::ok(); @@ -598,7 +598,7 @@ Status ServiceManager::getConnectionInfo(const std::string& name, auto ctx = mAccess->getCallingContext(); if (!mAccess->canFind(ctx, name)) { - return Status::fromExceptionCode(Status::EX_SECURITY); + return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); } *outReturn = std::nullopt; @@ -667,36 +667,37 @@ void ServiceManager::tryStartService(const std::string& name) { Status ServiceManager::registerClientCallback(const std::string& name, const sp<IBinder>& service, const sp<IClientCallback>& cb) { if (cb == nullptr) { - return Status::fromExceptionCode(Status::EX_NULL_POINTER); + return Status::fromExceptionCode(Status::EX_NULL_POINTER, "Callback null."); } auto ctx = mAccess->getCallingContext(); if (!mAccess->canAdd(ctx, name)) { - return Status::fromExceptionCode(Status::EX_SECURITY); + return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); } auto serviceIt = mNameToService.find(name); if (serviceIt == mNameToService.end()) { ALOGE("Could not add callback for nonexistent service: %s", name.c_str()); - return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT); + return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT, "Service doesn't exist."); } if (serviceIt->second.ctx.debugPid != IPCThreadState::self()->getCallingPid()) { ALOGW("Only a server can register for client callbacks (for %s)", name.c_str()); - return Status::fromExceptionCode(Status::EX_UNSUPPORTED_OPERATION); + return Status::fromExceptionCode(Status::EX_UNSUPPORTED_OPERATION, + "Only service can register client callback for itself."); } if (serviceIt->second.binder != service) { ALOGW("Tried to register client callback for %s but a different service is registered " "under this name.", name.c_str()); - return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT); + return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT, "Service mismatch."); } if (OK != IInterface::asBinder(cb)->linkToDeath(sp<ServiceManager>::fromExisting(this))) { ALOGE("Could not linkToDeath when adding client callback for %s", name.c_str()); - return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); + return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, "Couldn't linkToDeath."); } mNameToClientCallback[name].push_back(cb); @@ -810,24 +811,25 @@ void ServiceManager::sendClientCallbackNotifications(const std::string& serviceN Status ServiceManager::tryUnregisterService(const std::string& name, const sp<IBinder>& binder) { if (binder == nullptr) { - return Status::fromExceptionCode(Status::EX_NULL_POINTER); + return Status::fromExceptionCode(Status::EX_NULL_POINTER, "Null service."); } auto ctx = mAccess->getCallingContext(); if (!mAccess->canAdd(ctx, name)) { - return Status::fromExceptionCode(Status::EX_SECURITY); + return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); } auto serviceIt = mNameToService.find(name); if (serviceIt == mNameToService.end()) { ALOGW("Tried to unregister %s, but that service wasn't registered to begin with.", name.c_str()); - return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); + return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, "Service not registered."); } if (serviceIt->second.ctx.debugPid != IPCThreadState::self()->getCallingPid()) { ALOGW("Only a server can unregister itself (for %s)", name.c_str()); - return Status::fromExceptionCode(Status::EX_UNSUPPORTED_OPERATION); + return Status::fromExceptionCode(Status::EX_UNSUPPORTED_OPERATION, + "Service can only unregister itself."); } sp<IBinder> storedBinder = serviceIt->second.binder; @@ -835,14 +837,16 @@ Status ServiceManager::tryUnregisterService(const std::string& name, const sp<IB if (binder != storedBinder) { ALOGW("Tried to unregister %s, but a different service is registered under this name.", name.c_str()); - return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); + return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, + "Different service registered under this name."); } // important because we don't have timer-based guarantees, we don't want to clear // this if (serviceIt->second.guaranteeClient) { ALOGI("Tried to unregister %s, but there is about to be a client.", name.c_str()); - return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); + return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, + "Can't unregister, pending client."); } // - kernel driver will hold onto one refcount (during this transaction) @@ -857,7 +861,8 @@ Status ServiceManager::tryUnregisterService(const std::string& name, const sp<IB // help reduce thrashing, but we should be able to remove it. serviceIt->second.guaranteeClient = true; - return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); + return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, + "Can't unregister, known client."); } ALOGI("Unregistering %s", name.c_str()); @@ -868,7 +873,7 @@ Status ServiceManager::tryUnregisterService(const std::string& name, const sp<IB Status ServiceManager::getServiceDebugInfo(std::vector<ServiceDebugInfo>* outReturn) { if (!mAccess->canList(mAccess->getCallingContext())) { - return Status::fromExceptionCode(Status::EX_SECURITY); + return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); } outReturn->reserve(mNameToService.size()); diff --git a/include/android/keycodes.h b/include/android/keycodes.h index d4ba321057..f8fb256fae 100644 --- a/include/android/keycodes.h +++ b/include/android/keycodes.h @@ -831,6 +831,14 @@ enum { AKEYCODE_STYLUS_BUTTON_TAIL = 311, /** Key to open recent apps (a.k.a. Overview) */ AKEYCODE_RECENT_APPS = 312, + /** User customizable key #1. */ + AKEYCODE_MACRO_1 = 313, + /** User customizable key #2. */ + AKEYCODE_MACRO_2 = 314, + /** User customizable key #3. */ + AKEYCODE_MACRO_3 = 315, + /** User customizable key #4. */ + AKEYCODE_MACRO_4 = 316, // NOTE: If you add a new keycode here you must also add it to several other files. // Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list. diff --git a/include/input/Input.h b/include/input/Input.h index e8af5f7d46..a033535f4b 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -216,7 +216,21 @@ std::string inputEventSourceToString(int32_t source); bool isFromSource(uint32_t source, uint32_t test); -bool isStylusToolType(uint32_t toolType); +/** + * The pointer tool type. + */ +enum class ToolType { + UNKNOWN = AMOTION_EVENT_TOOL_TYPE_UNKNOWN, + FINGER = AMOTION_EVENT_TOOL_TYPE_FINGER, + STYLUS = AMOTION_EVENT_TOOL_TYPE_STYLUS, + MOUSE = AMOTION_EVENT_TOOL_TYPE_MOUSE, + ERASER = AMOTION_EVENT_TOOL_TYPE_ERASER, + PALM = AMOTION_EVENT_TOOL_TYPE_PALM, + ftl_first = UNKNOWN, + ftl_last = PALM, +}; + +bool isStylusToolType(ToolType toolType); /* * Flags that flow alongside events in the input dispatch system to help with certain @@ -320,8 +334,6 @@ enum class MotionClassification : uint8_t { */ const char* motionClassificationToString(MotionClassification classification); -const char* motionToolTypeToString(int32_t toolType); - /** * Portion of FrameMetrics timeline of interest to input code. */ @@ -448,11 +460,11 @@ struct PointerProperties { int32_t id; // The pointer tool type. - int32_t toolType; + ToolType toolType; inline void clear() { id = -1; - toolType = 0; + toolType = ToolType::UNKNOWN; } bool operator==(const PointerProperties& other) const; @@ -638,7 +650,7 @@ public: return mPointerProperties[pointerIndex].id; } - inline int32_t getToolType(size_t pointerIndex) const { + inline ToolType getToolType(size_t pointerIndex) const { return mPointerProperties[pointerIndex].toolType; } diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h index a1be542d7b..4f53c36d6f 100644 --- a/include/input/InputTransport.h +++ b/include/input/InputTransport.h @@ -669,7 +669,6 @@ private: static void addSample(MotionEvent* event, const InputMessage* msg); static bool canAddSample(const Batch& batch, const InputMessage* msg); static ssize_t findSampleNoLaterThan(const Batch& batch, nsecs_t time); - static bool shouldResampleTool(int32_t toolType); static bool isTouchResamplingEnabled(); }; diff --git a/libs/binder/TEST_MAPPING b/libs/binder/TEST_MAPPING index 07b38d7368..41707d48b2 100644 --- a/libs/binder/TEST_MAPPING +++ b/libs/binder/TEST_MAPPING @@ -79,6 +79,12 @@ }, { "name": "rustBinderSerializationTest" + }, + { + "name": "libbinder_ndk_bindgen_test" + }, + { + "name": "libbinder_rpc_unstable_bindgen_test" } ], "presubmit-large": [ diff --git a/libs/binder/trusty/binderRpcTest/rules.mk b/libs/binder/trusty/binderRpcTest/rules.mk index ae3949246d..975f689d1a 100644 --- a/libs/binder/trusty/binderRpcTest/rules.mk +++ b/libs/binder/trusty/binderRpcTest/rules.mk @@ -32,4 +32,8 @@ MODULE_LIBRARY_DEPS += \ trusty/user/base/lib/googletest \ trusty/user/base/lib/libstdc++-trusty \ +# TEST_P tests from binderRpcUniversalTests.cpp don't get linked in +# unless we pass in --whole-archive to the linker (b/275620340). +MODULE_USE_WHOLE_ARCHIVE := true + include make/trusted_app.mk diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp index cf171dcec9..fee91a40c2 100644 --- a/libs/gui/LayerState.cpp +++ b/libs/gui/LayerState.cpp @@ -190,8 +190,8 @@ status_t layer_state_t::write(Parcel& output) const } SAFE_PARCEL(output.writeParcelable, trustedPresentationThresholds); SAFE_PARCEL(output.writeParcelable, trustedPresentationListener); - SAFE_PARCEL(output.writeFloat, currentSdrHdrRatio); - SAFE_PARCEL(output.writeFloat, desiredSdrHdrRatio); + SAFE_PARCEL(output.writeFloat, currentHdrSdrRatio); + SAFE_PARCEL(output.writeFloat, desiredHdrSdrRatio); SAFE_PARCEL(output.writeInt32, static_cast<int32_t>(cachingHint)) return NO_ERROR; } @@ -335,9 +335,9 @@ status_t layer_state_t::read(const Parcel& input) SAFE_PARCEL(input.readParcelable, &trustedPresentationListener); SAFE_PARCEL(input.readFloat, &tmpFloat); - currentSdrHdrRatio = tmpFloat; + currentHdrSdrRatio = tmpFloat; SAFE_PARCEL(input.readFloat, &tmpFloat); - desiredSdrHdrRatio = tmpFloat; + desiredHdrSdrRatio = tmpFloat; int32_t tmpInt32; SAFE_PARCEL(input.readInt32, &tmpInt32); @@ -592,8 +592,8 @@ void layer_state_t::merge(const layer_state_t& other) { } if (other.what & eExtendedRangeBrightnessChanged) { what |= eExtendedRangeBrightnessChanged; - desiredSdrHdrRatio = other.desiredSdrHdrRatio; - currentSdrHdrRatio = other.currentSdrHdrRatio; + desiredHdrSdrRatio = other.desiredHdrSdrRatio; + currentHdrSdrRatio = other.currentHdrSdrRatio; } if (other.what & eCachingHintChanged) { what |= eCachingHintChanged; @@ -747,8 +747,8 @@ uint64_t layer_state_t::diff(const layer_state_t& other) const { CHECK_DIFF(diff, eCropChanged, other, crop); if (other.what & eBufferChanged) diff |= eBufferChanged; CHECK_DIFF(diff, eDataspaceChanged, other, dataspace); - CHECK_DIFF2(diff, eExtendedRangeBrightnessChanged, other, currentSdrHdrRatio, - desiredSdrHdrRatio); + CHECK_DIFF2(diff, eExtendedRangeBrightnessChanged, other, currentHdrSdrRatio, + desiredHdrSdrRatio); CHECK_DIFF(diff, eCachingHintChanged, other, cachingHint); CHECK_DIFF(diff, eHdrMetadataChanged, other, hdrMetadata); if (other.what & eSurfaceDamageRegionChanged && diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 2f5830d362..7700aa4044 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -1723,8 +1723,8 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setExten return *this; } s->what |= layer_state_t::eExtendedRangeBrightnessChanged; - s->currentSdrHdrRatio = currentBufferRatio; - s->desiredSdrHdrRatio = desiredRatio; + s->currentHdrSdrRatio = currentBufferRatio; + s->desiredHdrSdrRatio = desiredRatio; registerSurfaceControlForCallback(sc); return *this; diff --git a/libs/gui/WindowInfo.cpp b/libs/gui/WindowInfo.cpp index 804ce4fac0..6df9ff1664 100644 --- a/libs/gui/WindowInfo.cpp +++ b/libs/gui/WindowInfo.cpp @@ -125,6 +125,7 @@ status_t WindowInfo::writeToParcel(android::Parcel* parcel) const { parcel->writeBool(replaceTouchableRegionWithCrop) ?: parcel->writeStrongBinder(touchableRegionCropHandle.promote()) ?: parcel->writeStrongBinder(windowToken); + parcel->writeStrongBinder(focusTransferTarget); // clang-format on return status; } @@ -175,7 +176,9 @@ status_t WindowInfo::readFromParcel(const android::Parcel* parcel) { parcel->read(touchableRegion) ?: parcel->readBool(&replaceTouchableRegionWithCrop) ?: parcel->readNullableStrongBinder(&touchableRegionCropHandleSp) ?: - parcel->readNullableStrongBinder(&windowToken); + parcel->readNullableStrongBinder(&windowToken) ?: + parcel->readNullableStrongBinder(&focusTransferTarget); + // clang-format on if (status != OK) { diff --git a/libs/gui/android/gui/FocusRequest.aidl b/libs/gui/android/gui/FocusRequest.aidl index b13c60049c..62d1b68147 100644 --- a/libs/gui/android/gui/FocusRequest.aidl +++ b/libs/gui/android/gui/FocusRequest.aidl @@ -24,15 +24,6 @@ parcelable FocusRequest { @nullable IBinder token; @utf8InCpp String windowName; /** - * The token that the caller expects currently to be focused. If the - * specified token does not match the currently focused window, this request will be dropped. - * If the specified focused token matches the currently focused window, the call will succeed. - * Set this to "null" if this call should succeed no matter what the currently focused token - * is. - */ - @nullable IBinder focusedToken; - @utf8InCpp String focusedWindowName; - /** * SYSTEM_TIME_MONOTONIC timestamp in nanos set by the client (wm) when requesting the focus * change. This determines which request gets precedence if there is a focus change request * from another source such as pointer down. diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h index 6e3be5cef8..5c88a07ba8 100644 --- a/libs/gui/include/gui/LayerState.h +++ b/libs/gui/include/gui/LayerState.h @@ -389,8 +389,8 @@ struct layer_state_t { gui::DropInputMode dropInputMode; bool dimmingEnabled; - float currentSdrHdrRatio = 1.f; - float desiredSdrHdrRatio = 1.f; + float currentHdrSdrRatio = 1.f; + float desiredHdrSdrRatio = 1.f; gui::CachingHint cachingHint = gui::CachingHint::Enabled; diff --git a/libs/gui/include/gui/WindowInfo.h b/libs/gui/include/gui/WindowInfo.h index b01a3db52d..70b2ee8e32 100644 --- a/libs/gui/include/gui/WindowInfo.h +++ b/libs/gui/include/gui/WindowInfo.h @@ -236,6 +236,11 @@ struct WindowInfo : public Parcelable { Type layoutParamsType = Type::UNKNOWN; ftl::Flags<Flag> layoutParamsFlags; + // The input token for the window to which focus should be transferred when this input window + // can be successfully focused. If null, this input window will not transfer its focus to + // any other window. + sp<IBinder> focusTransferTarget; + void setInputConfig(ftl::Flags<InputConfig> config, bool value); void addTouchableRegion(const Rect& region); diff --git a/libs/gui/tests/EndToEndNativeInputTest.cpp b/libs/gui/tests/EndToEndNativeInputTest.cpp index 5f80c16f61..9e8c65c678 100644 --- a/libs/gui/tests/EndToEndNativeInputTest.cpp +++ b/libs/gui/tests/EndToEndNativeInputTest.cpp @@ -272,8 +272,6 @@ public: FocusRequest request; request.token = mInputInfo.token; request.windowName = mInputInfo.name; - request.focusedToken = nullptr; - request.focusedWindowName = ""; request.timestamp = systemTime(SYSTEM_TIME_MONOTONIC); request.displayId = displayId; t.setFocusedWindow(request); diff --git a/libs/gui/tests/WindowInfo_test.cpp b/libs/gui/tests/WindowInfo_test.cpp index c51b244c50..11b87efda7 100644 --- a/libs/gui/tests/WindowInfo_test.cpp +++ b/libs/gui/tests/WindowInfo_test.cpp @@ -71,6 +71,7 @@ TEST(WindowInfo, Parcelling) { i.applicationInfo.name = "ApplicationFooBar"; i.applicationInfo.token = new BBinder(); i.applicationInfo.dispatchingTimeoutMillis = 0x12345678ABCD; + i.focusTransferTarget = new BBinder(); Parcel p; i.writeToParcel(&p); @@ -101,6 +102,7 @@ TEST(WindowInfo, Parcelling) { ASSERT_EQ(i.replaceTouchableRegionWithCrop, i2.replaceTouchableRegionWithCrop); ASSERT_EQ(i.touchableRegionCropHandle, i2.touchableRegionCropHandle); ASSERT_EQ(i.applicationInfo, i2.applicationInfo); + ASSERT_EQ(i.focusTransferTarget, i2.focusTransferTarget); } TEST(InputApplicationInfo, Parcelling) { diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 53b22cb883..4dbf575490 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -79,25 +79,6 @@ const char* motionClassificationToString(MotionClassification classification) { } } -const char* motionToolTypeToString(int32_t toolType) { - switch (toolType) { - case AMOTION_EVENT_TOOL_TYPE_UNKNOWN: - return "UNKNOWN"; - case AMOTION_EVENT_TOOL_TYPE_FINGER: - return "FINGER"; - case AMOTION_EVENT_TOOL_TYPE_STYLUS: - return "STYLUS"; - case AMOTION_EVENT_TOOL_TYPE_MOUSE: - return "MOUSE"; - case AMOTION_EVENT_TOOL_TYPE_ERASER: - return "ERASER"; - case AMOTION_EVENT_TOOL_TYPE_PALM: - return "PALM"; - default: - return "INVALID"; - } -} - // --- IdGenerator --- #if defined(__ANDROID__) [[maybe_unused]] @@ -256,8 +237,8 @@ bool isFromSource(uint32_t source, uint32_t test) { return (source & test) == test; } -bool isStylusToolType(uint32_t toolType) { - return toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS || toolType == AMOTION_EVENT_TOOL_TYPE_ERASER; +bool isStylusToolType(ToolType toolType) { + return toolType == ToolType::STYLUS || toolType == ToolType::ERASER; } VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event) { @@ -810,7 +791,7 @@ status_t MotionEvent::readFromParcel(Parcel* parcel) { mPointerProperties.push_back({}); PointerProperties& properties = mPointerProperties.back(); properties.id = parcel->readInt32(); - properties.toolType = parcel->readInt32(); + properties.toolType = static_cast<ToolType>(parcel->readInt32()); } while (sampleCount > 0) { @@ -866,7 +847,7 @@ status_t MotionEvent::writeToParcel(Parcel* parcel) const { for (size_t i = 0; i < pointerCount; i++) { const PointerProperties& properties = mPointerProperties[i]; parcel->writeInt32(properties.id); - parcel->writeInt32(properties.toolType); + parcel->writeInt32(static_cast<int32_t>(properties.toolType)); } const PointerCoords* pc = mSamplePointerCoords.data(); @@ -1030,9 +1011,9 @@ std::ostream& operator<<(std::ostream& out, const MotionEvent& event) { out << ", x[" << i << "]=" << x; out << ", y[" << i << "]=" << y; } - int toolType = event.getToolType(i); - if (toolType != AMOTION_EVENT_TOOL_TYPE_FINGER) { - out << ", toolType[" << i << "]=" << toolType; + ToolType toolType = event.getToolType(i); + if (toolType != ToolType::FINGER) { + out << ", toolType[" << i << "]=" << ftl::enum_string(toolType); } } if (event.getButtonState() != 0) { diff --git a/libs/input/InputEventLabels.cpp b/libs/input/InputEventLabels.cpp index 4a19227694..f99a7d640e 100644 --- a/libs/input/InputEventLabels.cpp +++ b/libs/input/InputEventLabels.cpp @@ -343,7 +343,11 @@ namespace android { DEFINE_KEYCODE(STYLUS_BUTTON_SECONDARY), \ DEFINE_KEYCODE(STYLUS_BUTTON_TERTIARY), \ DEFINE_KEYCODE(STYLUS_BUTTON_TAIL), \ - DEFINE_KEYCODE(RECENT_APPS) + DEFINE_KEYCODE(RECENT_APPS), \ + DEFINE_KEYCODE(MACRO_1), \ + DEFINE_KEYCODE(MACRO_2), \ + DEFINE_KEYCODE(MACRO_3), \ + DEFINE_KEYCODE(MACRO_4) // NOTE: If you add a new axis here you must also add it to several other files. // Refer to frameworks/base/core/java/android/view/MotionEvent.java for the full list. diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp index 311b2441a4..f6b4648d67 100644 --- a/libs/input/InputTransport.cpp +++ b/libs/input/InputTransport.cpp @@ -145,6 +145,10 @@ inline static const char* toString(bool value) { return value ? "true" : "false"; } +static bool shouldResampleTool(ToolType toolType) { + return toolType == ToolType::FINGER || toolType == ToolType::UNKNOWN; +} + // --- InputMessage --- bool InputMessage::isValid(size_t actualSize) const { @@ -1274,11 +1278,6 @@ void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event, event->addSample(sampleTime, touchState.lastResample.pointers); } -bool InputConsumer::shouldResampleTool(int32_t toolType) { - return toolType == AMOTION_EVENT_TOOL_TYPE_FINGER - || toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN; -} - status_t InputConsumer::sendFinishedSignal(uint32_t seq, bool handled) { ALOGD_IF(DEBUG_TRANSPORT_CONSUMER, "channel '%s' consumer ~ sendFinishedSignal: seq=%u, handled=%s", diff --git a/libs/input/MotionPredictor.cpp b/libs/input/MotionPredictor.cpp index b4151c6ea1..3037573538 100644 --- a/libs/input/MotionPredictor.cpp +++ b/libs/input/MotionPredictor.cpp @@ -30,6 +30,7 @@ #include <log/log.h> #include <attestation/HmacKeyManager.h> +#include <ftl/enum.h> #include <input/TfLiteMotionPredictor.h> namespace android { @@ -108,10 +109,10 @@ android::base::Result<void> MotionPredictor::record(const MotionEvent& event) { return {}; } - const int32_t toolType = event.getPointerProperties(0)->toolType; - if (toolType != AMOTION_EVENT_TOOL_TYPE_STYLUS) { + const ToolType toolType = event.getPointerProperties(0)->toolType; + if (toolType != ToolType::STYLUS) { ALOGD_IF(isDebug(), "Prediction not supported for non-stylus tool: %s", - motionToolTypeToString(toolType)); + ftl::enum_string(toolType).c_str()); return {}; } diff --git a/libs/input/tests/InputEvent_test.cpp b/libs/input/tests/InputEvent_test.cpp index 2132dc1bdf..59125dd428 100644 --- a/libs/input/tests/InputEvent_test.cpp +++ b/libs/input/tests/InputEvent_test.cpp @@ -259,10 +259,10 @@ void MotionEventTest::SetUp() { mPointerProperties[0].clear(); mPointerProperties[0].id = 1; - mPointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + mPointerProperties[0].toolType = ToolType::FINGER; mPointerProperties[1].clear(); mPointerProperties[1].id = 2; - mPointerProperties[1].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + mPointerProperties[1].toolType = ToolType::STYLUS; mSamples[0].pointerCoords[0].clear(); mSamples[0].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 10); @@ -366,9 +366,9 @@ void MotionEventTest::assertEqualsEventWithHistory(const MotionEvent* event) { ASSERT_EQ(2U, event->getPointerCount()); ASSERT_EQ(1, event->getPointerId(0)); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, event->getToolType(0)); + ASSERT_EQ(ToolType::FINGER, event->getToolType(0)); ASSERT_EQ(2, event->getPointerId(1)); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, event->getToolType(1)); + ASSERT_EQ(ToolType::STYLUS, event->getToolType(1)); ASSERT_EQ(2U, event->getHistorySize()); @@ -692,7 +692,7 @@ TEST_F(MotionEventTest, Transform) { MotionEvent createMotionEvent(int32_t source, uint32_t action, float x, float y, float dx, float dy, const ui::Transform& transform, const ui::Transform& rawTransform) { std::vector<PointerProperties> pointerProperties; - pointerProperties.push_back(PointerProperties{/* id */ 0, AMOTION_EVENT_TOOL_TYPE_FINGER}); + pointerProperties.push_back(PointerProperties{/*id=*/0, ToolType::FINGER}); std::vector<PointerCoords> pointerCoords; pointerCoords.emplace_back().clear(); pointerCoords.back().setAxisValue(AMOTION_EVENT_AXIS_X, x); diff --git a/libs/input/tests/InputPublisherAndConsumer_test.cpp b/libs/input/tests/InputPublisherAndConsumer_test.cpp index 5d8b9700b3..965fda73b4 100644 --- a/libs/input/tests/InputPublisherAndConsumer_test.cpp +++ b/libs/input/tests/InputPublisherAndConsumer_test.cpp @@ -172,7 +172,7 @@ void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() { for (size_t i = 0; i < pointerCount; i++) { pointerProperties[i].clear(); pointerProperties[i].id = (i + 2) % pointerCount; - pointerProperties[i].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + pointerProperties[i].toolType = ToolType::FINGER; pointerCoords[i].clear(); pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, 100 * i); diff --git a/libs/input/tests/MotionPredictor_test.cpp b/libs/input/tests/MotionPredictor_test.cpp index c61efbf9ed..7a62f5ec58 100644 --- a/libs/input/tests/MotionPredictor_test.cpp +++ b/libs/input/tests/MotionPredictor_test.cpp @@ -45,7 +45,7 @@ static MotionEvent getMotionEvent(int32_t action, float x, float y, PointerProperties properties; properties.clear(); properties.id = i; - properties.toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + properties.toolType = ToolType::STYLUS; pointerProperties.push_back(properties); PointerCoords coords; coords.clear(); diff --git a/libs/input/tests/TouchResampling_test.cpp b/libs/input/tests/TouchResampling_test.cpp index 7cb9526af0..655de803ae 100644 --- a/libs/input/tests/TouchResampling_test.cpp +++ b/libs/input/tests/TouchResampling_test.cpp @@ -99,7 +99,7 @@ void TouchResamplingTest::publishSimpleMotionEvent(int32_t action, nsecs_t event properties.push_back({}); properties.back().clear(); properties.back().id = pointer.id; - properties.back().toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + properties.back().toolType = ToolType::FINGER; coords.push_back({}); coords.back().clear(); diff --git a/libs/input/tests/VelocityTracker_test.cpp b/libs/input/tests/VelocityTracker_test.cpp index 027757973b..ae721093a0 100644 --- a/libs/input/tests/VelocityTracker_test.cpp +++ b/libs/input/tests/VelocityTracker_test.cpp @@ -212,7 +212,7 @@ static std::vector<MotionEvent> createTouchMotionEventStream( coords[pointerIndex].isResampled = position.isResampled; properties[pointerIndex].id = pointerId; - properties[pointerIndex].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + properties[pointerIndex].toolType = ToolType::FINGER; pointerIndex++; } EXPECT_EQ(pointerIndex, pointerCount); diff --git a/libs/jpegrecoverymap/Android.bp b/libs/jpegrecoverymap/Android.bp index b470f351f4..a1b0e19509 100644 --- a/libs/jpegrecoverymap/Android.bp +++ b/libs/jpegrecoverymap/Android.bp @@ -24,7 +24,7 @@ package { cc_library { name: "libjpegrecoverymap", host_supported: true, - + vendor_available: true, export_include_dirs: ["include"], local_include_dirs: ["include"], @@ -49,10 +49,12 @@ cc_library { cc_library { name: "libjpegencoder", host_supported: true, + vendor_available: true, shared_libs: [ "libjpeg", "liblog", + "libutils", ], export_include_dirs: ["include"], @@ -65,10 +67,12 @@ cc_library { cc_library { name: "libjpegdecoder", host_supported: true, + vendor_available: true, shared_libs: [ "libjpeg", "liblog", + "libutils", ], export_include_dirs: ["include"], diff --git a/libs/ui/Gralloc5.cpp b/libs/ui/Gralloc5.cpp index 514b45f0a5..21068394d2 100644 --- a/libs/ui/Gralloc5.cpp +++ b/libs/ui/Gralloc5.cpp @@ -352,14 +352,12 @@ status_t Gralloc5Mapper::validateBufferSize(buffer_handle_t bufferHandle, uint32 } } { - (void)stride; - // TODO(b/261856851): Add StandardMetadataType::STRIDE && enable this - // auto value = getStandardMetadata<StandardMetadataType::STRIDE>(mMapper, - // bufferHandle); if (static_cast<BufferUsage>(usage) != value) { - // ALOGW("Layer count didn't match, expected %" PRIu64 " got %" PRId64, usage, - // static_cast<int64_t>(value.value_or(BufferUsage::CPU_READ_NEVER))); - // return BAD_VALUE; - // } + auto value = getStandardMetadata<StandardMetadataType::STRIDE>(mMapper, bufferHandle); + if (stride != value) { + ALOGW("Stride didn't match, expected %" PRIu32 " got %" PRId32, stride, + value.value_or(-1)); + return BAD_VALUE; + } } return OK; } diff --git a/services/gpuservice/vts/Android.bp b/services/gpuservice/vts/Android.bp index f4ea4408b6..a24822a7d1 100644 --- a/services/gpuservice/vts/Android.bp +++ b/services/gpuservice/vts/Android.bp @@ -21,7 +21,6 @@ java_test_host { srcs: ["src/**/*.java"], libs: [ "tradefed", - "vts-core-tradefed-harness", "compatibility-host-util", ], test_suites: [ diff --git a/services/gpuservice/vts/src/com/android/tests/gpuservice/GpuWorkTracepointTest.java b/services/gpuservice/vts/src/com/android/tests/gpuservice/GpuWorkTracepointTest.java index 290a6469c6..6c16335359 100644 --- a/services/gpuservice/vts/src/com/android/tests/gpuservice/GpuWorkTracepointTest.java +++ b/services/gpuservice/vts/src/com/android/tests/gpuservice/GpuWorkTracepointTest.java @@ -27,7 +27,7 @@ import com.android.tradefed.util.CommandResult; import com.android.tradefed.util.CommandStatus; import com.android.compatibility.common.util.PropertyUtil; -import com.android.compatibility.common.util.GmsTest; +import com.android.compatibility.common.util.VsrTest; import org.junit.Test; import org.junit.runner.RunWith; @@ -62,7 +62,7 @@ public class GpuWorkTracepointTest extends BaseHostJUnit4Test { commandResult.getStatus(), CommandStatus.SUCCESS); } - @GmsTest(requirement = "VSR-3.3-004") + @VsrTest(requirements={"VSR-3.3-004"}) @RestrictedBuildTest @Test public void testGpuWorkPeriodTracepointFormat() throws Exception { diff --git a/services/inputflinger/InputCommonConverter.cpp b/services/inputflinger/InputCommonConverter.cpp index 0c93f5ce40..2437d0fcfc 100644 --- a/services/inputflinger/InputCommonConverter.cpp +++ b/services/inputflinger/InputCommonConverter.cpp @@ -200,17 +200,12 @@ static common::Button getButtonState(int32_t buttonState) { return static_cast<common::Button>(buttonState); } -static common::ToolType getToolType(int32_t toolType) { - static_assert(static_cast<common::ToolType>(AMOTION_EVENT_TOOL_TYPE_UNKNOWN) == - common::ToolType::UNKNOWN); - static_assert(static_cast<common::ToolType>(AMOTION_EVENT_TOOL_TYPE_FINGER) == - common::ToolType::FINGER); - static_assert(static_cast<common::ToolType>(AMOTION_EVENT_TOOL_TYPE_STYLUS) == - common::ToolType::STYLUS); - static_assert(static_cast<common::ToolType>(AMOTION_EVENT_TOOL_TYPE_MOUSE) == - common::ToolType::MOUSE); - static_assert(static_cast<common::ToolType>(AMOTION_EVENT_TOOL_TYPE_ERASER) == - common::ToolType::ERASER); +static common::ToolType getToolType(ToolType toolType) { + static_assert(static_cast<common::ToolType>(ToolType::UNKNOWN) == common::ToolType::UNKNOWN); + static_assert(static_cast<common::ToolType>(ToolType::FINGER) == common::ToolType::FINGER); + static_assert(static_cast<common::ToolType>(ToolType::STYLUS) == common::ToolType::STYLUS); + static_assert(static_cast<common::ToolType>(ToolType::MOUSE) == common::ToolType::MOUSE); + static_assert(static_cast<common::ToolType>(ToolType::ERASER) == common::ToolType::ERASER); return static_cast<common::ToolType>(toolType); } diff --git a/services/inputflinger/NotifyArgs.cpp b/services/inputflinger/NotifyArgs.cpp index b192ad73c3..5f2a22f467 100644 --- a/services/inputflinger/NotifyArgs.cpp +++ b/services/inputflinger/NotifyArgs.cpp @@ -161,9 +161,9 @@ std::string NotifyMotionArgs::dump() const { StringPrintf("id=%" PRIu32 " x=%.1f y=%.1f pressure=%.1f", pointerProperties[i].id, pointerCoords[i].getX(), pointerCoords[i].getY(), pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE)); - const int32_t toolType = pointerProperties[i].toolType; - if (toolType != AMOTION_EVENT_TOOL_TYPE_FINGER) { - coords += StringPrintf(" toolType=%s", motionToolTypeToString(toolType)); + const ToolType toolType = pointerProperties[i].toolType; + if (toolType != ToolType::FINGER) { + coords += StringPrintf(" toolType=%s", ftl::enum_string(toolType).c_str()); } const float major = pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR); const float minor = pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR); diff --git a/services/inputflinger/PreferStylusOverTouchBlocker.cpp b/services/inputflinger/PreferStylusOverTouchBlocker.cpp index ddd514676b..fbd296c131 100644 --- a/services/inputflinger/PreferStylusOverTouchBlocker.cpp +++ b/services/inputflinger/PreferStylusOverTouchBlocker.cpp @@ -24,11 +24,11 @@ static std::pair<bool, bool> checkToolType(const NotifyMotionArgs& args) { bool hasTouch = false; for (size_t i = 0; i < args.pointerCount; i++) { // Make sure we are canceling stylus pointers - const int32_t toolType = args.pointerProperties[i].toolType; + const ToolType toolType = args.pointerProperties[i].toolType; if (isStylusToolType(toolType)) { hasStylus = true; } - if (toolType == AMOTION_EVENT_TOOL_TYPE_FINGER) { + if (toolType == ToolType::FINGER) { hasTouch = true; } } diff --git a/services/inputflinger/UnwantedInteractionBlocker.cpp b/services/inputflinger/UnwantedInteractionBlocker.cpp index c170b81475..ae20f862dc 100644 --- a/services/inputflinger/UnwantedInteractionBlocker.cpp +++ b/services/inputflinger/UnwantedInteractionBlocker.cpp @@ -18,6 +18,7 @@ #include "UnwantedInteractionBlocker.h" #include <android-base/stringprintf.h> +#include <ftl/enum.h> #include <input/PrintTools.h> #include <inttypes.h> #include <linux/input-event-codes.h> @@ -98,18 +99,21 @@ static bool isPalmRejectionEnabled() { return false; } -static int getLinuxToolCode(int toolType) { +static int getLinuxToolCode(ToolType toolType) { switch (toolType) { - case AMOTION_EVENT_TOOL_TYPE_STYLUS: + case ToolType::STYLUS: return BTN_TOOL_PEN; - case AMOTION_EVENT_TOOL_TYPE_ERASER: + case ToolType::ERASER: return BTN_TOOL_RUBBER; - case AMOTION_EVENT_TOOL_TYPE_FINGER: - return BTN_TOOL_FINGER; - default: - ALOGW("Got tool type %" PRId32 ", converting to BTN_TOOL_FINGER", toolType); + case ToolType::FINGER: return BTN_TOOL_FINGER; + case ToolType::UNKNOWN: + case ToolType::MOUSE: + case ToolType::PALM: + break; } + ALOGW("Got tool type %s, converting to BTN_TOOL_FINGER", ftl::enum_string(toolType).c_str()); + return BTN_TOOL_FINGER; } static int32_t getActionUpForPointerId(const NotifyMotionArgs& args, int32_t pointerId) { diff --git a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp index f03c837f56..58324c4762 100644 --- a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp +++ b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp @@ -207,7 +207,7 @@ static MotionEvent generateMotionEvent() { pointerProperties[0].clear(); pointerProperties[0].id = 0; - pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + pointerProperties[0].toolType = ToolType::FINGER; pointerCoords[0].clear(); pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 100); @@ -235,7 +235,7 @@ static NotifyMotionArgs generateMotionArgs() { pointerProperties[0].clear(); pointerProperties[0].id = 0; - pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + pointerProperties[0].toolType = ToolType::FINGER; pointerCoords[0].clear(); pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 100); diff --git a/services/inputflinger/dispatcher/FocusResolver.cpp b/services/inputflinger/dispatcher/FocusResolver.cpp index 4da846bcf8..0e4e79e88e 100644 --- a/services/inputflinger/dispatcher/FocusResolver.cpp +++ b/services/inputflinger/dispatcher/FocusResolver.cpp @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include <optional> #define LOG_TAG "InputDispatcher" #define ATRACE_TAG ATRACE_TAG_INPUT @@ -25,6 +26,7 @@ #include <binder/Binder.h> #include <ftl/enum.h> #include <gui/WindowInfo.h> +#include <unordered_set> #include "DebugConfig.h" #include "FocusResolver.h" @@ -34,6 +36,11 @@ using android::gui::WindowInfoHandle; namespace android::inputdispatcher { +template <typename T> +struct SpHash { + size_t operator()(const sp<T>& k) const { return std::hash<T*>()(k.get()); } +}; + sp<IBinder> FocusResolver::getFocusedWindowToken(int32_t displayId) const { auto it = mFocusedWindowTokenByDisplay.find(displayId); return it != mFocusedWindowTokenByDisplay.end() ? it->second.second : nullptr; @@ -54,30 +61,30 @@ std::optional<FocusResolver::FocusChanges> FocusResolver::setInputWindows( int32_t displayId, const std::vector<sp<WindowInfoHandle>>& windows) { std::string removeFocusReason; - // Check if the currently focused window is still focusable. + const std::optional<FocusRequest> request = getFocusRequest(displayId); const sp<IBinder> currentFocus = getFocusedWindowToken(displayId); - if (currentFocus) { - Focusability result = isTokenFocusable(currentFocus, windows); - if (result == Focusability::OK) { - return std::nullopt; - } - removeFocusReason = ftl::enum_string(result); - } - // We don't have a focused window or the currently focused window is no longer focusable. Check - // to see if we can grant focus to the window that previously requested focus. - const std::optional<FocusRequest> request = getFocusRequest(displayId); + // Find the next focused token based on the latest FocusRequest. If the requested focus window + // cannot be focused, focus will be removed. if (request) { sp<IBinder> requestedFocus = request->token; - const Focusability result = isTokenFocusable(requestedFocus, windows); + sp<WindowInfoHandle> resolvedFocusWindow; + Focusability result = getResolvedFocusWindow(requestedFocus, windows, resolvedFocusWindow); + if (result == Focusability::OK && resolvedFocusWindow->getToken() == currentFocus) { + return std::nullopt; + } const Focusability previousResult = mLastFocusResultByDisplay[displayId]; mLastFocusResultByDisplay[displayId] = result; if (result == Focusability::OK) { + LOG_ALWAYS_FATAL_IF(!resolvedFocusWindow, + "Focused window should be non-null when result is OK!"); return updateFocusedWindow(displayId, "Window became focusable. Previous reason: " + ftl::enum_string(previousResult), - requestedFocus, request->windowName); + resolvedFocusWindow->getToken(), + resolvedFocusWindow->getName()); } + removeFocusReason = ftl::enum_string(result); } // Focused window is no longer focusable and we don't have a suitable focus request to grant. @@ -96,35 +103,18 @@ std::optional<FocusResolver::FocusChanges> FocusResolver::setFocusedWindow( return std::nullopt; } - // Handle conditional focus requests, i.e. requests that have a focused token. These requests - // are not persistent. If the window is no longer focusable, we expect focus to go back to the - // previously focused window. - if (request.focusedToken) { - if (currentFocus != request.focusedToken) { - ALOGW("setFocusedWindow %s on display %" PRId32 - " ignored, reason: focusedToken %s is not focused", - request.windowName.c_str(), displayId, request.focusedWindowName.c_str()); - return std::nullopt; - } - Focusability result = isTokenFocusable(request.token, windows); - if (result == Focusability::OK) { - return updateFocusedWindow(displayId, "setFocusedWindow with focus check", - request.token, request.windowName); - } - ALOGW("setFocusedWindow %s on display %" PRId32 " ignored, reason: %s", - request.windowName.c_str(), displayId, ftl::enum_string(result).c_str()); - return std::nullopt; - } - - Focusability result = isTokenFocusable(request.token, windows); + sp<WindowInfoHandle> resolvedFocusWindow; + Focusability result = getResolvedFocusWindow(request.token, windows, resolvedFocusWindow); // Update focus request. The focus resolver will always try to handle this request if there is // no focused window on the display. mFocusRequestByDisplay[displayId] = request; mLastFocusResultByDisplay[displayId] = result; if (result == Focusability::OK) { - return updateFocusedWindow(displayId, "setFocusedWindow", request.token, - request.windowName); + LOG_ALWAYS_FATAL_IF(!resolvedFocusWindow, + "Focused window should be non-null when result is OK!"); + return updateFocusedWindow(displayId, "setFocusedWindow", resolvedFocusWindow->getToken(), + resolvedFocusWindow->getName()); } // The requested window is not currently focusable. Wait for the window to become focusable @@ -134,11 +124,43 @@ std::optional<FocusResolver::FocusChanges> FocusResolver::setFocusedWindow( nullptr); } +FocusResolver::Focusability FocusResolver::getResolvedFocusWindow( + const sp<IBinder>& token, const std::vector<sp<WindowInfoHandle>>& windows, + sp<WindowInfoHandle>& outFocusableWindow) { + sp<IBinder> curFocusCandidate = token; + bool focusedWindowFound = false; + + // Keep track of all windows reached to prevent a cyclical transferFocus request. + std::unordered_set<sp<IBinder>, SpHash<IBinder>> tokensReached; + + while (curFocusCandidate != nullptr && tokensReached.count(curFocusCandidate) == 0) { + tokensReached.emplace(curFocusCandidate); + Focusability result = isTokenFocusable(curFocusCandidate, windows, outFocusableWindow); + if (result == Focusability::OK) { + LOG_ALWAYS_FATAL_IF(!outFocusableWindow, + "Focused window should be non-null when result is OK!"); + focusedWindowFound = true; + // outFocusableWindow has been updated by isTokenFocusable to contain + // the window info for curFocusCandidate. See if we can grant focus + // to the token that it wants to transfer its focus to. + curFocusCandidate = outFocusableWindow->getInfo()->focusTransferTarget; + } + + // If the initial token is not focusable, return early with the failed result. + if (!focusedWindowFound) { + return result; + } + } + + return focusedWindowFound ? Focusability::OK : Focusability::NO_WINDOW; +} + FocusResolver::Focusability FocusResolver::isTokenFocusable( - const sp<IBinder>& token, const std::vector<sp<WindowInfoHandle>>& windows) { + const sp<IBinder>& token, const std::vector<sp<WindowInfoHandle>>& windows, + sp<WindowInfoHandle>& outFocusableWindow) { bool allWindowsAreFocusable = true; - bool visibleWindowFound = false; bool windowFound = false; + sp<WindowInfoHandle> visibleWindowHandle = nullptr; for (const sp<WindowInfoHandle>& window : windows) { if (window->getToken() != token) { continue; @@ -146,7 +168,7 @@ FocusResolver::Focusability FocusResolver::isTokenFocusable( windowFound = true; if (!window->getInfo()->inputConfig.test(gui::WindowInfo::InputConfig::NOT_VISIBLE)) { // Check if at least a single window is visible. - visibleWindowFound = true; + visibleWindowHandle = window; } if (window->getInfo()->inputConfig.test(gui::WindowInfo::InputConfig::NOT_FOCUSABLE)) { // Check if all windows with the window token are focusable. @@ -161,10 +183,12 @@ FocusResolver::Focusability FocusResolver::isTokenFocusable( if (!allWindowsAreFocusable) { return Focusability::NOT_FOCUSABLE; } - if (!visibleWindowFound) { + if (!visibleWindowHandle) { return Focusability::NOT_VISIBLE; } + // Only set the outFoundWindow if the window can be focused + outFocusableWindow = visibleWindowHandle; return Focusability::OK; } diff --git a/services/inputflinger/dispatcher/FocusResolver.h b/services/inputflinger/dispatcher/FocusResolver.h index 6d11a77aad..5bb157b7c6 100644 --- a/services/inputflinger/dispatcher/FocusResolver.h +++ b/services/inputflinger/dispatcher/FocusResolver.h @@ -92,7 +92,13 @@ private: // static Focusability isTokenFocusable( const sp<IBinder>& token, - const std::vector<sp<android::gui::WindowInfoHandle>>& windows); + const std::vector<sp<android::gui::WindowInfoHandle>>& windows, + sp<android::gui::WindowInfoHandle>& outFocusableWindow); + + static FocusResolver::Focusability getResolvedFocusWindow( + const sp<IBinder>& token, + const std::vector<sp<android::gui::WindowInfoHandle>>& windows, + sp<android::gui::WindowInfoHandle>& outFocusableWindow); // Focus tracking for keys, trackball, etc. A window token can be associated with one or // more InputWindowHandles. If a window is mirrored, the window and its mirror will share diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index cd427f03cf..6e2f86223f 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -31,6 +31,7 @@ #endif #include <input/InputDevice.h> #include <input/PrintTools.h> +#include <openssl/mem.h> #include <powermanager/PowerManager.h> #include <unistd.h> #include <utils/Trace.h> @@ -1862,11 +1863,12 @@ void InputDispatcher::logOutboundMotionDetails(const char* prefix, const MotionE entry.yPrecision, entry.downTime); for (uint32_t i = 0; i < entry.pointerCount; i++) { - ALOGD(" Pointer %d: id=%d, toolType=%d, " + ALOGD(" Pointer %d: id=%d, toolType=%s, " "x=%f, y=%f, pressure=%f, size=%f, " "touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, " "orientation=%f", - i, entry.pointerProperties[i].id, entry.pointerProperties[i].toolType, + i, entry.pointerProperties[i].id, + ftl::enum_string(entry.pointerProperties[i].toolType).c_str(), entry.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X), entry.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y), entry.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), @@ -4178,7 +4180,7 @@ void InputDispatcher::notifyMotion(const NotifyMotionArgs* args) { ALOGD(" Pointer %d: id=%d, toolType=%s, x=%f, y=%f, pressure=%f, size=%f, " "touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, orientation=%f", i, args->pointerProperties[i].id, - motionToolTypeToString(args->pointerProperties[i].toolType), + ftl::enum_string(args->pointerProperties[i].toolType).c_str(), args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X), args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y), args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), @@ -4629,7 +4631,7 @@ std::unique_ptr<VerifiedInputEvent> InputDispatcher::verifyInputEvent(const Inpu if (calculatedHmac == INVALID_HMAC) { return nullptr; } - if (calculatedHmac != event.getHmac()) { + if (0 != CRYPTO_memcmp(calculatedHmac.data(), event.getHmac().data(), calculatedHmac.size())) { return nullptr; } return result; diff --git a/services/inputflinger/include/InputReaderBase.h b/services/inputflinger/include/InputReaderBase.h index 841c914d60..1750c64eca 100644 --- a/services/inputflinger/include/InputReaderBase.h +++ b/services/inputflinger/include/InputReaderBase.h @@ -149,6 +149,9 @@ public: /* Get the Bluetooth address of an input device, if known. */ virtual std::optional<std::string> getBluetoothAddress(int32_t deviceId) const = 0; + + /* Sysfs node change reported. Recreate device if required to incorporate the new sysfs nodes */ + virtual void sysfsNodeChanged(const std::string& sysfsNodePath) = 0; }; // --- InputReaderConfiguration --- diff --git a/services/inputflinger/reader/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp index e65f3af107..ee8dde1d32 100644 --- a/services/inputflinger/reader/EventHub.cpp +++ b/services/inputflinger/reader/EventHub.cpp @@ -1531,6 +1531,20 @@ std::shared_ptr<const EventHub::AssociatedDevice> EventHub::obtainAssociatedDevi return associatedDevice; } +bool EventHub::AssociatedDevice::isChanged() const { + std::unordered_map<int32_t, RawBatteryInfo> newBatteryInfos = + readBatteryConfiguration(sysfsRootPath); + std::unordered_map<int32_t, RawLightInfo> newLightInfos = + readLightsConfiguration(sysfsRootPath); + std::optional<RawLayoutInfo> newLayoutInfo = readLayoutConfiguration(sysfsRootPath); + + if (newBatteryInfos == batteryInfos && newLightInfos == lightInfos && + newLayoutInfo == layoutInfo) { + return false; + } + return true; +} + void EventHub::vibrate(int32_t deviceId, const VibrationElement& element) { std::scoped_lock _l(mLock); Device* device = getDeviceLocked(deviceId); @@ -2536,6 +2550,42 @@ status_t EventHub::disableDevice(int32_t deviceId) { return device->disable(); } +// TODO(b/274755573): Shift to uevent handling on native side and remove this method +// Currently using Java UEventObserver to trigger this which uses UEvent infrastructure that uses a +// NETLINK socket to observe UEvents. We can create similar infrastructure on Eventhub side to +// directly observe UEvents instead of triggering from Java side. +void EventHub::sysfsNodeChanged(const std::string& sysfsNodePath) { + std::scoped_lock _l(mLock); + + // Check in opening devices + for (auto it = mOpeningDevices.begin(); it != mOpeningDevices.end(); it++) { + std::unique_ptr<Device>& device = *it; + if (device->associatedDevice && + sysfsNodePath.find(device->associatedDevice->sysfsRootPath.string()) != + std::string::npos && + device->associatedDevice->isChanged()) { + it = mOpeningDevices.erase(it); + openDeviceLocked(device->path); + } + } + + // Check in already added device + std::vector<Device*> devicesToReopen; + for (const auto& [id, device] : mDevices) { + if (device->associatedDevice && + sysfsNodePath.find(device->associatedDevice->sysfsRootPath.string()) != + std::string::npos && + device->associatedDevice->isChanged()) { + devicesToReopen.push_back(device.get()); + } + } + for (const auto& device : devicesToReopen) { + closeDeviceLocked(*device); + openDeviceLocked(device->path); + } + devicesToReopen.clear(); +} + void EventHub::createVirtualKeyboardLocked() { InputDeviceIdentifier identifier; identifier.name = "Virtual"; diff --git a/services/inputflinger/reader/InputReader.cpp b/services/inputflinger/reader/InputReader.cpp index 9080cc1d26..81ac03b7b3 100644 --- a/services/inputflinger/reader/InputReader.cpp +++ b/services/inputflinger/reader/InputReader.cpp @@ -928,6 +928,10 @@ bool InputReader::canDispatchToDisplay(int32_t deviceId, int32_t displayId) { return *associatedDisplayId == displayId; } +void InputReader::sysfsNodeChanged(const std::string& sysfsNodePath) { + mEventHub->sysfsNodeChanged(sysfsNodePath); +} + void InputReader::dump(std::string& dump) { std::scoped_lock _l(mLock); diff --git a/services/inputflinger/reader/include/EventHub.h b/services/inputflinger/reader/include/EventHub.h index 0b15efed12..20612c767c 100644 --- a/services/inputflinger/reader/include/EventHub.h +++ b/services/inputflinger/reader/include/EventHub.h @@ -388,6 +388,10 @@ public: /* Disable an input device. Closes file descriptor to that device. */ virtual status_t disableDevice(int32_t deviceId) = 0; + + /* Sysfs node changed. Reopen the Eventhub device if any new Peripheral like Light, Battery, + * etc. is detected. */ + virtual void sysfsNodeChanged(const std::string& sysfsNodePath) = 0; }; template <std::size_t BITS> @@ -567,6 +571,8 @@ public: status_t disableDevice(int32_t deviceId) override final; + void sysfsNodeChanged(const std::string& sysfsNodePath) override final; + ~EventHub() override; private: @@ -578,6 +584,7 @@ private: std::unordered_map<int32_t /*lightId*/, RawLightInfo> lightInfos; std::optional<RawLayoutInfo> layoutInfo; + bool isChanged() const; bool operator==(const AssociatedDevice&) const = default; bool operator!=(const AssociatedDevice&) const = default; std::string dump() const; diff --git a/services/inputflinger/reader/include/InputReader.h b/services/inputflinger/reader/include/InputReader.h index e9c989a224..120e15070c 100644 --- a/services/inputflinger/reader/include/InputReader.h +++ b/services/inputflinger/reader/include/InputReader.h @@ -117,6 +117,8 @@ public: std::optional<std::string> getBluetoothAddress(int32_t deviceId) const override; + void sysfsNodeChanged(const std::string& sysfsNodePath) override; + protected: // These members are protected so they can be instrumented by test cases. virtual std::shared_ptr<InputDevice> createDeviceLocked(int32_t deviceId, diff --git a/services/inputflinger/reader/include/StylusState.h b/services/inputflinger/reader/include/StylusState.h index ff15e0c660..d042784c9e 100644 --- a/services/inputflinger/reader/include/StylusState.h +++ b/services/inputflinger/reader/include/StylusState.h @@ -33,8 +33,8 @@ struct StylusState { std::optional<float> pressure{}; /* The state of the stylus buttons as a bitfield (e.g. AMOTION_EVENT_BUTTON_SECONDARY). */ uint32_t buttons{}; - /* Which tool type the stylus is currently using (e.g. AMOTION_EVENT_TOOL_TYPE_ERASER). */ - int32_t toolType{AMOTION_EVENT_TOOL_TYPE_UNKNOWN}; + /* Which tool type the stylus is currently using (e.g. ToolType::ERASER). */ + ToolType toolType{ToolType::UNKNOWN}; void clear() { *this = StylusState{}; } }; diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.cpp b/services/inputflinger/reader/mapper/CursorInputMapper.cpp index 83cf28798c..a3fdcdf19d 100644 --- a/services/inputflinger/reader/mapper/CursorInputMapper.cpp +++ b/services/inputflinger/reader/mapper/CursorInputMapper.cpp @@ -350,7 +350,7 @@ std::list<NotifyArgs> CursorInputMapper::sync(nsecs_t when, nsecs_t readTime) { PointerProperties pointerProperties; pointerProperties.clear(); pointerProperties.id = 0; - pointerProperties.toolType = AMOTION_EVENT_TOOL_TYPE_MOUSE; + pointerProperties.toolType = ToolType::MOUSE; PointerCoords pointerCoords; pointerCoords.clear(); diff --git a/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp b/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp index a44d15bcdf..99e6cf9a74 100644 --- a/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp +++ b/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp @@ -77,8 +77,8 @@ std::list<NotifyArgs> ExternalStylusInputMapper::sync(nsecs_t when) { mStylusState.when = when; mStylusState.toolType = mTouchButtonAccumulator.getToolType(); - if (mStylusState.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { - mStylusState.toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + if (mStylusState.toolType == ToolType::UNKNOWN) { + mStylusState.toolType = ToolType::STYLUS; } if (mRawPressureAxis.valid) { diff --git a/services/inputflinger/reader/mapper/JoystickInputMapper.cpp b/services/inputflinger/reader/mapper/JoystickInputMapper.cpp index 7724cf7ed5..f65cdcb677 100644 --- a/services/inputflinger/reader/mapper/JoystickInputMapper.cpp +++ b/services/inputflinger/reader/mapper/JoystickInputMapper.cpp @@ -321,7 +321,7 @@ std::list<NotifyArgs> JoystickInputMapper::sync(nsecs_t when, nsecs_t readTime, PointerProperties pointerProperties; pointerProperties.clear(); pointerProperties.id = 0; - pointerProperties.toolType = AMOTION_EVENT_TOOL_TYPE_UNKNOWN; + pointerProperties.toolType = ToolType::UNKNOWN; PointerCoords pointerCoords; pointerCoords.clear(); diff --git a/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp b/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp index 33e72c7c6f..e87128825d 100644 --- a/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp @@ -77,7 +77,7 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { continue; } - if (inSlot.getToolType() == AMOTION_EVENT_TOOL_TYPE_PALM) { + if (inSlot.getToolType() == ToolType::PALM) { std::optional<int32_t> id = getActiveBitId(inSlot); if (id) { outState->rawPointerData.canceledIdBits.markBit(id.value()); @@ -112,12 +112,12 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { outPointer.tiltY = 0; outPointer.toolType = inSlot.getToolType(); - if (outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { + if (outPointer.toolType == ToolType::UNKNOWN) { outPointer.toolType = mTouchButtonAccumulator.getToolType(); - if (outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { - outPointer.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + if (outPointer.toolType == ToolType::UNKNOWN) { + outPointer.toolType = ToolType::FINGER; } - } else if (outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS && !mStylusMtToolSeen) { + } else if (outPointer.toolType == ToolType::STYLUS && !mStylusMtToolSeen) { mStylusMtToolSeen = true; // The multi-touch device produced a stylus event with MT_TOOL_PEN. Dynamically // re-configure this input device so that we add SOURCE_STYLUS if we haven't already. @@ -130,12 +130,11 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { bumpGeneration(); } } - if (shouldSimulateStylusWithTouch() && - outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_FINGER) { - outPointer.toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + if (shouldSimulateStylusWithTouch() && outPointer.toolType == ToolType::FINGER) { + outPointer.toolType = ToolType::STYLUS; } - bool isHovering = mTouchButtonAccumulator.getToolType() != AMOTION_EVENT_TOOL_TYPE_MOUSE && + bool isHovering = mTouchButtonAccumulator.getToolType() != ToolType::MOUSE && (mTouchButtonAccumulator.isHovering() || (mRawPointerAxes.pressure.valid && inSlot.getPressure() <= 0)); outPointer.isHovering = isHovering; diff --git a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp index 94cc1457a9..c0a35b196e 100644 --- a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp +++ b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp @@ -121,7 +121,7 @@ std::list<NotifyArgs> RotaryEncoderInputMapper::sync(nsecs_t when, nsecs_t readT PointerProperties pointerProperties; pointerProperties.clear(); pointerProperties.id = 0; - pointerProperties.toolType = AMOTION_EVENT_TOOL_TYPE_UNKNOWN; + pointerProperties.toolType = ToolType::UNKNOWN; uint32_t policyFlags = 0; if (getDeviceContext().isExternal()) { diff --git a/services/inputflinger/reader/mapper/SingleTouchInputMapper.cpp b/services/inputflinger/reader/mapper/SingleTouchInputMapper.cpp index 13ad224111..f13417a93b 100644 --- a/services/inputflinger/reader/mapper/SingleTouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/SingleTouchInputMapper.cpp @@ -41,7 +41,7 @@ void SingleTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { outState->rawPointerData.pointerCount = 1; outState->rawPointerData.idToIndex[0] = 0; - bool isHovering = mTouchButtonAccumulator.getToolType() != AMOTION_EVENT_TOOL_TYPE_MOUSE && + bool isHovering = mTouchButtonAccumulator.getToolType() != ToolType::MOUSE && (mTouchButtonAccumulator.isHovering() || (mRawPointerAxes.pressure.valid && mSingleTouchMotionAccumulator.getAbsolutePressure() <= 0)); @@ -61,8 +61,8 @@ void SingleTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { outPointer.tiltX = mSingleTouchMotionAccumulator.getAbsoluteTiltX(); outPointer.tiltY = mSingleTouchMotionAccumulator.getAbsoluteTiltY(); outPointer.toolType = mTouchButtonAccumulator.getToolType(); - if (outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { - outPointer.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + if (outPointer.toolType == ToolType::UNKNOWN) { + outPointer.toolType = ToolType::FINGER; } outPointer.isHovering = isHovering; } diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp index df7ba49b4d..073c18babb 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp @@ -229,11 +229,12 @@ void TouchInputMapper::dump(std::string& dump) { dump += StringPrintf(INDENT4 "[%d]: id=%d, x=%d, y=%d, pressure=%d, " "touchMajor=%d, touchMinor=%d, toolMajor=%d, toolMinor=%d, " "orientation=%d, tiltX=%d, tiltY=%d, distance=%d, " - "toolType=%d, isHovering=%s\n", + "toolType=%s, isHovering=%s\n", i, pointer.id, pointer.x, pointer.y, pointer.pressure, pointer.touchMajor, pointer.touchMinor, pointer.toolMajor, pointer.toolMinor, pointer.orientation, pointer.tiltX, pointer.tiltY, - pointer.distance, pointer.toolType, toString(pointer.isHovering)); + pointer.distance, ftl::enum_string(pointer.toolType).c_str(), + toString(pointer.isHovering)); } dump += StringPrintf(INDENT3 "Last Cooked Button State: 0x%08x\n", @@ -248,7 +249,7 @@ void TouchInputMapper::dump(std::string& dump) { "pressure=%0.3f, touchMajor=%0.3f, touchMinor=%0.3f, " "toolMajor=%0.3f, toolMinor=%0.3f, " "orientation=%0.3f, tilt=%0.3f, distance=%0.3f, " - "toolType=%d, isHovering=%s\n", + "toolType=%s, isHovering=%s\n", i, pointerProperties.id, pointerCoords.getX(), pointerCoords.getY(), pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X), pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y), @@ -260,7 +261,7 @@ void TouchInputMapper::dump(std::string& dump) { pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION), pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TILT), pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_DISTANCE), - pointerProperties.toolType, + ftl::enum_string(pointerProperties.toolType).c_str(), toString(mLastCookedState.cookedPointerData.isHovering(i))); } @@ -1582,10 +1583,10 @@ std::list<NotifyArgs> TouchInputMapper::cookAndDispatch(nsecs_t when, nsecs_t re mCurrentRawState.rawPointerData.pointerForId(id); if (isStylusToolType(pointer.toolType)) { mCurrentCookedState.stylusIdBits.markBit(id); - } else if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_FINGER || - pointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { + } else if (pointer.toolType == ToolType::FINGER || + pointer.toolType == ToolType::UNKNOWN) { mCurrentCookedState.fingerIdBits.markBit(id); - } else if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_MOUSE) { + } else if (pointer.toolType == ToolType::MOUSE) { mCurrentCookedState.mouseIdBits.markBit(id); } } @@ -1704,7 +1705,7 @@ void TouchInputMapper::applyExternalStylusTouchState(nsecs_t when) { PointerCoords& coords = currentPointerData.editPointerCoordsWithId(*mFusedStylusPointerId); coords.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pressure); - if (mExternalStylusState.toolType != AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { + if (mExternalStylusState.toolType != ToolType::UNKNOWN) { PointerProperties& properties = currentPointerData.editPointerPropertiesWithId(*mFusedStylusPointerId); properties.toolType = mExternalStylusState.toolType; @@ -2678,7 +2679,7 @@ std::list<NotifyArgs> TouchInputMapper::dispatchPointerGestures(nsecs_t when, ns PointerProperties pointerProperties; pointerProperties.clear(); pointerProperties.id = 0; - pointerProperties.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + pointerProperties.toolType = ToolType::FINGER; PointerCoords pointerCoords; pointerCoords.clear(); @@ -2887,7 +2888,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi mPointerGesture.currentGestureIdToIndex[mPointerGesture.activeGestureId] = 0; mPointerGesture.currentGestureProperties[0].clear(); mPointerGesture.currentGestureProperties[0].id = mPointerGesture.activeGestureId; - mPointerGesture.currentGestureProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + mPointerGesture.currentGestureProperties[0].toolType = ToolType::FINGER; mPointerGesture.currentGestureCoords[0].clear(); mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x); mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y); @@ -2922,8 +2923,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi mPointerGesture.currentGestureProperties[0].clear(); mPointerGesture.currentGestureProperties[0].id = mPointerGesture.activeGestureId; - mPointerGesture.currentGestureProperties[0].toolType = - AMOTION_EVENT_TOOL_TYPE_FINGER; + mPointerGesture.currentGestureProperties[0].toolType = ToolType::FINGER; mPointerGesture.currentGestureCoords[0].clear(); mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, mPointerGesture.tapX); @@ -3010,7 +3010,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi mPointerGesture.currentGestureIdToIndex[mPointerGesture.activeGestureId] = 0; mPointerGesture.currentGestureProperties[0].clear(); mPointerGesture.currentGestureProperties[0].id = mPointerGesture.activeGestureId; - mPointerGesture.currentGestureProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + mPointerGesture.currentGestureProperties[0].toolType = ToolType::FINGER; mPointerGesture.currentGestureCoords[0].clear(); mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x); mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y); @@ -3040,9 +3040,10 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi uint32_t index = mPointerGesture.currentGestureIdToIndex[id]; const PointerProperties& properties = mPointerGesture.currentGestureProperties[index]; const PointerCoords& coords = mPointerGesture.currentGestureCoords[index]; - ALOGD(" currentGesture[%d]: index=%d, toolType=%d, " + ALOGD(" currentGesture[%d]: index=%d, toolType=%s, " "x=%0.3f, y=%0.3f, pressure=%0.3f", - id, index, properties.toolType, coords.getAxisValue(AMOTION_EVENT_AXIS_X), + id, index, ftl::enum_string(properties.toolType).c_str(), + coords.getAxisValue(AMOTION_EVENT_AXIS_X), coords.getAxisValue(AMOTION_EVENT_AXIS_Y), coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE)); } @@ -3051,9 +3052,10 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi uint32_t index = mPointerGesture.lastGestureIdToIndex[id]; const PointerProperties& properties = mPointerGesture.lastGestureProperties[index]; const PointerCoords& coords = mPointerGesture.lastGestureCoords[index]; - ALOGD(" lastGesture[%d]: index=%d, toolType=%d, " + ALOGD(" lastGesture[%d]: index=%d, toolType=%s, " "x=%0.3f, y=%0.3f, pressure=%0.3f", - id, index, properties.toolType, coords.getAxisValue(AMOTION_EVENT_AXIS_X), + id, index, ftl::enum_string(properties.toolType).c_str(), + coords.getAxisValue(AMOTION_EVENT_AXIS_X), coords.getAxisValue(AMOTION_EVENT_AXIS_Y), coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE)); } @@ -3342,7 +3344,7 @@ void TouchInputMapper::prepareMultiFingerPointerGestures(nsecs_t when, bool* can mPointerGesture.currentGestureIdToIndex[mPointerGesture.activeGestureId] = 0; mPointerGesture.currentGestureProperties[0].clear(); mPointerGesture.currentGestureProperties[0].id = mPointerGesture.activeGestureId; - mPointerGesture.currentGestureProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + mPointerGesture.currentGestureProperties[0].toolType = ToolType::FINGER; mPointerGesture.currentGestureCoords[0].clear(); mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, mPointerGesture.referenceGestureX); @@ -3435,7 +3437,7 @@ void TouchInputMapper::prepareMultiFingerPointerGestures(nsecs_t when, bool* can mPointerGesture.currentGestureProperties[i].clear(); mPointerGesture.currentGestureProperties[i].id = gestureId; - mPointerGesture.currentGestureProperties[i].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + mPointerGesture.currentGestureProperties[i].toolType = ToolType::FINGER; mPointerGesture.currentGestureCoords[i].clear(); mPointerGesture.currentGestureCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, mPointerGesture.referenceGestureX + diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.h b/services/inputflinger/reader/mapper/TouchInputMapper.h index ae7faa9909..bc358b97e6 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.h +++ b/services/inputflinger/reader/mapper/TouchInputMapper.h @@ -78,8 +78,8 @@ struct RawPointerData { int32_t distance{}; int32_t tiltX{}; int32_t tiltY{}; - // A fully decoded AMOTION_EVENT_TOOL_TYPE constant. - int32_t toolType{AMOTION_EVENT_TOOL_TYPE_UNKNOWN}; + // A fully decoded ToolType constant. + ToolType toolType{ToolType::UNKNOWN}; bool isHovering{false}; }; diff --git a/services/inputflinger/reader/mapper/accumulator/MultiTouchMotionAccumulator.cpp b/services/inputflinger/reader/mapper/accumulator/MultiTouchMotionAccumulator.cpp index f6a42bdea0..f70be72741 100644 --- a/services/inputflinger/reader/mapper/accumulator/MultiTouchMotionAccumulator.cpp +++ b/services/inputflinger/reader/mapper/accumulator/MultiTouchMotionAccumulator.cpp @@ -154,18 +154,18 @@ void MultiTouchMotionAccumulator::warnIfNotInUse(const RawEvent& event, const Sl // --- MultiTouchMotionAccumulator::Slot --- -int32_t MultiTouchMotionAccumulator::Slot::getToolType() const { +ToolType MultiTouchMotionAccumulator::Slot::getToolType() const { if (mHaveAbsMtToolType) { switch (mAbsMtToolType) { case MT_TOOL_FINGER: - return AMOTION_EVENT_TOOL_TYPE_FINGER; + return ToolType::FINGER; case MT_TOOL_PEN: - return AMOTION_EVENT_TOOL_TYPE_STYLUS; + return ToolType::STYLUS; case MT_TOOL_PALM: - return AMOTION_EVENT_TOOL_TYPE_PALM; + return ToolType::PALM; } } - return AMOTION_EVENT_TOOL_TYPE_UNKNOWN; + return ToolType::UNKNOWN; } } // namespace android diff --git a/services/inputflinger/reader/mapper/accumulator/MultiTouchMotionAccumulator.h b/services/inputflinger/reader/mapper/accumulator/MultiTouchMotionAccumulator.h index 3c1a2a9e64..943dde5ca2 100644 --- a/services/inputflinger/reader/mapper/accumulator/MultiTouchMotionAccumulator.h +++ b/services/inputflinger/reader/mapper/accumulator/MultiTouchMotionAccumulator.h @@ -45,7 +45,7 @@ public: inline int32_t getTrackingId() const { return mAbsMtTrackingId; } inline int32_t getPressure() const { return mAbsMtPressure; } inline int32_t getDistance() const { return mAbsMtDistance; } - int32_t getToolType() const; + ToolType getToolType() const; private: friend class MultiTouchMotionAccumulator; diff --git a/services/inputflinger/reader/mapper/accumulator/TouchButtonAccumulator.cpp b/services/inputflinger/reader/mapper/accumulator/TouchButtonAccumulator.cpp index 6b84f32db2..8c4bed3267 100644 --- a/services/inputflinger/reader/mapper/accumulator/TouchButtonAccumulator.cpp +++ b/services/inputflinger/reader/mapper/accumulator/TouchButtonAccumulator.cpp @@ -141,21 +141,21 @@ uint32_t TouchButtonAccumulator::getButtonState() const { return result; } -int32_t TouchButtonAccumulator::getToolType() const { +ToolType TouchButtonAccumulator::getToolType() const { if (mBtnToolMouse || mBtnToolLens) { - return AMOTION_EVENT_TOOL_TYPE_MOUSE; + return ToolType::MOUSE; } if (mBtnToolRubber) { - return AMOTION_EVENT_TOOL_TYPE_ERASER; + return ToolType::ERASER; } if (mBtnToolPen || mBtnToolBrush || mBtnToolPencil || mBtnToolAirbrush) { - return AMOTION_EVENT_TOOL_TYPE_STYLUS; + return ToolType::STYLUS; } if (mBtnToolFinger || mBtnToolDoubleTap || mBtnToolTripleTap || mBtnToolQuadTap || mBtnToolQuintTap) { - return AMOTION_EVENT_TOOL_TYPE_FINGER; + return ToolType::FINGER; } - return AMOTION_EVENT_TOOL_TYPE_UNKNOWN; + return ToolType::UNKNOWN; } bool TouchButtonAccumulator::isToolActive() const { diff --git a/services/inputflinger/reader/mapper/accumulator/TouchButtonAccumulator.h b/services/inputflinger/reader/mapper/accumulator/TouchButtonAccumulator.h index c2aa2adc0f..c5fd5f5168 100644 --- a/services/inputflinger/reader/mapper/accumulator/TouchButtonAccumulator.h +++ b/services/inputflinger/reader/mapper/accumulator/TouchButtonAccumulator.h @@ -36,7 +36,7 @@ public: void process(const RawEvent* rawEvent); uint32_t getButtonState() const; - int32_t getToolType() const; + ToolType getToolType() const; bool isToolActive() const; bool isHovering() const; bool hasStylus() const; diff --git a/services/inputflinger/reader/mapper/gestures/GestureConverter.h b/services/inputflinger/reader/mapper/gestures/GestureConverter.h index 2714d03ea3..70e8fb7758 100644 --- a/services/inputflinger/reader/mapper/gestures/GestureConverter.h +++ b/services/inputflinger/reader/mapper/gestures/GestureConverter.h @@ -99,10 +99,10 @@ private: // We never need any PointerProperties other than the finger tool type, so we can just keep a // const array of them. const std::array<PointerProperties, MAX_FAKE_FINGERS> mFingerProps = {{ - {.id = 0, .toolType = AMOTION_EVENT_TOOL_TYPE_FINGER}, - {.id = 1, .toolType = AMOTION_EVENT_TOOL_TYPE_FINGER}, - {.id = 2, .toolType = AMOTION_EVENT_TOOL_TYPE_FINGER}, - {.id = 3, .toolType = AMOTION_EVENT_TOOL_TYPE_FINGER}, + {.id = 0, .toolType = ToolType::FINGER}, + {.id = 1, .toolType = ToolType::FINGER}, + {.id = 2, .toolType = ToolType::FINGER}, + {.id = 3, .toolType = ToolType::FINGER}, }}; std::array<PointerCoords, MAX_FAKE_FINGERS> mFakeFingerCoords = {}; diff --git a/services/inputflinger/reader/mapper/gestures/HardwareStateConverter.cpp b/services/inputflinger/reader/mapper/gestures/HardwareStateConverter.cpp index d344babe72..e89262a71a 100644 --- a/services/inputflinger/reader/mapper/gestures/HardwareStateConverter.cpp +++ b/services/inputflinger/reader/mapper/gestures/HardwareStateConverter.cpp @@ -85,7 +85,7 @@ SelfContainedHardwareState HardwareStateConverter::produceHardwareState(nsecs_t MultiTouchMotionAccumulator::Slot slot = mMotionAccumulator.getSlot(i); // Some touchpads continue to report contacts even after they've identified them as palms. // We want to exclude these contacts from the HardwareStates. - if (!slot.isInUse() || slot.getToolType() == AMOTION_EVENT_TOOL_TYPE_PALM) { + if (!slot.isInUse() || slot.getToolType() == ToolType::PALM) { continue; } diff --git a/services/inputflinger/tests/FakeEventHub.cpp b/services/inputflinger/tests/FakeEventHub.cpp index ff6d584007..4626f5add7 100644 --- a/services/inputflinger/tests/FakeEventHub.cpp +++ b/services/inputflinger/tests/FakeEventHub.cpp @@ -594,4 +594,33 @@ std::optional<std::unordered_map<LightColor, int32_t>> FakeEventHub::getLightInt return lightIt->second; }; +void FakeEventHub::setSysfsRootPath(int32_t deviceId, std::string sysfsRootPath) const { + Device* device = getDevice(deviceId); + if (device == nullptr) { + return; + } + device->sysfsRootPath = sysfsRootPath; +} + +void FakeEventHub::sysfsNodeChanged(const std::string& sysfsNodePath) { + int32_t foundDeviceId = -1; + Device* foundDevice = nullptr; + for (size_t i = 0; i < mDevices.size(); i++) { + Device* d = mDevices.valueAt(i); + if (sysfsNodePath.find(d->sysfsRootPath) != std::string::npos) { + foundDeviceId = mDevices.keyAt(i); + foundDevice = d; + } + } + if (foundDevice == nullptr) { + return; + } + // If device sysfs changed -> reopen the device + if (!mRawLightInfos.empty() && !foundDevice->classes.test(InputDeviceClass::LIGHT)) { + removeDevice(foundDeviceId); + addDevice(foundDeviceId, foundDevice->identifier.name, + foundDevice->classes | InputDeviceClass::LIGHT, foundDevice->identifier.bus); + } +} + } // namespace android diff --git a/services/inputflinger/tests/FakeEventHub.h b/services/inputflinger/tests/FakeEventHub.h index e0a3f9eee1..8e06940aec 100644 --- a/services/inputflinger/tests/FakeEventHub.h +++ b/services/inputflinger/tests/FakeEventHub.h @@ -64,6 +64,7 @@ class FakeEventHub : public EventHubInterface { std::vector<VirtualKeyDefinition> virtualKeys; bool enabled; std::optional<RawLayoutInfo> layoutInfo; + std::string sysfsRootPath; status_t enable() { enabled = true; @@ -152,6 +153,7 @@ public: void enqueueEvent(nsecs_t when, nsecs_t readTime, int32_t deviceId, int32_t type, int32_t code, int32_t value); void assertQueueIsEmpty(); + void setSysfsRootPath(int32_t deviceId, std::string sysfsRootPath) const; private: Device* getDevice(int32_t deviceId) const; @@ -212,7 +214,7 @@ private: std::optional<int32_t> getLightBrightness(int32_t deviceId, int32_t lightId) const override; std::optional<std::unordered_map<LightColor, int32_t>> getLightIntensities( int32_t deviceId, int32_t lightId) const override; - + void sysfsNodeChanged(const std::string& sysfsNodePath) override; void dump(std::string&) const override {} void monitor() const override {} void requestReopenDevices() override {} diff --git a/services/inputflinger/tests/FocusResolver_test.cpp b/services/inputflinger/tests/FocusResolver_test.cpp index ccdb37afb0..5440a98db6 100644 --- a/services/inputflinger/tests/FocusResolver_test.cpp +++ b/services/inputflinger/tests/FocusResolver_test.cpp @@ -237,7 +237,7 @@ TEST(FocusResolverTest, FocusRequestsArePersistent) { ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ windowToken); } -TEST(FocusResolverTest, ConditionalFocusRequestsAreNotPersistent) { +TEST(FocusResolverTest, FocusTransferTarget) { sp<IBinder> hostWindowToken = sp<BBinder>::make(); std::vector<sp<WindowInfoHandle>> windows; @@ -247,47 +247,117 @@ TEST(FocusResolverTest, ConditionalFocusRequestsAreNotPersistent) { windows.push_back(hostWindow); sp<IBinder> embeddedWindowToken = sp<BBinder>::make(); sp<FakeWindowHandle> embeddedWindow = - sp<FakeWindowHandle>::make("Embedded Window", embeddedWindowToken, /*focusable=*/true, + sp<FakeWindowHandle>::make("Embedded Window", embeddedWindowToken, /*focusable=*/false, /*visible=*/true); windows.push_back(embeddedWindow); FocusRequest request; request.displayId = 42; request.token = hostWindowToken; + + // Host wants to transfer touch to embedded. + hostWindow->editInfo()->focusTransferTarget = embeddedWindowToken; + FocusResolver focusResolver; std::optional<FocusResolver::FocusChanges> changes = focusResolver.setFocusedWindow(request, windows); + // Embedded was not focusable so host gains focus. ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ hostWindowToken); - request.focusedToken = hostWindow->getToken(); - request.token = embeddedWindowToken; - changes = focusResolver.setFocusedWindow(request, windows); + // Embedded is now focusable so will gain focus + embeddedWindow->setFocusable(true); + changes = focusResolver.setInputWindows(request.displayId, windows); ASSERT_FOCUS_CHANGE(changes, /*from*/ hostWindowToken, /*to*/ embeddedWindowToken); - embeddedWindow->setFocusable(false); + // Embedded is not visible so host will get focus + embeddedWindow->setVisible(false); changes = focusResolver.setInputWindows(request.displayId, windows); - // The embedded window is no longer focusable, provide focus back to the original focused - // window. ASSERT_FOCUS_CHANGE(changes, /*from*/ embeddedWindowToken, /*to*/ hostWindowToken); - embeddedWindow->setFocusable(true); + // Embedded is now visible so will get focus + embeddedWindow->setVisible(true); changes = focusResolver.setInputWindows(request.displayId, windows); - // The embedded window is focusable again, but we it cannot gain focus unless there is another - // focus request. - ASSERT_FALSE(changes); + ASSERT_FOCUS_CHANGE(changes, /*from*/ hostWindowToken, /*to*/ embeddedWindowToken); - embeddedWindow->setVisible(false); - changes = focusResolver.setFocusedWindow(request, windows); - // If the embedded window is not visible/focusable, then we do not grant it focus and the - // request is dropped. - ASSERT_FALSE(changes); + // Remove focusTransferTarget from host. Host will gain focus. + hostWindow->editInfo()->focusTransferTarget = nullptr; + changes = focusResolver.setInputWindows(request.displayId, windows); + ASSERT_FOCUS_CHANGE(changes, /*from*/ embeddedWindowToken, /*to*/ hostWindowToken); - embeddedWindow->setVisible(true); + // Set invalid token for focusTransferTarget. Host will remain focus + hostWindow->editInfo()->focusTransferTarget = sp<BBinder>::make(); changes = focusResolver.setInputWindows(request.displayId, windows); - // If the embedded window becomes visble/focusable, nothing changes since the request has been - // dropped. ASSERT_FALSE(changes); } + +TEST(FocusResolverTest, FocusTransferMultipleInChain) { + sp<IBinder> hostWindowToken = sp<BBinder>::make(); + std::vector<sp<WindowInfoHandle>> windows; + + sp<FakeWindowHandle> hostWindow = + sp<FakeWindowHandle>::make("Host Window", hostWindowToken, /*focusable=*/true, + /*visible=*/true); + windows.push_back(hostWindow); + sp<IBinder> embeddedWindowToken = sp<BBinder>::make(); + sp<FakeWindowHandle> embeddedWindow = + sp<FakeWindowHandle>::make("Embedded Window", embeddedWindowToken, /*focusable=*/true, + /*visible=*/true); + windows.push_back(embeddedWindow); + + sp<IBinder> embeddedWindowToken2 = sp<BBinder>::make(); + sp<FakeWindowHandle> embeddedWindow2 = + sp<FakeWindowHandle>::make("Embedded Window2", embeddedWindowToken2, /*focusable=*/true, + /*visible=*/true); + windows.push_back(embeddedWindow2); + + FocusRequest request; + request.displayId = 42; + request.token = hostWindowToken; + + hostWindow->editInfo()->focusTransferTarget = embeddedWindowToken; + embeddedWindow->editInfo()->focusTransferTarget = embeddedWindowToken2; + + FocusResolver focusResolver; + std::optional<FocusResolver::FocusChanges> changes = + focusResolver.setFocusedWindow(request, windows); + ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ embeddedWindowToken2); +} + +TEST(FocusResolverTest, FocusTransferTargetCycle) { + sp<IBinder> hostWindowToken = sp<BBinder>::make(); + std::vector<sp<WindowInfoHandle>> windows; + + sp<FakeWindowHandle> hostWindow = + sp<FakeWindowHandle>::make("Host Window", hostWindowToken, /*focusable=*/true, + /*visible=*/true); + windows.push_back(hostWindow); + sp<IBinder> embeddedWindowToken = sp<BBinder>::make(); + sp<FakeWindowHandle> embeddedWindow = + sp<FakeWindowHandle>::make("Embedded Window", embeddedWindowToken, /*focusable=*/true, + /*visible=*/true); + windows.push_back(embeddedWindow); + + sp<IBinder> embeddedWindowToken2 = sp<BBinder>::make(); + sp<FakeWindowHandle> embeddedWindow2 = + sp<FakeWindowHandle>::make("Embedded Window2", embeddedWindowToken2, /*focusable=*/true, + /*visible=*/true); + windows.push_back(embeddedWindow2); + + FocusRequest request; + request.displayId = 42; + request.token = hostWindowToken; + + hostWindow->editInfo()->focusTransferTarget = embeddedWindowToken; + embeddedWindow->editInfo()->focusTransferTarget = embeddedWindowToken2; + embeddedWindow2->editInfo()->focusTransferTarget = hostWindowToken; + + FocusResolver focusResolver; + std::optional<FocusResolver::FocusChanges> changes = + focusResolver.setFocusedWindow(request, windows); + // Cycle will be detected and stop right before trying to transfer token to host again. + ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ embeddedWindowToken2); +} + TEST(FocusResolverTest, FocusRequestsAreClearedWhenWindowIsRemoved) { sp<IBinder> windowToken = sp<BBinder>::make(); std::vector<sp<WindowInfoHandle>> windows; diff --git a/services/inputflinger/tests/GestureConverter_test.cpp b/services/inputflinger/tests/GestureConverter_test.cpp index 33f404d56b..c6d541e962 100644 --- a/services/inputflinger/tests/GestureConverter_test.cpp +++ b/services/inputflinger/tests/GestureConverter_test.cpp @@ -93,7 +93,7 @@ TEST_F(GestureConverterTest, Move) { ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), WithButtonState(0), + WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f))); ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10)); @@ -111,7 +111,7 @@ TEST_F(GestureConverterTest, Move_Rotated) { ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(POINTER_X + 10, POINTER_Y + 5), WithRelativeMotion(10, 5), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), WithButtonState(0), + WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f))); ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X + 10, POINTER_Y + 5)); @@ -133,14 +133,14 @@ TEST_F(GestureConverterTest, ButtonsChange) { WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), @@ -148,7 +148,7 @@ TEST_F(GestureConverterTest, ButtonsChange) { WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); // Then release the left button Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, @@ -162,7 +162,7 @@ TEST_F(GestureConverterTest, ButtonsChange) { WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); // Finally release the right button Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, @@ -175,12 +175,12 @@ TEST_F(GestureConverterTest, ButtonsChange) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); } TEST_F(GestureConverterTest, DragWithButton) { @@ -198,14 +198,14 @@ TEST_F(GestureConverterTest, DragWithButton) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); // Move Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); @@ -215,7 +215,7 @@ TEST_F(GestureConverterTest, DragWithButton) { ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), + WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f))); ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10)); @@ -231,12 +231,12 @@ TEST_F(GestureConverterTest, DragWithButton) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0), WithCoords(POINTER_X - 5, POINTER_Y + 10), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0), WithCoords(POINTER_X - 5, POINTER_Y + 10), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); } TEST_F(GestureConverterTest, Scroll) { @@ -252,7 +252,7 @@ TEST_F(GestureConverterTest, Scroll) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y), WithGestureScrollDistance(0, 0, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), WithDownTime(downTime), + WithToolType(ToolType::FINGER), WithDownTime(downTime), WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))); args.pop_front(); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), @@ -260,7 +260,7 @@ TEST_F(GestureConverterTest, Scroll) { WithCoords(POINTER_X, POINTER_Y - 10), WithGestureScrollDistance(0, 10, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), + WithToolType(ToolType::FINGER), WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))); Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); @@ -271,7 +271,7 @@ TEST_F(GestureConverterTest, Scroll) { WithCoords(POINTER_X, POINTER_Y - 15), WithGestureScrollDistance(0, 5, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), + WithToolType(ToolType::FINGER), WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))); Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, @@ -283,7 +283,7 @@ TEST_F(GestureConverterTest, Scroll) { WithCoords(POINTER_X, POINTER_Y - 15), WithGestureScrollDistance(0, 0, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), + WithToolType(ToolType::FINGER), WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))); } @@ -301,14 +301,14 @@ TEST_F(GestureConverterTest, Scroll_Rotated) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y), WithGestureScrollDistance(0, 0, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), WithDownTime(downTime))); + WithToolType(ToolType::FINGER), WithDownTime(downTime))); args.pop_front(); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(POINTER_X - 10, POINTER_Y), WithGestureScrollDistance(0, 10, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); @@ -318,7 +318,7 @@ TEST_F(GestureConverterTest, Scroll_Rotated) { WithCoords(POINTER_X - 15, POINTER_Y), WithGestureScrollDistance(0, 5, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, GESTURES_FLING_START); @@ -329,7 +329,7 @@ TEST_F(GestureConverterTest, Scroll_Rotated) { WithCoords(POINTER_X - 15, POINTER_Y), WithGestureScrollDistance(0, 0, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); } TEST_F(GestureConverterTest, Scroll_ClearsClassificationAndOffsetsAfterGesture) { @@ -393,7 +393,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(1u), WithToolType(ToolType::FINGER))); PointerCoords finger0Start = arg.pointerCoords[0]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); @@ -402,7 +402,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(2u), WithToolType(ToolType::FINGER))); PointerCoords finger1Start = arg.pointerCoords[1]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); @@ -411,7 +411,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(3u), WithToolType(ToolType::FINGER))); PointerCoords finger2Start = arg.pointerCoords[2]; args.pop_front(); @@ -420,7 +420,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithGestureOffset(0, -0.01, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(3u), WithToolType(ToolType::FINGER))); EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); @@ -437,7 +437,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithGestureOffset(0, -0.005, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(3u), WithToolType(ToolType::FINGER))); EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); @@ -453,19 +453,19 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(3u), WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(2u), WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(1u), WithToolType(ToolType::FINGER))); } TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) { @@ -560,7 +560,7 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(1u), WithToolType(ToolType::FINGER))); PointerCoords finger0Start = arg.pointerCoords[0]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); @@ -569,7 +569,7 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(2u), WithToolType(ToolType::FINGER))); PointerCoords finger1Start = arg.pointerCoords[1]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); @@ -578,7 +578,7 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(3u), WithToolType(ToolType::FINGER))); PointerCoords finger2Start = arg.pointerCoords[2]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); @@ -587,7 +587,7 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(4u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(4u), WithToolType(ToolType::FINGER))); PointerCoords finger3Start = arg.pointerCoords[3]; args.pop_front(); @@ -596,7 +596,7 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithGestureOffset(0.01, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(4u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(4u), WithToolType(ToolType::FINGER))); EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10); EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10); EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10); @@ -615,7 +615,7 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithGestureOffset(0.005, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(4u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(4u), WithToolType(ToolType::FINGER))); EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15); EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15); EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15); @@ -633,26 +633,26 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(4u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(4u), WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(3u), WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(2u), WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(1u), WithToolType(ToolType::FINGER))); } TEST_F(GestureConverterTest, Pinch_Inwards) { @@ -668,7 +668,7 @@ TEST_F(GestureConverterTest, Pinch_Inwards) { WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | @@ -676,7 +676,7 @@ TEST_F(GestureConverterTest, Pinch_Inwards) { WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 0.8, GESTURES_ZOOM_UPDATE); @@ -688,7 +688,7 @@ TEST_F(GestureConverterTest, Pinch_Inwards) { WithGesturePinchScaleFactor(0.8f, EPSILON), WithPointerCoords(0, POINTER_X - 80, POINTER_Y), WithPointerCoords(1, POINTER_X + 80, POINTER_Y), WithPointerCount(2u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, GESTURES_ZOOM_END); @@ -699,13 +699,13 @@ TEST_F(GestureConverterTest, Pinch_Inwards) { 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); } TEST_F(GestureConverterTest, Pinch_Outwards) { @@ -721,7 +721,7 @@ TEST_F(GestureConverterTest, Pinch_Outwards) { WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | @@ -729,7 +729,7 @@ TEST_F(GestureConverterTest, Pinch_Outwards) { WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1.2, GESTURES_ZOOM_UPDATE); @@ -741,7 +741,7 @@ TEST_F(GestureConverterTest, Pinch_Outwards) { WithGesturePinchScaleFactor(1.2f, EPSILON), WithPointerCoords(0, POINTER_X - 120, POINTER_Y), WithPointerCoords(1, POINTER_X + 120, POINTER_Y), WithPointerCount(2u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, GESTURES_ZOOM_END); @@ -752,13 +752,13 @@ TEST_F(GestureConverterTest, Pinch_Outwards) { 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); } TEST_F(GestureConverterTest, Pinch_ClearsClassificationAndScaleFactorAfterGesture) { @@ -802,18 +802,18 @@ TEST_F(GestureConverterTest, ResetWithButtonPressed) { WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); } TEST_F(GestureConverterTest, ResetDuringScroll) { @@ -830,7 +830,7 @@ TEST_F(GestureConverterTest, ResetDuringScroll) { WithCoords(POINTER_X, POINTER_Y - 10), WithGestureScrollDistance(0, 0, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), + WithToolType(ToolType::FINGER), WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))); } @@ -849,19 +849,19 @@ TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) { 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(3u), WithToolType(ToolType::FINGER))); args.pop_front(); EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(2u), WithToolType(ToolType::FINGER))); args.pop_front(); EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(1u), WithToolType(ToolType::FINGER))); } TEST_F(GestureConverterTest, ResetDuringPinch) { @@ -879,13 +879,13 @@ TEST_F(GestureConverterTest, ResetDuringPinch) { 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); } } // namespace android diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index e2996437bf..fb808eb2a3 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -637,14 +637,10 @@ protected: } } - void setFocusedWindow(const sp<WindowInfoHandle>& window, - const sp<WindowInfoHandle>& focusedWindow = nullptr) { + void setFocusedWindow(const sp<WindowInfoHandle>& window) { FocusRequest request; request.token = window->getToken(); request.windowName = window->getName(); - if (focusedWindow) { - request.focusedToken = focusedWindow->getToken(); - } request.timestamp = systemTime(SYSTEM_TIME_MONOTONIC); request.displayId = window->getInfo()->displayId; mDispatcher->setFocusedWindow(request); @@ -1464,7 +1460,7 @@ static InputEventInjectionResult injectKeyUp(const std::unique_ptr<InputDispatch class PointerBuilder { public: - PointerBuilder(int32_t id, int32_t toolType) { + PointerBuilder(int32_t id, ToolType toolType) { mProperties.clear(); mProperties.id = id; mProperties.toolType = toolType; @@ -1722,7 +1718,7 @@ static InputEventInjectionResult injectMotionEvent( .eventTime(eventTime) .rawXCursorPosition(cursorPosition.x) .rawYCursorPosition(cursorPosition.y) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER) .x(position.x) .y(position.y)) .build(); @@ -1767,7 +1763,7 @@ static NotifyMotionArgs generateMotionArgs(int32_t action, int32_t source, int32 for (size_t i = 0; i < pointerCount; i++) { pointerProperties[i].clear(); pointerProperties[i].id = i; - pointerProperties[i].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + pointerProperties[i].toolType = ToolType::FINGER; pointerCoords[i].clear(); pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, points[i].x); @@ -1961,21 +1957,21 @@ TEST_F(InputDispatcherTest, CancelAfterPointer0Up) { // First touch pointer down on right window mDispatcher->notifyMotion(&( args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) .build())); // Second touch pointer down mDispatcher->notifyMotion(&( args = MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(110).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(110).y(100)) .build())); // First touch pointer lifts. The second one remains down mDispatcher->notifyMotion(&( args = MotionArgsBuilder(POINTER_0_UP, AINPUT_SOURCE_TOUCHSCREEN) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(110).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(110).y(100)) .build())); window->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); window->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); @@ -2069,8 +2065,8 @@ TEST_P(ShouldSplitTouchFixture, WallpaperWindowReceivesMultiTouch) { const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(150)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(100)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(150)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -2085,8 +2081,8 @@ TEST_P(ShouldSplitTouchFixture, WallpaperWindowReceivesMultiTouch) { MotionEventBuilder(POINTER_0_UP, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(150)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(100)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(150)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerUpEvent, INJECT_EVENT_TIMEOUT, @@ -2102,7 +2098,7 @@ TEST_P(ShouldSplitTouchFixture, WallpaperWindowReceivesMultiTouch) { .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) .pointer(PointerBuilder(/* id */ 1, - AMOTION_EVENT_TOOL_TYPE_FINGER) + ToolType::FINGER) .x(100) .y(100)) .build(), @@ -2154,8 +2150,8 @@ TEST_F(InputDispatcherTest, TwoWindows_SplitWallpaperTouch) { const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(300).y(100)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(100)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(300).y(100)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -2179,8 +2175,8 @@ TEST_F(InputDispatcherTest, TwoWindows_SplitWallpaperTouch) { const MotionEvent secondFingerMoveEvent = MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(310).y(110)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(100)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(310).y(110)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerMoveEvent, INJECT_EVENT_TIMEOUT, @@ -2274,15 +2270,15 @@ TEST_F(InputDispatcherTest, TwoPointerCancelInconsistentPolicy) { args = MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) .policyFlags(DEFAULT_POLICY_FLAGS) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) .build())); mDispatcher->notifyMotion(&( args = MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) .policyFlags(DEFAULT_POLICY_FLAGS) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(120).y(120)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(120).y(120)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); spyWindow->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); @@ -2294,8 +2290,8 @@ TEST_F(InputDispatcherTest, TwoPointerCancelInconsistentPolicy) { args = MotionArgsBuilder(AMOTION_EVENT_ACTION_CANCEL, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) .policyFlags(0) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(120).y(120)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(120).y(120)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)); window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)); @@ -2313,7 +2309,7 @@ TEST_F(InputDispatcherTest, TwoPointerCancelInconsistentPolicy) { args = MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) .policyFlags(DEFAULT_POLICY_FLAGS) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); @@ -2358,7 +2354,7 @@ TEST_F(InputDispatcherTest, HoverFromLeftToRightAndTap) { .deviceId(mouseDeviceId) .downTime(baseTime + 10) .eventTime(baseTime + 20) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(300) .y(100)) .build())); @@ -2372,7 +2368,7 @@ TEST_F(InputDispatcherTest, HoverFromLeftToRightAndTap) { .deviceId(mouseDeviceId) .downTime(baseTime + 10) .eventTime(baseTime + 30) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(110) .y(100)) .build())); @@ -2386,7 +2382,7 @@ TEST_F(InputDispatcherTest, HoverFromLeftToRightAndTap) { .deviceId(touchDeviceId) .downTime(baseTime + 40) .eventTime(baseTime + 40) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(100) .y(100)) .build())); @@ -2401,7 +2397,7 @@ TEST_F(InputDispatcherTest, HoverFromLeftToRightAndTap) { .deviceId(touchDeviceId) .downTime(baseTime + 40) .eventTime(baseTime + 50) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(100) .y(100)) .build())); @@ -2415,7 +2411,7 @@ TEST_F(InputDispatcherTest, HoverFromLeftToRightAndTap) { .deviceId(touchDeviceId) .downTime(baseTime + 60) .eventTime(baseTime + 60) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(300) .y(100)) .build())); @@ -2429,7 +2425,7 @@ TEST_F(InputDispatcherTest, HoverFromLeftToRightAndTap) { .deviceId(touchDeviceId) .downTime(baseTime + 60) .eventTime(baseTime + 70) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(300) .y(100)) .build())); @@ -2467,7 +2463,7 @@ TEST_F(InputDispatcherTest, MultiDeviceSplitTouch) { mDispatcher->notifyMotion(&( args = MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) .deviceId(mouseDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) .build())); leftWindow->consumeMotionEvent( AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId))); @@ -2477,7 +2473,7 @@ TEST_F(InputDispatcherTest, MultiDeviceSplitTouch) { args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) .deviceId(mouseDeviceId) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) .build())); leftWindow->consumeMotionEvent( @@ -2490,7 +2486,7 @@ TEST_F(InputDispatcherTest, MultiDeviceSplitTouch) { .deviceId(mouseDeviceId) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) .build())); leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); @@ -2498,7 +2494,7 @@ TEST_F(InputDispatcherTest, MultiDeviceSplitTouch) { mDispatcher->notifyMotion(&( args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(300).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) .build())); leftWindow->consumeMotionEvent(WithMotionAction(ACTION_CANCEL)); @@ -2508,8 +2504,8 @@ TEST_F(InputDispatcherTest, MultiDeviceSplitTouch) { mDispatcher->notifyMotion(&( args = MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(300).y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(100).y(100)) .build())); leftWindow->consumeMotionEvent( AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); @@ -2547,21 +2543,21 @@ TEST_F(InputDispatcherTest, MixedTouchAndMouseWithPointerDown) { mDispatcher->notifyMotion(&( args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(300).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) .build())); // Second touch pointer down mDispatcher->notifyMotion(&( args = MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(300).y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(350).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(350).y(100)) .build())); // First touch pointer lifts. The second one remains down mDispatcher->notifyMotion(&( args = MotionArgsBuilder(POINTER_0_UP, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(300).y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(350).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(350).y(100)) .build())); window->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); window->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); @@ -2572,7 +2568,7 @@ TEST_F(InputDispatcherTest, MixedTouchAndMouseWithPointerDown) { args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) .deviceId(mouseDeviceId) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(320).y(100)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(320).y(100)) .build())); window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(touchDeviceId), @@ -2584,7 +2580,7 @@ TEST_F(InputDispatcherTest, MixedTouchAndMouseWithPointerDown) { .deviceId(mouseDeviceId) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(320).y(100)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(320).y(100)) .build())); window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); @@ -2592,8 +2588,8 @@ TEST_F(InputDispatcherTest, MixedTouchAndMouseWithPointerDown) { mDispatcher->notifyMotion(&( args = MotionArgsBuilder(POINTER_0_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(300).y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(350).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(350).y(100)) .build())); // The pointer_down event should be ignored window->assertNoEvents(); @@ -2619,7 +2615,7 @@ TEST_F(InputDispatcherTest, UnfinishedInjectedEvent) { injectMotionEvent(mDispatcher, MotionEventBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) .deviceId(ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(50) .y(50)) .build())); @@ -2631,7 +2627,7 @@ TEST_F(InputDispatcherTest, UnfinishedInjectedEvent) { mDispatcher->notifyMotion(&( args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(300).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) .build())); window->consumeMotionEvent( @@ -2673,7 +2669,7 @@ TEST_F(InputDispatcherTest, HoverTapAndSplitTouch) { MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) .deviceId(mouseDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(50) .y(50)) .build())); @@ -2685,7 +2681,7 @@ TEST_F(InputDispatcherTest, HoverTapAndSplitTouch) { MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(100) .y(100)) .build())); @@ -2695,7 +2691,7 @@ TEST_F(InputDispatcherTest, HoverTapAndSplitTouch) { MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(100) .y(100)) .build())); @@ -2709,7 +2705,7 @@ TEST_F(InputDispatcherTest, HoverTapAndSplitTouch) { MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(300) .y(100)) .build())); @@ -2720,10 +2716,10 @@ TEST_F(InputDispatcherTest, HoverTapAndSplitTouch) { injectMotionEvent(mDispatcher, MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(300) .y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(1, ToolType::FINGER) .x(100) .y(100)) .build())); @@ -2756,7 +2752,7 @@ TEST_F(InputDispatcherTest, StylusHoverAndTouchTap) { MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) .deviceId(stylusDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS) + .pointer(PointerBuilder(0, ToolType::STYLUS) .x(50) .y(50)) .build())); @@ -2768,7 +2764,7 @@ TEST_F(InputDispatcherTest, StylusHoverAndTouchTap) { MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(100) .y(100)) .build())); @@ -2781,7 +2777,7 @@ TEST_F(InputDispatcherTest, StylusHoverAndTouchTap) { MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) .deviceId(stylusDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS) + .pointer(PointerBuilder(0, ToolType::STYLUS) .x(50) .y(50)) .build())); @@ -2794,7 +2790,7 @@ TEST_F(InputDispatcherTest, StylusHoverAndTouchTap) { MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(100) .y(100)) .build())); @@ -2806,7 +2802,7 @@ TEST_F(InputDispatcherTest, StylusHoverAndTouchTap) { MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) .deviceId(stylusDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS) + .pointer(PointerBuilder(0, ToolType::STYLUS) .x(50) .y(50)) .build())); @@ -2839,40 +2835,40 @@ TEST_F(InputDispatcherTest, StylusHoverAndDownNoInputChannel) { // Start hovering with stylus mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS).x(50).y(50)) + .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); // Stop hovering mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_HOVER_EXIT, AINPUT_SOURCE_STYLUS) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS).x(50).y(50)) + .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); // Stylus touches down mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_STYLUS) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS).x(50).y(50)) + .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); // Stylus goes up mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_STYLUS) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS).x(50).y(50)) + .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_UP)); // Again hover mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS).x(50).y(50)) + .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); // Stop hovering mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_HOVER_EXIT, AINPUT_SOURCE_STYLUS) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS).x(50).y(50)) + .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); @@ -2908,7 +2904,7 @@ TEST_F(InputDispatcherTest, TouchPilferAndMouseMove) { mDispatcher->notifyMotion(&( args = MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) .deviceId(mouseDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) .build())); spyWindow->consumeMotionEvent( AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId))); @@ -2919,7 +2915,7 @@ TEST_F(InputDispatcherTest, TouchPilferAndMouseMove) { mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); @@ -2929,7 +2925,7 @@ TEST_F(InputDispatcherTest, TouchPilferAndMouseMove) { mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(55).y(55)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(55).y(55)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); window->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); @@ -2941,7 +2937,7 @@ TEST_F(InputDispatcherTest, TouchPilferAndMouseMove) { mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(60).y(60)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(60).y(60)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); @@ -2950,7 +2946,7 @@ TEST_F(InputDispatcherTest, TouchPilferAndMouseMove) { args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) .deviceId(mouseDeviceId) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) .build())); spyWindow->consumeMotionEvent( @@ -2964,7 +2960,7 @@ TEST_F(InputDispatcherTest, TouchPilferAndMouseMove) { .deviceId(mouseDeviceId) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); @@ -2974,7 +2970,7 @@ TEST_F(InputDispatcherTest, TouchPilferAndMouseMove) { args = MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_MOUSE) .deviceId(mouseDeviceId) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(110).y(110)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(110).y(110)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); window->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); @@ -2983,7 +2979,7 @@ TEST_F(InputDispatcherTest, TouchPilferAndMouseMove) { mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(65).y(65)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(65).y(65)) .build())); // No more events @@ -3129,9 +3125,7 @@ TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(900) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(900).y(400)) .build())); windowRight->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); @@ -3140,9 +3134,7 @@ TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); windowRight->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)); windowLeft->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); @@ -3152,9 +3144,7 @@ TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); windowLeft->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); windowLeft->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); @@ -3165,9 +3155,7 @@ TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { AINPUT_SOURCE_MOUSE) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); windowLeft->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); @@ -3177,9 +3165,7 @@ TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { AINPUT_SOURCE_MOUSE) .buttonState(0) .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); windowLeft->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE)); @@ -3187,9 +3173,7 @@ TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_MOUSE) .buttonState(0) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); windowLeft->consumeMotionUp(ADISPLAY_ID_DEFAULT); @@ -3198,9 +3182,7 @@ TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(900) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(900).y(400)) .build())); windowRight->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); @@ -3230,14 +3212,14 @@ TEST_F(InputDispatcherTest, TwoPointersDownMouseClick) { mDispatcher->notifyMotion(&( args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) .build())); mDispatcher->notifyMotion(&( args = MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(120).y(120)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(120).y(120)) .build())); window->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); window->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); @@ -3247,7 +3229,7 @@ TEST_F(InputDispatcherTest, TwoPointersDownMouseClick) { args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) .deviceId(mouseDeviceId) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(300).y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(touchDeviceId), WithPointerCount(2u))); @@ -3258,7 +3240,7 @@ TEST_F(InputDispatcherTest, TwoPointersDownMouseClick) { .deviceId(mouseDeviceId) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(300).y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); @@ -3267,8 +3249,8 @@ TEST_F(InputDispatcherTest, TwoPointersDownMouseClick) { mDispatcher->notifyMotion(&( args = MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(101).y(101)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(121).y(121)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(101).y(101)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(121).y(121)) .build())); window->assertNoEvents(); } @@ -3293,7 +3275,7 @@ TEST_F(InputDispatcherTest, HoverWithSpyWindows) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(100) .y(100)) .build())); @@ -3327,7 +3309,7 @@ TEST_F(InputDispatcherTest, MouseAndTouchWithSpyWindows) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(100) .y(100)) .build())); @@ -3337,7 +3319,7 @@ TEST_F(InputDispatcherTest, MouseAndTouchWithSpyWindows) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(110) .y(110)) .build())); @@ -3356,7 +3338,7 @@ TEST_F(InputDispatcherTest, MouseAndTouchWithSpyWindows) { MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(SECOND_DEVICE_ID) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(200) .y(200)) .build())); @@ -3380,7 +3362,7 @@ TEST_F(InputDispatcherTest, MouseAndTouchWithSpyWindows) { MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(SECOND_DEVICE_ID) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(200) .y(200)) .build())); @@ -3397,7 +3379,7 @@ TEST_F(InputDispatcherTest, MouseAndTouchWithSpyWindows) { MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(SECOND_DEVICE_ID) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(250) .y(250)) .build())); @@ -3412,7 +3394,7 @@ TEST_F(InputDispatcherTest, MouseAndTouchWithSpyWindows) { MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(SECOND_DEVICE_ID) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(250) .y(250)) .build())); @@ -3441,9 +3423,7 @@ TEST_F(InputDispatcherTest, HoverEnterMouseClickAndHoverExit) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); // Inject a series of mouse events for a mouse click @@ -3451,9 +3431,7 @@ TEST_F(InputDispatcherTest, HoverEnterMouseClickAndHoverExit) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); window->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); @@ -3464,9 +3442,7 @@ TEST_F(InputDispatcherTest, HoverEnterMouseClickAndHoverExit) { AINPUT_SOURCE_MOUSE) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); @@ -3476,9 +3452,7 @@ TEST_F(InputDispatcherTest, HoverEnterMouseClickAndHoverExit) { AINPUT_SOURCE_MOUSE) .buttonState(0) .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE)); @@ -3486,9 +3460,7 @@ TEST_F(InputDispatcherTest, HoverEnterMouseClickAndHoverExit) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_MOUSE) .buttonState(0) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); window->consumeMotionUp(ADISPLAY_ID_DEFAULT); @@ -3496,9 +3468,7 @@ TEST_F(InputDispatcherTest, HoverEnterMouseClickAndHoverExit) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_EXIT, AINPUT_SOURCE_MOUSE) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); window->assertNoEvents(); } @@ -3521,7 +3491,7 @@ TEST_F(InputDispatcherTest, HoverExitIsSentToRemovedWindow) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(300) .y(400)) .build())); @@ -3551,7 +3521,7 @@ TEST_F(InputDispatcherTest, TouchDownAfterMouseHover) { mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) .deviceId(mouseDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(10).y(10)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(10).y(10)) .build())); window->consumeMotionEvent( AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId))); @@ -3560,7 +3530,7 @@ TEST_F(InputDispatcherTest, TouchDownAfterMouseHover) { mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) .build())); window->consumeMotionEvent( @@ -3633,7 +3603,7 @@ TEST_F(InputDispatcherTest, HoverEnterMoveRemoveWindowsInSecondDisplay) { MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) .displayId(ADISPLAY_ID_DEFAULT) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(300) .y(600)) .build())); @@ -3654,7 +3624,7 @@ TEST_F(InputDispatcherTest, HoverEnterMoveRemoveWindowsInSecondDisplay) { MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) .displayId(ADISPLAY_ID_DEFAULT) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(400) .y(700)) .build())); @@ -3911,8 +3881,8 @@ TEST_F(InputDispatcherTest, NonSplitTouchableWindowReceivesMultiTouch) { MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(-30).y(-50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(-30).y(-50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -4033,7 +4003,7 @@ TEST_F(InputDispatcherDisplayProjectionTest, InjectionWithTransformInLogicalDisp MotionEvent event = MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER) .x(untransformedPoint.x) .y(untransformedPoint.y)) .build(); @@ -5255,7 +5225,8 @@ TEST_F(InputDispatcherTest, SetFocusedWindow_CheckFocusedToken) { setFocusedWindow(windowTop); windowTop->consumeFocusEvent(true); - setFocusedWindow(windowSecond, windowTop); + windowTop->editInfo()->focusTransferTarget = windowSecond->getToken(); + mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {windowTop, windowSecond}}}); windowSecond->consumeFocusEvent(true); windowTop->consumeFocusEvent(false); @@ -5266,7 +5237,7 @@ TEST_F(InputDispatcherTest, SetFocusedWindow_CheckFocusedToken) { windowSecond->consumeKeyDown(ADISPLAY_ID_NONE); } -TEST_F(InputDispatcherTest, SetFocusedWindow_DropRequestFocusTokenNotFocused) { +TEST_F(InputDispatcherTest, SetFocusedWindow_TransferFocusTokenNotFocusable) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> windowTop = sp<FakeWindowHandle>::make(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); @@ -5275,15 +5246,17 @@ TEST_F(InputDispatcherTest, SetFocusedWindow_DropRequestFocusTokenNotFocused) { mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); windowTop->setFocusable(true); - windowSecond->setFocusable(true); + windowSecond->setFocusable(false); + windowTop->editInfo()->focusTransferTarget = windowSecond->getToken(); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {windowTop, windowSecond}}}); - setFocusedWindow(windowSecond, windowTop); + setFocusedWindow(windowTop); + windowTop->consumeFocusEvent(true); - ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, injectKeyDown(mDispatcher)) - << "Inject key event should return InputEventInjectionResult::TIMED_OUT"; + ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(mDispatcher)) + << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; // Event should be dropped. - windowTop->assertNoEvents(); + windowTop->consumeKeyDown(ADISPLAY_ID_NONE); windowSecond->assertNoEvents(); } @@ -6076,7 +6049,7 @@ TEST_F(InputDispatcherOnPointerDownOutsideFocus, NoFocusChangeFlag) { const MotionEvent event = MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(20).y(20)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(20).y(20)) .addFlag(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, event)) @@ -7937,7 +7910,7 @@ protected: MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_STYLUS) .buttonState(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS) + .pointer(PointerBuilder(0, ToolType::STYLUS) .x(50) .y(50)) .build())); @@ -7949,7 +7922,7 @@ protected: MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) .pointer(PointerBuilder(MOUSE_POINTER_ID, - AMOTION_EVENT_TOOL_TYPE_MOUSE) + ToolType::MOUSE) .x(50) .y(50)) .build())); @@ -8038,8 +8011,8 @@ TEST_F(InputDispatcherDragTests, DragEnterAndPointerDownPilfersPointers) { const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(60).y(60)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(60).y(60)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -8093,9 +8066,7 @@ TEST_F(InputDispatcherDragTests, StylusDragAndDrop) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_STYLUS) .buttonState(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS) - .x(50) - .y(50)) + .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) .build())) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT); @@ -8107,9 +8078,7 @@ TEST_F(InputDispatcherDragTests, StylusDragAndDrop) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_STYLUS) .buttonState(0) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS) - .x(150) - .y(50)) + .pointer(PointerBuilder(0, ToolType::STYLUS).x(150).y(50)) .build())) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT); @@ -8122,9 +8091,7 @@ TEST_F(InputDispatcherDragTests, StylusDragAndDrop) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_STYLUS) .buttonState(0) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS) - .x(150) - .y(50)) + .pointer(PointerBuilder(0, ToolType::STYLUS).x(150).y(50)) .build())) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT); @@ -8182,8 +8149,8 @@ TEST_F(InputDispatcherDragTests, NoDragAndDropWhenMultiFingers) { MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(75).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(75).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -8209,8 +8176,8 @@ TEST_F(InputDispatcherDragTests, DragAndDropWhenSplitTouch) { MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(50)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(50)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -8225,8 +8192,8 @@ TEST_F(InputDispatcherDragTests, DragAndDropWhenSplitTouch) { const MotionEvent secondFingerMoveEvent = MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(50)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(50)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerMoveEvent, INJECT_EVENT_TIMEOUT, @@ -8239,8 +8206,8 @@ TEST_F(InputDispatcherDragTests, DragAndDropWhenSplitTouch) { const MotionEvent secondFingerUpEvent = MotionEventBuilder(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(50)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(50)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerUpEvent, INJECT_EVENT_TIMEOUT, @@ -8265,9 +8232,7 @@ TEST_F(InputDispatcherDragTests, DragAndDropWhenMultiDisplays) { MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(SECOND_DISPLAY_ID) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) - .x(100) - .y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) .build())); windowInSecondary->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_DOWN, SECOND_DISPLAY_ID, /*expectedFlag=*/0); @@ -8311,7 +8276,7 @@ TEST_F(InputDispatcherDragTests, MouseDragAndDrop) { MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_MOUSE) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) .pointer(PointerBuilder(MOUSE_POINTER_ID, - AMOTION_EVENT_TOOL_TYPE_MOUSE) + ToolType::MOUSE) .x(50) .y(50)) .build())) @@ -8326,7 +8291,7 @@ TEST_F(InputDispatcherDragTests, MouseDragAndDrop) { MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_MOUSE) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) .pointer(PointerBuilder(MOUSE_POINTER_ID, - AMOTION_EVENT_TOOL_TYPE_MOUSE) + ToolType::MOUSE) .x(150) .y(50)) .build())) @@ -8341,7 +8306,7 @@ TEST_F(InputDispatcherDragTests, MouseDragAndDrop) { MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_MOUSE) .buttonState(0) .pointer(PointerBuilder(MOUSE_POINTER_ID, - AMOTION_EVENT_TOOL_TYPE_MOUSE) + ToolType::MOUSE) .x(150) .y(50)) .build())) @@ -8813,8 +8778,8 @@ TEST_F(InputDispatcherSpyWindowTest, ReceivesMultiplePointers) { const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -8845,8 +8810,8 @@ TEST_F(InputDispatcherSpyWindowTest, ReceivesSecondPointerAsDown) { const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -8884,8 +8849,8 @@ TEST_F(InputDispatcherSpyWindowTest, SplitIfNoForegroundWindowTouched) { MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(200)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -9007,8 +8972,8 @@ TEST_F(InputDispatcherPilferPointersTest, ContinuesToReceiveGestureAfterPilfer) MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(200)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -9022,9 +8987,9 @@ TEST_F(InputDispatcherPilferPointersTest, ContinuesToReceiveGestureAfterPilfer) MotionEventBuilder(POINTER_2_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(200)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) - .pointer(PointerBuilder(/*id=*/2, AMOTION_EVENT_TOOL_TYPE_FINGER).x(-5).y(-5)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/2, ToolType::FINGER).x(-5).y(-5)) .build(); ASSERT_EQ(InputEventInjectionResult::FAILED, injectMotionEvent(mDispatcher, thirdFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -9058,8 +9023,8 @@ TEST_F(InputDispatcherPilferPointersTest, PartiallyPilferRequiredPointers) { MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(150)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(10).y(10)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(150)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(10).y(10)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -9073,9 +9038,9 @@ TEST_F(InputDispatcherPilferPointersTest, PartiallyPilferRequiredPointers) { MotionEventBuilder(POINTER_2_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(150)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(10).y(10)) - .pointer(PointerBuilder(/*id=*/2, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(150)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(10).y(10)) + .pointer(PointerBuilder(/*id=*/2, ToolType::FINGER).x(50).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, thirdFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -9119,8 +9084,8 @@ TEST_F(InputDispatcherPilferPointersTest, PilferAllRequiredPointers) { MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(10).y(10)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(10).y(10)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -9166,8 +9131,8 @@ TEST_F(InputDispatcherPilferPointersTest, CanReceivePointersAfterPilfer) { MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(10).y(10)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(150)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(10).y(10)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(150)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -9221,7 +9186,7 @@ public: NotifyMotionArgs motionArgs = generateMotionArgs(action, AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS, ADISPLAY_ID_DEFAULT, {PointF{30, 40}}); - motionArgs.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + motionArgs.pointerProperties[0].toolType = ToolType::STYLUS; mDispatcher->notifyMotion(&motionArgs); } }; diff --git a/services/inputflinger/tests/InputProcessorConverter_test.cpp b/services/inputflinger/tests/InputProcessorConverter_test.cpp index 161a24ff70..4b42f4b141 100644 --- a/services/inputflinger/tests/InputProcessorConverter_test.cpp +++ b/services/inputflinger/tests/InputProcessorConverter_test.cpp @@ -30,7 +30,7 @@ static NotifyMotionArgs generateBasicMotionArgs() { // Create a basic motion event for testing PointerProperties properties; properties.id = 0; - properties.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + properties.toolType = ToolType::FINGER; PointerCoords coords; coords.clear(); diff --git a/services/inputflinger/tests/InputProcessor_test.cpp b/services/inputflinger/tests/InputProcessor_test.cpp index b6deed8aae..0ffdef9daa 100644 --- a/services/inputflinger/tests/InputProcessor_test.cpp +++ b/services/inputflinger/tests/InputProcessor_test.cpp @@ -37,7 +37,7 @@ static NotifyMotionArgs generateBasicMotionArgs() { // Create a basic motion event for testing PointerProperties properties; properties.id = 0; - properties.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + properties.toolType = ToolType::FINGER; PointerCoords coords; coords.clear(); diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 853c5b0115..3d0fbb4455 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -644,6 +644,30 @@ TEST_F(InputReaderTest, PolicyGetInputDevices) { ASSERT_EQ(0U, inputDevices[0].getMotionRanges().size()); } +TEST_F(InputReaderTest, InputDeviceRecreatedOnSysfsNodeChanged) { + ASSERT_NO_FATAL_FAILURE(addDevice(1, "keyboard", InputDeviceClass::KEYBOARD, nullptr)); + mFakeEventHub->setSysfsRootPath(1, "xyz"); + + // Should also have received a notification describing the new input device. + ASSERT_EQ(1U, mFakePolicy->getInputDevices().size()); + InputDeviceInfo inputDevice = mFakePolicy->getInputDevices()[0]; + ASSERT_EQ(0U, inputDevice.getLights().size()); + + RawLightInfo infoMonolight = {.id = 123, + .name = "mono_keyboard_backlight", + .maxBrightness = 255, + .flags = InputLightClass::BRIGHTNESS, + .path = ""}; + mFakeEventHub->addRawLightInfo(/*rawId=*/123, std::move(infoMonolight)); + mReader->sysfsNodeChanged("xyz"); + mReader->loopOnce(); + + // Should also have received a notification describing the new recreated input device. + ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged()); + inputDevice = mFakePolicy->getInputDevices()[0]; + ASSERT_EQ(1U, inputDevice.getLights().size()); +} + TEST_F(InputReaderTest, GetMergedInputDevices) { constexpr int32_t deviceId = END_RESERVED_ID + 1000; constexpr int32_t eventHubIds[2] = {END_RESERVED_ID, END_RESERVED_ID + 1}; @@ -1732,7 +1756,7 @@ TEST_F(TouchIntegrationTest, NotifiesPolicyWhenStylusGestureStarted) { mDevice->sendSync(); ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertStylusGestureNotified(mDeviceInfo.getId())); @@ -1751,7 +1775,7 @@ TEST_F(TouchIntegrationTest, NotifiesPolicyWhenStylusGestureStarted) { mDevice->sendSync(); ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER)))); + WithToolType(ToolType::FINGER)))); ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertStylusGestureNotNotified()); @@ -1768,7 +1792,7 @@ TEST_F(TouchIntegrationTest, NotifiesPolicyWhenStylusGestureStarted) { mDevice->sendSync(); ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertStylusGestureNotified(mDeviceInfo.getId())); } @@ -1864,12 +1888,12 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonsSurroundingTouchGe TestFixture::mTouchscreen->sendSync(); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), + WithToolType(ToolType::STYLUS), WithButtonState(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY), WithDeviceId(touchscreenId)))); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), + WithToolType(ToolType::STYLUS), WithButtonState(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY), WithDeviceId(touchscreenId)))); @@ -1877,11 +1901,11 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonsSurroundingTouchGe TestFixture::mTouchscreen->sendSync(); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); // Release the stylus button. @@ -1896,7 +1920,7 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonsSurroundingHoverin const auto touchscreenId = TestFixture::mTouchscreenInfo.getId(); const auto stylusId = TestFixture::mStylusInfo.getId(); auto toolTypeDevice = - AllOf(WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithDeviceId(touchscreenId)); + AllOf(WithToolType(ToolType::STYLUS), WithDeviceId(touchscreenId)); // Press the stylus button. TestFixture::mStylus->pressKey(BTN_STYLUS); @@ -1980,7 +2004,7 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonsWithinTouchGesture TestFixture::mTouchscreen->sendSync(); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); // Press and release a stylus button. Each change in button state also generates a MOVE event. @@ -1990,12 +2014,12 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonsWithinTouchGesture WithKeyCode(AKEYCODE_STYLUS_BUTTON_PRIMARY), WithDeviceId(stylusId)))); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), + WithToolType(ToolType::STYLUS), WithButtonState(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY), WithDeviceId(touchscreenId)))); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), + WithToolType(ToolType::STYLUS), WithButtonState(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY), WithDeviceId(touchscreenId)))); @@ -2005,11 +2029,11 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonsWithinTouchGesture WithKeyCode(AKEYCODE_STYLUS_BUTTON_PRIMARY), WithDeviceId(stylusId)))); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); // Finish the stylus gesture. @@ -2017,7 +2041,7 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonsWithinTouchGesture TestFixture::mTouchscreen->sendSync(); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); } @@ -2039,7 +2063,7 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonMotionEventsDisable TestFixture::mTouchscreen->sendSync(); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); // Press and release a stylus button. Each change only generates a MOVE motion event. @@ -2050,7 +2074,7 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonMotionEventsDisable WithKeyCode(AKEYCODE_STYLUS_BUTTON_PRIMARY), WithDeviceId(stylusId)))); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); TestFixture::mStylus->releaseKey(BTN_STYLUS); @@ -2059,7 +2083,7 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonMotionEventsDisable WithKeyCode(AKEYCODE_STYLUS_BUTTON_PRIMARY), WithDeviceId(stylusId)))); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); // Finish the stylus gesture. @@ -2067,7 +2091,7 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonMotionEventsDisable TestFixture::mTouchscreen->sendSync(); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); } @@ -2108,7 +2132,7 @@ TEST_F(ExternalStylusIntegrationTest, DISABLED_FusedExternalStylusPressureReport mDevice->sendSync(); ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId), WithPressure(100.f / RAW_PRESSURE_MAX)))); // Change the pressure on the external stylus, and ensure the touchscreen generates a MOVE @@ -2116,7 +2140,7 @@ TEST_F(ExternalStylusIntegrationTest, DISABLED_FusedExternalStylusPressureReport stylus->setPressure(200); ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId), WithPressure(200.f / RAW_PRESSURE_MAX)))); // The external stylus did not generate any events. @@ -2162,7 +2186,7 @@ TEST_F(ExternalStylusIntegrationTest, DISABLED_FusedExternalStylusPressureNotRep // it shows up as a finger pointer. ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), WithDeviceId(touchscreenId), + WithToolType(ToolType::FINGER), WithDeviceId(touchscreenId), WithPressure(1.f)))); // Change the pressure on the external stylus. Since the pressure was not present at the start @@ -2175,7 +2199,7 @@ TEST_F(ExternalStylusIntegrationTest, DISABLED_FusedExternalStylusPressureNotRep mDevice->sendSync(); ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER)))); + WithToolType(ToolType::FINGER)))); // Start a new gesture. Since we have a valid pressure value, it shows up as a stylus. mDevice->sendTrackingId(FIRST_TRACKING_ID); @@ -2184,7 +2208,7 @@ TEST_F(ExternalStylusIntegrationTest, DISABLED_FusedExternalStylusPressureNotRep mDevice->sendSync(); ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId), WithPressure(200.f / RAW_PRESSURE_MAX)))); // The external stylus did not generate any events. @@ -2220,7 +2244,7 @@ TEST_F(ExternalStylusIntegrationTest, DISABLED_UnfusedExternalStylus) { mTestListener ->assertNotifyMotionWasCalled(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithToolType( - AMOTION_EVENT_TOOL_TYPE_FINGER), + ToolType::FINGER), WithButtonState(0), WithDeviceId(touchscreenId), WithPressure(1.f)), @@ -3875,7 +3899,7 @@ TEST_F(CursorInputMapperTest, Process_ShouldSetAllFieldsAndIncludeGlobalMetaStat ASSERT_EQ(0, args.edgeFlags); ASSERT_EQ(uint32_t(1), args.pointerCount); ASSERT_EQ(0, args.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, args.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f, 0.0f, 1.0f)); ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision); ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision); @@ -3893,7 +3917,7 @@ TEST_F(CursorInputMapperTest, Process_ShouldSetAllFieldsAndIncludeGlobalMetaStat ASSERT_EQ(0, args.edgeFlags); ASSERT_EQ(uint32_t(1), args.pointerCount); ASSERT_EQ(0, args.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, args.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f, 0.0f, 1.0f)); ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision); ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision); @@ -3914,7 +3938,7 @@ TEST_F(CursorInputMapperTest, Process_ShouldSetAllFieldsAndIncludeGlobalMetaStat ASSERT_EQ(0, args.edgeFlags); ASSERT_EQ(uint32_t(1), args.pointerCount); ASSERT_EQ(0, args.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, args.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f, 0.0f, 0.0f)); ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision); ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision); @@ -3932,7 +3956,7 @@ TEST_F(CursorInputMapperTest, Process_ShouldSetAllFieldsAndIncludeGlobalMetaStat ASSERT_EQ(0, args.edgeFlags); ASSERT_EQ(uint32_t(1), args.pointerCount); ASSERT_EQ(0, args.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, args.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f, 0.0f, 0.0f)); ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision); ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision); @@ -5195,7 +5219,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndMovedOutOfB ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -5219,7 +5243,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndMovedOutOfB ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -5242,7 +5266,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndMovedOutOfB ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -5292,7 +5316,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenTouchStartsOutsideDisplayAndMoves ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -5315,7 +5339,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenTouchStartsOutsideDisplayAndMoves ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -5360,7 +5384,7 @@ TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture_VirtualDispl ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x, VIRTUAL_DISPLAY_WIDTH), toDisplayY(y, VIRTUAL_DISPLAY_HEIGHT), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -5387,7 +5411,7 @@ TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture_VirtualDispl ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x, VIRTUAL_DISPLAY_WIDTH), toDisplayY(y, VIRTUAL_DISPLAY_HEIGHT), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -5412,7 +5436,7 @@ TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture_VirtualDispl ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x, VIRTUAL_DISPLAY_WIDTH), toDisplayY(y, VIRTUAL_DISPLAY_HEIGHT), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -5455,7 +5479,7 @@ TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture) { ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -5480,7 +5504,7 @@ TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture) { ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -5503,7 +5527,7 @@ TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture) { ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -6151,14 +6175,14 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // eraser processKey(mapper, BTN_TOOL_RUBBER, 1); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::ERASER, motionArgs.pointerProperties[0].toolType); // stylus processKey(mapper, BTN_TOOL_RUBBER, 0); @@ -6166,7 +6190,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // brush processKey(mapper, BTN_TOOL_PEN, 0); @@ -6174,7 +6198,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // pencil processKey(mapper, BTN_TOOL_BRUSH, 0); @@ -6182,7 +6206,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // air-brush processKey(mapper, BTN_TOOL_PENCIL, 0); @@ -6190,7 +6214,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // mouse processKey(mapper, BTN_TOOL_AIRBRUSH, 0); @@ -6198,7 +6222,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, motionArgs.pointerProperties[0].toolType); // lens processKey(mapper, BTN_TOOL_MOUSE, 0); @@ -6206,7 +6230,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, motionArgs.pointerProperties[0].toolType); // double-tap processKey(mapper, BTN_TOOL_LENS, 0); @@ -6214,7 +6238,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // triple-tap processKey(mapper, BTN_TOOL_DOUBLETAP, 0); @@ -6222,7 +6246,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // quad-tap processKey(mapper, BTN_TOOL_TRIPLETAP, 0); @@ -6230,7 +6254,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // finger processKey(mapper, BTN_TOOL_QUADTAP, 0); @@ -6238,28 +6262,28 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // stylus trumps finger processKey(mapper, BTN_TOOL_PEN, 1); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // eraser trumps stylus processKey(mapper, BTN_TOOL_RUBBER, 1); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::ERASER, motionArgs.pointerProperties[0].toolType); // mouse trumps eraser processKey(mapper, BTN_TOOL_MOUSE, 1); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, motionArgs.pointerProperties[0].toolType); // back to default tool type processKey(mapper, BTN_TOOL_MOUSE, 0); @@ -6269,7 +6293,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); } TEST_F(SingleTouchInputMapperTest, Process_WhenBtnTouchPresent_HoversIfItsValueIsZero) { @@ -6659,7 +6683,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenConfigEnabled_ShouldShowDirectSty processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), + WithToolType(ToolType::STYLUS), WithPointerCoords(0, toDisplayX(100), toDisplayY(200))))); ASSERT_TRUE(fakePointerController->isPointerShown()); ASSERT_NO_FATAL_FAILURE( @@ -6683,7 +6707,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenConfigDisabled_ShouldNotShowDirec processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), + WithToolType(ToolType::STYLUS), WithPointerCoords(0, toDisplayX(100), toDisplayY(200))))); ASSERT_FALSE(fakePointerController->isPointerShown()); } @@ -7125,7 +7149,7 @@ public: mStylusState.when = ARBITRARY_TIME; mStylusState.pressure = 0.f; - mStylusState.toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + mStylusState.toolType = ToolType::STYLUS; mReader->getContext()->setExternalStylusDevices({mExternalStylusDeviceInfo}); configureDevice(InputReaderConfiguration::CHANGE_EXTERNAL_STYLUS_PRESENCE); processExternalStylusState(mapper); @@ -7149,7 +7173,7 @@ protected: void testStartFusedStylusGesture(SingleTouchInputMapper& mapper) { auto toolTypeSource = - AllOf(WithSource(EXPECTED_SOURCE), WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)); + AllOf(WithSource(EXPECTED_SOURCE), WithToolType(ToolType::STYLUS)); // The first pointer is withheld. processDown(mapper, 100, 200); @@ -7184,7 +7208,7 @@ protected: processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithSource(EXPECTED_SOURCE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); mStylusState.pressure = 0.f; processExternalStylusState(mapper); @@ -7194,7 +7218,7 @@ protected: void testUnsuccessfulFusionGesture(SingleTouchInputMapper& mapper) { auto toolTypeSource = - AllOf(WithSource(EXPECTED_SOURCE), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER)); + AllOf(WithSource(EXPECTED_SOURCE), WithToolType(ToolType::FINGER)); // The first pointer is withheld when an external stylus is connected, // and a timeout is requested. @@ -7252,7 +7276,7 @@ TEST_F(ExternalStylusFusionTest, SuccessfulFusion_TouchFirst) { TEST_F(ExternalStylusFusionTest, SuccessfulFusion_PressureFirst) { SingleTouchInputMapper& mapper = initializeInputMapperWithExternalStylus(); auto toolTypeSource = - AllOf(WithSource(EXPECTED_SOURCE), WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)); + AllOf(WithSource(EXPECTED_SOURCE), WithToolType(ToolType::STYLUS)); // The external stylus reports pressure first. It is ignored for now. mStylusState.pressure = 1.f; @@ -7295,7 +7319,7 @@ TEST_F(ExternalStylusFusionTest, FusionIsRepeatedForEachNewGesture) { TEST_F(ExternalStylusFusionTest, FusedPointerReportsPressureChanges) { SingleTouchInputMapper& mapper = initializeInputMapperWithExternalStylus(); auto toolTypeSource = - AllOf(WithSource(EXPECTED_SOURCE), WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)); + AllOf(WithSource(EXPECTED_SOURCE), WithToolType(ToolType::STYLUS)); mStylusState.pressure = 0.8f; processExternalStylusState(mapper); @@ -7357,7 +7381,7 @@ TEST_F(ExternalStylusFusionTest, FusedPointerReportsPressureChanges) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithSource(EXPECTED_SOURCE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); ASSERT_NO_FATAL_FAILURE(mReader->getContext()->assertTimeoutWasNotRequested()); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); @@ -7368,17 +7392,17 @@ TEST_F(ExternalStylusFusionTest, FusedPointerReportsToolTypeChanges) { auto source = WithSource(EXPECTED_SOURCE); mStylusState.pressure = 1.f; - mStylusState.toolType = AMOTION_EVENT_TOOL_TYPE_ERASER; + mStylusState.toolType = ToolType::ERASER; processExternalStylusState(mapper); processDown(mapper, 100, 200); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(source, WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithToolType(AMOTION_EVENT_TOOL_TYPE_ERASER)))); + WithToolType(ToolType::ERASER)))); ASSERT_NO_FATAL_FAILURE(mReader->getContext()->assertTimeoutWasNotRequested()); // The external stylus reports a tool change. We wait for some time for a touch event. - mStylusState.toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + mStylusState.toolType = ToolType::STYLUS; processExternalStylusState(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); ASSERT_NO_FATAL_FAILURE( @@ -7389,11 +7413,11 @@ TEST_F(ExternalStylusFusionTest, FusedPointerReportsToolTypeChanges) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(source, WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); ASSERT_NO_FATAL_FAILURE(mReader->getContext()->assertTimeoutWasNotRequested()); // There is another tool type change. - mStylusState.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + mStylusState.toolType = ToolType::FINGER; processExternalStylusState(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); ASSERT_NO_FATAL_FAILURE( @@ -7404,13 +7428,13 @@ TEST_F(ExternalStylusFusionTest, FusedPointerReportsToolTypeChanges) { handleTimeout(mapper, ARBITRARY_TIME + TOUCH_DATA_TIMEOUT); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(source, WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER)))); + WithToolType(ToolType::FINGER)))); processUp(mapper); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(source, WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER)))); + WithToolType(ToolType::FINGER)))); ASSERT_NO_FATAL_FAILURE(mReader->getContext()->assertTimeoutWasNotRequested()); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); @@ -7419,7 +7443,7 @@ TEST_F(ExternalStylusFusionTest, FusedPointerReportsToolTypeChanges) { TEST_F(ExternalStylusFusionTest, FusedPointerReportsButtons) { SingleTouchInputMapper& mapper = initializeInputMapperWithExternalStylus(); auto toolTypeSource = - AllOf(WithSource(EXPECTED_SOURCE), WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)); + AllOf(WithSource(EXPECTED_SOURCE), WithToolType(ToolType::STYLUS)); ASSERT_NO_FATAL_FAILURE(testStartFusedStylusGesture(mapper)); @@ -7636,7 +7660,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -7655,9 +7679,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -7686,9 +7710,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -7715,9 +7739,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -7738,7 +7762,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(1, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -7763,7 +7787,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(1, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -7790,9 +7814,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -7819,9 +7843,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -7842,7 +7866,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -7865,7 +7889,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -7953,7 +7977,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -7961,9 +7985,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(ACTION_POINTER_1_DOWN, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -7983,9 +8007,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -8002,9 +8026,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(ACTION_POINTER_0_UP, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -8014,7 +8038,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(1, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -8029,7 +8053,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(1, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -8047,9 +8071,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(ACTION_POINTER_0_DOWN, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -8066,9 +8090,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(ACTION_POINTER_1_UP, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -8078,7 +8102,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -8090,7 +8114,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -8123,7 +8147,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -8131,9 +8155,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(ACTION_POINTER_1_DOWN, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -8151,9 +8175,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -8171,9 +8195,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(ACTION_POINTER_0_UP, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -8183,7 +8207,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(1, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -8196,7 +8220,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(1, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -8212,9 +8236,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(ACTION_POINTER_0_DOWN, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -8232,9 +8256,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(ACTION_POINTER_1_UP, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -8244,7 +8268,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -8256,7 +8280,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -8783,14 +8807,14 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // eraser processKey(mapper, BTN_TOOL_RUBBER, 1); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::ERASER, motionArgs.pointerProperties[0].toolType); // stylus processKey(mapper, BTN_TOOL_RUBBER, 0); @@ -8798,7 +8822,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // brush processKey(mapper, BTN_TOOL_PEN, 0); @@ -8806,7 +8830,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // pencil processKey(mapper, BTN_TOOL_BRUSH, 0); @@ -8814,7 +8838,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // air-brush processKey(mapper, BTN_TOOL_PENCIL, 0); @@ -8822,7 +8846,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // mouse processKey(mapper, BTN_TOOL_AIRBRUSH, 0); @@ -8830,7 +8854,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, motionArgs.pointerProperties[0].toolType); // lens processKey(mapper, BTN_TOOL_MOUSE, 0); @@ -8838,7 +8862,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, motionArgs.pointerProperties[0].toolType); // double-tap processKey(mapper, BTN_TOOL_LENS, 0); @@ -8846,7 +8870,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // triple-tap processKey(mapper, BTN_TOOL_DOUBLETAP, 0); @@ -8854,7 +8878,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // quad-tap processKey(mapper, BTN_TOOL_TRIPLETAP, 0); @@ -8862,7 +8886,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // finger processKey(mapper, BTN_TOOL_QUADTAP, 0); @@ -8870,42 +8894,42 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // stylus trumps finger processKey(mapper, BTN_TOOL_PEN, 1); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // eraser trumps stylus processKey(mapper, BTN_TOOL_RUBBER, 1); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::ERASER, motionArgs.pointerProperties[0].toolType); // mouse trumps eraser processKey(mapper, BTN_TOOL_MOUSE, 1); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, motionArgs.pointerProperties[0].toolType); // MT tool type trumps BTN tool types: MT_TOOL_FINGER processToolType(mapper, MT_TOOL_FINGER); // this is the first time we send MT_TOOL_TYPE processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // MT tool type trumps BTN tool types: MT_TOOL_PEN processToolType(mapper, MT_TOOL_PEN); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // back to default tool type processToolType(mapper, -1); // use a deliberately undefined tool type, for testing @@ -8916,7 +8940,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); } TEST_F(MultiTouchInputMapperTest, Process_WhenBtnTouchPresent_HoversIfItsValueIsZero) { @@ -9531,7 +9555,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleSingleTouch) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // finger move processId(mapper, 1); @@ -9539,14 +9563,14 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleSingleTouch) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // finger up. processId(mapper, -1); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // new finger down processId(mapper, 1); @@ -9554,7 +9578,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleSingleTouch) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); } /** @@ -9576,7 +9600,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_SinglePointer processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // Tool changed to MT_TOOL_PALM expect sending the cancel event. processToolType(mapper, MT_TOOL_PALM); @@ -9602,7 +9626,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_SinglePointer processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); } /** @@ -9624,7 +9648,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_TwoPointers) processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // Second finger down. processSlot(mapper, SECOND_SLOT); @@ -9633,7 +9657,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_TwoPointers) processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(ACTION_POINTER_1_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); // If the tool type of the first finger changes to MT_TOOL_PALM, // we expect to receive ACTION_POINTER_UP with cancel flag. @@ -9699,7 +9723,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_ShouldCancelW processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // Second finger down. processSlot(mapper, SECOND_SLOT); @@ -9708,7 +9732,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_ShouldCancelW processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(ACTION_POINTER_1_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // If the tool type of the first finger changes to MT_TOOL_PALM, // we expect to receive ACTION_POINTER_UP with cancel flag. @@ -9743,7 +9767,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_ShouldCancelW processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(uint32_t(1), motionArgs.pointerCount); // third finger move @@ -9797,7 +9821,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_KeepFirstPoin processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // Second finger down. processSlot(mapper, SECOND_SLOT); @@ -9806,7 +9830,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_KeepFirstPoin processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(ACTION_POINTER_1_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // If the tool type of the second finger changes to MT_TOOL_PALM, // we expect to receive ACTION_POINTER_UP with cancel flag. @@ -10003,7 +10027,7 @@ TEST_F(MultiTouchInputMapperTest, StylusSourceIsAddedDynamicallyFromToolType) { ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithSource(AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); // Now that we know the device supports styluses, ensure that the device is re-configured with // the stylus source. @@ -10025,7 +10049,7 @@ TEST_F(MultiTouchInputMapperTest, StylusSourceIsAddedDynamicallyFromToolType) { ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithSource(AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); } TEST_F(MultiTouchInputMapperTest, Process_WhenConfigEnabled_ShouldShowDirectStylusPointer) { @@ -10048,7 +10072,7 @@ TEST_F(MultiTouchInputMapperTest, Process_WhenConfigEnabled_ShouldShowDirectStyl processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), + WithToolType(ToolType::STYLUS), WithPointerCoords(0, toDisplayX(100), toDisplayY(200))))); ASSERT_TRUE(fakePointerController->isPointerShown()); ASSERT_NO_FATAL_FAILURE( @@ -10075,7 +10099,7 @@ TEST_F(MultiTouchInputMapperTest, Process_WhenConfigDisabled_ShouldNotShowDirect processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), + WithToolType(ToolType::STYLUS), WithPointerCoords(0, toDisplayX(100), toDisplayY(200))))); ASSERT_FALSE(fakePointerController->isPointerShown()); } @@ -10468,7 +10492,7 @@ TEST_F(MultiTouchPointerModeTest, PointerGestureMaxSwipeWidthSwipe) { ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(1U, motionArgs.pointerCount); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(MotionClassification::NONE, motionArgs.classification); ASSERT_NO_FATAL_FAILURE( assertPointerCoords(motionArgs.pointerCoords[0], 0, 0, 1, 0, 0, 0, 0, 0, 0, 0)); @@ -10490,7 +10514,7 @@ TEST_F(MultiTouchPointerModeTest, PointerGestureMaxSwipeWidthSwipe) { ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(1U, motionArgs.pointerCount); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(MotionClassification::TWO_FINGER_SWIPE, motionArgs.classification); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 0, movingDistance * mPointerMovementScale, 1, 0, 0, 0, @@ -10528,7 +10552,7 @@ TEST_F(MultiTouchPointerModeTest, PointerGestureMaxSwipeWidthLowResolutionSwipe) ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(1U, motionArgs.pointerCount); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(MotionClassification::NONE, motionArgs.classification); ASSERT_NO_FATAL_FAILURE( assertPointerCoords(motionArgs.pointerCoords[0], 0, 0, 1, 0, 0, 0, 0, 0, 0, 0)); @@ -10550,7 +10574,7 @@ TEST_F(MultiTouchPointerModeTest, PointerGestureMaxSwipeWidthLowResolutionSwipe) ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(1U, motionArgs.pointerCount); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(MotionClassification::TWO_FINGER_SWIPE, motionArgs.classification); // New coordinate is the scaled relative coordinate from the initial coordinate. ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 0, @@ -10584,7 +10608,7 @@ TEST_F(MultiTouchPointerModeTest, PointerGestureMaxSwipeWidthFreeform) { ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(1U, motionArgs.pointerCount); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(MotionClassification::NONE, motionArgs.classification); // One pointer for PRESS, and its coordinate is used as the origin for pointer coordinates. ASSERT_NO_FATAL_FAILURE( @@ -10610,15 +10634,15 @@ TEST_F(MultiTouchPointerModeTest, PointerGestureMaxSwipeWidthFreeform) { ASSERT_EQ(1U, motionArgs.pointerCount); ASSERT_EQ(AMOTION_EVENT_ACTION_CANCEL, motionArgs.action); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1U, motionArgs.pointerCount); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(MotionClassification::NONE, motionArgs.classification); ASSERT_EQ(2U, motionArgs.pointerCount); ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN, motionArgs.action & AMOTION_EVENT_ACTION_MASK); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(MotionClassification::NONE, motionArgs.classification); // Two pointers' scaled relative coordinates from their initial centroid. // Initial y coordinates are 0 as y1 and y2 have the same value. @@ -10648,7 +10672,7 @@ TEST_F(MultiTouchPointerModeTest, PointerGestureMaxSwipeWidthFreeform) { ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(2U, motionArgs.pointerCount); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(MotionClassification::NONE, motionArgs.classification); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], cookedX1, movingDistance * 2 * mPointerMovementScale, 1, 0, 0, @@ -10718,12 +10742,12 @@ TEST_F(MultiTouchPointerModeTest, WhenViewportActiveStatusChanged_PointerGesture ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithSource(AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); // TODO(b/257078296): Pointer mode generates extra event. ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithSource(AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); // Make the viewport inactive. This will put the device in disabled mode, and the ongoing stylus @@ -10735,12 +10759,12 @@ TEST_F(MultiTouchPointerModeTest, WhenViewportActiveStatusChanged_PointerGesture ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL), WithSource(AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); // TODO(b/257078296): Pointer mode generates extra event. ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL), WithSource(AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); } diff --git a/services/inputflinger/tests/NotifyArgs_test.cpp b/services/inputflinger/tests/NotifyArgs_test.cpp index 671558509d..15367568ab 100644 --- a/services/inputflinger/tests/NotifyArgs_test.cpp +++ b/services/inputflinger/tests/NotifyArgs_test.cpp @@ -54,7 +54,7 @@ TEST(NotifyMotionArgsTest, TestCopyAssignmentOperator) { for (size_t i = 0; i < pointerCount; i++) { pointerProperties[i].clear(); pointerProperties[i].id = i; - pointerProperties[i].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + pointerProperties[i].toolType = ToolType::FINGER; pointerCoords[i].clear(); pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, x++); diff --git a/services/inputflinger/tests/PreferStylusOverTouch_test.cpp b/services/inputflinger/tests/PreferStylusOverTouch_test.cpp index 9014dfb48b..9818176cb0 100644 --- a/services/inputflinger/tests/PreferStylusOverTouch_test.cpp +++ b/services/inputflinger/tests/PreferStylusOverTouch_test.cpp @@ -45,8 +45,8 @@ static NotifyMotionArgs generateMotionArgs(nsecs_t downTime, nsecs_t eventTime, PointerCoords pointerCoords[pointerCount]; const int32_t deviceId = isFromSource(source, TOUCHSCREEN) ? TOUCH_DEVICE_ID : STYLUS_DEVICE_ID; - const int32_t toolType = isFromSource(source, TOUCHSCREEN) ? AMOTION_EVENT_TOOL_TYPE_FINGER - : AMOTION_EVENT_TOOL_TYPE_STYLUS; + const ToolType toolType = + isFromSource(source, TOUCHSCREEN) ? ToolType::FINGER : ToolType::STYLUS; for (size_t i = 0; i < pointerCount; i++) { pointerProperties[i].clear(); pointerProperties[i].id = i; @@ -278,20 +278,20 @@ TEST_F(PreferStylusOverTouchTest, MixedStylusAndTouchPointersAreIgnored) { // Event from a stylus device, but with finger tool type args = generateMotionArgs(/*downTime=*/1, /*eventTime=*/1, DOWN, {{1, 2}}, STYLUS); // Keep source stylus, but make the tool type touch - args.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + args.pointerProperties[0].toolType = ToolType::FINGER; assertNotBlocked(args); // Second pointer (stylus pointer) goes down, from the same device args = generateMotionArgs(/*downTime=*/1, /*eventTime=*/2, POINTER_1_DOWN, {{1, 2}, {10, 20}}, STYLUS); // Keep source stylus, but make the tool type touch - args.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args.pointerProperties[0].toolType = ToolType::STYLUS; assertNotBlocked(args); // Second pointer (stylus pointer) goes down, from the same device args = generateMotionArgs(/*downTime=*/1, /*eventTime=*/3, MOVE, {{2, 3}, {11, 21}}, STYLUS); // Keep source stylus, but make the tool type touch - args.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + args.pointerProperties[0].toolType = ToolType::FINGER; assertNotBlocked(args); } @@ -418,14 +418,14 @@ TEST_F(PreferStylusOverTouchTest, MixedStylusAndTouchDeviceIsCanceledAtFirst) { // Introduce a stylus pointer into the device 1 stream. It should be ignored. args = generateMotionArgs(/*downTime=*/1, /*eventTime=*/3, POINTER_1_DOWN, {{1, 2}, {3, 4}}, TOUCHSCREEN); - args.pointerProperties[1].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args.pointerProperties[1].toolType = ToolType::STYLUS; args.source = STYLUS; assertDropped(args); // Lift up touch from the mixed touch/stylus device args = generateMotionArgs(/*downTime=*/1, /*eventTime=*/4, CANCEL, {{1, 2}, {3, 4}}, TOUCHSCREEN); - args.pointerProperties[1].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args.pointerProperties[1].toolType = ToolType::STYLUS; args.source = STYLUS; assertDropped(args); diff --git a/services/inputflinger/tests/TestInputListenerMatchers.h b/services/inputflinger/tests/TestInputListenerMatchers.h index 09f7ae8b1c..338b74766e 100644 --- a/services/inputflinger/tests/TestInputListenerMatchers.h +++ b/services/inputflinger/tests/TestInputListenerMatchers.h @@ -138,8 +138,8 @@ MATCHER_P(WithPressure, pressure, "InputEvent with specified pressure") { MATCHER_P(WithToolType, toolType, "InputEvent with specified tool type") { const auto argToolType = arg.pointerProperties[0].toolType; - *result_listener << "expected tool type " << motionToolTypeToString(toolType) << ", but got " - << motionToolTypeToString(argToolType); + *result_listener << "expected tool type " << ftl::enum_string(toolType) << ", but got " + << ftl::enum_string(argToolType); return argToolType == toolType; } diff --git a/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp b/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp index 3f749b1fed..2a9ace00c5 100644 --- a/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp +++ b/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp @@ -79,7 +79,7 @@ static NotifyMotionArgs generateMotionArgs(nsecs_t downTime, nsecs_t eventTime, for (size_t i = 0; i < pointerCount; i++) { pointerProperties[i].clear(); pointerProperties[i].id = i; - pointerProperties[i].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + pointerProperties[i].toolType = ToolType::FINGER; pointerCoords[i].clear(); pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, points[i].x); @@ -507,7 +507,7 @@ TEST_F(UnwantedInteractionBlockerTest, NoCrashWhenResetHappens) { TEST_F(UnwantedInteractionBlockerTest, NoCrashWhenStylusSourceWithFingerToolIsReceived) { mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()}); NotifyMotionArgs args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, DOWN, {{1, 2, 3}}); - args.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + args.pointerProperties[0].toolType = ToolType::FINGER; args.source = AINPUT_SOURCE_STYLUS; mBlocker->notifyMotion(&args); } @@ -548,15 +548,15 @@ TEST_F(UnwantedInteractionBlockerTest, StylusAfterTouchWorks) { // Now touch down stylus args = generateMotionArgs(/*downTime=*/3, /*eventTime=*/3, DOWN, {{10, 20, 30}}); - args.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args.pointerProperties[0].toolType = ToolType::STYLUS; args.source |= AINPUT_SOURCE_STYLUS; mBlocker->notifyMotion(&args); args = generateMotionArgs(/*downTime=*/3, /*eventTime=*/4, MOVE, {{40, 50, 60}}); - args.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args.pointerProperties[0].toolType = ToolType::STYLUS; args.source |= AINPUT_SOURCE_STYLUS; mBlocker->notifyMotion(&args); args = generateMotionArgs(/*downTime=*/3, /*eventTime=*/5, UP, {{40, 50, 60}}); - args.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args.pointerProperties[0].toolType = ToolType::STYLUS; args.source |= AINPUT_SOURCE_STYLUS; mBlocker->notifyMotion(&args); } @@ -617,14 +617,14 @@ TEST_F(UnwantedInteractionBlockerTest, StylusIsNotBlocked) { info.addSource(AINPUT_SOURCE_STYLUS); mBlocker->notifyInputDevicesChanged({info}); NotifyMotionArgs args1 = generateMotionArgs(/*downTime=*/0, /*eventTime=*/0, DOWN, {{1, 2, 3}}); - args1.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args1.pointerProperties[0].toolType = ToolType::STYLUS; mBlocker->notifyMotion(&args1); mTestListener.assertNotifyMotionWasCalled(WithMotionAction(DOWN)); // Move the stylus, setting large TOUCH_MAJOR/TOUCH_MINOR dimensions NotifyMotionArgs args2 = generateMotionArgs(/*downTime=*/0, RESAMPLE_PERIOD, MOVE, {{4, 5, 200}}); - args2.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args2.pointerProperties[0].toolType = ToolType::STYLUS; mBlocker->notifyMotion(&args2); mTestListener.assertNotifyMotionWasCalled(WithMotionAction(MOVE)); @@ -632,7 +632,7 @@ TEST_F(UnwantedInteractionBlockerTest, StylusIsNotBlocked) { // it's a palm. NotifyMotionArgs args3 = generateMotionArgs(/*downTime=*/0, 2 * RESAMPLE_PERIOD, UP, {{4, 5, 200}}); - args3.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args3.pointerProperties[0].toolType = ToolType::STYLUS; mBlocker->notifyMotion(&args3); mTestListener.assertNotifyMotionWasCalled(WithMotionAction(UP)); } @@ -655,21 +655,21 @@ TEST_F(UnwantedInteractionBlockerTest, TouchIsBlockedWhenMixedWithStylus) { // Stylus pointer down NotifyMotionArgs args2 = generateMotionArgs(/*downTime=*/0, RESAMPLE_PERIOD, POINTER_1_DOWN, {{1, 2, 3}, {10, 20, 30}}); - args2.pointerProperties[1].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args2.pointerProperties[1].toolType = ToolType::STYLUS; mBlocker->notifyMotion(&args2); mTestListener.assertNotifyMotionWasCalled(WithMotionAction(POINTER_1_DOWN)); // Large touch oval on the next finger move NotifyMotionArgs args3 = generateMotionArgs(/*downTime=*/0, 2 * RESAMPLE_PERIOD, MOVE, {{1, 2, 300}, {11, 21, 30}}); - args3.pointerProperties[1].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args3.pointerProperties[1].toolType = ToolType::STYLUS; mBlocker->notifyMotion(&args3); mTestListener.assertNotifyMotionWasCalled(WithMotionAction(MOVE)); // Lift up the finger pointer. It should be canceled due to the heuristic filter. NotifyMotionArgs args4 = generateMotionArgs(/*downTime=*/0, 3 * RESAMPLE_PERIOD, POINTER_0_UP, {{1, 2, 300}, {11, 21, 30}}); - args4.pointerProperties[1].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args4.pointerProperties[1].toolType = ToolType::STYLUS; mBlocker->notifyMotion(&args4); mTestListener.assertNotifyMotionWasCalled( AllOf(WithMotionAction(POINTER_0_UP), WithFlags(FLAG_CANCELED))); @@ -677,7 +677,7 @@ TEST_F(UnwantedInteractionBlockerTest, TouchIsBlockedWhenMixedWithStylus) { NotifyMotionArgs args5 = generateMotionArgs(/*downTime=*/0, 4 * RESAMPLE_PERIOD, MOVE, {{12, 22, 30}}); args5.pointerProperties[0].id = args4.pointerProperties[1].id; - args5.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args5.pointerProperties[0].toolType = ToolType::STYLUS; mBlocker->notifyMotion(&args5); mTestListener.assertNotifyMotionWasCalled(WithMotionAction(MOVE)); @@ -685,7 +685,7 @@ TEST_F(UnwantedInteractionBlockerTest, TouchIsBlockedWhenMixedWithStylus) { NotifyMotionArgs args6 = generateMotionArgs(/*downTime=*/0, 5 * RESAMPLE_PERIOD, UP, {{4, 5, 200}}); args6.pointerProperties[0].id = args4.pointerProperties[1].id; - args6.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args6.pointerProperties[0].toolType = ToolType::STYLUS; mBlocker->notifyMotion(&args6); mTestListener.assertNotifyMotionWasCalled(WithMotionAction(UP)); } diff --git a/services/inputflinger/tests/fuzzers/InputClassifierFuzzer.cpp b/services/inputflinger/tests/fuzzers/InputClassifierFuzzer.cpp index 2909129126..6617f65adf 100644 --- a/services/inputflinger/tests/fuzzers/InputClassifierFuzzer.cpp +++ b/services/inputflinger/tests/fuzzers/InputClassifierFuzzer.cpp @@ -28,7 +28,7 @@ NotifyMotionArgs generateFuzzedMotionArgs(FuzzedDataProvider &fdp) { // Create a basic motion event for testing PointerProperties properties; properties.id = 0; - properties.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + properties.toolType = getFuzzedToolType(fdp); PointerCoords coords; coords.clear(); for (int32_t i = 0; i < fdp.ConsumeIntegralInRange<int32_t>(0, MAX_AXES); i++) { diff --git a/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp b/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp index 20242b1c15..baece3c110 100644 --- a/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp +++ b/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp @@ -165,6 +165,10 @@ public: return reader->getBluetoothAddress(deviceId); } + void sysfsNodeChanged(const std::string& sysfsNodePath) { + reader->sysfsNodeChanged(sysfsNodePath); + } + private: std::unique_ptr<InputReaderInterface> reader; }; diff --git a/services/inputflinger/tests/fuzzers/MapperHelpers.h b/services/inputflinger/tests/fuzzers/MapperHelpers.h index 2cb5cdf9fc..9f4aa5cd5e 100644 --- a/services/inputflinger/tests/fuzzers/MapperHelpers.h +++ b/services/inputflinger/tests/fuzzers/MapperHelpers.h @@ -66,6 +66,14 @@ constexpr size_t kMaxSize = 256; namespace android { +template<class Fdp> +ToolType getFuzzedToolType(Fdp& fdp) { + const int32_t toolType = fdp.template ConsumeIntegralInRange<int32_t>( + static_cast<int32_t>(ToolType::ftl_first), + static_cast<int32_t>(ToolType::ftl_last)); + return static_cast<ToolType>(toolType); +} + class FuzzEventHub : public EventHubInterface { InputDeviceIdentifier mIdentifier; std::vector<TouchVideoFrame> mVideoFrames; @@ -217,6 +225,7 @@ public: bool isDeviceEnabled(int32_t deviceId) const override { return mFdp->ConsumeBool(); } status_t enableDevice(int32_t deviceId) override { return mFdp->ConsumeIntegral<status_t>(); } status_t disableDevice(int32_t deviceId) override { return mFdp->ConsumeIntegral<status_t>(); } + void sysfsNodeChanged(const std::string& sysfsNodePath) override {} }; class FuzzPointerController : public PointerControllerInterface { diff --git a/services/inputflinger/tests/fuzzers/MultiTouchInputFuzzer.cpp b/services/inputflinger/tests/fuzzers/MultiTouchInputFuzzer.cpp index 59cb94a2e2..20db39d885 100644 --- a/services/inputflinger/tests/fuzzers/MultiTouchInputFuzzer.cpp +++ b/services/inputflinger/tests/fuzzers/MultiTouchInputFuzzer.cpp @@ -128,7 +128,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) { StylusState state{fdp->ConsumeIntegral<nsecs_t>(), fdp->ConsumeFloatingPoint<float>(), fdp->ConsumeIntegral<uint32_t>(), - fdp->ConsumeIntegral<int32_t>()}; + getFuzzedToolType(*fdp)}; std::list<NotifyArgs> unused = mapper.updateExternalStylusState(state); }, [&]() -> void { mapper.getAssociatedDisplayId(); }, diff --git a/services/powermanager/Android.bp b/services/powermanager/Android.bp index 7fb33e5dcf..b34e54fd6b 100644 --- a/services/powermanager/Android.bp +++ b/services/powermanager/Android.bp @@ -43,6 +43,14 @@ cc_library_shared { "android.hardware.power-V4-cpp", ], + export_shared_lib_headers: [ + "android.hardware.power@1.0", + "android.hardware.power@1.1", + "android.hardware.power@1.2", + "android.hardware.power@1.3", + "android.hardware.power-V4-cpp", + ], + cflags: [ "-Wall", "-Werror", diff --git a/services/sensorservice/SensorEventConnection.cpp b/services/sensorservice/SensorEventConnection.cpp index b94b1c0a1a..7a6b31d642 100644 --- a/services/sensorservice/SensorEventConnection.cpp +++ b/services/sensorservice/SensorEventConnection.cpp @@ -55,14 +55,13 @@ SensorService::SensorEventConnection::SensorEventConnection( SensorService::SensorEventConnection::~SensorEventConnection() { ALOGD_IF(DEBUG_CONNECTIONS, "~SensorEventConnection(%p)", this); destroy(); - mService->cleanupConnection(this); - if (mEventCache != nullptr) { - delete[] mEventCache; - } + delete[] mEventCache; } void SensorService::SensorEventConnection::destroy() { - mDestroyed = true; + if (!mDestroyed.exchange(true)) { + mService->cleanupConnection(this); + } } void SensorService::SensorEventConnection::onFirstRef() { diff --git a/services/stats/Android.bp b/services/stats/Android.bp index 7d358e1bd2..6b99627f5a 100644 --- a/services/stats/Android.bp +++ b/services/stats/Android.bp @@ -21,6 +21,7 @@ cc_library_shared { "android.frameworks.stats@1.0", "android.frameworks.stats-V2-ndk", "libbinder_ndk", + "libexpresslog", "libhidlbase", "liblog", "libstatslog", diff --git a/services/stats/StatsAidl.cpp b/services/stats/StatsAidl.cpp index 0f01507c9f..b22f903654 100644 --- a/services/stats/StatsAidl.cpp +++ b/services/stats/StatsAidl.cpp @@ -22,6 +22,7 @@ #include "StatsAidl.h" +#include <Counter.h> #include <log/log.h> #include <stats_annotations.h> #include <stats_event.h> @@ -29,11 +30,18 @@ #include <unordered_map> +namespace { + static const char* g_AtomErrorMetricName = + "statsd_errors.value_report_vendor_atom_errors_count"; +} + namespace aidl { namespace android { namespace frameworks { namespace stats { +using ::android::expresslog::Counter; + template <typename E> constexpr typename std::underlying_type<E>::type to_underlying(E e) noexcept { return static_cast<typename std::underlying_type<E>::type>(e); @@ -86,12 +94,14 @@ bool write_field_annotations(AStatsEvent* event, const std::vector<Annotation>& ndk::ScopedAStatus StatsHal::reportVendorAtom(const VendorAtom& vendorAtom) { if (vendorAtom.atomId < 100000 || vendorAtom.atomId >= 200000) { ALOGE("Atom ID %ld is not a valid vendor atom ID", (long)vendorAtom.atomId); + Counter::logIncrement(g_AtomErrorMetricName); return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage( -1, "Not a valid vendor atom ID"); } if (vendorAtom.reverseDomainName.length() > 50) { ALOGE("Vendor atom reverse domain name %s is too long.", vendorAtom.reverseDomainName.c_str()); + Counter::logIncrement(g_AtomErrorMetricName); return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage( -1, "Vendor atom reverse domain name is too long"); } @@ -100,8 +110,9 @@ ndk::ScopedAStatus StatsHal::reportVendorAtom(const VendorAtom& vendorAtom) { if (vendorAtom.atomAnnotations) { if (!write_atom_annotations(event, *vendorAtom.atomAnnotations)) { - ALOGE("Atom ID %ld has incompatible atom level annotation", (long)vendorAtom.atomId); AStatsEvent_release(event); + ALOGE("Atom ID %ld has incompatible atom level annotation", (long)vendorAtom.atomId); + Counter::logIncrement(g_AtomErrorMetricName); return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage( -1, "invalid atom annotation"); } @@ -222,6 +233,7 @@ ndk::ScopedAStatus StatsHal::reportVendorAtom(const VendorAtom& vendorAtom) { default: { AStatsEvent_release(event); ALOGE("Atom ID %ld has invalid atomValue.getTag", (long)vendorAtom.atomId); + Counter::logIncrement(g_AtomErrorMetricName); return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage( -1, "invalid atomValue.getTag"); break; @@ -235,9 +247,10 @@ ndk::ScopedAStatus StatsHal::reportVendorAtom(const VendorAtom& vendorAtom) { VLOG("Atom ID %ld has %ld annotations for field #%ld", (long)vendorAtom.atomId, (long)fieldAnnotations.size(), (long)atomValueIdx + 2); if (!write_field_annotations(event, fieldAnnotations)) { + AStatsEvent_release(event); ALOGE("Atom ID %ld has incompatible field level annotation for field #%ld", (long)vendorAtom.atomId, (long)atomValueIdx + 2); - AStatsEvent_release(event); + Counter::logIncrement(g_AtomErrorMetricName); return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage( -1, "invalid atom field annotation"); } @@ -249,6 +262,7 @@ ndk::ScopedAStatus StatsHal::reportVendorAtom(const VendorAtom& vendorAtom) { AStatsEvent_release(event); if (ret <= 0) { ALOGE("Error writing Atom ID %ld. Result: %d", (long)vendorAtom.atomId, ret); + Counter::logIncrement(g_AtomErrorMetricName); } return ret <= 0 ? ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage(ret, "report atom failed") diff --git a/services/surfaceflinger/Android.bp b/services/surfaceflinger/Android.bp index fe7cff7577..5683a9280f 100644 --- a/services/surfaceflinger/Android.bp +++ b/services/surfaceflinger/Android.bp @@ -47,8 +47,6 @@ cc_defaults { "android.hardware.graphics.composer@2.2", "android.hardware.graphics.composer@2.3", "android.hardware.graphics.composer@2.4", - "android.hardware.power@1.0", - "android.hardware.power@1.3", "android.hardware.power-V4-cpp", "libbase", "libbinder", @@ -63,6 +61,7 @@ cc_defaults { "liblayers_proto", "liblog", "libnativewindow", + "libpowermanager", "libprocessgroup", "libprotobuf-cpp-lite", "libsync", @@ -105,7 +104,7 @@ cc_defaults { "android.hardware.graphics.composer@2.2", "android.hardware.graphics.composer@2.3", "android.hardware.graphics.composer@2.4", - "android.hardware.power@1.3", + "libpowermanager", "libhidlbase", "libtimestats", ], diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/CompositionRefreshArgs.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/CompositionRefreshArgs.h index a8322d8572..d93e25e4ca 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/CompositionRefreshArgs.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/CompositionRefreshArgs.h @@ -83,12 +83,9 @@ struct CompositionRefreshArgs { // If set, causes the dirty regions to flash with the delay std::optional<std::chrono::microseconds> devOptFlashDirtyRegionsDelay; - // The earliest time to send the present command to the HAL - std::chrono::steady_clock::time_point earliestPresentTime; - - // The previous present fence. Used together with earliestPresentTime - // to prevent an early presentation of a frame. - std::shared_ptr<FenceTime> previousPresentFence; + // Optional. + // The earliest time to send the present command to the HAL. + std::optional<std::chrono::steady_clock::time_point> earliestPresentTime; // The expected time for the next present nsecs_t expectedPresentTime{0}; diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h index eae5871477..35ca3a58d9 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h @@ -210,8 +210,8 @@ struct LayerFECompositionState { // The dimming flag bool dimmingEnabled{true}; - float currentSdrHdrRatio = 1.f; - float desiredSdrHdrRatio = 1.f; + float currentHdrSdrRatio = 1.f; + float desiredHdrSdrRatio = 1.f; gui::CachingHint cachingHint = gui::CachingHint::Enabled; virtual ~LayerFECompositionState(); diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputCompositionState.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputCompositionState.h index c29165210d..a3fda61ecb 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputCompositionState.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputCompositionState.h @@ -122,12 +122,9 @@ struct OutputCompositionState { bool previousDeviceRequestedSuccess = false; + // Optional. // The earliest time to send the present command to the HAL - std::chrono::steady_clock::time_point earliestPresentTime; - - // The previous present fence. Used together with earliestPresentTime - // to prevent an early presentation of a frame. - std::shared_ptr<FenceTime> previousPresentFence; + std::optional<std::chrono::steady_clock::time_point> earliestPresentTime; // The expected time for the next present nsecs_t expectedPresentTime{0}; diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/LayerState.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/LayerState.h index d5c488e40e..ce2b96fc2b 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/LayerState.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/LayerState.h @@ -247,6 +247,10 @@ public: ui::Dataspace getDataspace() const { return mOutputDataspace.get(); } + float getHdrSdrRatio() const { + return getOutputLayer()->getLayerFE().getCompositionState()->currentHdrSdrRatio; + }; + wp<GraphicBuffer> getBuffer() const { return mBuffer.get(); } bool isProtected() const { return mIsProtected.get(); } diff --git a/services/surfaceflinger/CompositionEngine/src/Display.cpp b/services/surfaceflinger/CompositionEngine/src/Display.cpp index d50a768474..85fc09549b 100644 --- a/services/surfaceflinger/CompositionEngine/src/Display.cpp +++ b/services/surfaceflinger/CompositionEngine/src/Display.cpp @@ -263,7 +263,6 @@ bool Display::chooseCompositionStrategy( if (status_t result = hwc.getDeviceCompositionChanges(*halDisplayId, requiresClientComposition, getState().earliestPresentTime, - getState().previousPresentFence, getState().expectedPresentTime, outChanges); result != NO_ERROR) { ALOGE("chooseCompositionStrategy failed for %s: %d (%s)", getName().c_str(), result, @@ -380,16 +379,11 @@ compositionengine::Output::FrameFences Display::presentAndGetFrameFences() { const TimePoint startTime = TimePoint::now(); - if (isPowerHintSessionEnabled()) { - if (!getCompositionEngine().getHwComposer().getComposer()->isSupported( - Hwc2::Composer::OptionalFeature::ExpectedPresentTime) && - getState().previousPresentFence->getSignalTime() != Fence::SIGNAL_TIME_PENDING) { - mPowerAdvisor->setHwcPresentDelayedTime(mId, getState().earliestPresentTime); - } + if (isPowerHintSessionEnabled() && getState().earliestPresentTime) { + mPowerAdvisor->setHwcPresentDelayedTime(mId, *getState().earliestPresentTime); } - hwc.presentAndGetReleaseFences(*halDisplayIdOpt, getState().earliestPresentTime, - getState().previousPresentFence); + hwc.presentAndGetReleaseFences(*halDisplayIdOpt, getState().earliestPresentTime); if (isPowerHintSessionEnabled()) { mPowerAdvisor->setHwcPresentTiming(mId, startTime, TimePoint::now()); diff --git a/services/surfaceflinger/CompositionEngine/src/LayerFECompositionState.cpp b/services/surfaceflinger/CompositionEngine/src/LayerFECompositionState.cpp index 615d04b460..426cc57db8 100644 --- a/services/surfaceflinger/CompositionEngine/src/LayerFECompositionState.cpp +++ b/services/surfaceflinger/CompositionEngine/src/LayerFECompositionState.cpp @@ -121,9 +121,9 @@ void LayerFECompositionState::dump(std::string& out) const { dumpVal(out, "dataspace", toString(dataspace), dataspace); dumpVal(out, "hdr metadata types", hdrMetadata.validTypes); dumpVal(out, "dimming enabled", dimmingEnabled); - if (currentSdrHdrRatio > 1.01f || desiredSdrHdrRatio > 1.01f) { - dumpVal(out, "current sdr/hdr ratio", currentSdrHdrRatio); - dumpVal(out, "desired sdr/hdr ratio", desiredSdrHdrRatio); + if (currentHdrSdrRatio > 1.01f || desiredHdrSdrRatio > 1.01f) { + dumpVal(out, "current hdr/sdr ratio", currentHdrSdrRatio); + dumpVal(out, "desired hdr/sdr ratio", desiredHdrSdrRatio); } dumpVal(out, "colorTransform", colorTransform); dumpVal(out, "caching hint", toString(cachingHint)); diff --git a/services/surfaceflinger/CompositionEngine/src/Output.cpp b/services/surfaceflinger/CompositionEngine/src/Output.cpp index 175dd1d825..e720af5a33 100644 --- a/services/surfaceflinger/CompositionEngine/src/Output.cpp +++ b/services/surfaceflinger/CompositionEngine/src/Output.cpp @@ -842,7 +842,6 @@ void Output::writeCompositionState(const compositionengine::CompositionRefreshAr } editState().earliestPresentTime = refreshArgs.earliestPresentTime; - editState().previousPresentFence = refreshArgs.previousPresentFence; editState().expectedPresentTime = refreshArgs.expectedPresentTime; compositionengine::OutputLayer* peekThroughLayer = nullptr; diff --git a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp index 1b86cd376a..0ac0ecb727 100644 --- a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp +++ b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp @@ -344,8 +344,8 @@ void OutputLayer::updateCompositionState( // RANGE_EXTENDED can "self-promote" to HDR, but is still rendered for a particular // range that we may need to re-adjust to the current display conditions if ((state.dataspace & HAL_DATASPACE_RANGE_MASK) == HAL_DATASPACE_RANGE_EXTENDED && - layerFEState->currentSdrHdrRatio > 1.01f) { - layerBrightnessNits *= layerFEState->currentSdrHdrRatio; + layerFEState->currentHdrSdrRatio > 1.01f) { + layerBrightnessNits *= layerFEState->currentHdrSdrRatio; } state.dimmingRatio = std::clamp(layerBrightnessNits / getOutput().getState().displayBrightnessNits, 0.f, diff --git a/services/surfaceflinger/CompositionEngine/src/planner/CachedSet.cpp b/services/surfaceflinger/CompositionEngine/src/planner/CachedSet.cpp index a00ce57e29..8ced0aca36 100644 --- a/services/surfaceflinger/CompositionEngine/src/planner/CachedSet.cpp +++ b/services/surfaceflinger/CompositionEngine/src/planner/CachedSet.cpp @@ -378,6 +378,10 @@ bool CachedSet::hasUnsupportedDataspace() const { // to avoid flickering/color differences. return true; } + // TODO(b/274804887): temp fix of overdimming issue, skip caching if hsdr/sdr ratio > 1.01f + if (layer.getState()->getHdrSdrRatio() > 1.01f) { + return true; + } return false; }); } diff --git a/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp b/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp index 0756c1becd..9be6bc2075 100644 --- a/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp +++ b/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp @@ -595,7 +595,7 @@ TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfGpuDisplay) { TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) { EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false)); EXPECT_CALL(mHwComposer, - getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), false, _, _, _, _)) + getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), false, _, _, _)) .WillOnce(Return(INVALID_OPERATION)); chooseCompositionStrategy(mDisplay.get()); @@ -619,8 +619,8 @@ TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) { .WillOnce(Return(false)); EXPECT_CALL(mHwComposer, - getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _)) - .WillOnce(testing::DoAll(testing::SetArgPointee<5>(mDeviceRequestedChanges), + getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _)) + .WillOnce(testing::DoAll(testing::SetArgPointee<4>(mDeviceRequestedChanges), Return(NO_ERROR))); EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(mDeviceRequestedChanges.changedTypes)) .Times(1); @@ -672,8 +672,8 @@ TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) { .WillOnce(Return(false)); EXPECT_CALL(mHwComposer, - getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _)) - .WillOnce(DoAll(SetArgPointee<5>(mDeviceRequestedChanges), Return(NO_ERROR))); + getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _)) + .WillOnce(DoAll(SetArgPointee<4>(mDeviceRequestedChanges), Return(NO_ERROR))); EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(mDeviceRequestedChanges.changedTypes)) .Times(1); EXPECT_CALL(*mDisplay, applyDisplayRequests(mDeviceRequestedChanges.displayRequests)).Times(1); @@ -901,7 +901,7 @@ TEST_F(DisplayPresentAndGetFrameFencesTest, returnsPresentAndLayerFences) { sp<Fence> layer1Fence = sp<Fence>::make(); sp<Fence> layer2Fence = sp<Fence>::make(); - EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID), _, _)) + EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID), _)) .Times(1); EXPECT_CALL(mHwComposer, getPresentFence(HalDisplayId(DEFAULT_DISPLAY_ID))) .WillOnce(Return(presentFence)); @@ -1078,7 +1078,7 @@ TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) { mDisplay->editState().isEnabled = true; - EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(_, _, _)); + EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(_, _)); EXPECT_CALL(*mDisplaySurface, onFrameCommitted()); mDisplay->postFramebuffer(); diff --git a/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h b/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h index 1a56ab751f..67b94ee749 100644 --- a/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h +++ b/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h @@ -54,16 +54,14 @@ public: MOCK_METHOD2(allocatePhysicalDisplay, void(hal::HWDisplayId, PhysicalDisplayId)); MOCK_METHOD1(createLayer, std::shared_ptr<HWC2::Layer>(HalDisplayId)); - MOCK_METHOD6(getDeviceCompositionChanges, - status_t(HalDisplayId, bool, std::chrono::steady_clock::time_point, - const std::shared_ptr<FenceTime>&, nsecs_t, - std::optional<android::HWComposer::DeviceRequestedChanges>*)); + MOCK_METHOD5(getDeviceCompositionChanges, + status_t(HalDisplayId, bool, std::optional<std::chrono::steady_clock::time_point>, + nsecs_t, std::optional<android::HWComposer::DeviceRequestedChanges>*)); MOCK_METHOD5(setClientTarget, status_t(HalDisplayId, uint32_t, const sp<Fence>&, const sp<GraphicBuffer>&, ui::Dataspace)); - MOCK_METHOD3(presentAndGetReleaseFences, - status_t(HalDisplayId, std::chrono::steady_clock::time_point, - const std::shared_ptr<FenceTime>&)); + MOCK_METHOD2(presentAndGetReleaseFences, + status_t(HalDisplayId, std::optional<std::chrono::steady_clock::time_point>)); MOCK_METHOD2(setPowerMode, status_t(PhysicalDisplayId, hal::PowerMode)); MOCK_METHOD2(setActiveConfig, status_t(HalDisplayId, size_t)); MOCK_METHOD2(setColorTransform, status_t(HalDisplayId, const mat4&)); diff --git a/services/surfaceflinger/CompositionEngine/tests/MockPowerAdvisor.h b/services/surfaceflinger/CompositionEngine/tests/MockPowerAdvisor.h index c555b39db1..961ec808e8 100644 --- a/services/surfaceflinger/CompositionEngine/tests/MockPowerAdvisor.h +++ b/services/surfaceflinger/CompositionEngine/tests/MockPowerAdvisor.h @@ -37,11 +37,10 @@ public: MOCK_METHOD(void, notifyDisplayUpdateImminentAndCpuReset, (), (override)); MOCK_METHOD(bool, usePowerHintSession, (), (override)); MOCK_METHOD(bool, supportsPowerHintSession, (), (override)); - MOCK_METHOD(bool, isPowerHintSessionRunning, (), (override)); - MOCK_METHOD(void, setTargetWorkDuration, (Duration targetDuration), (override)); - MOCK_METHOD(void, sendActualWorkDuration, (), (override)); - MOCK_METHOD(void, sendPredictedWorkDuration, (), (override)); - MOCK_METHOD(void, enablePowerHint, (bool enabled), (override)); + MOCK_METHOD(bool, ensurePowerHintSessionRunning, (), (override)); + MOCK_METHOD(void, updateTargetWorkDuration, (Duration targetDuration), (override)); + MOCK_METHOD(void, reportActualWorkDuration, (), (override)); + MOCK_METHOD(void, enablePowerHintSession, (bool enabled), (override)); MOCK_METHOD(bool, startPowerHintSession, (const std::vector<int32_t>& threadIds), (override)); MOCK_METHOD(void, setGpuFenceTime, (DisplayId displayId, std::unique_ptr<FenceTime>&& fenceTime), (override)); diff --git a/services/surfaceflinger/CompositionEngine/tests/planner/CachedSetTest.cpp b/services/surfaceflinger/CompositionEngine/tests/planner/CachedSetTest.cpp index ca5ba69e8e..bd030d090f 100644 --- a/services/surfaceflinger/CompositionEngine/tests/planner/CachedSetTest.cpp +++ b/services/surfaceflinger/CompositionEngine/tests/planner/CachedSetTest.cpp @@ -662,6 +662,26 @@ TEST_F(CachedSetTest, holePunch_requiresNonBT601_625) { EXPECT_FALSE(cachedSet.requiresHolePunch()); } +TEST_F(CachedSetTest, holePunch_requiresNonHdrWithExtendedBrightness) { + const auto dataspace = static_cast<ui::Dataspace>(ui::Dataspace::STANDARD_DCI_P3 | + ui::Dataspace::TRANSFER_SRGB | + ui::Dataspace::RANGE_EXTENDED); + mTestLayers[0]->outputLayerCompositionState.dataspace = dataspace; + mTestLayers[0]->layerFECompositionState.currentHdrSdrRatio = 5.f; + mTestLayers[0]->layerState->update(&mTestLayers[0]->outputLayer); + + CachedSet::Layer& layer = *mTestLayers[0]->cachedSetLayer.get(); + auto& layerFECompositionState = mTestLayers[0]->layerFECompositionState; + layerFECompositionState.buffer = sp<GraphicBuffer>::make(); + layerFECompositionState.blendMode = hal::BlendMode::NONE; + sp<mock::LayerFE> layerFE = mTestLayers[0]->layerFE; + + CachedSet cachedSet(layer); + EXPECT_CALL(*layerFE, hasRoundedCorners()).WillRepeatedly(Return(true)); + + EXPECT_FALSE(cachedSet.requiresHolePunch()); +} + TEST_F(CachedSetTest, holePunch_requiresNoBlending) { CachedSet::Layer& layer = *mTestLayers[0]->cachedSetLayer.get(); auto& layerFECompositionState = mTestLayers[0]->layerFECompositionState; diff --git a/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp b/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp index bd2680fbb5..f28bfd44cd 100644 --- a/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp +++ b/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp @@ -1547,6 +1547,8 @@ void AidlComposer::onHotplugDisconnect(Display display) { } bool AidlComposer::hasMultiThreadedPresentSupport(Display display) { +#if 0 + // TODO (b/259132483): Reenable const auto displayId = translate<int64_t>(display); std::vector<AidlDisplayCapability> capabilities; const auto status = mAidlComposerClient->getDisplayCapabilities(displayId, &capabilities); @@ -1556,6 +1558,10 @@ bool AidlComposer::hasMultiThreadedPresentSupport(Display display) { } return std::find(capabilities.begin(), capabilities.end(), AidlDisplayCapability::MULTI_THREADED_PRESENT) != capabilities.end(); +#else + (void) display; + return false; +#endif } void AidlComposer::addReader(Display display) { diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp index 28148ac1dc..f350eba7ca 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp +++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp @@ -395,8 +395,8 @@ status_t HWComposer::setClientTarget(HalDisplayId displayId, uint32_t slot, status_t HWComposer::getDeviceCompositionChanges( HalDisplayId displayId, bool frameUsesClientComposition, - std::chrono::steady_clock::time_point earliestPresentTime, - const std::shared_ptr<FenceTime>& previousPresentFence, nsecs_t expectedPresentTime, + std::optional<std::chrono::steady_clock::time_point> earliestPresentTime, + nsecs_t expectedPresentTime, std::optional<android::HWComposer::DeviceRequestedChanges>* outChanges) { ATRACE_CALL(); @@ -426,14 +426,13 @@ status_t HWComposer::getDeviceCompositionChanges( // If composer supports getting the expected present time, we can skip // as composer will make sure to prevent early presentation - if (mComposer->isSupported(Hwc2::Composer::OptionalFeature::ExpectedPresentTime)) { + if (!earliestPresentTime) { return true; } // composer doesn't support getting the expected present time. We can only // skip validate if we know that we are not going to present early. - return std::chrono::steady_clock::now() >= earliestPresentTime || - previousPresentFence->getSignalTime() == Fence::SIGNAL_TIME_PENDING; + return std::chrono::steady_clock::now() >= *earliestPresentTime; }(); displayData.validateWasSkipped = false; @@ -508,8 +507,8 @@ sp<Fence> HWComposer::getLayerReleaseFence(HalDisplayId displayId, HWC2::Layer* } status_t HWComposer::presentAndGetReleaseFences( - HalDisplayId displayId, std::chrono::steady_clock::time_point earliestPresentTime, - const std::shared_ptr<FenceTime>& previousPresentFence) { + HalDisplayId displayId, + std::optional<std::chrono::steady_clock::time_point> earliestPresentTime) { ATRACE_CALL(); RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); @@ -525,13 +524,9 @@ status_t HWComposer::presentAndGetReleaseFences( return NO_ERROR; } - const bool waitForEarliestPresent = - !mComposer->isSupported(Hwc2::Composer::OptionalFeature::ExpectedPresentTime) && - previousPresentFence->getSignalTime() != Fence::SIGNAL_TIME_PENDING; - - if (waitForEarliestPresent) { + if (earliestPresentTime) { ATRACE_NAME("wait for earliest present time"); - std::this_thread::sleep_until(earliestPresentTime); + std::this_thread::sleep_until(*earliestPresentTime); } auto error = hwcDisplay->present(&displayData.lastPresentFence); diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.h b/services/surfaceflinger/DisplayHardware/HWComposer.h index 7a3f41cc1c..3702c62b65 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.h +++ b/services/surfaceflinger/DisplayHardware/HWComposer.h @@ -143,17 +143,16 @@ public: // expected. virtual status_t getDeviceCompositionChanges( HalDisplayId, bool frameUsesClientComposition, - std::chrono::steady_clock::time_point earliestPresentTime, - const std::shared_ptr<FenceTime>& previousPresentFence, nsecs_t expectedPresentTime, - std::optional<DeviceRequestedChanges>* outChanges) = 0; + std::optional<std::chrono::steady_clock::time_point> earliestPresentTime, + nsecs_t expectedPresentTime, std::optional<DeviceRequestedChanges>* outChanges) = 0; virtual status_t setClientTarget(HalDisplayId, uint32_t slot, const sp<Fence>& acquireFence, const sp<GraphicBuffer>& target, ui::Dataspace) = 0; // Present layers to the display and read releaseFences. virtual status_t presentAndGetReleaseFences( - HalDisplayId, std::chrono::steady_clock::time_point earliestPresentTime, - const std::shared_ptr<FenceTime>& previousPresentFence) = 0; + HalDisplayId, + std::optional<std::chrono::steady_clock::time_point> earliestPresentTime) = 0; // set power mode virtual status_t setPowerMode(PhysicalDisplayId, hal::PowerMode) = 0; @@ -339,8 +338,8 @@ public: status_t getDeviceCompositionChanges( HalDisplayId, bool frameUsesClientComposition, - std::chrono::steady_clock::time_point earliestPresentTime, - const std::shared_ptr<FenceTime>& previousPresentFence, nsecs_t expectedPresentTime, + std::optional<std::chrono::steady_clock::time_point> earliestPresentTime, + nsecs_t expectedPresentTime, std::optional<DeviceRequestedChanges>* outChanges) override; status_t setClientTarget(HalDisplayId, uint32_t slot, const sp<Fence>& acquireFence, @@ -348,8 +347,8 @@ public: // Present layers to the display and read releaseFences. status_t presentAndGetReleaseFences( - HalDisplayId, std::chrono::steady_clock::time_point earliestPresentTime, - const std::shared_ptr<FenceTime>& previousPresentFence) override; + HalDisplayId, + std::optional<std::chrono::steady_clock::time_point> earliestPresentTime) override; // set power mode status_t setPowerMode(PhysicalDisplayId, hal::PowerMode mode) override; diff --git a/services/surfaceflinger/DisplayHardware/PowerAdvisor.cpp b/services/surfaceflinger/DisplayHardware/PowerAdvisor.cpp index f05223cce0..37b68c865e 100644 --- a/services/surfaceflinger/DisplayHardware/PowerAdvisor.cpp +++ b/services/surfaceflinger/DisplayHardware/PowerAdvisor.cpp @@ -31,7 +31,7 @@ #include <utils/Mutex.h> #include <utils/Trace.h> -#include <android/hardware/power/1.3/IPower.h> +#include <android/hardware/power/IPower.h> #include <android/hardware/power/IPowerHintSession.h> #include <android/hardware/power/WorkDuration.h> @@ -49,12 +49,7 @@ PowerAdvisor::~PowerAdvisor() = default; namespace impl { -namespace V1_0 = android::hardware::power::V1_0; -namespace V1_3 = android::hardware::power::V1_3; -using V1_3::PowerHint; - using android::hardware::power::Boost; -using android::hardware::power::IPower; using android::hardware::power::IPowerHintSession; using android::hardware::power::Mode; using android::hardware::power::SessionHint; @@ -80,7 +75,8 @@ void traceExpensiveRendering(bool enabled) { } // namespace -PowerAdvisor::PowerAdvisor(SurfaceFlinger& flinger) : mFlinger(flinger) { +PowerAdvisor::PowerAdvisor(SurfaceFlinger& flinger) + : mPowerHal(std::make_unique<power::PowerHalController>()), mFlinger(flinger) { if (getUpdateTimeout() > 0ms) { mScreenUpdateTimer.emplace("UpdateImminentTimer", getUpdateTimeout(), /* resetCallback */ nullptr, @@ -117,6 +113,10 @@ void PowerAdvisor::onBootFinished() { } void PowerAdvisor::setExpensiveRenderingExpected(DisplayId displayId, bool expected) { + if (!mHasExpensiveRendering) { + ALOGV("Skipped sending EXPENSIVE_RENDERING because HAL doesn't support it"); + return; + } if (expected) { mExpensiveDisplays.insert(displayId); } else { @@ -125,19 +125,16 @@ void PowerAdvisor::setExpensiveRenderingExpected(DisplayId displayId, bool expec const bool expectsExpensiveRendering = !mExpensiveDisplays.empty(); if (mNotifiedExpensiveRendering != expectsExpensiveRendering) { - std::lock_guard lock(mPowerHalMutex); - HalWrapper* const halWrapper = getPowerHal(); - if (halWrapper == nullptr) { - return; - } - - if (!halWrapper->setExpensiveRendering(expectsExpensiveRendering)) { - // The HAL has become unavailable; attempt to reconnect later - mReconnectPowerHal = true; + auto ret = getPowerHal().setMode(Mode::EXPENSIVE_RENDERING, expectsExpensiveRendering); + if (!ret.isOk()) { + if (ret.isUnsupported()) { + mHasExpensiveRendering = false; + } return; } mNotifiedExpensiveRendering = expectsExpensiveRendering; + traceExpensiveRendering(mNotifiedExpensiveRendering); } } @@ -149,16 +146,22 @@ void PowerAdvisor::notifyDisplayUpdateImminentAndCpuReset() { } if (mSendUpdateImminent.exchange(false)) { - std::lock_guard lock(mPowerHalMutex); - HalWrapper* const halWrapper = getPowerHal(); - if (halWrapper == nullptr) { - return; + ALOGV("AIDL notifyDisplayUpdateImminentAndCpuReset"); + if (usePowerHintSession() && ensurePowerHintSessionRunning()) { + std::lock_guard lock(mHintSessionMutex); + auto ret = mHintSession->sendHint(SessionHint::CPU_LOAD_RESET); + if (!ret.isOk()) { + mHintSessionRunning = false; + } } - if (!halWrapper->notifyDisplayUpdateImminentAndCpuReset()) { - // The HAL has become unavailable; attempt to reconnect later - mReconnectPowerHal = true; - return; + if (!mHasDisplayUpdateImminent) { + ALOGV("Skipped sending DISPLAY_UPDATE_IMMINENT because HAL doesn't support it"); + } else { + auto ret = getPowerHal().setBoost(Boost::DISPLAY_UPDATE_IMMINENT, 0); + if (ret.isUnsupported()) { + mHasDisplayUpdateImminent = false; + } } if (mScreenUpdateTimer) { @@ -178,88 +181,123 @@ void PowerAdvisor::notifyDisplayUpdateImminentAndCpuReset() { // checks both if it supports and if it's enabled bool PowerAdvisor::usePowerHintSession() { // uses cached value since the underlying support and flag are unlikely to change at runtime - return mPowerHintEnabled.value_or(false) && supportsPowerHintSession(); + return mHintSessionEnabled.value_or(false) && supportsPowerHintSession(); } bool PowerAdvisor::supportsPowerHintSession() { // cache to avoid needing lock every time - if (!mSupportsPowerHint.has_value()) { - std::lock_guard lock(mPowerHalMutex); - HalWrapper* const halWrapper = getPowerHal(); - mSupportsPowerHint = halWrapper && halWrapper->supportsPowerHintSession(); + if (!mSupportsHintSession.has_value()) { + mSupportsHintSession = getPowerHal().getHintSessionPreferredRate().isOk(); } - return *mSupportsPowerHint; + return *mSupportsHintSession; } -bool PowerAdvisor::isPowerHintSessionRunning() { - return mPowerHintSessionRunning; +bool PowerAdvisor::ensurePowerHintSessionRunning() { + if (!mHintSessionRunning && !mHintSessionThreadIds.empty() && usePowerHintSession()) { + startPowerHintSession(mHintSessionThreadIds); + } + return mHintSessionRunning; } -void PowerAdvisor::setTargetWorkDuration(Duration targetDuration) { +void PowerAdvisor::updateTargetWorkDuration(Duration targetDuration) { if (!usePowerHintSession()) { ALOGV("Power hint session target duration cannot be set, skipping"); return; } + ATRACE_CALL(); { - std::lock_guard lock(mPowerHalMutex); - HalWrapper* const halWrapper = getPowerHal(); - if (halWrapper != nullptr) { - halWrapper->setTargetWorkDuration(targetDuration); + mTargetDuration = targetDuration; + if (sTraceHintSessionData) ATRACE_INT64("Time target", targetDuration.ns()); + if (ensurePowerHintSessionRunning() && (targetDuration != mLastTargetDurationSent)) { + ALOGV("Sending target time: %" PRId64 "ns", targetDuration.ns()); + mLastTargetDurationSent = targetDuration; + std::lock_guard lock(mHintSessionMutex); + auto ret = mHintSession->updateTargetWorkDuration(targetDuration.ns()); + if (!ret.isOk()) { + ALOGW("Failed to set power hint target work duration with error: %s", + ret.exceptionMessage().c_str()); + mHintSessionRunning = false; + } } } } -void PowerAdvisor::sendActualWorkDuration() { +void PowerAdvisor::reportActualWorkDuration() { if (!mBootFinished || !usePowerHintSession()) { ALOGV("Actual work duration power hint cannot be sent, skipping"); return; } - const std::optional<Duration> actualDuration = estimateWorkDuration(false); - if (actualDuration.has_value()) { - std::lock_guard lock(mPowerHalMutex); - HalWrapper* const halWrapper = getPowerHal(); - if (halWrapper != nullptr) { - halWrapper->sendActualWorkDuration(*actualDuration + kTargetSafetyMargin, - TimePoint::now()); - } + ATRACE_CALL(); + std::optional<Duration> actualDuration = estimateWorkDuration(); + if (!actualDuration.has_value() || actualDuration < 0ns || !ensurePowerHintSessionRunning()) { + ALOGV("Failed to send actual work duration, skipping"); + return; } -} + actualDuration = std::make_optional(*actualDuration + sTargetSafetyMargin); + mActualDuration = actualDuration; + WorkDuration duration; + duration.durationNanos = actualDuration->ns(); + duration.timeStampNanos = TimePoint::now().ns(); + mHintSessionQueue.push_back(duration); -void PowerAdvisor::sendPredictedWorkDuration() { - if (!mBootFinished || !usePowerHintSession()) { - ALOGV("Actual work duration power hint cannot be sent, skipping"); - return; + if (sTraceHintSessionData) { + ATRACE_INT64("Measured duration", actualDuration->ns()); + ATRACE_INT64("Target error term", Duration{*actualDuration - mTargetDuration}.ns()); + ATRACE_INT64("Reported duration", actualDuration->ns()); + ATRACE_INT64("Reported target", mLastTargetDurationSent.ns()); + ATRACE_INT64("Reported target error term", + Duration{*actualDuration - mLastTargetDurationSent}.ns()); } - const std::optional<Duration> predictedDuration = estimateWorkDuration(true); + ALOGV("Sending actual work duration of: %" PRId64 " on reported target: %" PRId64 + " with error: %" PRId64, + actualDuration->ns(), mLastTargetDurationSent.ns(), + Duration{*actualDuration - mLastTargetDurationSent}.ns()); - if (predictedDuration.has_value()) { - std::lock_guard lock(mPowerHalMutex); - HalWrapper* const halWrapper = getPowerHal(); - if (halWrapper != nullptr) { - halWrapper->sendActualWorkDuration(*predictedDuration + kTargetSafetyMargin, - TimePoint::now()); + { + std::lock_guard lock(mHintSessionMutex); + auto ret = mHintSession->reportActualWorkDuration(mHintSessionQueue); + if (!ret.isOk()) { + ALOGW("Failed to report actual work durations with error: %s", + ret.exceptionMessage().c_str()); + mHintSessionRunning = false; + return; } } + mHintSessionQueue.clear(); } -void PowerAdvisor::enablePowerHint(bool enabled) { - mPowerHintEnabled = enabled; +void PowerAdvisor::enablePowerHintSession(bool enabled) { + mHintSessionEnabled = enabled; } bool PowerAdvisor::startPowerHintSession(const std::vector<int32_t>& threadIds) { + if (!mBootFinished.load()) { + return false; + } if (!usePowerHintSession()) { - ALOGI("Power hint session cannot be started, skipping"); + ALOGI("Cannot start power hint session: disabled or unsupported"); + return false; } + if (mHintSessionRunning) { + ALOGE("Cannot start power hint session: already running"); + return false; + } + LOG_ALWAYS_FATAL_IF(threadIds.empty(), "No thread IDs provided to power hint session!"); { - std::lock_guard lock(mPowerHalMutex); - HalWrapper* halWrapper = getPowerHal(); - if (halWrapper != nullptr && usePowerHintSession()) { - halWrapper->setPowerHintSessionThreadIds(threadIds); - mPowerHintSessionRunning = halWrapper->startPowerHintSession(); + std::lock_guard lock(mHintSessionMutex); + mHintSession = nullptr; + mHintSessionThreadIds = threadIds; + + auto ret = getPowerHal().createHintSession(getpid(), static_cast<int32_t>(getuid()), + threadIds, mTargetDuration.ns()); + + if (ret.isOk()) { + mHintSessionRunning = true; + mHintSession = ret.value(); } } - return mPowerHintSessionRunning; + return mHintSessionRunning; } void PowerAdvisor::setGpuFenceTime(DisplayId displayId, std::unique_ptr<FenceTime>&& fenceTime) { @@ -357,13 +395,13 @@ std::vector<DisplayId> PowerAdvisor::getOrderedDisplayIds( return sortedDisplays; } -std::optional<Duration> PowerAdvisor::estimateWorkDuration(bool earlyHint) { - if (earlyHint && (!mExpectedPresentTimes.isFull() || !mCommitStartTimes.isFull())) { +std::optional<Duration> PowerAdvisor::estimateWorkDuration() { + if (!mExpectedPresentTimes.isFull() || !mCommitStartTimes.isFull()) { return std::nullopt; } // Tracks when we finish presenting to hwc - TimePoint estimatedEndTime = mCommitStartTimes[0]; + TimePoint estimatedHwcEndTime = mCommitStartTimes[0]; // How long we spent this frame not doing anything, waiting for fences or vsync Duration idleDuration = 0ns; @@ -376,21 +414,11 @@ std::optional<Duration> PowerAdvisor::estimateWorkDuration(bool earlyHint) { // used to accumulate gpu time as we iterate over the active displays std::optional<TimePoint> estimatedGpuEndTime; - // If we're predicting at the start of the frame, we use last frame as our reference point - // If we're predicting at the end of the frame, we use the current frame as a reference point - TimePoint referenceFrameStartTime = (earlyHint ? mCommitStartTimes[-1] : mCommitStartTimes[0]); - - // When the prior frame should be presenting to the display - // If we're predicting at the start of the frame, we use last frame's expected present time - // If we're predicting at the end of the frame, the present fence time is already known - TimePoint lastFramePresentTime = - (earlyHint ? mExpectedPresentTimes[-1] : mLastPresentFenceTime); - // The timing info for the previously calculated display, if there was one - std::optional<DisplayTimeline> previousDisplayReferenceTiming; + std::optional<DisplayTimeline> previousDisplayTiming; std::vector<DisplayId>&& displayIds = getOrderedDisplayIds(&DisplayTimingData::hwcPresentStartTime); - DisplayTimeline referenceTiming, estimatedTiming; + DisplayTimeline displayTiming; // Iterate over the displays that use hwc in the same order they are presented for (DisplayId displayId : displayIds) { @@ -400,35 +428,26 @@ std::optional<Duration> PowerAdvisor::estimateWorkDuration(bool earlyHint) { auto& displayData = mDisplayTimingData.at(displayId); - // mLastPresentFenceTime should always be the time of the reference frame, since it will be - // the previous frame's present fence if called at the start, and current frame's if called - // at the end - referenceTiming = displayData.calculateDisplayTimeline(mLastPresentFenceTime); + displayTiming = displayData.calculateDisplayTimeline(mLastPresentFenceTime); // If this is the first display, include the duration before hwc present starts - if (!previousDisplayReferenceTiming.has_value()) { - estimatedEndTime += referenceTiming.hwcPresentStartTime - referenceFrameStartTime; + if (!previousDisplayTiming.has_value()) { + estimatedHwcEndTime += displayTiming.hwcPresentStartTime - mCommitStartTimes[0]; } else { // Otherwise add the time since last display's hwc present finished - estimatedEndTime += referenceTiming.hwcPresentStartTime - - previousDisplayReferenceTiming->hwcPresentEndTime; + estimatedHwcEndTime += + displayTiming.hwcPresentStartTime - previousDisplayTiming->hwcPresentEndTime; } - // Late hint can re-use reference timing here since it's estimating its own reference frame - estimatedTiming = earlyHint - ? referenceTiming.estimateTimelineFromReference(lastFramePresentTime, - estimatedEndTime) - : referenceTiming; - // Update predicted present finish time with this display's present time - estimatedEndTime = estimatedTiming.hwcPresentEndTime; + estimatedHwcEndTime = displayTiming.hwcPresentEndTime; // Track how long we spent waiting for the fence, can be excluded from the timing estimate - idleDuration += estimatedTiming.probablyWaitsForPresentFence - ? lastFramePresentTime - estimatedTiming.presentFenceWaitStartTime + idleDuration += displayTiming.probablyWaitsForPresentFence + ? mLastPresentFenceTime - displayTiming.presentFenceWaitStartTime : 0ns; // Track how long we spent waiting to present, can be excluded from the timing estimate - idleDuration += earlyHint ? 0ns : referenceTiming.hwcPresentDelayDuration; + idleDuration += displayTiming.hwcPresentDelayDuration; // Estimate the reference frame's gpu timing auto gpuTiming = displayData.estimateGpuTiming(previousValidGpuEndTime); @@ -436,24 +455,24 @@ std::optional<Duration> PowerAdvisor::estimateWorkDuration(bool earlyHint) { previousValidGpuEndTime = gpuTiming->startTime + gpuTiming->duration; // Estimate the prediction frame's gpu end time from the reference frame - estimatedGpuEndTime = std::max(estimatedTiming.hwcPresentStartTime, + estimatedGpuEndTime = std::max(displayTiming.hwcPresentStartTime, estimatedGpuEndTime.value_or(TimePoint{0ns})) + gpuTiming->duration; } - previousDisplayReferenceTiming = referenceTiming; + previousDisplayTiming = displayTiming; } ATRACE_INT64("Idle duration", idleDuration.ns()); - TimePoint estimatedFlingerEndTime = earlyHint ? estimatedEndTime : mLastSfPresentEndTime; + TimePoint estimatedFlingerEndTime = mLastSfPresentEndTime; // Don't count time spent idly waiting in the estimate as we could do more work in that time - estimatedEndTime -= idleDuration; + estimatedHwcEndTime -= idleDuration; estimatedFlingerEndTime -= idleDuration; // We finish the frame when both present and the gpu are done, so wait for the later of the two // Also add the frame delay duration since the target did not move while we were delayed Duration totalDuration = mFrameDelayDuration + - std::max(estimatedEndTime, estimatedGpuEndTime.value_or(TimePoint{0ns})) - + std::max(estimatedHwcEndTime, estimatedGpuEndTime.value_or(TimePoint{0ns})) - mCommitStartTimes[0]; // We finish SurfaceFlinger when post-composition finishes, so add that in here @@ -468,10 +487,7 @@ std::optional<Duration> PowerAdvisor::estimateWorkDuration(bool earlyHint) { Duration PowerAdvisor::combineTimingEstimates(Duration totalDuration, Duration flingerDuration) { Duration targetDuration{0ns}; - { - std::lock_guard lock(mPowerHalMutex); - targetDuration = *getPowerHal()->getTargetWorkDuration(); - } + targetDuration = mTargetDuration; if (!mTotalFrameTargetDuration.has_value()) return flingerDuration; // Normalize total to the flinger target (vsync period) since that's how often we actually send @@ -481,26 +497,6 @@ Duration PowerAdvisor::combineTimingEstimates(Duration totalDuration, Duration f return std::max(flingerDuration, normalizedTotalDuration); } -PowerAdvisor::DisplayTimeline PowerAdvisor::DisplayTimeline::estimateTimelineFromReference( - TimePoint fenceTime, TimePoint displayStartTime) { - DisplayTimeline estimated; - estimated.hwcPresentStartTime = displayStartTime; - - // We don't predict waiting for vsync alignment yet - estimated.hwcPresentDelayDuration = 0ns; - - // How long we expect to run before we start waiting for the fence - // For now just re-use last frame's post-present duration and assume it will not change much - // Excludes time spent waiting for vsync since that's not going to be consistent - estimated.presentFenceWaitStartTime = estimated.hwcPresentStartTime + - (presentFenceWaitStartTime - (hwcPresentStartTime + hwcPresentDelayDuration)); - estimated.probablyWaitsForPresentFence = fenceTime > estimated.presentFenceWaitStartTime; - estimated.hwcPresentEndTime = postPresentFenceHwcPresentDuration + - (estimated.probablyWaitsForPresentFence ? fenceTime - : estimated.presentFenceWaitStartTime); - return estimated; -} - PowerAdvisor::DisplayTimeline PowerAdvisor::DisplayTimingData::calculateDisplayTimeline( TimePoint fenceTime) { DisplayTimeline timeline; @@ -561,317 +557,17 @@ std::optional<PowerAdvisor::GpuTimeline> PowerAdvisor::DisplayTimingData::estima return GpuTimeline{.duration = gpuDuration, .startTime = latestGpuStartTime}; } -class HidlPowerHalWrapper : public PowerAdvisor::HalWrapper { -public: - HidlPowerHalWrapper(sp<V1_3::IPower> powerHal) : mPowerHal(std::move(powerHal)) {} - - ~HidlPowerHalWrapper() override = default; - - static std::unique_ptr<HalWrapper> connect() { - // Power HAL 1.3 is not guaranteed to be available, thus we need to query - // Power HAL 1.0 first and try to cast it to Power HAL 1.3. - sp<V1_3::IPower> powerHal = nullptr; - sp<V1_0::IPower> powerHal_1_0 = V1_0::IPower::getService(); - if (powerHal_1_0 != nullptr) { - // Try to cast to Power HAL 1.3 - powerHal = V1_3::IPower::castFrom(powerHal_1_0); - if (powerHal == nullptr) { - ALOGW("No Power HAL 1.3 service in system, disabling PowerAdvisor"); - } else { - ALOGI("Loaded Power HAL 1.3 service"); - } - } else { - ALOGW("No Power HAL found, disabling PowerAdvisor"); - } - - if (powerHal == nullptr) { - return nullptr; - } - - return std::make_unique<HidlPowerHalWrapper>(std::move(powerHal)); - } - - bool setExpensiveRendering(bool enabled) override { - ALOGV("HIDL setExpensiveRendering %s", enabled ? "T" : "F"); - auto ret = mPowerHal->powerHintAsync_1_3(PowerHint::EXPENSIVE_RENDERING, enabled); - if (ret.isOk()) { - traceExpensiveRendering(enabled); - } - return ret.isOk(); - } - - bool notifyDisplayUpdateImminentAndCpuReset() override { - // Power HAL 1.x doesn't have a notification for this - ALOGV("HIDL notifyUpdateImminent received but can't send"); - return true; - } - - bool supportsPowerHintSession() override { return false; } - - bool isPowerHintSessionRunning() override { return false; } - - void restartPowerHintSession() override {} - - void setPowerHintSessionThreadIds(const std::vector<int32_t>&) override {} - - bool startPowerHintSession() override { return false; } - - void setTargetWorkDuration(Duration) override {} - - void sendActualWorkDuration(Duration, TimePoint) override {} - - bool shouldReconnectHAL() override { return false; } - - std::vector<int32_t> getPowerHintSessionThreadIds() override { return std::vector<int32_t>{}; } - - std::optional<Duration> getTargetWorkDuration() override { return std::nullopt; } - -private: - const sp<V1_3::IPower> mPowerHal = nullptr; -}; - -AidlPowerHalWrapper::AidlPowerHalWrapper(sp<IPower> powerHal) : mPowerHal(std::move(powerHal)) { - auto ret = mPowerHal->isModeSupported(Mode::EXPENSIVE_RENDERING, &mHasExpensiveRendering); - if (!ret.isOk()) { - mHasExpensiveRendering = false; - } - - ret = mPowerHal->isBoostSupported(Boost::DISPLAY_UPDATE_IMMINENT, &mHasDisplayUpdateImminent); - if (!ret.isOk()) { - mHasDisplayUpdateImminent = false; - } - - mSupportsPowerHint = checkPowerHintSessionSupported(); -} - -AidlPowerHalWrapper::~AidlPowerHalWrapper() { - if (mPowerHintSession != nullptr) { - mPowerHintSession->close(); - mPowerHintSession = nullptr; - } -} - -std::unique_ptr<PowerAdvisor::HalWrapper> AidlPowerHalWrapper::connect() { - // This only waits if the service is actually declared - sp<IPower> powerHal = waitForVintfService<IPower>(); - if (powerHal == nullptr) { - return nullptr; - } - ALOGI("Loaded AIDL Power HAL service"); - - return std::make_unique<AidlPowerHalWrapper>(std::move(powerHal)); -} - -bool AidlPowerHalWrapper::setExpensiveRendering(bool enabled) { - ALOGV("AIDL setExpensiveRendering %s", enabled ? "T" : "F"); - if (!mHasExpensiveRendering) { - ALOGV("Skipped sending EXPENSIVE_RENDERING because HAL doesn't support it"); - return true; - } - - auto ret = mPowerHal->setMode(Mode::EXPENSIVE_RENDERING, enabled); - if (ret.isOk()) { - traceExpensiveRendering(enabled); - } - return ret.isOk(); -} - -bool AidlPowerHalWrapper::notifyDisplayUpdateImminentAndCpuReset() { - ALOGV("AIDL notifyDisplayUpdateImminentAndCpuReset"); - if (isPowerHintSessionRunning()) { - mPowerHintSession->sendHint(SessionHint::CPU_LOAD_RESET); - } - - if (!mHasDisplayUpdateImminent) { - ALOGV("Skipped sending DISPLAY_UPDATE_IMMINENT because HAL doesn't support it"); - return true; - } - - auto ret = mPowerHal->setBoost(Boost::DISPLAY_UPDATE_IMMINENT, 0); - return ret.isOk(); -} - -// Only version 2+ of the aidl supports power hint sessions, hidl has no support -bool AidlPowerHalWrapper::supportsPowerHintSession() { - return mSupportsPowerHint; -} - -bool AidlPowerHalWrapper::checkPowerHintSessionSupported() { - int64_t unused; - // Try to get preferred rate to determine if hint sessions are supported - // We check for isOk not EX_UNSUPPORTED_OPERATION to lump together errors - return mPowerHal->getHintSessionPreferredRate(&unused).isOk(); -} - -bool AidlPowerHalWrapper::isPowerHintSessionRunning() { - return mPowerHintSession != nullptr; -} - -void AidlPowerHalWrapper::closePowerHintSession() { - if (mPowerHintSession != nullptr) { - mPowerHintSession->close(); - mPowerHintSession = nullptr; - } -} - -void AidlPowerHalWrapper::restartPowerHintSession() { - closePowerHintSession(); - startPowerHintSession(); -} - -void AidlPowerHalWrapper::setPowerHintSessionThreadIds(const std::vector<int32_t>& threadIds) { - if (threadIds != mPowerHintThreadIds) { - mPowerHintThreadIds = threadIds; - if (isPowerHintSessionRunning()) { - restartPowerHintSession(); - } - } -} - -bool AidlPowerHalWrapper::startPowerHintSession() { - if (mPowerHintSession != nullptr || mPowerHintThreadIds.empty()) { - ALOGV("Cannot start power hint session, skipping"); - return false; - } - auto ret = mPowerHal->createHintSession(getpid(), static_cast<int32_t>(getuid()), - mPowerHintThreadIds, mTargetDuration.ns(), - &mPowerHintSession); - if (!ret.isOk()) { - ALOGW("Failed to start power hint session with error: %s", - ret.exceptionToString(ret.exceptionCode()).c_str()); - } else { - mLastTargetDurationSent = mTargetDuration; - } - return isPowerHintSessionRunning(); -} - -void AidlPowerHalWrapper::setTargetWorkDuration(Duration targetDuration) { - ATRACE_CALL(); - mTargetDuration = targetDuration; - if (sTraceHintSessionData) ATRACE_INT64("Time target", targetDuration.ns()); - if (isPowerHintSessionRunning() && (targetDuration != mLastTargetDurationSent)) { - ALOGV("Sending target time: %" PRId64 "ns", targetDuration.ns()); - mLastTargetDurationSent = targetDuration; - auto ret = mPowerHintSession->updateTargetWorkDuration(targetDuration.ns()); - if (!ret.isOk()) { - ALOGW("Failed to set power hint target work duration with error: %s", - ret.exceptionMessage().c_str()); - mShouldReconnectHal = true; - } - } -} - -void AidlPowerHalWrapper::sendActualWorkDuration(Duration actualDuration, TimePoint timestamp) { - ATRACE_CALL(); - if (actualDuration < 0ns || !isPowerHintSessionRunning()) { - ALOGV("Failed to send actual work duration, skipping"); - return; - } - mActualDuration = actualDuration; - WorkDuration duration; - duration.durationNanos = actualDuration.ns(); - duration.timeStampNanos = timestamp.ns(); - mPowerHintQueue.push_back(duration); - - if (sTraceHintSessionData) { - ATRACE_INT64("Measured duration", actualDuration.ns()); - ATRACE_INT64("Target error term", Duration{actualDuration - mTargetDuration}.ns()); - - ATRACE_INT64("Reported duration", actualDuration.ns()); - ATRACE_INT64("Reported target", mLastTargetDurationSent.ns()); - ATRACE_INT64("Reported target error term", - Duration{actualDuration - mLastTargetDurationSent}.ns()); - } - - ALOGV("Sending actual work duration of: %" PRId64 " on reported target: %" PRId64 - " with error: %" PRId64, - actualDuration.ns(), mLastTargetDurationSent.ns(), - Duration{actualDuration - mLastTargetDurationSent}.ns()); - - auto ret = mPowerHintSession->reportActualWorkDuration(mPowerHintQueue); - if (!ret.isOk()) { - ALOGW("Failed to report actual work durations with error: %s", - ret.exceptionMessage().c_str()); - mShouldReconnectHal = true; - } - mPowerHintQueue.clear(); -} - -bool AidlPowerHalWrapper::shouldReconnectHAL() { - return mShouldReconnectHal; -} - -std::vector<int32_t> AidlPowerHalWrapper::getPowerHintSessionThreadIds() { - return mPowerHintThreadIds; -} - -std::optional<Duration> AidlPowerHalWrapper::getTargetWorkDuration() { - return mTargetDuration; -} - -const bool AidlPowerHalWrapper::sTraceHintSessionData = +const bool PowerAdvisor::sTraceHintSessionData = base::GetBoolProperty(std::string("debug.sf.trace_hint_sessions"), false); -PowerAdvisor::HalWrapper* PowerAdvisor::getPowerHal() { - if (!mHasHal) { - return nullptr; - } - - // Grab old hint session values before we destroy any existing wrapper - std::vector<int32_t> oldPowerHintSessionThreadIds; - std::optional<Duration> oldTargetWorkDuration; - - if (mHalWrapper != nullptr) { - oldPowerHintSessionThreadIds = mHalWrapper->getPowerHintSessionThreadIds(); - oldTargetWorkDuration = mHalWrapper->getTargetWorkDuration(); - } - - // If we used to have a HAL, but it stopped responding, attempt to reconnect - if (mReconnectPowerHal) { - mHalWrapper = nullptr; - mReconnectPowerHal = false; - } - - if (mHalWrapper != nullptr) { - auto wrapper = mHalWrapper.get(); - // If the wrapper is fine, return it, but if it indicates a reconnect, remake it - if (!wrapper->shouldReconnectHAL()) { - return wrapper; - } - ALOGD("Reconnecting Power HAL"); - mHalWrapper = nullptr; - } - - // At this point, we know for sure there is no running session - mPowerHintSessionRunning = false; - - // First attempt to connect to the AIDL Power HAL - mHalWrapper = AidlPowerHalWrapper::connect(); - - // If that didn't succeed, attempt to connect to the HIDL Power HAL - if (mHalWrapper == nullptr) { - mHalWrapper = HidlPowerHalWrapper::connect(); - } else { - ALOGD("Successfully connecting AIDL Power HAL"); - // If AIDL, pass on any existing hint session values - mHalWrapper->setPowerHintSessionThreadIds(oldPowerHintSessionThreadIds); - // Only set duration and start if duration is defined - if (oldTargetWorkDuration.has_value()) { - mHalWrapper->setTargetWorkDuration(*oldTargetWorkDuration); - // Only start if possible to run and both threadids and duration are defined - if (usePowerHintSession() && !oldPowerHintSessionThreadIds.empty()) { - mPowerHintSessionRunning = mHalWrapper->startPowerHintSession(); - } - } - } - - // If we make it to this point and still don't have a HAL, it's unlikely we - // will, so stop trying - if (mHalWrapper == nullptr) { - mHasHal = false; - } +const Duration PowerAdvisor::sTargetSafetyMargin = std::chrono::microseconds( + base::GetIntProperty<int64_t>("debug.sf.hint_margin_us", + ticks<std::micro>(PowerAdvisor::kDefaultTargetSafetyMargin))); - return mHalWrapper.get(); +power::PowerHalController& PowerAdvisor::getPowerHal() { + static std::once_flag halFlag; + std::call_once(halFlag, [this] { mPowerHal->init(); }); + return *mPowerHal; } } // namespace impl diff --git a/services/surfaceflinger/DisplayHardware/PowerAdvisor.h b/services/surfaceflinger/DisplayHardware/PowerAdvisor.h index d45e7cb572..7a0d4267fe 100644 --- a/services/surfaceflinger/DisplayHardware/PowerAdvisor.h +++ b/services/surfaceflinger/DisplayHardware/PowerAdvisor.h @@ -27,6 +27,7 @@ #include <android/hardware/power/IPower.h> #include <compositionengine/impl/OutputCompositionState.h> +#include <powermanager/PowerHalController.h> #include <scheduler/Time.h> #include <ui/DisplayIdentification.h> #include "../Scheduler/OneShotTimer.h" @@ -52,15 +53,14 @@ public: // Checks both if it supports and if it's enabled virtual bool usePowerHintSession() = 0; virtual bool supportsPowerHintSession() = 0; - virtual bool isPowerHintSessionRunning() = 0; + + virtual bool ensurePowerHintSessionRunning() = 0; // Sends a power hint that updates to the target work duration for the frame - virtual void setTargetWorkDuration(Duration targetDuration) = 0; + virtual void updateTargetWorkDuration(Duration targetDuration) = 0; // Sends a power hint for the actual known work duration at the end of the frame - virtual void sendActualWorkDuration() = 0; - // Sends a power hint for the upcoming frame predicted from previous frame timing - virtual void sendPredictedWorkDuration() = 0; + virtual void reportActualWorkDuration() = 0; // Sets whether the power hint session is enabled - virtual void enablePowerHint(bool enabled) = 0; + virtual void enablePowerHintSession(bool enabled) = 0; // Initializes the power hint session virtual bool startPowerHintSession(const std::vector<int32_t>& threadIds) = 0; // Provides PowerAdvisor with a copy of the gpu fence so it can determine the gpu end time @@ -101,24 +101,6 @@ namespace impl { // full state of the system when sending out power hints to things like the GPU. class PowerAdvisor final : public Hwc2::PowerAdvisor { public: - class HalWrapper { - public: - virtual ~HalWrapper() = default; - - virtual bool setExpensiveRendering(bool enabled) = 0; - virtual bool notifyDisplayUpdateImminentAndCpuReset() = 0; - virtual bool supportsPowerHintSession() = 0; - virtual bool isPowerHintSessionRunning() = 0; - virtual void restartPowerHintSession() = 0; - virtual void setPowerHintSessionThreadIds(const std::vector<int32_t>& threadIds) = 0; - virtual bool startPowerHintSession() = 0; - virtual void setTargetWorkDuration(Duration targetDuration) = 0; - virtual void sendActualWorkDuration(Duration actualDuration, TimePoint timestamp) = 0; - virtual bool shouldReconnectHAL() = 0; - virtual std::vector<int32_t> getPowerHintSessionThreadIds() = 0; - virtual std::optional<Duration> getTargetWorkDuration() = 0; - }; - PowerAdvisor(SurfaceFlinger& flinger); ~PowerAdvisor() override; @@ -129,11 +111,10 @@ public: void notifyDisplayUpdateImminentAndCpuReset() override; bool usePowerHintSession() override; bool supportsPowerHintSession() override; - bool isPowerHintSessionRunning() override; - void setTargetWorkDuration(Duration targetDuration) override; - void sendActualWorkDuration() override; - void sendPredictedWorkDuration() override; - void enablePowerHint(bool enabled) override; + bool ensurePowerHintSessionRunning() override; + void updateTargetWorkDuration(Duration targetDuration) override; + void reportActualWorkDuration() override; + void enablePowerHintSession(bool enabled) override; bool startPowerHintSession(const std::vector<int32_t>& threadIds) override; void setGpuFenceTime(DisplayId displayId, std::unique_ptr<FenceTime>&& fenceTime); void setHwcValidateTiming(DisplayId displayId, TimePoint validateStartTime, @@ -155,15 +136,7 @@ public: private: friend class PowerAdvisorTest; - // Tracks if powerhal exists - bool mHasHal = true; - // Holds the hal wrapper for getPowerHal - std::unique_ptr<HalWrapper> mHalWrapper GUARDED_BY(mPowerHalMutex) = nullptr; - - HalWrapper* getPowerHal() REQUIRES(mPowerHalMutex); - bool mReconnectPowerHal GUARDED_BY(mPowerHalMutex) = false; - std::mutex mPowerHalMutex; - + std::unique_ptr<power::PowerHalController> mPowerHal; std::atomic_bool mBootFinished = false; std::unordered_set<DisplayId> mExpensiveDisplays; @@ -189,9 +162,6 @@ private: Duration postPresentFenceHwcPresentDuration{0ns}; // Are we likely to have waited for the present fence during composition bool probablyWaitsForPresentFence = false; - // Estimate one frame's timeline from that of a previous frame - DisplayTimeline estimateTimelineFromReference(TimePoint fenceTime, - TimePoint displayStartTime); }; struct GpuTimeline { @@ -243,8 +213,7 @@ private: std::vector<DisplayId> getOrderedDisplayIds( std::optional<TimePoint> DisplayTimingData::*sortBy); // Estimates a frame's total work duration including gpu time. - // Runs either at the beginning or end of a frame, using the most recent data available - std::optional<Duration> estimateWorkDuration(bool earlyHint); + std::optional<Duration> estimateWorkDuration(); // There are two different targets and actual work durations we care about, // this normalizes them together and takes the max of the two Duration combineTimingEstimates(Duration totalDuration, Duration flingerDuration); @@ -268,67 +237,41 @@ private: // Updated list of display IDs std::vector<DisplayId> mDisplayIds; - std::optional<bool> mPowerHintEnabled; - std::optional<bool> mSupportsPowerHint; - bool mPowerHintSessionRunning = false; - - // An adjustable safety margin which pads the "actual" value sent to PowerHAL, - // encouraging more aggressive boosting to give SurfaceFlinger a larger margin for error - static constexpr const Duration kTargetSafetyMargin{1ms}; - - // How long we expect hwc to run after the present call until it waits for the fence - static constexpr const Duration kFenceWaitStartDelayValidated{150us}; - static constexpr const Duration kFenceWaitStartDelaySkippedValidate{250us}; -}; - -class AidlPowerHalWrapper : public PowerAdvisor::HalWrapper { -public: - explicit AidlPowerHalWrapper(sp<hardware::power::IPower> powerHal); - ~AidlPowerHalWrapper() override; - - static std::unique_ptr<HalWrapper> connect(); - - bool setExpensiveRendering(bool enabled) override; - bool notifyDisplayUpdateImminentAndCpuReset() override; - bool supportsPowerHintSession() override; - bool isPowerHintSessionRunning() override; - void restartPowerHintSession() override; - void setPowerHintSessionThreadIds(const std::vector<int32_t>& threadIds) override; - bool startPowerHintSession() override; - void setTargetWorkDuration(Duration targetDuration) override; - void sendActualWorkDuration(Duration actualDuration, TimePoint timestamp) override; - bool shouldReconnectHAL() override; - std::vector<int32_t> getPowerHintSessionThreadIds() override; - std::optional<Duration> getTargetWorkDuration() override; + // Ensure powerhal connection is initialized + power::PowerHalController& getPowerHal(); -private: - friend class AidlPowerHalWrapperTest; - - bool checkPowerHintSessionSupported(); - void closePowerHintSession(); + std::optional<bool> mHintSessionEnabled; + std::optional<bool> mSupportsHintSession; + bool mHintSessionRunning = false; - const sp<hardware::power::IPower> mPowerHal = nullptr; - bool mHasExpensiveRendering = false; - bool mHasDisplayUpdateImminent = false; - // Used to indicate an error state and need for reconstruction - bool mShouldReconnectHal = false; + std::mutex mHintSessionMutex; + sp<hardware::power::IPowerHintSession> mHintSession GUARDED_BY(mHintSessionMutex) = nullptr; - // Power hint session data - - // Concurrent access for this is protected by mPowerHalMutex - sp<hardware::power::IPowerHintSession> mPowerHintSession = nullptr; + // Initialize to true so we try to call, to check if it's supported + bool mHasExpensiveRendering = true; + bool mHasDisplayUpdateImminent = true; // Queue of actual durations saved to report - std::vector<hardware::power::WorkDuration> mPowerHintQueue; + std::vector<hardware::power::WorkDuration> mHintSessionQueue; // The latest values we have received for target and actual Duration mTargetDuration = kDefaultTargetDuration; std::optional<Duration> mActualDuration; // The list of thread ids, stored so we can restart the session from this class if needed - std::vector<int32_t> mPowerHintThreadIds; - bool mSupportsPowerHint = false; + std::vector<int32_t> mHintSessionThreadIds; Duration mLastTargetDurationSent = kDefaultTargetDuration; // Whether we should emit ATRACE_INT data for hint sessions static const bool sTraceHintSessionData; - static constexpr Duration kDefaultTargetDuration{16ms}; + + // Default target duration for the hint session + static constexpr const Duration kDefaultTargetDuration{16ms}; + + // An adjustable safety margin which pads the "actual" value sent to PowerHAL, + // encouraging more aggressive boosting to give SurfaceFlinger a larger margin for error + static const Duration sTargetSafetyMargin; + static constexpr const Duration kDefaultTargetSafetyMargin{1ms}; + + // How long we expect hwc to run after the present call until it waits for the fence + static constexpr const Duration kFenceWaitStartDelayValidated{150us}; + static constexpr const Duration kFenceWaitStartDelaySkippedValidate{250us}; }; } // namespace impl diff --git a/services/surfaceflinger/FrontEnd/LayerCreationArgs.cpp b/services/surfaceflinger/FrontEnd/LayerCreationArgs.cpp index ce21233424..6af352c9f4 100644 --- a/services/surfaceflinger/FrontEnd/LayerCreationArgs.cpp +++ b/services/surfaceflinger/FrontEnd/LayerCreationArgs.cpp @@ -74,4 +74,23 @@ LayerCreationArgs LayerCreationArgs::fromOtherArgs(const LayerCreationArgs& othe return LayerCreationArgs(other.flinger, other.client, other.name, other.flags, other.metadata); } +std::string LayerCreationArgs::getDebugString() const { + std::stringstream stream; + stream << "LayerCreationArgs{" << name << "[" << sequence << "] flags=" << flags + << " pid=" << ownerPid << " uid=" << ownerUid; + if (addToRoot) { + stream << " addToRoot=" << addToRoot; + } + if (parentId != UNASSIGNED_LAYER_ID) { + stream << " parentId=" << parentId; + } + if (layerIdToMirror != UNASSIGNED_LAYER_ID) { + stream << " layerIdToMirror=" << layerIdToMirror; + } + if (layerStackToMirror != ui::INVALID_LAYER_STACK) { + stream << " layerStackToMirror=" << layerStackToMirror.id; + } + return stream.str(); +} + } // namespace android::surfaceflinger diff --git a/services/surfaceflinger/FrontEnd/LayerCreationArgs.h b/services/surfaceflinger/FrontEnd/LayerCreationArgs.h index 011250c52d..3a0fc6d7a3 100644 --- a/services/surfaceflinger/FrontEnd/LayerCreationArgs.h +++ b/services/surfaceflinger/FrontEnd/LayerCreationArgs.h @@ -44,6 +44,7 @@ struct LayerCreationArgs { bool internalLayer = false); LayerCreationArgs(std::optional<uint32_t> id, bool internalLayer = false); LayerCreationArgs() = default; // for tracing + std::string getDebugString() const; android::SurfaceFlinger* flinger; sp<android::Client> client; diff --git a/services/surfaceflinger/FrontEnd/LayerLifecycleManager.cpp b/services/surfaceflinger/FrontEnd/LayerLifecycleManager.cpp index 3706225228..33d9dbe796 100644 --- a/services/surfaceflinger/FrontEnd/LayerLifecycleManager.cpp +++ b/services/surfaceflinger/FrontEnd/LayerLifecycleManager.cpp @@ -164,7 +164,8 @@ void LayerLifecycleManager::onHandlesDestroyed(const std::vector<uint32_t>& dest } } -void LayerLifecycleManager::applyTransactions(const std::vector<TransactionState>& transactions) { +void LayerLifecycleManager::applyTransactions(const std::vector<TransactionState>& transactions, + bool ignoreUnknownLayers) { for (const auto& transaction : transactions) { for (const auto& resolvedComposerState : transaction.states) { const auto& clientState = resolvedComposerState.state; @@ -176,7 +177,8 @@ void LayerLifecycleManager::applyTransactions(const std::vector<TransactionState RequestedLayerState* layer = getLayerFromId(layerId); if (layer == nullptr) { - LOG_ALWAYS_FATAL("%s Layer with layerid=%d not found", __func__, layerId); + LOG_ALWAYS_FATAL_IF(!ignoreUnknownLayers, "%s Layer with layerid=%d not found", + __func__, layerId); continue; } diff --git a/services/surfaceflinger/FrontEnd/LayerLifecycleManager.h b/services/surfaceflinger/FrontEnd/LayerLifecycleManager.h index 3d9a74c843..f258678598 100644 --- a/services/surfaceflinger/FrontEnd/LayerLifecycleManager.h +++ b/services/surfaceflinger/FrontEnd/LayerLifecycleManager.h @@ -39,7 +39,11 @@ class LayerLifecycleManager { public: // External state changes should be updated in the following order: void addLayers(std::vector<std::unique_ptr<RequestedLayerState>>); - void applyTransactions(const std::vector<TransactionState>&); + // Ignore unknown layers when interoping with legacy front end. In legacy we destroy + // the layers it is unreachable. When using the LayerLifecycleManager for layer trace + // generation we may encounter layers which are known because we don't have an explicit + // lifecycle. Ignore these errors while we have to interop with legacy. + void applyTransactions(const std::vector<TransactionState>&, bool ignoreUnknownLayers = false); // Ignore unknown handles when iteroping with legacy front end. In the old world, we // would create child layers which are not necessary with the new front end. This means // we will get notified for handle changes that don't exist in the new front end. diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp b/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp index 2d6d8ad0b0..1e931a7a1a 100644 --- a/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp +++ b/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp @@ -187,6 +187,8 @@ std::string LayerSnapshot::getDebugString() const { << " geomLayerTransform={tx=" << geomLayerTransform.tx() << ",ty=" << geomLayerTransform.ty() << "}" << "}"; + debug << " input{ touchCropId=" << touchCropId + << " replaceTouchableRegionWithCrop=" << inputInfo.replaceTouchableRegionWithCrop << "}"; return debug.str(); } diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshot.h b/services/surfaceflinger/FrontEnd/LayerSnapshot.h index 5491d9af17..b167d3ea1b 100644 --- a/services/surfaceflinger/FrontEnd/LayerSnapshot.h +++ b/services/surfaceflinger/FrontEnd/LayerSnapshot.h @@ -94,6 +94,7 @@ struct LayerSnapshot : public compositionengine::LayerFECompositionState { int32_t frameRateSelectionPriority; LayerHierarchy::TraversalPath mirrorRootPath; bool unreachable = true; + uint32_t touchCropId; uid_t uid; pid_t pid; ChildState childState; diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp index bdd4427d20..25cbe7ae54 100644 --- a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp +++ b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp @@ -447,23 +447,36 @@ void LayerSnapshotBuilder::updateSnapshots(const Args& args) { } } + // Update touchable region crops outside the main update pass. This is because a layer could be + // cropped by any other layer and it requires both snapshots to be updated. + updateTouchableRegionCrop(args); + const bool hasUnreachableSnapshots = sortSnapshotsByZ(args); clearChanges(mRootSnapshot); - // Destroy unreachable snapshots - if (!hasUnreachableSnapshots) { + // Destroy unreachable snapshots for clone layers. And destroy snapshots for non-clone + // layers if the layer have been destroyed. + // TODO(b/238781169) consider making clone layer ids stable as well + if (!hasUnreachableSnapshots && args.layerLifecycleManager.getDestroyedLayers().empty()) { return; } + std::unordered_set<uint32_t> destroyedLayerIds; + for (auto& destroyedLayer : args.layerLifecycleManager.getDestroyedLayers()) { + destroyedLayerIds.insert(destroyedLayer->id); + } + auto it = mSnapshots.begin(); while (it < mSnapshots.end()) { auto& traversalPath = it->get()->path; - if (!it->get()->unreachable) { + if (!it->get()->unreachable && + destroyedLayerIds.find(traversalPath.id) == destroyedLayerIds.end()) { it++; continue; } mIdToSnapshot.erase(traversalPath); + mNeedsTouchableRegionCrop.erase(traversalPath); mSnapshots.back()->globalZ = it->get()->globalZ; std::iter_swap(it, mSnapshots.end() - 1); mSnapshots.erase(mSnapshots.end() - 1); @@ -554,7 +567,7 @@ bool LayerSnapshotBuilder::sortSnapshotsByZ(const Args& args) { mResortSnapshots = false; for (auto& snapshot : mSnapshots) { - snapshot->unreachable = true; + snapshot->unreachable = snapshot->path.isClone(); } size_t globalZ = 0; @@ -720,8 +733,8 @@ void LayerSnapshotBuilder::updateSnapshot(LayerSnapshot& snapshot, const Args& a snapshot.sidebandStream = requested.sidebandStream; snapshot.transparentRegionHint = requested.transparentRegion; snapshot.color.rgb = requested.getColor().rgb; - snapshot.currentSdrHdrRatio = requested.currentSdrHdrRatio; - snapshot.desiredSdrHdrRatio = requested.desiredSdrHdrRatio; + snapshot.currentHdrSdrRatio = requested.currentHdrSdrRatio; + snapshot.desiredHdrSdrRatio = requested.desiredHdrSdrRatio; } if (snapshot.isHiddenByPolicyFromParent && @@ -739,6 +752,8 @@ void LayerSnapshotBuilder::updateSnapshot(LayerSnapshot& snapshot, const Args& a // If root layer, use the layer stack otherwise get the parent's layer stack. snapshot.color.a = parentSnapshot.color.a * requested.color.a; snapshot.alpha = snapshot.color.a; + snapshot.inputInfo.alpha = snapshot.color.a; + snapshot.isSecure = parentSnapshot.isSecure || (requested.flags & layer_state_t::eLayerSecure); snapshot.isTrustedOverlay = parentSnapshot.isTrustedOverlay || requested.isTrustedOverlay; @@ -986,9 +1001,11 @@ void LayerSnapshotBuilder::updateInput(LayerSnapshot& snapshot, snapshot.inputInfo.ownerUid = static_cast<int32_t>(requested.ownerUid); snapshot.inputInfo.ownerPid = requested.ownerPid; } + snapshot.touchCropId = requested.touchCropId; snapshot.inputInfo.id = static_cast<int32_t>(snapshot.uniqueSequence); snapshot.inputInfo.displayId = static_cast<int32_t>(snapshot.outputFilter.layerStack.id); + updateVisibility(snapshot, snapshot.isVisible); if (!needsInputInfo(snapshot, requested)) { return; } @@ -1033,27 +1050,13 @@ void LayerSnapshotBuilder::updateInput(LayerSnapshot& snapshot, } auto cropLayerSnapshot = getSnapshot(requested.touchCropId); - if (snapshot.inputInfo.replaceTouchableRegionWithCrop) { - Rect inputBoundsInDisplaySpace; - if (!cropLayerSnapshot) { - FloatRect inputBounds = getInputBounds(snapshot, /*fillParentBounds=*/true).first; - inputBoundsInDisplaySpace = - getInputBoundsInDisplaySpace(snapshot, inputBounds, displayInfo.transform); - } else { - FloatRect inputBounds = - getInputBounds(*cropLayerSnapshot, /*fillParentBounds=*/true).first; - inputBoundsInDisplaySpace = - getInputBoundsInDisplaySpace(*cropLayerSnapshot, inputBounds, - displayInfo.transform); - } - snapshot.inputInfo.touchableRegion = Region(inputBoundsInDisplaySpace); - } else if (cropLayerSnapshot) { - FloatRect inputBounds = getInputBounds(*cropLayerSnapshot, /*fillParentBounds=*/true).first; + if (cropLayerSnapshot) { + mNeedsTouchableRegionCrop.insert(path); + } else if (snapshot.inputInfo.replaceTouchableRegionWithCrop) { + FloatRect inputBounds = getInputBounds(snapshot, /*fillParentBounds=*/true).first; Rect inputBoundsInDisplaySpace = - getInputBoundsInDisplaySpace(*cropLayerSnapshot, inputBounds, - displayInfo.transform); - snapshot.inputInfo.touchableRegion = snapshot.inputInfo.touchableRegion.intersect( - displayInfo.transform.transform(inputBoundsInDisplaySpace)); + getInputBoundsInDisplaySpace(snapshot, inputBounds, displayInfo.transform); + snapshot.inputInfo.touchableRegion = Region(inputBoundsInDisplaySpace); } // Inherit the trusted state from the parent hierarchy, but don't clobber the trusted state @@ -1066,12 +1069,7 @@ void LayerSnapshotBuilder::updateInput(LayerSnapshot& snapshot, // touches from going outside the cloned area. if (path.isClone()) { snapshot.inputInfo.inputConfig |= gui::WindowInfo::InputConfig::CLONE; - auto clonedRootSnapshot = getSnapshot(snapshot.mirrorRootPath); - if (clonedRootSnapshot) { - const Rect rect = - displayInfo.transform.transform(Rect{clonedRootSnapshot->transformedBounds}); - snapshot.inputInfo.touchableRegion = snapshot.inputInfo.touchableRegion.intersect(rect); - } + mNeedsTouchableRegionCrop.insert(path); } } @@ -1117,4 +1115,77 @@ void LayerSnapshotBuilder::forEachInputSnapshot(const ConstVisitor& visitor) con } } +void LayerSnapshotBuilder::updateTouchableRegionCrop(const Args& args) { + if (mNeedsTouchableRegionCrop.empty()) { + return; + } + + static constexpr ftl::Flags<RequestedLayerState::Changes> AFFECTS_INPUT = + RequestedLayerState::Changes::Visibility | RequestedLayerState::Changes::Created | + RequestedLayerState::Changes::Hierarchy | RequestedLayerState::Changes::Geometry | + RequestedLayerState::Changes::Input; + + if (args.forceUpdate != ForceUpdateFlags::ALL && + !args.layerLifecycleManager.getGlobalChanges().any(AFFECTS_INPUT)) { + return; + } + + for (auto& path : mNeedsTouchableRegionCrop) { + frontend::LayerSnapshot* snapshot = getSnapshot(path); + if (!snapshot) { + continue; + } + const std::optional<frontend::DisplayInfo> displayInfoOpt = + args.displays.get(snapshot->outputFilter.layerStack); + static frontend::DisplayInfo sDefaultInfo = {.isSecure = false}; + auto displayInfo = displayInfoOpt.value_or(sDefaultInfo); + + bool needsUpdate = + args.forceUpdate == ForceUpdateFlags::ALL || snapshot->changes.any(AFFECTS_INPUT); + auto cropLayerSnapshot = getSnapshot(snapshot->touchCropId); + needsUpdate = + needsUpdate || (cropLayerSnapshot && cropLayerSnapshot->changes.any(AFFECTS_INPUT)); + auto clonedRootSnapshot = path.isClone() ? getSnapshot(snapshot->mirrorRootPath) : nullptr; + needsUpdate = needsUpdate || + (clonedRootSnapshot && clonedRootSnapshot->changes.any(AFFECTS_INPUT)); + + if (!needsUpdate) { + continue; + } + + if (snapshot->inputInfo.replaceTouchableRegionWithCrop) { + Rect inputBoundsInDisplaySpace; + if (!cropLayerSnapshot) { + FloatRect inputBounds = getInputBounds(*snapshot, /*fillParentBounds=*/true).first; + inputBoundsInDisplaySpace = + getInputBoundsInDisplaySpace(*snapshot, inputBounds, displayInfo.transform); + } else { + FloatRect inputBounds = + getInputBounds(*cropLayerSnapshot, /*fillParentBounds=*/true).first; + inputBoundsInDisplaySpace = + getInputBoundsInDisplaySpace(*cropLayerSnapshot, inputBounds, + displayInfo.transform); + } + snapshot->inputInfo.touchableRegion = Region(inputBoundsInDisplaySpace); + } else if (cropLayerSnapshot) { + FloatRect inputBounds = + getInputBounds(*cropLayerSnapshot, /*fillParentBounds=*/true).first; + Rect inputBoundsInDisplaySpace = + getInputBoundsInDisplaySpace(*cropLayerSnapshot, inputBounds, + displayInfo.transform); + snapshot->inputInfo.touchableRegion = snapshot->inputInfo.touchableRegion.intersect( + displayInfo.transform.transform(inputBoundsInDisplaySpace)); + } + + // If the layer is a clone, we need to crop the input region to cloned root to prevent + // touches from going outside the cloned area. + if (clonedRootSnapshot) { + const Rect rect = + displayInfo.transform.transform(Rect{clonedRootSnapshot->transformedBounds}); + snapshot->inputInfo.touchableRegion = + snapshot->inputInfo.touchableRegion.intersect(rect); + } + } +} + } // namespace android::surfaceflinger::frontend diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.h b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.h index 7b1ff2710b..148c98e2b1 100644 --- a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.h +++ b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.h @@ -119,10 +119,14 @@ private: const LayerSnapshot& parentSnapshot); void updateChildState(LayerSnapshot& snapshot, const LayerSnapshot& childSnapshot, const Args& args); + void updateTouchableRegionCrop(const Args& args); std::unordered_map<LayerHierarchy::TraversalPath, LayerSnapshot*, LayerHierarchy::TraversalPathHash> mIdToSnapshot; + // Track snapshots that needs touchable region crop from other snapshots + std::unordered_set<LayerHierarchy::TraversalPath, LayerHierarchy::TraversalPathHash> + mNeedsTouchableRegionCrop; std::vector<std::unique_ptr<LayerSnapshot>> mSnapshots; LayerSnapshot mRootSnapshot; bool mResortSnapshots = false; diff --git a/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp b/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp index a5fdaf4fe3..1f670c81df 100644 --- a/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp +++ b/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp @@ -100,8 +100,8 @@ RequestedLayerState::RequestedLayerState(const LayerCreationArgs& args) layerStack = ui::DEFAULT_LAYER_STACK; transformToDisplayInverse = false; dataspace = ui::Dataspace::UNKNOWN; - desiredSdrHdrRatio = 1.f; - currentSdrHdrRatio = 1.f; + desiredHdrSdrRatio = 1.f; + currentHdrSdrRatio = 1.f; dataspaceRequested = false; hdrMetadata.validTypes = 0; surfaceDamageRegion = Region::INVALID_REGION; diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index c1920bae50..8dec57bf3c 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -75,6 +75,7 @@ #include "FrontEnd/LayerCreationArgs.h" #include "FrontEnd/LayerHandle.h" #include "LayerProtoHelper.h" +#include "MutexUtils.h" #include "SurfaceFlinger.h" #include "TimeStats/TimeStats.h" #include "TunnelModeEnabledReporter.h" @@ -305,10 +306,12 @@ void Layer::onRemovedFromCurrentState() { auto layersInTree = getRootLayer()->getLayersInTree(LayerVector::StateSet::Current); std::sort(layersInTree.begin(), layersInTree.end()); - traverse(LayerVector::StateSet::Current, [&](Layer* layer) { - layer->removeFromCurrentState(); - layer->removeRelativeZ(layersInTree); - }); + REQUIRE_MUTEX(mFlinger->mStateLock); + traverse(LayerVector::StateSet::Current, + [&](Layer* layer) REQUIRES(layer->mFlinger->mStateLock) { + layer->removeFromCurrentState(); + layer->removeRelativeZ(layersInTree); + }); } void Layer::addToCurrentState() { @@ -643,8 +646,8 @@ void Layer::preparePerFrameCompositionState() { snapshot->surfaceDamage = surfaceDamageRegion; snapshot->hasProtectedContent = isProtected(); snapshot->dimmingEnabled = isDimmingEnabled(); - snapshot->currentSdrHdrRatio = getCurrentSdrHdrRatio(); - snapshot->desiredSdrHdrRatio = getDesiredSdrHdrRatio(); + snapshot->currentHdrSdrRatio = getCurrentHdrSdrRatio(); + snapshot->desiredHdrSdrRatio = getDesiredHdrSdrRatio(); snapshot->cachingHint = getCachingHint(); const bool usesRoundedCorners = hasRoundedCorners(); @@ -1009,10 +1012,12 @@ bool Layer::setBackgroundColor(const half3& color, float alpha, ui::Dataspace da mFlinger->mLayersAdded = true; // set up SF to handle added color layer if (isRemovedFromCurrentState()) { + MUTEX_ALIAS(mFlinger->mStateLock, mDrawingState.bgColorLayer->mFlinger->mStateLock); mDrawingState.bgColorLayer->onRemovedFromCurrentState(); } mFlinger->setTransactionFlags(eTransactionNeeded); } else if (mDrawingState.bgColorLayer && alpha == 0) { + MUTEX_ALIAS(mFlinger->mStateLock, mDrawingState.bgColorLayer->mFlinger->mStateLock); mDrawingState.bgColorLayer->reparent(nullptr); mDrawingState.bgColorLayer = nullptr; return true; @@ -3145,11 +3150,11 @@ bool Layer::setDataspace(ui::Dataspace dataspace) { } bool Layer::setExtendedRangeBrightness(float currentBufferRatio, float desiredRatio) { - if (mDrawingState.currentSdrHdrRatio == currentBufferRatio && - mDrawingState.desiredSdrHdrRatio == desiredRatio) + if (mDrawingState.currentHdrSdrRatio == currentBufferRatio && + mDrawingState.desiredHdrSdrRatio == desiredRatio) return false; - mDrawingState.currentSdrHdrRatio = currentBufferRatio; - mDrawingState.desiredSdrHdrRatio = desiredRatio; + mDrawingState.currentHdrSdrRatio = currentBufferRatio; + mDrawingState.desiredHdrSdrRatio = desiredRatio; mDrawingState.modified = true; setTransactionFlags(eTransactionNeeded); return true; @@ -3404,8 +3409,8 @@ void Layer::gatherBufferInfo() { if (lastDataspace != mBufferInfo.mDataspace) { mFlinger->mHdrLayerInfoChanged = true; } - if (mBufferInfo.mDesiredSdrHdrRatio != mDrawingState.desiredSdrHdrRatio) { - mBufferInfo.mDesiredSdrHdrRatio = mDrawingState.desiredSdrHdrRatio; + if (mBufferInfo.mDesiredHdrSdrRatio != mDrawingState.desiredHdrSdrRatio) { + mBufferInfo.mDesiredHdrSdrRatio = mDrawingState.desiredHdrSdrRatio; mFlinger->mHdrLayerInfoChanged = true; } mBufferInfo.mCrop = computeBufferCrop(mDrawingState); @@ -3691,9 +3696,9 @@ bool Layer::simpleBufferUpdate(const layer_state_t& s) const { } if (s.what & layer_state_t::eExtendedRangeBrightnessChanged) { - if (mDrawingState.currentSdrHdrRatio != s.currentSdrHdrRatio || - mDrawingState.desiredSdrHdrRatio != s.desiredSdrHdrRatio) { - ALOGV("%s: false [eDimmingEnabledChanged changed]", __func__); + if (mDrawingState.currentHdrSdrRatio != s.currentHdrSdrRatio || + mDrawingState.desiredHdrSdrRatio != s.desiredHdrSdrRatio) { + ALOGV("%s: false [eExtendedRangeBrightnessChanged changed]", __func__); return false; } } diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index 552ea3701c..0bfab7cc77 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -225,8 +225,8 @@ public: gui::DropInputMode dropInputMode; bool autoRefresh = false; bool dimmingEnabled = true; - float currentSdrHdrRatio = 1.f; - float desiredSdrHdrRatio = 1.f; + float currentHdrSdrRatio = 1.f; + float desiredHdrSdrRatio = 1.f; gui::CachingHint cachingHint = gui::CachingHint::Enabled; int64_t latchedVsyncId = 0; }; @@ -290,14 +290,14 @@ public: virtual bool setMetadata(const LayerMetadata& data); virtual void setChildrenDrawingParent(const sp<Layer>&); - virtual bool reparent(const sp<IBinder>& newParentHandle); + virtual bool reparent(const sp<IBinder>& newParentHandle) REQUIRES(mFlinger->mStateLock); virtual bool setColorTransform(const mat4& matrix); virtual mat4 getColorTransform() const; virtual bool hasColorTransform() const; virtual bool isColorSpaceAgnostic() const { return mDrawingState.colorSpaceAgnostic; } virtual bool isDimmingEnabled() const { return getDrawingState().dimmingEnabled; } - float getDesiredSdrHdrRatio() const { return getDrawingState().desiredSdrHdrRatio; } - float getCurrentSdrHdrRatio() const { return getDrawingState().currentSdrHdrRatio; } + float getDesiredHdrSdrRatio() const { return getDrawingState().desiredHdrSdrRatio; } + float getCurrentHdrSdrRatio() const { return getDrawingState().currentHdrSdrRatio; } gui::CachingHint getCachingHint() const { return getDrawingState().cachingHint; } bool setTransform(uint32_t /*transform*/); @@ -316,7 +316,8 @@ public: bool setSidebandStream(const sp<NativeHandle>& /*sidebandStream*/); bool setTransactionCompletedListeners(const std::vector<sp<CallbackHandle>>& /*handles*/, bool willPresent); - virtual bool setBackgroundColor(const half3& color, float alpha, ui::Dataspace dataspace); + virtual bool setBackgroundColor(const half3& color, float alpha, ui::Dataspace dataspace) + REQUIRES(mFlinger->mStateLock); virtual bool setColorSpaceAgnostic(const bool agnostic); virtual bool setDimmingEnabled(const bool dimmingEnabled); virtual bool setDefaultFrameRateCompatibility(FrameRateCompatibility compatibility); @@ -517,7 +518,7 @@ public: uint64_t mFrameNumber; bool mFrameLatencyNeeded{false}; - float mDesiredSdrHdrRatio = 1.f; + float mDesiredHdrSdrRatio = 1.f; }; BufferInfo mBufferInfo; @@ -641,13 +642,13 @@ public: /* * Remove from current state and mark for removal. */ - void removeFromCurrentState(); + void removeFromCurrentState() REQUIRES(mFlinger->mStateLock); /* * called with the state lock from a binder thread when the layer is * removed from the current list to the pending removal list */ - void onRemovedFromCurrentState(); + void onRemovedFromCurrentState() REQUIRES(mFlinger->mStateLock); /* * Called when the layer is added back to the current state list. @@ -880,6 +881,9 @@ public: mTransformHint = transformHint; } + // Exposed so SurfaceFlinger can assert that it's held + const sp<SurfaceFlinger> mFlinger; + protected: // For unit tests friend class TestableSurfaceFlinger; @@ -941,9 +945,6 @@ protected: */ std::pair<FloatRect, bool> getInputBounds(bool fillParentBounds) const; - // constant - sp<SurfaceFlinger> mFlinger; - bool mPremultipliedAlpha{true}; const std::string mName; const std::string mTransactionName{"TX - " + mName}; diff --git a/services/surfaceflinger/MutexUtils.h b/services/surfaceflinger/MutexUtils.h index f8be6f3b85..58f7cb4c43 100644 --- a/services/surfaceflinger/MutexUtils.h +++ b/services/surfaceflinger/MutexUtils.h @@ -50,4 +50,14 @@ struct SCOPED_CAPABILITY TimedLock { const status_t status; }; +// Require, under penalty of compilation failure, that the compiler thinks that a mutex is held. +#define REQUIRE_MUTEX(expr) ([]() REQUIRES(expr) {})() + +// Tell the compiler that we know that a mutex is held. +#define ASSERT_MUTEX(expr) ([]() ASSERT_CAPABILITY(expr) {})() + +// Specify that one mutex is an alias for another. +// (e.g. SurfaceFlinger::mStateLock and Layer::mFlinger->mStateLock) +#define MUTEX_ALIAS(held, alias) (REQUIRE_MUTEX(held), ASSERT_MUTEX(alias)) + } // namespace android diff --git a/services/surfaceflinger/Scheduler/RefreshRateSelector.cpp b/services/surfaceflinger/Scheduler/RefreshRateSelector.cpp index eec7c085cc..f136e9f9df 100644 --- a/services/surfaceflinger/Scheduler/RefreshRateSelector.cpp +++ b/services/surfaceflinger/Scheduler/RefreshRateSelector.cpp @@ -564,7 +564,7 @@ auto RefreshRateSelector::getRankedFrameRatesLocked(const std::vector<LayerRequi continue; } - const bool inPrimaryRange = policy->primaryRanges.physical.includes(modePtr->getFps()); + const bool inPrimaryRange = policy->primaryRanges.render.includes(fps); if ((primaryRangeIsSingleRate || !inPrimaryRange) && !(layer.focused && (layer.vote == LayerVoteType::ExplicitDefault || diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp index f18dfdceb6..7f8d39451e 100644 --- a/services/surfaceflinger/Scheduler/Scheduler.cpp +++ b/services/surfaceflinger/Scheduler/Scheduler.cpp @@ -109,7 +109,6 @@ void Scheduler::startTimers() { void Scheduler::setPacesetterDisplay(std::optional<PhysicalDisplayId> pacesetterIdOpt) { demotePacesetterDisplay(); - std::scoped_lock lock(mDisplayLock); promotePacesetterDisplay(pacesetterIdOpt); } @@ -123,26 +122,34 @@ void Scheduler::registerDisplayInternal(PhysicalDisplayId displayId, std::shared_ptr<VsyncSchedule> vsyncSchedule) { demotePacesetterDisplay(); - std::scoped_lock lock(mDisplayLock); - mRefreshRateSelectors.emplace_or_replace(displayId, std::move(selectorPtr)); - mVsyncSchedules.emplace_or_replace(displayId, std::move(vsyncSchedule)); + std::shared_ptr<VsyncSchedule> pacesetterVsyncSchedule; + { + std::scoped_lock lock(mDisplayLock); + mRefreshRateSelectors.emplace_or_replace(displayId, std::move(selectorPtr)); + mVsyncSchedules.emplace_or_replace(displayId, std::move(vsyncSchedule)); - promotePacesetterDisplay(); + pacesetterVsyncSchedule = promotePacesetterDisplayLocked(); + } + applyNewVsyncSchedule(std::move(pacesetterVsyncSchedule)); } void Scheduler::unregisterDisplay(PhysicalDisplayId displayId) { demotePacesetterDisplay(); - std::scoped_lock lock(mDisplayLock); - mRefreshRateSelectors.erase(displayId); - mVsyncSchedules.erase(displayId); + std::shared_ptr<VsyncSchedule> pacesetterVsyncSchedule; + { + std::scoped_lock lock(mDisplayLock); + mRefreshRateSelectors.erase(displayId); + mVsyncSchedules.erase(displayId); - // Do not allow removing the final display. Code in the scheduler expects - // there to be at least one display. (This may be relaxed in the future with - // headless virtual display.) - LOG_ALWAYS_FATAL_IF(mRefreshRateSelectors.empty(), "Cannot unregister all displays!"); + // Do not allow removing the final display. Code in the scheduler expects + // there to be at least one display. (This may be relaxed in the future with + // headless virtual display.) + LOG_ALWAYS_FATAL_IF(mRefreshRateSelectors.empty(), "Cannot unregister all displays!"); - promotePacesetterDisplay(); + pacesetterVsyncSchedule = promotePacesetterDisplayLocked(); + } + applyNewVsyncSchedule(std::move(pacesetterVsyncSchedule)); } void Scheduler::run() { @@ -678,6 +685,18 @@ bool Scheduler::updateFrameRateOverrides(GlobalSignals consideredSignals, Fps di } void Scheduler::promotePacesetterDisplay(std::optional<PhysicalDisplayId> pacesetterIdOpt) { + std::shared_ptr<VsyncSchedule> pacesetterVsyncSchedule; + + { + std::scoped_lock lock(mDisplayLock); + pacesetterVsyncSchedule = promotePacesetterDisplayLocked(pacesetterIdOpt); + } + + applyNewVsyncSchedule(std::move(pacesetterVsyncSchedule)); +} + +std::shared_ptr<VsyncSchedule> Scheduler::promotePacesetterDisplayLocked( + std::optional<PhysicalDisplayId> pacesetterIdOpt) { // TODO(b/241286431): Choose the pacesetter display. mPacesetterDisplayId = pacesetterIdOpt.value_or(mRefreshRateSelectors.begin()->first); ALOGI("Display %s is the pacesetter", to_string(*mPacesetterDisplayId).c_str()); @@ -697,14 +716,22 @@ void Scheduler::promotePacesetterDisplay(std::optional<PhysicalDisplayId> pacese vsyncSchedule->startPeriodTransition(mSchedulerCallback, refreshRate.getPeriod(), true /* force */); } + return vsyncSchedule; +} +void Scheduler::applyNewVsyncSchedule(std::shared_ptr<VsyncSchedule> vsyncSchedule) { onNewVsyncSchedule(vsyncSchedule->getDispatch()); + std::vector<android::EventThread*> threads; { std::lock_guard<std::mutex> lock(mConnectionsLock); + threads.reserve(mConnections.size()); for (auto& [_, connection] : mConnections) { - connection.thread->onNewVsyncSchedule(vsyncSchedule); + threads.push_back(connection.thread.get()); } } + for (auto* thread : threads) { + thread->onNewVsyncSchedule(vsyncSchedule); + } } void Scheduler::demotePacesetterDisplay() { diff --git a/services/surfaceflinger/Scheduler/Scheduler.h b/services/surfaceflinger/Scheduler/Scheduler.h index 74547d5ea1..3423652163 100644 --- a/services/surfaceflinger/Scheduler/Scheduler.h +++ b/services/surfaceflinger/Scheduler/Scheduler.h @@ -321,7 +321,18 @@ private: // Chooses a pacesetter among the registered displays, unless `pacesetterIdOpt` is specified. // The new `mPacesetterDisplayId` is never `std::nullopt`. void promotePacesetterDisplay(std::optional<PhysicalDisplayId> pacesetterIdOpt = std::nullopt) + REQUIRES(kMainThreadContext) EXCLUDES(mDisplayLock); + + // Changes to the displays (e.g. registering and unregistering) must be made + // while mDisplayLock is locked, and the new pacesetter then must be promoted while + // mDisplayLock is still locked. However, a new pacesetter means that + // MessageQueue and EventThread need to use the new pacesetter's + // VsyncSchedule, and this must happen while mDisplayLock is *not* locked, + // or else we may deadlock with EventThread. + std::shared_ptr<VsyncSchedule> promotePacesetterDisplayLocked( + std::optional<PhysicalDisplayId> pacesetterIdOpt = std::nullopt) REQUIRES(kMainThreadContext, mDisplayLock); + void applyNewVsyncSchedule(std::shared_ptr<VsyncSchedule>) EXCLUDES(mDisplayLock); // Blocks until the pacesetter's idle timer thread exits. `mDisplayLock` must not be locked by // the caller on the main thread to avoid deadlock, since the timer thread locks it before exit. diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 791b42512c..145fd46187 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -478,10 +478,6 @@ SurfaceFlinger::SurfaceFlinger(Factory& factory) : SurfaceFlinger(factory, SkipI mIgnoreHdrCameraLayers = ignore_hdr_camera_layers(false); - // Power hint session mode, representing which hint(s) to send: early, late, or both) - mPowerHintSessionMode = - {.late = base::GetBoolProperty("debug.sf.send_late_power_session_hint"s, true), - .early = base::GetBoolProperty("debug.sf.send_early_power_session_hint"s, false)}; mLayerLifecycleManagerEnabled = base::GetBoolProperty("persist.debug.sf.enable_layer_lifecycle_manager"s, false); mLegacyFrontEndEnabled = !mLayerLifecycleManagerEnabled || @@ -715,12 +711,12 @@ void SurfaceFlinger::bootFinished() { readPersistentProperties(); mPowerAdvisor->onBootFinished(); - const bool powerHintEnabled = mFlagManager.use_adpf_cpu_hint(); - mPowerAdvisor->enablePowerHint(powerHintEnabled); - const bool powerHintUsed = mPowerAdvisor->usePowerHintSession(); + const bool hintSessionEnabled = mFlagManager.use_adpf_cpu_hint(); + mPowerAdvisor->enablePowerHintSession(hintSessionEnabled); + const bool hintSessionUsed = mPowerAdvisor->usePowerHintSession(); ALOGD("Power hint is %s", - powerHintUsed ? "supported" : (powerHintEnabled ? "unsupported" : "disabled")); - if (powerHintUsed) { + hintSessionUsed ? "supported" : (hintSessionEnabled ? "unsupported" : "disabled")); + if (hintSessionUsed) { std::optional<pid_t> renderEngineTid = getRenderEngine().getRenderEngineTid(); std::vector<int32_t> tidList; tidList.emplace_back(gettid()); @@ -2461,16 +2457,7 @@ bool SurfaceFlinger::commit(TimePoint frameTime, VsyncId vsyncId, TimePoint expe mPowerAdvisor->setFrameDelay(frameDelay); mPowerAdvisor->setTotalFrameTargetWorkDuration(idealSfWorkDuration); - - const auto& display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()).get(); - const Period vsyncPeriod = display->getActiveMode().fps.getPeriod(); - mPowerAdvisor->setTargetWorkDuration(vsyncPeriod); - - // Send early hint here to make sure there's not another frame pending - if (mPowerHintSessionMode.early) { - // Send a rough prediction for this frame based on last frame's timing info - mPowerAdvisor->sendPredictedWorkDuration(); - } + mPowerAdvisor->updateTargetWorkDuration(vsyncPeriod); } if (mRefreshRateOverlaySpinner) { @@ -2623,8 +2610,21 @@ void SurfaceFlinger::composite(TimePoint frameTime, VsyncId vsyncId) const auto prevVsyncTime = mExpectedPresentTime - mScheduler->getVsyncSchedule()->period(); const auto hwcMinWorkDuration = mVsyncConfiguration->getCurrentConfigs().hwcMinWorkDuration; - refreshArgs.earliestPresentTime = prevVsyncTime - hwcMinWorkDuration; - refreshArgs.previousPresentFence = mPreviousPresentFences[0].fenceTime; + const Period vsyncPeriod = mScheduler->getVsyncSchedule()->period(); + const bool threeVsyncsAhead = mExpectedPresentTime - frameTime > 2 * vsyncPeriod; + + // We should wait for the earliest present time if HWC doesn't support ExpectedPresentTime, + // and the next vsync is not already taken by the previous frame. + const bool waitForEarliestPresent = + !getHwComposer().getComposer()->isSupported( + Hwc2::Composer::OptionalFeature::ExpectedPresentTime) && + (threeVsyncsAhead || + mPreviousPresentFences[0].fenceTime->getSignalTime() != Fence::SIGNAL_TIME_PENDING); + + if (waitForEarliestPresent) { + refreshArgs.earliestPresentTime = prevVsyncTime - hwcMinWorkDuration; + } + refreshArgs.scheduledFrameTime = mScheduler->getScheduledFrameTime(); refreshArgs.expectedPresentTime = mExpectedPresentTime.ns(); refreshArgs.hasTrustedPresentationListener = mNumTrustedPresentationListeners > 0; @@ -2658,9 +2658,7 @@ void SurfaceFlinger::composite(TimePoint frameTime, VsyncId vsyncId) mPowerAdvisor->setSfPresentTiming(TimePoint::fromNs(mPreviousPresentFences[0] .fenceTime->getSignalTime()), TimePoint::now()); - if (mPowerHintSessionMode.late) { - mPowerAdvisor->sendActualWorkDuration(); - } + mPowerAdvisor->reportActualWorkDuration(); } if (mScheduler->onPostComposition(presentTime)) { @@ -2763,7 +2761,7 @@ bool SurfaceFlinger::isHdrLayer(const frontend::LayerSnapshot& snapshot) const { // RANGE_EXTENDED layers may identify themselves as being "HDR" via a desired sdr/hdr ratio if ((snapshot.dataspace & (int32_t)Dataspace::RANGE_MASK) == (int32_t)Dataspace::RANGE_EXTENDED && - snapshot.desiredSdrHdrRatio > 1.01f) { + snapshot.desiredHdrSdrRatio > 1.01f) { return true; } return false; @@ -2900,11 +2898,9 @@ void SurfaceFlinger::postComposition(nsecs_t callTime) { const auto* outputLayer = compositionDisplay->getOutputLayerForLayer(layerFe); if (outputLayer) { - // TODO(b/267350616): Rename SdrHdrRatio -> HdrSdrRatio - // everywhere - const float desiredHdrSdrRatio = snapshot.desiredSdrHdrRatio <= 1.f + const float desiredHdrSdrRatio = snapshot.desiredHdrSdrRatio <= 1.f ? std::numeric_limits<float>::infinity() - : snapshot.desiredSdrHdrRatio; + : snapshot.desiredHdrSdrRatio; info.mergeDesiredRatio(desiredHdrSdrRatio); info.numberOfHdrLayers++; const auto displayFrame = outputLayer->getState().displayFrame; @@ -3725,11 +3721,8 @@ void SurfaceFlinger::updateInputFlinger() { ATRACE_NAME("BackgroundExecutor::updateInputFlinger"); if (updateWindowInfo) { mWindowInfosListenerInvoker - ->windowInfosChanged(std::move(windowInfos), std::move(displayInfos), - std::move( - inputWindowCommands.windowInfosReportedListeners), - /* forceImmediateCall= */ - !inputWindowCommands.focusRequests.empty()); + ->windowInfosChanged(windowInfos, displayInfos, + inputWindowCommands.windowInfosReportedListeners); } else { // If there are listeners but no changes to input windows, call the listeners // immediately. @@ -4762,6 +4755,7 @@ uint32_t SurfaceFlinger::setClientStateLocked(const FrameTimelineInfo& frameTime } return 0; } + MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); ui::LayerStack oldLayerStack = layer->getLayerStack(LayerVector::StateSet::Current); @@ -4962,7 +4956,7 @@ uint32_t SurfaceFlinger::setClientStateLocked(const FrameTimelineInfo& frameTime if (layer->setDimmingEnabled(s.dimmingEnabled)) flags |= eTraversalNeeded; } if (what & layer_state_t::eExtendedRangeBrightnessChanged) { - if (layer->setExtendedRangeBrightness(s.currentSdrHdrRatio, s.desiredSdrHdrRatio)) { + if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { flags |= eTraversalNeeded; } } @@ -7756,6 +7750,7 @@ void SurfaceFlinger::handleLayerCreatedLocked(const LayerCreatedState& state, Vs ALOGD("Layer was destroyed soon after creation %p", state.layer.unsafe_get()); return; } + MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); sp<Layer> parent; bool addToRoot = state.addToRoot; @@ -7930,9 +7925,15 @@ bool SurfaceFlinger::commitMirrorDisplays(VsyncId vsyncId) { ISurfaceComposerClient::eNoColorFill, gui::LayerMetadata()); sp<Layer> childMirror; - createEffectLayer(mirrorArgs, &unused, &childMirror); - childMirror->setClonedChild(layer->createClone()); - childMirror->reparent(mirrorDisplay.rootHandle); + { + Mutex::Autolock lock(mStateLock); + createEffectLayer(mirrorArgs, &unused, &childMirror); + MUTEX_ALIAS(mStateLock, childMirror->mFlinger->mStateLock); + childMirror->setClonedChild(layer->createClone()); + childMirror->reparent(mirrorDisplay.rootHandle); + } + // lock on mStateLock needs to be released before binder handle gets destroyed + unused.clear(); } } return true; diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 44847885ca..35707a2682 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -797,7 +797,7 @@ private: status_t mirrorDisplay(DisplayId displayId, const LayerCreationArgs& args, gui::CreateSurfaceResult& outResult); - void markLayerPendingRemovalLocked(const sp<Layer>& layer); + void markLayerPendingRemovalLocked(const sp<Layer>& layer) REQUIRES(mStateLock); // add a layer to SurfaceFlinger status_t addClientLayer(LayerCreationArgs& args, const sp<IBinder>& handle, @@ -1413,10 +1413,6 @@ private: // These classes do not store any client state but help with managing transaction callbacks // and stats. std::unordered_map<uint32_t, sp<Layer>> mLegacyLayers; - struct { - bool late = false; - bool early = false; - } mPowerHintSessionMode; TransactionHandler mTransactionHandler; display::DisplayMap<ui::LayerStack, frontend::DisplayInfo> mFrontEndDisplayInfos; diff --git a/services/surfaceflinger/Tracing/TransactionProtoParser.cpp b/services/surfaceflinger/Tracing/TransactionProtoParser.cpp index 7642122adc..593c4ffc03 100644 --- a/services/surfaceflinger/Tracing/TransactionProtoParser.cpp +++ b/services/surfaceflinger/Tracing/TransactionProtoParser.cpp @@ -585,7 +585,7 @@ frontend::DisplayInfo TransactionProtoParser::fromProto(const proto::DisplayInfo displayInfo.receivesInput = proto.receives_input(); displayInfo.isSecure = proto.is_secure(); displayInfo.isPrimary = proto.is_primary(); - displayInfo.isPrimary = proto.is_virtual(); + displayInfo.isVirtual = proto.is_virtual(); displayInfo.rotationFlags = (ui::Transform::RotationFlags)proto.rotation_flags(); displayInfo.transformHint = (ui::Transform::RotationFlags)proto.transform_hint(); return displayInfo; @@ -593,7 +593,7 @@ frontend::DisplayInfo TransactionProtoParser::fromProto(const proto::DisplayInfo void TransactionProtoParser::fromProto( const google::protobuf::RepeatedPtrField<proto::DisplayInfo>& proto, - display::DisplayMap<ui::LayerStack, frontend::DisplayInfo> outDisplayInfos) { + display::DisplayMap<ui::LayerStack, frontend::DisplayInfo>& outDisplayInfos) { outDisplayInfos.clear(); for (const proto::DisplayInfo& displayInfo : proto) { outDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(displayInfo.layer_stack()), diff --git a/services/surfaceflinger/Tracing/TransactionProtoParser.h b/services/surfaceflinger/Tracing/TransactionProtoParser.h index 50944fce0f..d6c98e1120 100644 --- a/services/surfaceflinger/Tracing/TransactionProtoParser.h +++ b/services/surfaceflinger/Tracing/TransactionProtoParser.h @@ -49,15 +49,16 @@ public: proto::TransactionState toProto(const std::map<uint32_t /* layerId */, TracingLayerState>&); proto::LayerCreationArgs toProto(const LayerCreationArgs& args); proto::LayerState toProto(const ResolvedComposerState&); - proto::DisplayInfo toProto(const frontend::DisplayInfo&, uint32_t layerStack); + static proto::DisplayInfo toProto(const frontend::DisplayInfo&, uint32_t layerStack); TransactionState fromProto(const proto::TransactionState&); void mergeFromProto(const proto::LayerState&, TracingLayerState& outState); void fromProto(const proto::LayerCreationArgs&, LayerCreationArgs& outArgs); std::unique_ptr<FlingerDataMapper> mMapper; - frontend::DisplayInfo fromProto(const proto::DisplayInfo&); - void fromProto(const google::protobuf::RepeatedPtrField<proto::DisplayInfo>&, - display::DisplayMap<ui::LayerStack, frontend::DisplayInfo> outDisplayInfos); + static frontend::DisplayInfo fromProto(const proto::DisplayInfo&); + static void fromProto( + const google::protobuf::RepeatedPtrField<proto::DisplayInfo>&, + display::DisplayMap<ui::LayerStack, frontend::DisplayInfo>& outDisplayInfos); private: proto::DisplayState toProto(const DisplayState&); diff --git a/services/surfaceflinger/Tracing/TransactionTracing.cpp b/services/surfaceflinger/Tracing/TransactionTracing.cpp index 26ed878396..87a633fc9d 100644 --- a/services/surfaceflinger/Tracing/TransactionTracing.cpp +++ b/services/surfaceflinger/Tracing/TransactionTracing.cpp @@ -271,6 +271,7 @@ void TransactionTracing::updateStartingStateLocked( for (const proto::LayerState& layerState : transaction.layer_changes()) { auto it = mStartingStates.find(layerState.layer_id()); if (it == mStartingStates.end()) { + // TODO(b/238781169) make this log fatal when we switch over to using new fe ALOGW("Could not find layer id %d", layerState.layer_id()); continue; } diff --git a/services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp b/services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp index 0ea421bd24..55004c5e70 100644 --- a/services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp +++ b/services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp @@ -14,14 +14,6 @@ * limitations under the License. */ -#include <ios> -#include <memory> -#include <vector> -#include "FrontEnd/LayerCreationArgs.h" -#include "FrontEnd/RequestedLayerState.h" -#include "Tracing/LayerTracing.h" -#include "TransactionState.h" -#include "cutils/properties.h" #undef LOG_TAG #define LOG_TAG "LayerTraceGenerator" //#define LOG_NDEBUG 0 @@ -33,8 +25,15 @@ #include <utils/String16.h> #include <filesystem> #include <fstream> +#include <ios> #include <string> +#include <vector> +#include "FrontEnd/LayerCreationArgs.h" +#include "FrontEnd/RequestedLayerState.h" #include "LayerProtoHelper.h" +#include "Tracing/LayerTracing.h" +#include "TransactionState.h" +#include "cutils/properties.h" #include "LayerTraceGenerator.h" @@ -84,6 +83,7 @@ bool LayerTraceGenerator::generate(const proto::TransactionTraceFile& traceFile, for (int j = 0; j < entry.added_layers_size(); j++) { LayerCreationArgs args; parser.fromProto(entry.added_layers(j), args); + ALOGV(" %s", args.getDebugString().c_str()); addedLayers.emplace_back(std::make_unique<frontend::RequestedLayerState>(args)); } @@ -92,12 +92,27 @@ bool LayerTraceGenerator::generate(const proto::TransactionTraceFile& traceFile, for (int j = 0; j < entry.transactions_size(); j++) { // apply transactions TransactionState transaction = parser.fromProto(entry.transactions(j)); + for (auto& resolvedComposerState : transaction.states) { + if (resolvedComposerState.state.what & layer_state_t::eInputInfoChanged) { + if (!resolvedComposerState.state.windowInfoHandle->getInfo()->inputConfig.test( + gui::WindowInfo::InputConfig::NO_INPUT_CHANNEL)) { + // create a fake token since the FE expects a valid token + resolvedComposerState.state.windowInfoHandle->editInfo()->token = + sp<BBinder>::make(); + } + } + } transactions.emplace_back(std::move(transaction)); } + for (int j = 0; j < entry.destroyed_layers_size(); j++) { + ALOGV(" destroyedHandles=%d", entry.destroyed_layers(j)); + } + std::vector<uint32_t> destroyedHandles; destroyedHandles.reserve((size_t)entry.destroyed_layer_handles_size()); for (int j = 0; j < entry.destroyed_layer_handles_size(); j++) { + ALOGV(" destroyedHandles=%d", entry.destroyed_layer_handles(j)); destroyedHandles.push_back(entry.destroyed_layer_handles(j)); } @@ -108,7 +123,7 @@ bool LayerTraceGenerator::generate(const proto::TransactionTraceFile& traceFile, // apply updates lifecycleManager.addLayers(std::move(addedLayers)); - lifecycleManager.applyTransactions(transactions); + lifecycleManager.applyTransactions(transactions, /*ignoreUnknownHandles=*/true); lifecycleManager.onHandlesDestroyed(destroyedHandles, /*ignoreUnknownHandles=*/true); if (lifecycleManager.getGlobalChanges().test( diff --git a/services/surfaceflinger/WindowInfosListenerInvoker.cpp b/services/surfaceflinger/WindowInfosListenerInvoker.cpp index 73a7cae6d6..292083b9bc 100644 --- a/services/surfaceflinger/WindowInfosListenerInvoker.cpp +++ b/services/surfaceflinger/WindowInfosListenerInvoker.cpp @@ -25,14 +25,20 @@ using gui::DisplayInfo; using gui::IWindowInfosListener; using gui::WindowInfo; -struct WindowInfosReportedListenerInvoker : gui::BnWindowInfosReportedListener, - IBinder::DeathRecipient { - WindowInfosReportedListenerInvoker(size_t callbackCount, - WindowInfosReportedListenerSet windowInfosReportedListeners) +struct WindowInfosListenerInvoker::WindowInfosReportedListener : gui::BnWindowInfosReportedListener, + DeathRecipient { + explicit WindowInfosReportedListener( + size_t callbackCount, + const std::unordered_set<sp<gui::IWindowInfosReportedListener>, + SpHash<gui::IWindowInfosReportedListener>>& + windowInfosReportedListeners) : mCallbacksPending(callbackCount), - mWindowInfosReportedListeners(std::move(windowInfosReportedListeners)) {} + mWindowInfosReportedListeners(windowInfosReportedListeners) {} binder::Status onWindowInfosReported() override { + // TODO(b/222421815) There could potentially be callbacks that we don't need to wait for + // before calling the WindowInfosReportedListeners coming from InputWindowCommands. Filter + // the list of callbacks down to those from system server. if (--mCallbacksPending == 0) { for (const auto& listener : mWindowInfosReportedListeners) { sp<IBinder> asBinder = IInterface::asBinder(listener); @@ -48,7 +54,9 @@ struct WindowInfosReportedListenerInvoker : gui::BnWindowInfosReportedListener, private: std::atomic<size_t> mCallbacksPending; - WindowInfosReportedListenerSet mWindowInfosReportedListeners; + std::unordered_set<sp<gui::IWindowInfosReportedListener>, + SpHash<gui::IWindowInfosReportedListener>> + mWindowInfosReportedListeners; }; void WindowInfosListenerInvoker::addWindowInfosListener(sp<IWindowInfosListener> listener) { @@ -74,76 +82,38 @@ void WindowInfosListenerInvoker::binderDied(const wp<IBinder>& who) { } void WindowInfosListenerInvoker::windowInfosChanged( - std::vector<WindowInfo> windowInfos, std::vector<DisplayInfo> displayInfos, - WindowInfosReportedListenerSet reportedListeners, bool forceImmediateCall) { - reportedListeners.insert(sp<WindowInfosListenerInvoker>::fromExisting(this)); - auto callListeners = [this, windowInfos = std::move(windowInfos), - displayInfos = std::move(displayInfos), - reportedListeners = std::move(reportedListeners)]() mutable { - ftl::SmallVector<const sp<IWindowInfosListener>, kStaticCapacity> windowInfosListeners; - { - std::scoped_lock lock(mListenersMutex); - for (const auto& [_, listener] : mWindowInfosListeners) { - windowInfosListeners.push_back(listener); - } - } - - auto reportedInvoker = - sp<WindowInfosReportedListenerInvoker>::make(windowInfosListeners.size(), - std::move(reportedListeners)); - - for (const auto& listener : windowInfosListeners) { - sp<IBinder> asBinder = IInterface::asBinder(listener); - - // linkToDeath is used here to ensure that the windowInfosReportedListeners - // are called even if one of the windowInfosListeners dies before - // calling onWindowInfosReported. - asBinder->linkToDeath(reportedInvoker); - - auto status = - listener->onWindowInfosChanged(windowInfos, displayInfos, reportedInvoker); - if (!status.isOk()) { - reportedInvoker->onWindowInfosReported(); - } - } - }; - + const std::vector<WindowInfo>& windowInfos, const std::vector<DisplayInfo>& displayInfos, + const std::unordered_set<sp<gui::IWindowInfosReportedListener>, + SpHash<gui::IWindowInfosReportedListener>>& + windowInfosReportedListeners) { + ftl::SmallVector<const sp<IWindowInfosListener>, kStaticCapacity> windowInfosListeners; { - std::scoped_lock lock(mMessagesMutex); - // If there are unacked messages and this isn't a forced call, then return immediately. - // If a forced window infos change doesn't happen first, the update will be sent after - // the WindowInfosReportedListeners are called. If a forced window infos change happens or - // if there are subsequent delayed messages before this update is sent, then this message - // will be dropped and the listeners will only be called with the latest info. This is done - // to reduce the amount of binder memory used. - if (mActiveMessageCount > 0 && !forceImmediateCall) { - mWindowInfosChangedDelayed = std::move(callListeners); - return; + std::scoped_lock lock(mListenersMutex); + for (const auto& [_, listener] : mWindowInfosListeners) { + windowInfosListeners.push_back(listener); } - - mWindowInfosChangedDelayed = nullptr; - mActiveMessageCount++; } - callListeners(); -} - -binder::Status WindowInfosListenerInvoker::onWindowInfosReported() { - std::function<void()> callListeners; - { - std::scoped_lock lock{mMessagesMutex}; - mActiveMessageCount--; - if (!mWindowInfosChangedDelayed || mActiveMessageCount > 0) { - return binder::Status::ok(); + auto windowInfosReportedListener = windowInfosReportedListeners.empty() + ? nullptr + : sp<WindowInfosReportedListener>::make(windowInfosListeners.size(), + windowInfosReportedListeners); + for (const auto& listener : windowInfosListeners) { + sp<IBinder> asBinder = IInterface::asBinder(listener); + + // linkToDeath is used here to ensure that the windowInfosReportedListeners + // are called even if one of the windowInfosListeners dies before + // calling onWindowInfosReported. + if (windowInfosReportedListener) { + asBinder->linkToDeath(windowInfosReportedListener); } - mActiveMessageCount++; - callListeners = std::move(mWindowInfosChangedDelayed); - mWindowInfosChangedDelayed = nullptr; + auto status = listener->onWindowInfosChanged(windowInfos, displayInfos, + windowInfosReportedListener); + if (windowInfosReportedListener && !status.isOk()) { + windowInfosReportedListener->onWindowInfosReported(); + } } - - callListeners(); - return binder::Status::ok(); } } // namespace android diff --git a/services/surfaceflinger/WindowInfosListenerInvoker.h b/services/surfaceflinger/WindowInfosListenerInvoker.h index bfe036e025..d60a9c4157 100644 --- a/services/surfaceflinger/WindowInfosListenerInvoker.h +++ b/services/surfaceflinger/WindowInfosListenerInvoker.h @@ -23,40 +23,34 @@ #include <android/gui/IWindowInfosReportedListener.h> #include <binder/IBinder.h> #include <ftl/small_map.h> -#include <gui/SpHash.h> #include <utils/Mutex.h> namespace android { -using WindowInfosReportedListenerSet = - std::unordered_set<sp<gui::IWindowInfosReportedListener>, - gui::SpHash<gui::IWindowInfosReportedListener>>; +class SurfaceFlinger; -class WindowInfosListenerInvoker : public gui::BnWindowInfosReportedListener, - public IBinder::DeathRecipient { +class WindowInfosListenerInvoker : public IBinder::DeathRecipient { public: void addWindowInfosListener(sp<gui::IWindowInfosListener>); void removeWindowInfosListener(const sp<gui::IWindowInfosListener>& windowInfosListener); - void windowInfosChanged(std::vector<gui::WindowInfo>, std::vector<gui::DisplayInfo>, - WindowInfosReportedListenerSet windowInfosReportedListeners, - bool forceImmediateCall); - - binder::Status onWindowInfosReported() override; + void windowInfosChanged(const std::vector<gui::WindowInfo>&, + const std::vector<gui::DisplayInfo>&, + const std::unordered_set<sp<gui::IWindowInfosReportedListener>, + SpHash<gui::IWindowInfosReportedListener>>& + windowInfosReportedListeners); protected: void binderDied(const wp<IBinder>& who) override; private: + struct WindowInfosReportedListener; + std::mutex mListenersMutex; static constexpr size_t kStaticCapacity = 3; ftl::SmallMap<wp<IBinder>, const sp<gui::IWindowInfosListener>, kStaticCapacity> mWindowInfosListeners GUARDED_BY(mListenersMutex); - - std::mutex mMessagesMutex; - uint32_t mActiveMessageCount GUARDED_BY(mMessagesMutex) = 0; - std::function<void()> mWindowInfosChangedDelayed GUARDED_BY(mMessagesMutex); }; } // namespace android diff --git a/services/surfaceflinger/fuzzer/Android.bp b/services/surfaceflinger/fuzzer/Android.bp index 7350e09cb5..f76a8d762a 100644 --- a/services/surfaceflinger/fuzzer/Android.bp +++ b/services/surfaceflinger/fuzzer/Android.bp @@ -69,6 +69,7 @@ cc_defaults { "-Wno-unused-result", "-Wno-conversion", "-Wno-sign-compare", + "-Wno-unused-function", ], fuzz_config: { cc: [ diff --git a/services/surfaceflinger/fuzzer/surfaceflinger_displayhardware_fuzzer.cpp b/services/surfaceflinger/fuzzer/surfaceflinger_displayhardware_fuzzer.cpp index 8a6af10f58..a9247fe903 100644 --- a/services/surfaceflinger/fuzzer/surfaceflinger_displayhardware_fuzzer.cpp +++ b/services/surfaceflinger/fuzzer/surfaceflinger_displayhardware_fuzzer.cpp @@ -222,7 +222,7 @@ void DisplayHardwareFuzzer::getDeviceCompositionChanges(HalDisplayId halDisplayI std::optional<impl::HWComposer::DeviceRequestedChanges> outChanges; mHwc.getDeviceCompositionChanges(halDisplayID, mFdp.ConsumeBool() /*frameUsesClientComposition*/, - std::chrono::steady_clock::now(), FenceTime::NO_FENCE, + std::chrono::steady_clock::now(), mFdp.ConsumeIntegral<nsecs_t>(), &outChanges); } @@ -555,8 +555,7 @@ void DisplayHardwareFuzzer::invokeComposer() { mHwc.setClientTarget(halDisplayID, mFdp.ConsumeIntegral<uint32_t>(), Fence::NO_FENCE, sp<GraphicBuffer>::make(), mFdp.PickValueInArray(kDataspaces)); - mHwc.presentAndGetReleaseFences(halDisplayID, std::chrono::steady_clock::now(), - FenceTime::NO_FENCE); + mHwc.presentAndGetReleaseFences(halDisplayID, std::chrono::steady_clock::now()); mHwc.setPowerMode(mPhysicalDisplayId, mFdp.PickValueInArray(kPowerModes)); diff --git a/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h b/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h index 6074bb7a16..c1bab0e89b 100644 --- a/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h +++ b/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h @@ -49,6 +49,7 @@ #include "SurfaceFlingerDefaultFactory.h" #include "ThreadContext.h" #include "TimeStats/TimeStats.h" +#include "surfaceflinger_scheduler_fuzzer.h" #include "renderengine/mock/RenderEngine.h" #include "scheduler/TimeKeeper.h" @@ -237,7 +238,8 @@ public: const auto displayId = selectorPtr->getActiveMode().modePtr->getPhysicalDisplayId(); registerDisplayInternal(displayId, std::move(selectorPtr), std::shared_ptr<VsyncSchedule>( - new VsyncSchedule(displayId, std::move(tracker), nullptr, + new VsyncSchedule(displayId, std::move(tracker), + std::make_shared<FuzzImplVSyncDispatch>(), std::move(controller)))); } diff --git a/services/surfaceflinger/fuzzer/surfaceflinger_scheduler_fuzzer.h b/services/surfaceflinger/fuzzer/surfaceflinger_scheduler_fuzzer.h index e6be9a8b21..a32750e657 100644 --- a/services/surfaceflinger/fuzzer/surfaceflinger_scheduler_fuzzer.h +++ b/services/surfaceflinger/fuzzer/surfaceflinger_scheduler_fuzzer.h @@ -129,6 +129,11 @@ public: return (scheduler::ScheduleResult)0; } + scheduler::ScheduleResult update(CallbackToken /* token */, + ScheduleTiming /* scheduleTiming */) override { + return (scheduler::ScheduleResult)0; + } + scheduler::CancelResult cancel(CallbackToken /* token */) override { return (scheduler::CancelResult)0; } diff --git a/services/surfaceflinger/tests/tracing/TransactionTraceTestSuite.cpp b/services/surfaceflinger/tests/tracing/TransactionTraceTestSuite.cpp index 7355c35131..2b295309e7 100644 --- a/services/surfaceflinger/tests/tracing/TransactionTraceTestSuite.cpp +++ b/services/surfaceflinger/tests/tracing/TransactionTraceTestSuite.cpp @@ -22,6 +22,7 @@ #include <string> #include <unordered_map> +#include <LayerProtoHelper.h> #include <LayerTraceGenerator.h> #include <Tracing/TransactionProtoParser.h> #include <layerproto/LayerProtoHeader.h> @@ -94,11 +95,14 @@ struct LayerInfo { float y; uint32_t bufferWidth; uint32_t bufferHeight; + Rect touchableRegionBounds; }; bool operator==(const LayerInfo& lh, const LayerInfo& rh) { - return std::make_tuple(lh.id, lh.name, lh.parent, lh.z, lh.curr_frame) == - std::make_tuple(rh.id, rh.name, rh.parent, rh.z, rh.curr_frame); + return std::make_tuple(lh.id, lh.name, lh.parent, lh.z, lh.curr_frame, lh.bufferWidth, + lh.bufferHeight, lh.touchableRegionBounds) == + std::make_tuple(rh.id, rh.name, rh.parent, rh.z, rh.curr_frame, rh.bufferWidth, + rh.bufferHeight, rh.touchableRegionBounds); } bool compareById(const LayerInfo& a, const LayerInfo& b) { @@ -109,7 +113,9 @@ inline void PrintTo(const LayerInfo& info, ::std::ostream* os) { *os << "Layer [" << info.id << "] name=" << info.name << " parent=" << info.parent << " z=" << info.z << " curr_frame=" << info.curr_frame << " x=" << info.x << " y=" << info.y << " bufferWidth=" << info.bufferWidth - << " bufferHeight=" << info.bufferHeight; + << " bufferHeight=" << info.bufferHeight << "touchableRegionBounds={" + << info.touchableRegionBounds.left << "," << info.touchableRegionBounds.top << "," + << info.touchableRegionBounds.right << "," << info.touchableRegionBounds.bottom << "}"; } struct find_id : std::unary_function<LayerInfo, bool> { @@ -119,6 +125,17 @@ struct find_id : std::unary_function<LayerInfo, bool> { }; static LayerInfo getLayerInfoFromProto(::android::surfaceflinger::LayerProto& proto) { + Rect touchableRegionBounds = Rect::INVALID_RECT; + // ignore touchable region for layers without buffers, the new fe aggressively avoids + // calculating state for layers that are not visible which could lead to mismatches + if (proto.has_input_window_info() && proto.input_window_info().has_touchable_region() && + proto.has_active_buffer()) { + Region touchableRegion; + LayerProtoHelper::readFromProto(proto.input_window_info().touchable_region(), + touchableRegion); + touchableRegionBounds = touchableRegion.bounds(); + } + return {proto.id(), proto.name(), proto.parent(), @@ -127,45 +144,52 @@ static LayerInfo getLayerInfoFromProto(::android::surfaceflinger::LayerProto& pr proto.has_position() ? proto.position().x() : -1, proto.has_position() ? proto.position().y() : -1, proto.has_active_buffer() ? proto.active_buffer().width() : 0, - proto.has_active_buffer() ? proto.active_buffer().height() : 0}; + proto.has_active_buffer() ? proto.active_buffer().height() : 0, + touchableRegionBounds}; } -TEST_P(TransactionTraceTestSuite, validateEndState) { - ASSERT_GT(mActualLayersTraceProto.entry_size(), 0); - ASSERT_GT(mExpectedLayersTraceProto.entry_size(), 0); - - auto expectedLastEntry = - mExpectedLayersTraceProto.entry(mExpectedLayersTraceProto.entry_size() - 1); - auto actualLastEntry = mActualLayersTraceProto.entry(mActualLayersTraceProto.entry_size() - 1); - - EXPECT_EQ(expectedLastEntry.layers().layers_size(), actualLastEntry.layers().layers_size()); - - std::vector<LayerInfo> expectedLayers; - expectedLayers.reserve(static_cast<size_t>(expectedLastEntry.layers().layers_size())); - for (int i = 0; i < expectedLastEntry.layers().layers_size(); i++) { - auto layer = expectedLastEntry.layers().layers(i); - LayerInfo layerInfo = getLayerInfoFromProto(layer); - expectedLayers.push_back(layerInfo); - } - std::sort(expectedLayers.begin(), expectedLayers.end(), compareById); - +static std::vector<LayerInfo> getLayerInfosFromProto( + android::surfaceflinger::LayersTraceProto& entry) { std::unordered_map<int32_t /* snapshotId*/, int32_t /*layerId*/> snapshotIdToLayerId; - std::vector<LayerInfo> actualLayers; - actualLayers.reserve(static_cast<size_t>(actualLastEntry.layers().layers_size())); - for (int i = 0; i < actualLastEntry.layers().layers_size(); i++) { - auto layer = actualLastEntry.layers().layers(i); + std::vector<LayerInfo> layers; + layers.reserve(static_cast<size_t>(entry.layers().layers_size())); + bool mapSnapshotIdToLayerId = false; + for (int i = 0; i < entry.layers().layers_size(); i++) { + auto layer = entry.layers().layers(i); LayerInfo layerInfo = getLayerInfoFromProto(layer); + snapshotIdToLayerId[layerInfo.id] = static_cast<int32_t>(layer.original_id()); - actualLayers.push_back(layerInfo); + if (layer.original_id() != 0) { + mapSnapshotIdToLayerId = true; + } + layers.push_back(layerInfo); } + std::sort(layers.begin(), layers.end(), compareById); - for (auto& layer : actualLayers) { + if (!mapSnapshotIdToLayerId) { + return layers; + } + for (auto& layer : layers) { layer.id = snapshotIdToLayerId[layer.id]; auto it = snapshotIdToLayerId.find(layer.parent); layer.parent = it == snapshotIdToLayerId.end() ? -1 : it->second; } + return layers; +} + +TEST_P(TransactionTraceTestSuite, validateEndState) { + ASSERT_GT(mActualLayersTraceProto.entry_size(), 0); + ASSERT_GT(mExpectedLayersTraceProto.entry_size(), 0); + + auto expectedLastEntry = + mExpectedLayersTraceProto.entry(mExpectedLayersTraceProto.entry_size() - 1); + auto actualLastEntry = mActualLayersTraceProto.entry(mActualLayersTraceProto.entry_size() - 1); + + EXPECT_EQ(expectedLastEntry.layers().layers_size(), actualLastEntry.layers().layers_size()); - std::sort(actualLayers.begin(), actualLayers.end(), compareById); + std::vector<LayerInfo> expectedLayers = getLayerInfosFromProto(expectedLastEntry); + std::vector<LayerInfo> actualLayers = getLayerInfosFromProto(actualLastEntry); + ; size_t i = 0; for (; i < actualLayers.size() && i < expectedLayers.size(); i++) { diff --git a/services/surfaceflinger/tests/tracing/testdata/layers_trace_b275630566.winscope b/services/surfaceflinger/tests/tracing/testdata/layers_trace_b275630566.winscope Binary files differnew file mode 100644 index 0000000000..fe504d741b --- /dev/null +++ b/services/surfaceflinger/tests/tracing/testdata/layers_trace_b275630566.winscope diff --git a/services/surfaceflinger/tests/tracing/testdata/transactions_trace_b275630566.winscope b/services/surfaceflinger/tests/tracing/testdata/transactions_trace_b275630566.winscope Binary files differnew file mode 100644 index 0000000000..6f7ba15421 --- /dev/null +++ b/services/surfaceflinger/tests/tracing/testdata/transactions_trace_b275630566.winscope diff --git a/services/surfaceflinger/tests/unittests/AidlPowerHalWrapperTest.cpp b/services/surfaceflinger/tests/unittests/AidlPowerHalWrapperTest.cpp deleted file mode 100644 index 513f77989b..0000000000 --- a/services/surfaceflinger/tests/unittests/AidlPowerHalWrapperTest.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#undef LOG_TAG -#define LOG_TAG "AidlPowerHalWrapperTest" - -#include <android-base/stringprintf.h> -#include <android/hardware/power/IPower.h> -#include <android/hardware/power/IPowerHintSession.h> -#include <gmock/gmock.h> -#include <gtest/gtest.h> -#include <algorithm> -#include <chrono> -#include <memory> -#include "DisplayHardware/PowerAdvisor.h" -#include "android/hardware/power/WorkDuration.h" -#include "binder/Status.h" -#include "log/log_main.h" -#include "mock/DisplayHardware/MockIPower.h" -#include "mock/DisplayHardware/MockIPowerHintSession.h" -#include "utils/Timers.h" - -using namespace android; -using namespace android::Hwc2::mock; -using namespace android::hardware::power; -using namespace std::chrono_literals; -using namespace testing; - -namespace android::Hwc2::impl { - -class AidlPowerHalWrapperTest : public testing::Test { -public: - void SetUp() override; - -protected: - std::unique_ptr<AidlPowerHalWrapper> mWrapper = nullptr; - sp<NiceMock<MockIPower>> mMockHal = nullptr; - sp<NiceMock<MockIPowerHintSession>> mMockSession = nullptr; - void verifyAndClearExpectations(); - void sendActualWorkDurationGroup(std::vector<WorkDuration> durations); - static constexpr std::chrono::duration kStaleTimeout = 100ms; -}; - -void AidlPowerHalWrapperTest::SetUp() { - mMockHal = sp<NiceMock<MockIPower>>::make(); - mMockSession = sp<NiceMock<MockIPowerHintSession>>::make(); - ON_CALL(*mMockHal.get(), getHintSessionPreferredRate(_)).WillByDefault(Return(Status::ok())); - mWrapper = std::make_unique<AidlPowerHalWrapper>(mMockHal); -} - -void AidlPowerHalWrapperTest::verifyAndClearExpectations() { - Mock::VerifyAndClearExpectations(mMockHal.get()); - Mock::VerifyAndClearExpectations(mMockSession.get()); -} - -void AidlPowerHalWrapperTest::sendActualWorkDurationGroup(std::vector<WorkDuration> durations) { - for (size_t i = 0; i < durations.size(); i++) { - auto duration = durations[i]; - mWrapper->sendActualWorkDuration(Duration::fromNs(duration.durationNanos), - TimePoint::fromNs(duration.timeStampNanos)); - } -} - -WorkDuration toWorkDuration(std::chrono::nanoseconds durationNanos, int64_t timeStampNanos) { - WorkDuration duration; - duration.durationNanos = durationNanos.count(); - duration.timeStampNanos = timeStampNanos; - return duration; -} - -WorkDuration toWorkDuration(std::pair<std::chrono::nanoseconds, nsecs_t> timePair) { - return toWorkDuration(timePair.first, timePair.second); -} - -std::string printWorkDurations(const ::std::vector<WorkDuration>& durations) { - std::ostringstream os; - for (auto duration : durations) { - os << duration.toString(); - os << "\n"; - } - return os.str(); -} - -namespace { -TEST_F(AidlPowerHalWrapperTest, supportsPowerHintSession) { - ASSERT_TRUE(mWrapper->supportsPowerHintSession()); - Mock::VerifyAndClearExpectations(mMockHal.get()); - ON_CALL(*mMockHal.get(), getHintSessionPreferredRate(_)) - .WillByDefault(Return(Status::fromExceptionCode(Status::Exception::EX_ILLEGAL_STATE))); - auto newWrapper = AidlPowerHalWrapper(mMockHal); - EXPECT_FALSE(newWrapper.supportsPowerHintSession()); -} - -TEST_F(AidlPowerHalWrapperTest, startPowerHintSession) { - ASSERT_TRUE(mWrapper->supportsPowerHintSession()); - std::vector<int32_t> threadIds = {1, 2}; - mWrapper->setPowerHintSessionThreadIds(threadIds); - EXPECT_CALL(*mMockHal.get(), createHintSession(_, _, threadIds, _, _)) - .WillOnce(DoAll(SetArgPointee<4>(mMockSession), Return(Status::ok()))); - EXPECT_TRUE(mWrapper->startPowerHintSession()); - EXPECT_FALSE(mWrapper->startPowerHintSession()); -} - -TEST_F(AidlPowerHalWrapperTest, restartNewPowerHintSessionWithNewThreadIds) { - ASSERT_TRUE(mWrapper->supportsPowerHintSession()); - - std::vector<int32_t> threadIds = {1, 2}; - EXPECT_CALL(*mMockHal.get(), createHintSession(_, _, threadIds, _, _)) - .WillOnce(DoAll(SetArgPointee<4>(mMockSession), Return(Status::ok()))); - mWrapper->setPowerHintSessionThreadIds(threadIds); - EXPECT_EQ(mWrapper->getPowerHintSessionThreadIds(), threadIds); - ASSERT_TRUE(mWrapper->startPowerHintSession()); - verifyAndClearExpectations(); - - threadIds = {2, 3}; - EXPECT_CALL(*mMockHal.get(), createHintSession(_, _, threadIds, _, _)) - .WillOnce(DoAll(SetArgPointee<4>(mMockSession), Return(Status::ok()))); - EXPECT_CALL(*mMockSession.get(), close()).Times(1); - mWrapper->setPowerHintSessionThreadIds(threadIds); - EXPECT_EQ(mWrapper->getPowerHintSessionThreadIds(), threadIds); - verifyAndClearExpectations(); - - EXPECT_CALL(*mMockHal.get(), createHintSession(_, _, threadIds, _, _)).Times(0); - EXPECT_CALL(*mMockSession.get(), close()).Times(0); - mWrapper->setPowerHintSessionThreadIds(threadIds); - verifyAndClearExpectations(); -} - -TEST_F(AidlPowerHalWrapperTest, setTargetWorkDuration) { - ASSERT_TRUE(mWrapper->supportsPowerHintSession()); - - std::vector<int32_t> threadIds = {1, 2}; - mWrapper->setPowerHintSessionThreadIds(threadIds); - EXPECT_CALL(*mMockHal.get(), createHintSession(_, _, threadIds, _, _)) - .WillOnce(DoAll(SetArgPointee<4>(mMockSession), Return(Status::ok()))); - ASSERT_TRUE(mWrapper->startPowerHintSession()); - verifyAndClearExpectations(); - - std::chrono::nanoseconds base = 100ms; - // test cases with target work duration and whether it should update hint against baseline 100ms - const std::vector<std::pair<std::chrono::nanoseconds, bool>> testCases = - {{0ms, true}, {-1ms, true}, {200ms, true}, {2ms, true}, {100ms, false}, {109ms, true}}; - - for (const auto& test : testCases) { - // reset to 100ms baseline - mWrapper->setTargetWorkDuration(1ns); - mWrapper->setTargetWorkDuration(base); - - std::chrono::nanoseconds target = test.first; - EXPECT_CALL(*mMockSession.get(), updateTargetWorkDuration(target.count())) - .Times(test.second ? 1 : 0); - mWrapper->setTargetWorkDuration(target); - verifyAndClearExpectations(); - } -} - -TEST_F(AidlPowerHalWrapperTest, setTargetWorkDuration_shouldReconnectOnError) { - ASSERT_TRUE(mWrapper->supportsPowerHintSession()); - - std::vector<int32_t> threadIds = {1, 2}; - mWrapper->setPowerHintSessionThreadIds(threadIds); - EXPECT_CALL(*mMockHal.get(), createHintSession(_, _, threadIds, _, _)) - .WillOnce(DoAll(SetArgPointee<4>(mMockSession), Return(Status::ok()))); - ASSERT_TRUE(mWrapper->startPowerHintSession()); - verifyAndClearExpectations(); - - EXPECT_CALL(*mMockSession.get(), updateTargetWorkDuration(1)) - .WillOnce(Return(Status::fromExceptionCode(Status::Exception::EX_ILLEGAL_STATE))); - mWrapper->setTargetWorkDuration(1ns); - EXPECT_TRUE(mWrapper->shouldReconnectHAL()); -} - -TEST_F(AidlPowerHalWrapperTest, sendActualWorkDuration) { - ASSERT_TRUE(mWrapper->supportsPowerHintSession()); - - std::vector<int32_t> threadIds = {1, 2}; - mWrapper->setPowerHintSessionThreadIds(threadIds); - EXPECT_CALL(*mMockHal.get(), createHintSession(_, _, threadIds, _, _)) - .WillOnce(DoAll(SetArgPointee<4>(mMockSession), Return(Status::ok()))); - ASSERT_TRUE(mWrapper->startPowerHintSession()); - verifyAndClearExpectations(); - - auto base = toWorkDuration(100ms, 0); - // test cases with actual work durations and whether it should update hint against baseline - // 100ms - const std::vector<std::pair<std::vector<std::pair<std::chrono::nanoseconds, nsecs_t>>, bool>> - testCases = {{{{-1ms, 100}}, false}, - {{{50ms, 100}}, true}, - {{{100ms, 100}, {200ms, 200}}, true}, - {{{100ms, 500}, {100ms, 600}, {3ms, 600}}, true}}; - - for (const auto& test : testCases) { - // reset actual duration - sendActualWorkDurationGroup({base}); - - auto raw = test.first; - std::vector<WorkDuration> durations(raw.size()); - std::transform(raw.begin(), raw.end(), durations.begin(), - [](auto d) { return toWorkDuration(d); }); - for (auto& duration : durations) { - EXPECT_CALL(*mMockSession.get(), - reportActualWorkDuration(std::vector<WorkDuration>{duration})) - .Times(test.second ? 1 : 0); - } - sendActualWorkDurationGroup(durations); - verifyAndClearExpectations(); - } -} - -TEST_F(AidlPowerHalWrapperTest, sendActualWorkDuration_shouldReconnectOnError) { - ASSERT_TRUE(mWrapper->supportsPowerHintSession()); - - std::vector<int32_t> threadIds = {1, 2}; - mWrapper->setPowerHintSessionThreadIds(threadIds); - EXPECT_CALL(*mMockHal.get(), createHintSession(_, _, threadIds, _, _)) - .WillOnce(DoAll(SetArgPointee<4>(mMockSession), Return(Status::ok()))); - ASSERT_TRUE(mWrapper->startPowerHintSession()); - verifyAndClearExpectations(); - WorkDuration duration; - duration.durationNanos = 1; - EXPECT_CALL(*mMockSession.get(), reportActualWorkDuration(_)) - .WillOnce(Return(Status::fromExceptionCode(Status::Exception::EX_ILLEGAL_STATE))); - sendActualWorkDurationGroup({duration}); - EXPECT_TRUE(mWrapper->shouldReconnectHAL()); -} - -} // namespace -} // namespace android::Hwc2::impl diff --git a/services/surfaceflinger/tests/unittests/Android.bp b/services/surfaceflinger/tests/unittests/Android.bp index df3ffd288c..201d37ff7e 100644 --- a/services/surfaceflinger/tests/unittests/Android.bp +++ b/services/surfaceflinger/tests/unittests/Android.bp @@ -24,7 +24,7 @@ package { filegroup { name: "libsurfaceflinger_mock_sources", srcs: [ - "mock/DisplayHardware/MockAidlPowerHalWrapper.cpp", + "mock/DisplayHardware/MockPowerHalController.cpp", "mock/DisplayHardware/MockComposer.cpp", "mock/DisplayHardware/MockHWC2.cpp", "mock/DisplayHardware/MockIPower.cpp", @@ -70,7 +70,6 @@ cc_test { ":libsurfaceflinger_mock_sources", ":libsurfaceflinger_sources", "libsurfaceflinger_unittest_main.cpp", - "AidlPowerHalWrapperTest.cpp", "CompositionTest.cpp", "DisplayIdGeneratorTest.cpp", "DisplayTransactionTest.cpp", @@ -196,6 +195,7 @@ cc_defaults { "libinput", "liblog", "libnativewindow", + "libpowermanager", "libprocessgroup", "libprotobuf-cpp-lite", "libSurfaceFlingerProp", diff --git a/services/surfaceflinger/tests/unittests/LayerHierarchyTest.h b/services/surfaceflinger/tests/unittests/LayerHierarchyTest.h index 5b3c7efe92..79cfd6a891 100644 --- a/services/surfaceflinger/tests/unittests/LayerHierarchyTest.h +++ b/services/surfaceflinger/tests/unittests/LayerHierarchyTest.h @@ -278,6 +278,25 @@ protected: mLifecycleManager.applyTransactions(transactions); } + void setTouchableRegionCrop(uint32_t id, Region region, uint32_t touchCropId, + bool replaceTouchableRegionWithCrop) { + std::vector<TransactionState> transactions; + transactions.emplace_back(); + transactions.back().states.push_back({}); + + transactions.back().states.front().state.what = layer_state_t::eInputInfoChanged; + transactions.back().states.front().layerId = id; + transactions.back().states.front().state.windowInfoHandle = + sp<gui::WindowInfoHandle>::make(); + auto inputInfo = transactions.back().states.front().state.windowInfoHandle->editInfo(); + inputInfo->touchableRegion = region; + inputInfo->replaceTouchableRegionWithCrop = replaceTouchableRegionWithCrop; + transactions.back().states.front().touchCropId = touchCropId; + + inputInfo->token = sp<BBinder>::make(); + mLifecycleManager.applyTransactions(transactions); + } + LayerLifecycleManager mLifecycleManager; }; diff --git a/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp b/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp index b8c47817ca..5a066a6482 100644 --- a/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp +++ b/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp @@ -308,6 +308,31 @@ TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotes) { EXPECT_EQ(getSnapshot(1)->frameRate.type, scheduler::LayerInfo::FrameRateCompatibility::NoVote); } +TEST_F(LayerSnapshotTest, canCropTouchableRegion) { + // ROOT + // ├── 1 + // │ ├── 11 + // │ │ └── 111 (touchregion set to touch but cropped by layer 13) + // │ ├── 12 + // │ │ ├── 121 + // │ │ └── 122 + // │ │ └── 1221 + // │ └── 13 (crop set to touchCrop) + // └── 2 + + Rect touchCrop{300, 300, 400, 500}; + setCrop(13, touchCrop); + Region touch{Rect{0, 0, 1000, 1000}}; + setTouchableRegionCrop(111, touch, /*touchCropId=*/13, /*replaceTouchableRegionWithCrop=*/true); + UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); + EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), touchCrop); + + Rect modifiedTouchCrop{100, 300, 400, 700}; + setCrop(13, modifiedTouchCrop); + UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); + EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), modifiedTouchCrop); +} + // Display Mirroring Tests // tree with 3 levels of children // ROOT (DISPLAY 0) diff --git a/services/surfaceflinger/tests/unittests/PowerAdvisorTest.cpp b/services/surfaceflinger/tests/unittests/PowerAdvisorTest.cpp index 2d66d3cf92..0d66d59f26 100644 --- a/services/surfaceflinger/tests/unittests/PowerAdvisorTest.cpp +++ b/services/surfaceflinger/tests/unittests/PowerAdvisorTest.cpp @@ -25,13 +25,15 @@ #include <ui/DisplayId.h> #include <chrono> #include "TestableSurfaceFlinger.h" -#include "mock/DisplayHardware/MockAidlPowerHalWrapper.h" +#include "mock/DisplayHardware/MockIPowerHintSession.h" +#include "mock/DisplayHardware/MockPowerHalController.h" using namespace android; using namespace android::Hwc2::mock; using namespace android::hardware::power; using namespace std::chrono_literals; using namespace testing; +using namespace android::power; namespace android::Hwc2::impl { @@ -42,28 +44,32 @@ public: void fakeBasicFrameTiming(TimePoint startTime, Duration vsyncPeriod); void setExpectedTiming(Duration totalFrameTargetDuration, TimePoint expectedPresentTime); Duration getFenceWaitDelayDuration(bool skipValidate); + Duration getErrorMargin(); protected: TestableSurfaceFlinger mFlinger; std::unique_ptr<PowerAdvisor> mPowerAdvisor; - NiceMock<MockAidlPowerHalWrapper>* mMockAidlWrapper; - Duration kErrorMargin = 1ms; + MockPowerHalController* mMockPowerHalController; + sp<MockIPowerHintSession> mMockPowerHintSession; }; -void PowerAdvisorTest::SetUp() FTL_FAKE_GUARD(mPowerAdvisor->mPowerHalMutex) { - std::unique_ptr<MockAidlPowerHalWrapper> mockAidlWrapper = - std::make_unique<NiceMock<MockAidlPowerHalWrapper>>(); - mPowerAdvisor = std::make_unique<PowerAdvisor>(*mFlinger.flinger()); - ON_CALL(*mockAidlWrapper.get(), supportsPowerHintSession()).WillByDefault(Return(true)); - ON_CALL(*mockAidlWrapper.get(), startPowerHintSession()).WillByDefault(Return(true)); - mPowerAdvisor->mHalWrapper = std::move(mockAidlWrapper); - mMockAidlWrapper = - reinterpret_cast<NiceMock<MockAidlPowerHalWrapper>*>(mPowerAdvisor->mHalWrapper.get()); +void PowerAdvisorTest::SetUp() { + mPowerAdvisor = std::make_unique<impl::PowerAdvisor>(*mFlinger.flinger()); + mPowerAdvisor->mPowerHal = std::make_unique<NiceMock<MockPowerHalController>>(); + mMockPowerHalController = + reinterpret_cast<MockPowerHalController*>(mPowerAdvisor->mPowerHal.get()); + ON_CALL(*mMockPowerHalController, getHintSessionPreferredRate) + .WillByDefault(Return(HalResult<int64_t>::fromStatus(binder::Status::ok(), 16000))); } void PowerAdvisorTest::startPowerHintSession() { const std::vector<int32_t> threadIds = {1, 2, 3}; - mPowerAdvisor->enablePowerHint(true); + mMockPowerHintSession = android::sp<NiceMock<MockIPowerHintSession>>::make(); + ON_CALL(*mMockPowerHalController, createHintSession) + .WillByDefault( + Return(HalResult<sp<IPowerHintSession>>::fromStatus(binder::Status::ok(), + mMockPowerHintSession))); + mPowerAdvisor->enablePowerHintSession(true); mPowerAdvisor->startPowerHintSession(threadIds); } @@ -76,7 +82,7 @@ void PowerAdvisorTest::setExpectedTiming(Duration totalFrameTargetDuration, void PowerAdvisorTest::fakeBasicFrameTiming(TimePoint startTime, Duration vsyncPeriod) { mPowerAdvisor->setCommitStart(startTime); mPowerAdvisor->setFrameDelay(0ns); - mPowerAdvisor->setTargetWorkDuration(vsyncPeriod); + mPowerAdvisor->updateTargetWorkDuration(vsyncPeriod); } Duration PowerAdvisorTest::getFenceWaitDelayDuration(bool skipValidate) { @@ -84,6 +90,10 @@ Duration PowerAdvisorTest::getFenceWaitDelayDuration(bool skipValidate) { : PowerAdvisor::kFenceWaitStartDelayValidated); } +Duration PowerAdvisorTest::getErrorMargin() { + return mPowerAdvisor->sTargetSafetyMargin; +} + namespace { TEST_F(PowerAdvisorTest, hintSessionUseHwcDisplay) { @@ -109,8 +119,11 @@ TEST_F(PowerAdvisorTest, hintSessionUseHwcDisplay) { // increment the frame startTime += vsyncPeriod; - const Duration expectedDuration = kErrorMargin + presentDuration + postCompDuration; - EXPECT_CALL(*mMockAidlWrapper, sendActualWorkDuration(Eq(expectedDuration), _)).Times(1); + const Duration expectedDuration = getErrorMargin() + presentDuration + postCompDuration; + EXPECT_CALL(*mMockPowerHintSession, + reportActualWorkDuration(ElementsAre( + Field(&WorkDuration::durationNanos, Eq(expectedDuration.ns()))))) + .Times(1); fakeBasicFrameTiming(startTime, vsyncPeriod); setExpectedTiming(vsyncPeriod, startTime + vsyncPeriod); @@ -118,7 +131,7 @@ TEST_F(PowerAdvisorTest, hintSessionUseHwcDisplay) { mPowerAdvisor->setHwcValidateTiming(displayIds[0], startTime + 1ms, startTime + 1500us); mPowerAdvisor->setHwcPresentTiming(displayIds[0], startTime + 2ms, startTime + 2500us); mPowerAdvisor->setSfPresentTiming(startTime, startTime + presentDuration); - mPowerAdvisor->sendActualWorkDuration(); + mPowerAdvisor->reportActualWorkDuration(); } TEST_F(PowerAdvisorTest, hintSessionSubtractsHwcFenceTime) { @@ -145,9 +158,12 @@ TEST_F(PowerAdvisorTest, hintSessionSubtractsHwcFenceTime) { // increment the frame startTime += vsyncPeriod; - const Duration expectedDuration = kErrorMargin + presentDuration + + const Duration expectedDuration = getErrorMargin() + presentDuration + getFenceWaitDelayDuration(false) - hwcBlockedDuration + postCompDuration; - EXPECT_CALL(*mMockAidlWrapper, sendActualWorkDuration(Eq(expectedDuration), _)).Times(1); + EXPECT_CALL(*mMockPowerHintSession, + reportActualWorkDuration(ElementsAre( + Field(&WorkDuration::durationNanos, Eq(expectedDuration.ns()))))) + .Times(1); fakeBasicFrameTiming(startTime, vsyncPeriod); setExpectedTiming(vsyncPeriod, startTime + vsyncPeriod); @@ -157,7 +173,7 @@ TEST_F(PowerAdvisorTest, hintSessionSubtractsHwcFenceTime) { // now report the fence as having fired during the display HWC time mPowerAdvisor->setSfPresentTiming(startTime + 2ms + hwcBlockedDuration, startTime + presentDuration); - mPowerAdvisor->sendActualWorkDuration(); + mPowerAdvisor->reportActualWorkDuration(); } TEST_F(PowerAdvisorTest, hintSessionUsingSecondaryVirtualDisplays) { @@ -185,8 +201,11 @@ TEST_F(PowerAdvisorTest, hintSessionUsingSecondaryVirtualDisplays) { // increment the frame startTime += vsyncPeriod; - const Duration expectedDuration = kErrorMargin + presentDuration + postCompDuration; - EXPECT_CALL(*mMockAidlWrapper, sendActualWorkDuration(Eq(expectedDuration), _)).Times(1); + const Duration expectedDuration = getErrorMargin() + presentDuration + postCompDuration; + EXPECT_CALL(*mMockPowerHintSession, + reportActualWorkDuration(ElementsAre( + Field(&WorkDuration::durationNanos, Eq(expectedDuration.ns()))))) + .Times(1); fakeBasicFrameTiming(startTime, vsyncPeriod); setExpectedTiming(vsyncPeriod, startTime + vsyncPeriod); @@ -196,7 +215,7 @@ TEST_F(PowerAdvisorTest, hintSessionUsingSecondaryVirtualDisplays) { mPowerAdvisor->setHwcValidateTiming(displayIds[0], startTime + 1ms, startTime + 1500us); mPowerAdvisor->setHwcPresentTiming(displayIds[0], startTime + 2ms, startTime + 2500us); mPowerAdvisor->setSfPresentTiming(startTime, startTime + presentDuration); - mPowerAdvisor->sendActualWorkDuration(); + mPowerAdvisor->reportActualWorkDuration(); } } // namespace diff --git a/services/surfaceflinger/tests/unittests/RefreshRateSelectorTest.cpp b/services/surfaceflinger/tests/unittests/RefreshRateSelectorTest.cpp index 63ed87b846..d63e187ac4 100644 --- a/services/surfaceflinger/tests/unittests/RefreshRateSelectorTest.cpp +++ b/services/surfaceflinger/tests/unittests/RefreshRateSelectorTest.cpp @@ -3026,5 +3026,21 @@ TEST_P(RefreshRateSelectorTest, frameRateIsCappedByPolicy) { EXPECT_FRAME_RATE_MODE(kMode60, 30_Hz, selector.getBestScoredFrameRate(layers).frameRateMode); } +TEST_P(RefreshRateSelectorTest, frameRateNotInRange) { + auto selector = createSelector(kModes_60_90, kModeId60); + + constexpr FpsRanges k60Only = {{60_Hz, 90_Hz}, {60_Hz, 60_Hz}}; + constexpr FpsRanges kAll = {{0_Hz, 90_Hz}, {0_Hz, 90_Hz}}; + + EXPECT_EQ(SetPolicyResult::Changed, + selector.setDisplayManagerPolicy({DisplayModeId(kModeId60), k60Only, kAll})); + + std::vector<LayerRequirement> layers = {{.weight = 1.f}}; + layers[0].name = "Test layer"; + layers[0].vote = LayerVoteType::Heuristic; + layers[0].desiredRefreshRate = 45_Hz; + EXPECT_FRAME_RATE_MODE(kMode60, 60_Hz, selector.getBestScoredFrameRate(layers).frameRateMode); +} + } // namespace } // namespace android::scheduler diff --git a/services/surfaceflinger/tests/unittests/SurfaceFlinger_PowerHintTest.cpp b/services/surfaceflinger/tests/unittests/SurfaceFlinger_PowerHintTest.cpp index 7839ef0dbb..d0290ea03e 100644 --- a/services/surfaceflinger/tests/unittests/SurfaceFlinger_PowerHintTest.cpp +++ b/services/surfaceflinger/tests/unittests/SurfaceFlinger_PowerHintTest.cpp @@ -70,7 +70,6 @@ void SurfaceFlingerPowerHintTest::SetUp() { mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine)); mFlinger.setupTimeStats(std::shared_ptr<TimeStats>(mTimeStats)); mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); - mFlinger.setPowerHintSessionMode(true, true); mFlinger.setupPowerAdvisor(std::unique_ptr<Hwc2::PowerAdvisor>(mPowerAdvisor)); static constexpr bool kIsPrimary = true; FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, hal::DisplayType::PHYSICAL, kIsPrimary) @@ -100,7 +99,7 @@ void SurfaceFlingerPowerHintTest::SetUp() { TEST_F(SurfaceFlingerPowerHintTest, sendDurationsIncludingHwcWaitTime) { ON_CALL(*mPowerAdvisor, usePowerHintSession()).WillByDefault(Return(true)); - EXPECT_CALL(*mPowerAdvisor, setTargetWorkDuration(_)).Times(1); + EXPECT_CALL(*mPowerAdvisor, updateTargetWorkDuration(_)).Times(1); EXPECT_CALL(*mDisplaySurface, prepareFrame(compositionengine::DisplaySurface::CompositionType::Hwc)) .Times(1); @@ -109,7 +108,7 @@ TEST_F(SurfaceFlingerPowerHintTest, sendDurationsIncludingHwcWaitTime) { std::this_thread::sleep_for(kMockHwcRunTime); return hardware::graphics::composer::V2_1::Error::NONE; }); - EXPECT_CALL(*mPowerAdvisor, sendActualWorkDuration()).Times(1); + EXPECT_CALL(*mPowerAdvisor, reportActualWorkDuration()).Times(1); const TimePoint frameTime = scheduler::SchedulerClock::now(); constexpr Period kMockVsyncPeriod = 15ms; @@ -121,7 +120,7 @@ TEST_F(SurfaceFlingerPowerHintTest, inactiveOnDisplayDoze) { mDisplay->setPowerMode(hal::PowerMode::DOZE); - EXPECT_CALL(*mPowerAdvisor, setTargetWorkDuration(_)).Times(0); + EXPECT_CALL(*mPowerAdvisor, updateTargetWorkDuration(_)).Times(0); EXPECT_CALL(*mDisplaySurface, prepareFrame(compositionengine::DisplaySurface::CompositionType::Hwc)) .Times(1); @@ -130,7 +129,7 @@ TEST_F(SurfaceFlingerPowerHintTest, inactiveOnDisplayDoze) { std::this_thread::sleep_for(kMockHwcRunTime); return hardware::graphics::composer::V2_1::Error::NONE; }); - EXPECT_CALL(*mPowerAdvisor, sendActualWorkDuration()).Times(0); + EXPECT_CALL(*mPowerAdvisor, reportActualWorkDuration()).Times(0); const TimePoint frameTime = scheduler::SchedulerClock::now(); constexpr Period kMockVsyncPeriod = 15ms; diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h index 89a190e9ea..6f48df8be2 100644 --- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h +++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h @@ -344,10 +344,6 @@ public: layer->mDrawingParent = drawingParent; } - void setPowerHintSessionMode(bool early, bool late) { - mFlinger->mPowerHintSessionMode = {.late = late, .early = early}; - } - /* ------------------------------------------------------------------------ * Forwarding for functions being tested */ diff --git a/services/surfaceflinger/tests/unittests/TransactionProtoParserTest.cpp b/services/surfaceflinger/tests/unittests/TransactionProtoParserTest.cpp index 3dea189ca0..dd72174a37 100644 --- a/services/surfaceflinger/tests/unittests/TransactionProtoParserTest.cpp +++ b/services/surfaceflinger/tests/unittests/TransactionProtoParserTest.cpp @@ -19,6 +19,7 @@ #include <limits> // std::numeric_limits #include <gui/SurfaceComposerClient.h> +#include <ui/Rotation.h> #include "LayerProtoHelper.h" #include "Tracing/TransactionProtoParser.h" @@ -103,4 +104,48 @@ TEST(TransactionProtoParserTest, parse) { ASSERT_EQ(t1.displays[0].token, t2.displays[0].token); } +TEST(TransactionProtoParserTest, parseDisplayInfo) { + frontend::DisplayInfo d1; + d1.info.displayId = 42; + d1.info.logicalWidth = 43; + d1.info.logicalHeight = 44; + d1.info.transform.set(1, 2, 3, 4); + d1.transform = d1.info.transform.inverse(); + d1.receivesInput = true; + d1.isSecure = false; + d1.isPrimary = true; + d1.isVirtual = false; + d1.rotationFlags = ui::Transform::ROT_180; + d1.transformHint = ui::Transform::ROT_90; + + const uint32_t layerStack = 2; + google::protobuf::RepeatedPtrField<proto::DisplayInfo> displayProtos; + auto displayInfoProto = displayProtos.Add(); + *displayInfoProto = TransactionProtoParser::toProto(d1, layerStack); + display::DisplayMap<ui::LayerStack, frontend::DisplayInfo> displayInfos; + TransactionProtoParser::fromProto(displayProtos, displayInfos); + + ASSERT_TRUE(displayInfos.contains(ui::LayerStack::fromValue(layerStack))); + frontend::DisplayInfo d2 = displayInfos.get(ui::LayerStack::fromValue(layerStack))->get(); + EXPECT_EQ(d1.info.displayId, d2.info.displayId); + EXPECT_EQ(d1.info.logicalWidth, d2.info.logicalWidth); + EXPECT_EQ(d1.info.logicalHeight, d2.info.logicalHeight); + + EXPECT_EQ(d1.info.transform.dsdx(), d2.info.transform.dsdx()); + EXPECT_EQ(d1.info.transform.dsdy(), d2.info.transform.dsdy()); + EXPECT_EQ(d1.info.transform.dtdx(), d2.info.transform.dtdx()); + EXPECT_EQ(d1.info.transform.dtdy(), d2.info.transform.dtdy()); + + EXPECT_EQ(d1.transform.dsdx(), d2.transform.dsdx()); + EXPECT_EQ(d1.transform.dsdy(), d2.transform.dsdy()); + EXPECT_EQ(d1.transform.dtdx(), d2.transform.dtdx()); + EXPECT_EQ(d1.transform.dtdy(), d2.transform.dtdy()); + + EXPECT_EQ(d1.receivesInput, d2.receivesInput); + EXPECT_EQ(d1.isSecure, d2.isSecure); + EXPECT_EQ(d1.isVirtual, d2.isVirtual); + EXPECT_EQ(d1.rotationFlags, d2.rotationFlags); + EXPECT_EQ(d1.transformHint, d2.transformHint); +} + } // namespace android diff --git a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockAidlPowerHalWrapper.h b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockAidlPowerHalWrapper.h deleted file mode 100644 index 5654691884..0000000000 --- a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockAidlPowerHalWrapper.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include <gmock/gmock.h> -#include <scheduler/Time.h> - -#include "DisplayHardware/PowerAdvisor.h" - -namespace android { -namespace hardware { -namespace power { -class IPower; -} -} // namespace hardware -} // namespace android - -namespace android::Hwc2::mock { - -class MockAidlPowerHalWrapper : public Hwc2::impl::AidlPowerHalWrapper { -public: - MockAidlPowerHalWrapper(); - ~MockAidlPowerHalWrapper() override; - MOCK_METHOD(bool, setExpensiveRendering, (bool enabled), (override)); - MOCK_METHOD(bool, notifyDisplayUpdateImminentAndCpuReset, (), (override)); - MOCK_METHOD(bool, supportsPowerHintSession, (), (override)); - MOCK_METHOD(bool, isPowerHintSessionRunning, (), (override)); - MOCK_METHOD(void, restartPowerHintSession, (), (override)); - MOCK_METHOD(void, setPowerHintSessionThreadIds, (const std::vector<int32_t>& threadIds), - (override)); - MOCK_METHOD(bool, startPowerHintSession, (), (override)); - MOCK_METHOD(void, setTargetWorkDuration, (Duration targetDuration), (override)); - MOCK_METHOD(void, sendActualWorkDuration, (Duration actualDuration, TimePoint timestamp), - (override)); - MOCK_METHOD(bool, shouldReconnectHAL, (), (override)); -}; - -} // namespace android::Hwc2::mock
\ No newline at end of file diff --git a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockPowerAdvisor.h b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockPowerAdvisor.h index 7fc625c4b6..3caa2b9847 100644 --- a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockPowerAdvisor.h +++ b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockPowerAdvisor.h @@ -35,11 +35,10 @@ public: MOCK_METHOD(void, notifyDisplayUpdateImminentAndCpuReset, (), (override)); MOCK_METHOD(bool, usePowerHintSession, (), (override)); MOCK_METHOD(bool, supportsPowerHintSession, (), (override)); - MOCK_METHOD(bool, isPowerHintSessionRunning, (), (override)); - MOCK_METHOD(void, setTargetWorkDuration, (Duration targetDuration), (override)); - MOCK_METHOD(void, sendActualWorkDuration, (), (override)); - MOCK_METHOD(void, sendPredictedWorkDuration, (), (override)); - MOCK_METHOD(void, enablePowerHint, (bool enabled), (override)); + MOCK_METHOD(bool, ensurePowerHintSessionRunning, (), (override)); + MOCK_METHOD(void, updateTargetWorkDuration, (Duration targetDuration), (override)); + MOCK_METHOD(void, reportActualWorkDuration, (), (override)); + MOCK_METHOD(void, enablePowerHintSession, (bool enabled), (override)); MOCK_METHOD(bool, startPowerHintSession, (const std::vector<int32_t>& threadIds), (override)); MOCK_METHOD(void, setGpuFenceTime, (DisplayId displayId, std::unique_ptr<FenceTime>&& fenceTime), (override)); diff --git a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockAidlPowerHalWrapper.cpp b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockPowerHalController.cpp index 5049b1d367..3ec5c2d09b 100644 --- a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockAidlPowerHalWrapper.cpp +++ b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockPowerHalController.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 The Android Open Source Project + * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,11 @@ * limitations under the License. */ -#include "MockAidlPowerHalWrapper.h" -#include "MockIPower.h" +#include "MockPowerHalController.h" namespace android::Hwc2::mock { -MockAidlPowerHalWrapper::MockAidlPowerHalWrapper() - : AidlPowerHalWrapper(sp<testing::NiceMock<MockIPower>>::make()){}; -MockAidlPowerHalWrapper::~MockAidlPowerHalWrapper() = default; +MockPowerHalController::MockPowerHalController() = default; +MockPowerHalController::~MockPowerHalController() = default; } // namespace android::Hwc2::mock diff --git a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockPowerHalController.h b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockPowerHalController.h new file mode 100644 index 0000000000..358395d323 --- /dev/null +++ b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockPowerHalController.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include <gmock/gmock.h> +#include <scheduler/Time.h> + +#include <powermanager/PowerHalController.h> + +namespace android { +namespace hardware { +namespace power { +class IPower; +} +} // namespace hardware +} // namespace android + +namespace android::Hwc2::mock { + +using android::hardware::power::Boost; +using android::hardware::power::Mode; +using android::power::HalResult; + +class MockPowerHalController : public power::PowerHalController { +public: + MockPowerHalController(); + ~MockPowerHalController() override; + MOCK_METHOD(HalResult<void>, setBoost, (Boost, int32_t), (override)); + MOCK_METHOD(HalResult<void>, setMode, (Mode, bool), (override)); + MOCK_METHOD(HalResult<sp<hardware::power::IPowerHintSession>>, createHintSession, + (int32_t, int32_t, const std::vector<int32_t>&, int64_t), (override)); + MOCK_METHOD(HalResult<int64_t>, getHintSessionPreferredRate, (), (override)); +}; + +} // namespace android::Hwc2::mock
\ No newline at end of file |