resolve merge conflicts of 696ce1c4a44be6f3c3c340dba2a16c3e8ea628ba to master

Test: I solemnly swear I tested this conflict resolution.
Bug: None
Change-Id: Iab1e8ba7453b3c40421c4ee0fdbf9d8ad70989ce
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 982332b..30760dc 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -182,8 +182,6 @@
     <!-- Needed for emergency contact notification. -->
     <uses-permission android:name="android.permission.WRITE_BLOCKED_NUMBERS" />
     <uses-permission android:name="android.permission.NETWORK_SETTINGS" />
-    <!-- Needed for emergency info user name. -->
-    <uses-permission android:name="com.android.emergency.permission.READ_EMERGENCY_INFO_NAME"/>
 
     <!-- This tells the activity manager to not delay any of our activity
          start requests, even if they happen immediately after the user
diff --git a/res/layout/emergency_information.xml b/res/layout/emergency_information.xml
index 881fb88..c4ab74b 100644
--- a/res/layout/emergency_information.xml
+++ b/res/layout/emergency_information.xml
@@ -16,7 +16,7 @@
 <com.android.phone.EmergencyInfoGroup
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/emergency_info_button"
-    android:layout_height="@dimen/emergency_info_button_height"
+    android:layout_height="@dimen/emergency_info_button_singleline_height"
     android:layout_width="match_parent"
     android:layout_marginTop="@dimen/emergency_info_button_margin_top">
     <LinearLayout
@@ -38,7 +38,7 @@
         </FrameLayout>
         <LinearLayout
             android:layout_height="wrap_content"
-            android:layout_width="wrap_content"
+            android:layout_width="match_parent"
             android:orientation="vertical"
             android:layout_gravity="center_vertical">
             <TextView
@@ -46,13 +46,16 @@
                 android:layout_height="wrap_content"
                 android:layout_width="wrap_content"
                 android:includeFontPadding="false"
+                android:maxLines="1"
+                android:ellipsize="end"
                 android:textAppearance="@style/HeadlineTextAppearance"/>
             <TextView
                 android:id="@+id/emergency_info_hint"
                 android:layout_height="wrap_content"
                 android:layout_width="wrap_content"
-                android:paddingTop="9dp"
-                android:includeFontPadding="false"
+                android:maxLines="2"
+                android:ellipsize="end"
+                android:lineHeight="@dimen/emergency_info_hint_line_height"
                 android:alpha="0.7"
                 android:textAppearance="@style/SubtitleTextAppearance"
                 android:text="@string/emergency_information_hint"/>
diff --git a/res/layout/emergency_shortcut_button.xml b/res/layout/emergency_shortcut_button.xml
index 5dc59af..414899b 100644
--- a/res/layout/emergency_shortcut_button.xml
+++ b/res/layout/emergency_shortcut_button.xml
@@ -28,6 +28,7 @@
         <LinearLayout
             android:layout_height="match_parent"
             android:layout_width="wrap_content"
+            android:layout_marginEnd="@dimen/emergency_info_image_width"
             android:layout_gravity="center_vertical|start"
             android:orientation="horizontal">
             <FrameLayout
@@ -44,7 +45,7 @@
             </FrameLayout>
             <LinearLayout
                 android:layout_height="wrap_content"
-                android:layout_width="wrap_content"
+                android:layout_width="match_parent"
                 android:layout_gravity="center_vertical"
                 android:orientation="vertical">
                 <TextView
@@ -52,14 +53,16 @@
                     android:layout_height="wrap_content"
                     android:layout_width="wrap_content"
                     android:includeFontPadding="false"
+                    android:maxLines="1"
+                    android:ellipsize="end"
                     android:textAppearance="@style/HeadlineTextAppearance"/>
                 <TextView
                     android:id="@+id/phone_number_description"
                     android:layout_height="wrap_content"
                     android:layout_width="wrap_content"
-                    android:includeFontPadding="false"
-                    android:paddingTop="9dp"
                     android:alpha="0.8"
+                    android:maxLines="1"
+                    android:ellipsize="end"
                     android:textAppearance="@style/SubtitleTextAppearance"/>
             </LinearLayout>
         </LinearLayout>
@@ -88,6 +91,7 @@
         <LinearLayout
             android:layout_height="match_parent"
             android:layout_width="wrap_content"
+            android:layout_marginEnd="@dimen/emergency_info_image_width"
             android:layout_gravity="center_vertical|start"
             android:gravity="center_vertical"
             android:orientation="horizontal">
@@ -106,12 +110,15 @@
             </FrameLayout>
             <FrameLayout
                 android:layout_height="wrap_content"
-                android:layout_width="wrap_content"
+                android:layout_width="match_parent"
                 android:gravity="center_vertical">
                 <TextView
                     android:id="@+id/phone_call_hint"
                     android:layout_height="wrap_content"
                     android:layout_width="wrap_content"
+                    android:maxLines="2"
+                    android:ellipsize="end"
+                    android:lineHeight="@dimen/phone_call_hint_line_height"
                     android:textAppearance="@style/ShortcutsHintTextAppearance"/>
             </FrameLayout>
         </LinearLayout>
@@ -126,4 +133,4 @@
                 android:src="@drawable/ic_emergency_callback_mode"/>
         </FrameLayout>
     </FrameLayout>
-</com.android.phone.EmergencyShortcutButton>
\ No newline at end of file
+</com.android.phone.EmergencyShortcutButton>
diff --git a/res/layout/emergency_shortcut_buttons_group.xml b/res/layout/emergency_shortcut_buttons_group.xml
index 86c521d..613c3b4 100644
--- a/res/layout/emergency_shortcut_buttons_group.xml
+++ b/res/layout/emergency_shortcut_buttons_group.xml
@@ -28,13 +28,15 @@
         <FrameLayout
             android:id="@+id/emergency_number_title_container"
             android:layout_height="wrap_content"
-            android:layout_width="wrap_content"
+            android:layout_width="@dimen/emergency_number_title_container_width"
             android:layout_gravity="center_vertical|start">
             <TextView
                 android:id="@+id/emergency_number_title"
                 android:layout_height="wrap_content"
                 android:layout_width="wrap_content"
-                android:layout_gravity="center"
+                android:layout_gravity="start"
+                android:maxLines="1"
+                android:ellipsize="end"
                 android:textAppearance="@style/SubtitleTextAppearance"
                 android:text="@string/single_emergency_number_title"/>
         </FrameLayout>
@@ -42,9 +44,11 @@
             android:id="@+id/location_info"
             android:layout_height="wrap_content"
             android:layout_width="wrap_content"
+            android:layout_marginStart="@dimen/emergency_number_title_container_width"
             android:layout_gravity="center_vertical|end"
             android:gravity="center_vertical"
-            android:orientation="horizontal">
+            android:orientation="horizontal"
+            android:alpha="0.7">
             <ImageView
                 android:id="@+id/location_icon"
                 android:layout_width="@dimen/location_image_width"
@@ -55,7 +59,8 @@
                 android:layout_height="wrap_content"
                 android:layout_width="wrap_content"
                 android:paddingStart="4dp"
-                android:alpha="0.7"
+                android:maxLines="1"
+                android:ellipsize="end"
                 android:textAppearance="@style/SubtitleTextAppearance"/>
         </LinearLayout>
     </FrameLayout>
@@ -69,4 +74,4 @@
         android:showDividers="middle"
         android:background="@drawable/btn_emergency_shortcuts">
     </LinearLayout>
-</LinearLayout>
\ No newline at end of file
+</LinearLayout>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 2cb4e7a..97417bd 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -130,8 +130,9 @@
     <dimen name="emergency_number_title_group_padding_horizontal">16dp</dimen>
 
     <!-- Height and top margin for the emergency information button. -->
-    <dimen name="emergency_info_button_height">72dp</dimen>
+    <dimen name="emergency_info_button_singleline_height">72dp</dimen>
     <dimen name="emergency_info_button_margin_top">56dp</dimen>
+    <dimen name="emergency_info_button_multiline_height">90dp</dimen>
 
     <!-- The height and width for the image of emergency information. -->
     <dimen name="emergency_info_image_height">56dp</dimen>
@@ -167,4 +168,11 @@
     <dimen name="phone_icon_height">24dp</dimen>
     <dimen name="phone_icon_width">24dp</dimen>
 
+    <!-- The line height for emergency info hint and phone call hint.-->
+    <dimen name="emergency_info_hint_line_height">17dp</dimen>
+    <dimen name="phone_call_hint_line_height">20dp</dimen>
+
+    <!-- The width for emergency number title container.-->
+    <dimen name="emergency_number_title_container_width">210dp</dimen>
+
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f8ee40d..b60d85f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1126,8 +1126,6 @@
     <string name="emergency_information_hint">Emergency information</string>
     <!-- Hint for the owner of emergency information -->
     <string name="emergency_information_owner_hint">Owner</string>
-    <!-- Content description for the owner of emergency information -->
-    <string name="emergency_information_owner_content_description"><xliff:g id="user_name">%s</xliff:g>\'s</string>
     <!-- Dialog title for the "radio enable" UI for emergency calls -->
     <string name="emergency_enable_radio_dialog_title">Emergency call</string>
     <!-- Title for the emergency dialpad UI -->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 544ac41..ac3f66d 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -317,8 +317,6 @@
 
     <style name="HeadlineTextAppearance">
         <item name="android:textColor">@android:color/white</item>
-        <item name="android:maxLines">1</item>
-        <item name="android:ellipsize">end</item>
         <item name="android:textSize">24sp</item>
     </style>
 
diff --git a/src/com/android/phone/EmergencyDialer.java b/src/com/android/phone/EmergencyDialer.java
index b91f927..fc4ef6a 100644
--- a/src/com/android/phone/EmergencyDialer.java
+++ b/src/com/android/phone/EmergencyDialer.java
@@ -25,12 +25,9 @@
 import android.app.Dialog;
 import android.app.WallpaperManager;
 import android.content.BroadcastReceiver;
-import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.database.ContentObserver;
-import android.database.Cursor;
 import android.graphics.Color;
 import android.graphics.Point;
 import android.media.AudioManager;
@@ -38,7 +35,6 @@
 import android.net.Uri;
 import android.os.AsyncTask;
 import android.os.Bundle;
-import android.os.Handler;
 import android.os.PersistableBundle;
 import android.provider.Settings;
 import android.telecom.PhoneAccount;
@@ -177,25 +173,6 @@
 
     private boolean mAreEmergencyDialerShortcutsEnabled;
 
-    /** Key of emergency information user name */
-    private static final String KEY_EMERGENCY_INFO_NAME = "name";
-
-    /** Authority of emergency information */
-    private static final String AUTHORITY = "com.android.emergency.info.name";
-
-    /** Content path of emergency information name */
-    private static final String CONTENT_PATH = "name";
-
-    /** Content URI of emergency information */
-    private static final Uri CONTENT_URI = new Uri.Builder()
-            .scheme(ContentResolver.SCHEME_CONTENT)
-            .authority(AUTHORITY)
-            .path(CONTENT_PATH)
-            .build();
-
-    /** ContentObserver for monitoring emergency info name changes */
-    private ContentObserver mEmergencyInfoNameObserver;
-
     @Override
     public void beforeTextChanged(CharSequence s, int start, int count, int after) {
         // Do nothing
@@ -348,10 +325,6 @@
             }
         }
         unregisterReceiver(mBroadcastReceiver);
-        if (mEmergencyInfoNameObserver != null) {
-            getContentResolver().unregisterContentObserver(mEmergencyInfoNameObserver);
-            mEmergencyInfoNameObserver = null;
-        }
     }
 
     @Override
@@ -930,19 +903,6 @@
         setupEmergencyCallShortcutButton();
 
         switchView(mEmergencyShortcutView, mDialpadView, false);
-
-        mEmergencyInfoNameObserver = new ContentObserver(new Handler()) {
-            @Override
-            public void onChange(boolean selfChange) {
-                super.onChange(selfChange);
-                getEmergencyInfoNameAsync();
-            }
-        };
-        // Register ContentProvider for monitoring emergency info name changes.
-        getContentResolver().registerContentObserver(CONTENT_URI, false,
-                mEmergencyInfoNameObserver);
-        // Query emergency info name.
-        getEmergencyInfoNameAsync();
     }
 
     private void setLocationInfo(String country) {
@@ -1063,38 +1023,4 @@
                     }
                 });
     }
-
-    /**
-     * Get emergency info name from EmergencyInfo and then update EmergencyInfoGroup.
-     */
-    private void getEmergencyInfoNameAsync() {
-        new AsyncTask<Void, Void, String>() {
-            @Override
-            protected String doInBackground(Void... params) {
-                String name = "";
-                try (Cursor cursor = getContentResolver().query(CONTENT_URI, null, null, null,
-                        null)) {
-                    if (cursor != null && cursor.moveToFirst()) {
-                        int index = cursor.getColumnIndex(KEY_EMERGENCY_INFO_NAME);
-                        name = index > -1 ? cursor.getString(index) : "";
-                    }
-                } catch (IllegalArgumentException ex) {
-                    Log.w(LOG_TAG, "getEmergencyInfoNameAsync failed", ex);
-                }
-                return name;
-            }
-
-            @Override
-            protected void onPostExecute(String result) {
-                super.onPostExecute(result);
-                if (!isFinishing() && !isDestroyed()) {
-                    // Update emergency info with emergency info name
-                    EmergencyInfoGroup group = findViewById(R.id.emergency_info_button);
-                    if (group != null) {
-                        group.updateEmergencyInfo(result);
-                    }
-                }
-            }
-        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
-    }
 }
diff --git a/src/com/android/phone/EmergencyInfoGroup.java b/src/com/android/phone/EmergencyInfoGroup.java
index 73fa92a..898af32 100644
--- a/src/com/android/phone/EmergencyInfoGroup.java
+++ b/src/com/android/phone/EmergencyInfoGroup.java
@@ -30,6 +30,7 @@
 import android.view.View;
 import android.widget.FrameLayout;
 import android.widget.ImageView;
+import android.widget.LinearLayout;
 import android.widget.TextView;
 
 import androidx.core.graphics.drawable.RoundedBitmapDrawable;
@@ -46,6 +47,7 @@
 public class EmergencyInfoGroup extends FrameLayout {
     private ImageView mEmergencyInfoImage;
     private TextView mEmergencyInfoName;
+    private TextView mEmergencyInfoHint;
     private View mEmergencyInfoButton;
 
     public EmergencyInfoGroup(Context context, @Nullable AttributeSet attrs) {
@@ -58,6 +60,7 @@
         mEmergencyInfoButton = findViewById(R.id.emergency_info_button);
         mEmergencyInfoImage = (ImageView) findViewById(R.id.emergency_info_image);
         mEmergencyInfoName = (TextView) findViewById(R.id.emergency_info_name);
+        mEmergencyInfoHint = (TextView) findViewById(R.id.emergency_info_hint);
     }
 
     @Override
@@ -68,6 +71,12 @@
         }
     }
 
+    @Override
+    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+        super.onLayout(changed, left, top, right, bottom);
+        updateLayoutHeight();
+    }
+
     private void setupButtonInfo() {
         List<ResolveInfo> infos;
 
@@ -88,6 +97,7 @@
 
             visible = true;
         }
+        mEmergencyInfoName.setText(getUserName());
 
         setVisibility(visible ? View.VISIBLE : View.GONE);
     }
@@ -95,34 +105,19 @@
     /**
      * Get user icon.
      *
-     * @return user icon, or anonymous avatar if user do not set photo.
+     * @return user icon, or default user icon if user do not set photo.
      */
     private Drawable getCircularUserIcon() {
-        final int userId = UserHandle.getCallingUserId();
-
         final UserManager userManager = (UserManager) getContext().getSystemService(
                 Context.USER_SERVICE);
-
-        // get user icon.
-        Bitmap bitmapUserIcon = userManager.getUserIcon(userId);
+        Bitmap bitmapUserIcon = userManager.getUserIcon(UserHandle.getCallingUserId());
 
         if (bitmapUserIcon == null) {
-            // use anonymous avatar.
-            return getContext().getDrawable(R.drawable.logo_avatar_anonymous_120);
+            // get default user icon.
+            final Drawable defaultUserIcon = UserIcons.getDefaultUserIcon(
+                    getContext().getResources(), UserHandle.myUserId(), false);
+            bitmapUserIcon = UserIcons.convertToBitmap(defaultUserIcon);
         }
-
-        // get default user icon.
-        Drawable drawableDefaultUserIcon = UserIcons.getDefaultUserIcon(
-                getContext().getResources(), userId, false);
-        Bitmap bitmapDefaultUserIcon = UserIcons.convertToBitmap(drawableDefaultUserIcon);
-
-        // User icon is default icon that means user do not set photo, replacing default icon
-        // with anonymous avatar on emergency info button.
-        if (bitmapUserIcon.sameAs(bitmapDefaultUserIcon)) {
-            return getContext().getDrawable(R.drawable.logo_avatar_anonymous_120);
-        }
-
-        // set user icon circular.
         RoundedBitmapDrawable drawableUserIcon = RoundedBitmapDrawableFactory.create(
                 getContext().getResources(), bitmapUserIcon);
         drawableUserIcon.setCircular(true);
@@ -130,14 +125,24 @@
         return drawableUserIcon;
     }
 
-    void updateEmergencyInfo(String emergencyInfoName) {
-        if (TextUtils.isEmpty(emergencyInfoName)) {
-            emergencyInfoName = getContext().getString(R.string.emergency_information_owner_hint);
-        }
-        mEmergencyInfoName.setText(emergencyInfoName);
+    private CharSequence getUserName() {
+        final UserManager userManager = (UserManager) getContext().getSystemService(
+                Context.USER_SERVICE);
+        final String userName = userManager.getUserName();
 
-        final String infoNameDescription = getContext().getString(
-                R.string.emergency_information_owner_content_description, emergencyInfoName);
-        mEmergencyInfoName.setContentDescription(infoNameDescription);
+        return TextUtils.isEmpty(userName) ? getContext().getText(
+                R.string.emergency_information_owner_hint) : userName;
     }
-}
\ No newline at end of file
+
+    private void updateLayoutHeight() {
+        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLayoutParams();
+        // Update height if mEmergencyInfoHint text line more than 1.
+        // EmergencyInfoGroup max line is 2, eclipse type "end" will be adopt if string too long.
+        params.height =
+                mEmergencyInfoHint.getLineCount() > 1 ? getResources().getDimensionPixelSize(
+                        R.dimen.emergency_info_button_multiline_height)
+                        : getResources().getDimensionPixelSize(
+                                R.dimen.emergency_info_button_singleline_height);
+        setLayoutParams(params);
+    }
+}