From fa1e28d36c11c7f9e67ab732b2331e4d0c685ba3 Mon Sep 17 00:00:00 2001 From: Stefan Andonian Date: Fri, 16 Jun 2023 17:22:08 +0000 Subject: Revert "Revert "Add Winscope Magic Number to ViewCapture data output."" This reverts commit 1ca32b9147d7ecd0aabd7c25ff86987a636121aa. Bug: 287509119 Test: Found a fix. Same code is now being pushed again. Change-Id: Iddd4a505ddc5bb3f4d9129bb9b31cf6af3887e9d --- .../src/com/android/app/viewcapture/ViewCapture.java | 7 +++++++ .../com/android/app/viewcapture/proto/view_capture.proto | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/viewcapturelib/src/com/android/app/viewcapture/ViewCapture.java b/viewcapturelib/src/com/android/app/viewcapture/ViewCapture.java index bf8737a..e635e85 100644 --- a/viewcapturelib/src/com/android/app/viewcapture/ViewCapture.java +++ b/viewcapturelib/src/com/android/app/viewcapture/ViewCapture.java @@ -16,6 +16,9 @@ package com.android.app.viewcapture; +import static com.android.app.viewcapture.data.ExportedData.MagicNumber.MAGIC_NUMBER_H; +import static com.android.app.viewcapture.data.ExportedData.MagicNumber.MAGIC_NUMBER_L; + import android.content.Context; import android.content.res.Resources; import android.media.permission.SafeCloseable; @@ -65,6 +68,9 @@ public abstract class ViewCapture { private static final int PFLAG_INVALIDATED = 0x80000000; private static final int PFLAG_DIRTY_MASK = 0x00200000; + private static final long MAGIC_NUMBER_FOR_WINSCOPE = + ((long) MAGIC_NUMBER_H.getNumber() << 32) | MAGIC_NUMBER_L.getNumber(); + // Number of frames to keep in memory private final int mMemorySize; protected static final int DEFAULT_MEMORY_SIZE = 2000; @@ -179,6 +185,7 @@ public abstract class ViewCapture { throws InterruptedException, ExecutionException { ArrayList classList = new ArrayList<>(); return ExportedData.newBuilder() + .setMagicNumber(MAGIC_NUMBER_FOR_WINSCOPE) .setPackage(context.getPackageName()) .addAllWindowData(getWindowData(context, classList, l -> l.mIsActive).get()) .addAllClassname(toStringList(classList)) diff --git a/viewcapturelib/src/com/android/app/viewcapture/proto/view_capture.proto b/viewcapturelib/src/com/android/app/viewcapture/proto/view_capture.proto index d4df2ae..6e71889 100644 --- a/viewcapturelib/src/com/android/app/viewcapture/proto/view_capture.proto +++ b/viewcapturelib/src/com/android/app/viewcapture/proto/view_capture.proto @@ -21,9 +21,19 @@ package com.android.app.viewcapture.data; option java_multiple_files = true; message ExportedData { - repeated WindowData windowData = 1; - optional string package = 2; - repeated string classname = 3; + /* constant; MAGIC_NUMBER = (long) MAGIC_NUMBER_H << 32 | MagicNumber.MAGIC_NUMBER_L + (this is needed because enums have to be 32 bits and there's no nice way to put 64bit + constants into .proto files. */ + enum MagicNumber { + INVALID = 0; + MAGIC_NUMBER_L = 0x65906578; /* AZAN (ASCII) */ + MAGIC_NUMBER_H = 0x68658273; /* DARI (ASCII) */ + } + + optional fixed64 magic_number = 1; /* Must be the first field, set to value in MagicNumber */ + repeated WindowData windowData = 2; + optional string package = 3; + repeated string classname = 4; } message WindowData { -- cgit v1.2.3