diff options
| author | 2022-03-10 06:32:13 +0000 | |
|---|---|---|
| committer | 2022-03-10 06:32:13 +0000 | |
| commit | 23b14a95ddd5759f959a1bda7d849b8d5ff25d0c (patch) | |
| tree | bac9e7a70396fa3009dac2d033f5a8434a3b9f3d /libs/binder/ProcessState.cpp | |
| parent | 4eaf8abdcc78d2fc1a536c90bfd548830334c04c (diff) | |
| parent | e3049d49e2d876ffeb7ddd2b80baf39fbc097967 (diff) | |
Merge "libbinder: detect features supported by the driver" am: 9630721fb3 am: c58e8c2a08 am: e3049d49e2
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2015375
Change-Id: Ie16b4d1a8e99b0fd467bb2479ee0d3e5bd6b92c2
Diffstat (limited to 'libs/binder/ProcessState.cpp')
| -rw-r--r-- | libs/binder/ProcessState.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp index baa817c6b9..b14a838447 100644 --- a/libs/binder/ProcessState.cpp +++ b/libs/binder/ProcessState.cpp @@ -409,6 +409,28 @@ size_t ProcessState::getThreadPoolMaxThreadCount() const { return 0; } +#define DRIVER_FEATURES_PATH "/dev/binderfs/features/" +bool ProcessState::isDriverFeatureEnabled(const DriverFeature feature) { + static const char* const names[] = { + [static_cast<int>(DriverFeature::ONEWAY_SPAM_DETECTION)] = + DRIVER_FEATURES_PATH "oneway_spam_detection", + }; + int fd = open(names[static_cast<int>(feature)], O_RDONLY | O_CLOEXEC); + char on; + if (fd == -1) { + ALOGE_IF(errno != ENOENT, "%s: cannot open %s: %s", __func__, + names[static_cast<int>(feature)], strerror(errno)); + return false; + } + if (read(fd, &on, sizeof(on)) == -1) { + ALOGE("%s: error reading to %s: %s", __func__, + names[static_cast<int>(feature)], strerror(errno)); + return false; + } + close(fd); + return on == '1'; +} + status_t ProcessState::enableOnewaySpamDetection(bool enable) { uint32_t enableDetection = enable ? 1 : 0; if (ioctl(mDriverFD, BINDER_ENABLE_ONEWAY_SPAM_DETECTION, &enableDetection) == -1) { @@ -452,7 +474,9 @@ static base::Result<int> open_driver(const char* driver) { uint32_t enable = DEFAULT_ENABLE_ONEWAY_SPAM_DETECTION; result = ioctl(fd, BINDER_ENABLE_ONEWAY_SPAM_DETECTION, &enable); if (result == -1) { - ALOGV("Binder ioctl to enable oneway spam detection failed: %s", strerror(errno)); + ALOGE_IF(ProcessState::isDriverFeatureEnabled( + ProcessState::DriverFeature::ONEWAY_SPAM_DETECTION), + "Binder ioctl to enable oneway spam detection failed: %s", strerror(errno)); } return fd; } |