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
diff --git a/include/input/InputApplication.h b/include/input/InputApplication.h
index b6b9353..d01d2d4 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 @@
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 @@
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 cca8ddd..5b429d0 100644
--- a/libs/gui/tests/EndToEndNativeInputTest.cpp
+++ b/libs/gui/tests/EndToEndNativeInputTest.cpp
@@ -63,6 +63,7 @@
// 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 @@
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 7dd5276..180700d 100644
--- a/libs/input/Android.bp
+++ b/libs/input/Android.bp
@@ -54,13 +54,13 @@
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 41721a7..0000000
--- 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 51190a0..6db9ed5 100644
--- a/libs/input/InputWindow.cpp
+++ b/libs/input/InputWindow.cpp
@@ -57,17 +57,15 @@
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 0000000..d1161e1
--- /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 1b58460..052222e 100644
--- a/libs/input/tests/InputWindow_test.cpp
+++ b/libs/input/tests/InputWindow_test.cpp
@@ -66,6 +66,9 @@
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 @@
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 4e4af7e..5ce9f23 100644
--- a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp
+++ b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp
@@ -94,7 +94,7 @@
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 296201d..86d62d7 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -583,7 +583,7 @@
FakeApplicationHandle() {
mInfo.name = "Fake Application";
mInfo.token = new BBinder();
- mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT;
+ mInfo.dispatchingTimeoutNanos = DISPATCHING_TIMEOUT.count();
}
virtual ~FakeApplicationHandle() {}
@@ -592,7 +592,7 @@
}
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 02342c0..87e0fb5 100644
--- a/services/inputflinger/tests/InputFlingerService_test.cpp
+++ b/services/inputflinger/tests/InputFlingerService_test.cpp
@@ -310,7 +310,7 @@
mInfo.applicationInfo.name = TestAppInfoName;
mInfo.applicationInfo.token = TestAppInfoToken;
- mInfo.applicationInfo.dispatchingTimeout = TestAppInfoDispatchingTimeout;
+ mInfo.applicationInfo.dispatchingTimeoutNanos = TestAppInfoDispatchingTimeout.count();
InitializeInputFlinger();
}