diff options
| author | Yifan Hong <elsk@google.com> | 2018-01-16 16:03:36 -0800 |
|---|---|---|
| committer | Yifan Hong <elsk@google.com> | 2018-01-16 19:25:01 -0800 |
| commit | 845e35bdc38fae940bed36438bede7bf96b98d4d (patch) | |
| tree | 21020b51650699c16e79253412772c8ed8ec8cdf /storaged/storaged_info.cpp | |
| parent | c4b46e0ad972cf8f238794349c6e939b268de522 (diff) | |
| download | system_core-845e35bdc38fae940bed36438bede7bf96b98d4d.tar.gz system_core-845e35bdc38fae940bed36438bede7bf96b98d4d.tar.bz2 system_core-845e35bdc38fae940bed36438bede7bf96b98d4d.zip | |
storaged: use health HAL to read StorageInfo.
Test: storaged unit tests
Bug: 68388678
Change-Id: Iec395a33bac72f49366e8c30ea7e709c8acdcfa2
Diffstat (limited to 'storaged/storaged_info.cpp')
| -rw-r--r-- | storaged/storaged_info.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/storaged/storaged_info.cpp b/storaged/storaged_info.cpp index 036d7e1f9..b6dd16462 100644 --- a/storaged/storaged_info.cpp +++ b/storaged/storaged_info.cpp @@ -36,6 +36,10 @@ using namespace chrono; using namespace android::base; using namespace storaged_proto; +using android::hardware::health::V2_0::IHealth; +using android::hardware::health::V2_0::Result; +using android::hardware::health::V2_0::StorageInfo; + const string emmc_info_t::emmc_sysfs = "/sys/bus/mmc/devices/mmc0:0001/"; const string emmc_info_t::emmc_debugfs = "/d/mmc0/mmc0:0001/ext_csd"; const char* emmc_info_t::emmc_ver_str[9] = { @@ -54,8 +58,10 @@ bool FileExists(const std::string& filename) } // namespace -storage_info_t* storage_info_t::get_storage_info() -{ +storage_info_t* storage_info_t::get_storage_info(const sp<IHealth>& healthService) { + if (healthService != nullptr) { + return new health_storage_info_t(healthService); + } if (FileExists(emmc_info_t::emmc_sysfs) || FileExists(emmc_info_t::emmc_debugfs)) { return new emmc_info_t; @@ -351,3 +357,25 @@ void ufs_info_t::report() publish(); } +void health_storage_info_t::report() { + auto ret = mHealth->getStorageInfo([this](auto result, const auto& halInfos) { + if (result != Result::SUCCESS || halInfos.size() == 0) { + LOG_TO(SYSTEM, DEBUG) << "getStorageInfo failed with result " << toString(result) + << " and size " << halInfos.size(); + return; + } + set_values_from_hal_storage_info(halInfos[0]); + publish(); + }); + + if (!ret.isOk()) { + LOG_TO(SYSTEM, DEBUG) << "getStorageInfo failed with " << ret.description(); + } +} + +void health_storage_info_t::set_values_from_hal_storage_info(const StorageInfo& halInfo) { + eol = halInfo.eol; + lifetime_a = halInfo.lifetimeA; + lifetime_b = halInfo.lifetimeB; + version = halInfo.version; +} |
