Replace surfaceflinger protobufs with protobuf-lite
Use lite protobufs for surfaceflinger to remove dependency on
libprotobuf-cpp-full, which will be removed from the platform.
Bug: 32417805
Test: builds
Change-Id: Ie27b253a2f6c1b296c4ae7c7cb056cd3c4c0dde6
diff --git a/cmds/surfacereplayer/proto/Android.mk b/cmds/surfacereplayer/proto/Android.mk
index b87d34f..3cf1148 100644
--- a/cmds/surfacereplayer/proto/Android.mk
+++ b/cmds/surfacereplayer/proto/Android.mk
@@ -18,10 +18,7 @@
LOCAL_SRC_FILES := $(call all-proto-files-under, src)
-LOCAL_SHARED_LIBRARIES := \
- libprotobuf-cpp-full
-
-LOCAL_PROTOC_OPTIMIZE_TYPE := full
+LOCAL_PROTOC_OPTIMIZE_TYPE := lite
LOCAL_MODULE := libtrace_proto
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
diff --git a/cmds/surfacereplayer/proto/src/trace.proto b/cmds/surfacereplayer/proto/src/trace.proto
index 45060af..0bc08a9 100644
--- a/cmds/surfacereplayer/proto/src/trace.proto
+++ b/cmds/surfacereplayer/proto/src/trace.proto
@@ -1,4 +1,5 @@
syntax = "proto2";
+option optimize_for = LITE_RUNTIME;
message Trace {
repeated Increment increment = 1;
diff --git a/cmds/surfacereplayer/replayer/Android.mk b/cmds/surfacereplayer/replayer/Android.mk
index dac4314..3ec3178 100644
--- a/cmds/surfacereplayer/replayer/Android.mk
+++ b/cmds/surfacereplayer/replayer/Android.mk
@@ -40,7 +40,8 @@
libgui \
libui \
libutils \
- libprotobuf-cpp-full \
+ libprotobuf-cpp-lite \
+ libbase \
LOCAL_STATIC_LIBRARIES := \
libtrace_proto \
@@ -57,7 +58,7 @@
Main.cpp \
LOCAL_SHARED_LIBRARIES := \
- libprotobuf-cpp-full \
+ libprotobuf-cpp-lite \
libsurfacereplayer \
libutils \
diff --git a/cmds/surfacereplayer/replayer/Replayer.cpp b/cmds/surfacereplayer/replayer/Replayer.cpp
index ace10d1..a49da37 100644
--- a/cmds/surfacereplayer/replayer/Replayer.cpp
+++ b/cmds/surfacereplayer/replayer/Replayer.cpp
@@ -20,6 +20,8 @@
#include <android/native_window.h>
+#include <android-base/file.h>
+
#include <binder/IMemory.h>
#include <gui/BufferQueue.h>
@@ -61,14 +63,18 @@
mStopTimeStamp(stopHere) {
srand(RAND_COLOR_SEED);
- std::fstream input(filename, std::ios::in | std::ios::binary);
-
- mLoaded = mTrace.ParseFromIstream(&input);
- if (!mLoaded) {
+ std::string input;
+ if (!android::base::ReadFileToString(filename, &input, true)) {
std::cerr << "Trace did not load. Does " << filename << " exist?" << std::endl;
abort();
}
+ mLoaded = mTrace.ParseFromString(input);
+ if (!mLoaded) {
+ std::cerr << "Trace did not load." << std::endl;
+ abort();
+ }
+
mCurrentTime = mTrace.increment(0).time_stamp();
sReplayingManually.store(replayManually);
diff --git a/services/surfaceflinger/Android.mk b/services/surfaceflinger/Android.mk
index f695edb..ba036dd 100644
--- a/services/surfaceflinger/Android.mk
+++ b/services/surfaceflinger/Android.mk
@@ -145,7 +145,7 @@
libgui \
libpowermanager \
libvulkan \
- libprotobuf-cpp-full \
+ libprotobuf-cpp-lite \
libhidl \
libhwbinder \
libbase \
diff --git a/services/surfaceflinger/SurfaceInterceptor.cpp b/services/surfaceflinger/SurfaceInterceptor.cpp
index 4ae3580..a12276a 100644
--- a/services/surfaceflinger/SurfaceInterceptor.cpp
+++ b/services/surfaceflinger/SurfaceInterceptor.cpp
@@ -20,6 +20,9 @@
#include "Layer.h"
#include "SurfaceFlinger.h"
#include "SurfaceInterceptor.h"
+
+#include <android-base/file.h>
+
#include <cutils/log.h>
#include <utils/Trace.h>
@@ -119,14 +122,18 @@
status_t SurfaceInterceptor::writeProtoFileLocked() {
ATRACE_CALL();
- std::ofstream output(mOutputFileName, std::ios::out | std::ios::trunc | std::ios::binary);
- // SerializeToOstream returns false when it's missing required data or when it could not write
+ std::string output;
+
if (!mTrace.IsInitialized()) {
return NOT_ENOUGH_DATA;
}
- if (!mTrace.SerializeToOstream(&output)) {
+ if (!mTrace.SerializeToString(&output)) {
return PERMISSION_DENIED;
}
+ if (!android::base::WriteStringToFile(output, mOutputFileName, true)) {
+ return PERMISSION_DENIED;
+ }
+
return NO_ERROR;
}