summaryrefslogtreecommitdiffstats
path: root/storaged/include
diff options
context:
space:
mode:
authorJin Qian <jinqian@google.com>2017-03-15 19:03:06 -0700
committerJin Qian <jinqian@google.com>2017-03-16 16:12:55 -0700
commit4fc338e60bf1d85212f1540d109beb1b248c4830 (patch)
tree0c2911d0119f8dcec09a81cda517895b319a4030 /storaged/include
parentbb82a5a53c437a778ae4a090f7bca7f76f86bc0c (diff)
downloadsystem_core-4fc338e60bf1d85212f1540d109beb1b248c4830.tar.gz
system_core-4fc338e60bf1d85212f1540d109beb1b248c4830.tar.bz2
system_core-4fc338e60bf1d85212f1540d109beb1b248c4830.zip
storaged: rewrite emmc info class
Test: adb logcat -d -b events | grep storaged_emmc_info Bug: 36228467 Change-Id: Ib799e60ed65661a9fb99be8ad4c930f547339975
Diffstat (limited to 'storaged/include')
-rw-r--r--storaged/include/storaged.h40
-rw-r--r--storaged/include/storaged_info.h66
2 files changed, 73 insertions, 33 deletions
diff --git a/storaged/include/storaged.h b/storaged/include/storaged.h
index c291bd98c..bd1391c98 100644
--- a/storaged/include/storaged.h
+++ b/storaged/include/storaged.h
@@ -28,6 +28,7 @@
#include <batteryservice/IBatteryPropertiesListener.h>
+#include "storaged_info.h"
#include "storaged_uid_monitor.h"
using namespace android;
@@ -44,6 +45,8 @@ friend class test_case_name##_##test_name##_Test
#define debuginfo(...)
#endif
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
#define SECTOR_SIZE ( 512 )
#define SEC_TO_MSEC ( 1000 )
#define MSEC_TO_USEC ( 1000 )
@@ -83,15 +86,7 @@ struct disk_stats {
double io_avg; // average io_in_flight for accumulate calculations
};
-#define MMC_VER_STR_LEN ( 9 ) // maximum length of the MMC version string, including NULL terminator
-// minimum size of a ext_csd file
-#define EXT_CSD_FILE_MIN_SIZE ( 1024 )
-struct emmc_info {
- int eol; // pre-eol (end of life) information
- int lifetime_a; // device life time estimation (type A)
- int lifetime_b; // device life time estimation (type B)
- char mmc_ver[MMC_VER_STR_LEN]; // device version string
-};
+
struct disk_perf {
uint32_t read_perf; // read speed (kbytes/s)
@@ -232,26 +227,6 @@ public:
void update(void);
};
-class emmc_info_t {
-private:
- struct emmc_info mInfo;
- bool mValid;
- int mFdEmmc;
-public:
- emmc_info_t(void) :
- mValid(false),
- mFdEmmc(-1) {
- memset(&mInfo, 0, sizeof(struct emmc_info));
- }
- ~emmc_info_t(void) {}
-
- void publish(void);
- void update(void);
- void set_emmc_fd(int fd) {
- mFdEmmc = fd;
- }
-};
-
// Periodic chores intervals in seconds
#define DEFAULT_PERIODIC_CHORES_INTERVAL_UNIT ( 60 )
#define DEFAULT_PERIODIC_CHORES_INTERVAL_DISK_STATS_PUBLISH ( 3600 )
@@ -268,7 +243,6 @@ struct storaged_config {
int periodic_chores_interval_emmc_info_publish;
int periodic_chores_interval_uid_io;
bool proc_uid_io_available; // whether uid_io is accessible
- bool emmc_available; // whether eMMC est_csd file is readable
bool diskstats_available; // whether diskstats is accessible
int event_time_check_usec; // check how much cputime spent in event loop
};
@@ -279,7 +253,7 @@ private:
storaged_config mConfig;
disk_stats_publisher mDiskStats;
disk_stats_monitor mDsm;
- emmc_info_t mEmmcInfo;
+ storage_info_t *info = nullptr;
uid_monitor mUidm;
time_t mStarttime;
public:
@@ -290,8 +264,8 @@ public:
void pause(void) {
sleep(mConfig.periodic_chores_interval_unit);
}
- void set_privileged_fds(int fd_emmc) {
- mEmmcInfo.set_emmc_fd(fd_emmc);
+ void set_storage_info(storage_info_t *storage_info) {
+ info = storage_info;
}
time_t get_starttime(void) {
diff --git a/storaged/include/storaged_info.h b/storaged/include/storaged_info.h
new file mode 100644
index 000000000..cb5b8a8e2
--- /dev/null
+++ b/storaged/include/storaged_info.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _STORAGED_INFO_H_
+#define _STORAGED_INFO_H_
+
+#include <string.h>
+
+#define FRIEND_TEST(test_case_name, test_name) \
+friend class test_case_name##_##test_name##_Test
+
+using namespace std;
+
+// two characters in string for each byte
+struct str_hex {
+ char str[2];
+};
+
+class storage_info_t {
+protected:
+ FRIEND_TEST(storaged_test, storage_info_t);
+ uint8_t eol; // pre-eol (end of life) information
+ uint8_t lifetime_a; // device life time estimation (type A)
+ uint8_t lifetime_b; // device life time estimation (type B)
+ string version; // version string
+public:
+ void publish();
+ virtual ~storage_info_t() {}
+ virtual bool init() = 0;
+ virtual bool update() = 0;
+};
+
+class emmc_info_t : public storage_info_t {
+private:
+ // minimum size of a ext_csd file
+ const int EXT_CSD_FILE_MIN_SIZE = 1024;
+ // List of interesting offsets
+ const size_t EXT_CSD_REV_IDX = 192 * sizeof(str_hex);
+ const size_t EXT_PRE_EOL_INFO_IDX = 267 * sizeof(str_hex);
+ const size_t EXT_DEVICE_LIFE_TIME_EST_A_IDX = 268 * sizeof(str_hex);
+ const size_t EXT_DEVICE_LIFE_TIME_EST_B_IDX = 269 * sizeof(str_hex);
+
+ const char* ext_csd_file = "/d/mmc0/mmc0:0001/ext_csd";
+ const char* emmc_ver_str[8] = {
+ "4.0", "4.1", "4.2", "4.3", "Obsolete", "4.41", "4.5", "5.0"
+ };
+public:
+ virtual ~emmc_info_t() {}
+ bool init();
+ bool update();
+};
+
+#endif /* _STORAGED_INFO_H_ */