Loading libs/battery/MultiStateCounter.h +22 −0 Original line number Diff line number Diff line Loading @@ -62,6 +62,12 @@ public: void setState(state_t state, time_t timestamp); /** * Copies the current state and accumulated times-in-state from the source. Resets * the accumulated value. */ void copyStatesFrom(const MultiStateCounter<T>& source); void setValue(state_t state, const T& value); /** Loading Loading @@ -192,6 +198,22 @@ void MultiStateCounter<T>::setState(state_t state, time_t timestamp) { lastStateChangeTimestamp = timestamp; } template <class T> void MultiStateCounter<T>::copyStatesFrom(const MultiStateCounter<T>& source) { if (stateCount != source.stateCount) { ALOGE("State count mismatch: %u vs. %u\n", stateCount, source.stateCount); return; } currentState = source.currentState; for (int i = 0; i < stateCount; i++) { states[i].timeInStateSinceUpdate = source.states[i].timeInStateSinceUpdate; states[i].counter = emptyValue; } lastStateChangeTimestamp = source.lastStateChangeTimestamp; lastUpdateTimestamp = source.lastUpdateTimestamp; } template <class T> void MultiStateCounter<T>::setValue(state_t state, const T& value) { states[state].counter = value; Loading libs/battery/MultiStateCounterTest.cpp +16 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,22 @@ TEST_F(MultiStateCounterTest, stateChange) { EXPECT_DOUBLE_EQ(4.0, testCounter.getCount(2)); } TEST_F(MultiStateCounterTest, copyStatesFrom) { DoubleMultiStateCounter sourceCounter(3, 0); sourceCounter.updateValue(0, 0); sourceCounter.setState(1, 0); sourceCounter.setState(2, 1000); DoubleMultiStateCounter testCounter(3, 0); testCounter.copyStatesFrom(sourceCounter); testCounter.updateValue(6.0, 3000); EXPECT_DOUBLE_EQ(0, testCounter.getCount(0)); EXPECT_DOUBLE_EQ(2.0, testCounter.getCount(1)); EXPECT_DOUBLE_EQ(4.0, testCounter.getCount(2)); } TEST_F(MultiStateCounterTest, setEnabled) { DoubleMultiStateCounter testCounter(3, 0); testCounter.updateValue(0, 0); Loading libs/binder/ndk/Android.bp +41 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ cc_library { "-DBINDER_WITH_KERNEL_IPC", "-Wall", "-Wextra", "-Wextra-semi", "-Werror", ], Loading Loading @@ -146,6 +147,46 @@ cc_library { afdo: true, } cc_library { name: "libbinder_ndk_on_trusty_mock", defaults: [ "trusty_mock_defaults", ], export_include_dirs: [ "include_cpp", "include_ndk", "include_platform", ], srcs: [ "ibinder.cpp", "libbinder.cpp", "parcel.cpp", "stability.cpp", "status.cpp", ], shared_libs: [ "libbinder_on_trusty_mock", ], header_libs: [ "libbinder_trusty_ndk_headers", ], export_header_lib_headers: [ "libbinder_trusty_ndk_headers", ], cflags: [ "-Wall", "-Wextra", "-Werror", ], visibility: ["//frameworks/native/libs/binder:__subpackages__"], } cc_library_headers { name: "libbinder_headers_platform_shared", export_include_dirs: ["include_cpp"], Loading libs/binder/ndk/ibinder.cpp +8 −2 Original line number Diff line number Diff line Loading @@ -45,7 +45,9 @@ namespace ABBinderTag { static const void* kId = "ABBinder"; static void* kValue = static_cast<void*>(new bool{true}); void clean(const void* /*id*/, void* /*obj*/, void* /*cookie*/){/* do nothing */}; void clean(const void* /*id*/, void* /*obj*/, void* /*cookie*/) { /* do nothing */ } static void attach(const sp<IBinder>& binder) { auto alreadyAttached = binder->attachObject(kId, kValue, nullptr /*cookie*/, clean); Loading @@ -70,7 +72,7 @@ void clean(const void* id, void* obj, void* cookie) { LOG_ALWAYS_FATAL_IF(id != kId, "%p %p %p", id, obj, cookie); delete static_cast<Value*>(obj); }; } } // namespace ABpBinderTag Loading Loading @@ -609,6 +611,7 @@ binder_status_t AIBinder_unlinkToDeath(AIBinder* binder, AIBinder_DeathRecipient return recipient->unlinkToDeath(binder->getBinder(), cookie); } #ifdef BINDER_WITH_KERNEL_IPC uid_t AIBinder_getCallingUid() { return ::android::IPCThreadState::self()->getCallingUid(); } Loading @@ -620,6 +623,7 @@ pid_t AIBinder_getCallingPid() { bool AIBinder_isHandlingTransaction() { return ::android::IPCThreadState::self()->getServingStackPointer() != nullptr; } #endif void AIBinder_incStrong(AIBinder* binder) { if (binder == nullptr) { Loading Loading @@ -837,9 +841,11 @@ void AIBinder_setRequestingSid(AIBinder* binder, bool requestingSid) { localBinder->setRequestingSid(requestingSid); } #ifdef BINDER_WITH_KERNEL_IPC const char* AIBinder_getCallingSid() { return ::android::IPCThreadState::self()->getCallingSid(); } #endif void AIBinder_setMinSchedulerPolicy(AIBinder* binder, int policy, int priority) { binder->asABBinder()->setMinSchedulerPolicy(policy, priority); Loading libs/binder/tests/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -435,6 +435,7 @@ cc_test { // Add the Trusty mock library as a fake dependency so it gets built required: [ "libbinder_on_trusty_mock", "libbinder_ndk_on_trusty_mock", "binderRpcTestService_on_trusty_mock", "binderRpcTest_on_trusty_mock", ], Loading Loading
libs/battery/MultiStateCounter.h +22 −0 Original line number Diff line number Diff line Loading @@ -62,6 +62,12 @@ public: void setState(state_t state, time_t timestamp); /** * Copies the current state and accumulated times-in-state from the source. Resets * the accumulated value. */ void copyStatesFrom(const MultiStateCounter<T>& source); void setValue(state_t state, const T& value); /** Loading Loading @@ -192,6 +198,22 @@ void MultiStateCounter<T>::setState(state_t state, time_t timestamp) { lastStateChangeTimestamp = timestamp; } template <class T> void MultiStateCounter<T>::copyStatesFrom(const MultiStateCounter<T>& source) { if (stateCount != source.stateCount) { ALOGE("State count mismatch: %u vs. %u\n", stateCount, source.stateCount); return; } currentState = source.currentState; for (int i = 0; i < stateCount; i++) { states[i].timeInStateSinceUpdate = source.states[i].timeInStateSinceUpdate; states[i].counter = emptyValue; } lastStateChangeTimestamp = source.lastStateChangeTimestamp; lastUpdateTimestamp = source.lastUpdateTimestamp; } template <class T> void MultiStateCounter<T>::setValue(state_t state, const T& value) { states[state].counter = value; Loading
libs/battery/MultiStateCounterTest.cpp +16 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,22 @@ TEST_F(MultiStateCounterTest, stateChange) { EXPECT_DOUBLE_EQ(4.0, testCounter.getCount(2)); } TEST_F(MultiStateCounterTest, copyStatesFrom) { DoubleMultiStateCounter sourceCounter(3, 0); sourceCounter.updateValue(0, 0); sourceCounter.setState(1, 0); sourceCounter.setState(2, 1000); DoubleMultiStateCounter testCounter(3, 0); testCounter.copyStatesFrom(sourceCounter); testCounter.updateValue(6.0, 3000); EXPECT_DOUBLE_EQ(0, testCounter.getCount(0)); EXPECT_DOUBLE_EQ(2.0, testCounter.getCount(1)); EXPECT_DOUBLE_EQ(4.0, testCounter.getCount(2)); } TEST_F(MultiStateCounterTest, setEnabled) { DoubleMultiStateCounter testCounter(3, 0); testCounter.updateValue(0, 0); Loading
libs/binder/ndk/Android.bp +41 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ cc_library { "-DBINDER_WITH_KERNEL_IPC", "-Wall", "-Wextra", "-Wextra-semi", "-Werror", ], Loading Loading @@ -146,6 +147,46 @@ cc_library { afdo: true, } cc_library { name: "libbinder_ndk_on_trusty_mock", defaults: [ "trusty_mock_defaults", ], export_include_dirs: [ "include_cpp", "include_ndk", "include_platform", ], srcs: [ "ibinder.cpp", "libbinder.cpp", "parcel.cpp", "stability.cpp", "status.cpp", ], shared_libs: [ "libbinder_on_trusty_mock", ], header_libs: [ "libbinder_trusty_ndk_headers", ], export_header_lib_headers: [ "libbinder_trusty_ndk_headers", ], cflags: [ "-Wall", "-Wextra", "-Werror", ], visibility: ["//frameworks/native/libs/binder:__subpackages__"], } cc_library_headers { name: "libbinder_headers_platform_shared", export_include_dirs: ["include_cpp"], Loading
libs/binder/ndk/ibinder.cpp +8 −2 Original line number Diff line number Diff line Loading @@ -45,7 +45,9 @@ namespace ABBinderTag { static const void* kId = "ABBinder"; static void* kValue = static_cast<void*>(new bool{true}); void clean(const void* /*id*/, void* /*obj*/, void* /*cookie*/){/* do nothing */}; void clean(const void* /*id*/, void* /*obj*/, void* /*cookie*/) { /* do nothing */ } static void attach(const sp<IBinder>& binder) { auto alreadyAttached = binder->attachObject(kId, kValue, nullptr /*cookie*/, clean); Loading @@ -70,7 +72,7 @@ void clean(const void* id, void* obj, void* cookie) { LOG_ALWAYS_FATAL_IF(id != kId, "%p %p %p", id, obj, cookie); delete static_cast<Value*>(obj); }; } } // namespace ABpBinderTag Loading Loading @@ -609,6 +611,7 @@ binder_status_t AIBinder_unlinkToDeath(AIBinder* binder, AIBinder_DeathRecipient return recipient->unlinkToDeath(binder->getBinder(), cookie); } #ifdef BINDER_WITH_KERNEL_IPC uid_t AIBinder_getCallingUid() { return ::android::IPCThreadState::self()->getCallingUid(); } Loading @@ -620,6 +623,7 @@ pid_t AIBinder_getCallingPid() { bool AIBinder_isHandlingTransaction() { return ::android::IPCThreadState::self()->getServingStackPointer() != nullptr; } #endif void AIBinder_incStrong(AIBinder* binder) { if (binder == nullptr) { Loading Loading @@ -837,9 +841,11 @@ void AIBinder_setRequestingSid(AIBinder* binder, bool requestingSid) { localBinder->setRequestingSid(requestingSid); } #ifdef BINDER_WITH_KERNEL_IPC const char* AIBinder_getCallingSid() { return ::android::IPCThreadState::self()->getCallingSid(); } #endif void AIBinder_setMinSchedulerPolicy(AIBinder* binder, int policy, int priority) { binder->asABBinder()->setMinSchedulerPolicy(policy, priority); Loading
libs/binder/tests/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -435,6 +435,7 @@ cc_test { // Add the Trusty mock library as a fake dependency so it gets built required: [ "libbinder_on_trusty_mock", "libbinder_ndk_on_trusty_mock", "binderRpcTestService_on_trusty_mock", "binderRpcTest_on_trusty_mock", ], Loading