Adding atoms for metrics logging

Define the atom protos for
UpdateEngineUpdateAttemptReported
UpdateEngineSuccessfulUpdateReported

The fields for both atoms are copied from the already reported Tron
counters, except for the source fingerprint. By defining our own proto,
we can have a better insight about each update events. It also makes the
query easier without the server side work to correlate each counters.

Sample output from testdrive shows:
data {
    elapsed_timestamp_nanos: 64932607816092
    atom {
      update_engine_update_attempt_reported {
        attempt_number: 1
        payload_type: FULL
        duration_boottime_in_minutes: 0
        duration_monotonic_in_minutes: 0
        payload_size_mib: 510
        attempt_result: METADATA_VERIFICATION_FAILED
        error_code: DOWNLOAD_METADATA_SIGNATURE_MISMATCH
        fingerprint: "google/walleye/walleye:R/MASTER/eng.xuncha.20190731.151212:userdebug/dev-keys"
    }
  }
}

Bug: 138253582
Bug: 137682371
Test: run statsd_testdrive and check events

Change-Id: Ic502acc8831fe4da0b32a826171d10e9c0f9876d
Merged-In: Ic502acc8831fe4da0b32a826171d10e9c0f9876d
Merged-In: Ifa57f23135b4cd63888df2b8f25650be133bb1de
(cherry picked from commit 167c3db93401adccc703815a9d71ef057b17e780)
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index c0e414f..d908388 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -50,6 +50,7 @@
 import "frameworks/base/core/proto/android/stats/launcher/launcher.proto";
 import "frameworks/base/core/proto/android/stats/location/location_enums.proto";
 import "frameworks/base/core/proto/android/stats/mediametrics/mediametrics.proto";
+import "frameworks/base/core/proto/android/stats/otaupdate/updateengine_enums.proto";
 import "frameworks/base/core/proto/android/stats/storage/storage_enums.proto";
 import "frameworks/base/core/proto/android/stats/style/style_enums.proto";
 import "frameworks/base/core/proto/android/telecomm/enums.proto";
@@ -322,6 +323,8 @@
         ExclusionRectStateChanged exclusion_rect_state_changed = 223;
         BackGesture back_gesture_reported_reported = 224;
 
+        UpdateEngineUpdateAttemptReported update_engine_update_attempt_reported = 225;
+        UpdateEngineSuccessfulUpdateReported update_engine_successful_update_reported = 226;
         AppCompatibilityChangeReported app_compatibility_change_reported =
             228 [(allow_from_any_uid) = true];
         PerfettoUploaded perfetto_uploaded =
@@ -6894,3 +6897,70 @@
     optional int64 trace_uuid_lsb = 2;
     optional int64 trace_uuid_msb = 3;
 }
+
+/**
+ * Information about an OTA update attempt by update_engine.
+ * Logged from platform/system/update_engine/metrics_reporter_android.cc
+ */
+message UpdateEngineUpdateAttemptReported {
+    // The number of attempts for the update engine to apply a given payload.
+    optional int32 attempt_number = 1;
+
+    optional android.stats.otaupdate.PayloadType payload_type = 2;
+
+    // The total time in minutes for the update engine to apply a given payload.
+    // The time is calculated by calling clock_gettime() / CLOCK_BOOTTIME; and
+    // it's increased when the system is sleeping.
+    optional int32 duration_boottime_in_minutes = 3;
+
+    // The total time in minutes for the update engine to apply a given payload.
+    // The time is calculated by calling clock_gettime() / CLOCK_MONOTONIC_RAW;
+    // and it's not increased when the system is sleeping.
+    optional int32 duration_monotonic_in_minutes = 4;
+
+    // The size of the payload in MiBs.
+    optional int32 payload_size_mib = 5;
+
+    // The attempt result reported by the update engine for an OTA update.
+    optional android.stats.otaupdate.AttemptResult attempt_result = 6;
+
+    // The error code reported by the update engine after an OTA update attempt
+    // on A/B devices.
+    optional android.stats.otaupdate.ErrorCode error_code = 7;
+
+    // The build fingerprint of the source system. The value is read from a
+    // system property when the device takes the update. e.g.
+    // Android/aosp_sailfish/sailfish:10/QP1A.190425.004/5507117:userdebug/test-keys
+    optional string source_fingerprint = 8;
+}
+
+/**
+ * Information about all the attempts the device make before finishing the
+ * successful update.
+ * Logged from platform/system/update_engine/metrics_reporter_android.cc
+ */
+message UpdateEngineSuccessfulUpdateReported {
+    // The number of attempts for the update engine to apply the payload for a
+    // successful update.
+    optional int32 attempt_count = 1;
+
+    optional android.stats.otaupdate.PayloadType payload_type = 2;
+
+    optional int32 payload_size_mib = 3;
+
+    // The total number of bytes downloaded by update_engine since the last
+    // successful update.
+    optional int32 total_bytes_downloaded_mib = 4;
+
+    // The ratio in percentage of the over-downloaded bytes compared to the
+    // total bytes needed to successfully install the update. e.g. 200 if we
+    // download 200MiB in total for a 100MiB package.
+    optional int32 download_overhead_percentage = 5;
+
+    // The total time in minutes for the update engine to apply the payload for a
+    // successful update.
+    optional int32 total_duration_minutes = 6;
+
+    // The number of reboot of the device during a successful update.
+    optional int32 reboot_count = 7;
+}
diff --git a/core/proto/android/stats/otaupdate/updateengine_enums.proto b/core/proto/android/stats/otaupdate/updateengine_enums.proto
new file mode 100644
index 0000000..a6e9919
--- /dev/null
+++ b/core/proto/android/stats/otaupdate/updateengine_enums.proto
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto2";
+package android.stats.otaupdate;
+
+// The payload type of an OTA update attempt on A/B devices.
+enum PayloadType {
+    FULL = 10000;
+    DELTA = 10001;
+}
+
+// The attempt result reported by the update engine for an OTA update.
+enum AttemptResult {
+    UPDATE_SUCCEEDED = 10000;
+    INTERNAL_ERROR = 10001;
+    PAYLOAD_DOWNLOAD_ERROR = 10002;
+    METADATA_MALFORMED = 10003;
+    OPERATION_MALFORMED = 10004;
+    OPERATION_EXECUTION_ERROR = 10005;
+    METADATA_VERIFICATION_FAILED = 10006;
+    PAYLOAD_VERIFICATION_FAILED = 10007;
+    VERIFICATION_FAILED = 10008;
+    POSTINSTALL_FAILED = 10009;
+    ABNORMAL_TERMINATION = 10010;
+    UPDATE_CANCELED = 10011;
+    UPDATE_SUCCEEDED_NOT_ACTIVE = 10012;
+}
+
+// The error code reported by the update engine after an OTA update attempt
+// on A/B devices. More details in system/update_engine/common/error_code.h
+enum ErrorCode {
+    SUCCESS = 10000;
+    ERROR = 10001;
+    FILESYSTEM_COPIER_ERROR = 10004;
+    POST_INSTALL_RUNNER_ERROR = 10005;
+    PAYLOAD_MISMATCHED_TYPE_ERROR = 10006;
+    INSTALL_DEVICE_OPEN_ERROR = 10007;
+    KERNEL_DEVICE_OPEN_ERROR = 10008;
+    DOWNLOAD_TRANSFER_ERROR = 10009;
+    PAYLOAD_HASH_MISMATCH_ERROR = 10010;
+    PAYLOAD_SIZE_MISMATCH_ERROR = 10011;
+    DOWNLOAD_PAYLOAD_VERIFICATION_ERROR = 10012;
+    DOWNLOAD_NEW_PARTITION_INFO_ERROR = 10013;
+    DOWNLOAD_WRITE_ERROR = 10014;
+    NEW_ROOTFS_VERIFICATION_ERROR = 10015;
+    SIGNED_DELTA_PAYLOAD_EXPECTED_ERROR = 10017;
+    DOWNLOAD_PAYLOAD_PUB_KEY_VERIFICATION_ERROR = 10018;
+    DOWNLOAD_STATE_INITIALIZATION_ERROR = 10020;
+    DOWNLOAD_INVALID_METADATA_MAGIC_STRING = 10021;
+    DOWNLOAD_SIGNATURE_MISSING_IN_MANIFEST = 10022;
+    DOWNLOAD_MANIFEST_PARSE_ERROR = 10023;
+    DOWNLOAD_METADATA_SIGNATURE_ERROR = 10024;
+    DOWNLOAD_METADATA_SIGNATURE_VERIFICATION_ERROR = 10025;
+    DOWNLOAD_METADATA_SIGNATURE_MISMATCH = 10026;
+    DOWNLOAD_OPERATION_HASH_VERIFICATION_ERROR = 10027;
+    DOWNLOAD_OPERATION_EXECUTION_ERROR = 10028;
+    DOWNLOAD_OPERATION_HASH_MISMATCH = 10029;
+    DOWNLOAD_INVALID_METADATA_SIZE = 10032;
+    DOWNLOAD_INVALID_METADATA_SIGNATURE = 10033;
+    DOWNLOAD_OPERATION_HASH_MISSING_ERROR = 10038;
+    DOWNLOAD_METADATA_SIGNATURE_MISSING_ERROR = 10039;
+    UNSUPPORTED_MAJOR_PAYLOAD_VERSION = 10044;
+    UNSUPPORTED_MINOR_PAYLOAD_VERSION = 10045;
+    FILESYSTEM_VERIFIER_ERROR = 10047;
+    USER_CANCELED = 10048;
+    PAYLOAD_TIMESTAMP_ERROR = 10051;
+    UPDATED_BUT_NOT_ACTIVE = 10052;
+}