Merge "Do not show phonebook access permission dialog if pairing dialog has already been shown." into lmp-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 0fb6228..a2d80b9 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -193,7 +193,7 @@
 
         <activity android:name=".wifi.WifiSetupActivity"
                 android:taskAffinity="com.android.wizard"
-                android:theme="@style/SetupWizardWifiTheme"
+                android:theme="@style/SetupWizardDisableAppStartingTheme"
                 android:label="@string/wifi_setup_wizard_title"
                 android:icon="@drawable/empty_icon"
                 android:clearTaskOnLaunch="true">
diff --git a/res/layout/wifi_assistant_card.xml b/res/layout/wifi_assistant_card.xml
index 28756a0..b7ab7b9 100644
--- a/res/layout/wifi_assistant_card.xml
+++ b/res/layout/wifi_assistant_card.xml
@@ -57,7 +57,6 @@
         android:layout_marginLeft="@dimen/wifi_assistant_padding_start_end"
         android:layout_marginRight="@dimen/wifi_assistant_padding_start_end"
         android:gravity="start"
-        android:text="@string/wifi_assistant_title_message"
         android:textAppearance="?android:attr/textAppearanceMedium" />
 
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 25bf278..df9afb4 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1339,29 +1339,7 @@
     <!-- Wifi Assistant title.  [CHAR LIMIT=40] -->
     <string name="wifi_assistant_title">Wi\u2011Fi Assistant</string>
     <!-- Wifi Assistant title message.  First piece of text on the Wifi Assistant setup wizard.  [CHAR LIMIT=200] -->
-    <string name="wifi_assistant_title_message">Google Wi\u2011Fi Assistant automatically connects you to the best available Wi\u2011Fi</string>
-    <!-- Wifi Assistant explanation message.  Explains what wifi assistant does to the android phone.  [CHAR LIMIT=200] -->
-    <string name="wifi_assistant_explanation_message">Google Wi\u2011Fi Assistant detects the networks available to you and connects your device to the one with the best speed and reliability.</string>
-    <!-- Wifi Assistant vpn message.  Explains to the user that Google may use/provide a secure VPN connecte to Google's servers.  [CHAR LIMIT=100] -->
-    <string name="wifi_assistant_vpn_message">To help protect your data, Google Wi\u2011Fi Assistant may provide a secure VPN connection through Google servers.</string>
-    <!-- Wifi Assistant No, thanks string.  Text to say no to wifi assistant. [CHAR LIMIT=20] -->
-    <string name="wifi_assistant_activity_no_thanks">No, thanks</string>
-    <!-- Wifi Assistant Yes string.  Text to say yes to wifi assistant. [CHAR LIMIT=20] -->
-    <string name="wifi_assistant_activity_yes">YES, I\'M IN</string>
-    <!-- Wifi Assistant Dialog title.  [CHAR LIMIT=30] -->
-    <string name="wifi_assistant_dialog_title">Connection Request</string>
-    <!-- Wifi Assistant Dialog message.  Explains what monitor may occur with wifi-assistant [CHAR LIMIT=100] -->
-    <string name="wifi_assistant_dialog_message">Wi\u2011Fi Assistant" wants to set up a VPN connection that allows it to monitor network traffic.  Only accept if you trust the source.</string>
-    <!-- Wifi Assistant Dialog message. Notice of the icon that will appear when wifi assistant is on.  [CHAR LIMIT=100] -->
-    <string name="wifi_assistant_dialog_notice">appears at the top of your screen when VPN is active.</string>
-    <!-- Wifi Assistant dialog accept.  [CHAR LIMIT=20] -->
-    <string name="wifi_assistant_accept">ACCEPT</string>
-    <!-- Wifi Assistant dialog deny.  [CHAR LIMIT=20] -->
-    <string name="wifi_assistant_deny">DENY</string>
-    <!-- Wifi Assistant Network Monitoring titile.  [CHAR LIMIT=40] -->
-    <string name="wifi_assistant_network_title">Network monitoring</string>
-    <!-- Wifi Assistant permission accepted message.  [CHAR LIMIT=140] -->
-    <string name="wifi_assistant_permission_accepted">You gave “Google Wi\u2011Fi Assistant” permission to set up a VPN connection. That means this app can monitor network traffic.</string>
+    <string name="wifi_assistant_title_message"><xliff:g id="wifi_assistant">%1$s</xliff:g> automatically connects you to the best available Wi\u2011Fi</string>
     <!-- Wifi Assistant open app button text.  [CHAR LIMIT=40] -->
     <string name="wifi_assistant_open_app">OPEN APP</string>
 
@@ -1489,10 +1467,6 @@
     <string name="wifi_automatically_manage_title">Automatically manage Wi\u2011Fi</string>
     <!-- Checkbox summary for option to Automatically manage Wi\u2011Fi  [CHAR LIMIT=100] -->
     <string name="wifi_automatically_manage_summary">Let <xliff:g id="wifi_assistant">%1$s</xliff:g> manage your Wi\u2011Fi connection</string>
-    <!-- Checkbox title for option for Wi\u2011Fi Assistant  [CHAR LIMIT=40] -->
-    <string name="wifi_assistant_setting_title">Wi\u2011Fi assistant</string>
-    <!-- Checkbox summary for option for Wi\u2011Fi Assistant  [CHAR LIMIT=40] -->
-    <string name="wifi_assistant_setting_summary">Google Wi\u2011Fi Assistant</string>
     <!-- Preference title for option to install certificates -->
     <string name="wifi_install_credentials">Install certificates</string>
     <string name="wifi_scan_notify_text_location_on">To improve location accuracy and for other purposes, Google and other apps may scan for nearby networks, even when Wi-Fi is off. If you don\'t want this to happen, go to Advanced &gt; Scanning always available.</string>
diff --git a/res/values/themes.xml b/res/values/themes.xml
index ef53618..e9d4297 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -22,6 +22,12 @@
     <attr name="wifi_signal_color" format="reference" />
     <attr name="wifi_signal" format="reference" />
 
+    <style name="SetupWizardDisableAppStartingTheme">
+        <!-- Theme to disable the app starting window. The actual theme of the activity needs to
+             be then set in code via setTheme or onApplyThemeResource. -->
+        <item name="android:windowBackground">@null</item>
+    </style>
+
     <style name="SetupWizardWifiTheme" parent="android:Theme.Material.NoActionBar">
         <item name="android:alertDialogTheme">@style/Theme.WifiDialog</item>
         <item name="android:colorAccent">@color/setup_wizard_color_accent_dark</item>
diff --git a/res/xml/wifi_advanced_settings.xml b/res/xml/wifi_advanced_settings.xml
index f83a106..5b81d25 100644
--- a/res/xml/wifi_advanced_settings.xml
+++ b/res/xml/wifi_advanced_settings.xml
@@ -33,7 +33,6 @@
     <SwitchPreference
             android:key="wifi_assistant"
             android:title="@string/wifi_automatically_manage_title"
-            android:summary="@string/wifi_assistant_setting_summary"
             android:persistent="false" />
 
     <ListPreference
diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
index c16708d..fbd0ea3 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
+++ b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
@@ -565,10 +565,22 @@
                 }
                 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
                         || rec.cmd == HistoryItem.CMD_RESET) {
+                    // If there is a ridiculously large jump in time, then we won't be
+                    // able to create a good chart with that data, so just ignore the
+                    // times we got before and pretend like our data extends back from
+                    // the time we have now.
+                    // Also, if we are getting a time change and we are less than 5 minutes
+                    // since the start of the history real time, then also use this new
+                    // time to compute the base time, since whatever time we had before is
+                    // pretty much just noise.
+                    if (rec.currentTime > (lastWallTime+(180*24*60*60*1000L))
+                            || rec.time < (mHistStart+(5*60*1000L))) {
+                        mStartWallTime = 0;
+                    }
                     lastWallTime = rec.currentTime;
                     lastRealtime = rec.time;
                     if (mStartWallTime == 0) {
-                        mStartWallTime = lastWallTime;
+                        mStartWallTime = lastWallTime - (lastRealtime-mHistStart);
                     }
                 }
                 if (rec.isDeltaData()) {
@@ -774,7 +786,7 @@
         final long walltimeStart = mStartWallTime;
         final long walltimeChange = mEndWallTime > walltimeStart
                 ? (mEndWallTime-walltimeStart) : 1;
-        long curWalltime = 0;
+        long curWalltime = mStartWallTime;
         long lastRealtime = 0;
 
         final int batLow = mBatLow;
@@ -791,17 +803,12 @@
         boolean lastWifiRunning = false, lastWifiSupplRunning = false, lastCpuRunning = false;
         int lastWifiSupplState = BatteryStats.WIFI_SUPPL_STATE_INVALID;
         final int N = mNumHist;
-        if (mStats.startIteratingHistoryLocked()) {
+        if (mEndDataWallTime > mStartWallTime && mStats.startIteratingHistoryLocked()) {
             final HistoryItem rec = new HistoryItem();
             while (mStats.getNextHistoryLocked(rec) && i < N) {
-                if (rec.cmd == HistoryItem.CMD_CURRENT_TIME || rec.cmd == HistoryItem.CMD_RESET) {
-                    curWalltime = rec.currentTime;
-                    lastRealtime = rec.time;
-                } else if (curWalltime != 0) {
+                if (rec.isDeltaData()) {
                     curWalltime += rec.time-lastRealtime;
                     lastRealtime = rec.time;
-                }
-                if (curWalltime != 0 && rec.isDeltaData()) {
                     x = mLevelLeft + (int)(((curWalltime-walltimeStart)*levelWidth)/walltimeChange);
                     if (x < 0) {
                         x = 0;
@@ -950,21 +957,36 @@
                         }
                     }
 
-                } else if (rec.cmd != HistoryItem.CMD_OVERFLOW
-                        && rec.cmd != HistoryItem.CMD_CURRENT_TIME) {
-                    if (curLevelPath != null) {
-                        finishPaths(x+1, h, levelh, startX, lastY, curLevelPath, lastX,
-                                lastCharging, lastScreenOn, lastGpsOn, lastWifiRunning,
-                                lastCpuRunning, lastLinePath);
-                        lastX = lastY = -1;
-                        curLevelPath = null;
-                        lastLinePath = null;
-                        lastCharging = lastScreenOn = lastGpsOn = lastCpuRunning = false;
+                } else {
+                    long lastWalltime = curWalltime;
+                    if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
+                            || rec.cmd == HistoryItem.CMD_RESET) {
+                        if (rec.currentTime >= mStartWallTime) {
+                            curWalltime = rec.currentTime;
+                        } else {
+                            curWalltime = mStartWallTime + (rec.time-mHistStart);
+                        }
+                        lastRealtime = rec.time;
+                    }
+
+                    if (rec.cmd != HistoryItem.CMD_OVERFLOW
+                            && (rec.cmd != HistoryItem.CMD_CURRENT_TIME
+                                    || Math.abs(lastWalltime-curWalltime) > (60*60*1000))) {
+                        if (curLevelPath != null) {
+                            finishPaths(x+1, h, levelh, startX, lastY, curLevelPath, lastX,
+                                    lastCharging, lastScreenOn, lastGpsOn, lastWifiRunning,
+                                    lastCpuRunning, lastLinePath);
+                            lastX = lastY = -1;
+                            curLevelPath = null;
+                            lastLinePath = null;
+                            lastCharging = lastScreenOn = lastGpsOn = lastCpuRunning = false;
+                        }
                     }
                 }
                 
                 i++;
             }
+            mStats.finishIteratingHistoryLocked();
         }
 
         if (lastY < 0 || lastX < 0) {
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 6d4237c..258c220 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -735,6 +735,10 @@
                     .inflate(R.layout.wifi_assistant_card, getListView(), false);
             Button setup = (Button) mWifiAssistantCard.findViewById(R.id.setup);
             Button noThanks = (Button) mWifiAssistantCard.findViewById(R.id.no_thanks_button);
+            TextView assistantText =
+                (TextView) mWifiAssistantCard.findViewById(R.id.wifi_assistant_text);
+            assistantText.setText(getResources().getString(
+                    R.string.wifi_assistant_title_message, mWifiAssistantApp.mScorerName));
 
             if (setup != null && noThanks != null) {
                 setup.setOnClickListener(new OnClickListener() {