Merge "Add TelephonyMonitor debug switch in Developer Options."
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ff9de38..d5bc1ec 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -891,7 +891,7 @@
 
         <activity android:name="Settings$DisplaySettingsActivity"
                 android:label="@string/display_settings"
-                android:icon="@drawable/ic_settings_display"
+                android:icon="@drawable/ic_dashboard_display"
                 android:taskAffinity="">
             <intent-filter android:priority="1">
                 <action android:name="com.android.settings.DISPLAY_SETTINGS" />
@@ -1271,7 +1271,7 @@
 
         <activity android:name="Settings$SecuritySettingsActivity"
                 android:label="@string/security_settings_title"
-                android:icon="@drawable/ic_settings_security"
+                android:icon="@drawable/ic_dashboard_security"
                 android:configChanges="orientation|keyboardHidden|screenSize"
                 android:taskAffinity=""
                 android:parentActivityName="Settings">
@@ -2993,7 +2993,7 @@
         <activity android:name=".Settings$NetworkDashboardActivity"
                   android:taskAffinity=""
                   android:label="@string/network_dashboard_title"
-                  android:icon="@drawable/ic_settings_wireless">
+                  android:icon="@drawable/ic_dashboard_network">
             <intent-filter android:priority="10">
                 <action android:name="com.android.settings.action.SETTINGS"/>
             </intent-filter>
@@ -3032,7 +3032,7 @@
 
         <activity android:name=".Settings$AppAndNotificationDashboardActivity"
                   android:label="@string/app_and_notification_dashboard_title"
-                  android:icon="@drawable/ic_apps">
+                  android:icon="@drawable/ic_dashboard_apps">
             <intent-filter android:priority="9">
                 <action android:name="com.android.settings.action.SETTINGS"/>
             </intent-filter>
@@ -3071,7 +3071,8 @@
         </activity-alias>
 
         <activity-alias android:name="SoundDashboardAlias"
-                        android:targetActivity="Settings$SoundSettingsActivity">
+                        android:targetActivity="Settings$SoundSettingsActivity"
+                        android:icon="@drawable/ic_dashboard_sound">
             <intent-filter android:priority="6">
                 <action android:name="com.android.settings.action.SETTINGS" />
             </intent-filter>
@@ -3087,7 +3088,7 @@
 
         <activity android:name=".Settings$StorageDashboardActivity"
                   android:label="@string/storage_settings"
-                  android:icon="@drawable/ic_settings_storage">
+                  android:icon="@drawable/ic_dashboard_storage">
             <intent-filter android:priority="5">
                 <action android:name="com.android.settings.action.SETTINGS" />
             </intent-filter>
@@ -3114,7 +3115,7 @@
 
         <activity android:name=".Settings$UserAndAccountDashboardActivity"
                   android:label="@string/account_dashboard_title"
-                  android:icon="@drawable/ic_settings_accounts">
+                  android:icon="@drawable/ic_dashboard_user">
             <intent-filter android:priority="3">
                 <action android:name="com.android.settings.action.SETTINGS"/>
             </intent-filter>
@@ -3147,7 +3148,7 @@
 
         <activity android:name=".Settings$SystemDashboardActivity"
                   android:label="@string/header_category_system"
-                  android:icon="@drawable/ic_settings_about">
+                  android:icon="@drawable/ic_dashboard_system">
             <intent-filter android:priority="1">
                 <action android:name="com.android.settings.action.SETTINGS"/>
             </intent-filter>
diff --git a/res/drawable/ic_dashboard_apps.xml b/res/drawable/ic_dashboard_apps.xml
new file mode 100644
index 0000000..c0083a6
--- /dev/null
+++ b/res/drawable/ic_dashboard_apps.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2017 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:pathData="M4,8h4L8,4L4,4v4zM10,20h4v-4h-4v4zM4,20h4v-4L4,16v4zM4,14h4v-4L4,10v4zM10,14h4v-4h-4v4zM16,4v4h4L20,4h-4zM10,8h4L14,4h-4v4zM16,14h4v-4h-4v4zM16,20h4v-4h-4v4z"
+        android:fillColor="#ec8122"/>
+</vector>
diff --git a/res/drawable/ic_dashboard_display.xml b/res/drawable/ic_dashboard_display.xml
new file mode 100644
index 0000000..ae367cf
--- /dev/null
+++ b/res/drawable/ic_dashboard_display.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright (C) 2017 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.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24.0dp"
+        android:height="24.0dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#4184f3"
+        android:pathData="M20.0,15.31L23.31,12.0 20.0,8.69L20.0,4.0l-4.69,0.0L12.0,0.69 8.69,4.0L4.0,4.0l0.0,4.69L0.69,12.0 4.0,15.31L4.0,20.0l4.69,0.0L12.0,23.31 15.31,20.0L20.0,20.0l0.0,-4.69zM12.0,18.0L12.0,6.0c3.31,0.0 6.0,2.69 6.0,6.0s-2.69,6.0 -6.0,6.0z"/>
+</vector>
\ No newline at end of file
diff --git a/res/drawable/ic_dashboard_network.xml b/res/drawable/ic_dashboard_network.xml
new file mode 100644
index 0000000..6c7ee2e
--- /dev/null
+++ b/res/drawable/ic_dashboard_network.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright (C) 2017 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.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24.0dp"
+        android:height="24.0dp"
+        android:viewportWidth="18.0"
+        android:viewportHeight="18.0">
+    <path
+        android:fillColor="#0b9c57"
+        android:pathData="M9.01,15.99l8.8,-10.96C17.47,4.77 14.08,2.0 9.0,2.0S0.53,4.7 0.19,5.03l8.8,10.96l0.02,0.0z"/>
+</vector>
diff --git a/res/drawable/ic_dashboard_security.xml b/res/drawable/ic_dashboard_security.xml
new file mode 100644
index 0000000..1e6a1e8
--- /dev/null
+++ b/res/drawable/ic_dashboard_security.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright (C) 2017 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.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24.0dp"
+        android:height="24.0dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#7a1ea1"
+        android:pathData="M18.0,8.0l-1.0,0.0L17.0,6.0c0.0,-2.76 -2.24,-5.0 -5.0,-5.0S7.0,3.24 7.0,6.0l0.0,2.0L6.0,8.0c-1.1,0.0 -2.0,0.9 -2.0,2.0l0.0,10.0c0.0,1.0 0.9,2.0 2.0,2.0l12.0,0.0c1.1,0.0 2.0,-0.9 2.0,-2.0L20.0,10.0c0.0,-1.1 -0.9,-2.0 -2.0,-2.0zm-6.0,9.0c-1.1,0.0 -2.0,-0.9 -2.0,-2.0s0.9,-2.0 2.0,-2.0 2.0,0.9 2.0,2.0 -0.9,2.0 -2.0,2.0zm3.1,-9.0L8.9,8.0L8.9,6.0c0.0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0.0 3.1,1.39 3.1,3.1l0.0,2.0z"/>
+</vector>
\ No newline at end of file
diff --git a/res/drawable/ic_dashboard_sound.xml b/res/drawable/ic_dashboard_sound.xml
new file mode 100644
index 0000000..0cd3b04
--- /dev/null
+++ b/res/drawable/ic_dashboard_sound.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright (C) 2017 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.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24.0dp"
+        android:height="24.0dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#4184f3"
+        android:pathData="M3.0,9.0l0.0,6.0l4.0,0.0l5.0,5.0L12.0,4.0L7.0,9.0L3.0,9.0zm13.5,3.0c0.0,-1.77 -1.02,-3.29 -2.5,-4.03l0.0,8.05c1.48,-0.73 2.5,-2.25 2.5,-4.02zM14.0,3.23l0.0,2.06c2.8,0.86 5.0,3.54 5.0,6.71s-2.11,5.85 -5.0,6.71l0.0,2.06c4.01,-0.91 7.0,-4.49 7.0,-8.77s-2.99,-7.86 -7.0,-8.77z"/>
+</vector>
\ No newline at end of file
diff --git a/res/drawable/ic_dashboard_storage.xml b/res/drawable/ic_dashboard_storage.xml
new file mode 100644
index 0000000..2b6160e
--- /dev/null
+++ b/res/drawable/ic_dashboard_storage.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright (C) 2017 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.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24.0dp"
+        android:height="24.0dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#4184f3"
+        android:pathData="M2.0,20.0l20.0,0.0l0.0,-4.0L2.0,16.0l0.0,4.0zm2.0,-3.0l2.0,0.0l0.0,2.0L4.0,19.0l0.0,-2.0zM2.0,4.0l0.0,4.0l20.0,0.0L22.0,4.0L2.0,4.0zm4.0,3.0L4.0,7.0L4.0,5.0l2.0,0.0l0.0,2.0zm-4.0,7.0l20.0,0.0l0.0,-4.0L2.0,10.0l0.0,4.0zm2.0,-3.0l2.0,0.0l0.0,2.0L4.0,13.0l0.0,-2.0z"/>
+</vector>
diff --git a/res/drawable/ic_dashboard_system.xml b/res/drawable/ic_dashboard_system.xml
new file mode 100644
index 0000000..fdd9214
--- /dev/null
+++ b/res/drawable/ic_dashboard_system.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright (C) 2017 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.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24.0dp"
+        android:height="24.0dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#606060"
+        android:pathData="M11.0,17.0l2.0,0.0l0.0,-6.0l-2.0,0.0l0.0,6.0zm1.0,-15.0C6.48,2.0 2.0,6.48 2.0,12.0s4.48,10.0 10.0,10.0 10.0,-4.48 10.0,-10.0S17.52,2.0 12.0,2.0zm0.0,18.0c-4.41,0.0 -8.0,-3.59 -8.0,-8.0s3.59,-8.0 8.0,-8.0 8.0,3.59 8.0,8.0 -3.59,8.0 -8.0,8.0zM11.0,9.0l2.0,0.0L13.0,7.0l-2.0,0.0l0.0,2.0z"/>
+</vector>
diff --git a/res/drawable/ic_dashboard_user.xml b/res/drawable/ic_dashboard_user.xml
new file mode 100644
index 0000000..302d33e
--- /dev/null
+++ b/res/drawable/ic_dashboard_user.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright (C) 2017 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.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24.0dp"
+        android:height="24.0dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#aeb32a"
+        android:pathData="M3.0,5.0
+        l0.0,14.0c0.0,1.0 0.89,2.0 2.0,2.0l14.0,0.0c1.1,0.0 2.0,-0.9 2.0,-2.0
+        L21.0,5.0c0.0,-1.1 -0.9,-2.0 -2.0,-2.0
+        L5.0,3.0c-1.11,0.0 -2.0,0.9 -2.0,2.0zm12.0,4.0c0.0,1.66 -1.34,3.0 -3.0,3.0s-3.0,-1.34 -3.0,-3.0 1.34,-3.0 3.0,-3.0 3.0,1.34 3.0,3.0zm-9.0,8.0c0.0,-2.0 4.0,-3.1 6.0,-3.1s6.0,1.1 6.0,3.1l0.0,1.0
+        l-12.0,0l0.0,-1.0z"/>
+</vector>
\ No newline at end of file
diff --git a/res/drawable/ic_devices_other.xml b/res/drawable/ic_devices_other.xml
index 20639a3..73407a3 100644
--- a/res/drawable/ic_devices_other.xml
+++ b/res/drawable/ic_devices_other.xml
@@ -17,9 +17,8 @@
         android:width="24dp"
         android:height="24dp"
         android:viewportWidth="24.0"
-        android:viewportHeight="24.0"
-        android:tint="?android:attr/colorControlNormal">
+        android:viewportHeight="24.0">
     <path
         android:pathData="M3,6h18L21,4L3,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h4v-2L3,18L3,6zM13,12L9,12v1.78c-0.61,0.55 -1,1.33 -1,2.22s0.39,1.67 1,2.22L9,20h4v-1.78c0.61,-0.55 1,-1.34 1,-2.22s-0.39,-1.67 -1,-2.22L13,12zM11,17.5c-0.83,0 -1.5,-0.67 -1.5,-1.5s0.67,-1.5 1.5,-1.5 1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5zM22,8h-6c-0.5,0 -1,0.5 -1,1v10c0,0.5 0.5,1 1,1h6c0.5,0 1,-0.5 1,-1L23,9c0,-0.5 -0.5,-1 -1,-1zM21,18h-4v-8h4v8z"
-        android:fillColor="#FFFFFFFF"/>
+        android:fillColor="#0b9c57"/>
 </vector>
diff --git a/res/drawable/ic_help.xml b/res/drawable/ic_help.xml
index 7a225e5..5b056e7 100644
--- a/res/drawable/ic_help.xml
+++ b/res/drawable/ic_help.xml
@@ -17,9 +17,8 @@
         android:width="24dp"
         android:height="24dp"
         android:viewportWidth="24.0"
-        android:viewportHeight="24.0"
-        android:tint="?android:attr/colorControlNormal">
+        android:viewportHeight="24.0">
     <path
         android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,19h-2v-2h2v2zM15.07,11.25l-0.9,0.92C13.45,12.9 13,13.5 13,15h-2v-0.5c0,-1.1 0.45,-2.1 1.17,-2.83l1.24,-1.26c0.37,-0.36 0.59,-0.86 0.59,-1.41 0,-1.1 -0.9,-2 -2,-2s-2,0.9 -2,2L8,9c0,-2.21 1.79,-4 4,-4s4,1.79 4,4c0,0.88 -0.36,1.68 -0.93,2.25z"
-        android:fillColor="#FFFFFFFF"/>
+        android:fillColor="#f3501d"/>
 </vector>
diff --git a/res/drawable/ic_settings_accessibility.xml b/res/drawable/ic_settings_accessibility.xml
index 34c0bdd..a689c4a 100644
--- a/res/drawable/ic_settings_accessibility.xml
+++ b/res/drawable/ic_settings_accessibility.xml
@@ -17,9 +17,8 @@
         android:width="24.0dp"
         android:height="24.0dp"
         android:viewportWidth="24.0"
-        android:viewportHeight="24.0"
-        android:tint="?android:attr/colorControlNormal">
+        android:viewportHeight="24.0">
     <path
-        android:fillColor="#FFFFFFFF"
+        android:fillColor="#3e50b4"
         android:pathData="M12.0,2.0c1.1,0.0 2.0,0.9 2.0,2.0s-0.9,2.0 -2.0,2.0 -2.0,-0.9 -2.0,-2.0 0.9,-2.0 2.0,-2.0zm9.0,7.0l-6.0,0.0l0.0,13.0l-2.0,0.0l0.0,-6.0l-2.0,0.0l0.0,6.0L9.0,22.0L9.0,9.0L3.0,9.0L3.0,7.0l18.0,0.0l0.0,2.0z"/>
 </vector>
diff --git a/res/drawable/ic_settings_battery.xml b/res/drawable/ic_settings_battery.xml
index c8e053d..f1e56d8 100644
--- a/res/drawable/ic_settings_battery.xml
+++ b/res/drawable/ic_settings_battery.xml
@@ -17,10 +17,9 @@
         android:width="24.0dp"
         android:height="24.0dp"
         android:viewportWidth="24.0"
-        android:viewportHeight="24.0"
-        android:tint="?android:attr/colorControlNormal">
+        android:viewportHeight="24.0">
     <path
-        android:fillColor="#FFFFFFFF"
+        android:fillColor="#4184f3"
         android:pathData="M15.67,4.0L14.0,4.0L14.0,2.0l-4.0,0.0l0.0,2.0L8.33,4.0C7.6,4.0 7.0,4.6 7.0,5.33l0.0,15.33C7.0,21.4 7.6,22.0 8.33,22.0l7.33,0.0c0.74,0.0 1.34,-0.6 1.34,-1.33L17.0,5.33C17.0,4.6 16.4,4.0 15.67,4.0z
         M16,5l0,5.5l-8,0l0,-5.5l3,0l0,-2l2,0l0,2l3,0z"/>
 </vector>
diff --git a/src/com/android/settings/WifiCallingSettings.java b/src/com/android/settings/WifiCallingSettings.java
index 196e4bd..78f9de6 100644
--- a/src/com/android/settings/WifiCallingSettings.java
+++ b/src/com/android/settings/WifiCallingSettings.java
@@ -252,15 +252,6 @@
 
         final Context context = getActivity();
 
-        if (ImsManager.isWfcEnabledByPlatform(context)) {
-            TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
-            tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
-
-            mSwitchBar.addOnSwitchChangeListener(this);
-
-            mValidListener = true;
-        }
-
         // NOTE: Buttons will be enabled/disabled in mPhoneStateListener
         boolean wfcEnabled = ImsManager.isWfcEnabledByUser(context)
                 && ImsManager.isNonTtyOrTtyOnVolteEnabled(context);
@@ -271,6 +262,15 @@
         mButtonWfcRoamingMode.setValue(Integer.toString(wfcRoamingMode));
         updateButtonWfcMode(context, wfcEnabled, wfcMode, wfcRoamingMode);
 
+        if (ImsManager.isWfcEnabledByPlatform(context)) {
+            TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
+            tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
+
+            mSwitchBar.addOnSwitchChangeListener(this);
+
+            mValidListener = true;
+        }
+
         context.registerReceiver(mIntentReceiver, mIntentFilter);
 
         Intent intent = getActivity().getIntent();
diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java
index 32b9c57..5206336 100644
--- a/src/com/android/settings/dashboard/DashboardSummary.java
+++ b/src/com/android/settings/dashboard/DashboardSummary.java
@@ -70,6 +70,7 @@
     private SuggestionsChecks mSuggestionsChecks;
     private DashboardFeatureProvider mDashboardFeatureProvider;
     private SuggestionFeatureProvider mSuggestionFeatureProvider;
+    private boolean isOnCategoriesChangedCalled;
 
     @Override
     public int getMetricsCategory() {
@@ -204,25 +205,27 @@
             Log.d(TAG, "onViewCreated took "
                     + (System.currentTimeMillis() - startTime) + " ms");
         }
-        rebuildUI(true /* rebuildSuggestions */);
+        rebuildUI();
     }
 
-    private void rebuildUI(boolean rebuildSuggestions) {
-        if (rebuildSuggestions) {
-            // recheck to see if any suggestions have been changed.
-            new SuggestionLoader().execute();
-            // Set categories on their own if loading suggestions takes too long.
-            mHandler.postDelayed(() -> {
-                updateCategoryAndSuggestion(null /* tiles */);
-            }, MAX_WAIT_MILLIS);
-        } else {
+    @VisibleForTesting
+    void rebuildUI() {
+        new SuggestionLoader().execute();
+        // Set categories on their own if loading suggestions takes too long.
+        mHandler.postDelayed(() -> {
             updateCategoryAndSuggestion(null /* tiles */);
-        }
+        }, MAX_WAIT_MILLIS);
     }
 
     @Override
     public void onCategoriesChanged() {
-        rebuildUI(false /* rebuildSuggestions */);
+        // Bypass rebuildUI() on the first call of onCategoriesChanged, since rebuildUI() happens
+        // in onViewCreated as well when app starts. But, on the subsequent calls we need to
+        // rebuildUI() because there might be some changes to suggestions and categories.
+        if (isOnCategoriesChangedCalled) {
+            rebuildUI();
+        }
+        isOnCategoriesChangedCalled = true;
     }
 
     @Override
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index 180618d..5f0e6e0 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -535,6 +535,10 @@
 
     @VisibleForTesting
     void updateHeaderPreference(BatteryInfo info) {
+        final Context context = getContext();
+        if (context == null) {
+            return;
+        }
         final BatteryMeterView batteryView = (BatteryMeterView) mBatteryLayoutPref
                 .findViewById(R.id.battery_header_icon);
         final TextView timeText = (TextView) mBatteryLayoutPref.findViewById(R.id.time);
@@ -545,8 +549,7 @@
                 R.string.estimated_time_left : R.string.estimated_charging_time_left;
 
         if (info.remainingTimeUs != 0) {
-            timeText.setText(Utils.formatElapsedTime(getContext(),
-                    info.remainingTimeUs / 1000, false));
+            timeText.setText(Utils.formatElapsedTime(context, info.remainingTimeUs / 1000, false));
         } else {
             timeText.setText(info.statusLabel);
         }
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java
index 62866c9..b3f9fe0 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java
@@ -34,6 +34,7 @@
 import org.robolectric.util.ReflectionHelpers;
 
 import static org.mockito.Matchers.anyList;
+import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
@@ -41,6 +42,7 @@
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class DashboardSummaryTest {
@@ -93,11 +95,19 @@
     }
 
     @Test
-    public void onCategoryChanged_updateCategoryOnly() {
+    public void onCategoryChanged_noRebuildOnFirstCall() {
         doReturn(mock(Activity.class)).when(mSummary).getActivity();
-        when(mDashboardFeatureProvider.isEnabled()).thenReturn(true);
-
+        doNothing().when(mSummary).rebuildUI();
         mSummary.onCategoriesChanged();
-        verify(mAdapter).setCategory(anyList());
+        verify(mSummary, never()).rebuildUI();
+    }
+
+    @Test
+    public void onCategoryChanged_rebuildOnSecondCall() {
+        doReturn(mock(Activity.class)).when(mSummary).getActivity();
+        doNothing().when(mSummary).rebuildUI();
+        mSummary.onCategoriesChanged();
+        mSummary.onCategoriesChanged();
+        verify(mSummary).rebuildUI();
     }
 }
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
index 4e7b715..0755a36 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
@@ -362,6 +362,14 @@
         verify(mSummary1).setText(R.string.estimated_time_left);
     }
 
+    @Test
+    public void testUpdateHeaderPreference_AsyncUpdate_ShouldNotCrash() {
+        when(mPowerUsageSummary.getContext()).thenReturn(null);
+        mBatteryInfo.remainingTimeUs = REMAINING_TIME_US;
+
+        //Should not crash
+        mPowerUsageSummary.updateHeaderPreference(mBatteryInfo);
+    }
 
     private void testToggleAllApps(final boolean isShowApps) {
         mFragment.mShowAllApps = isShowApps;