Loading cmds/installd/TEST_MAPPING +6 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,12 @@ "name": "CtsCompilationTestCases" }, { "name": "SdkSandboxStorageHostTest" "name": "SdkSandboxStorageHostTest", "options": [ { "exclude-annotation": "android.platform.test.annotations.LargeTest" } ] } ] } libs/binder/ndk/include_cpp/android/binder_interface_utils.h +38 −0 Original line number Diff line number Diff line Loading @@ -324,4 +324,42 @@ SpAIBinder BpCInterface<INTERFACE>::asBinder() { } // namespace ndk // Once minSdkVersion is 30, we are guaranteed to be building with the // Android 11 AIDL compiler which supports the SharedRefBase::make API. #if !defined(__ANDROID_API__) || __ANDROID_API__ >= 30 || defined(__ANDROID_APEX__) namespace ndk::internal { template <typename T, typename = void> struct is_complete_type : std::false_type {}; template <typename T> struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {}; } // namespace ndk::internal namespace std { // Define `SharedRefBase` specific versions of `std::make_shared` and // `std::make_unique` to block people from using them. Using them to allocate // `ndk::SharedRefBase` objects results in double ownership. Use // `ndk::SharedRefBase::make<T>(...)` instead. // // Note: We exclude incomplete types because `std::is_base_of` is undefined in // that case. template <typename T, typename... Args, std::enable_if_t<ndk::internal::is_complete_type<T>::value, bool> = true, std::enable_if_t<std::is_base_of<ndk::SharedRefBase, T>::value, bool> = true> shared_ptr<T> make_shared(Args...) { // SEE COMMENT ABOVE. static_assert(!std::is_base_of<ndk::SharedRefBase, T>::value); } template <typename T, typename... Args, std::enable_if_t<ndk::internal::is_complete_type<T>::value, bool> = true, std::enable_if_t<std::is_base_of<ndk::SharedRefBase, T>::value, bool> = true> unique_ptr<T> make_unique(Args...) { // SEE COMMENT ABOVE. static_assert(!std::is_base_of<ndk::SharedRefBase, T>::value); } } // namespace std #endif /** @} */ libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp +1 −2 Original line number Diff line number Diff line Loading @@ -231,8 +231,7 @@ TEST(NdkBinder, DetectDoubleOwn) { } TEST(NdkBinder, DetectNoSharedRefBaseCreated) { EXPECT_DEATH(std::make_shared<MyBinderNdkUnitTest>(), "SharedRefBase: no ref created during lifetime"); EXPECT_DEATH(MyBinderNdkUnitTest(), "SharedRefBase: no ref created during lifetime"); } TEST(NdkBinder, GetServiceThatDoesntExist) { Loading services/sensorservice/HidlSensorHalWrapper.cpp +11 −9 Original line number Diff line number Diff line Loading @@ -281,7 +281,7 @@ status_t HidlSensorHalWrapper::injectSensorData(const sensors_event_t* event) { } status_t HidlSensorHalWrapper::registerDirectChannel(const sensors_direct_mem_t* memory, int32_t* /*channelHandle*/) { int32_t* outChannelHandle) { if (mSensors == nullptr) return NO_INIT; SharedMemType type; Loading Loading @@ -309,10 +309,12 @@ status_t HidlSensorHalWrapper::registerDirectChannel(const sensors_direct_mem_t* .memoryHandle = memory->handle, }; status_t ret; checkReturn(mSensors->registerDirectChannel(mem, [&ret](auto result, auto channelHandle) { status_t ret = OK; checkReturn(mSensors->registerDirectChannel(mem, [&ret, &outChannelHandle](auto result, auto channelHandle) { if (result == Result::OK) { ret = channelHandle; *outChannelHandle = channelHandle; } else { ret = statusFromResult(result); } Loading services/sensorservice/HidlSensorHalWrapper.h +1 −1 Original line number Diff line number Diff line Loading @@ -112,7 +112,7 @@ public: virtual status_t injectSensorData(const sensors_event_t* event) override; virtual status_t registerDirectChannel(const sensors_direct_mem_t* memory, int32_t* channelHandle) override; int32_t* outChannelHandle) override; virtual status_t unregisterDirectChannel(int32_t channelHandle) override; Loading Loading
cmds/installd/TEST_MAPPING +6 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,12 @@ "name": "CtsCompilationTestCases" }, { "name": "SdkSandboxStorageHostTest" "name": "SdkSandboxStorageHostTest", "options": [ { "exclude-annotation": "android.platform.test.annotations.LargeTest" } ] } ] }
libs/binder/ndk/include_cpp/android/binder_interface_utils.h +38 −0 Original line number Diff line number Diff line Loading @@ -324,4 +324,42 @@ SpAIBinder BpCInterface<INTERFACE>::asBinder() { } // namespace ndk // Once minSdkVersion is 30, we are guaranteed to be building with the // Android 11 AIDL compiler which supports the SharedRefBase::make API. #if !defined(__ANDROID_API__) || __ANDROID_API__ >= 30 || defined(__ANDROID_APEX__) namespace ndk::internal { template <typename T, typename = void> struct is_complete_type : std::false_type {}; template <typename T> struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {}; } // namespace ndk::internal namespace std { // Define `SharedRefBase` specific versions of `std::make_shared` and // `std::make_unique` to block people from using them. Using them to allocate // `ndk::SharedRefBase` objects results in double ownership. Use // `ndk::SharedRefBase::make<T>(...)` instead. // // Note: We exclude incomplete types because `std::is_base_of` is undefined in // that case. template <typename T, typename... Args, std::enable_if_t<ndk::internal::is_complete_type<T>::value, bool> = true, std::enable_if_t<std::is_base_of<ndk::SharedRefBase, T>::value, bool> = true> shared_ptr<T> make_shared(Args...) { // SEE COMMENT ABOVE. static_assert(!std::is_base_of<ndk::SharedRefBase, T>::value); } template <typename T, typename... Args, std::enable_if_t<ndk::internal::is_complete_type<T>::value, bool> = true, std::enable_if_t<std::is_base_of<ndk::SharedRefBase, T>::value, bool> = true> unique_ptr<T> make_unique(Args...) { // SEE COMMENT ABOVE. static_assert(!std::is_base_of<ndk::SharedRefBase, T>::value); } } // namespace std #endif /** @} */
libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp +1 −2 Original line number Diff line number Diff line Loading @@ -231,8 +231,7 @@ TEST(NdkBinder, DetectDoubleOwn) { } TEST(NdkBinder, DetectNoSharedRefBaseCreated) { EXPECT_DEATH(std::make_shared<MyBinderNdkUnitTest>(), "SharedRefBase: no ref created during lifetime"); EXPECT_DEATH(MyBinderNdkUnitTest(), "SharedRefBase: no ref created during lifetime"); } TEST(NdkBinder, GetServiceThatDoesntExist) { Loading
services/sensorservice/HidlSensorHalWrapper.cpp +11 −9 Original line number Diff line number Diff line Loading @@ -281,7 +281,7 @@ status_t HidlSensorHalWrapper::injectSensorData(const sensors_event_t* event) { } status_t HidlSensorHalWrapper::registerDirectChannel(const sensors_direct_mem_t* memory, int32_t* /*channelHandle*/) { int32_t* outChannelHandle) { if (mSensors == nullptr) return NO_INIT; SharedMemType type; Loading Loading @@ -309,10 +309,12 @@ status_t HidlSensorHalWrapper::registerDirectChannel(const sensors_direct_mem_t* .memoryHandle = memory->handle, }; status_t ret; checkReturn(mSensors->registerDirectChannel(mem, [&ret](auto result, auto channelHandle) { status_t ret = OK; checkReturn(mSensors->registerDirectChannel(mem, [&ret, &outChannelHandle](auto result, auto channelHandle) { if (result == Result::OK) { ret = channelHandle; *outChannelHandle = channelHandle; } else { ret = statusFromResult(result); } Loading
services/sensorservice/HidlSensorHalWrapper.h +1 −1 Original line number Diff line number Diff line Loading @@ -112,7 +112,7 @@ public: virtual status_t injectSensorData(const sensors_event_t* event) override; virtual status_t registerDirectChannel(const sensors_direct_mem_t* memory, int32_t* channelHandle) override; int32_t* outChannelHandle) override; virtual status_t unregisterDirectChannel(int32_t channelHandle) override; Loading