diff options
author | 2020-07-22 12:07:12 -0700 | |
---|---|---|
committer | 2020-07-28 18:01:10 -0700 | |
commit | 6c4243bfedc2ad66c92a7bc470be1470cf99b2f7 (patch) | |
tree | 633879c0c5b9236f14f295823e9e0e9faf914799 | |
parent | 30cb610116c678d5c03e3e2113fd02d67c631691 (diff) |
Use AIDL compiler to generate InputApplicationInfo class.
Define parcelable structure in AIDL file to skip manual code of parcel
read and write.
Bug: 160178917
Test: atest libinput_tests
Change-Id: Ic7a5a0b383fdb5784b9b8cdb0ee5acce30b89223
-rw-r--r-- | include/input/InputApplication.h | 24 | ||||
-rw-r--r-- | libs/gui/tests/EndToEndNativeInputTest.cpp | 3 | ||||
-rw-r--r-- | libs/input/Android.bp | 2 | ||||
-rw-r--r-- | libs/input/InputApplication.cpp | 55 | ||||
-rw-r--r-- | libs/input/InputWindow.cpp | 14 | ||||
-rw-r--r-- | libs/input/android/InputApplicationInfo.aidl | 23 | ||||
-rw-r--r-- | libs/input/tests/InputWindow_test.cpp | 18 | ||||
-rw-r--r-- | services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp | 2 | ||||
-rw-r--r-- | services/inputflinger/tests/InputDispatcher_test.cpp | 4 | ||||
-rw-r--r-- | services/inputflinger/tests/InputFlingerService_test.cpp | 2 |
10 files changed, 59 insertions, 88 deletions
diff --git a/include/input/InputApplication.h b/include/input/InputApplication.h index b6b935329b..d01d2d458f 100644 --- a/include/input/InputApplication.h +++ b/include/input/InputApplication.h @@ -19,6 +19,8 @@ #include <string> +#include <android/InputApplicationInfo.h> + #include <binder/IBinder.h> #include <binder/Parcel.h> #include <binder/Parcelable.h> @@ -28,22 +30,6 @@ #include <utils/Timers.h> namespace android { - -/* - * Describes the properties of an application that can receive input. - */ -struct InputApplicationInfo : public Parcelable { - sp<IBinder> token; - std::string name; - std::chrono::nanoseconds dispatchingTimeout; - - InputApplicationInfo() = default; - - status_t readFromParcel(const android::Parcel* parcel) override; - - status_t writeToParcel(android::Parcel* parcel) const override; -}; - /* * Handle for an application that can receive input. * @@ -62,7 +48,7 @@ public: inline std::chrono::nanoseconds getDispatchingTimeout( std::chrono::nanoseconds defaultValue) const { - return mInfo.token ? std::chrono::nanoseconds(mInfo.dispatchingTimeout) : defaultValue; + return mInfo.token ? std::chrono::nanoseconds(mInfo.dispatchingTimeoutNanos) : defaultValue; } inline sp<IBinder> getApplicationToken() const { @@ -81,8 +67,8 @@ public: virtual bool updateInfo() = 0; protected: - InputApplicationHandle(); - virtual ~InputApplicationHandle(); + InputApplicationHandle() = default; + virtual ~InputApplicationHandle() = default; InputApplicationInfo mInfo; }; diff --git a/libs/gui/tests/EndToEndNativeInputTest.cpp b/libs/gui/tests/EndToEndNativeInputTest.cpp index cca8dddfe6..5b429d00c1 100644 --- a/libs/gui/tests/EndToEndNativeInputTest.cpp +++ b/libs/gui/tests/EndToEndNativeInputTest.cpp @@ -63,6 +63,7 @@ sp<IInputFlinger> getInputFlinger() { // We use the top 10 layers as a way to haphazardly place ourselves above anything else. static const int LAYER_BASE = INT32_MAX - 10; +static constexpr std::chrono::nanoseconds DISPATCHING_TIMEOUT = 5s; class InputSurface { public: @@ -206,7 +207,7 @@ private: InputApplicationInfo aInfo; aInfo.token = new BBinder(); aInfo.name = "Test app info"; - aInfo.dispatchingTimeout = 5s; + aInfo.dispatchingTimeoutNanos = DISPATCHING_TIMEOUT.count(); mInputInfo.applicationInfo = aInfo; } diff --git a/libs/input/Android.bp b/libs/input/Android.bp index 7dd5276958..180700db0b 100644 --- a/libs/input/Android.bp +++ b/libs/input/Android.bp @@ -54,13 +54,13 @@ cc_library { target: { android: { srcs: [ - "InputApplication.cpp", "InputTransport.cpp", "InputWindow.cpp", "LatencyStatistics.cpp", "VelocityControl.cpp", "VelocityTracker.cpp", "android/FocusRequest.aidl", + "android/InputApplicationInfo.aidl", "android/os/IInputFlinger.aidl", "android/os/ISetInputWindowsListener.aidl", ], diff --git a/libs/input/InputApplication.cpp b/libs/input/InputApplication.cpp deleted file mode 100644 index 41721a7344..0000000000 --- a/libs/input/InputApplication.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2011 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. - */ - -#define LOG_TAG "InputApplication" - -#include <input/InputApplication.h> - -#include <android/log.h> - -namespace android { - -status_t InputApplicationInfo::readFromParcel(const android::Parcel* parcel) { - if (parcel == nullptr) { - ALOGE("%s: Null parcel", __func__); - return BAD_VALUE; - } - token = parcel->readStrongBinder(); - dispatchingTimeout = decltype(dispatchingTimeout)(parcel->readInt64()); - status_t status = parcel->readUtf8FromUtf16(&name); - - return status; -} - -status_t InputApplicationInfo::writeToParcel(android::Parcel* parcel) const { - if (parcel == nullptr) { - ALOGE("%s: Null parcel", __func__); - return BAD_VALUE; - } - status_t status = parcel->writeStrongBinder(token) - ?: parcel->writeInt64(dispatchingTimeout.count()) - ?: parcel->writeUtf8AsUtf16(name) ; - - return status; -} - -// --- InputApplicationHandle --- - -InputApplicationHandle::InputApplicationHandle() {} - -InputApplicationHandle::~InputApplicationHandle() {} - -} // namespace android diff --git a/libs/input/InputWindow.cpp b/libs/input/InputWindow.cpp index 51190a0451..6db9ed5148 100644 --- a/libs/input/InputWindow.cpp +++ b/libs/input/InputWindow.cpp @@ -57,17 +57,15 @@ bool InputWindowInfo::operator==(const InputWindowInfo& info) const { info.frameLeft == frameLeft && info.frameTop == frameTop && info.frameRight == frameRight && info.frameBottom == frameBottom && info.surfaceInset == surfaceInset && info.globalScaleFactor == globalScaleFactor && - info.transform == transform && - info.touchableRegion.hasSameRects(touchableRegion) && info.visible == visible && - info.canReceiveKeys == canReceiveKeys && info.trustedOverlay == trustedOverlay && - info.hasFocus == hasFocus && info.hasWallpaper == hasWallpaper && - info.paused == paused && info.ownerPid == ownerPid && info.ownerUid == ownerUid && + info.transform == transform && info.touchableRegion.hasSameRects(touchableRegion) && + info.visible == visible && info.canReceiveKeys == canReceiveKeys && + info.trustedOverlay == trustedOverlay && info.hasFocus == hasFocus && + info.hasWallpaper == hasWallpaper && info.paused == paused && + info.ownerPid == ownerPid && info.ownerUid == ownerUid && info.inputFeatures == inputFeatures && info.displayId == displayId && info.portalToDisplayId == portalToDisplayId && info.replaceTouchableRegionWithCrop == replaceTouchableRegionWithCrop && - info.applicationInfo.name == applicationInfo.name && - info.applicationInfo.token == applicationInfo.token && - info.applicationInfo.dispatchingTimeout == applicationInfo.dispatchingTimeout; + info.applicationInfo == applicationInfo; } status_t InputWindowInfo::writeToParcel(android::Parcel* parcel) const { diff --git a/libs/input/android/InputApplicationInfo.aidl b/libs/input/android/InputApplicationInfo.aidl new file mode 100644 index 0000000000..d1161e1b12 --- /dev/null +++ b/libs/input/android/InputApplicationInfo.aidl @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2020, 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. + */ + +package android; + +parcelable InputApplicationInfo { + @nullable IBinder token; + @utf8InCpp String name; + long dispatchingTimeoutNanos; +} diff --git a/libs/input/tests/InputWindow_test.cpp b/libs/input/tests/InputWindow_test.cpp index 1b5846023c..052222e428 100644 --- a/libs/input/tests/InputWindow_test.cpp +++ b/libs/input/tests/InputWindow_test.cpp @@ -66,6 +66,9 @@ TEST(InputWindowInfo, Parcelling) { i.portalToDisplayId = 2; i.replaceTouchableRegionWithCrop = true; i.touchableRegionCropHandle = touchableRegionCropHandle; + i.applicationInfo.name = "ApplicationFooBar"; + i.applicationInfo.token = new BBinder(); + i.applicationInfo.dispatchingTimeoutNanos = 0x12345678ABCD; Parcel p; i.writeToParcel(&p); @@ -97,6 +100,21 @@ TEST(InputWindowInfo, Parcelling) { ASSERT_EQ(i.portalToDisplayId, i2.portalToDisplayId); ASSERT_EQ(i.replaceTouchableRegionWithCrop, i2.replaceTouchableRegionWithCrop); ASSERT_EQ(i.touchableRegionCropHandle, i2.touchableRegionCropHandle); + ASSERT_EQ(i.applicationInfo, i2.applicationInfo); +} + +TEST(InputApplicationInfo, Parcelling) { + InputApplicationInfo i; + i.token = new BBinder(); + i.name = "ApplicationFooBar"; + i.dispatchingTimeoutNanos = 0x12345678ABCD; + + Parcel p; + ASSERT_EQ(i.writeToParcel(&p), OK); + p.setDataPosition(0); + InputApplicationInfo i2; + ASSERT_EQ(i2.readFromParcel(&p), OK); + ASSERT_EQ(i, i2); } } // namespace test diff --git a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp index 4e4af7e1e7..5ce9f23e82 100644 --- a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp +++ b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp @@ -94,7 +94,7 @@ public: virtual ~FakeApplicationHandle() {} virtual bool updateInfo() { - mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT; + mInfo.dispatchingTimeoutNanos = DISPATCHING_TIMEOUT.count(); return true; } }; diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index 296201d8e0..86d62d74ca 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -583,7 +583,7 @@ public: FakeApplicationHandle() { mInfo.name = "Fake Application"; mInfo.token = new BBinder(); - mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT; + mInfo.dispatchingTimeoutNanos = DISPATCHING_TIMEOUT.count(); } virtual ~FakeApplicationHandle() {} @@ -592,7 +592,7 @@ public: } void setDispatchingTimeout(std::chrono::nanoseconds timeout) { - mInfo.dispatchingTimeout = timeout; + mInfo.dispatchingTimeoutNanos = timeout.count(); } }; diff --git a/services/inputflinger/tests/InputFlingerService_test.cpp b/services/inputflinger/tests/InputFlingerService_test.cpp index 02342c0fea..87e0fb5a3d 100644 --- a/services/inputflinger/tests/InputFlingerService_test.cpp +++ b/services/inputflinger/tests/InputFlingerService_test.cpp @@ -310,7 +310,7 @@ void InputFlingerServiceTest::SetUp() { mInfo.applicationInfo.name = TestAppInfoName; mInfo.applicationInfo.token = TestAppInfoToken; - mInfo.applicationInfo.dispatchingTimeout = TestAppInfoDispatchingTimeout; + mInfo.applicationInfo.dispatchingTimeoutNanos = TestAppInfoDispatchingTimeout.count(); InitializeInputFlinger(); } |