Code layout cleanup

- Fwd declare where possible
- List .h first in the .cpp to verify proper includes
- Remove hacky -internal.h file and move testBitInRange to a new component

Change-Id: I442248c4b32738c6c2af250f45d4c8822c862e08
This commit is contained in:
Tim Kilbourn
2015-05-19 15:04:30 -07:00
parent 4f3145d75f
commit dbc8c16841
17 changed files with 221 additions and 143 deletions

View File

@@ -17,8 +17,7 @@
#define LOG_TAG "InputHub"
//#define LOG_NDEBUG 0
// Enables debug output for hasKeyInRange
#define DEBUG_KEY_RANGE 0
#include "InputHub.h"
#include <dirent.h>
#include <errno.h>
@@ -36,15 +35,14 @@
#include <vector>
#include "InputHub.h"
#include "InputHub-internal.h"
#include <android/input.h>
#include <hardware_legacy/power.h>
#include <linux/input.h>
#include <utils/Log.h>
#include "BitUtils.h"
namespace android {
static const char WAKE_LOCK_ID[] = "KeyEvents";
@@ -60,57 +58,6 @@ static constexpr size_t sizeofBitArray(size_t bits) {
return (bits + 7) / 8;
}
namespace internal {
#if DEBUG_KEY_RANGE
static const char* bitstrings[16] = {
"0000", "0001", "0010", "0011",
"0100", "0101", "0110", "0111",
"1000", "1001", "1010", "1011",
"1100", "1101", "1110", "1111",
};
#endif
bool testBitInRange(const uint8_t arr[], size_t start, size_t end) {
#if DEBUG_KEY_RANGE
ALOGD("testBitInRange(%d, %d)", start, end);
#endif
// Invalid range! This is nonsense; just say no.
if (end <= start) return false;
// Find byte array indices. The end is not included in the range, nor is
// endIndex. Round up for endIndex.
size_t startIndex = start / 8;
size_t endIndex = (end + 7) / 8;
#if DEBUG_KEY_RANGE
ALOGD("startIndex=%d, endIndex=%d", startIndex, endIndex);
#endif
for (size_t i = startIndex; i < endIndex; ++i) {
uint8_t bits = arr[i];
uint8_t mask = 0xff;
#if DEBUG_KEY_RANGE
ALOGD("block %04d: %s%s", i, bitstrings[bits >> 4], bitstrings[bits & 0x0f]);
#endif
if (bits) {
// Mask off bits before our start bit
if (i == startIndex) {
mask &= 0xff << (start % 8);
}
// Mask off bits after our end bit
if (i == endIndex - 1 && (end % 8)) {
mask &= 0xff >> (8 - (end % 8));
}
#if DEBUG_KEY_RANGE
ALOGD("mask: %s%s", bitstrings[mask >> 4], bitstrings[mask & 0x0f]);
#endif
// Test the index against the mask
if (bits & mask) return true;
}
}
return false;
}
} // namespace internal
static void getLinuxRelease(int* major, int* minor) {
struct utsname info;
if (uname(&info) || sscanf(info.release, "%d.%d", major, minor) <= 0) {
@@ -331,7 +278,7 @@ bool EvdevDeviceNode::hasKey(int32_t key) const {
}
bool EvdevDeviceNode::hasKeyInRange(int32_t startKey, int32_t endKey) const {
return internal::testBitInRange(mKeyBitmask, startKey, endKey);
return testBitInRange(mKeyBitmask, startKey, endKey);
}
bool EvdevDeviceNode::hasRelativeAxis(int axis) const {