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

Commit ec5aa591 authored by Josh Gao's avatar Josh Gao
Browse files

adb: don't cache failure to get features.

When we're waiting for the device to show up (e.g. `adb logcat` with the
device not connected), we can transition from the feature set being
unavailable to being available.

Test: `adb logcat` with device disconnected
Change-Id: I5c93a725605c886cba2c66daa25b484c90a170ec
parent 227dd4f8
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -417,17 +417,19 @@ std::string format_host_command(const char* command) {
}

const std::optional<FeatureSet>& adb_get_feature_set(std::string* error) {
    static std::string cached_error [[clang::no_destroy]];
    static const std::optional<FeatureSet> features
            [[clang::no_destroy]] ([]() -> std::optional<FeatureSet> {
    static std::mutex feature_mutex [[clang::no_destroy]];
    static std::optional<FeatureSet> features [[clang::no_destroy]] GUARDED_BY(feature_mutex);
    std::lock_guard<std::mutex> lock(feature_mutex);
    if (!features) {
        std::string result;
                if (adb_query(format_host_command("features"), &result, &cached_error)) {
                    return StringToFeatureSet(result);
        std::string err;
        if (adb_query(format_host_command("features"), &result, &err)) {
            features = StringToFeatureSet(result);
        } else {
            if (error) {
                *error = err;
            }
        }
                return std::nullopt;
            }());
    if (!features && error) {
        *error = cached_error;
    }
    return features;
}