Replace GPS provider with FUSED provider to have both GPS & network location
Bug: 358360971
Flag: com.android.internal.telephony.flags.oem_enabled_satellite_flag
Test: atest
SatelliteAccessControllerTest(http://ab/I63400010308766089-passed)
Test: Manually verified if GPS is checked with priority then NETWORK with FUSED provider, more detail is updated at b/358360971#comment12 and b/358360971#comment17.
Change-Id: I72752c2802dfa9362cb5186985ec121af83c7a54
diff --git a/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java b/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java
index 032fa9c..2a64caa 100644
--- a/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java
+++ b/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java
@@ -198,7 +198,7 @@
};
@GuardedBy("mLock")
@Nullable
- CancellationSignal mLocationRequestCancellationSignal = null;
+ protected CancellationSignal mLocationRequestCancellationSignal = null;
private int mS2Level = DEFAULT_S2_LEVEL;
@GuardedBy("mLock")
@Nullable
@@ -948,14 +948,14 @@
*/
private boolean isRegionDisallowed(List<String> networkCountryIsoList) {
if (networkCountryIsoList.isEmpty()) {
- plogd("isRegionDisallowed : true : it's not sure if empty is disallowed");
+ plogd("isRegionDisallowed : false : network country code is not available");
return false;
}
for (String countryCode : networkCountryIsoList) {
if (isSatelliteAccessAllowedForLocation(List.of(countryCode))) {
plogd("isRegionDisallowed : false : Country Code " + countryCode
- + " is in the list from the configuration");
+ + " is allowed but not sure if current location should be allowed.");
return false;
}
}
@@ -1279,18 +1279,20 @@
}
}
- private void queryCurrentLocation() {
+ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
+ protected void queryCurrentLocation() {
synchronized (mLock) {
if (mLocationRequestCancellationSignal != null) {
- plogd("Request for current location was already sent to LocationManager");
+ plogd("queryCurrentLocation : "
+ + "Request for current location was already sent to LocationManager");
return;
}
mLocationRequestCancellationSignal = new CancellationSignal();
mLocationQueryStartTimeMillis = System.currentTimeMillis();
- mLocationManager.getCurrentLocation(LocationManager.GPS_PROVIDER,
+ mLocationManager.getCurrentLocation(LocationManager.FUSED_PROVIDER,
new LocationRequest.Builder(0)
.setQuality(LocationRequest.QUALITY_HIGH_ACCURACY)
- .setLocationSettingsIgnored(true)
+ .setLocationSettingsIgnored(isInEmergency())
.build(),
mLocationRequestCancellationSignal, this::post,
this::onCurrentLocationAvailable);
diff --git a/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessControllerTest.java b/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessControllerTest.java
index 186fbd2..8a2b4d6 100644
--- a/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessControllerTest.java
+++ b/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessControllerTest.java
@@ -135,7 +135,7 @@
private static final long TIMEOUT = 500;
private static final List<String> EMPTY_STRING_LIST = new ArrayList<>();
private static final List<String> LOCATION_PROVIDERS =
- listOf(LocationManager.NETWORK_PROVIDER, LocationManager.GPS_PROVIDER);
+ listOf(LocationManager.NETWORK_PROVIDER, LocationManager.FUSED_PROVIDER);
private static final int SUB_ID = 0;
@Mock
@@ -203,6 +203,10 @@
private ArgumentCaptor<BroadcastReceiver> mLocationBroadcastReceiverCaptor;
@Captor
private ArgumentCaptor<IntentFilter> mIntentFilterCaptor;
+ @Captor
+ private ArgumentCaptor<LocationRequest> mLocationRequestCaptor;
+ @Captor
+ private ArgumentCaptor<String> mLocationProviderStringCaptor;
private boolean mQueriedSatelliteAllowed = false;
private int mQueriedSatelliteAllowedResultCode = SATELLITE_RESULT_SUCCESS;
@@ -294,7 +298,7 @@
when(mMockLocationManager.getProviders(true)).thenReturn(LOCATION_PROVIDERS);
when(mMockLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER))
.thenReturn(mMockLocation0);
- when(mMockLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER))
+ when(mMockLocationManager.getLastKnownLocation(LocationManager.FUSED_PROVIDER))
.thenReturn(mMockLocation1);
when(mMockLocation0.getLatitude()).thenReturn(0.0);
when(mMockLocation0.getLongitude()).thenReturn(0.0);
@@ -701,7 +705,7 @@
mTestableLooper.processAllMessages();
assertFalse(
mSatelliteAccessControllerUT.isKeepOnDeviceAccessControllerResourcesTimerStarted());
- verify(mMockLocationManager).getCurrentLocation(eq(LocationManager.GPS_PROVIDER),
+ verify(mMockLocationManager).getCurrentLocation(eq(LocationManager.FUSED_PROVIDER),
any(LocationRequest.class), mLocationRequestCancellationSignalCaptor.capture(),
any(Executor.class), mLocationRequestConsumerCaptor.capture());
assertTrue(mSatelliteAccessControllerUT.isWaitForCurrentLocationTimerStarted());
@@ -799,19 +803,20 @@
ALLOWED_STATE_CACHE_VALID_DURATION_NANOS - 10;
// cash is valid and never queried before
- mSatelliteAccessControllerUT.mLastLocationQueryForPossibleChangeInAllowedRegionTimeNanos = 0;
+ mSatelliteAccessControllerUT.mLastLocationQueryForPossibleChangeInAllowedRegionTimeNanos =
+ 0;
assertTrue(mSatelliteAccessControllerUT.allowLocationQueryForSatelliteAllowedCheck());
// cash is valid and throttled
mSatelliteAccessControllerUT.mLastLocationQueryForPossibleChangeInAllowedRegionTimeNanos =
mSatelliteAccessControllerUT.elapsedRealtimeNanos
- - TEST_LOCATION_QUERY_THROTTLE_INTERVAL_NANOS + 100;
+ - TEST_LOCATION_QUERY_THROTTLE_INTERVAL_NANOS + 100;
assertFalse(mSatelliteAccessControllerUT.allowLocationQueryForSatelliteAllowedCheck());
// cash is valid and not throttled
mSatelliteAccessControllerUT.mLastLocationQueryForPossibleChangeInAllowedRegionTimeNanos =
mSatelliteAccessControllerUT.elapsedRealtimeNanos
- - TEST_LOCATION_QUERY_THROTTLE_INTERVAL_NANOS - 100;
+ - TEST_LOCATION_QUERY_THROTTLE_INTERVAL_NANOS - 100;
assertTrue(mSatelliteAccessControllerUT.allowLocationQueryForSatelliteAllowedCheck());
}
@@ -994,7 +999,7 @@
// Captor and Verify if the mockReceiver and mocContext is registered well
verify(mMockContext).registerReceiver(mLocationBroadcastReceiverCaptor.capture(),
- mIntentFilterCaptor.capture());
+ mIntentFilterCaptor.capture());
assertSame(mSatelliteAccessControllerUT.getLocationBroadcastReceiver(),
mLocationBroadcastReceiverCaptor.getValue());
assertSame(MODE_CHANGED_ACTION, mIntentFilterCaptor.getValue().getAction(0));
@@ -1031,6 +1036,37 @@
assertEquals(false, mSatelliteAccessControllerUT.isSatelliteAllowedRegionPossiblyChanged());
}
+ @Test
+ public void testCheckSatelliteAccessRestrictionUsingGPS() {
+ // In emergency case,
+ // verify if the location manager get FUSED provider and ignore location settings
+ doReturn(true).when(mMockTelecomManager).isInEmergencyCall();
+ mSatelliteAccessControllerUT.setLocationRequestCancellationSignalAsNull();
+ mSatelliteAccessControllerUT.queryCurrentLocation();
+
+ verify(mMockLocationManager, times(1))
+ .getCurrentLocation(mLocationProviderStringCaptor.capture(),
+ mLocationRequestCaptor.capture(), any(), any(), any());
+ assertEquals(LocationManager.FUSED_PROVIDER, mLocationProviderStringCaptor.getValue());
+ assertTrue(mLocationRequestCaptor.getValue().isLocationSettingsIgnored());
+
+ // In non-emergency case,
+ // verify if the location manager get FUSED provider and not ignore location settings
+ clearInvocations(mMockLocationManager);
+ doReturn(false).when(mMockTelecomManager).isInEmergencyCall();
+ doReturn(false).when(mMockPhone).isInEcm();
+ doReturn(false).when(mMockPhone2).isInEcm();
+ doReturn(false).when(mMockSatelliteController).isInEmergencyMode();
+ mSatelliteAccessControllerUT.setLocationRequestCancellationSignalAsNull();
+ mSatelliteAccessControllerUT.queryCurrentLocation();
+
+ verify(mMockLocationManager, times(1))
+ .getCurrentLocation(mLocationProviderStringCaptor.capture(),
+ mLocationRequestCaptor.capture(), any(), any(), any());
+ assertEquals(LocationManager.FUSED_PROVIDER, mLocationProviderStringCaptor.getValue());
+ assertFalse(mLocationRequestCaptor.getValue().isLocationSettingsIgnored());
+ }
+
private void sendSatelliteCommunicationAllowedEvent() {
Pair<Integer, ResultReceiver> requestPair =
new Pair<>(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
@@ -1214,5 +1250,11 @@
public BroadcastReceiver getLocationBroadcastReceiver() {
return mLocationModeChangedBroadcastReceiver;
}
+
+ public void setLocationRequestCancellationSignalAsNull() {
+ synchronized (mLock) {
+ mLocationRequestCancellationSignal = null;
+ }
+ }
}
}