4/ Sort property values on Winscope

Present the values of WM and SF traces alphabetically

Bug: 185516271
Test: build winscope and open WM/SF traces, check the property list
Change-Id: I6cc5553ae6e987d52f812c030b0e4706ab58606b
diff --git a/tools/winscope/src/flickerlib/ObjectFormatter.ts b/tools/winscope/src/flickerlib/ObjectFormatter.ts
new file mode 100644
index 0000000..5bbf7cc
--- /dev/null
+++ b/tools/winscope/src/flickerlib/ObjectFormatter.ts
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2021, 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.
+ */
+
+export default class ObjectFormatter {
+    static format(obj: any): {} {
+        const entries = Object.entries(obj)
+        const sortedEntries = entries.sort()
+
+        const result: any = {}
+        sortedEntries.forEach(entry => {
+            const key = entry[0]
+            const value = entry[1]
+            if (value && typeof(value) == `object`) {
+                result[key] = this.format(value)
+            } else {
+                result[key] = value
+            }
+        })
+
+        // Reassign prototype to ensure formatters work
+        result.__proto__ = obj.__proto__
+        return result
+    }
+}
\ No newline at end of file
diff --git a/tools/winscope/src/flickerlib/mixin.ts b/tools/winscope/src/flickerlib/mixin.ts
index f664054..8c5844b 100644
--- a/tools/winscope/src/flickerlib/mixin.ts
+++ b/tools/winscope/src/flickerlib/mixin.ts
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+import ObjectFormatter from "./ObjectFormatter"
+
 /**
  * Get the properties of a WM object for display.
  *
@@ -30,7 +32,8 @@
     if (obj.rootDisplayArea) delete obj.rootDisplayArea
     if (obj.rootWindowContainer) delete obj.rootWindowContainer
     if (obj.windowContainer?.children) delete obj.windowContainer.children
-    return obj
+
+    return ObjectFormatter.format(obj)
 }
 
 export function shortenName(name: any): string {
diff --git a/tools/winscope/src/transform_sf.js b/tools/winscope/src/transform_sf.js
index 8d6c20d..6a48cd4 100644
--- a/tools/winscope/src/transform_sf.js
+++ b/tools/winscope/src/transform_sf.js
@@ -19,6 +19,7 @@
 // eslint-disable-next-line camelcase
 import {fill_occlusion_state, fill_inherited_state} from './sf_visibility.js';
 import {getSimplifiedLayerName} from './utils/names';
+import ObjectFormatter from './flickerlib/ObjectFormatter'
 
 const RELATIVE_Z_CHIP = {
   short: 'RelZ',
@@ -100,7 +101,7 @@
       layer.id + ': ' + simplifiedLayerName : undefined;
 
   const transformedLayer = transform({
-    obj: layer,
+    obj: ObjectFormatter.format(layer),
     kind: '',
     name: layer.id + ': ' + layer.name,
     shortName,