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 | |
| 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
| -rw-r--r-- | storaged/include/storaged_info.h | 23 | ||||
| -rw-r--r-- | storaged/storaged.cpp | 3 | ||||
| -rw-r--r-- | storaged/storaged_info.cpp | 32 |
3 files changed, 51 insertions, 7 deletions
diff --git a/storaged/include/storaged_info.h b/storaged/include/storaged_info.h index b1efac24f..3a6a0d48c 100644 --- a/storaged/include/storaged_info.h +++ b/storaged/include/storaged_info.h @@ -21,6 +21,7 @@ #include <chrono> +#include <android/hardware/health/2.0/IHealth.h> #include <utils/Mutex.h> #include "storaged.h" @@ -35,7 +36,7 @@ using namespace chrono; using namespace storaged_proto; class storage_info_t { -protected: + protected: FRIEND_TEST(storaged_test, storage_info_t); // emmc lifetime uint16_t eol; // pre-eol (end of life) information @@ -66,8 +67,10 @@ protected: } void publish(); storage_info_t* s_info; -public: - static storage_info_t* get_storage_info(); + + public: + static storage_info_t* get_storage_info( + const sp<android::hardware::health::V2_0::IHealth>& healthService); virtual ~storage_info_t() {}; virtual void report() {}; void load_perf_history_proto(const IOPerfHistory& perf_history); @@ -98,4 +101,18 @@ public: virtual void report(); }; +class health_storage_info_t : public storage_info_t { + private: + using IHealth = hardware::health::V2_0::IHealth; + using StorageInfo = hardware::health::V2_0::StorageInfo; + + sp<IHealth> mHealth; + void set_values_from_hal_storage_info(const StorageInfo& halInfo); + + public: + health_storage_info_t(const sp<IHealth>& service) : mHealth(service){}; + virtual ~health_storage_info_t() {} + virtual void report(); +}; + #endif /* _STORAGED_INFO_H_ */ diff --git a/storaged/storaged.cpp b/storaged/storaged.cpp index 09f2abec1..6807cd920 100644 --- a/storaged/storaged.cpp +++ b/storaged/storaged.cpp @@ -87,6 +87,7 @@ Return<void> storaged_t::healthInfoChanged(const HealthInfo& props) { void storaged_t::init() { init_health_service(); mDsm = std::make_unique<disk_stats_monitor>(health); + storage_info.reset(storage_info_t::get_storage_info(health)); } void storaged_t::init_health_service() { @@ -157,8 +158,6 @@ storaged_t::storaged_t(void) { property_get_int32("ro.storaged.flush_proto.interval", DEFAULT_PERIODIC_CHORES_INTERVAL_FLUSH_PROTO); - storage_info.reset(storage_info_t::get_storage_info()); - mStarttime = time(NULL); mTimer = 0; } 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; +} |
