Merge "Add FixedActivityService" into qt-qpr1-dev
diff --git a/car_product/sepolicy/private/bluetooth.te b/car_product/sepolicy/private/bluetooth.te
new file mode 100644
index 0000000..6ba74c2
--- /dev/null
+++ b/car_product/sepolicy/private/bluetooth.te
@@ -0,0 +1 @@
+allow bluetooth mediametrics_service:service_manager find;
diff --git a/service/src/com/android/car/vms/VmsClientManager.java b/service/src/com/android/car/vms/VmsClientManager.java
index 710793c..a00e179 100644
--- a/service/src/com/android/car/vms/VmsClientManager.java
+++ b/service/src/com/android/car/vms/VmsClientManager.java
@@ -146,16 +146,16 @@
CarUserService userService, CarUserManagerHelper userManagerHelper,
VmsHalService halService) {
this(context, brokerService, userService, userManagerHelper, halService,
- Binder::getCallingUid);
+ new Handler(Looper.getMainLooper()), Binder::getCallingUid);
}
@VisibleForTesting
VmsClientManager(Context context, VmsBrokerService brokerService,
CarUserService userService, CarUserManagerHelper userManagerHelper,
- VmsHalService halService, IntSupplier getCallingUid) {
+ VmsHalService halService, Handler handler, IntSupplier getCallingUid) {
mContext = context;
mPackageManager = context.getPackageManager();
- mHandler = new Handler(Looper.getMainLooper());
+ mHandler = handler;
mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
mUserService = userService;
mUserManagerHelper = userManagerHelper;
diff --git a/tests/carservice_unit_test/src/com/android/car/vms/VmsClientManagerTest.java b/tests/carservice_unit_test/src/com/android/car/vms/VmsClientManagerTest.java
index b90dac4..73217e7 100644
--- a/tests/carservice_unit_test/src/com/android/car/vms/VmsClientManagerTest.java
+++ b/tests/carservice_unit_test/src/com/android/car/vms/VmsClientManagerTest.java
@@ -97,6 +97,8 @@
private static final String HAL_CLIENT_NAME = "HalClient";
private static final String UNKNOWN_PACKAGE = "UnknownPackage";
+ private static final long MILLIS_BEFORE_REBIND = 100;
+
@Rule
public MockitoRule mMockitoRule = MockitoJUnit.rule();
@Mock
@@ -120,6 +122,12 @@
private VmsHalService mHal;
@Mock
+ private Handler mHandler;
+
+ @Captor
+ private ArgumentCaptor<Runnable> mRebindCaptor;
+
+ @Mock
private VmsPublisherService mPublisherService;
@Mock
@@ -152,7 +160,7 @@
when(mResources.getInteger(
com.android.car.R.integer.millisecondsBeforeRebindToVmsPublisher)).thenReturn(
- 5);
+ (int) MILLIS_BEFORE_REBIND);
when(mResources.getStringArray(
com.android.car.R.array.vmsPublisherSystemClients)).thenReturn(
new String[]{ SYSTEM_CLIENT });
@@ -168,7 +176,7 @@
mCallingAppUid = UserHandle.getUid(USER_ID, 0);
mClientManager = new VmsClientManager(mContext, mBrokerService, mUserService,
- mUserManagerHelper, mHal, () -> mCallingAppUid);
+ mUserManagerHelper, mHal, mHandler, () -> mCallingAppUid);
verify(mHal).setClientManager(mClientManager);
mClientManager.setPublisherService(mPublisherService);
@@ -180,11 +188,10 @@
@After
public void tearDown() throws Exception {
- Thread.sleep(10); // Time to allow for delayed rebinds to settle
verify(mContext, atLeast(0)).getSystemService(eq(Context.USER_SERVICE));
verify(mContext, atLeast(0)).getResources();
verify(mContext, atLeast(0)).getPackageManager();
- verifyNoMoreInteractions(mContext, mBrokerService, mHal, mPublisherService);
+ verifyNoMoreInteractions(mContext, mBrokerService, mHal, mPublisherService, mHandler);
}
@Test
@@ -467,7 +474,7 @@
connection.onServiceDisconnected(null);
verify(mPublisherService).onClientDisconnected(eq(SYSTEM_CLIENT_NAME));
- Thread.sleep(10);
+ verifyAndRunRebindTask();
verify(mContext).unbindService(connection);
verifySystemBind(1);
}
@@ -490,6 +497,8 @@
binder = createPublisherBinder();
connection.onServiceConnected(null, binder);
verifyOnClientConnected(SYSTEM_CLIENT_NAME, binder);
+
+ verifyAndRunRebindTask();
// No more interactions (verified by tearDown)
}
@@ -507,7 +516,7 @@
connection.onBindingDied(null);
verify(mPublisherService).onClientDisconnected(eq(SYSTEM_CLIENT_NAME));
- Thread.sleep(10);
+ verifyAndRunRebindTask();
verify(mContext).unbindService(connection);
verifySystemBind(1);
}
@@ -523,7 +532,7 @@
verifyZeroInteractions(mPublisherService);
- Thread.sleep(10);
+ verifyAndRunRebindTask();
verify(mContext).unbindService(connection);
verifySystemBind(1);
}
@@ -541,7 +550,7 @@
connection.onServiceDisconnected(null);
verify(mPublisherService).onClientDisconnected(eq(USER_CLIENT_NAME));
- Thread.sleep(10);
+ verifyAndRunRebindTask();
verify(mContext).unbindService(connection);
verifyUserBind(1);
}
@@ -564,6 +573,8 @@
binder = createPublisherBinder();
connection.onServiceConnected(null, binder);
verifyOnClientConnected(USER_CLIENT_NAME, binder);
+
+ verifyAndRunRebindTask();
// No more interactions (verified by tearDown)
}
@@ -580,7 +591,7 @@
connection.onBindingDied(null);
verify(mPublisherService).onClientDisconnected(eq(USER_CLIENT_NAME));
- Thread.sleep(10);
+ verifyAndRunRebindTask();
verify(mContext).unbindService(connection);
verifyUserBind(1);
}
@@ -596,7 +607,7 @@
verifyZeroInteractions(mPublisherService);
- Thread.sleep(10);
+ verifyAndRunRebindTask();
verify(mContext).unbindService(connection);
verifyUserBind(1);
}
@@ -975,6 +986,11 @@
eq(Context.BIND_AUTO_CREATE), any(Handler.class), eq(user));
}
+ private void verifyAndRunRebindTask() {
+ verify(mHandler).postDelayed(mRebindCaptor.capture(), eq(MILLIS_BEFORE_REBIND));
+ mRebindCaptor.getValue().run();
+ }
+
private void verifyOnClientConnected(String publisherName, IBinder binder) {
ArgumentCaptor<IVmsPublisherClient> clientCaptor =
ArgumentCaptor.forClass(IVmsPublisherClient.class);
diff --git a/user/car-user-lib/src/android/car/userlib/CarUserManagerHelper.java b/user/car-user-lib/src/android/car/userlib/CarUserManagerHelper.java
index 0745945..72332d9 100644
--- a/user/car-user-lib/src/android/car/userlib/CarUserManagerHelper.java
+++ b/user/car-user-lib/src/android/car/userlib/CarUserManagerHelper.java
@@ -238,10 +238,8 @@
// If an override user is present and a real user, return it
if (bootUserOverride != BOOT_USER_NOT_FOUND
&& allUsers.contains(bootUserOverride)) {
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "Boot user id override found for initial user, user id: "
- + bootUserOverride);
- }
+ Log.i(TAG, "Boot user id override found for initial user, user id: "
+ + bootUserOverride);
return bootUserOverride;
}
@@ -249,19 +247,15 @@
int lastActiveUser = getLastActiveUser();
if (lastActiveUser != UserHandle.USER_SYSTEM
&& allUsers.contains(lastActiveUser)) {
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "Last active user loaded for initial user, user id: "
- + lastActiveUser);
- }
+ Log.i(TAG, "Last active user loaded for initial user, user id: "
+ + lastActiveUser);
return lastActiveUser;
}
// If all else fails, return the smallest user id
int returnId = Collections.min(allUsers);
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "Saved ids were invalid. Returning smallest user id, user id: "
- + returnId);
- }
+ Log.i(TAG, "Saved ids were invalid. Returning smallest user id, user id: "
+ + returnId);
return returnId;
}