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

Commit a4d8aaac authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Run some inputflinger_tests on host"

parents 3a785048 31977184
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ package {


cc_library_static {
cc_library_static {
    name: "libattestation",
    name: "libattestation",
    host_supported: true,
    cflags: [
    cflags: [
        "-Wall",
        "-Wall",
        "-Wextra",
        "-Wextra",
+20 −16
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@
#include <inttypes.h>
#include <inttypes.h>
#include <string.h>
#include <string.h>


#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/logging.h>
#include <android-base/stringprintf.h>
#include <android-base/stringprintf.h>
#include <cutils/compiler.h>
#include <cutils/compiler.h>
@@ -34,9 +35,6 @@
#ifdef __linux__
#ifdef __linux__
#include <binder/Parcel.h>
#include <binder/Parcel.h>
#endif
#endif
#ifdef __ANDROID__
#include <sys/random.h>
#endif


using android::base::StringPrintf;
using android::base::StringPrintf;


@@ -112,28 +110,34 @@ const char* motionToolTypeToString(int32_t toolType) {
}
}


// --- IdGenerator ---
// --- IdGenerator ---

static status_t getRandomBytes(uint8_t* data, size_t size) {
    int ret = TEMP_FAILURE_RETRY(open("/dev/urandom", O_RDONLY | O_CLOEXEC | O_NOFOLLOW));
    if (ret == -1) {
        return -errno;
    }

    base::unique_fd fd(ret);
    if (!base::ReadFully(fd, data, size)) {
        return -errno;
    }
    return OK;
}

IdGenerator::IdGenerator(Source source) : mSource(source) {}
IdGenerator::IdGenerator(Source source) : mSource(source) {}


int32_t IdGenerator::nextId() const {
int32_t IdGenerator::nextId() const {
    constexpr uint32_t SEQUENCE_NUMBER_MASK = ~SOURCE_MASK;
    constexpr uint32_t SEQUENCE_NUMBER_MASK = ~SOURCE_MASK;
    int32_t id = 0;
    int32_t id = 0;


// Avoid building against syscall getrandom(2) on host, which will fail build on Mac. Host doesn't
#if defined(__linux__)
// use sequence number so just always return mSource.
    while (true) {
#ifdef __ANDROID__
        status_t result = getRandomBytes(reinterpret_cast<uint8_t*>(&id), sizeof(id));
    constexpr size_t BUF_LEN = sizeof(id);
        if (result == OK) {
    size_t totalBytes = 0;
    while (totalBytes < BUF_LEN) {
        ssize_t bytes = TEMP_FAILURE_RETRY(getrandom(&id, BUF_LEN, GRND_NONBLOCK));
        if (CC_UNLIKELY(bytes < 0)) {
            ALOGW("Failed to fill in random number for sequence number: %s.", strerror(errno));
            id = 0;
            break;
            break;
        }
        }
        totalBytes += bytes;
    }
    }
#endif // __ANDROID__
#endif // __linux__

    return (id & SEQUENCE_NUMBER_MASK) | static_cast<int32_t>(mSource);
    return (id & SEQUENCE_NUMBER_MASK) | static_cast<int32_t>(mSource);
}
}


+1 −0
Original line number Original line Diff line number Diff line
@@ -9,6 +9,7 @@ package {


cc_library_headers {
cc_library_headers {
    name: "libbatteryservice_headers",
    name: "libbatteryservice_headers",
    host_supported: true,
    vendor_available: true,
    vendor_available: true,
    recovery_available: true,
    recovery_available: true,
    export_include_dirs: ["include"],
    export_include_dirs: ["include"],
+37 −9
Original line number Original line Diff line number Diff line
@@ -41,7 +41,9 @@ cc_defaults {
        "-DANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION",
        "-DANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION",
    ],
    ],
    sanitize: {
    sanitize: {
        misc_undefined: ["bounds"],
        misc_undefined: [
            "bounds",
        ],
    },
    },
    tidy: true,
    tidy: true,
    tidy_checks: [
    tidy_checks: [
@@ -57,11 +59,11 @@ cc_defaults {
filegroup {
filegroup {
    name: "libinputflinger_sources",
    name: "libinputflinger_sources",
    srcs: [
    srcs: [
        "InputProcessor.cpp",
        "InputCommonConverter.cpp",
        "InputCommonConverter.cpp",
        "InputManager.cpp",
        "InputProcessor.cpp",
        "PreferStylusOverTouchBlocker.cpp",
        "PreferStylusOverTouchBlocker.cpp",
        "UnwantedInteractionBlocker.cpp",
        "UnwantedInteractionBlocker.cpp",
        "InputManager.cpp",
    ],
    ],
}
}


@@ -77,13 +79,10 @@ cc_defaults {
        "libcrypto",
        "libcrypto",
        "libcutils",
        "libcutils",
        "libhidlbase",
        "libhidlbase",
        "libinput",
        "libkll",
        "libkll",
        "liblog",
        "liblog",
        "libprotobuf-cpp-lite",
        "libprotobuf-cpp-lite",
        "libstatslog",
        "libstatslog",
        "libstatspull",
        "libstatssocket",
        "libutils",
        "libutils",
        "server_configurable_flags",
        "server_configurable_flags",
    ],
    ],
@@ -92,6 +91,23 @@ cc_defaults {
        "libpalmrejection",
        "libpalmrejection",
        "libui-types",
        "libui-types",
    ],
    ],
    target: {
        android: {
            shared_libs: [
                "libgui",
                "libinput",
                "libstatspull",
                "libstatssocket",
            ],
        },
        host: {
            static_libs: [
                "libinput",
                "libstatspull",
                "libstatssocket",
            ],
        },
    },
}
}


cc_library_shared {
cc_library_shared {
@@ -108,9 +124,8 @@ cc_library_shared {
        // This should consist only of dependencies from inputflinger. Other dependencies should be
        // This should consist only of dependencies from inputflinger. Other dependencies should be
        // in cc_defaults so that they are included in the tests.
        // in cc_defaults so that they are included in the tests.
        "libinputflinger_base",
        "libinputflinger_base",
        "libinputreporter",
        "libinputreader",
        "libinputreader",
        "libgui",
        "libinputreporter",
    ],
    ],
    static_libs: [
    static_libs: [
        "libinputdispatcher",
        "libinputdispatcher",
@@ -130,6 +145,7 @@ cc_library_shared {


cc_library_headers {
cc_library_headers {
    name: "libinputflinger_headers",
    name: "libinputflinger_headers",
    host_supported: true,
    export_include_dirs: ["include"],
    export_include_dirs: ["include"],
}
}


@@ -151,17 +167,29 @@ cc_defaults {
        "libbase",
        "libbase",
        "libbinder",
        "libbinder",
        "libcutils",
        "libcutils",
        "libinput",
        "liblog",
        "liblog",
        "libutils",
        "libutils",
    ],
    ],
    header_libs: [
    header_libs: [
        "libinputflinger_headers",
        "libinputflinger_headers",
    ],
    ],
    target: {
        android: {
            shared_libs: [
                "libinput",
            ],
        },
        host: {
            static_libs: [
                "libinput",
            ],
        },
    },
}
}


cc_library_shared {
cc_library_shared {
    name: "libinputflinger_base",
    name: "libinputflinger_base",
    host_supported: true,
    defaults: [
    defaults: [
        "inputflinger_defaults",
        "inputflinger_defaults",
        "libinputflinger_base_defaults",
        "libinputflinger_base_defaults",
+6 −0
Original line number Original line Diff line number Diff line
@@ -54,7 +54,13 @@ InputThread::~InputThread() {
}
}


bool InputThread::isCallingThread() {
bool InputThread::isCallingThread() {
#if defined(__ANDROID__)
    return gettid() == mThread->getTid();
    return gettid() == mThread->getTid();
#else
    // Assume that the caller is doing everything correctly,
    // since thread information is not available on host
    return false;
#endif
}
}


} // namespace android
} // namespace android
 No newline at end of file
Loading