Update TrainInfo and BinaryPushStateChanged atoms
Add trainName string field to TrainInfo atom
Add status enum to TrainInfo atom
Add additional states to BinaryPushStateChanged.State
Bug: 124397500
Bug: 126787525
Bug: 126780868
Test: add/edit tests in StorageManagerTest to verify new
serialization/deserialization logic
Change-Id: I7bf4cd3b3cb4fdb8b1ebe51a602cfde9fdace6e1
diff --git a/cmds/statsd/src/StatsService.cpp b/cmds/statsd/src/StatsService.cpp
index 9ac888b..1526d66 100644
--- a/cmds/statsd/src/StatsService.cpp
+++ b/cmds/statsd/src/StatsService.cpp
@@ -1210,20 +1210,22 @@
(long long)expId);
}
- vector<uint8_t> buffer;
- buffer.resize(proto.size());
+ vector<uint8_t> experimentIdsProtoBuffer;
+ experimentIdsProtoBuffer.resize(proto.size());
size_t pos = 0;
auto iter = proto.data();
while (iter.readBuffer() != NULL) {
size_t toRead = iter.currentToRead();
- std::memcpy(&(buffer[pos]), iter.readBuffer(), toRead);
+ std::memcpy(&(experimentIdsProtoBuffer[pos]), iter.readBuffer(), toRead);
pos += toRead;
iter.rp()->move(toRead);
}
- LogEvent event(std::string(String8(trainName).string()), trainVersionCode, requiresStaging,
- rollbackEnabled, requiresLowLatencyMonitor, state, buffer, userId);
+
+ std::string trainNameUtf8 = std::string(String8(trainName).string());
+ LogEvent event(trainNameUtf8, trainVersionCode, requiresStaging, rollbackEnabled,
+ requiresLowLatencyMonitor, state, experimentIdsProtoBuffer, userId);
mProcessor->OnLogEvent(&event);
- StorageManager::writeTrainInfo(trainVersionCode, buffer);
+ StorageManager::writeTrainInfo(trainVersionCode, trainNameUtf8, state, experimentIdsProtoBuffer);
return Status::ok();
}
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index 5968fa8..4fd212c 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -3240,8 +3240,18 @@
INSTALL_FAILURE = 6;
INSTALL_CANCELLED = 7;
INSTALLER_ROLLBACK_REQUESTED = 8;
- INSTALLER_ROLLBACK_SUCCESS = 9;
- INSTALLER_ROLLBACK_FAILURE = 10;
+ INSTALLER_ROLLBACK_INITIATED = 9;
+ INSTALLER_ROLLBACK_INITIATED_FAILURE = 10;
+ INSTALLER_ROLLBACK_STAGED = 11;
+ INSTALLER_ROLLBACK_STAGED_FAILURE = 12;
+ INSTALLER_ROLLBACK_BOOT_TRIGGERED = 13;
+ INSTALLER_ROLLBACK_BOOT_TRIGGERED_FAILURE = 14;
+ INSTALLER_ROLLBACK_SUCCESS = 15;
+ INSTALLER_ROLLBACK_FAILURE = 16;
+ INSTALLER_ROLLBACK_CANCEL_STAGED_REMOVE_FROM_QUEUE = 17;
+ INSTALLER_ROLLBACK_CANCEL_STAGED_DELETE_SESSION_INITIATED = 18;
+ INSTALLER_ROLLBACK_CANCEL_STAGED_DELETE_SESSION_SUCCESS = 19;
+ INSTALLER_ROLLBACK_CANCEL_STAGED_DELETE_SESSION_FAILURE = 20;
}
optional State state = 6;
// Possible experiment ids for monitoring this push.
@@ -5650,6 +5660,33 @@
optional int64 train_version_code = 1;
optional TrainExperimentIds train_experiment_id = 2;
+
+ optional string train_name = 3;
+
+ enum Status {
+ UNKNOWN = 0;
+ INSTALL_REQUESTED = 1;
+ INSTALL_STARTED = 2;
+ INSTALL_STAGED_NOT_READY = 3;
+ INSTALL_STAGED_READY = 4;
+ INSTALL_SUCCESS = 5;
+ INSTALL_FAILURE = 6;
+ INSTALL_CANCELLED = 7;
+ INSTALLER_ROLLBACK_REQUESTED = 8;
+ INSTALLER_ROLLBACK_INITIATED = 9;
+ INSTALLER_ROLLBACK_INITIATED_FAILURE = 10;
+ INSTALLER_ROLLBACK_STAGED = 11;
+ INSTALLER_ROLLBACK_STAGED_FAILURE = 12;
+ INSTALLER_ROLLBACK_BOOT_TRIGGERED = 13;
+ INSTALLER_ROLLBACK_BOOT_TRIGGERED_FAILURE = 14;
+ INSTALLER_ROLLBACK_SUCCESS = 15;
+ INSTALLER_ROLLBACK_FAILURE = 16;
+ INSTALLER_ROLLBACK_CANCEL_STAGED_REMOVE_FROM_QUEUE = 17;
+ INSTALLER_ROLLBACK_CANCEL_STAGED_DELETE_SESSION_INITIATED = 18;
+ INSTALLER_ROLLBACK_CANCEL_STAGED_DELETE_SESSION_SUCCESS = 19;
+ INSTALLER_ROLLBACK_CANCEL_STAGED_DELETE_SESSION_FAILURE = 20;
+ }
+ optional Status status = 4;
}
/**
diff --git a/cmds/statsd/src/logd/LogEvent.cpp b/cmds/statsd/src/logd/LogEvent.cpp
index 0430e4e..d9f5415 100644
--- a/cmds/statsd/src/logd/LogEvent.cpp
+++ b/cmds/statsd/src/logd/LogEvent.cpp
@@ -238,9 +238,12 @@
mLogdTimestampNs = wallClockTimestampNs;
mElapsedTimestampNs = elapsedTimestampNs;
mTagId = android::util::TRAIN_INFO;
+
mValues.push_back(
FieldValue(Field(mTagId, getSimpleField(1)), Value(trainInfo.trainVersionCode)));
mValues.push_back(FieldValue(Field(mTagId, getSimpleField(2)), Value(trainInfo.experimentIds)));
+ mValues.push_back(FieldValue(Field(mTagId, getSimpleField(3)), Value(trainInfo.trainName)));
+ mValues.push_back(FieldValue(Field(mTagId, getSimpleField(4)), Value(trainInfo.status)));
}
LogEvent::LogEvent(int32_t tagId, int64_t timestampNs) : LogEvent(tagId, timestampNs, 0) {}
diff --git a/cmds/statsd/src/logd/LogEvent.h b/cmds/statsd/src/logd/LogEvent.h
index 2fde8b4..753a9a5 100644
--- a/cmds/statsd/src/logd/LogEvent.h
+++ b/cmds/statsd/src/logd/LogEvent.h
@@ -58,6 +58,8 @@
struct InstallTrainInfo {
int64_t trainVersionCode;
+ std::string trainName;
+ int32_t status;
std::vector<uint8_t> experimentIds;
};
/**
diff --git a/cmds/statsd/src/storage/StorageManager.cpp b/cmds/statsd/src/storage/StorageManager.cpp
index 165e57c..5df8fb5 100644
--- a/cmds/statsd/src/storage/StorageManager.cpp
+++ b/cmds/statsd/src/storage/StorageManager.cpp
@@ -95,8 +95,8 @@
close(fd);
}
-bool StorageManager::writeTrainInfo(int64_t trainVersionCode,
- const std::vector<uint8_t>& experimentIds) {
+bool StorageManager::writeTrainInfo(int64_t trainVersionCode, const std::string& trainName,
+ int32_t status, const std::vector<uint8_t>& experimentIds) {
std::lock_guard<std::mutex> lock(sTrainInfoMutex);
deleteAllFiles(TRAIN_INFO_DIR);
@@ -109,7 +109,34 @@
return false;
}
- size_t result = write(fd, experimentIds.data(), experimentIds.size());
+ size_t result;
+
+ // Write # of bytes in trainName to file
+ const size_t trainNameSize = trainName.size();
+ const size_t trainNameSizeByteCount = sizeof(trainNameSize);
+ result = write(fd, (uint8_t*)&trainNameSize, trainNameSizeByteCount);
+ if (result != trainNameSizeByteCount) {
+ VLOG("Failed to write %s", file_name.c_str());
+ return false;
+ }
+
+ // Write trainName to file
+ result = write(fd, trainName.c_str(), trainNameSize);
+ if (result != trainNameSize) {
+ VLOG("Failed to write %s", file_name.c_str());
+ return false;
+ }
+
+ // Write status to file
+ const size_t statusByteCount = sizeof(status);
+ result = write(fd, (uint8_t*)&status, statusByteCount);
+ if (result != statusByteCount) {
+ VLOG("Failed to write %s", file_name.c_str());
+ return false;
+ }
+
+ // Write experimentIds to file
+ result = write(fd, experimentIds.data(), experimentIds.size());
if (result == experimentIds.size()) {
VLOG("Successfully wrote %s", file_name.c_str());
} else {
@@ -150,7 +177,27 @@
string str;
if (android::base::ReadFdToString(fd, &str)) {
close(fd);
- std::copy(str.begin(), str.end(), std::back_inserter(trainInfo.experimentIds));
+
+ auto it = str.begin();
+
+ // Read # of bytes taken by trainName in the file
+ size_t trainNameSize;
+ const size_t trainNameSizeByteCount = sizeof(trainNameSize);
+ std::copy_n(it, trainNameSizeByteCount, &trainNameSize);
+ it += trainNameSizeByteCount;
+
+ // Read trainName
+ std::copy_n(it, trainNameSize, std::back_inserter(trainInfo.trainName));
+ it += trainNameSize;
+
+ // Read status
+ const size_t statusByteCount = sizeof(trainInfo.status);
+ std::copy_n(it, statusByteCount, &trainInfo.status);
+ it += statusByteCount;
+
+ // Read experimentIds
+ std::copy(it, str.end(), std::back_inserter(trainInfo.experimentIds));
+
VLOG("Read train info file successful: %s", fullPath.c_str());
return true;
}
diff --git a/cmds/statsd/src/storage/StorageManager.h b/cmds/statsd/src/storage/StorageManager.h
index d6df867..88280cf 100644
--- a/cmds/statsd/src/storage/StorageManager.h
+++ b/cmds/statsd/src/storage/StorageManager.h
@@ -44,7 +44,8 @@
/**
* Writes train info.
*/
- static bool writeTrainInfo(int64_t trainVersionCode, const std::vector<uint8_t>& experimentIds);
+ static bool writeTrainInfo(int64_t trainVersionCode, const std::string& trainName,
+ int32_t status, const std::vector<uint8_t>& experimentIds);
/**
* Reads train info.