Fix a crash during mock testing

Bug: 249161784

This fixes a crash during mock testing of the broadcast queue when
BOOT_COMPLETED broadcasts are simulated.  The umInternal variable is
null, and umInternal.getUserInfo() throws a null pointer
exception. The change avoids dereferencing umInternal if it is null.

This was tested with a draft version of the broadcast replay code; it
was verified that BOOT_COMPLETED did not generate an NPE.

Test: atest
 * FrameworksMockingServicesTests:BroadcastQueueTest
Change-Id: I31f57f1dcb7f2ed9f02558f841e18958e8097373
This commit is contained in:
Lee Shombert
2022-10-24 08:09:47 -07:00
parent 281eb31fee
commit c185ae1c29

View File

@@ -1488,7 +1488,8 @@ public class BroadcastQueueImpl extends BroadcastQueue {
// LocalServices.getService() here.
final UserManagerInternal umInternal = LocalServices.getService(
UserManagerInternal.class);
final UserInfo userInfo = umInternal.getUserInfo(r.userId);
final UserInfo userInfo =
(umInternal != null) ? umInternal.getUserInfo(r.userId) : null;
if (userInfo != null) {
userType = UserManager.getUserTypeForStatsd(userInfo.userType);
}