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

Commit e5f82927 authored by yro's avatar yro
Browse files

Fix adb shell cmd config remove command when no (uid, id) pair is

specified.

- Previous logic was omitting commands when only 'adb shell cmd config
remove' was provided without any uid, id argument. This change fixes it.
- Recent disk guardrail change flips the convention of file name in
statsd directories to begin with timestamps. So delete with prefix was
changed to delete with suffix.

Bug: 72265185
Test: manual testing, statsd_test
Change-Id: Ia727fbc7acf0d9268b9f4952fa59975f4a9134cb
parent f74e56af
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -380,6 +380,8 @@ status_t StatsService::cmd_config(FILE* in, FILE* out, FILE* err, Vector<String8
                            "The config can only be set for other UIDs on eng or userdebug "
                            "builds.\n");
                }
            } else if (argCount == 2 && args[1] == "remove") {
                good = true;
            }

            if (!good) {
+3 −2
Original line number Diff line number Diff line
@@ -101,8 +101,8 @@ void ConfigManager::RemoveConfig(const ConfigKey& key) {
}

void ConfigManager::remove_saved_configs(const ConfigKey& key) {
    string prefix = StringPrintf("%d-%lld", key.GetUid(), (long long)key.GetId());
    StorageManager::deletePrefixedFiles(STATS_SERVICE_DIR, prefix.c_str());
    string suffix = StringPrintf("%d-%lld", key.GetUid(), (long long)key.GetId());
    StorageManager::deleteSuffixedFiles(STATS_SERVICE_DIR, suffix.c_str());
}

void ConfigManager::RemoveConfigs(int uid) {
@@ -111,6 +111,7 @@ void ConfigManager::RemoveConfigs(int uid) {
    for (auto it = mConfigs.begin(); it != mConfigs.end();) {
        // Remove from map
        if (it->GetUid() == uid) {
            remove_saved_configs(*it);
            removed.push_back(*it);
            mConfigReceivers.erase(*it);
            it = mConfigs.erase(it);
+7 −3
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ void StorageManager::deleteAllFiles(const char* path) {
    }
}

void StorageManager::deletePrefixedFiles(const char* path, const char* prefix) {
void StorageManager::deleteSuffixedFiles(const char* path, const char* suffix) {
    unique_ptr<DIR, decltype(&closedir)> dir(opendir(path), closedir);
    if (dir == NULL) {
        VLOG("Directory does not exist: %s", path);
@@ -88,12 +88,16 @@ void StorageManager::deletePrefixedFiles(const char* path, const char* prefix) {
    dirent* de;
    while ((de = readdir(dir.get()))) {
        char* name = de->d_name;
        if (name[0] == '.' || strncmp(name, prefix, strlen(prefix)) != 0) {
        if (name[0] == '.') {
            continue;
        }
        size_t nameLen = strlen(name);
        size_t suffixLen = strlen(suffix);
        if (suffixLen <= nameLen && strncmp(name + nameLen - suffixLen, suffix, suffixLen) == 0) {
            deleteFile(StringPrintf("%s/%s", path, name).c_str());
        }
    }
}

void StorageManager::sendBroadcast(const char* path,
                                   const std::function<void(const ConfigKey&)>& sendBroadcast) {
+2 −2
Original line number Diff line number Diff line
@@ -47,9 +47,9 @@ public:
    static void deleteAllFiles(const char* path);

    /**
     * Deletes all files whose name matches with a provided prefix.
     * Deletes all files whose name matches with a provided suffix.
     */
    static void deletePrefixedFiles(const char* path, const char* prefix);
    static void deleteSuffixedFiles(const char* path, const char* suffix);

    /**
     * Send broadcasts to relevant receiver for each data stored on disk.