Adding privacy tags to graphicsstats proto.

Creating a copy of the graphicsstats proto so that one can be tagged
with privacy annotations and the other can be used internally while
still using the protobuf-cpp-lite library.

This is the same change as the pi-dev one (http://ag/3841646), but due
to changes in master, that change has a merge conflict, so I have to
create a separate CL for master.

Bug: 72570104
Test: it builds
Change-Id: I2d72e7bd17689c1401a16d5a13956e6528ddb525
diff --git a/core/proto/android/service/graphicsstats.proto b/core/proto/android/service/graphicsstats.proto
index c2fedf5..d75f135 100644
--- a/core/proto/android/service/graphicsstats.proto
+++ b/core/proto/android/service/graphicsstats.proto
@@ -20,11 +20,19 @@
 option java_multiple_files = true;
 option java_outer_classname = "GraphicsStatsServiceProto";
 
+import "frameworks/base/libs/incident/proto/android/privacy.proto";
+
+// This file is based on frameworks/base/libs/hwui/protos/graphicsstats.proto.
+// Please try to keep the two files in sync.
+
 message GraphicsStatsServiceDumpProto {
+    option (android.msg_privacy).dest = DEST_AUTOMATIC;
+
     repeated GraphicsStatsProto stats = 1;
 }
 
 message GraphicsStatsProto {
+    option (android.msg_privacy).dest = DEST_AUTOMATIC;
 
     // The package name of the app
     optional string package_name = 1;
@@ -46,6 +54,8 @@
 }
 
 message GraphicsStatsJankSummaryProto {
+    option (android.msg_privacy).dest = DEST_AUTOMATIC;
+
     // Distinct frame count.
     optional int32 total_frames = 1;
 
@@ -73,6 +83,8 @@
 }
 
 message GraphicsStatsHistogramBucketProto {
+    option (android.msg_privacy).dest = DEST_AUTOMATIC;
+
     // Lower bound of render time in milliseconds.
     optional int32 render_millis = 1;
     // Number of frames in the bucket.
diff --git a/libs/hwui/Android.bp b/libs/hwui/Android.bp
index de4eaf5..3b0abc3 100644
--- a/libs/hwui/Android.bp
+++ b/libs/hwui/Android.bp
@@ -69,7 +69,6 @@
         "libRScpp",
     ],
     static_libs: [
-        "libplatformprotos",
         "libEGL_blobCache",
     ],
 }
@@ -269,8 +268,13 @@
         "TextureCache.cpp",
         "VectorDrawable.cpp",
         "VkLayer.cpp",
+        "protos/graphicsstats.proto",
     ],
 
+    proto: {
+        export_proto_headers: true,
+    },
+
     export_include_dirs: ["."],
     export_shared_lib_headers: ["libRScpp"],
 }
diff --git a/libs/hwui/protos/graphicsstats.proto b/libs/hwui/protos/graphicsstats.proto
new file mode 100644
index 0000000..1226d44
--- /dev/null
+++ b/libs/hwui/protos/graphicsstats.proto
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2017 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.uirenderer.protos;
+
+option optimize_for = LITE_RUNTIME;
+
+// frameworks/base/core/proto/android/service/graphicsstats.proto is based on
+// this proto. Please only make valid protobuf changes to these messages, and
+// keep the other file in sync with this one.
+
+message GraphicsStatsServiceDumpProto {
+    repeated GraphicsStatsProto stats = 1;
+}
+
+message GraphicsStatsProto {
+    // The package name of the app
+    optional string package_name = 1;
+
+    // The version code of the app
+    optional int64 version_code = 2;
+
+    // The start & end timestamps in UTC as
+    // milliseconds since January 1, 1970
+    // Compatible with java.util.Date#setTime()
+    optional int64 stats_start = 3;
+    optional int64 stats_end = 4;
+
+    // The aggregated statistics for the package
+    optional GraphicsStatsJankSummaryProto summary = 5;
+
+    // The frame time histogram for the package
+    repeated GraphicsStatsHistogramBucketProto histogram = 6;
+}
+
+message GraphicsStatsJankSummaryProto {
+    // Distinct frame count.
+    optional int32 total_frames = 1;
+
+    // Number of frames with slow render time. Frames are considered janky if
+    // they took more than a vsync interval (typically 16.667ms) to be rendered.
+    optional int32 janky_frames = 2;
+
+    // Number of "missed vsync" events.
+    optional int32 missed_vsync_count = 3;
+
+    // Number of frames in triple-buffering scenario (high input latency)
+    optional int32 high_input_latency_count = 4;
+
+    // Number of "slow UI thread" events.
+    optional int32 slow_ui_thread_count = 5;
+
+    // Number of "slow bitmap upload" events.
+    optional int32 slow_bitmap_upload_count = 6;
+
+    // Number of "slow draw" events.
+    optional int32 slow_draw_count = 7;
+
+    // Number of frames that missed their deadline (aka, visibly janked)
+    optional int32 missed_deadline_count = 8;
+}
+
+message GraphicsStatsHistogramBucketProto {
+    // Lower bound of render time in milliseconds.
+    optional int32 render_millis = 1;
+    // Number of frames in the bucket.
+    optional int32 frame_count = 2;
+}
diff --git a/libs/hwui/service/GraphicsStatsService.cpp b/libs/hwui/service/GraphicsStatsService.cpp
index 599226b..7f8cb2d 100644
--- a/libs/hwui/service/GraphicsStatsService.cpp
+++ b/libs/hwui/service/GraphicsStatsService.cpp
@@ -17,8 +17,8 @@
 #include "GraphicsStatsService.h"
 
 #include "JankTracker.h"
+#include "protos/graphicsstats.pb.h"
 
-#include <frameworks/base/core/proto/android/service/graphicsstats.pb.h>
 #include <google/protobuf/io/zero_copy_stream_impl_lite.h>
 #include <log/log.h>
 
@@ -41,10 +41,10 @@
 
 constexpr int sHistogramSize = ProfileData::HistogramSize();
 
-static bool mergeProfileDataIntoProto(service::GraphicsStatsProto* proto,
+static bool mergeProfileDataIntoProto(protos::GraphicsStatsProto* proto,
                                       const std::string& package, int64_t versionCode,
                                       int64_t startTime, int64_t endTime, const ProfileData* data);
-static void dumpAsTextToFd(service::GraphicsStatsProto* proto, int outFd);
+static void dumpAsTextToFd(protos::GraphicsStatsProto* proto, int outFd);
 
 class FileDescriptor {
 public:
@@ -104,7 +104,7 @@
 };
 
 bool GraphicsStatsService::parseFromFile(const std::string& path,
-                                         service::GraphicsStatsProto* output) {
+                                         protos::GraphicsStatsProto* output) {
     FileDescriptor fd{open(path.c_str(), O_RDONLY)};
     if (!fd.valid()) {
         int err = errno;
@@ -153,7 +153,7 @@
     return success;
 }
 
-bool mergeProfileDataIntoProto(service::GraphicsStatsProto* proto, const std::string& package,
+bool mergeProfileDataIntoProto(protos::GraphicsStatsProto* proto, const std::string& package,
                                int64_t versionCode, int64_t startTime, int64_t endTime,
                                const ProfileData* data) {
     if (proto->stats_start() == 0 || proto->stats_start() > startTime) {
@@ -193,7 +193,7 @@
     data->histogramForEach([&](ProfileData::HistogramEntry entry) {
         if (hitMergeError) return;
 
-        service::GraphicsStatsHistogramBucketProto* bucket;
+        protos::GraphicsStatsHistogramBucketProto* bucket;
         if (creatingHistogram) {
             bucket = proto->add_histogram();
             bucket->set_render_millis(entry.renderTimeMs);
@@ -212,7 +212,7 @@
     return !hitMergeError;
 }
 
-static int32_t findPercentile(service::GraphicsStatsProto* proto, int percentile) {
+static int32_t findPercentile(protos::GraphicsStatsProto* proto, int percentile) {
     int32_t pos = percentile * proto->summary().total_frames() / 100;
     int32_t remaining = proto->summary().total_frames() - pos;
     for (auto it = proto->histogram().rbegin(); it != proto->histogram().rend(); ++it) {
@@ -224,7 +224,7 @@
     return 0;
 }
 
-void dumpAsTextToFd(service::GraphicsStatsProto* proto, int fd) {
+void dumpAsTextToFd(protos::GraphicsStatsProto* proto, int fd) {
     // This isn't a full validation, just enough that we can deref at will
     if (proto->package_name().empty() || !proto->has_summary()) {
         ALOGW("Skipping dump, invalid package_name() '%s' or summary %d",
@@ -259,7 +259,7 @@
 void GraphicsStatsService::saveBuffer(const std::string& path, const std::string& package,
                                       int64_t versionCode, int64_t startTime, int64_t endTime,
                                       const ProfileData* data) {
-    service::GraphicsStatsProto statsProto;
+    protos::GraphicsStatsProto statsProto;
     if (!parseFromFile(path, &statsProto)) {
         statsProto.Clear();
     }
@@ -310,12 +310,12 @@
     Dump(int outFd, DumpType type) : mFd(outFd), mType(type) {}
     int fd() { return mFd; }
     DumpType type() { return mType; }
-    service::GraphicsStatsServiceDumpProto& proto() { return mProto; }
+    protos::GraphicsStatsServiceDumpProto& proto() { return mProto; }
 
 private:
     int mFd;
     DumpType mType;
-    service::GraphicsStatsServiceDumpProto mProto;
+    protos::GraphicsStatsServiceDumpProto mProto;
 };
 
 GraphicsStatsService::Dump* GraphicsStatsService::createDump(int outFd, DumpType type) {
@@ -325,7 +325,7 @@
 void GraphicsStatsService::addToDump(Dump* dump, const std::string& path,
                                      const std::string& package, int64_t versionCode,
                                      int64_t startTime, int64_t endTime, const ProfileData* data) {
-    service::GraphicsStatsProto statsProto;
+    protos::GraphicsStatsProto statsProto;
     if (!path.empty() && !parseFromFile(path, &statsProto)) {
         statsProto.Clear();
     }
@@ -347,7 +347,7 @@
 }
 
 void GraphicsStatsService::addToDump(Dump* dump, const std::string& path) {
-    service::GraphicsStatsProto statsProto;
+    protos::GraphicsStatsProto statsProto;
     if (!parseFromFile(path, &statsProto)) {
         return;
     }
diff --git a/libs/hwui/service/GraphicsStatsService.h b/libs/hwui/service/GraphicsStatsService.h
index bce0f3d..389f599 100644
--- a/libs/hwui/service/GraphicsStatsService.h
+++ b/libs/hwui/service/GraphicsStatsService.h
@@ -22,12 +22,11 @@
 #include "utils/Macros.h"
 
 namespace android {
-namespace service {
+namespace uirenderer {
+namespace protos {
 class GraphicsStatsProto;
 }
 
-namespace uirenderer {
-
 /*
  * The exported entry points used by GraphicsStatsService.java in f/b/services/core
  *
@@ -55,8 +54,8 @@
     ANDROID_API static void finishDump(Dump* dump);
 
     // Visible for testing
-    static bool parseFromFile(const std::string& path, service::GraphicsStatsProto* output);
+    static bool parseFromFile(const std::string& path, protos::GraphicsStatsProto* output);
 };
 
 } /* namespace uirenderer */
-} /* namespace android */
\ No newline at end of file
+} /* namespace android */
diff --git a/libs/hwui/tests/unit/GraphicsStatsServiceTests.cpp b/libs/hwui/tests/unit/GraphicsStatsServiceTests.cpp
index 30c3b4e..098b4cc 100644
--- a/libs/hwui/tests/unit/GraphicsStatsServiceTests.cpp
+++ b/libs/hwui/tests/unit/GraphicsStatsServiceTests.cpp
@@ -16,10 +16,9 @@
 
 #include <gtest/gtest.h>
 
+#include "protos/graphicsstats.pb.h"
 #include "service/GraphicsStatsService.h"
 
-#include <frameworks/base/core/proto/android/service/graphicsstats.pb.h>
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/stat.h>
@@ -74,7 +73,7 @@
         mockData.editSlowFrameCounts()[i] = (i % 5) + 1;
     }
     GraphicsStatsService::saveBuffer(path, packageName, 5, 3000, 7000, &mockData);
-    service::GraphicsStatsProto loadedProto;
+    protos::GraphicsStatsProto loadedProto;
     EXPECT_TRUE(GraphicsStatsService::parseFromFile(path, &loadedProto));
     // Clean up the file
     unlink(path.c_str());
@@ -130,7 +129,7 @@
     }
     GraphicsStatsService::saveBuffer(path, packageName, 5, 7050, 10000, &mockData);
 
-    service::GraphicsStatsProto loadedProto;
+    protos::GraphicsStatsProto loadedProto;
     EXPECT_TRUE(GraphicsStatsService::parseFromFile(path, &loadedProto));
     // Clean up the file
     unlink(path.c_str());