diff --git a/Android.bp b/Android.bp index 1c0ed17..861abba 100644 --- a/Android.bp +++ b/Android.bp @@ -155,6 +155,8 @@ cc_library_static { }, shared_libs: [ "android.hardware.health.storage@1.0", + "android.hardware.health.storage-unstable-ndk_platform", + "libbinder_ndk", ], whole_static_libs: [ "com.android.sysprop.apex", @@ -184,6 +186,8 @@ cc_binary { shared_libs: [ "android.hardware.health.storage@1.0", + "android.hardware.health.storage-unstable-ndk_platform", + "libbinder_ndk", ], } diff --git a/IdleMaint.cpp b/IdleMaint.cpp index 466cf19..4c3041b 100644 --- a/IdleMaint.cpp +++ b/IdleMaint.cpp @@ -24,11 +24,14 @@ #include #include +#include +#include #include #include #include #include #include +#include #include #include #include @@ -49,9 +52,14 @@ using android::base::Timer; using android::base::WriteStringToFile; using android::hardware::Return; using android::hardware::Void; +using AStorage = aidl::android::hardware::health::storage::IStorage; +using ABnGarbageCollectCallback = + aidl::android::hardware::health::storage::BnGarbageCollectCallback; +using AResult = aidl::android::hardware::health::storage::Result; using HStorage = android::hardware::health::storage::V1_0::IStorage; using HGarbageCollectCallback = android::hardware::health::storage::V1_0::IGarbageCollectCallback; using HResult = android::hardware::health::storage::V1_0::Result; +using std::string_literals::operator""s; namespace android { namespace vold { @@ -301,9 +309,9 @@ static void runDevGcFstab(void) { return; } -enum class IDL { HIDL }; +enum class IDL { HIDL, AIDL }; std::ostream& operator<<(std::ostream& os, IDL idl) { - return os << "HIDL"; + return os << (idl == IDL::HIDL ? "HIDL" : "AIDL"); } template @@ -338,6 +346,14 @@ class GcCallbackImpl { Result mResult{Result::UNKNOWN_ERROR}; }; +class AGcCallbackImpl : public ABnGarbageCollectCallback, + public GcCallbackImpl { + ndk::ScopedAStatus onFinish(AResult result) override { + onFinishInternal(result); + return ndk::ScopedAStatus::ok(); + } +}; + class HGcCallbackImpl : public HGarbageCollectCallback, public GcCallbackImpl { Return onFinish(HResult result) override { onFinishInternal(result); @@ -358,6 +374,21 @@ static void runDevGcOnHal(Service service, GcCallbackImpl cb, GetDescription get } static void runDevGc(void) { + auto aidl_service_name = AStorage::descriptor + "/default"s; + if (AServiceManager_isDeclared(aidl_service_name.c_str())) { + ndk::SpAIBinder binder(AServiceManager_waitForService(aidl_service_name.c_str())); + if (binder.get() != nullptr) { + std::shared_ptr aidl_service = AStorage::fromBinder(binder); + if (aidl_service != nullptr) { + runDevGcOnHal(aidl_service, ndk::SharedRefBase::make(), + &ndk::ScopedAStatus::getDescription); + return; + } + } + LOG(WARNING) << "Device declares " << aidl_service_name + << " but it is not running, skip dev GC on AIDL HAL"; + return; + } auto hidl_service = HStorage::getService(); if (hidl_service != nullptr) { runDevGcOnHal(hidl_service, sp(new HGcCallbackImpl()),