Merge "Make alert dialog buttons always on the left" into rvc-dev
diff --git a/TEST_MAPPING b/TEST_MAPPING
new file mode 100644
index 0000000..6239f78
--- /dev/null
+++ b/TEST_MAPPING
@@ -0,0 +1,12 @@
+{
+  "auto-postsubmit": [
+    {
+      "name": "AndroidCarApiTest",
+      "options": [
+        {
+          "include-filter": "android.car.apitest.PreInstalledPackagesTest"
+        }
+      ]
+    }
+  ]
+}
\ No newline at end of file
diff --git a/car-lib/src/android/car/VehicleAreaSeat.java b/car-lib/src/android/car/VehicleAreaSeat.java
index 792ca27..611827d 100644
--- a/car-lib/src/android/car/VehicleAreaSeat.java
+++ b/car-lib/src/android/car/VehicleAreaSeat.java
@@ -16,16 +16,26 @@
 package android.car;
 
 import android.annotation.IntDef;
-import android.car.hardware.CarPropertyValue;
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 
 /**
- * VehicleAreaSeat is an abstraction for a seat in a car. Some car APIs like
- * {@link CarPropertyValue} may provide control per seat and
- * values defined here should be used to distinguish different seats.
+ * Object used to indicate the area value for car properties which have area type
+ * {@link VehicleAreaType#VEHICLE_AREA_TYPE_SEAT}.
+ * <p>
+ * The constants defined by {@link VehicleAreaSeat} indicate the position for area type
+ * {@link VehicleAreaType#VEHICLE_AREA_TYPE_SEAT}. A property can have a single or a combination of
+ * positions. Developers can query the position using
+ * {@link android.car.hardware.property.CarPropertyManager#getAreaId(int, int)}.
+ * </p><p>
+ * Refer to {@link android.car.hardware.CarPropertyConfig#getAreaIds()} for more information about
+ * areaId.
+ * </p>
  */
+
+// This class is only designed to provide constants for VehicleAreaSeat. The constants should
+// be same as VehicleAreaSeat in /hardware/interfaces/automotive/vehicle/2.0/types.hal.
 public final class VehicleAreaSeat {
     /** List of vehicle's seats. */
     public static final int SEAT_UNKNOWN = 0;
diff --git a/car-lib/src/android/car/VehicleAreaType.java b/car-lib/src/android/car/VehicleAreaType.java
index 826ffe3..5cd5c7a 100644
--- a/car-lib/src/android/car/VehicleAreaType.java
+++ b/car-lib/src/android/car/VehicleAreaType.java
@@ -16,15 +16,24 @@
 package android.car;
 
 import android.annotation.IntDef;
+import android.car.hardware.CarPropertyConfig;
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 
 /**
- * Represents vehicle area such as window, door, seat, etc.
- * See also {@link VehicleAreaDoor}, {@link VehicleAreaSeat},
- * {@link VehicleAreaWindow},
+ * Object used to indicate area types for car properties.
+ * <p>
+ * The constants defined by {@link VehicleAreaType} indicate the area types for properties.  A
+ * property only has one area type. Developers can query the area type using
+ * {@link CarPropertyConfig#getPropertyType()}.
+ * </p><p>
+ * Refer to {@link VehicleAreaSeat} and {@link VehicleAreaWheel} for more information about areaId.
+ * </p>
  */
+
+// This class is only designed to provide constants for VehicleAreaType. The constants should
+// exactly be same as VehicleAreaType in /hardware/interfaces/automotive/vehicle/2.0/types.hal.
 public final class VehicleAreaType {
     /** Used for global properties */
     public static final int VEHICLE_AREA_TYPE_GLOBAL = 0;
diff --git a/car-lib/src/android/car/diagnostic/FloatSensorIndex.java b/car-lib/src/android/car/diagnostic/FloatSensorIndex.java
index 6ec7e8c..790d43f 100644
--- a/car-lib/src/android/car/diagnostic/FloatSensorIndex.java
+++ b/car-lib/src/android/car/diagnostic/FloatSensorIndex.java
@@ -12,12 +12,13 @@
  * 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 android.car.diagnostic;
 
 import android.annotation.IntDef;
 import android.annotation.SystemApi;
+
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 
diff --git a/car-lib/src/android/car/diagnostic/IntegerSensorIndex.java b/car-lib/src/android/car/diagnostic/IntegerSensorIndex.java
index 15291f7..83fd303 100644
--- a/car-lib/src/android/car/diagnostic/IntegerSensorIndex.java
+++ b/car-lib/src/android/car/diagnostic/IntegerSensorIndex.java
@@ -12,12 +12,13 @@
  * 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 android.car.diagnostic;
 
 import android.annotation.IntDef;
 import android.annotation.SystemApi;
+
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 
diff --git a/evs/manager/1.1/HalCamera.cpp b/evs/manager/1.1/HalCamera.cpp
index 4b5feae..f0ae13d 100644
--- a/evs/manager/1.1/HalCamera.cpp
+++ b/evs/manager/1.1/HalCamera.cpp
@@ -14,15 +14,12 @@
  * limitations under the License.
  */
 
+#include <android-base/logging.h>
+
 #include "HalCamera.h"
 #include "VirtualCamera.h"
 #include "Enumerator.h"
 
-#include <android-base/logging.h>
-#include <ui/GraphicBufferAllocator.h>
-#include <ui/GraphicBufferMapper.h>
-
-
 namespace android {
 namespace automotive {
 namespace evs {
diff --git a/evs/manager/1.1/HalCamera.h b/evs/manager/1.1/HalCamera.h
index 88f8592..240737e 100644
--- a/evs/manager/1.1/HalCamera.h
+++ b/evs/manager/1.1/HalCamera.h
@@ -20,12 +20,12 @@
 #include <android/hardware/automotive/evs/1.1/types.h>
 #include <android/hardware/automotive/evs/1.1/IEvsCamera.h>
 #include <android/hardware/automotive/evs/1.1/IEvsCameraStream.h>
-#include <ui/GraphicBuffer.h>
+#include <utils/Mutex.h>
 #include <utils/SystemClock.h>
 
-#include <thread>
-#include <list>
 #include <deque>
+#include <list>
+#include <thread>
 #include <unordered_map>
 
 #include "sync/unique_fd.h"
diff --git a/evs/manager/1.1/VirtualCamera.cpp b/evs/manager/1.1/VirtualCamera.cpp
index cfef6ea..09c6804 100644
--- a/evs/manager/1.1/VirtualCamera.cpp
+++ b/evs/manager/1.1/VirtualCamera.cpp
@@ -14,14 +14,13 @@
  * limitations under the License.
  */
 
+#include <android/hardware_buffer.h>
+#include <android-base/logging.h>
+
 #include "VirtualCamera.h"
 #include "HalCamera.h"
 #include "Enumerator.h"
 
-#include <android-base/logging.h>
-#include <ui/GraphicBufferAllocator.h>
-#include <ui/GraphicBufferMapper.h>
-
 using ::android::hardware::automotive::evs::V1_0::DisplayState;
 
 
diff --git a/evs/manager/1.1/VirtualCamera.h b/evs/manager/1.1/VirtualCamera.h
index 2a8eae9..e57ddcf 100644
--- a/evs/manager/1.1/VirtualCamera.h
+++ b/evs/manager/1.1/VirtualCamera.h
@@ -21,7 +21,6 @@
 #include <android/hardware/automotive/evs/1.1/IEvsCamera.h>
 #include <android/hardware/automotive/evs/1.1/IEvsCameraStream.h>
 #include <android/hardware/automotive/evs/1.1/IEvsDisplay.h>
-#include <ui/GraphicBuffer.h>
 
 #include <thread>
 #include <deque>
diff --git a/service/src/com/android/car/user/CarUserService.java b/service/src/com/android/car/user/CarUserService.java
index d570ccb..fc3d3a4 100644
--- a/service/src/com/android/car/user/CarUserService.java
+++ b/service/src/com/android/car/user/CarUserService.java
@@ -450,7 +450,7 @@
     @NonNull
     public List<UserInfo> getAllDrivers() {
         checkManageUsersOrDumpPermission("getAllDrivers");
-        return getUsers((user) -> !isSystemUser(user.id) && user.isEnabled()
+        return getUsers((user) -> !UserHelper.isHeadlessSystemUser(user.id) && user.isEnabled()
                 && !user.isManagedProfile() && !user.isEphemeral());
     }
 
@@ -465,8 +465,8 @@
     public List<UserInfo> getPassengers(@UserIdInt int driverId) {
         checkManageUsersOrDumpPermission("getPassengers");
         return getUsers((user) -> {
-            return !isSystemUser(user.id) && user.isEnabled() && user.isManagedProfile()
-                    && user.profileGroupId == driverId;
+            return !UserHelper.isHeadlessSystemUser(user.id) && user.isEnabled()
+                    && user.isManagedProfile() && user.profileGroupId == driverId;
         });
     }
 
@@ -1106,11 +1106,6 @@
         return usersInfo;
     }
 
-    /** Returns whether the given user is a system user. */
-    private static boolean isSystemUser(@UserIdInt int userId) {
-        return userId == UserHandle.USER_SYSTEM;
-    }
-
     private void updateDefaultUserRestriction() {
         // We want to set restrictions on system and guest users only once. These are persisted
         // onto disk, so it's sufficient to do it once + we minimize the number of disk writes.
@@ -1405,7 +1400,7 @@
     }
 
     private void onUserSwitching(@UserIdInt int fromUserId, @UserIdInt int toUserId) {
-        Log.i(TAG_USER, "onSwitchUser() callback for user " + toUserId);
+        Log.i(TAG_USER, "onUserSwitching() callback for user " + toUserId);
         TimingsTraceLog t = new TimingsTraceLog(TAG_USER, Trace.TRACE_TAG_SYSTEM_SERVER);
         t.traceBegin("onUserSwitching-" + toUserId);
 
diff --git a/tests/android_car_api_test/src/android/car/apitest/PreInstalledPackagesTest.java b/tests/android_car_api_test/src/android/car/apitest/PreInstalledPackagesTest.java
new file mode 100644
index 0000000..f072fff
--- /dev/null
+++ b/tests/android_car_api_test/src/android/car/apitest/PreInstalledPackagesTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2020 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 android.car.apitest;
+
+import static com.android.compatibility.common.util.ShellUtils.runShellCommand;
+
+import static org.junit.Assert.fail;
+
+import android.text.TextUtils;
+
+import androidx.test.filters.FlakyTest;
+
+import org.junit.Test;
+
+public final class PreInstalledPackagesTest {
+
+    @FlakyTest // TODO(b/154112291): remove once it's passing on acloud
+    @Test
+    public void testNoCriticalErrors_currentMode() {
+        assertNoCriticalErrors(/* enforceMode= */ false);
+    }
+
+    @FlakyTest // TODO(b/154112291): remove once it's passing on acloud
+    @Test
+    public void testNoCriticalErrors_enforceMode() {
+        assertNoCriticalErrors(/* enforceMode= */ true);
+    }
+
+    private static void assertNoCriticalErrors(boolean enforceMode) {
+        String cmd = "cmd user report-system-user-package-whitelist-problems --critical-only%s";
+        String mode =  enforceMode ? " --mode 1" : "";
+        String result = runShellCommand(cmd, mode);
+        if (!TextUtils.isEmpty(result)) {
+            fail("Command '" + cmd + " reported errors:\n" + result);
+        }
+    }
+}
diff --git a/tests/carservice_unit_test/src/com/android/car/user/CarUserServiceTest.java b/tests/carservice_unit_test/src/com/android/car/user/CarUserServiceTest.java
index c44ea24..560d5c6 100644
--- a/tests/carservice_unit_test/src/com/android/car/user/CarUserServiceTest.java
+++ b/tests/carservice_unit_test/src/com/android/car/user/CarUserServiceTest.java
@@ -289,7 +289,8 @@
     }
 
     /**
-     * Test that the {@link CarUserService} updates last active user on user switch.
+     * Test that the {@link CarUserService} updates last active user on user switch in non-headless
+     * system user mode.
      */
     @Test
     public void testLastActiveUserUpdatedOnUserSwitch_nonHeadlessSystemUser() throws Exception {
@@ -301,13 +302,17 @@
         verifyLastActiveUserSet(mRegularUser.id);
     }
 
+    /**
+     * Test that the {@link CarUserService} doesn't update last active user on user switch in
+     * headless system user mode.
+     */
     @Test
     public void testLastActiveUserUpdatedOnUserSwitch_headlessSystemUser() throws Exception {
         mockIsHeadlessSystemUser(mRegularUser.id, true);
         mockUmGetSystemUser(mMockedUserManager);
         mockExistingUsers();
 
-        sendUserSwitchingEvent(mAdminUser.id, UserHandle.USER_SYSTEM);
+        sendUserSwitchingEvent(mAdminUser.id, mRegularUser.id);
 
         verifyLastActiveUserNotSet();
     }
@@ -603,7 +608,8 @@
                 new UserInfo(15, "test15", UserInfo.FLAG_EPHEMERAL),
                 new UserInfo(16, "test16", UserInfo.FLAG_DISABLED),
                 new UserInfo(17, "test17", UserInfo.FLAG_MANAGED_PROFILE),
-                new UserInfo(18, "test18", UserInfo.FLAG_MANAGED_PROFILE)
+                new UserInfo(18, "test18", UserInfo.FLAG_MANAGED_PROFILE),
+                new UserInfo(19, "test19", NO_USER_INFO_FLAGS)
         ));
         // Parent: test10, child: test12
         associateParentChild(users.get(0), users.get(2));
@@ -617,12 +623,13 @@
     @Test
     public void testGetAllPossibleDrivers() {
         Set<Integer> expected = new HashSet<Integer>(Arrays.asList(10, 11, 13, 14));
-        doReturn(prepareUserList()).when(mMockedUserManager).getUsers(true);
+        when(mMockedUserManager.getUsers(true)).thenReturn(prepareUserList());
+        mockIsHeadlessSystemUser(19, true);
         for (UserInfo user : mCarUserService.getAllDrivers()) {
-            assertTrue(expected.contains(user.id));
+            assertThat(expected).contains(user.id);
             expected.remove(user.id);
         }
-        assertEquals(0, expected.size());
+        assertThat(expected).isEmpty();
     }
 
     @Test
@@ -632,18 +639,19 @@
                 put(0, new HashSet<Integer>());
                 put(10, new HashSet<Integer>(Arrays.asList(12)));
                 put(11, new HashSet<Integer>());
-                put(13, new HashSet<Integer>(Arrays.asList(17, 18)));
+                put(13, new HashSet<Integer>(Arrays.asList(17)));
             }
         };
+        mockIsHeadlessSystemUser(18, true);
         for (int i = 0; i < testCases.size(); i++) {
-            doReturn(prepareUserList()).when(mMockedUserManager).getUsers(true);
+            when(mMockedUserManager.getUsers(true)).thenReturn(prepareUserList());
             List<UserInfo> passengers = mCarUserService.getPassengers(testCases.keyAt(i));
             HashSet<Integer> expected = testCases.valueAt(i);
             for (UserInfo user : passengers) {
-                assertTrue(expected.contains(user.id));
+                assertThat(expected).contains(user.id);
                 expected.remove(user.id);
             }
-            assertEquals(0, expected.size());
+            assertThat(expected).isEmpty();
         }
     }