Merge "Fixed that RadioInfo does not work in HSUM mode" into main
diff --git a/Android.bp b/Android.bp
index 78e6afb..2c41fb9 100644
--- a/Android.bp
+++ b/Android.bp
@@ -29,7 +29,7 @@
"libprotobuf-java-lite",
"app-compat-annotations",
"unsupportedappusage",
- "org.apache.http.legacy",
+ "org.apache.http.legacy.stubs.system",
],
static_libs: [
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index f337704..5ac898f 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -8159,31 +8159,15 @@
@Override
public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
- if (com.android.internal.telephony.flags.Flags.supportPhoneUidCheckForMultiuser()) {
- enforceCallingPackage(callingPackage, Binder.getCallingUid(),
- "Invalid package:" + callingPackage);
- } else {
- try {
- if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
- Binder.getCallingUid())) {
- throw new SecurityException("Invalid package:" + callingPackage);
- }
- } catch (PackageManager.NameNotFoundException e) {
- throw new SecurityException("Invalid package:" + callingPackage);
- }
- }
-
+ enforceCallingPackage(callingPackage, Binder.getCallingUid(),
+ "Invalid package:" + callingPackage);
enforceTelephonyFeatureWithException(callingPackage,
PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
RoleManager rm = mApp.getSystemService(RoleManager.class);
List<String> dialerRoleHolders;
- if (com.android.internal.telephony.flags.Flags.supportPhoneUidCheckForMultiuser()) {
- dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER,
- UserHandle.of(ActivityManager.getCurrentUser()));
- } else {
- dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
- }
+ dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER,
+ UserHandle.of(ActivityManager.getCurrentUser()));
if (!dialerRoleHolders.contains(callingPackage)) {
throw new SecurityException("App must be the dialer role holder to"
+ " upload a call composer pic");
diff --git a/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java b/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java
index 331bf29..2a64caa 100644
--- a/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java
+++ b/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java
@@ -28,7 +28,10 @@
import android.annotation.ArrayRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.location.Location;
@@ -133,7 +136,8 @@
protected static final int EVENT_WAIT_FOR_CURRENT_LOCATION_TIMEOUT = 2;
protected static final int EVENT_KEEP_ON_DEVICE_ACCESS_CONTROLLER_RESOURCES_TIMEOUT = 3;
protected static final int EVENT_CONFIG_DATA_UPDATED = 4;
- protected static final int CMD_HANDLE_COUNTRY_CODE_CHANGED = 5;
+ protected static final int EVENT_COUNTRY_CODE_CHANGED = 5;
+ protected static final int EVENT_LOCATION_SETTINGS_ENABLED = 6;
private static SatelliteAccessController sInstance;
@@ -194,7 +198,7 @@
};
@GuardedBy("mLock")
@Nullable
- CancellationSignal mLocationRequestCancellationSignal = null;
+ protected CancellationSignal mLocationRequestCancellationSignal = null;
private int mS2Level = DEFAULT_S2_LEVEL;
@GuardedBy("mLock")
@Nullable
@@ -263,6 +267,19 @@
private long mOnDeviceLookupStartTimeMillis;
private long mTotalCheckingStartTimeMillis;
+ protected BroadcastReceiver mLocationModeChangedBroadcastReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().equals(LocationManager.MODE_CHANGED_ACTION)) {
+ plogd("LocationManager mode is changed");
+ if (mLocationManager.isLocationEnabled()) {
+ plogd("Location settings is just enabled");
+ sendRequestAsync(EVENT_LOCATION_SETTINGS_ENABLED, null);
+ }
+ }
+ }
+ };
+
/**
* Create a SatelliteAccessController instance.
*
@@ -295,7 +312,7 @@
mCountryDetector = TelephonyCountryDetector.getInstance(context, mFeatureFlags);
mCountryDetector.registerForCountryCodeChanged(this,
- CMD_HANDLE_COUNTRY_CODE_CHANGED, null);
+ EVENT_COUNTRY_CODE_CHANGED, null);
initializeHandlerForSatelliteAllowedResult();
setIsSatelliteAllowedRegionPossiblyChanged(false);
@@ -372,6 +389,7 @@
// Init the SatelliteOnDeviceAccessController so that the S2 level can be cached
initSatelliteOnDeviceAccessController();
+ registerLocationModeChangedBroadcastReceiver(context);
}
private void updateCurrentSatelliteAllowedState(boolean isAllowed) {
@@ -418,7 +436,9 @@
AsyncResult ar = (AsyncResult) msg.obj;
updateSatelliteConfigData((Context) ar.userObj);
break;
- case CMD_HANDLE_COUNTRY_CODE_CHANGED:
+ case EVENT_LOCATION_SETTINGS_ENABLED:
+ // Fall through
+ case EVENT_COUNTRY_CODE_CHANGED:
handleSatelliteAllowedRegionPossiblyChanged();
break;
default:
@@ -909,6 +929,17 @@
}
}
+ private void registerLocationModeChangedBroadcastReceiver(Context context) {
+ if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
+ plogd("registerLocationModeChangedBroadcastReceiver: Flag "
+ + "oemEnabledSatellite is disabled");
+ return;
+ }
+ IntentFilter intentFilter = new IntentFilter();
+ intentFilter.addAction(LocationManager.MODE_CHANGED_ACTION);
+ context.registerReceiver(mLocationModeChangedBroadcastReceiver, intentFilter);
+ }
+
/**
* At country borders, a multi-SIM device might connect to multiple cellular base
* stations and thus might have multiple different MCCs.
@@ -917,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;
}
}
@@ -1248,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/testapps/TestRcsApp/TestApp/Android.bp b/testapps/TestRcsApp/TestApp/Android.bp
index 7654973..3bc31b1 100644
--- a/testapps/TestRcsApp/TestApp/Android.bp
+++ b/testapps/TestRcsApp/TestApp/Android.bp
@@ -17,7 +17,7 @@
"libphonenumber-platform",
],
- libs: ["org.apache.http.legacy"],
+ libs: ["org.apache.http.legacy.stubs.system"],
certificate: "platform",
privileged: true,
diff --git a/testapps/TestRcsApp/aosp_test_rcsclient/Android.bp b/testapps/TestRcsApp/aosp_test_rcsclient/Android.bp
index fc4dc8b..f6ed10f 100644
--- a/testapps/TestRcsApp/aosp_test_rcsclient/Android.bp
+++ b/testapps/TestRcsApp/aosp_test_rcsclient/Android.bp
@@ -17,7 +17,7 @@
libs: [
"auto_value_annotations",
- "org.apache.http.legacy",
+ "org.apache.http.legacy.stubs.system",
],
plugins: [
diff --git a/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/TestSatelliteWrapper.java b/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/TestSatelliteWrapper.java
index 109ebbf..d8e6e7c 100644
--- a/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/TestSatelliteWrapper.java
+++ b/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/TestSatelliteWrapper.java
@@ -23,13 +23,13 @@
import android.os.OutcomeReceiver;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
-import android.telephony.satellite.wrapper.CarrierRoamingNtnModeListenerWrapper;
+import android.telephony.satellite.wrapper.CarrierRoamingNtnModeListenerWrapper2;
import android.telephony.satellite.wrapper.NtnSignalStrengthCallbackWrapper;
import android.telephony.satellite.wrapper.NtnSignalStrengthWrapper;
import android.telephony.satellite.wrapper.SatelliteCapabilitiesCallbackWrapper;
import android.telephony.satellite.wrapper.SatelliteCommunicationAllowedStateCallbackWrapper;
import android.telephony.satellite.wrapper.SatelliteManagerWrapper;
-import android.telephony.satellite.wrapper.SatelliteModemStateCallbackWrapper;
+import android.telephony.satellite.wrapper.SatelliteModemStateCallbackWrapper2;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
@@ -401,7 +401,7 @@
}
}
- private class CarrierRoamingNtnModeListener implements CarrierRoamingNtnModeListenerWrapper {
+ private class CarrierRoamingNtnModeListener implements CarrierRoamingNtnModeListenerWrapper2 {
@Override
public void onCarrierRoamingNtnModeChanged(boolean active) {
@@ -431,7 +431,7 @@
}
}
- private class SatelliteModemStateCallback implements SatelliteModemStateCallbackWrapper {
+ private class SatelliteModemStateCallback implements SatelliteModemStateCallbackWrapper2 {
@Override
public void onSatelliteModemStateChanged(int state) {
String message = "Received onSatelliteModemStateChanged state: " + state;
diff --git a/testapps/TestSliceApp/app/src/main/Android.bp b/testapps/TestSliceApp/app/src/main/Android.bp
index b02d5ff..fa22c2b 100644
--- a/testapps/TestSliceApp/app/src/main/Android.bp
+++ b/testapps/TestSliceApp/app/src/main/Android.bp
@@ -12,7 +12,7 @@
"androidx-constraintlayout_constraintlayout",
"androidx.appcompat_appcompat",
],
- libs: ["org.apache.http.legacy"],
+ libs: ["org.apache.http.legacy.stubs.system"],
certificate: "platform",
privileged: true,
product_specific: true,
diff --git a/tests/Android.bp b/tests/Android.bp
index 0fcd60e..22b2f46 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -25,12 +25,12 @@
srcs: ["src/**/*.java"],
libs: [
- "android.test.mock",
- "android.test.runner",
+ "android.test.mock.stubs.system",
+ "android.test.runner.stubs.system",
"telephony-common",
- "android.test.base",
+ "android.test.base.stubs.system",
"ims-common",
- "android.test.mock",
+ "android.test.mock.stubs.system",
],
platform_apis: true,
certificate: "platform",
diff --git a/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessControllerTest.java b/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessControllerTest.java
index 83dc290..8a2b4d6 100644
--- a/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessControllerTest.java
+++ b/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessControllerTest.java
@@ -16,6 +16,7 @@
package com.android.phone.satellite.accesscontrol;
+import static android.location.LocationManager.MODE_CHANGED_ACTION;
import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED;
import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_LOCATION_NOT_AVAILABLE;
import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_MODEM_ERROR;
@@ -23,7 +24,7 @@
import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS;
import static com.android.phone.satellite.accesscontrol.SatelliteAccessController.ALLOWED_STATE_CACHE_VALID_DURATION_NANOS;
-import static com.android.phone.satellite.accesscontrol.SatelliteAccessController.CMD_HANDLE_COUNTRY_CODE_CHANGED;
+import static com.android.phone.satellite.accesscontrol.SatelliteAccessController.EVENT_COUNTRY_CODE_CHANGED;
import static com.android.phone.satellite.accesscontrol.SatelliteAccessController.CMD_IS_SATELLITE_COMMUNICATION_ALLOWED;
import static com.android.phone.satellite.accesscontrol.SatelliteAccessController.DEFAULT_DELAY_MINUTES_BEFORE_VALIDATING_POSSIBLE_CHANGE_IN_ALLOWED_REGION;
import static com.android.phone.satellite.accesscontrol.SatelliteAccessController.DEFAULT_THROTTLE_INTERVAL_FOR_LOCATION_QUERY_MINUTES;
@@ -55,7 +56,10 @@
import static org.mockito.Mockito.when;
import android.annotation.Nullable;
+import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.location.Location;
@@ -131,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
@@ -171,6 +175,8 @@
@Mock
private Map<SatelliteOnDeviceAccessController.LocationToken, Boolean>
mMockCachedAccessRestrictionMap;
+ @Mock
+ private Intent mMockLocationIntent;
private Looper mLooper;
private TestableLooper mTestableLooper;
@@ -193,6 +199,14 @@
private ArgumentCaptor<Integer> mCountryDetectorIntCaptor;
@Captor
private ArgumentCaptor<Object> mCountryDetectorObjCaptor;
+ @Captor
+ 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;
@@ -284,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);
@@ -309,6 +323,7 @@
when(mMockFeatureFlags.satellitePersistentLogging()).thenReturn(true);
when(mMockFeatureFlags.geofenceEnhancementForBetterUx()).thenReturn(true);
+ when(mMockFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true);
mSatelliteAccessControllerUT = new TestSatelliteAccessController(mMockContext,
mMockFeatureFlags, mLooper, mMockLocationManager, mMockTelecomManager,
@@ -690,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());
@@ -788,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());
}
@@ -814,7 +830,7 @@
mCountryDetectorObjCaptor.capture());
assertSame(mCountryDetectorHandlerCaptor.getValue(), mSatelliteAccessControllerUT);
- assertSame(mCountryDetectorIntCaptor.getValue(), CMD_HANDLE_COUNTRY_CODE_CHANGED);
+ assertSame(mCountryDetectorIntCaptor.getValue(), EVENT_COUNTRY_CODE_CHANGED);
assertNull(mCountryDetectorObjCaptor.getValue());
// Normal case that invokes
@@ -867,7 +883,7 @@
mCountryDetectorObjCaptor.capture());
assertSame(mCountryDetectorHandlerCaptor.getValue(), mSatelliteAccessControllerUT);
- assertSame(mCountryDetectorIntCaptor.getValue(), CMD_HANDLE_COUNTRY_CODE_CHANGED);
+ assertSame(mCountryDetectorIntCaptor.getValue(), EVENT_COUNTRY_CODE_CHANGED);
assertNull(mCountryDetectorObjCaptor.getValue());
assertTrue(mSatelliteAccessControllerUT
@@ -964,6 +980,93 @@
verify(mMockCachedAccessRestrictionMap, times(1)).clear();
}
+ @Test
+ public void testLocationModeChanged() throws Exception {
+ // setup for querying GPS not to reset mIsSatelliteAllowedRegionPossiblyChanged false.
+ when(mMockFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true);
+ when(mMockContext.getResources()).thenReturn(mMockResources);
+ when(mMockResources.getBoolean(
+ com.android.internal.R.bool.config_oem_enabled_satellite_access_allow))
+ .thenReturn(TEST_SATELLITE_ALLOW);
+ setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS);
+ setUpResponseForRequestIsSatelliteProvisioned(true, SATELLITE_RESULT_SUCCESS);
+ when(mMockSatelliteOnDeviceAccessController.isSatCommunicationAllowedAtLocation(
+ any(SatelliteOnDeviceAccessController.LocationToken.class))).thenReturn(true);
+ replaceInstance(SatelliteAccessController.class, "mCachedAccessRestrictionMap",
+ mSatelliteAccessControllerUT, mMockCachedAccessRestrictionMap);
+ doReturn(false).when(mMockCachedAccessRestrictionMap).containsKey(any());
+ mSatelliteAccessControllerUT.elapsedRealtimeNanos = TEST_LOCATION_FRESH_DURATION_NANOS + 1;
+
+ // Captor and Verify if the mockReceiver and mocContext is registered well
+ verify(mMockContext).registerReceiver(mLocationBroadcastReceiverCaptor.capture(),
+ mIntentFilterCaptor.capture());
+ assertSame(mSatelliteAccessControllerUT.getLocationBroadcastReceiver(),
+ mLocationBroadcastReceiverCaptor.getValue());
+ assertSame(MODE_CHANGED_ACTION, mIntentFilterCaptor.getValue().getAction(0));
+
+ // When the intent action is not MODE_CHANGED_ACTION,
+ // verify if the location manager never invoke isLocationEnabled()
+ doReturn("").when(mMockLocationIntent).getAction();
+ mSatelliteAccessControllerUT.setIsSatelliteAllowedRegionPossiblyChanged(false);
+ mSatelliteAccessControllerUT.getLocationBroadcastReceiver()
+ .onReceive(mMockContext, mMockLocationIntent);
+ verify(mMockLocationManager, never()).isLocationEnabled();
+
+ // When the intent action is MODE_CHANGED_ACTION and isLocationEnabled() is true,
+ // verify if mIsSatelliteAllowedRegionPossiblyChanged is true
+ doReturn(MODE_CHANGED_ACTION).when(mMockLocationIntent).getAction();
+ doReturn(true).when(mMockLocationManager).isLocationEnabled();
+ clearInvocations(mMockLocationManager);
+ mSatelliteAccessControllerUT.setIsSatelliteAllowedRegionPossiblyChanged(false);
+ mSatelliteAccessControllerUT.getLocationBroadcastReceiver()
+ .onReceive(mMockContext, mMockLocationIntent);
+ verify(mMockLocationManager, times(1)).isLocationEnabled();
+ mTestableLooper.processAllMessages();
+ assertEquals(true, mSatelliteAccessControllerUT.isSatelliteAllowedRegionPossiblyChanged());
+
+ // When the intent action is MODE_CHANGED_ACTION and isLocationEnabled() is false,
+ // verify if mIsSatelliteAllowedRegionPossiblyChanged is false
+ doReturn(false).when(mMockLocationManager).isLocationEnabled();
+ clearInvocations(mMockLocationManager);
+ mSatelliteAccessControllerUT.setIsSatelliteAllowedRegionPossiblyChanged(false);
+ mSatelliteAccessControllerUT.getLocationBroadcastReceiver()
+ .onReceive(mMockContext, mMockLocationIntent);
+ verify(mMockLocationManager, times(1)).isLocationEnabled();
+ mTestableLooper.processAllMessages();
+ 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,
@@ -984,7 +1087,7 @@
}
private void sendCommandValidateCountryCodeChangeEvent(Context context) {
- Message msg = mSatelliteAccessControllerUT.obtainMessage(CMD_HANDLE_COUNTRY_CODE_CHANGED);
+ Message msg = mSatelliteAccessControllerUT.obtainMessage(EVENT_COUNTRY_CODE_CHANGED);
msg.obj = new AsyncResult(context, SATELLITE_RESULT_SUCCESS, null);
msg.sendToTarget();
mTestableLooper.processAllMessages();
@@ -1143,5 +1246,15 @@
public ResultReceiver getResultReceiverCurrentLocation() {
return mHandlerForSatelliteAllowedResult;
}
+
+ public BroadcastReceiver getLocationBroadcastReceiver() {
+ return mLocationModeChangedBroadcastReceiver;
+ }
+
+ public void setLocationRequestCancellationSignalAsNull() {
+ synchronized (mLock) {
+ mLocationRequestCancellationSignal = null;
+ }
+ }
}
}