Allow for different log levels on WM traces

Currently only a boolean value (trim) is supported. If trim is true then the configuration (Configuration.java) is written only once, otherwise it is written 3 times. With this implementation too much information is written in the log and it is not possible to activate a continuous tracing mode without affecting system performance. Trace logging currently consumes ~1ms for each log write  on a Pixel 2 device, divided into ~0.6ms to write the data to the ProtoBuf and ~0.4ms to it to the circular buffer.

This implementation converts this boolean into an enum and defines 3 different log levels (WindowTraceLogLevel enum): "Critical", "Trim" and "All".

"Trim" and "All" behave as the previously existing boolean. "Critical" is a new log level which logs only the elements which are visible with the minimum amount of information required for analysis. With this mode the average overhead of continuous logging drops to ~0.26ms on the same Pixel 2 device (0.2ms to write to ProtoBuf and 0.06 to add ot circular buffer).

The system automatically configures the log level between "Trim" and "Critical" according to the trace strategy used. When using continuous tracing mode it automatically uses the "Critical" level, otherwise it uses "Trim".

To activate the continuous mode use:
- adb shell cmd window tracing continuous true

Test: Flash a device. Set continuous mode to true and enable Winscope tracing. Start a systrace test for wm category and use the device. Check the "writeToProto" item to inspect the overhead.
Change-Id: I7abd74969b94abe44af4f7c65be5fefdd0860155
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index a52f1af..6fd7753 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -2882,10 +2882,16 @@
 
     @CallSuper
     @Override
-    public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
+    public void writeToProto(ProtoOutputStream proto, long fieldId,
+            @WindowTraceLogLevel int logLevel) {
+        // Critical log level logs only visible elements to mitigate performance overheard
+        if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible()) {
+            return;
+        }
+
         final long token = proto.start(fieldId);
         writeNameToProto(proto, NAME);
-        super.writeToProto(proto, WINDOW_TOKEN, trim);
+        super.writeToProto(proto, WINDOW_TOKEN, logLevel);
         proto.write(LAST_SURFACE_SHOWING, mLastSurfaceShowing);
         proto.write(IS_WAITING_FOR_TRANSITION_START, isWaitingForTransitionStart());
         proto.write(IS_REALLY_ANIMATING, isReallyAnimating());
@@ -2904,7 +2910,7 @@
         proto.write(ALL_DRAWN, allDrawn);
         proto.write(LAST_ALL_DRAWN, mLastAllDrawn);
         proto.write(REMOVED, removed);
-        if (startingWindow != null){
+        if (startingWindow != null) {
             startingWindow.writeIdentifierToProto(proto, STARTING_WINDOW);
         }
         proto.write(STARTING_DISPLAYED, startingDisplayed);