Merge "Update recovery to use Health AIDL HAL V3." into main
diff --git a/minui/graphics.cpp b/minui/graphics.cpp
index 41a3661..cc82094 100644
--- a/minui/graphics.cpp
+++ b/minui/graphics.cpp
@@ -503,6 +503,10 @@
   rotation = rot;
 }
 
+GRRotation gr_get_rotation() {
+  return rotation;
+}
+
 bool gr_has_multiple_connectors() {
   return gr_backend->HasMultipleConnectors();
 }
diff --git a/minui/include/minui/minui.h b/minui/include/minui/minui.h
index 2353ed3..6a71ad3 100644
--- a/minui/include/minui/minui.h
+++ b/minui/include/minui/minui.h
@@ -153,6 +153,9 @@
 // Sets rotation, flips gr_fb_width/height if 90 degree rotation difference
 void gr_rotate(GRRotation rotation);
 
+// Get current rotation
+GRRotation gr_get_rotation();
+
 // Returns the current PixelFormat being used.
 PixelFormat gr_pixel_format();
 
diff --git a/recovery_ui/include/recovery_ui/wear_ui.h b/recovery_ui/include/recovery_ui/wear_ui.h
index e27e940..5dc432a 100644
--- a/recovery_ui/include/recovery_ui/wear_ui.h
+++ b/recovery_ui/include/recovery_ui/wear_ui.h
@@ -26,6 +26,8 @@
  public:
   WearRecoveryUI();
 
+  bool Init(const std::string& locale) override;
+
   void SetStage(int current, int max) override;
 
  protected:
diff --git a/recovery_ui/ui.cpp b/recovery_ui/ui.cpp
index 8bc0244..9b0fd94 100644
--- a/recovery_ui/ui.cpp
+++ b/recovery_ui/ui.cpp
@@ -197,8 +197,23 @@
   return true;
 }
 
+enum SwipeDirection { UP, DOWN, RIGHT, LEFT };
+
+static SwipeDirection FlipSwipeDirection(SwipeDirection direction) {
+  switch (direction) {
+    case UP:
+      return SwipeDirection::DOWN;
+    case DOWN:
+      return SwipeDirection::UP;
+    case RIGHT:
+      return SwipeDirection::LEFT;
+    case LEFT:
+      return SwipeDirection::RIGHT;
+  }
+}
+
 void RecoveryUI::OnTouchDetected(int dx, int dy) {
-  enum SwipeDirection { UP, DOWN, RIGHT, LEFT } direction;
+  SwipeDirection direction;
 
   // We only consider a valid swipe if:
   // - the delta along one axis is below touch_low_threshold_;
@@ -219,6 +234,11 @@
     return;
   }
 
+  // Flip swipe direction if screen is rotated upside down
+  if (gr_get_rotation() == GRRotation::DOWN) {
+    direction = FlipSwipeDirection(direction);
+  }
+
   LOG(DEBUG) << "Swipe direction=" << direction;
   switch (direction) {
     case SwipeDirection::UP:
diff --git a/recovery_ui/wear_ui.cpp b/recovery_ui/wear_ui.cpp
index 7b9ecf8..552f0cf 100644
--- a/recovery_ui/wear_ui.cpp
+++ b/recovery_ui/wear_ui.cpp
@@ -22,6 +22,7 @@
 #include <string>
 #include <vector>
 
+#include <android-base/logging.h>
 #include <android-base/properties.h>
 #include <android-base/strings.h>
 
@@ -44,6 +45,50 @@
   touch_screen_allowed_ = true;
 }
 
+static void FlipOrientation() {
+  auto rotation = gr_get_rotation();
+  if (rotation == GRRotation::NONE) {
+    gr_rotate(GRRotation::DOWN);
+  } else if (rotation == GRRotation::DOWN) {
+    gr_rotate(GRRotation::NONE);
+  } else {
+    LOG(WARNING) << "Unsupported rotation for wrist orientation" << static_cast<int>(rotation);
+  }
+}
+
+// Match values in
+// frameworks/opt/wear/src/com/android/clockwork/wristorientation/WristOrientationService.java
+enum class WristOrientation : unsigned {
+  LEFT_WRIST_ROTATION_0 = 0,
+  LEFT_WRIST_ROTATION_180 = 1,
+  RIGHT_WRIST_ROTATION_0 = 2,
+  RIGHT_WRIST_ROTATION_180 = 3,
+};
+
+static void InitWristOrientation() {
+  auto prop = android::base::GetUintProperty("ro.boot.wrist_orientation", 0u);
+  WristOrientation orientation{ prop };
+  if (orientation == WristOrientation::LEFT_WRIST_ROTATION_180 ||
+      orientation == WristOrientation::RIGHT_WRIST_ROTATION_180) {
+    LOG(INFO)
+        << "InitWristOrientation(): flipping orientation because, 'ro.boot.wrist_orientation'="
+        << prop;
+
+    FlipOrientation();
+  }
+}
+
+bool WearRecoveryUI::Init(const std::string& locale) {
+  auto result = ScreenRecoveryUI::Init(locale);
+  auto wrist_orientation_enabled =
+      android::base::GetBoolProperty("config.enable_wristorientation", false);
+  LOG(INFO) << "WearRecoveryUI::Init(): enable_wristorientation=" << wrist_orientation_enabled;
+  if (wrist_orientation_enabled) {
+    InitWristOrientation();
+  }
+  return result;
+}
+
 // Draw background frame on the screen.  Does not flip pages.
 // Should only be called with updateMutex locked.
 // TODO merge drawing routines with screen_ui
diff --git a/tools/recovery_l10n/res/values-as/strings.xml b/tools/recovery_l10n/res/values-as/strings.xml
index 8119090..d956b9a 100644
--- a/tools/recovery_l10n/res/values-as/strings.xml
+++ b/tools/recovery_l10n/res/values-as/strings.xml
@@ -1,11 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="recovery_installing" msgid="2013591905463558223">"আপডে’ট ইনষ্টল কৰি থকা হৈছে"</string>
+    <string name="recovery_installing" msgid="2013591905463558223">"আপডেইট ইনষ্টল কৰি থকা হৈছে"</string>
     <string name="recovery_erasing" msgid="7334826894904037088">"মচি থকা হৈছে"</string>
     <string name="recovery_no_command" msgid="4465476568623024327">"কোনো আদেশ নাই"</string>
     <string name="recovery_error" msgid="5748178989622716736">"ত্ৰুটি!"</string>
-    <string name="recovery_installing_security" msgid="9184031299717114342">"সুৰক্ষা আপডে’ট ইনষ্টল কৰি থকা হৈছে"</string>
+    <string name="recovery_installing_security" msgid="9184031299717114342">"সুৰক্ষা আপডেইট ইনষ্টল কৰি থকা হৈছে"</string>
     <string name="recovery_wipe_data_menu_header" msgid="550255032058254478">"Android ছিষ্টেম ল\'ড কৰিব নোৱাৰি। আপোনাৰ ডেটাত কিবা আসোঁৱাহ থকা যেন লাগিছে। আপুনি যদি এই বাৰ্তাটো পায়েই থাকে, আপুনি নিজৰ ডিভাইচটো ফেক্টৰী ডেটা ৰিছেট কৰি সেইটোত থকা ব্যৱহাৰকাৰীৰ আটাইবোৰ ডেটা মচিব লগা হ\'ব পাৰে।"</string>
     <string name="recovery_try_again" msgid="7168248750158873496">"আকৌ চেষ্টা কৰক"</string>
     <string name="recovery_factory_data_reset" msgid="7321351565602894783">"ফেক্টৰী ডেটা ৰিছেট"</string>
diff --git a/tools/recovery_l10n/res/values-pt-rPT/strings.xml b/tools/recovery_l10n/res/values-pt-rPT/strings.xml
index 8fd1d9b..08eb3c9 100644
--- a/tools/recovery_l10n/res/values-pt-rPT/strings.xml
+++ b/tools/recovery_l10n/res/values-pt-rPT/strings.xml
@@ -9,6 +9,6 @@
     <string name="recovery_wipe_data_menu_header" msgid="550255032058254478">"Não é possível carregar o sistema Android. Os seus dados podem estar danificados. Se continuar a receber esta mensagem, pode ter de efetuar uma reposição de dados de fábrica e apagar todos os dados do utilizador armazenados neste dispositivo."</string>
     <string name="recovery_try_again" msgid="7168248750158873496">"Tentar novamente"</string>
     <string name="recovery_factory_data_reset" msgid="7321351565602894783">"Reposição de dados de fábrica"</string>
-    <string name="recovery_wipe_data_confirmation" msgid="5439823343348043954">"Quer limpar todos os dados do utilizador?\n\n NÃO É POSSÍVEL ANULAR ESTA AÇÃO."</string>
+    <string name="recovery_wipe_data_confirmation" msgid="5439823343348043954">"Pretende limpar todos os dados do utilizador?\n\n NÃO É POSSÍVEL ANULAR ESTA AÇÃO."</string>
     <string name="recovery_cancel_wipe_data" msgid="66987687653647384">"Cancelar"</string>
 </resources>
diff --git a/tools/recovery_l10n/res/values-zh-rHK/strings.xml b/tools/recovery_l10n/res/values-zh-rHK/strings.xml
index 0f5b7d9..55ce31e 100644
--- a/tools/recovery_l10n/res/values-zh-rHK/strings.xml
+++ b/tools/recovery_l10n/res/values-zh-rHK/strings.xml
@@ -6,7 +6,7 @@
     <string name="recovery_no_command" msgid="4465476568623024327">"沒有指令"</string>
     <string name="recovery_error" msgid="5748178989622716736">"錯誤!"</string>
     <string name="recovery_installing_security" msgid="9184031299717114342">"正在安裝安全性更新"</string>
-    <string name="recovery_wipe_data_menu_header" msgid="550255032058254478">"無法載入 Android 系統。你的資料可能已損壞。如你繼續收到此訊息,則可能需要將裝置回復原廠設定,並清除儲存在裝置上的所有使用者資料。"</string>
+    <string name="recovery_wipe_data_menu_header" msgid="550255032058254478">"無法載入 Android 系統。您的資料可能已損壞。如您繼續收到此訊息,則可能需要將裝置回復原廠設定,並清除儲存在裝置上的所有使用者資料。"</string>
     <string name="recovery_try_again" msgid="7168248750158873496">"再試一次"</string>
     <string name="recovery_factory_data_reset" msgid="7321351565602894783">"回復原廠設定"</string>
     <string name="recovery_wipe_data_confirmation" msgid="5439823343348043954">"要清除所有使用者資料嗎?\n\n這項操作無法復原!"</string>