diff options
| author | Xin Li <delphij@google.com> | 2020-09-08 16:56:21 -0700 |
|---|---|---|
| committer | Xin Li <delphij@google.com> | 2020-09-08 16:56:21 -0700 |
| commit | cbbd712e067b94d7f916159e3cd73136dd160467 (patch) | |
| tree | e041eef0fff3530b2a2f426a3836119f3a279472 /src/com/android/ons | |
| parent | 4c4eea7c1c2038f1e917f420d03c8c941f2d733d (diff) | |
| parent | 316e24b8936e7c4a672c7bac3efa237bcd5a301b (diff) | |
| download | platform_packages_services_AlternativeNetworkAccess-master.tar.gz platform_packages_services_AlternativeNetworkAccess-master.tar.bz2 platform_packages_services_AlternativeNetworkAccess-master.zip | |
Bug: 168057903
Merged-In: I76a40f211cb9022b7ee1c372266c8cc1e2537e57
Change-Id: I0e116f3777af27d0e768ac234e4cc97b23fe23f8
Diffstat (limited to 'src/com/android/ons')
| -rw-r--r-- | src/com/android/ons/ONSProfileSelector.java | 51 | ||||
| -rw-r--r-- | src/com/android/ons/OpportunisticNetworkService.java | 50 |
2 files changed, 63 insertions, 38 deletions
diff --git a/src/com/android/ons/ONSProfileSelector.java b/src/com/android/ons/ONSProfileSelector.java index 7266660..3e903c9 100644 --- a/src/com/android/ons/ONSProfileSelector.java +++ b/src/com/android/ons/ONSProfileSelector.java @@ -28,13 +28,13 @@ import android.os.Handler; import android.os.HandlerThread; import android.os.Message; import android.os.RemoteException; -import android.os.ServiceManager; import android.telephony.AvailableNetworkInfo; import android.telephony.CellInfo; import android.telephony.CellInfoLte; import android.telephony.SignalStrength; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; +import android.telephony.TelephonyFrameworkInitializer; import android.telephony.TelephonyManager; import android.text.TextUtils; @@ -148,7 +148,8 @@ public class ONSProfileSelector { .UPDATE_AVAILABLE_NETWORKS_INVALID_ARGUMENTS); } else { if (Compatibility.isChangeEnabled( - TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + OpportunisticNetworkService + .CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(mNetworkScanCallback, TelephonyManager .UPDATE_AVAILABLE_NETWORKS_SERVICE_IS_DISABLED); @@ -172,7 +173,8 @@ public class ONSProfileSelector { TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SUCCESS); } else { if (Compatibility.isChangeEnabled( - TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + OpportunisticNetworkService + .CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(mNetworkScanCallback, TelephonyManager .UPDATE_AVAILABLE_NETWORKS_ENABLE_MODEM_FAIL); @@ -294,7 +296,6 @@ public class ONSProfileSelector { } } } - return SubscriptionManager.INVALID_SUBSCRIPTION_ID; } @@ -379,7 +380,7 @@ public class ONSProfileSelector { TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SUCCESS); } else { if (Compatibility.isChangeEnabled( - TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + OpportunisticNetworkService.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(mNetworkScanCallback, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_ENABLE_MODEM_FAIL); } else { @@ -484,7 +485,7 @@ public class ONSProfileSelector { if (mOppSubscriptionInfos == null) { logDebug("null subscription infos"); if (Compatibility.isChangeEnabled( - TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + OpportunisticNetworkService.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_NO_OPPORTUNISTIC_SUB_AVAILABLE); } else { @@ -538,14 +539,13 @@ public class ONSProfileSelector { TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SUCCESS); } else { if (Compatibility.isChangeEnabled( - TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + OpportunisticNetworkService.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; @@ -557,7 +557,7 @@ public class ONSProfileSelector { } } else if (mOppSubscriptionInfos.size() == 0) { if (Compatibility.isChangeEnabled( - TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + OpportunisticNetworkService.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_NO_OPPORTUNISTIC_SUB_AVAILABLE); } else { @@ -647,7 +647,7 @@ public class ONSProfileSelector { int subId = getActiveOpportunisticSubId(); if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { if (Compatibility.isChangeEnabled( - TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + OpportunisticNetworkService.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_NO_OPPORTUNISTIC_SUB_AVAILABLE); } else { @@ -661,7 +661,7 @@ public class ONSProfileSelector { TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SUCCESS); } else { if (Compatibility.isChangeEnabled( - TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + OpportunisticNetworkService.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_DISABLE_MODEM_FAIL); } else { @@ -672,7 +672,9 @@ public class ONSProfileSelector { } private boolean enableModem(int subId, boolean enable) { - if (!mSubscriptionManager.isActiveSubId(subId)) { + SubscriptionInfo info = mSubscriptionManager.getActiveSubscriptionInfo(subId); + if (info == null) { + // Subscription is not active. Do nothing. return false; } @@ -682,7 +684,7 @@ public class ONSProfileSelector { selectProfileForData(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, false, null); } } - int phoneId = SubscriptionManager.getPhoneId(subId); + int phoneId = info.getSimSlotIndex(); /* Todo: b/135067156 * Reenable this code once 135067156 is fixed if (mSubscriptionBoundTelephonyManager.isModemEnabledForSlot(phoneId) == enable) { @@ -800,11 +802,15 @@ public class ONSProfileSelector { ISetOpportunisticDataCallback callbackStub) { if ((subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) || (isOpprotunisticSub(subId) && mSubscriptionManager.isActiveSubId(subId))) { - ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); + ISub iSub = ISub.Stub.asInterface( + TelephonyFrameworkInitializer + .getTelephonyServiceManager() + .getSubscriptionServiceRegisterer() + .get()); if (iSub == null) { log("Could not get Subscription Service handle"); if (Compatibility.isChangeEnabled( - TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + OpportunisticNetworkService.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendSetOpptCallbackHelper(callbackStub, TelephonyManager.SET_OPPORTUNISTIC_SUB_REMOTE_SERVICE_EXCEPTION); } else { @@ -818,7 +824,7 @@ public class ONSProfileSelector { } catch (RemoteException ex) { log("Could not connect to Subscription Service"); if (Compatibility.isChangeEnabled( - TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + OpportunisticNetworkService.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendSetOpptCallbackHelper(callbackStub, TelephonyManager.SET_OPPORTUNISTIC_SUB_REMOTE_SERVICE_EXCEPTION); } else { @@ -831,7 +837,7 @@ public class ONSProfileSelector { } else { log("Inactive sub passed for preferred data " + subId); if (Compatibility.isChangeEnabled( - TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + OpportunisticNetworkService.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { if (isOpprotunisticSub(subId)) { sendSetOpptCallbackHelper(callbackStub, TelephonyManager.SET_OPPORTUNISTIC_SUB_INACTIVE_SUBSCRIPTION); @@ -863,9 +869,14 @@ public class ONSProfileSelector { protected void updateOpportunisticSubscriptions() { synchronized (mLock) { mOppSubscriptionInfos = mSubscriptionManager - .getOpportunisticSubscriptions().stream() - .filter(subInfo -> subInfo.isGroupDisabled() != true) - .collect(Collectors.toList()); + .getOpportunisticSubscriptions().stream() + .filter(subInfo -> subInfo.isGroupDisabled() != true) + .collect(Collectors.toList()); + if (mOppSubscriptionInfos != null) { + mStandaloneOppSubInfos = mOppSubscriptionInfos.stream() + .filter(subInfo -> subInfo.getGroupUuid() == null) + .collect(Collectors.toList()); + } } } diff --git a/src/com/android/ons/OpportunisticNetworkService.java b/src/com/android/ons/OpportunisticNetworkService.java index 62e292b..1178538 100644 --- a/src/com/android/ons/OpportunisticNetworkService.java +++ b/src/com/android/ons/OpportunisticNetworkService.java @@ -18,6 +18,8 @@ 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; @@ -25,14 +27,16 @@ 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.IBinder; import android.os.Message; import android.os.RemoteException; -import android.os.ServiceManager; +import android.os.TelephonyServiceManager.ServiceRegisterer; import android.telephony.AvailableNetworkInfo; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; +import android.telephony.TelephonyFrameworkInitializer; import android.telephony.TelephonyManager; import com.android.internal.annotations.VisibleForTesting; @@ -66,7 +70,6 @@ public class OpportunisticNetworkService extends Service { private static final String TAG = "ONS"; private static final String PREF_NAME = TAG; private static final String PREF_ENABLED = "isEnabled"; - private static final String SERVICE_NAME = "ions"; private static final String CARRIER_APP_CONFIG_NAME = "carrierApp"; private static final String SYSTEM_APP_CONFIG_NAME = "systemApp"; private static final boolean DBG = true; @@ -74,6 +77,14 @@ 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. */ @@ -325,8 +336,11 @@ public class OpportunisticNetworkService extends Service { initialize(getBaseContext()); /* register the service */ - if (ServiceManager.getService(SERVICE_NAME) == null) { - ServiceManager.addService(SERVICE_NAME, mBinder); + ServiceRegisterer opportunisticNetworkServiceRegisterer = TelephonyFrameworkInitializer + .getTelephonyServiceManager() + .getOpportunisticNetworkServiceRegisterer(); + if (opportunisticNetworkServiceRegisterer.get() == null) { + opportunisticNetworkServiceRegisterer.register(mBinder); } } @@ -388,8 +402,7 @@ 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( - TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + if (Compatibility.isChangeEnabled(CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager .UPDATE_AVAILABLE_NETWORKS_MULTIPLE_NETWORKS_NOT_SUPPORTED); @@ -402,8 +415,7 @@ public class OpportunisticNetworkService extends Service { if (!mProfileSelector.hasOpprotunisticSub(availableNetworks)) { log("No opportunistic subscriptions received"); - if (Compatibility.isChangeEnabled( - TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + if (Compatibility.isChangeEnabled(CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager .UPDATE_AVAILABLE_NETWORKS_NO_OPPORTUNISTIC_SUB_AVAILABLE); @@ -415,9 +427,15 @@ public class OpportunisticNetworkService extends Service { } for (AvailableNetworkInfo availableNetworkInfo : availableNetworks) { - if (Binder.withCleanCallingIdentity( - () -> mSubscriptionManager.isActiveSubId( - availableNetworkInfo.getSubId()))) { + final long identity = Binder.clearCallingIdentity(); + boolean isActiveSubId = false; + try { + isActiveSubId = + mSubscriptionManager.isActiveSubId(availableNetworkInfo.getSubId()); + } finally { + Binder.restoreCallingIdentity(identity); + } + if (isActiveSubId) { TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mContext, availableNetworkInfo.getSubId(), "updateAvailableNetworks"); } else { @@ -454,8 +472,7 @@ public class OpportunisticNetworkService extends Service { /* if carrier is reporting availability, then it takes higher priority. */ mProfileSelector.startProfileSelection(availableNetworks, callbackStub); } else { - if (Compatibility.isChangeEnabled( - TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + if (Compatibility.isChangeEnabled(CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SERVICE_IS_DISABLED); } else { @@ -521,8 +538,7 @@ public class OpportunisticNetworkService extends Service { /* all subscriptions should be opportunistic subscriptions */ if (!mProfileSelector.hasOpprotunisticSub(availableNetworks)) { log("No opportunistic subscriptions received"); - if (Compatibility.isChangeEnabled( - TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + if (Compatibility.isChangeEnabled(CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager .UPDATE_AVAILABLE_NETWORKS_NO_OPPORTUNISTIC_SUB_AVAILABLE); @@ -534,7 +550,6 @@ public class OpportunisticNetworkService extends Service { } mONSConfigInputHashMap.put(SYSTEM_APP_CONFIG_NAME, new ONSConfigInput(availableNetworks, callbackStub)); - /* reporting availability. proceed if carrier app has not requested any, but standalone opportunistic subscription should be handled in priority. */ if (mIsEnabled) { @@ -543,8 +558,7 @@ public class OpportunisticNetworkService extends Service { mProfileSelector.startProfileSelection(availableNetworks, callbackStub); } } else { - if (Compatibility.isChangeEnabled( - TelephonyManager.CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { + if (Compatibility.isChangeEnabled(CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { sendUpdateNetworksCallbackHelper(callbackStub, TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SERVICE_IS_DISABLED); } else { |
