From 390b5c4601d435abcda2437259570639e5b67234 Mon Sep 17 00:00:00 2001 From: Sooraj Sasindran Date: Mon, 20 May 2019 17:56:05 -0700 Subject: Do not depend upon sequenceId Do not depend upon sequenceId to determine the callback from eSIM as eSIM may not send callback if the subscription is already active Bug: 132731516 Test: verified that no regression Change-Id: I3485050e367a02755a832411ebb03a4bcd12a92e --- src/com/android/ons/ONSProfileSelector.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/com/android/ons/ONSProfileSelector.java b/src/com/android/ons/ONSProfileSelector.java index 0d600a7..127c8cb 100644 --- a/src/com/android/ons/ONSProfileSelector.java +++ b/src/com/android/ons/ONSProfileSelector.java @@ -92,6 +92,7 @@ public class ONSProfileSelector { protected List mOppSubscriptionInfos; private ONSProfileSelectionCallback mProfileSelectionCallback; private int mSequenceId; + private int mSubId; private int mCurrentDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; private ArrayList 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); @@ -323,15 +324,16 @@ public class ONSProfileSelector { SubscriptionManager.INVALID_SUBSCRIPTION_ID); logDebug("ACTION_SUB_SWITCH sequenceId: " + sequenceId + " mSequenceId: " + mSequenceId); - if (sequenceId != mSequenceId) { - return; - } - 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 +473,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(); @@ -723,6 +725,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); -- cgit v1.2.3 From b1fd0964932ec9e0aeb0809d3777110371c3bf98 Mon Sep 17 00:00:00 2001 From: Sooraj Sasindran Date: Tue, 21 May 2019 14:51:55 -0700 Subject: Do not enforce carrier permission Do not enforce carrier permission if the profile is inactive Bug: 133176992 Test: Verified that Fi is not getting security exception Change-Id: Iac9289f1cad07bcd44a9b15beef926bbaf51be90 --- src/com/android/ons/ONSProfileSelector.java | 5 ++++- .../android/ons/OpportunisticNetworkService.java | 24 ++++++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/com/android/ons/ONSProfileSelector.java b/src/com/android/ons/ONSProfileSelector.java index 127c8cb..04fd3dd 100644 --- a/src/com/android/ons/ONSProfileSelector.java +++ b/src/com/android/ons/ONSProfileSelector.java @@ -323,7 +323,9 @@ public class ONSProfileSelector { int subId = intent.getIntExtra("subId", SubscriptionManager.INVALID_SUBSCRIPTION_ID); logDebug("ACTION_SUB_SWITCH sequenceId: " + sequenceId - + " mSequenceId: " + mSequenceId); + + " mSequenceId: " + mSequenceId + + " mSubId: " + mSubId + + " subId: " + subId); Message message = Message.obtain(mHandler, MSG_SUB_SWITCH_COMPLETE, subId); message.sendToTarget(); } @@ -590,6 +592,7 @@ public class ONSProfileSelector { int phoneId = SubscriptionManager.getPhoneId(subId); if (mSubscriptionBoundTelephonyManager.isModemEnabledForSlot(phoneId) == enable) { + logDebug("modem is already enabled "); return true; } 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); -- cgit v1.2.3