Merge "Revert changes for disallowing user to run in background for now."
diff --git a/service/res/values/config.xml b/service/res/values/config.xml
index e8c520a..e1ef1fe 100644
--- a/service/res/values/config.xml
+++ b/service/res/values/config.xml
@@ -50,7 +50,7 @@
           The current implementations expects the following system packages/activities to be
           whitelisted. For general guidelines to design distraction optimized apps, please refer
           to Android Auto Driver Distraction Guidelines. -->
-    <string name="activityWhitelist">com.android.systemui,com.google.android.packageinstaller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity</string>
+    <string name="activityWhitelist">com.android.systemui,com.google.android.packageinstaller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity,android/com.android.internal.app.ResolverActivity</string>
     <!--  Comma separated list of activities that will be blocked during restricted state.
           Format of each entry is either to specify package name to whitelist the whole package
           or use format of "packagename/activity_classname" for tagging each activities.-->
diff --git a/tests/EmbeddedKitchenSinkApp/res/layout/notification_fragment.xml b/tests/EmbeddedKitchenSinkApp/res/layout/notification_fragment.xml
index 4e8e1b3..f0bd53b 100644
--- a/tests/EmbeddedKitchenSinkApp/res/layout/notification_fragment.xml
+++ b/tests/EmbeddedKitchenSinkApp/res/layout/notification_fragment.xml
@@ -13,138 +13,144 @@
      See the License for the specific language governing permissions and
      limitations under the License.
 -->
-<LinearLayout
+<ScrollView
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:orientation="vertical">
-
-    <TextView
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:text="Ongoing notifications can only be dismissed by the CANCEL ALL button."/>
-
-    <Button
-        android:id="@+id/cancel_all_button"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_margin="10dp"
-        android:text="Cancel All"
-        android:textSize="30sp"/>
+    android:fadeScrollbars="false">
 
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:background="#334666"
-        android:orientation="horizontal">
+        android:orientation="vertical">
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="Ongoing notifications can only be dismissed by the CANCEL ALL button."/>
 
         <Button
-            android:id="@+id/category_message_button"
+            android:id="@+id/cancel_all_button"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_margin="10dp"
-            android:text="Message"
+            android:text="Cancel All"
             android:textSize="30sp"/>
 
-        <Button
-            android:id="@+id/navigation_button"
-            android:layout_width="wrap_content"
+        <LinearLayout
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_margin="10dp"
-            android:text="Navigation"
-            android:textSize="30sp"/>
+            android:background="#334666"
+            android:orientation="vertical">
 
-        <Button
-            android:id="@+id/ongoing_button"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_margin="10dp"
-            android:text="Persistent (No heads-up)"
-            android:textSize="30sp"/>
+            <Button
+                android:id="@+id/category_message_button"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Message"
+                android:textSize="30sp"/>
 
-        <Button
-            android:id="@+id/progress_button"
-            android:layout_width="wrap_content"
+            <Button
+                android:id="@+id/navigation_button"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Navigation"
+                android:textSize="30sp"/>
+
+            <Button
+                android:id="@+id/ongoing_button"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Persistent (No heads-up)"
+                android:textSize="30sp"/>
+
+            <Button
+                android:id="@+id/progress_button"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Progress (No heads-up)"
+                android:textSize="30sp"/>
+        </LinearLayout>
+
+        <LinearLayout
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_margin="10dp"
-            android:text="Progress (No heads-up)"
-            android:textSize="30sp"/>
+            android:background="#5a6633"
+            android:orientation="vertical">
+
+            <Button
+                android:id="@+id/importance_high_button"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Importance: HIGH"
+                android:textSize="30sp"/>
+
+            <Button
+                android:id="@+id/importance_default_button"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Importance: DEFAULT (No heads-up)"
+                android:textSize="30sp"/>
+        </LinearLayout>
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:background="#5a6633"
+            android:orientation="vertical">
+
+            <Button
+                android:id="@+id/importance_low_button"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Importance: LOW (No heads-up)"
+                android:textSize="30sp"/>
+
+            <Button
+                android:id="@+id/importance_min_button"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Importance: MIN (No heads-up)"
+                android:textSize="30sp"/>
+        </LinearLayout>
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:background="#33664d"
+            android:orientation="vertical">
+
+            <Button
+                android:id="@+id/category_car_emergency_button"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Car Emergency"
+                android:textSize="30sp"/>
+
+            <Button
+                android:id="@+id/category_car_warning_button"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Car Warning"
+                android:textSize="30sp"/>
+
+            <Button
+                android:id="@+id/category_car_info_button"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Car Information (No heads-up)"
+                android:textSize="30sp"/>
+        </LinearLayout>
     </LinearLayout>
-
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:background="#5a6633"
-        android:orientation="horizontal">
-
-        <Button
-            android:id="@+id/importance_high_button"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_margin="10dp"
-            android:text="Importance: HIGH"
-            android:textSize="30sp"/>
-
-        <Button
-            android:id="@+id/importance_default_button"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_margin="10dp"
-            android:text="Importance: DEFAULT (No heads-up)"
-            android:textSize="30sp"/>
-    </LinearLayout>
-
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:background="#5a6633"
-        android:orientation="horizontal">
-
-        <Button
-            android:id="@+id/importance_low_button"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_margin="10dp"
-            android:text="Importance: LOW (No heads-up)"
-            android:textSize="30sp"/>
-
-        <Button
-            android:id="@+id/importance_min_button"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_margin="10dp"
-            android:text="Importance: MIN (No heads-up)"
-            android:textSize="30sp"/>
-    </LinearLayout>
-
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:background="#33664d"
-        android:orientation="horizontal">
-
-        <Button
-            android:id="@+id/category_car_emergency_button"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_margin="10dp"
-            android:text="Car Emergency"
-            android:textSize="30sp"/>
-
-        <Button
-            android:id="@+id/category_car_warning_button"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_margin="10dp"
-            android:text="Car Warning"
-            android:textSize="30sp"/>
-
-        <Button
-            android:id="@+id/category_car_info_button"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_margin="10dp"
-            android:text="Car Information (No heads-up)"
-            android:textSize="30sp"/>
-    </LinearLayout>
-</LinearLayout>
+</ScrollView>
\ No newline at end of file
diff --git a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/connectivity/ConnectivityFragment.java b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/connectivity/ConnectivityFragment.java
index 23565ed..31b83cc 100644
--- a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/connectivity/ConnectivityFragment.java
+++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/connectivity/ConnectivityFragment.java
@@ -515,15 +515,30 @@
     }
 
     private void updateApState() {
-        String apState = sWifiApStates.get(mWifiManager.getWifiApState(), "?");
-        String staState = sWifiStaStates.get(mWifiManager.getWifiState(), "?");
+        int apState = mWifiManager.getWifiApState();
+        String apStateTmp = sWifiApStates.get(apState, "?");
+        final String staStateStr = sWifiStaStates.get(mWifiManager.getWifiState(), "?");
 
+        WifiConfiguration config = mWifiManager.getWifiApConfiguration();
+        if (config != null && config.SSID != null && apState == WifiManager.WIFI_AP_STATE_ENABLED) {
+            apStateTmp += " (" + config.SSID + "/" + config.preSharedKey + ")";
+        }
+
+        final String apStateStr = apStateTmp;
         mTetheringStatusPolled.post(() -> {
-            mTetheringStatusPolled.setText(apState);
-            mWifiStatusPolled.setText(staState);
+            mTetheringStatusPolled.setText(apStateStr);
+            mWifiStatusPolled.setText(staStateStr);
         });
     }
 
+    private void setTetheringStatus(String status) {
+        mTetheringStatus.post(() -> mTetheringStatus.setText(status));
+    }
+
+    private void setLocalOnlyStatus(String status) {
+        mLocalOnlyStatus.post(() -> mLocalOnlyStatus.setText(status));
+    }
+
     public void showToast(String text) {
         Toast toast = Toast.makeText(getContext(), text, Toast.LENGTH_SHORT);
         TextView v = (TextView) toast.getView().findViewById(android.R.id.message);
@@ -540,18 +555,16 @@
     }
 
     private void startTethering() {
-        mTetheringStatus.setText("starting...");
+        setTetheringStatus("starting...");
 
         ConnectivityManager.OnStartTetheringCallback cb =
                 new ConnectivityManager.OnStartTetheringCallback() {
             public void onTetheringStarted() {
-                WifiConfiguration config = mWifiManager.getWifiApConfiguration();
-                mTetheringStatus.setText("started ("
-                        + config.SSID + "/" + config.preSharedKey + ")");
+                setTetheringStatus("started");
             }
 
             public void onTetheringFailed() {
-                mTetheringStatus.setText("failed");
+                setTetheringStatus("failed");
             }
         };
 
@@ -559,59 +572,59 @@
     }
 
     private void stopTethering() {
-        mTetheringStatus.setText("stopping...");
+        setTetheringStatus("stopping...");
         mConnectivityManager.stopTethering(ConnectivityManager.TETHERING_WIFI);
-        mTetheringStatus.setText("stopped");
+        setTetheringStatus("stopped");
     }
 
     private WifiManager.LocalOnlyHotspotReservation mLocalOnlyReservation;
 
     private void startLocalOnly() {
-        mLocalOnlyStatus.setText("starting...");
+        setLocalOnlyStatus("starting...");
 
         UserHandle user = Process.myUserHandle();
         if (!mLocationManager.isLocationEnabledForUser(user)) {
-            mLocalOnlyStatus.setText("enabling location...");
+            setLocalOnlyStatus("enabling location...");
             mLocationManager.setLocationEnabledForUser(true, user);
-            mLocalOnlyStatus.setText("location enabled; starting...");
+            setLocalOnlyStatus("location enabled; starting...");
         }
 
         WifiManager.LocalOnlyHotspotCallback cb = new WifiManager.LocalOnlyHotspotCallback() {
             public void onStarted(WifiManager.LocalOnlyHotspotReservation reservation) {
                 mLocalOnlyReservation = reservation;
                 WifiConfiguration config = reservation.getWifiConfiguration();
-                mLocalOnlyStatus.setText("started ("
+                setLocalOnlyStatus("started ("
                         + config.SSID + "/" + config.preSharedKey + ")");
             };
 
             public void onStopped() {
-                mLocalOnlyStatus.setText("stopped");
+                setLocalOnlyStatus("stopped");
             };
 
             public void onFailed(int reason) {
-                mLocalOnlyStatus.setText("failed " + reason);
+                setLocalOnlyStatus("failed " + reason);
             };
         };
 
         try {
             mWifiManager.startLocalOnlyHotspot(cb, null);
         } catch (IllegalStateException ex) {
-            mLocalOnlyStatus.setText(ex.getMessage());
+            setLocalOnlyStatus(ex.getMessage());
         }
     }
 
     private void stopLocalOnly() {
-        mLocalOnlyStatus.setText("stopping...");
+        setLocalOnlyStatus("stopping...");
 
         WifiManager.LocalOnlyHotspotReservation reservation = mLocalOnlyReservation;
         mLocalOnlyReservation = null;
 
         if (reservation == null) {
-            mLocalOnlyStatus.setText("no reservation");
+            setLocalOnlyStatus("no reservation");
             return;
         }
 
         reservation.close();
-        mLocalOnlyStatus.setText("stopped");
+        setLocalOnlyStatus("stopped");
     }
 }