Merge "Import translations. DO NOT MERGE" into pi-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 406251d..ef02a10 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4960,8 +4960,8 @@
     <!-- Bluetooth on time -->
     <string name="bluetooth_on_time">Wi\u2011Fi on time</string>
 
-    <!-- Activity title for advanced battery usage page [CHAR LIMIT=60] -->
-    <string name="advanced_battery_title">Advanced battery usage</string>
+    <!-- Activity title for advanced battery usage page [CHAR LIMIT=25] -->
+    <string name="advanced_battery_title">Battery usage</string>
     <!-- Activity title for battery usage history details [CHAR LIMIT=60] -->
     <string name="history_details_title">History details</string>
 
diff --git a/res/xml/app_and_notification.xml b/res/xml/app_and_notification.xml
index 85a766e..e3319e9 100644
--- a/res/xml/app_and_notification.xml
+++ b/res/xml/app_and_notification.xml
@@ -20,7 +20,7 @@
     xmlns:settings="http://schemas.android.com/apk/res-auto"
     android:key="apps_and_notification_screen"
     android:title="@string/app_and_notification_dashboard_title"
-    settings:initialExpandedChildrenCount="9">
+    settings:initialExpandedChildrenCount="7">
 
     <PreferenceCategory
         android:key="recent_apps_category"
diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java
index 937e6db..52ca127 100644
--- a/src/com/android/settings/dashboard/DashboardAdapter.java
+++ b/src/com/android/settings/dashboard/DashboardAdapter.java
@@ -17,6 +17,7 @@
 
 import android.app.Activity;
 import android.content.Context;
+import android.content.pm.PackageManager;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.service.settings.suggestions.Suggestion;
@@ -47,6 +48,7 @@
 import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
 import com.android.settingslib.drawer.DashboardCategory;
 import com.android.settingslib.drawer.Tile;
+import com.android.settingslib.drawer.TileUtils;
 import com.android.settingslib.suggestions.SuggestionControllerMixin;
 import com.android.settingslib.utils.IconCache;
 
@@ -316,6 +318,20 @@
         if (!TextUtils.equals(tile.icon.getResPackage(), mContext.getPackageName())
                 && !(icon instanceof RoundedHomepageIcon)) {
             icon = new RoundedHomepageIcon(mContext, icon);
+            try {
+                if (tile.metaData != null) {
+                    final int colorRes = tile.metaData.getInt(
+                            TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT, 0 /* default */);
+                    if (colorRes != 0) {
+                        final int bgColor = mContext.getPackageManager()
+                                .getResourcesForApplication(tile.icon.getResPackage())
+                                .getColor(colorRes, null /* theme */);
+                        ((RoundedHomepageIcon) icon).setBackgroundColor(bgColor);
+                    }
+                }
+            } catch (PackageManager.NameNotFoundException e) {
+                Log.e(TAG, "Failed to set background color for " + tile.intent.getPackage());
+            }
             mCache.updateIcon(tile.icon, icon);
         }
         holder.icon.setImageDrawable(icon);
diff --git a/src/com/android/settings/dashboard/RoundedHomepageIcon.java b/src/com/android/settings/dashboard/RoundedHomepageIcon.java
index 19749b9..d63b80a 100644
--- a/src/com/android/settings/dashboard/RoundedHomepageIcon.java
+++ b/src/com/android/settings/dashboard/RoundedHomepageIcon.java
@@ -16,14 +16,21 @@
 
 package com.android.settings.dashboard;
 
+import static android.support.annotation.VisibleForTesting.NONE;
+
 import android.content.Context;
+import android.graphics.PorterDuff;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.LayerDrawable;
+import android.support.annotation.VisibleForTesting;
 
 import com.android.settings.R;
 
 public class RoundedHomepageIcon extends LayerDrawable {
 
+    @VisibleForTesting(otherwise = NONE)
+    int mBackgroundColor = -1;
+
     public RoundedHomepageIcon(Context context, Drawable foreground) {
         super(new Drawable[] {
                 context.getDrawable(R.drawable.ic_homepage_generic_background),
@@ -33,4 +40,9 @@
                 .getDimensionPixelSize(R.dimen.dashboard_tile_foreground_image_inset);
         setLayerInset(1 /* index */, insetPx, insetPx, insetPx, insetPx);
     }
+
+    public void setBackgroundColor(int color) {
+        mBackgroundColor = color;
+        getDrawable(0).setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
+    }
 }
diff --git a/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java b/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java
index 1d71bea..7913bb5 100644
--- a/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java
+++ b/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java
@@ -21,32 +21,49 @@
 import android.net.wifi.WifiConfiguration;
 import android.net.wifi.WifiManager;
 import android.os.Build;
+import android.os.Bundle;
 import android.provider.Settings;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceScreen;
 import android.text.SpannedString;
 
+import com.android.internal.annotations.VisibleForTesting;
+
 import com.android.settings.bluetooth.BluetoothLengthDeviceNameFilter;
 import com.android.settings.core.BasePreferenceController;
 import com.android.settings.widget.ValidatedEditTextPreference;
 import com.android.settings.wifi.tether.WifiDeviceNameTextValidator;
 import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
 import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnCreate;
+import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
 
 public class DeviceNamePreferenceController extends BasePreferenceController
-        implements ValidatedEditTextPreference.Validator, Preference.OnPreferenceChangeListener {
+        implements ValidatedEditTextPreference.Validator,
+                Preference.OnPreferenceChangeListener,
+                LifecycleObserver,
+                OnSaveInstanceState,
+                OnCreate {
     private static final String PREF_KEY = "device_name";
+    public static final int DEVICE_NAME_SET_WARNING_ID = 1;
+    private static final String KEY_PENDING_DEVICE_NAME = "key_pending_device_name";
     private String mDeviceName;
     protected WifiManager mWifiManager;
     private final WifiDeviceNameTextValidator mWifiDeviceNameTextValidator;
     private ValidatedEditTextPreference mPreference;
     @Nullable
     private LocalBluetoothManager mBluetoothManager;
+    private DeviceNamePreferenceHost mHost;
+    private String mPendingDeviceName;
 
     public DeviceNamePreferenceController(Context context) {
         super(context, PREF_KEY);
+
         mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
         mWifiDeviceNameTextValidator = new WifiDeviceNameTextValidator();
+
         initializeDeviceName();
     }
 
@@ -85,9 +102,10 @@
 
     @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
-        mDeviceName = (String) newValue;
-        setDeviceName(mDeviceName);
-        preference.setSummary(getSummary());
+        mPendingDeviceName = (String) newValue;
+        if (mHost != null) {
+            mHost.showDeviceNameWarningDialog(mPendingDeviceName);
+        }
         return true;
     }
 
@@ -103,13 +121,25 @@
         mBluetoothManager = localBluetoothManager;
     }
 
+    public void confirmDeviceName() {
+        if (mPendingDeviceName != null) {
+            setDeviceName(mPendingDeviceName);
+        }
+    }
+
+    public void setHost(DeviceNamePreferenceHost host) {
+        mHost = host;
+    }
+
     /**
      * This method presumes that security/validity checks have already been passed.
      */
     private void setDeviceName(String deviceName) {
+        mDeviceName = deviceName;
         setSettingsGlobalDeviceName(deviceName);
         setBluetoothDeviceName(deviceName);
         setTetherSsidName(deviceName);
+        mPreference.setSummary(getSummary());
     }
 
     private void setSettingsGlobalDeviceName(String deviceName) {
@@ -150,4 +180,20 @@
         // TODO: If tether is running, turn off the AP and restart it after setting config.
         mWifiManager.setWifiApConfiguration(config);
     }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        if (savedInstanceState != null) {
+            mPendingDeviceName = savedInstanceState.getString(KEY_PENDING_DEVICE_NAME, null);
+        }
+    }
+
+    @Override
+    public void onSaveInstanceState(Bundle outState) {
+        outState.putString(KEY_PENDING_DEVICE_NAME, mPendingDeviceName);
+    }
+
+    public interface DeviceNamePreferenceHost {
+        void showDeviceNameWarningDialog(String deviceName);
+    }
 }
\ No newline at end of file
diff --git a/src/com/android/settings/deviceinfo/aboutphone/DeviceNameWarningDialog.java b/src/com/android/settings/deviceinfo/aboutphone/DeviceNameWarningDialog.java
new file mode 100644
index 0000000..9808069
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/aboutphone/DeviceNameWarningDialog.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.deviceinfo.aboutphone;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.FragmentManager;
+import android.content.DialogInterface;
+import android.os.Bundle;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+
+/**
+ * Warning dialog to let the user know where the device name will be shown before setting it.
+ */
+public class DeviceNameWarningDialog extends InstrumentedDialogFragment
+        implements DialogInterface.OnClickListener {
+
+    public static final String TAG = "DeviceNameWarningDlg";
+
+    public static void show(MyDeviceInfoFragment host) {
+        final FragmentManager manager = host.getActivity().getFragmentManager();
+        if (manager.findFragmentByTag(TAG) != null) {
+            return;
+        }
+
+        final DeviceNameWarningDialog dialog = new DeviceNameWarningDialog();
+        dialog.setTargetFragment(host, 0 /* requestCode */);
+        dialog.show(manager, TAG);
+    }
+
+    @Override
+    public int getMetricsCategory() {
+        return MetricsProto.MetricsEvent.DIALOG_ENABLE_DEVELOPMENT_OPTIONS;
+    }
+
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        return new AlertDialog.Builder(getActivity())
+                .setTitle(R.string.my_device_info_device_name_preference_title)
+                .setMessage(R.string.about_phone_device_name_warning)
+                .setCancelable(false)
+                .setPositiveButton(com.android.internal.R.string.ok, this)
+                .setNegativeButton(com.android.internal.R.string.cancel, this)
+                .create();
+    }
+
+    @Override
+    public void onClick(DialogInterface dialog, int which) {
+        final MyDeviceInfoFragment host = (MyDeviceInfoFragment) getTargetFragment();
+        if (which == DialogInterface.BUTTON_POSITIVE) {
+            host.onSetDeviceNameConfirm();
+        }
+    }
+}
diff --git a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
index e6303dc..09262a0 100644
--- a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
+++ b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
@@ -19,7 +19,6 @@
 import static com.android.settings.bluetooth.Utils.getLocalBtManager;
 
 import android.app.Activity;
-import android.app.Fragment;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.UserInfo;
@@ -60,7 +59,8 @@
 import java.util.Arrays;
 import java.util.List;
 
-public class MyDeviceInfoFragment extends DashboardFragment {
+public class MyDeviceInfoFragment extends DashboardFragment
+        implements DeviceNamePreferenceController.DeviceNamePreferenceHost {
     private static final String LOG_TAG = "MyDeviceInfoFragment";
 
     private static final String KEY_MY_DEVICE_INFO_HEADER = "my_device_info_header";
@@ -98,8 +98,11 @@
                 getLifecycle());
     }
 
-    private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
-            Activity activity, Fragment fragment, Lifecycle lifecycle) {
+    private static List<AbstractPreferenceController> buildPreferenceControllers(
+            Context context,
+            Activity activity,
+            MyDeviceInfoFragment fragment,
+            Lifecycle lifecycle) {
         final List<AbstractPreferenceController> controllers = new ArrayList<>();
         controllers.add(new EmergencyInfoPreferenceController(context));
         controllers.add(new PhoneNumberPreferenceController(context));
@@ -107,6 +110,10 @@
         DeviceNamePreferenceController deviceNamePreferenceController =
                 new DeviceNamePreferenceController(context);
         deviceNamePreferenceController.setLocalBluetoothManager(getLocalBtManager(context));
+        deviceNamePreferenceController.setHost(fragment);
+        if (lifecycle != null) {
+            lifecycle.addObserver(deviceNamePreferenceController);
+        }
         controllers.add(deviceNamePreferenceController);
         controllers.add(new SimStatusPreferenceController(context, fragment));
         controllers.add(new DeviceModelPreferenceController(context, fragment));
@@ -162,6 +169,16 @@
         controller.done(context, true /* rebindActions */);
     }
 
+    @Override
+    public void showDeviceNameWarningDialog(String deviceName) {
+        DeviceNameWarningDialog.show(this);
+    }
+
+    public void onSetDeviceNameConfirm() {
+        final DeviceNamePreferenceController controller = use(DeviceNamePreferenceController.class);
+        controller.confirmDeviceName();
+    }
+
     private static class SummaryProvider implements SummaryLoader.SummaryProvider {
 
         private final SummaryLoader mSummaryLoader;
diff --git a/src/com/android/settings/fuelgauge/BatteryUtils.java b/src/com/android/settings/fuelgauge/BatteryUtils.java
index 111b279..c8a5d47 100644
--- a/src/com/android/settings/fuelgauge/BatteryUtils.java
+++ b/src/com/android/settings/fuelgauge/BatteryUtils.java
@@ -20,6 +20,7 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.os.BatteryStats;
@@ -595,5 +596,21 @@
 
         return false;
     }
+
+    /**
+     * Return version number of an app represented by {@code packageName}, and return -1 if not
+     * found.
+     */
+    public long getAppLongVersionCode(String packageName) {
+        try {
+            final PackageInfo packageInfo = mPackageManager.getPackageInfo(packageName,
+                    0 /* flags */);
+            return packageInfo.getLongVersionCode();
+        } catch (PackageManager.NameNotFoundException e) {
+            Log.e(TAG, "Cannot find package: " + packageName, e);
+        }
+
+        return -1L;
+    }
 }
 
diff --git a/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java b/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
index 661cb53..518b633 100644
--- a/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
+++ b/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
@@ -146,6 +146,7 @@
                     : Settings.Global.getInt(contentResolver,
                             Settings.Global.APP_AUTO_RESTRICTION_ENABLED, ON) == ON;
             final String packageName = batteryUtils.getPackageName(uid);
+            final long versionCode = batteryUtils.getAppLongVersionCode(packageName);
 
             final boolean anomalyDetected;
             if (isExcessiveBackgroundAnomaly(anomalyInfo)) {
@@ -162,7 +163,9 @@
                             MetricsProto.MetricsEvent.ACTION_ANOMALY_IGNORED,
                             packageName,
                             Pair.create(MetricsProto.MetricsEvent.FIELD_CONTEXT,
-                                    anomalyInfo.anomalyType));
+                                    anomalyInfo.anomalyType),
+                            Pair.create(MetricsProto.MetricsEvent.FIELD_APP_VERSION_CODE,
+                                    versionCode));
                 } else {
                     if (autoFeatureOn && anomalyInfo.autoRestriction) {
                         // Auto restrict this app
@@ -180,7 +183,9 @@
                             MetricsProto.MetricsEvent.ACTION_ANOMALY_TRIGGERED,
                             packageName,
                             Pair.create(MetricsProto.MetricsEvent.FIELD_ANOMALY_TYPE,
-                                    anomalyInfo.anomalyType));
+                                    anomalyInfo.anomalyType),
+                            Pair.create(MetricsProto.MetricsEvent.FIELD_APP_VERSION_CODE,
+                                    versionCode));
                 }
             }
         } catch (NullPointerException | IndexOutOfBoundsException e) {
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
index 5256ac4..ad0b01f 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
@@ -18,6 +18,7 @@
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.reset;
@@ -30,6 +31,7 @@
 import android.content.res.Resources;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.Icon;
+import android.os.Bundle;
 import android.service.settings.suggestions.Suggestion;
 import android.support.v7.widget.RecyclerView;
 import android.util.DisplayMetrics;
@@ -46,6 +48,7 @@
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.testutils.shadow.SettingsShadowResources;
 import com.android.settingslib.drawer.Tile;
+import com.android.settingslib.drawer.TileUtils;
 import com.android.settingslib.utils.IconCache;
 
 import org.junit.Before;
@@ -193,24 +196,48 @@
 
     @Test
     public void onBindTile_externalTile_shouldUpdateIcon() {
-        final Context context = RuntimeEnvironment.application;
+        final Context context = spy(RuntimeEnvironment.application);
         final View view = LayoutInflater.from(context).inflate(R.layout.dashboard_tile, null);
         final DashboardAdapter.DashboardItemHolder holder =
                 new DashboardAdapter.DashboardItemHolder(view);
         final Tile tile = new Tile();
-        tile.icon = mock(Icon.class);
+        tile.icon = Icon.createWithResource(context, R.drawable.ic_settings);
         when(tile.icon.getResPackage()).thenReturn("another.package");
 
-        final IconCache iconCache = mock(IconCache.class);
-        when(iconCache.getIcon(tile.icon)).thenReturn(context.getDrawable(R.drawable.ic_settings));
+        final IconCache iconCache = new IconCache(context);
 
         mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
                 null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
         ReflectionHelpers.setField(mDashboardAdapter, "mCache", iconCache);
 
+        doReturn("another.package").when(context).getPackageName();
         mDashboardAdapter.onBindTile(holder, tile);
 
-        verify(iconCache).updateIcon(eq(tile.icon), any(RoundedHomepageIcon.class));
+        assertThat(iconCache.getIcon(tile.icon)).isInstanceOf(RoundedHomepageIcon.class);
+    }
+
+    @Test
+    public void onBindTile_externalTileWithBackgroundColorHint_shouldUpdateIcon() {
+        final Context context = spy(RuntimeEnvironment.application);
+        final View view = LayoutInflater.from(context).inflate(R.layout.dashboard_tile, null);
+        final DashboardAdapter.DashboardItemHolder holder =
+                new DashboardAdapter.DashboardItemHolder(view);
+        final Tile tile = new Tile();
+        tile.metaData = new Bundle();
+        tile.metaData.putInt(TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT,
+                R.color.memory_critical);
+        tile.icon = Icon.createWithResource(context, R.drawable.ic_settings);
+        final IconCache iconCache = new IconCache(context);
+        mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
+                null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
+        ReflectionHelpers.setField(mDashboardAdapter, "mCache", iconCache);
+
+        doReturn("another.package").when(context).getPackageName();
+        mDashboardAdapter.onBindTile(holder, tile);
+
+        final RoundedHomepageIcon homepageIcon = (RoundedHomepageIcon) iconCache.getIcon(tile.icon);
+        assertThat(homepageIcon.mBackgroundColor)
+                .isEqualTo(RuntimeEnvironment.application.getColor(R.color.memory_critical));
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/dashboard/RoundedHomepageIconTest.java b/tests/robotests/src/com/android/settings/dashboard/RoundedHomepageIconTest.java
index f270395..0c90660 100644
--- a/tests/robotests/src/com/android/settings/dashboard/RoundedHomepageIconTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/RoundedHomepageIconTest.java
@@ -17,10 +17,16 @@
 package com.android.settings.dashboard;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import android.content.Context;
 import android.graphics.Color;
+import android.graphics.PorterDuff;
 import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.ShapeDrawable;
 
 import com.android.settings.R;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -43,10 +49,22 @@
     @Test
     public void createIcon_shouldSetBackgroundAndInset() {
         final RoundedHomepageIcon icon =
-            new RoundedHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
+                new RoundedHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
 
         assertThat(icon.getNumberOfLayers()).isEqualTo(2);
         assertThat(icon.getDrawable(0))
-            .isEqualTo(mContext.getDrawable(R.drawable.ic_homepage_generic_background));
+                .isEqualTo(mContext.getDrawable(R.drawable.ic_homepage_generic_background));
+    }
+
+    @Test
+    public void setBackgroundColor_shouldUpdateColorFilter() {
+        final RoundedHomepageIcon icon =
+                spy(new RoundedHomepageIcon(mContext, new ColorDrawable(Color.BLACK)));
+        final ShapeDrawable background = mock(ShapeDrawable.class);
+        when(icon.getDrawable(0)).thenReturn(background);
+
+        icon.setBackgroundColor(Color.BLUE);
+
+        verify(background).setColorFilter(Color.BLUE, PorterDuff.Mode.SRC_ATOP);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/DeviceNamePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/DeviceNamePreferenceControllerTest.java
index a4e0975..66a50ee 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/DeviceNamePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/DeviceNamePreferenceControllerTest.java
@@ -17,8 +17,10 @@
 package com.android.settings.deviceinfo;
 
 import static com.google.common.truth.Truth.assertThat;
+
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -84,8 +86,8 @@
 
     @Test
     public void constructor_deviceNameLoadedIfSet() {
-        Settings.Global
-            .putString(mContext.getContentResolver(), Settings.Global.DEVICE_NAME, "Test");
+        Settings.Global.putString(
+                mContext.getContentResolver(), Settings.Global.DEVICE_NAME, "Test");
         mController = new DeviceNamePreferenceController(mContext);
         mController.setLocalBluetoothManager(mBluetoothManager);
         assertThat(mController.getSummary()).isEqualTo("Test");
@@ -103,6 +105,8 @@
 
     @Test
     public void setDeviceName_preferenceUpdatedWhenDeviceNameUpdated() {
+        forceAcceptDeviceName();
+        mController.displayPreference(mScreen);
         mController.onPreferenceChange(mPreference, TESTING_STRING);
 
         assertThat(mPreference.getSummary()).isEqualTo(TESTING_STRING);
@@ -110,6 +114,8 @@
 
     @Test
     public void setDeviceName_bluetoothNameUpdatedWhenDeviceNameUpdated() {
+        forceAcceptDeviceName();
+        mController.displayPreference(mScreen);
         mController.onPreferenceChange(mPreference, TESTING_STRING);
 
         verify(mBluetoothAdapter).setName(eq(TESTING_STRING));
@@ -117,6 +123,8 @@
 
     @Test
     public void setDeviceName_wifiTetherNameUpdatedWhenDeviceNameUpdated() {
+        forceAcceptDeviceName();
+        mController.displayPreference(mScreen);
         mController.onPreferenceChange(mPreference, TESTING_STRING);
 
         ArgumentCaptor<WifiConfiguration> captor = ArgumentCaptor.forClass(WifiConfiguration.class);
@@ -131,4 +139,22 @@
         assertThat(mPreference.getText()).isEqualTo(Build.MODEL);
     }
 
+    @Test
+    public void setDeviceName_ignoresIfCancelPressed() {
+        mController.displayPreference(mScreen);
+        mController.onPreferenceChange(mPreference, TESTING_STRING);
+
+        verify(mBluetoothAdapter, never()).setName(eq(TESTING_STRING));
+    }
+
+    private void forceAcceptDeviceName() {
+        mController.setHost(
+                new DeviceNamePreferenceController.DeviceNamePreferenceHost() {
+                    @Override
+                    public void showDeviceNameWarningDialog(String deviceName) {
+                        mController.confirmDeviceName();
+                    }
+                });
+    }
+
 }
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/deviceinfo/DeviceNameWarningDialogTest.java b/tests/robotests/src/com/android/settings/deviceinfo/deviceinfo/DeviceNameWarningDialogTest.java
new file mode 100644
index 0000000..376264e
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/deviceinfo/DeviceNameWarningDialogTest.java
@@ -0,0 +1,48 @@
+package com.android.settings.deviceinfo.deviceinfo;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import android.content.DialogInterface;
+
+import com.android.settings.deviceinfo.aboutphone.DeviceNameWarningDialog;
+import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
+import org.robolectric.android.controller.FragmentController;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class DeviceNameWarningDialogTest {
+    DeviceNameWarningDialog mDialog;
+
+    @Test
+    public void onClick_okSetsName() {
+        final FragmentController<DeviceNameWarningDialog> fragmentController =
+                Robolectric.buildFragment(DeviceNameWarningDialog.class);
+        final DeviceNameWarningDialog fragment = spy(fragmentController.get());
+        final MyDeviceInfoFragment deviceInfoFragment = mock(MyDeviceInfoFragment.class);
+        fragment.setTargetFragment(deviceInfoFragment, 0);
+        fragmentController.create().start().resume();
+        fragment.onClick(null, DialogInterface.BUTTON_POSITIVE);
+
+        verify(deviceInfoFragment).onSetDeviceNameConfirm();
+    }
+
+    @Test
+    public void onClick_cancelDoesNothing() {
+        final FragmentController<DeviceNameWarningDialog> fragmentController =
+                Robolectric.buildFragment(DeviceNameWarningDialog.class);
+        final DeviceNameWarningDialog fragment = spy(fragmentController.get());
+        final MyDeviceInfoFragment deviceInfoFragment = mock(MyDeviceInfoFragment.class);
+        fragment.setTargetFragment(deviceInfoFragment, 0);
+        fragmentController.create().start().resume();
+        fragment.onClick(null, DialogInterface.BUTTON_NEGATIVE);
+
+        verify(deviceInfoFragment, never()).onSetDeviceNameConfirm();
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java
index 16d7c3f..d6fad34 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java
@@ -79,6 +79,7 @@
     private static final String SUBSCRIBER_COOKIES_NOT_AUTO_RESTRICTION =
             "anomaly_type=6,auto_restriction=false";
     private static final int ANOMALY_TYPE = 6;
+    private static final long VERSION_CODE = 15;
     @Mock
     private BatteryStatsHelper mBatteryStatsHelper;
     @Mock
@@ -107,6 +108,7 @@
         mBundle = new Bundle();
         mBundle.putParcelable(StatsManager.EXTRA_STATS_DIMENSIONS_VALUE, mStatsDimensionsValue);
         mFeatureFactory = FakeFeatureFactory.setupForTest();
+        when(mBatteryUtils.getAppLongVersionCode(any())).thenReturn(VERSION_CODE);
 
         mAnomalyDetectionJobService = spy(new AnomalyDetectionJobService());
     }
@@ -163,7 +165,8 @@
         verify(mFeatureFactory.metricsFeatureProvider).action(mContext,
                 MetricsProto.MetricsEvent.ACTION_ANOMALY_IGNORED,
                 SYSTEM_PACKAGE,
-                Pair.create(MetricsProto.MetricsEvent.FIELD_CONTEXT, ANOMALY_TYPE));
+                Pair.create(MetricsProto.MetricsEvent.FIELD_CONTEXT, ANOMALY_TYPE),
+                Pair.create(MetricsProto.MetricsEvent.FIELD_APP_VERSION_CODE, VERSION_CODE));
     }
 
     @Test
@@ -217,7 +220,8 @@
         verify(mFeatureFactory.metricsFeatureProvider).action(mContext,
                 MetricsProto.MetricsEvent.ACTION_ANOMALY_TRIGGERED,
                 SYSTEM_PACKAGE,
-                Pair.create(MetricsProto.MetricsEvent.FIELD_ANOMALY_TYPE, ANOMALY_TYPE));
+                Pair.create(MetricsProto.MetricsEvent.FIELD_ANOMALY_TYPE, ANOMALY_TYPE),
+                Pair.create(MetricsProto.MetricsEvent.FIELD_APP_VERSION_CODE, VERSION_CODE));
     }
 
 
@@ -242,7 +246,8 @@
         verify(mFeatureFactory.metricsFeatureProvider).action(mContext,
                 MetricsProto.MetricsEvent.ACTION_ANOMALY_TRIGGERED,
                 SYSTEM_PACKAGE,
-                Pair.create(MetricsProto.MetricsEvent.FIELD_ANOMALY_TYPE, ANOMALY_TYPE));
+                Pair.create(MetricsProto.MetricsEvent.FIELD_ANOMALY_TYPE, ANOMALY_TYPE),
+                Pair.create(MetricsProto.MetricsEvent.FIELD_APP_VERSION_CODE, VERSION_CODE));
     }
 
     @Test