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

Commit bbe311c0 authored by Jonathan Nguyen's avatar Jonathan Nguyen Committed by Tej Singh
Browse files

Maintain existing train information

When sendBinaryPushStateChangedAtom is called with empty train
name/version/experiment ids, populate the empty fields from the
trainInfo previously stored on disk if possible.

If no train info is on disk (or read fails), the empty fields are passed
through.

Test: gts in ag/6731864
Test: testdrive 10051 with partially/completely missing train info
Bug: 128640419

Change-Id: Iea3c2db5c11d07f0b42b41aec7b2d7913a99ca03
parent a3e9de11
Loading
Loading
Loading
Loading
+36 −18
Original line number Diff line number Diff line
@@ -1198,19 +1198,26 @@ Status StatsService::sendBinaryPushStateChangedAtom(const android::String16& tra
    }
    // TODO: add verifier permission

    userid_t userId = multiuser_get_user_id(uid);
    bool readTrainInfoSuccess = false;
    InstallTrainInfo trainInfo;
    if (trainVersionCode == -1 || experimentIds.empty() || trainName.size() == 0) {
        readTrainInfoSuccess = StorageManager::readTrainInfo(trainInfo);
    }

    bool requiresStaging = options & IStatsManager::FLAG_REQUIRE_STAGING;
    bool rollbackEnabled = options & IStatsManager::FLAG_ROLLBACK_ENABLED;
    bool requiresLowLatencyMonitor = options & IStatsManager::FLAG_REQUIRE_LOW_LATENCY_MONITOR;
    if (trainVersionCode == -1 && readTrainInfoSuccess) {
        trainVersionCode = trainInfo.trainVersionCode;
    }

    vector<uint8_t> experimentIdsProtoBuffer;
    if (readTrainInfoSuccess && experimentIds.empty()) {
        experimentIdsProtoBuffer = trainInfo.experimentIds;
    } else {
        ProtoOutputStream proto;
        for (const auto& expId : experimentIds) {
            proto.write(FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED | FIELD_ID_EXPERIMENT_ID,
                        (long long)expId);
        }

    vector<uint8_t> experimentIdsProtoBuffer;
        experimentIdsProtoBuffer.resize(proto.size());
        size_t pos = 0;
        auto iter = proto.data();
@@ -1220,8 +1227,19 @@ Status StatsService::sendBinaryPushStateChangedAtom(const android::String16& tra
            pos += toRead;
            iter.rp()->move(toRead);
        }
    }

    std::string trainNameUtf8;
    if (readTrainInfoSuccess && trainName.size() == 0) {
        trainNameUtf8 = trainInfo.trainName;
    } else {
        trainNameUtf8 = std::string(String8(trainName).string());
    }

    std::string trainNameUtf8 = std::string(String8(trainName).string());
    userid_t userId = multiuser_get_user_id(uid);
    bool requiresStaging = options & IStatsManager::FLAG_REQUIRE_STAGING;
    bool rollbackEnabled = options & IStatsManager::FLAG_ROLLBACK_ENABLED;
    bool requiresLowLatencyMonitor = options & IStatsManager::FLAG_REQUIRE_LOW_LATENCY_MONITOR;
    LogEvent event(trainNameUtf8, trainVersionCode, requiresStaging, rollbackEnabled,
                   requiresLowLatencyMonitor, state, experimentIdsProtoBuffer, userId);
    mProcessor->OnLogEvent(&event);