Merge "Import translations. DO NOT MERGE" into pi-dev
diff --git a/res/layout/data_usage_summary_preference.xml b/res/layout/data_usage_summary_preference.xml
index bd13d80..1432c72 100644
--- a/res/layout/data_usage_summary_preference.xml
+++ b/res/layout/data_usage_summary_preference.xml
@@ -59,8 +59,7 @@
             android:layout_height="wrap_content"
             android:fontFamily="@*android:string/config_headlineFontFamily"
             android:textAppearance="?android:attr/textAppearanceMedium"
-            android:textSize="16sp"
-            android:textColor="?android:attr/colorAccent" />
+            android:textSize="16sp" />
 
     </LinearLayout>
 
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 1e65b37..1d0612e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6690,6 +6690,8 @@
     <string name="help_uri_private_dns" translatable="false"></string>
     <string name="help_uri_about_phone_v2" translatable="false"></string>
     <string name="help_uri_wifi_calling" translatable="false"></string>
+    <!-- url for the wifi scanning required dialog help page -->
+    <string name="help_uri_wifi_scanning_required" translatable="false"></string>
 
     <!-- User account title [CHAR LIMIT=30] -->
     <string name="user_account_title">Account for content</string>
diff --git a/src/com/android/settings/datausage/DataUsageSummaryPreference.java b/src/com/android/settings/datausage/DataUsageSummaryPreference.java
index 6473ca7..3faa433 100644
--- a/src/com/android/settings/datausage/DataUsageSummaryPreference.java
+++ b/src/com/android/settings/datausage/DataUsageSummaryPreference.java
@@ -234,10 +234,14 @@
                 usageRemainingField.setText(
                         TextUtils.expandTemplate(getContext().getText(R.string.data_remaining),
                                 Formatter.formatFileSize(getContext(), dataRemaining)));
+                usageRemainingField.setTextColor(
+                        Utils.getColorAttr(getContext(), android.R.attr.colorAccent));
             } else {
                 usageRemainingField.setText(
                         TextUtils.expandTemplate(getContext().getText(R.string.data_overusage),
                                 Formatter.formatFileSize(getContext(), -dataRemaining)));
+                usageRemainingField.setTextColor(
+                        Utils.getColorAttr(getContext(), android.R.attr.colorError));
             }
         }
     }
diff --git a/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java b/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
index 44e5cf2..ccceae3 100644
--- a/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
+++ b/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
@@ -17,7 +17,6 @@
 package com.android.settings.datausage;
 
 import android.app.Activity;
-import android.app.Fragment;
 import android.content.Context;
 import android.content.Intent;
 import android.net.NetworkPolicyManager;
@@ -27,7 +26,6 @@
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 import android.telephony.SubscriptionPlan;
-import android.telephony.TelephonyManager;
 import android.text.BidiFormatter;
 import android.text.Spannable;
 import android.text.SpannableString;
@@ -91,6 +89,8 @@
      * -1 if no information is available.
      */
     private long mDataplanSize;
+    /** The "size" of the data usage bar, i.e. the amount of data its rhs end represents */
+    private long mDataBarSize;
     /** The number of bytes used since the start of the cycle. */
     private long mDataplanUse;
     /** The starting time of the billing cycle in ms since the epoch */
@@ -171,6 +171,7 @@
     void setPlanValues(int dataPlanCount, long dataPlanSize, long dataPlanUse) {
         mDataplanCount = dataPlanCount;
         mDataplanSize = dataPlanSize;
+        mDataBarSize = dataPlanSize;
         mDataplanUse = dataPlanUse;
     }
 
@@ -237,13 +238,13 @@
 
         summaryPreference.setUsageNumbers(mDataplanUse, mDataplanSize, mHasMobileData);
 
-        if (mDataplanSize <= 0) {
+        if (mDataBarSize <= 0) {
             summaryPreference.setChartEnabled(false);
         } else {
             summaryPreference.setChartEnabled(true);
             summaryPreference.setLabels(Formatter.formatFileSize(mContext, 0 /* sizeBytes */),
-                    Formatter.formatFileSize(mContext, mDataplanSize));
-            summaryPreference.setProgress(mDataplanUse / (float) mDataplanSize);
+                    Formatter.formatFileSize(mContext, mDataBarSize));
+            summaryPreference.setProgress(mDataplanUse / (float) mDataBarSize);
         }
         summaryPreference.setUsageInfo(mCycleEnd, mSnapshotTime, mCarrierName,
                 mDataplanCount, mManageSubscriptionIntent);
@@ -262,7 +263,8 @@
         // reset data before overwriting
         mCarrierName = null;
         mDataplanCount = 0;
-        mDataplanSize = mDataInfoController.getSummaryLimit(info);
+        mDataplanSize = -1L;
+        mDataBarSize = mDataInfoController.getSummaryLimit(info);
         mDataplanUse = info.usageLevel;
         mCycleStart = info.cycleStart;
         mCycleEnd = info.cycleEnd;
@@ -278,8 +280,9 @@
                 mDataplanCount = plans.size();
                 mDataplanSize = primaryPlan.getDataLimitBytes();
                 if (unlimited(mDataplanSize)) {
-                    mDataplanSize = 0L;
+                    mDataplanSize = -1L;
                 }
+                mDataBarSize = mDataplanSize;
                 mDataplanUse = primaryPlan.getDataUsageBytes();
 
                 RecurrenceRule rule = primaryPlan.getCycleRule();
diff --git a/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java b/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
index 5255578..451b402 100644
--- a/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
+++ b/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
@@ -144,7 +144,8 @@
             if (!powerWhitelistBackend.isSysWhitelistedExceptIdle(packageName)
                     && !isSystemUid(uid)) {
                 boolean anomalyDetected = true;
-                if (anomalyInfo.anomalyType == StatsManagerConfig.AnomalyType.EXCESSIVE_BG) {
+                if (anomalyInfo.anomalyType
+                        == StatsManagerConfig.AnomalyType.EXCESSIVE_BACKGROUND_SERVICE) {
                     if (!batteryUtils.isPreOApp(packageName)
                             || !batteryUtils.isAppHeavilyUsed(batteryStatsHelper, userManager, uid,
                             policy.excessiveBgDrainPercentage)) {
diff --git a/src/com/android/settings/fuelgauge/batterytip/StatsManagerConfig.java b/src/com/android/settings/fuelgauge/batterytip/StatsManagerConfig.java
index 4ae3f10..7f4b1eb 100644
--- a/src/com/android/settings/fuelgauge/batterytip/StatsManagerConfig.java
+++ b/src/com/android/settings/fuelgauge/batterytip/StatsManagerConfig.java
@@ -23,8 +23,6 @@
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
-import java.util.HashMap;
-import java.util.Map;
 
 /**
  * This class provides all the configs needed if we want to use {@link android.app.StatsManager}
@@ -43,16 +41,20 @@
 
     @Retention(RetentionPolicy.SOURCE)
     @IntDef({AnomalyType.NULL,
-            AnomalyType.WAKE_LOCK,
-            AnomalyType.WAKEUP_ALARM,
-            AnomalyType.BLUETOOTH_SCAN,
-            AnomalyType.EXCESSIVE_BG})
+            AnomalyType.UNKNOWN_REASON,
+            AnomalyType.EXCESSIVE_WAKELOCK_ALL_SCREEN_OFF,
+            AnomalyType.EXCESSIVE_WAKEUPS_IN_BACKGROUND,
+            AnomalyType.EXCESSIVE_UNOPTIMIZED_BLE_SCAN,
+            AnomalyType.EXCESSIVE_BACKGROUND_SERVICE,
+            AnomalyType.EXCESSIVE_WIFI_SCAN})
     public @interface AnomalyType {
         int NULL = -1;
-        int WAKE_LOCK = 0;
-        int WAKEUP_ALARM = 1;
-        int BLUETOOTH_SCAN = 2;
-        int EXCESSIVE_BG = 3;
+        int UNKNOWN_REASON = 0;
+        int EXCESSIVE_WAKELOCK_ALL_SCREEN_OFF = 1;
+        int EXCESSIVE_WAKEUPS_IN_BACKGROUND = 2;
+        int EXCESSIVE_UNOPTIMIZED_BLE_SCAN = 3;
+        int EXCESSIVE_BACKGROUND_SERVICE = 4;
+        int EXCESSIVE_WIFI_SCAN = 5;
     }
 
 }
diff --git a/src/com/android/settings/wifi/WifiScanningRequiredFragment.java b/src/com/android/settings/wifi/WifiScanningRequiredFragment.java
index e0b804a..4ff023d 100644
--- a/src/com/android/settings/wifi/WifiScanningRequiredFragment.java
+++ b/src/com/android/settings/wifi/WifiScanningRequiredFragment.java
@@ -15,24 +15,31 @@
  */
 package com.android.settings.wifi;
 
-import static com.android.settings.wifi.ConfigureWifiSettings.WIFI_WAKEUP_REQUEST_CODE;
-
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.Dialog;
+import android.content.ActivityNotFoundException;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.DialogInterface;
+import android.content.Intent;
 import android.os.Bundle;
 import android.provider.Settings;
+import android.support.annotation.VisibleForTesting;
+import android.text.TextUtils;
+import android.util.Log;
 import android.widget.Toast;
 
+import com.android.internal.logging.nano.MetricsProto;
 import com.android.settings.R;
 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+import com.android.settingslib.HelpUtils;
 
 public class WifiScanningRequiredFragment extends InstrumentedDialogFragment implements
         DialogInterface.OnClickListener {
 
+    private static final String TAG = "WifiScanReqFrag";
+
     public static WifiScanningRequiredFragment newInstance() {
         WifiScanningRequiredFragment fragment = new WifiScanningRequiredFragment();
         return fragment;
@@ -40,19 +47,20 @@
 
     @Override
     public Dialog onCreateDialog(Bundle savedInstanceState) {
-        return new AlertDialog.Builder(getContext())
+        AlertDialog.Builder builder = new AlertDialog.Builder(getContext())
                 .setTitle(R.string.wifi_settings_scanning_required_title)
                 .setView(R.layout.wifi_settings_scanning_required_view)
-                .setNeutralButton(R.string.do_disclosure_learn_more, this)
                 .setPositiveButton(R.string.wifi_settings_scanning_required_turn_on, this)
-                .setNegativeButton(R.string.cancel, null)
-                .create();
+                .setNegativeButton(R.string.cancel, null);
+        addButtonIfNeeded(builder);
+
+
+        return builder.create();
     }
 
     @Override
     public int getMetricsCategory() {
-        // TODO(b/67070896): add metric code
-        return 0;
+        return MetricsProto.MetricsEvent.WIFI_SCANNING_NEEDED_DIALOG;
     }
 
     @Override
@@ -81,7 +89,29 @@
         }
     }
 
+    void addButtonIfNeeded(AlertDialog.Builder builder) {
+        // Only show "learn more" if there is a help page to show
+        if (!TextUtils.isEmpty(getContext().getString(R.string.help_uri_wifi_scanning_required))) {
+            builder.setNeutralButton(R.string.do_disclosure_learn_more, this);
+        }
+    }
+
     private void openHelpPage() {
-        // TODO(b/67070896): actually open help page on Pixel only
+        Intent intent = getHelpIntent(getContext());
+        if (intent != null) {
+            try {
+                startActivity(intent);
+            } catch (ActivityNotFoundException e) {
+                Log.e(TAG, "Activity was not found for intent, " + intent.toString());
+            }
+        }
+    }
+
+    @VisibleForTesting
+    Intent getHelpIntent(Context context) {
+        return HelpUtils.getHelpIntent(
+                    context,
+                    context.getString(R.string.help_uri_wifi_scanning_required),
+                    context.getClass().getName());
     }
 }
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java
index 67caed4..6092357 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java
@@ -76,8 +76,6 @@
     @Mock
     private DataUsageController mDataUsageController;
     @Mock
-    private DataUsageInfoController mDataInfoController;
-    @Mock
     private DataUsageSummaryPreference mSummaryPreference;
     @Mock
     private NetworkPolicyEditor mPolicyEditor;
@@ -96,6 +94,8 @@
     @Mock
     private ConnectivityManager mConnectivityManager;
 
+    private DataUsageInfoController mDataInfoController;
+
     private FakeFeatureFactory mFactory;
     private Activity mActivity;
     private Context mContext;
@@ -113,6 +113,7 @@
         when(mFactory.metricsFeatureProvider.getMetricsCategory(any(Object.class)))
                 .thenReturn(MetricsProto.MetricsEvent.SETTINGS_APP_NOTIF_CATEGORY);
         ShadowEntityHeaderController.setUseMock(mHeaderController);
+        mDataInfoController = new DataUsageInfoController();
 
         mActivity = spy(Robolectric.buildActivity(Activity.class).get());
         when(mActivity.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceTest.java
index 6bc76cf..7a14ea0 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceTest.java
@@ -369,6 +369,8 @@
         bindViewHolder();
         assertThat(mDataUsed.getText().toString()).isEqualTo("1.00 MB used");
         assertThat(mDataRemaining.getText().toString()).isEqualTo("9.00 MB left");
+        final int colorId = Utils.getColorAttr(mContext, android.R.attr.colorAccent);
+        assertThat(mDataRemaining.getCurrentTextColor()).isEqualTo(colorId);
     }
 
     @Test
@@ -380,6 +382,8 @@
         bindViewHolder();
         assertThat(mDataUsed.getText().toString()).isEqualTo("11.00 MB used");
         assertThat(mDataRemaining.getText().toString()).isEqualTo("1.00 MB over");
+        final int colorId = Utils.getColorAttr(mContext, android.R.attr.colorError);
+        assertThat(mDataRemaining.getCurrentTextColor()).isEqualTo(colorId);
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiScanningRequiredFragmentTest.java b/tests/robotests/src/com/android/settings/wifi/WifiScanningRequiredFragmentTest.java
index f9d2176..0c42c34 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiScanningRequiredFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiScanningRequiredFragmentTest.java
@@ -18,17 +18,24 @@
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.ArgumentMatchers.nullable;
 import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
+import android.app.AlertDialog;
 import android.app.Fragment;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.provider.Settings;
 
+import com.android.settings.R;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.testutils.shadow.SettingsShadowResources;
 
@@ -48,6 +55,8 @@
     private ContentResolver mResolver;
     @Mock
     Fragment mCallbackFragment;
+    @Mock
+    AlertDialog.Builder mBuilder;
 
     @Before
     public void setUp() {
@@ -81,4 +90,19 @@
 
         verify(mCallbackFragment).onActivityResult(anyInt(), anyInt(), isNull());
     }
+
+    @Test
+    public void learnMore_launchesHelpWhenIntentFound() {
+        Context context = mock(Context.class);
+        doReturn(context).when(mFragment).getContext();
+        doReturn("").when(context).getString(eq(R.string.help_uri_wifi_scanning_required));
+        mFragment.addButtonIfNeeded(mBuilder);
+        verify(mBuilder, never())
+                .setNeutralButton(anyInt(), nullable(DialogInterface.OnClickListener.class));
+
+        doReturn("help").when(context).getString(eq(R.string.help_uri_wifi_scanning_required));
+        mFragment.addButtonIfNeeded(mBuilder);
+        verify(mBuilder, times(1))
+                .setNeutralButton(anyInt(), nullable(DialogInterface.OnClickListener.class));
+    }
 }