Use AIDL HAL for Dev GC
Test: run idle maint Bug: 177470478 Change-Id: Iefddf8628e31f020b86ff56dfb4926c2c9a2a888
This commit is contained in:
parent
8f0d45441c
commit
e1e494519e
2 changed files with 37 additions and 2 deletions
|
@ -155,6 +155,8 @@ cc_library_static {
|
||||||
},
|
},
|
||||||
shared_libs: [
|
shared_libs: [
|
||||||
"android.hardware.health.storage@1.0",
|
"android.hardware.health.storage@1.0",
|
||||||
|
"android.hardware.health.storage-unstable-ndk_platform",
|
||||||
|
"libbinder_ndk",
|
||||||
],
|
],
|
||||||
whole_static_libs: [
|
whole_static_libs: [
|
||||||
"com.android.sysprop.apex",
|
"com.android.sysprop.apex",
|
||||||
|
@ -184,6 +186,8 @@ cc_binary {
|
||||||
|
|
||||||
shared_libs: [
|
shared_libs: [
|
||||||
"android.hardware.health.storage@1.0",
|
"android.hardware.health.storage@1.0",
|
||||||
|
"android.hardware.health.storage-unstable-ndk_platform",
|
||||||
|
"libbinder_ndk",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,11 +24,14 @@
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include <aidl/android/hardware/health/storage/BnGarbageCollectCallback.h>
|
||||||
|
#include <aidl/android/hardware/health/storage/IStorage.h>
|
||||||
#include <android-base/chrono_utils.h>
|
#include <android-base/chrono_utils.h>
|
||||||
#include <android-base/file.h>
|
#include <android-base/file.h>
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
#include <android-base/stringprintf.h>
|
#include <android-base/stringprintf.h>
|
||||||
#include <android-base/strings.h>
|
#include <android-base/strings.h>
|
||||||
|
#include <android/binder_manager.h>
|
||||||
#include <android/hardware/health/storage/1.0/IStorage.h>
|
#include <android/hardware/health/storage/1.0/IStorage.h>
|
||||||
#include <fs_mgr.h>
|
#include <fs_mgr.h>
|
||||||
#include <private/android_filesystem_config.h>
|
#include <private/android_filesystem_config.h>
|
||||||
|
@ -49,9 +52,14 @@ using android::base::Timer;
|
||||||
using android::base::WriteStringToFile;
|
using android::base::WriteStringToFile;
|
||||||
using android::hardware::Return;
|
using android::hardware::Return;
|
||||||
using android::hardware::Void;
|
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 HStorage = android::hardware::health::storage::V1_0::IStorage;
|
||||||
using HGarbageCollectCallback = android::hardware::health::storage::V1_0::IGarbageCollectCallback;
|
using HGarbageCollectCallback = android::hardware::health::storage::V1_0::IGarbageCollectCallback;
|
||||||
using HResult = android::hardware::health::storage::V1_0::Result;
|
using HResult = android::hardware::health::storage::V1_0::Result;
|
||||||
|
using std::string_literals::operator""s;
|
||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
namespace vold {
|
namespace vold {
|
||||||
|
@ -301,9 +309,9 @@ static void runDevGcFstab(void) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class IDL { HIDL };
|
enum class IDL { HIDL, AIDL };
|
||||||
std::ostream& operator<<(std::ostream& os, IDL idl) {
|
std::ostream& operator<<(std::ostream& os, IDL idl) {
|
||||||
return os << "HIDL";
|
return os << (idl == IDL::HIDL ? "HIDL" : "AIDL");
|
||||||
}
|
}
|
||||||
|
|
||||||
template <IDL idl, typename Result>
|
template <IDL idl, typename Result>
|
||||||
|
@ -338,6 +346,14 @@ class GcCallbackImpl {
|
||||||
Result mResult{Result::UNKNOWN_ERROR};
|
Result mResult{Result::UNKNOWN_ERROR};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class AGcCallbackImpl : public ABnGarbageCollectCallback,
|
||||||
|
public GcCallbackImpl<IDL::AIDL, AResult> {
|
||||||
|
ndk::ScopedAStatus onFinish(AResult result) override {
|
||||||
|
onFinishInternal(result);
|
||||||
|
return ndk::ScopedAStatus::ok();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class HGcCallbackImpl : public HGarbageCollectCallback, public GcCallbackImpl<IDL::HIDL, HResult> {
|
class HGcCallbackImpl : public HGarbageCollectCallback, public GcCallbackImpl<IDL::HIDL, HResult> {
|
||||||
Return<void> onFinish(HResult result) override {
|
Return<void> onFinish(HResult result) override {
|
||||||
onFinishInternal(result);
|
onFinishInternal(result);
|
||||||
|
@ -358,6 +374,21 @@ static void runDevGcOnHal(Service service, GcCallbackImpl cb, GetDescription get
|
||||||
}
|
}
|
||||||
|
|
||||||
static void runDevGc(void) {
|
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<AStorage> aidl_service = AStorage::fromBinder(binder);
|
||||||
|
if (aidl_service != nullptr) {
|
||||||
|
runDevGcOnHal<IDL::AIDL>(aidl_service, ndk::SharedRefBase::make<AGcCallbackImpl>(),
|
||||||
|
&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();
|
auto hidl_service = HStorage::getService();
|
||||||
if (hidl_service != nullptr) {
|
if (hidl_service != nullptr) {
|
||||||
runDevGcOnHal<IDL::HIDL>(hidl_service, sp<HGcCallbackImpl>(new HGcCallbackImpl()),
|
runDevGcOnHal<IDL::HIDL>(hidl_service, sp<HGcCallbackImpl>(new HGcCallbackImpl()),
|
||||||
|
|
Loading…
Reference in a new issue