Set default rotation and boot animation orientation for logical display

Introduce ro.bootanim.set_orientation_logical_<display_id> allows to
change the default orientation of logical display.

Bug: 272527451
Test: Manual test with all 4 values
Change-Id: I39a0d5df97d5185090b6a793e52ecaa5f3bc0baa
diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp
index 89776db..820d2b0 100644
--- a/cmds/bootanimation/BootAnimation.cpp
+++ b/cmds/bootanimation/BootAnimation.cpp
@@ -675,7 +675,11 @@
         ss << "ro.bootanim.set_orientation_" << displayId.value;
         return ss.str();
     }();
-    const auto syspropValue = android::base::GetProperty(syspropName, "ORIENTATION_0");
+    auto syspropValue = android::base::GetProperty(syspropName, "");
+    if (syspropValue == "") {
+        syspropValue = android::base::GetProperty("ro.bootanim.set_orientation_logical_0", "");
+    }
+
     if (syspropValue == "ORIENTATION_90") {
         return ui::ROTATION_90;
     } else if (syspropValue == "ORIENTATION_180") {
diff --git a/services/core/java/com/android/server/wm/DisplayRotation.java b/services/core/java/com/android/server/wm/DisplayRotation.java
index a1b8949..d376613 100644
--- a/services/core/java/com/android/server/wm/DisplayRotation.java
+++ b/services/core/java/com/android/server/wm/DisplayRotation.java
@@ -281,7 +281,7 @@
         mDeskDockRotation = readRotation(R.integer.config_deskDockRotation);
         mUndockedHdmiRotation = readRotation(R.integer.config_undockedHdmiRotation);
 
-        int defaultRotation = readDefaultDisplayRotation(displayAddress);
+        int defaultRotation = readDefaultDisplayRotation(displayAddress, displayContent);
         mRotation = defaultRotation;
 
         mDisplayRotationCoordinator = displayRotationCoordinator;
@@ -327,22 +327,31 @@
     }
 
     // Change the default value to the value specified in the sysprop
-    // ro.bootanim.set_orientation_<display_id>. Four values are supported: ORIENTATION_0,
+    // ro.bootanim.set_orientation_<physical_display_id> or
+    // ro.bootanim.set_orientation_logical_<logical_display_id>.
+    // Four values are supported: ORIENTATION_0,
     // ORIENTATION_90, ORIENTATION_180 and ORIENTATION_270.
     // If the value isn't specified or is ORIENTATION_0, nothing will be changed.
     // This is needed to support having default orientation different from the natural
     // device orientation. For example, on tablets that may want to keep natural orientation
     // portrait for applications compatibility but have landscape orientation as a default choice
     // from the UX perspective.
+    // On watches that may want to keep the wrist orientation as the default.
     @Surface.Rotation
-    private int readDefaultDisplayRotation(DisplayAddress displayAddress) {
-        if (!(displayAddress instanceof DisplayAddress.Physical)) {
-            return Surface.ROTATION_0;
+    private int readDefaultDisplayRotation(DisplayAddress displayAddress,
+            DisplayContent displayContent) {
+        String syspropValue = "";
+        if (displayAddress instanceof DisplayAddress.Physical) {
+            final DisplayAddress.Physical physicalAddress =
+                    (DisplayAddress.Physical) displayAddress;
+            syspropValue = SystemProperties.get(
+                    "ro.bootanim.set_orientation_" + physicalAddress.getPhysicalDisplayId(), "");
         }
-        final DisplayAddress.Physical physicalAddress = (DisplayAddress.Physical) displayAddress;
-        String syspropValue = SystemProperties.get(
-                "ro.bootanim.set_orientation_" + physicalAddress.getPhysicalDisplayId(),
-                "ORIENTATION_0");
+        if ("".equals(syspropValue) && displayContent.isDefaultDisplay) {
+            syspropValue = SystemProperties.get(
+                    "ro.bootanim.set_orientation_logical_" + displayContent.getDisplayId(), "");
+        }
+
         if (syspropValue.equals("ORIENTATION_90")) {
             return Surface.ROTATION_90;
         } else if (syspropValue.equals("ORIENTATION_180")) {