Merge "Add device name to About Phone page."
diff --git a/res/layout/suggestion_container.xml b/res/layout/suggestion_container.xml
index e01a590..9110c58 100644
--- a/res/layout/suggestion_container.xml
+++ b/res/layout/suggestion_container.xml
@@ -20,7 +20,7 @@
     style="@style/SuggestionConditionStyle"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:paddingTop="20dp"
+    android:paddingTop="12dp"
     android:orientation="vertical">
 
     <LinearLayout
@@ -55,7 +55,7 @@
         android:id="@+id/suggestion_list"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:paddingTop="20dp"
+        android:paddingTop="18dp"
         android:paddingBottom="16dp"
         android:scrollbars="none"/>
 
diff --git a/res/layout/suggestion_tile_v2.xml b/res/layout/suggestion_tile_v2.xml
index 27b3c34..b0e3d4c 100644
--- a/res/layout/suggestion_tile_v2.xml
+++ b/res/layout/suggestion_tile_v2.xml
@@ -20,6 +20,7 @@
     android:id="@+id/suggestion_card"
     android:layout_width="328dp"
     android:layout_height="wrap_content"
+    app:cardPreventCornerOverlap="false"
     app:cardUseCompatPadding="true"
     app:cardElevation="2dp"
     app:cardCornerRadius="@dimen/suggestion_card_corner_radius">
@@ -45,8 +46,9 @@
 
             <ImageView
                 android:id="@+id/close_button"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
+                android:layout_width="18dp"
+                android:layout_height="18dp"
+                android:alpha="0.54"
                 android:layout_alignParentEnd="true"
                 android:layout_marginTop="8dp"
                 android:layout_marginEnd="8dp"
@@ -62,7 +64,7 @@
             android:layout_marginStart="12dp"
             android:layout_marginEnd="12dp"
             android:singleLine="true"
-            android:textAppearance="@style/TextAppearance.TileTitle"
+            android:textAppearance="@style/TextAppearance.SuggestionTitleV2"
             android:ellipsize="marquee"
             android:fadingEdge="horizontal" />
 
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 1fc8e41..043196d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3228,7 +3228,7 @@
     <!-- SD card & phone storage settings screen, title for the checkbox to let user decide whether erase eSIM data together [CHAR LIMIT=NONE] -->
     <string name="reset_esim_title">Also reset eSIMs</string>
     <!-- SD card & phone storage settings screen, message for the checkbox to let user decide whether erase eSIM data together [CHAR LIMIT=NONE] -->
-    <string name="reset_esim_desc">Erase all eSIMs on the phone. You\u2019ll have to contract your carrier to redownload your eSIMs. This will not cancel your mobile service plan.</string>
+    <string name="reset_esim_desc">Erase all eSIMs on the phone. You\u2019ll have to contact your carrier to redownload your eSIMs. This will not cancel your mobile service plan.</string>
     <!-- SD card & phone storage settings screen, button on screen after user selects Reset network settings -->
     <string name="reset_network_button_text">Reset settings</string>
     <!-- SD card & phone storage settings screen, message on screen after user selects Reset settings button -->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 7764e74..b672247 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -318,7 +318,7 @@
 
     <style name="TextAppearance.SuggestionHeader"
            parent="@android:style/TextAppearance.Material.Subhead">
-        <item name="android:fontFamily">sans-serif-medium</item>
+        <item name="android:fontFamily">@config/config_headlineFontFamilyMedium</item>
         <item name="android:textSize">14sp</item>
         <item name="android:textColor">?android:attr/colorAccent</item>
     </style>
@@ -337,6 +337,11 @@
         <item name="android:fontFamily">sans-serif-medium</item>
     </style>
 
+    <style name="TextAppearance.SuggestionTitleV2"
+           parent="@android:style/TextAppearance.Material.Subhead">
+        <item name="android:fontFamily">@config/config_headlineFontFamily</item>
+    </style>
+
     <style name="TextAppearance.SuggestionSummary" parent="TextAppearance.Small">
         <item name="android:textColor">?android:attr/textColorSecondary</item>
     </style>
@@ -469,6 +474,7 @@
 
     <style name="TextAppearance.SearchBar" parent="@android:style/TextAppearance.Material.Widget.Toolbar.Subtitle">
         <item name="android:textSize">@dimen/search_bar_text_size</item>
+        <item name="android:fontFamily">@config/config_headlineFontFamily</item>
     </style>
 
     <style name="device_info_dialog_label">
diff --git a/src/com/android/settings/wfd/WifiDisplaySettings.java b/src/com/android/settings/wfd/WifiDisplaySettings.java
index 7a9fc39..8f42389 100755
--- a/src/com/android/settings/wfd/WifiDisplaySettings.java
+++ b/src/com/android/settings/wfd/WifiDisplaySettings.java
@@ -22,6 +22,7 @@
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.content.pm.PackageManager;
 import android.database.ContentObserver;
 import android.hardware.display.DisplayManager;
 import android.hardware.display.WifiDisplay;
@@ -218,13 +219,9 @@
     }
 
     public static boolean isAvailable(Context context) {
-        try {
-            return context.getSystemService(Context.DISPLAY_SERVICE) != null
-                    && context.getSystemService(Context.WIFI_P2P_SERVICE) != null;
-        } catch (Exception e) {
-            // Service is not registered, so this is definitely not available.
-            return false;
-        }
+        return context.getSystemService(Context.DISPLAY_SERVICE) != null
+                && context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT)
+                && context.getSystemService(Context.WIFI_P2P_SERVICE) != null;
     }
 
     private void scheduleUpdate(int changes) {
diff --git a/src/com/android/settings/widget/SettingsAppWidgetProvider.java b/src/com/android/settings/widget/SettingsAppWidgetProvider.java
index 5ccfc1b..adc386a 100644
--- a/src/com/android/settings/widget/SettingsAppWidgetProvider.java
+++ b/src/com/android/settings/widget/SettingsAppWidgetProvider.java
@@ -26,6 +26,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.database.ContentObserver;
+import android.hardware.display.DisplayManager;
 import android.location.LocationManager;
 import android.net.ConnectivityManager;
 import android.net.Uri;
@@ -736,7 +737,7 @@
                     R.drawable.appwidget_settings_ind_on_r_holo);
         } else {
             final int brightness = getBrightness(context);
-            final PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
+            final PowerManager pm = context.getSystemService(PowerManager.class);
             // Set the icon
             final int full = (int)(pm.getMaximumScreenBrightnessSetting()
                     * FULL_BRIGHTNESS_THRESHOLD);
@@ -872,53 +873,48 @@
      */
     private void toggleBrightness(Context context) {
         try {
-            IPowerManager power = IPowerManager.Stub.asInterface(
-                    ServiceManager.getService("power"));
-            if (power != null) {
-                PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
+            DisplayManager dm = context.getSystemService(DisplayManager.class);
+            PowerManager pm = context.getSystemService(PowerManager.class);
 
-                ContentResolver cr = context.getContentResolver();
-                int brightness = Settings.System.getInt(cr,
-                        Settings.System.SCREEN_BRIGHTNESS);
-                int brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
-                //Only get brightness setting if available
-                if (context.getResources().getBoolean(
-                        com.android.internal.R.bool.config_automatic_brightness_available)) {
-                    brightnessMode = Settings.System.getInt(cr,
-                            Settings.System.SCREEN_BRIGHTNESS_MODE);
-                }
-
-                // Rotate AUTO -> MINIMUM -> DEFAULT -> MAXIMUM
-                // Technically, not a toggle...
-                if (brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
-                    brightness = pm.getMinimumScreenBrightnessSetting();
-                    brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
-                } else if (brightness < pm.getDefaultScreenBrightnessSetting()) {
-                    brightness = pm.getDefaultScreenBrightnessSetting();
-                } else if (brightness < pm.getMaximumScreenBrightnessSetting()) {
-                    brightness = pm.getMaximumScreenBrightnessSetting();
-                } else {
-                    brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
-                    brightness = pm.getMinimumScreenBrightnessSetting();
-                }
-
-                if (context.getResources().getBoolean(
-                        com.android.internal.R.bool.config_automatic_brightness_available)) {
-                    // Set screen brightness mode (automatic or manual)
-                    Settings.System.putInt(context.getContentResolver(),
-                            Settings.System.SCREEN_BRIGHTNESS_MODE,
-                            brightnessMode);
-                } else {
-                    // Make sure we set the brightness if automatic mode isn't available
-                    brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
-                }
-                if (brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL) {
-                    power.setTemporaryScreenBrightnessSettingOverride(brightness);
-                    Settings.System.putInt(cr, Settings.System.SCREEN_BRIGHTNESS, brightness);
-                }
+            ContentResolver cr = context.getContentResolver();
+            int brightness = Settings.System.getInt(cr,
+                    Settings.System.SCREEN_BRIGHTNESS);
+            int brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
+            //Only get brightness setting if available
+            if (context.getResources().getBoolean(
+                    com.android.internal.R.bool.config_automatic_brightness_available)) {
+                brightnessMode = Settings.System.getInt(cr,
+                        Settings.System.SCREEN_BRIGHTNESS_MODE);
             }
-        } catch (RemoteException e) {
-            Log.d(TAG, "toggleBrightness: " + e);
+
+            // Rotate AUTO -> MINIMUM -> DEFAULT -> MAXIMUM
+            // Technically, not a toggle...
+            if (brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
+                brightness = pm.getMinimumScreenBrightnessSetting();
+                brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
+            } else if (brightness < pm.getDefaultScreenBrightnessSetting()) {
+                brightness = pm.getDefaultScreenBrightnessSetting();
+            } else if (brightness < pm.getMaximumScreenBrightnessSetting()) {
+                brightness = pm.getMaximumScreenBrightnessSetting();
+            } else {
+                brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
+                brightness = pm.getMinimumScreenBrightnessSetting();
+            }
+
+            if (context.getResources().getBoolean(
+                    com.android.internal.R.bool.config_automatic_brightness_available)) {
+                // Set screen brightness mode (automatic or manual)
+                Settings.System.putInt(context.getContentResolver(),
+                        Settings.System.SCREEN_BRIGHTNESS_MODE,
+                        brightnessMode);
+            } else {
+                // Make sure we set the brightness if automatic mode isn't available
+                brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
+            }
+            if (brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL) {
+                dm.setTemporaryBrightness(brightness);
+                Settings.System.putInt(cr, Settings.System.SCREEN_BRIGHTNESS, brightness);
+            }
         } catch (Settings.SettingNotFoundException e) {
             Log.d(TAG, "toggleBrightness: " + e);
         }
diff --git a/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java b/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java
index 1cf85fb..fc634d2 100644
--- a/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java
@@ -24,6 +24,7 @@
 
 import android.app.Activity;
 import android.content.Context;
+import android.content.pm.PackageManager;
 import android.hardware.display.DisplayManager;
 import android.media.MediaRouter;
 import android.net.wifi.p2p.WifiP2pManager;
@@ -50,6 +51,8 @@
     private SummaryLoader mSummaryLoader;
     @Mock
     private MediaRouter mMediaRouter;
+    @Mock
+    private PackageManager mPackageManager;
 
     private SummaryLoader.SummaryProvider mSummaryProvider;
 
@@ -58,6 +61,8 @@
         MockitoAnnotations.initMocks(this);
         when(mActivity.getSystemService(Context.MEDIA_ROUTER_SERVICE))
                 .thenReturn(mMediaRouter);
+        when(mActivity.getPackageManager()).thenReturn(mPackageManager);
+        when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT)).thenReturn(true);
 
         mSummaryProvider = WifiDisplaySettings.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(
                 mActivity, mSummaryLoader);
@@ -86,15 +91,15 @@
     }
 
     @Test
-    public void isAvailable_noService_shouldReturnFalse() {
+    public void isAvailable_nullService_shouldReturnFalse() {
         assertThat(WifiDisplaySettings.isAvailable(mActivity))
                 .isFalse();
     }
 
     @Test
-    public void isAvailable_throwException_shouldReturnFalse() {
-        when(mActivity.getSystemService(Context.WIFI_P2P_SERVICE))
-                .thenThrow(new IllegalStateException());
+    public void isAvailable_noWifiDirectFeature_shouldReturnFalse() {
+        when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT))
+                .thenReturn(false);
 
         assertThat(WifiDisplaySettings.isAvailable(mActivity))
                 .isFalse();