Removed BOOT_LOCKED_COMPLETED from CarLocationService.
Bug: b/129955669
Test: atest CarLocationServiceTest
Change-Id: I12d9831892762c8c2bf8b2f27a5c59d8a54c678a
diff --git a/service/src/com/android/car/CarLocationService.java b/service/src/com/android/car/CarLocationService.java
index d5f6ae6..90eba07 100644
--- a/service/src/com/android/car/CarLocationService.java
+++ b/service/src/com/android/car/CarLocationService.java
@@ -132,7 +132,6 @@
logd("init");
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_USER_SWITCHED);
- filter.addAction(Intent.ACTION_LOCKED_BOOT_COMPLETED);
filter.addAction(LocationManager.MODE_CHANGED_ACTION);
filter.addAction(LocationManager.PROVIDERS_CHANGED_ACTION);
mContext.registerReceiver(this, filter);
@@ -183,14 +182,7 @@
public void onReceive(Context context, Intent intent) {
logd("onReceive " + intent);
String action = intent.getAction();
- if (action == Intent.ACTION_LOCKED_BOOT_COMPLETED) {
- // If the system user is not headless, then we can inject location as soon as the
- // system has completed booting.
- if (!mCarUserManagerHelper.isHeadlessSystemUser()) {
- logd("not headless on boot complete");
- asyncOperation(() -> loadLocation());
- }
- } else if (action == Intent.ACTION_USER_SWITCHED) {
+ if (action == Intent.ACTION_USER_SWITCHED) {
int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
logd("USER_SWITCHED: " + userHandle);
if (mCarUserManagerHelper.isHeadlessSystemUser()
diff --git a/tests/carservice_unit_test/src/com/android/car/CarLocationServiceTest.java b/tests/carservice_unit_test/src/com/android/car/CarLocationServiceTest.java
index a264c91..504c098 100644
--- a/tests/carservice_unit_test/src/com/android/car/CarLocationServiceTest.java
+++ b/tests/carservice_unit_test/src/com/android/car/CarLocationServiceTest.java
@@ -154,8 +154,8 @@
}
/**
- * Test that the {@link CarLocationService} registers to receive the locked boot completed
- * intent and ignition sensor events upon initialization.
+ * Test that the {@link CarLocationService} registers to receive the ignition sensor event upon
+ * initialization.
*/
@Test
public void testRegistersToReceiveEvents() {
@@ -163,10 +163,9 @@
mCarLocationService.init();
verify(mMockContext).registerReceiver(eq(mCarLocationService), argument.capture());
IntentFilter intentFilter = argument.getValue();
- assertEquals(4, intentFilter.countActions());
+ assertEquals(3, intentFilter.countActions());
String[] actions = {intentFilter.getAction(0), intentFilter.getAction(1),
- intentFilter.getAction(2), intentFilter.getAction(3)};
- assertTrue(ArrayUtils.contains(actions, Intent.ACTION_LOCKED_BOOT_COMPLETED));
+ intentFilter.getAction(2)};
assertTrue(ArrayUtils.contains(actions, LocationManager.MODE_CHANGED_ACTION));
assertTrue(ArrayUtils.contains(actions, LocationManager.PROVIDERS_CHANGED_ACTION));
assertTrue(ArrayUtils.contains(actions, Intent.ACTION_USER_SWITCHED));
@@ -187,39 +186,7 @@
/**
* Test that the {@link CarLocationService} parses a location from a JSON serialization and then
- * injects it into the {@link LocationManager} upon boot complete if the system user is not
- * headless.
- */
- @Test
- public void testLoadsLocationOnLockedBootComplete() throws Exception {
- long currentTime = System.currentTimeMillis();
- long elapsedTime = SystemClock.elapsedRealtimeNanos();
- long pastTime = currentTime - 60000;
- writeCacheFile("{\"provider\": \"gps\", \"latitude\": 16.7666, \"longitude\": 3.0026,"
- + "\"accuracy\":12.3, \"captureTime\": " + pastTime + "}");
- ArgumentCaptor<Location> argument = ArgumentCaptor.forClass(Location.class);
- when(mMockContext.getSystemService(Context.LOCATION_SERVICE))
- .thenReturn(mMockLocationManager);
- when(mMockSystemInterface.getSystemCarDir()).thenReturn(mTempDirectory);
- when(mMockLocationManager.injectLocation(argument.capture())).thenReturn(true);
- when(mMockCarUserManagerHelper.isHeadlessSystemUser()).thenReturn(false);
-
- mCarLocationService.onReceive(mMockContext,
- new Intent(Intent.ACTION_LOCKED_BOOT_COMPLETED));
- mLatch.await();
-
- Location location = argument.getValue();
- assertEquals("gps", location.getProvider());
- assertEquals(16.7666, location.getLatitude());
- assertEquals(3.0026, location.getLongitude());
- assertEquals(12.3f, location.getAccuracy());
- assertTrue(location.getTime() >= currentTime);
- assertTrue(location.getElapsedRealtimeNanos() >= elapsedTime);
- }
-
- /**
- * Test that the {@link CarLocationService} parses a location from a JSON serialization and then
- * injects it into the {@link LocationManager} upon user switch if the system user is headless.
+ * injects it into the {@link LocationManager} upon user switch.
*/
@Test
public void testLoadsLocationWithHeadlessSystemUser() throws Exception {
@@ -259,8 +226,10 @@
.thenReturn(mMockLocationManager);
when(mMockLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER))
.thenReturn(null);
- mCarLocationService.onReceive(mMockContext,
- new Intent(Intent.ACTION_LOCKED_BOOT_COMPLETED));
+ when(mMockCarUserManagerHelper.isHeadlessSystemUser()).thenReturn(true);
+ Intent userSwitchedIntent = new Intent(Intent.ACTION_USER_SWITCHED);
+ userSwitchedIntent.putExtra(Intent.EXTRA_USER_HANDLE, 11);
+ mCarLocationService.onReceive(mMockContext, userSwitchedIntent);
mLatch.await();
verify(mMockLocationManager, never()).injectLocation(any());
}
@@ -275,8 +244,10 @@
.thenReturn(mMockLocationManager);
when(mMockLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER))
.thenReturn(null);
- mCarLocationService.onReceive(mMockContext,
- new Intent(Intent.ACTION_LOCKED_BOOT_COMPLETED));
+ when(mMockCarUserManagerHelper.isHeadlessSystemUser()).thenReturn(true);
+ Intent userSwitchedIntent = new Intent(Intent.ACTION_USER_SWITCHED);
+ userSwitchedIntent.putExtra(Intent.EXTRA_USER_HANDLE, 11);
+ mCarLocationService.onReceive(mMockContext, userSwitchedIntent);
mLatch.await();
verify(mMockLocationManager, never()).injectLocation(any());
}
@@ -291,8 +262,10 @@
.thenReturn(mMockLocationManager);
when(mMockLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER))
.thenReturn(null);
- mCarLocationService.onReceive(mMockContext,
- new Intent(Intent.ACTION_LOCKED_BOOT_COMPLETED));
+ when(mMockCarUserManagerHelper.isHeadlessSystemUser()).thenReturn(true);
+ Intent userSwitchedIntent = new Intent(Intent.ACTION_USER_SWITCHED);
+ userSwitchedIntent.putExtra(Intent.EXTRA_USER_HANDLE, 11);
+ mCarLocationService.onReceive(mMockContext, userSwitchedIntent);
mLatch.await();
verify(mMockLocationManager, never()).injectLocation(any());
}
@@ -308,8 +281,10 @@
.thenReturn(mMockLocationManager);
when(mMockLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER))
.thenReturn(null);
- mCarLocationService.onReceive(mMockContext,
- new Intent(Intent.ACTION_LOCKED_BOOT_COMPLETED));
+ when(mMockCarUserManagerHelper.isHeadlessSystemUser()).thenReturn(true);
+ Intent userSwitchedIntent = new Intent(Intent.ACTION_USER_SWITCHED);
+ userSwitchedIntent.putExtra(Intent.EXTRA_USER_HANDLE, 11);
+ mCarLocationService.onReceive(mMockContext, userSwitchedIntent);
mLatch.await();
verify(mMockLocationManager, never()).injectLocation(any());
}
@@ -328,8 +303,10 @@
.thenReturn(mMockLocationManager);
when(mMockLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER))
.thenReturn(null);
- mCarLocationService.onReceive(mMockContext,
- new Intent(Intent.ACTION_LOCKED_BOOT_COMPLETED));
+ when(mMockCarUserManagerHelper.isHeadlessSystemUser()).thenReturn(true);
+ Intent userSwitchedIntent = new Intent(Intent.ACTION_USER_SWITCHED);
+ userSwitchedIntent.putExtra(Intent.EXTRA_USER_HANDLE, 11);
+ mCarLocationService.onReceive(mMockContext, userSwitchedIntent);
mLatch.await();
verify(mMockLocationManager, never()).injectLocation(any());
}