summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXin Li <delphij@google.com>2023-08-14 15:43:23 -0700
committerXin Li <delphij@google.com>2023-08-14 15:43:23 -0700
commit35c9ec7234001fad142e81414fb80947c89d9488 (patch)
tree6ab377c21a9227c077fe7707c570cc95a6f93968
parent47576bd165d192a11eabe18ff589d507402909fe (diff)
parentcdbd29aa0b32c5d79eb342b2f46d2fe47cc2a965 (diff)
downloadAlternativeNetworkAccess-tmp_amf_298295554.tar.gz
Merge Android U (ab/10368041)tmp_amf_298295554
Bug: 291102124 Merged-In: I4829d4a25fc43857d134447e9e1f43bb9c84729e Change-Id: I6dd4f600113472084343cd13f7c6b00bdd01b473
-rw-r--r--src/com/android/ons/ONSProfileActivator.java7
-rw-r--r--src/com/android/ons/ONSProfileConfigurator.java14
-rw-r--r--src/com/android/ons/ONSStats.java2
-rw-r--r--src/com/android/ons/OpportunisticNetworkService.java17
-rw-r--r--tests/src/com/android/ons/ONSProfileActivatorTest.java17
-rw-r--r--tests/src/com/android/ons/ONSProfileConfiguratorTest.java2
6 files changed, 47 insertions, 12 deletions
diff --git a/src/com/android/ons/ONSProfileActivator.java b/src/com/android/ons/ONSProfileActivator.java
index 1c16c53..05228b8 100644
--- a/src/com/android/ons/ONSProfileActivator.java
+++ b/src/com/android/ons/ONSProfileActivator.java
@@ -173,12 +173,13 @@ public class ONSProfileActivator implements ONSProfileConfigurator.ONSProfConfig
//Check the number of active subscriptions.
List<SubscriptionInfo> activeSubInfos = mSubManager.getActiveSubscriptionInfoList();
+ if (activeSubInfos == null || activeSubInfos.size() <= 0) {
+ return Result.ERR_NO_SIM_INSERTED;
+ }
int activeSubCount = activeSubInfos.size();
Log.d(TAG, "Active subscription count:" + activeSubCount);
- if (activeSubCount <= 0) {
- return Result.ERR_NO_SIM_INSERTED;
- } else if (activeSubCount == 1) {
+ if (activeSubCount == 1) {
SubscriptionInfo pSubInfo = activeSubInfos.get(0);
if (pSubInfo.isOpportunistic()) {
//Only one SIM is active and its opportunistic SIM.
diff --git a/src/com/android/ons/ONSProfileConfigurator.java b/src/com/android/ons/ONSProfileConfigurator.java
index 09e31f9..84bcdad 100644
--- a/src/com/android/ons/ONSProfileConfigurator.java
+++ b/src/com/android/ons/ONSProfileConfigurator.java
@@ -156,7 +156,7 @@ public class ONSProfileConfigurator {
PendingIntent callbackIntent = PendingIntent.getBroadcast(mContext,
REQUEST_CODE_ACTIVATE_SUB, intent, PendingIntent.FLAG_IMMUTABLE);
Log.d(TAG, "Activate oppSub request sent to SubManager");
- mSubscriptionManager.switchToSubscription(subId, callbackIntent);
+ mEuiccManager.switchToSubscription(subId, callbackIntent);
}
/**
@@ -258,6 +258,10 @@ public class ONSProfileConfigurator {
//Get the list of active subscriptions
List<SubscriptionInfo> availSubInfoList = mSubscriptionManager
.getAvailableSubscriptionInfoList();
+ if (availSubInfoList == null) {
+ Log.e(TAG, "getAvailableSubscriptionInfoList returned null");
+ return null;
+ }
Log.d(TAG, "Available subscriptions: " + availSubInfoList.size());
//Get the list of opportunistic carrier-ids list from carrier config.
@@ -269,8 +273,12 @@ public class ONSProfileConfigurator {
return null;
}
- ParcelUuid pSIMSubGroupId = mSubscriptionManager.getActiveSubscriptionInfo(pSIMId)
- .getGroupUuid();
+ SubscriptionInfo subscriptionInfo = mSubscriptionManager.getActiveSubscriptionInfo(pSIMId);
+ if (subscriptionInfo == null) {
+ Log.e(TAG, "getActiveSubscriptionInfo returned null for: " + pSIMId);
+ return null;
+ }
+ ParcelUuid pSIMSubGroupId = subscriptionInfo.getGroupUuid();
for (SubscriptionInfo subInfo : availSubInfoList) {
if (subInfo.getSubscriptionId() != pSIMId) {
for (int carrId : oppCarrierIdArr) {
diff --git a/src/com/android/ons/ONSStats.java b/src/com/android/ons/ONSStats.java
index 21ce607..d961344 100644
--- a/src/com/android/ons/ONSStats.java
+++ b/src/com/android/ons/ONSStats.java
@@ -151,7 +151,7 @@ public class ONSStats {
// add subscription id for carrier if it doesn't support CBRS.
if (result == Result.ERR_CARRIER_DOESNT_SUPPORT_CBRS) {
List<SubscriptionInfo> subInfos =
- mSubscriptionManager.getAvailableSubscriptionInfoList();
+ mSubscriptionManager.getActiveSubscriptionInfoList();
info.setPrimarySimSubId(
(subInfos != null && !subInfos.isEmpty())
? subInfos.get(0).getSubscriptionId()
diff --git a/src/com/android/ons/OpportunisticNetworkService.java b/src/com/android/ons/OpportunisticNetworkService.java
index 485722f..d41051c 100644
--- a/src/com/android/ons/OpportunisticNetworkService.java
+++ b/src/com/android/ons/OpportunisticNetworkService.java
@@ -313,10 +313,19 @@ public class OpportunisticNetworkService extends Service {
@Override
public int getPreferredDataSubscriptionId(String callingPackage,
String callingFeatureId) {
- TelephonyPermissions
- .checkCallingOrSelfReadPhoneState(mContext,
- mSubscriptionManager.getDefaultSubscriptionId(),
- callingPackage, callingFeatureId, "getPreferredDataSubscriptionId");
+ if (!TelephonyPermissions.checkReadPhoneStateOnAnyActiveSub(
+ mContext,
+ Binder.getCallingPid(),
+ Binder.getCallingUid(),
+ callingPackage,
+ callingFeatureId,
+ "getPreferredDataSubscriptionId")) {
+ throw new SecurityException(
+ "getPreferredDataSubscriptionId requires READ_PHONE_STATE,"
+ + " READ_PRIVILEGED_PHONE_STATE, or carrier privileges on"
+ + " any active subscription.");
+ }
+
final long identity = Binder.clearCallingIdentity();
try {
return mProfileSelector.getPreferredDataSubscriptionId();
diff --git a/tests/src/com/android/ons/ONSProfileActivatorTest.java b/tests/src/com/android/ons/ONSProfileActivatorTest.java
index 3e94bd5..478f23a 100644
--- a/tests/src/com/android/ons/ONSProfileActivatorTest.java
+++ b/tests/src/com/android/ons/ONSProfileActivatorTest.java
@@ -251,6 +251,23 @@ public class ONSProfileActivatorTest extends ONSBaseTest {
onsProfileActivator.handleCarrierConfigChange());
}
+ public void testNullActiveSubscriptionList() {
+
+ doReturn(true).when(mMockResources).getBoolean(R.bool.enable_ons_auto_provisioning);
+ doReturn(true).when(mMockEuiccManager).isEnabled();
+ doReturn(2).when(mMockTeleManager).getSupportedModemCount();
+ doReturn(2).when(mMockTeleManager).getActiveModemCount();
+ doReturn(null).when(mMockSubManager).getActiveSubscriptionInfoList();
+
+ ONSProfileActivator onsProfileActivator = new ONSProfileActivator(mMockContext,
+ mMockSubManager, mMockTeleManager, mMockCarrierConfigManager, mMockEuiccManager,
+ mMockConnectivityManager, mMockONSProfileConfigurator, mMockONSProfileDownloader,
+ mMockONSStats);
+
+ assertEquals(ONSProfileActivator.Result.ERR_NO_SIM_INSERTED,
+ onsProfileActivator.handleCarrierConfigChange());
+ }
+
@Test
//@DisplayName("Dual SIM device and non CBRS carrier pSIM inserted")
public void testNonCBRSCarrierPSIMInserted() {
diff --git a/tests/src/com/android/ons/ONSProfileConfiguratorTest.java b/tests/src/com/android/ons/ONSProfileConfiguratorTest.java
index b583f73..7c88658 100644
--- a/tests/src/com/android/ons/ONSProfileConfiguratorTest.java
+++ b/tests/src/com/android/ons/ONSProfileConfiguratorTest.java
@@ -131,7 +131,7 @@ public class ONSProfileConfiguratorTest extends ONSBaseTest {
PendingIntent.FLAG_IMMUTABLE);
mOnsProfileConfigurator.activateSubscription(TEST_SUB_ID);
- verify(mMockSubManager).switchToSubscription(TEST_SUB_ID, callbackIntent);
+ verify(mMockEuiccMngr).switchToSubscription(TEST_SUB_ID, callbackIntent);
}
@Test