Loading libs/binder/ProcessState.cpp +25 −1 Original line number Original line Diff line number Diff line Loading @@ -409,6 +409,28 @@ size_t ProcessState::getThreadPoolMaxThreadCount() const { return 0; 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) { status_t ProcessState::enableOnewaySpamDetection(bool enable) { uint32_t enableDetection = enable ? 1 : 0; uint32_t enableDetection = enable ? 1 : 0; if (ioctl(mDriverFD, BINDER_ENABLE_ONEWAY_SPAM_DETECTION, &enableDetection) == -1) { if (ioctl(mDriverFD, BINDER_ENABLE_ONEWAY_SPAM_DETECTION, &enableDetection) == -1) { Loading Loading @@ -452,7 +474,9 @@ static base::Result<int> open_driver(const char* driver) { uint32_t enable = DEFAULT_ENABLE_ONEWAY_SPAM_DETECTION; uint32_t enable = DEFAULT_ENABLE_ONEWAY_SPAM_DETECTION; result = ioctl(fd, BINDER_ENABLE_ONEWAY_SPAM_DETECTION, &enable); result = ioctl(fd, BINDER_ENABLE_ONEWAY_SPAM_DETECTION, &enable); if (result == -1) { 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; return fd; } } Loading libs/binder/include/binder/ProcessState.h +6 −0 Original line number Original line Diff line number Diff line Loading @@ -91,6 +91,12 @@ public: */ */ size_t getThreadPoolMaxThreadCount() const; size_t getThreadPoolMaxThreadCount() const; enum class DriverFeature { ONEWAY_SPAM_DETECTION, }; // Determine whether a feature is supported by the binder driver. static bool isDriverFeatureEnabled(const DriverFeature feature); private: private: static sp<ProcessState> init(const char* defaultDriver, bool requireDefault); static sp<ProcessState> init(const char* defaultDriver, bool requireDefault); Loading Loading
libs/binder/ProcessState.cpp +25 −1 Original line number Original line Diff line number Diff line Loading @@ -409,6 +409,28 @@ size_t ProcessState::getThreadPoolMaxThreadCount() const { return 0; 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) { status_t ProcessState::enableOnewaySpamDetection(bool enable) { uint32_t enableDetection = enable ? 1 : 0; uint32_t enableDetection = enable ? 1 : 0; if (ioctl(mDriverFD, BINDER_ENABLE_ONEWAY_SPAM_DETECTION, &enableDetection) == -1) { if (ioctl(mDriverFD, BINDER_ENABLE_ONEWAY_SPAM_DETECTION, &enableDetection) == -1) { Loading Loading @@ -452,7 +474,9 @@ static base::Result<int> open_driver(const char* driver) { uint32_t enable = DEFAULT_ENABLE_ONEWAY_SPAM_DETECTION; uint32_t enable = DEFAULT_ENABLE_ONEWAY_SPAM_DETECTION; result = ioctl(fd, BINDER_ENABLE_ONEWAY_SPAM_DETECTION, &enable); result = ioctl(fd, BINDER_ENABLE_ONEWAY_SPAM_DETECTION, &enable); if (result == -1) { 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; return fd; } } Loading
libs/binder/include/binder/ProcessState.h +6 −0 Original line number Original line Diff line number Diff line Loading @@ -91,6 +91,12 @@ public: */ */ size_t getThreadPoolMaxThreadCount() const; size_t getThreadPoolMaxThreadCount() const; enum class DriverFeature { ONEWAY_SPAM_DETECTION, }; // Determine whether a feature is supported by the binder driver. static bool isDriverFeatureEnabled(const DriverFeature feature); private: private: static sp<ProcessState> init(const char* defaultDriver, bool requireDefault); static sp<ProcessState> init(const char* defaultDriver, bool requireDefault); Loading