diff options
| author | Xin Li <delphij@google.com> | 2020-01-15 15:57:25 -0800 |
|---|---|---|
| committer | Xin Li <delphij@google.com> | 2020-01-15 15:57:25 -0800 |
| commit | ce193a92ee306e3e09af34056fe4ce1302128298 (patch) | |
| tree | 39c4db1069f6057714c2225f68449e7a5b488fb1 | |
| parent | 13bfd977669318842e0d8a93046253a40ecd41ca (diff) | |
| parent | 8e7ad14e76daab647092296095d6371e3ffceea9 (diff) | |
| download | platform_packages_services_AlternativeNetworkAccess-ce193a92ee306e3e09af34056fe4ce1302128298.tar.gz platform_packages_services_AlternativeNetworkAccess-ce193a92ee306e3e09af34056fe4ce1302128298.tar.bz2 platform_packages_services_AlternativeNetworkAccess-ce193a92ee306e3e09af34056fe4ce1302128298.zip | |
DO NOT MERGE - Merge qt-qpr1-dev-plus-aosp-without-vendor (6129114) into stage-aosp-master
Bug: 146167222
Change-Id: I0c142f0bd4c8c6ec4739533782bb7c012da7c52f
| -rw-r--r-- | Android.bp | 5 | ||||
| -rw-r--r-- | src/com/android/ons/ONSProfileSelector.java | 57 | ||||
| -rw-r--r-- | src/com/android/ons/OpportunisticNetworkService.java | 41 | ||||
| -rw-r--r-- | tests/src/com/android/ons/ONSProfileSelectorTest.java | 105 |
4 files changed, 168 insertions, 40 deletions
@@ -19,10 +19,7 @@ android_app { name: "ONS", platform_apis: true, privileged: true, - libs: [ - "telephony-common", - "app-compat-annotations", - ], + libs: ["telephony-common"], srcs: ["src/**/*.java"], aaptflags: ["--auto-add-overlay"], certificate: "platform", diff --git a/src/com/android/ons/ONSProfileSelector.java b/src/com/android/ons/ONSProfileSelector.java index 962d7de..82f5f86 100644 --- a/src/com/android/ons/ONSProfileSelector.java +++ b/src/com/android/ons/ONSProfileSelector.java @@ -75,6 +75,9 @@ public class ONSProfileSelector { /* message to indicate Subscription switch completion */ private static final int MSG_SUB_SWITCH_COMPLETE = 3; + /* message to stop profile selection process */ + private static final int MSG_STOP_PROFILE_SELECTION = 4; + private boolean mIsEnabled = false; @VisibleForTesting @@ -95,7 +98,8 @@ public class ONSProfileSelector { private ONSProfileSelectionCallback mProfileSelectionCallback; private int mSequenceId; private int mSubId; - private int mCurrentDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; + @VisibleForTesting + protected int mCurrentDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; private ArrayList<AvailableNetworkInfo> mAvailableNetworkInfos; private IUpdateAvailableNetworksCallback mNetworkScanCallback; @@ -144,8 +148,7 @@ public class ONSProfileSelector { .UPDATE_AVAILABLE_NETWORKS_INVALID_ARGUMENTS); } else { if (Compatibility.isChangeEnabled( - OpportunisticNetworkService - .CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(mNetworkScanCallback, TelephonyManager .UPDATE_AVAILABLE_NETWORKS_SERVICE_IS_DISABLED); @@ -169,8 +172,7 @@ public class ONSProfileSelector { TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SUCCESS); } else { if (Compatibility.isChangeEnabled( - OpportunisticNetworkService - .CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(mNetworkScanCallback, TelephonyManager .UPDATE_AVAILABLE_NETWORKS_ENABLE_MODEM_FAIL); @@ -377,7 +379,7 @@ public class ONSProfileSelector { TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SUCCESS); } else { if (Compatibility.isChangeEnabled( - OpportunisticNetworkService.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(mNetworkScanCallback, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_ENABLE_MODEM_FAIL); } else { @@ -482,7 +484,7 @@ public class ONSProfileSelector { if (mOppSubscriptionInfos == null) { logDebug("null subscription infos"); if (Compatibility.isChangeEnabled( - OpportunisticNetworkService.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_NO_OPPORTUNISTIC_SUB_AVAILABLE); } else { @@ -536,13 +538,14 @@ public class ONSProfileSelector { TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SUCCESS); } else { if (Compatibility.isChangeEnabled( - OpportunisticNetworkService.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_ENABLE_MODEM_FAIL); } else { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_ABORTED); } + } mProfileSelectionCallback.onProfileSelectionDone(); mAvailableNetworkInfos = null; @@ -554,7 +557,7 @@ public class ONSProfileSelector { } } else if (mOppSubscriptionInfos.size() == 0) { if (Compatibility.isChangeEnabled( - OpportunisticNetworkService.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_NO_OPPORTUNISTIC_SUB_AVAILABLE); } else { @@ -643,7 +646,7 @@ public class ONSProfileSelector { int subId = getActiveOpportunisticSubId(); if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { if (Compatibility.isChangeEnabled( - OpportunisticNetworkService.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_NO_OPPORTUNISTIC_SUB_AVAILABLE); } else { @@ -657,7 +660,7 @@ public class ONSProfileSelector { TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SUCCESS); } else { if (Compatibility.isChangeEnabled( - OpportunisticNetworkService.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_DISABLE_MODEM_FAIL); } else { @@ -672,6 +675,12 @@ public class ONSProfileSelector { return false; } + // If disabling modem for opportunistic sub, make sure to switch data back to default sub. + if (!enable) { + if (mSubscriptionManager.getPreferredDataSubscriptionId() == subId) { + selectProfileForData(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, false, null); + } + } int phoneId = SubscriptionManager.getPhoneId(subId); /* Todo: b/135067156 * Reenable this code once 135067156 is fixed @@ -683,6 +692,12 @@ public class ONSProfileSelector { return mSubscriptionBoundTelephonyManager.enableModemForSlot(phoneId, enable); } + private void stopProfileSelectionProcess(IUpdateAvailableNetworksCallback callbackStub) { + stopProfileScanningPrecedure(); + logDebug("stopProfileSelection"); + disableOpportunisticModem(callbackStub); + } + private void stopProfileScanningPrecedure() { synchronized (mLock) { if (mNetworkScanCallback != null) { @@ -737,6 +752,10 @@ public class ONSProfileSelector { IUpdateAvailableNetworksCallback callbackStub) { logDebug("startProfileSelection availableNetworks: " + availableNetworks); if (availableNetworks == null || availableNetworks.size() == 0) { + if (callbackStub != null) { + sendUpdateNetworksCallbackHelper(callbackStub, + TelephonyManager.UPDATE_AVAILABLE_NETWORKS_INVALID_ARGUMENTS); + } return; } Object[] objects = new Object[]{availableNetworks, callbackStub}; @@ -766,7 +785,7 @@ public class ONSProfileSelector { if (iSub == null) { log("Could not get Subscription Service handle"); if (Compatibility.isChangeEnabled( - OpportunisticNetworkService.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendSetOpptCallbackHelper(callbackStub, TelephonyManager.SET_OPPORTUNISTIC_SUB_REMOTE_SERVICE_EXCEPTION); } else { @@ -780,7 +799,7 @@ public class ONSProfileSelector { } catch (RemoteException ex) { log("Could not connect to Subscription Service"); if (Compatibility.isChangeEnabled( - OpportunisticNetworkService.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendSetOpptCallbackHelper(callbackStub, TelephonyManager.SET_OPPORTUNISTIC_SUB_REMOTE_SERVICE_EXCEPTION); } else { @@ -793,7 +812,7 @@ public class ONSProfileSelector { } else { log("Inactive sub passed for preferred data " + subId); if (Compatibility.isChangeEnabled( - OpportunisticNetworkService.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { if (isOpprotunisticSub(subId)) { sendSetOpptCallbackHelper(callbackStub, TelephonyManager.SET_OPPORTUNISTIC_SUB_INACTIVE_SUBSCRIPTION); @@ -816,9 +835,9 @@ public class ONSProfileSelector { * stop profile selection procedure */ public void stopProfileSelection(IUpdateAvailableNetworksCallback callbackStub) { - stopProfileScanningPrecedure(); logDebug("stopProfileSelection"); - disableOpportunisticModem(callbackStub); + Message message = Message.obtain(mHandler, MSG_STOP_PROFILE_SELECTION, callbackStub); + message.sendToTarget(); } @VisibleForTesting @@ -882,6 +901,12 @@ public class ONSProfileSelector { checkProfileUpdate((Object[]) msg.obj); } break; + case MSG_STOP_PROFILE_SELECTION: + logDebug("Msg received to stop profile selection"); + synchronized (mLock) { + stopProfileSelectionProcess((IUpdateAvailableNetworksCallback) msg.obj); + } + break; case MSG_SUB_SWITCH_COMPLETE: logDebug("Msg received for sub switch"); synchronized (mLock) { diff --git a/src/com/android/ons/OpportunisticNetworkService.java b/src/com/android/ons/OpportunisticNetworkService.java index ddd3e78..2ea684c 100644 --- a/src/com/android/ons/OpportunisticNetworkService.java +++ b/src/com/android/ons/OpportunisticNetworkService.java @@ -18,8 +18,6 @@ package com.android.ons; import android.app.Service; import android.compat.Compatibility; -import android.compat.annotation.ChangeId; -import android.compat.annotation.EnabledAfter; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -27,7 +25,6 @@ import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.os.Binder; -import android.os.Build; import android.os.Handler; import android.os.Message; import android.os.IBinder; @@ -77,14 +74,6 @@ public class OpportunisticNetworkService extends Service { private static final int MSG_SIM_STATE_CHANGE = 1; /** - * To expand the error codes for {@link TelephonyManager#updateAvailableNetworks} and - * {@link TelephonyManager#setPreferredOpportunisticDataSubscription}. - */ - @ChangeId - @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q) - static final long CALLBACK_ON_MORE_ERROR_CODE_CHANGE = 130595455L; - - /** * Profile selection callback. Will be called once Profile selector decides on * the opportunistic data profile. */ @@ -139,6 +128,11 @@ public class OpportunisticNetworkService extends Service { } List<SubscriptionInfo> subscriptionInfos = mSubscriptionManager.getActiveSubscriptionInfoList(false); + if (subscriptionInfos == null) { + return; + } + + logDebug("handleSimStateChange: subscriptionInfos - " + subscriptionInfos); for (SubscriptionInfo subscriptionInfo : subscriptionInfos) { if (subscriptionInfo.getSubscriptionId() == carrierAppConfigInput.getPrimarySub()) { return; @@ -394,7 +388,8 @@ public class OpportunisticNetworkService extends Service { /* carrier apps should report only subscription */ if (availableNetworks.size() > 1) { log("Carrier app should not pass more than one subscription"); - if (Compatibility.isChangeEnabled(CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + if (Compatibility.isChangeEnabled( + TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager .UPDATE_AVAILABLE_NETWORKS_MULTIPLE_NETWORKS_NOT_SUPPORTED); @@ -407,7 +402,8 @@ public class OpportunisticNetworkService extends Service { if (!mProfileSelector.hasOpprotunisticSub(availableNetworks)) { log("No opportunistic subscriptions received"); - if (Compatibility.isChangeEnabled(CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + if (Compatibility.isChangeEnabled( + TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager .UPDATE_AVAILABLE_NETWORKS_NO_OPPORTUNISTIC_SUB_AVAILABLE); @@ -439,16 +435,19 @@ public class OpportunisticNetworkService extends Service { final long identity = Binder.clearCallingIdentity(); try { ONSConfigInput onsConfigInput = new ONSConfigInput(availableNetworks, callbackStub); - onsConfigInput.setPrimarySub( - mSubscriptionManager.getDefaultVoiceSubscriptionInfo().getSubscriptionId()); - onsConfigInput.setPreferredDataSub(availableNetworks.get(0).getSubId()); - mONSConfigInputHashMap.put(CARRIER_APP_CONFIG_NAME, onsConfigInput); + SubscriptionInfo subscriptionInfo = mSubscriptionManager.getDefaultVoiceSubscriptionInfo(); + if (subscriptionInfo != null) { + onsConfigInput.setPrimarySub(subscriptionInfo.getSubscriptionId()); + onsConfigInput.setPreferredDataSub(availableNetworks.get(0).getSubId()); + mONSConfigInputHashMap.put(CARRIER_APP_CONFIG_NAME, onsConfigInput); + } if (mIsEnabled) { /* if carrier is reporting availability, then it takes higher priority. */ mProfileSelector.startProfileSelection(availableNetworks, callbackStub); } else { - if (Compatibility.isChangeEnabled(CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + if (Compatibility.isChangeEnabled( + TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SERVICE_IS_DISABLED); } else { @@ -514,7 +513,8 @@ public class OpportunisticNetworkService extends Service { /* all subscriptions should be opportunistic subscriptions */ if (!mProfileSelector.hasOpprotunisticSub(availableNetworks)) { log("No opportunistic subscriptions received"); - if (Compatibility.isChangeEnabled(CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + if (Compatibility.isChangeEnabled( + TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager .UPDATE_AVAILABLE_NETWORKS_NO_OPPORTUNISTIC_SUB_AVAILABLE); @@ -533,7 +533,8 @@ public class OpportunisticNetworkService extends Service { mProfileSelector.startProfileSelection(availableNetworks, callbackStub); } } else { - if (Compatibility.isChangeEnabled(CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + if (Compatibility.isChangeEnabled( + TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SERVICE_IS_DISABLED); } else { diff --git a/tests/src/com/android/ons/ONSProfileSelectorTest.java b/tests/src/com/android/ons/ONSProfileSelectorTest.java index 86cf826..c979f4a 100644 --- a/tests/src/com/android/ons/ONSProfileSelectorTest.java +++ b/tests/src/com/android/ons/ONSProfileSelectorTest.java @@ -82,6 +82,14 @@ public class ONSProfileSelectorTest extends ONSBaseTest { updateOpportunisticSubscriptions(); } + public int getCurrentPreferredData() { + return mCurrentDataSubId; + } + + public void setCurrentPreferredData(int subId) { + mCurrentDataSubId = subId; + } + protected void init(Context c, MyONSProfileSelector.ONSProfileSelectionCallback aNSProfileSelectionCallback) { super.init(c, aNSProfileSelectionCallback); @@ -544,4 +552,101 @@ public class ONSProfileSelectorTest extends ONSBaseTest { assertEquals(TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SUCCESS, mResult); assertTrue(mReady); } + + @Test + public void testStopProfileSelectionWithPreferredDataOnSame() { + List<SubscriptionInfo> subscriptionInfoList = new ArrayList<SubscriptionInfo>(); + SubscriptionInfo subscriptionInfo = new SubscriptionInfo(5, "", 1, "TMO", "TMO", 1, 1, + "123", 1, null, "310", "210", "", true, null, "1", true, null, 0, 0); + subscriptionInfoList.add(subscriptionInfo); + + IUpdateAvailableNetworksCallback mCallback = new IUpdateAvailableNetworksCallback.Stub() { + @Override + public void onComplete(int result) { + mResult = result; + } + }; + + mResult = -1; + mReady = false; + new Thread(new Runnable() { + @Override + public void run() { + Looper.prepare(); + doReturn(subscriptionInfoList).when(mSubscriptionManager) + .getOpportunisticSubscriptions(); + doReturn(true).when(mSubscriptionManager).isActiveSubId(anyInt()); + doReturn(true).when(mSubscriptionBoundTelephonyManager).enableModemForSlot( + anyInt(), anyBoolean()); + doReturn(5).when(mSubscriptionManager).getPreferredDataSubscriptionId(); + doReturn(subscriptionInfoList).when(mSubscriptionManager) + .getActiveSubscriptionInfoList(anyBoolean()); + + mONSProfileSelector = new MyONSProfileSelector(mContext, + new MyONSProfileSelector.ONSProfileSelectionCallback() { + public void onProfileSelectionDone() { + setReady(true); + } + }); + mONSProfileSelector.updateOppSubs(); + mONSProfileSelector.setCurrentPreferredData(5); + mONSProfileSelector.stopProfileSelection(null); + mLooper = Looper.myLooper(); + setReady(true); + Looper.loop(); + } + }).start(); + waitUntilReady(); + waitForMs(500); + assertEquals(mONSProfileSelector.getCurrentPreferredData(), SubscriptionManager.DEFAULT_SUBSCRIPTION_ID); + } + + @Test + public void testStopProfileSelectionWithPreferredDataOnDifferent() { + List<SubscriptionInfo> subscriptionInfoList = new ArrayList<SubscriptionInfo>(); + SubscriptionInfo subscriptionInfo = new SubscriptionInfo(5, "", 1, "TMO", "TMO", 1, 1, + "123", 1, null, "310", "210", "", true, null, "1", true, null, 0, 0); + subscriptionInfoList.add(subscriptionInfo); + + IUpdateAvailableNetworksCallback mCallback = new IUpdateAvailableNetworksCallback.Stub() { + @Override + public void onComplete(int result) { + mResult = result; + } + }; + + mResult = -1; + mReady = false; + new Thread(new Runnable() { + @Override + public void run() { + Looper.prepare(); + doReturn(subscriptionInfoList).when(mSubscriptionManager) + .getOpportunisticSubscriptions(); + doReturn(true).when(mSubscriptionManager).isActiveSubId(anyInt()); + doReturn(true).when(mSubscriptionBoundTelephonyManager).enableModemForSlot( + anyInt(), anyBoolean()); + doReturn(4).when(mSubscriptionManager).getPreferredDataSubscriptionId(); + doReturn(subscriptionInfoList).when(mSubscriptionManager) + .getActiveSubscriptionInfoList(anyBoolean()); + + mONSProfileSelector = new MyONSProfileSelector(mContext, + new MyONSProfileSelector.ONSProfileSelectionCallback() { + public void onProfileSelectionDone() { + setReady(true); + } + }); + mONSProfileSelector.updateOppSubs(); + mONSProfileSelector.setCurrentPreferredData(5); + mONSProfileSelector.stopProfileSelection(null); + mLooper = Looper.myLooper(); + setReady(true); + Looper.loop(); + } + }).start(); + waitUntilReady(); + waitForMs(500); + assertEquals(mONSProfileSelector.getCurrentPreferredData(), 5); + } + } |
