Merge "Import TLS handshake atom for Conscrypt"
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index 12ef9ba..cca6299 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -58,6 +58,7 @@
 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/stats/sysui/notification_enums.proto";
+import "frameworks/base/core/proto/android/stats/tls/enums.proto";
 import "frameworks/base/core/proto/android/telecomm/enums.proto";
 import "frameworks/base/core/proto/android/telephony/enums.proto";
 import "frameworks/base/core/proto/android/view/enums.proto";
@@ -485,6 +486,7 @@
         NetworkTetheringReported  network_tethering_reported =
             303 [(module) = "network_tethering"];
         ImeTouchReported ime_touch_reported = 304 [(module) = "sysui"];
+        TlsHandshakeReported tls_handshake_reported = 317 [(module) = "conscrypt"];
 
         // StatsdStats tracks platform atoms with ids upto 500.
         // Update StatsdStats::kMaxPushedAtomId when atom ids here approach that value.
@@ -11197,3 +11199,19 @@
     // List of leasees of this Blob
     optional BlobLeaseeListProto leasees = 5;
 }
+
+/**
+  * Pushes TLS handshake counters from Conscrypt.
+  * Pulled from:
+  *   external/conscrypt/common/src/main/java/org/conscrypt/ConscryptEngineSocket.java
+  *   external/conscrypt/common/src/main/java/org/conscrypt/ConscryptFileDescriptorSocket.java
+  */
+  message TlsHandshakeReported {
+    optional bool success = 1;
+
+    optional android.stats.tls.Protocol protocol = 2;
+
+    optional android.stats.tls.CipherSuite cipher_suite = 3;
+
+    optional int32 handshake_duration_millis = 4;
+}
diff --git a/core/proto/android/stats/tls/enums.proto b/core/proto/android/stats/tls/enums.proto
new file mode 100644
index 0000000..1777d69
--- /dev/null
+++ b/core/proto/android/stats/tls/enums.proto
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2020 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.tls;
+
+// Keep in sync with
+// external/conscrypt/{android,platform}/src/main/java/org/conscrypt/Platform.java
+enum Protocol {
+    UNKNOWN_PROTO = 0;
+    SSL_V3 = 1;
+    TLS_V1 = 2;
+    TLS_V1_1 = 3;
+    TLS_V1_2 = 4;
+    TLS_V1_3 = 5;
+}
+
+// Cipher suites' ids are based on IANA's database:
+// https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-4
+//
+// If you add new cipher suite, make sure id is the same as in  IANA's database (see link above)
+//
+// Keep in sync with
+// external/conscrypt/{android,platform}/src/main/java/org/conscrypt/Platform.java
+enum CipherSuite {
+    UNKNOWN_CIPHER_SUITE = 0x0000;
+
+    TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA = 0xC00A;
+    TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = 0xC014;
+    TLS_RSA_WITH_AES_256_CBC_SHA = 0x0035;
+    TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA = 0xC009;
+    TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA = 0xC013;
+    TLS_RSA_WITH_AES_128_CBC_SHA = 0x002F;
+    TLS_RSA_WITH_3DES_EDE_CBC_SHA = 0x000A;
+
+    // TLSv1.2 cipher suites
+    TLS_RSA_WITH_AES_128_GCM_SHA256 = 0x009C;
+    TLS_RSA_WITH_AES_256_GCM_SHA384 = 0x009D;
+    TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 = 0xC02F;
+    TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 = 0xC030;
+    TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 = 0xC02B;
+    TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 = 0xC02C;
+    TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 = 0xCCA9;
+    TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = 0xCCA8;
+
+    // Pre-Shared Key (PSK) cipher suites
+    TLS_PSK_WITH_AES_128_CBC_SHA = 0x008C;
+    TLS_PSK_WITH_AES_256_CBC_SHA = 0x008D;
+    TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA = 0xC035;
+    TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA = 0xC036;
+    TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 = 0xCCAC;
+
+    // TLS 1.3 cipher suites
+    TLS_AES_128_GCM_SHA256 = 0x1301;
+    TLS_AES_256_GCM_SHA384 = 0x1302;
+    TLS_CHACHA20_POLY1305_SHA256 = 0x1303;
+}
\ No newline at end of file