HFP device support change.

Test: manual
PiperOrigin-RevId: 194561401
Change-Id: Ia94765a3979b5f3c3e4d02c1dc235f5e41fbf6f9
diff --git a/java/com/android/incallui/audioroute/AudioRouteSelectorDialogFragment.java b/java/com/android/incallui/audioroute/AudioRouteSelectorDialogFragment.java
index 79cae09..316dd12 100644
--- a/java/com/android/incallui/audioroute/AudioRouteSelectorDialogFragment.java
+++ b/java/com/android/incallui/audioroute/AudioRouteSelectorDialogFragment.java
@@ -16,6 +16,7 @@
 
 package com.android.incallui.audioroute;
 
+import android.annotation.SuppressLint;
 import android.app.Dialog;
 import android.bluetooth.BluetoothDevice;
 import android.content.Context;
@@ -35,6 +36,8 @@
 import com.android.dialer.common.FragmentUtils;
 import com.android.dialer.common.LogUtil;
 import com.android.incallui.audiomode.BluetoothDeviceProviderComponent;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.Set;
 
 /** Shows picker for audio routes */
@@ -142,7 +145,7 @@
     int selectedColor = getResources().getColor(R.color.dialer_theme_color);
     TextView textView =
         (TextView) getLayoutInflater().inflate(R.layout.audioroute_item, null, false);
-    textView.setText(bluetoothDevice.getName());
+    textView.setText(getAliasName(bluetoothDevice));
     if (selected) {
       textView.setTextColor(selectedColor);
       textView.setCompoundDrawableTintList(ColorStateList.valueOf(selectedColor));
@@ -163,4 +166,16 @@
 
     return textView;
   }
+
+  @SuppressLint("PrivateApi")
+  private String getAliasName(BluetoothDevice bluetoothDevice) {
+    try {
+      Method getActiveDeviceMethod = bluetoothDevice.getClass().getDeclaredMethod("getAliasName");
+      getActiveDeviceMethod.setAccessible(true);
+      return (String) getActiveDeviceMethod.invoke(bluetoothDevice);
+    } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
+      e.printStackTrace();
+      return bluetoothDevice.getName();
+    }
+  }
 }
diff --git a/java/com/android/incallui/audioroute/res/layout/audioroute_item.xml b/java/com/android/incallui/audioroute/res/layout/audioroute_item.xml
index 66c83f6..dfd795f 100644
--- a/java/com/android/incallui/audioroute/res/layout/audioroute_item.xml
+++ b/java/com/android/incallui/audioroute/res/layout/audioroute_item.xml
@@ -18,4 +18,6 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:drawableStart="@drawable/quantum_ic_bluetooth_audio_vd_theme_24"
-    android:drawableTint="@color/material_grey_600"/>
\ No newline at end of file
+    android:drawableTint="@color/material_grey_600"
+    android:gravity="start"
+    android:textAlignment="viewStart"/>
\ No newline at end of file
diff --git a/java/com/android/incallui/audioroute/res/layout/audioroute_selector.xml b/java/com/android/incallui/audioroute/res/layout/audioroute_selector.xml
index 145101d..b63f387 100644
--- a/java/com/android/incallui/audioroute/res/layout/audioroute_selector.xml
+++ b/java/com/android/incallui/audioroute/res/layout/audioroute_selector.xml
@@ -14,31 +14,34 @@
 ~ limitations under the License
 -->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-  xmlns:tools="http://schemas.android.com/tools"
-  android:layout_width="match_parent"
-  android:layout_height="wrap_content"
-  android:orientation="vertical"
-  tools:layout_gravity="bottom">
-  <TextView
-    android:id="@+id/audioroute_speaker"
-    style="@style/AudioRouteItem"
+    xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:drawableStart="@drawable/quantum_ic_volume_up_grey600_24"
-    android:text="@string/audioroute_speaker"/>
+    android:orientation="vertical"
+    tools:layout_gravity="bottom">
   <TextView
-    android:id="@+id/audioroute_earpiece"
-    style="@style/AudioRouteItem"
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:drawableStart="@drawable/ic_phone_audio_grey600_24dp"
-    android:text="@string/audioroute_phone"/>
+      android:id="@+id/audioroute_speaker"
+      style="@style/AudioRouteItem"
+      android:layout_width="match_parent"
+      android:layout_height="wrap_content"
+      android:drawableStart="@drawable/quantum_ic_volume_up_grey600_24"
+      android:text="@string/audioroute_speaker"
+      android:textAlignment="viewStart"/>
   <TextView
-    android:id="@+id/audioroute_headset"
-    style="@style/AudioRouteItem"
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:drawableStart="@drawable/quantum_ic_headset_grey600_24"
-    android:text="@string/audioroute_headset"/>
+      android:id="@+id/audioroute_earpiece"
+      style="@style/AudioRouteItem"
+      android:layout_width="match_parent"
+      android:layout_height="wrap_content"
+      android:drawableStart="@drawable/ic_phone_audio_grey600_24dp"
+      android:text="@string/audioroute_phone"
+      android:textAlignment="viewStart"/>
+  <TextView
+      android:id="@+id/audioroute_headset"
+      style="@style/AudioRouteItem"
+      android:layout_width="match_parent"
+      android:layout_height="wrap_content"
+      android:drawableStart="@drawable/quantum_ic_headset_grey600_24"
+      android:text="@string/audioroute_headset"
+      android:textAlignment="viewStart"/>
 
 </LinearLayout>