diff options
-rw-r--r-- | src/com/android/ons/ONSProfileSelector.java | 22 | ||||
-rw-r--r-- | src/com/android/ons/OpportunisticNetworkService.java | 24 |
2 files changed, 29 insertions, 17 deletions
diff --git a/src/com/android/ons/ONSProfileSelector.java b/src/com/android/ons/ONSProfileSelector.java index 0d600a7..04fd3dd 100644 --- a/src/com/android/ons/ONSProfileSelector.java +++ b/src/com/android/ons/ONSProfileSelector.java @@ -92,6 +92,7 @@ public class ONSProfileSelector { protected List<SubscriptionInfo> mOppSubscriptionInfos; private ONSProfileSelectionCallback mProfileSelectionCallback; private int mSequenceId; + private int mSubId; private int mCurrentDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; private ArrayList<AvailableNetworkInfo> mAvailableNetworkInfos; private IUpdateAvailableNetworksCallback mNetworkScanCallback; @@ -310,7 +311,7 @@ public class ONSProfileSelector { updateToken(); callbackIntent.putExtra("sequenceId", mSequenceId); callbackIntent.putExtra("subId", subId); - + mSubId = subId; PendingIntent replyIntent = PendingIntent.getService(mContext, 1, callbackIntent, Intent.FILL_IN_ACTION); @@ -322,16 +323,19 @@ public class ONSProfileSelector { int subId = intent.getIntExtra("subId", SubscriptionManager.INVALID_SUBSCRIPTION_ID); logDebug("ACTION_SUB_SWITCH sequenceId: " + sequenceId - + " mSequenceId: " + mSequenceId); - if (sequenceId != mSequenceId) { - return; - } - + + " mSequenceId: " + mSequenceId + + " mSubId: " + mSubId + + " subId: " + subId); Message message = Message.obtain(mHandler, MSG_SUB_SWITCH_COMPLETE, subId); message.sendToTarget(); } private void onSubSwitchComplete(int subId) { + /* Ignore if this is callback for an older request */ + if (mSubId != subId) { + return; + } + if (enableModem(subId, true)) { sendUpdateNetworksCallbackHelper(mNetworkScanCallback, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SUCCESS); @@ -471,10 +475,10 @@ public class ONSProfileSelector { switchToSubscription(filteredAvailableNetworks.get(0).getSubId()); } else { if (enableModem(filteredAvailableNetworks.get(0).getSubId(), true)) { - sendUpdateNetworksCallbackHelper(mNetworkScanCallback, + sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SUCCESS); } else { - sendUpdateNetworksCallbackHelper(mNetworkScanCallback, + sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_ABORTED); } mProfileSelectionCallback.onProfileSelectionDone(); @@ -588,6 +592,7 @@ public class ONSProfileSelector { int phoneId = SubscriptionManager.getPhoneId(subId); if (mSubscriptionBoundTelephonyManager.isModemEnabledForSlot(phoneId) == enable) { + logDebug("modem is already enabled "); return true; } @@ -723,6 +728,7 @@ public class ONSProfileSelector { protected void init(Context c, ONSProfileSelectionCallback profileSelectionCallback) { mContext = c; mSequenceId = START_SEQUENCE_ID; + mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; mProfileSelectionCallback = profileSelectionCallback; mTelephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); diff --git a/src/com/android/ons/OpportunisticNetworkService.java b/src/com/android/ons/OpportunisticNetworkService.java index f23b488..91a17b2 100644 --- a/src/com/android/ons/OpportunisticNetworkService.java +++ b/src/com/android/ons/OpportunisticNetworkService.java @@ -383,17 +383,23 @@ public class OpportunisticNetworkService extends Service { TelephonyManager.UPDATE_AVAILABLE_NETWORKS_INVALID_ARGUMENTS); return; } - TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( - availableNetworks.get(0).getSubId(), "updateAvailableNetworks"); - /* check if the app has opportunistic carrier permission */ - if (!hasOpportunisticSubPrivilege(callingPackage, - availableNetworks.get(0).getSubId())) { - log("No carrier privelege for opportunistic subscription"); - sendUpdateNetworksCallbackHelper(callbackStub, - TelephonyManager.UPDATE_AVAILABLE_NETWORKS_NO_CARRIER_PRIVILEGE); - return; + for (AvailableNetworkInfo availableNetworkInfo : availableNetworks) { + if (mSubscriptionManager.isActiveSubId(availableNetworkInfo.getSubId())) { + TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( + availableNetworkInfo.getSubId(), "updateAvailableNetworks"); + } else { + /* check if the app has opportunistic carrier permission */ + if (!hasOpportunisticSubPrivilege(callingPackage, + availableNetworkInfo.getSubId())) { + log("No carrier privilege for opportunistic subscription"); + sendUpdateNetworksCallbackHelper(callbackStub, + TelephonyManager.UPDATE_AVAILABLE_NETWORKS_NO_CARRIER_PRIVILEGE); + return; + } + } } + final long identity = Binder.clearCallingIdentity(); try { ONSConfigInput onsConfigInput = new ONSConfigInput(availableNetworks, callbackStub); |