Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7415da6a authored by Hridya Valsaraju's avatar Hridya Valsaraju Committed by android-build-merger
Browse files

Merge "Do not access ext_csd register in debugfs from storaged"

am: 3e80af1d

Change-Id: I5c8aee6b4e98211758e32898362e0675ca213286
parents d62c31d3 3e80af1d
Loading
Loading
Loading
Loading
+3 −55
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ 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] = {
    "4.0", "4.1", "4.2", "4.3", "Obsolete", "4.41", "4.5", "5.0", "5.1"
};
@@ -62,10 +61,8 @@ storage_info_t* storage_info_t::get_storage_info(const sp<IHealth>& healthServic
    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;
    }
    if (FileExists(emmc_info_t::emmc_sysfs)) return new emmc_info_t;

    if (FileExists(ufs_info_t::health_file)) {
        return new ufs_info_t;
    }
@@ -241,8 +238,7 @@ uint32_t storage_info_t::get_recent_perf() {

void emmc_info_t::report()
{
    if (!report_sysfs() && !report_debugfs())
        return;
    if (!report_sysfs()) return;

    publish();
}
@@ -284,54 +280,6 @@ bool emmc_info_t::report_sysfs()
    return true;
}

namespace {

const size_t EXT_CSD_FILE_MIN_SIZE = 1024;
/* 2 characters in string for each byte */
const size_t EXT_CSD_REV_IDX = 192 * 2;
const size_t EXT_PRE_EOL_INFO_IDX = 267 * 2;
const size_t EXT_DEVICE_LIFE_TIME_EST_A_IDX = 268 * 2;
const size_t EXT_DEVICE_LIFE_TIME_EST_B_IDX = 269 * 2;

} // namespace

bool emmc_info_t::report_debugfs()
{
    string buffer;
    uint16_t rev = 0;

    if (!ReadFileToString(emmc_debugfs, &buffer) ||
        buffer.length() < (size_t)EXT_CSD_FILE_MIN_SIZE) {
        return false;
    }

    string str = buffer.substr(EXT_CSD_REV_IDX, 2);
    if (!ParseUint(str, &rev) ||
        rev < 7 || rev > ARRAY_SIZE(emmc_ver_str)) {
        return false;
    }

    version = "emmc ";
    version += emmc_ver_str[rev];

    str = buffer.substr(EXT_PRE_EOL_INFO_IDX, 2);
    if (!ParseUint(str, &eol)) {
        return false;
    }

    str = buffer.substr(EXT_DEVICE_LIFE_TIME_EST_A_IDX, 2);
    if (!ParseUint(str, &lifetime_a)) {
        return false;
    }

    str = buffer.substr(EXT_DEVICE_LIFE_TIME_EST_B_IDX, 2);
    if (!ParseUint(str, &lifetime_b)) {
        return false;
    }

    return true;
}

void ufs_info_t::report()
{
    string buffer;