Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6c4243bf authored by Chris Ye's avatar Chris Ye
Browse files

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
parent 30cb6101
Loading
Loading
Loading
Loading
+5 −19
Original line number Diff line number Diff line
@@ -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;
};
+2 −1
Original line number Diff line number Diff line
@@ -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;
    }
+1 −1
Original line number Diff line number Diff line
@@ -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",
            ],
+6 −8
Original line number Diff line number Diff line
@@ -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 {
+23 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The Android Open Source Project
/**
 * 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.
@@ -14,42 +14,10 @@
 * limitations under the License.
 */

#define LOG_TAG "InputApplication"
package android;

#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;
parcelable InputApplicationInfo {
    @nullable IBinder token;
    @utf8InCpp String name;
    long dispatchingTimeoutNanos;
}
    status_t status = parcel->writeStrongBinder(token)
            ?: parcel->writeInt64(dispatchingTimeout.count())
            ?: parcel->writeUtf8AsUtf16(name) ;

    return status;
}

// --- InputApplicationHandle ---

InputApplicationHandle::InputApplicationHandle() {}

InputApplicationHandle::~InputApplicationHandle() {}

} // namespace android
Loading