Loading src/java/com/android/internal/telephony/data/AccessNetworksManager.java +42 −48 Original line number Diff line number Diff line Loading @@ -19,13 +19,10 @@ package com.android.internal.telephony.data; import android.annotation.CallbackExecutor; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; import android.content.pm.PackageManager; import android.os.AsyncResult; import android.os.Handler; import android.os.IBinder; Loading @@ -35,7 +32,6 @@ import android.os.PersistableBundle; import android.os.Registrant; import android.os.RegistrantList; import android.os.RemoteException; import android.os.UserHandle; import android.telephony.AccessNetworkConstants; import android.telephony.AccessNetworkConstants.AccessNetworkType; import android.telephony.AccessNetworkConstants.RadioAccessNetworkType; Loading Loading @@ -125,22 +121,6 @@ public class AccessNetworksManager extends Handler { private final RegistrantList mQualifiedNetworksChangedRegistrants = new RegistrantList(); private final BroadcastReceiver mConfigChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED.equals(action) && mPhone.getPhoneId() == intent.getIntExtra( CarrierConfigManager.EXTRA_SLOT_INDEX, 0)) { // We should wait for carrier config changed event because the target binding // package name can come from the carrier config. Note that we still get this event // even when SIM is absent. if (DBG) log("Carrier config changed. Try to bind qualified network service."); bindQualifiedNetworksService(); } } }; /** * The preferred transport of the APN type. The key is the APN type, and the value is the * transport. The preferred transports are updated as soon as QNS changes the preference. Loading Loading @@ -366,16 +346,18 @@ public class AccessNetworksManager extends Handler { mApnTypeToQnsChangeNetworkCounter = new SparseArray<>(); mAvailableTransports = new int[]{AccessNetworkConstants.TRANSPORT_TYPE_WWAN, AccessNetworkConstants.TRANSPORT_TYPE_WLAN}; IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); try { Context contextAsUser = phone.getContext().createPackageContextAsUser( phone.getContext().getPackageName(), 0, UserHandle.ALL); contextAsUser.registerReceiver(mConfigChangedReceiver, intentFilter, null /* broadcastPermission */, null); } catch (PackageManager.NameNotFoundException e) { loge("Package name not found: ", e); } // bindQualifiedNetworksService posts real work to handler thread. So here we can // let the callback execute in binder thread to avoid post twice. mCarrierConfigManager.registerCarrierConfigChangeListener(Runnable::run, (slotIndex, subId, carrierId, specificCarrierId) -> { if (slotIndex != mPhone.getPhoneId()) return; // We should wait for carrier config changed event because the target binding // package name can come from the carrier config. Note that we still get this // event even when SIM is absent. if (DBG) log("Carrier config changed. Try to bind qualified network service."); bindQualifiedNetworksService(); }); bindQualifiedNetworksService(); // Using post to delay the registering because data retry manager and data config Loading Loading @@ -488,9 +470,12 @@ public class AccessNetworksManager extends Handler { String packageName = mPhone.getContext().getResources().getString( com.android.internal.R.string.config_qualified_networks_service_package); PersistableBundle b = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId()); if (b != null) { PersistableBundle b; try { b = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId(), CarrierConfigManager .KEY_CARRIER_QUALIFIED_NETWORKS_SERVICE_PACKAGE_OVERRIDE_STRING); if (!b.isEmpty()) { // If carrier config overrides it, use the one from carrier config String carrierConfigPackageName = b.getString(CarrierConfigManager .KEY_CARRIER_QUALIFIED_NETWORKS_SERVICE_PACKAGE_OVERRIDE_STRING); Loading @@ -499,6 +484,9 @@ public class AccessNetworksManager extends Handler { packageName = carrierConfigPackageName; } } } catch (RuntimeException e) { loge("Carrier config loader is not available."); } return packageName; } Loading @@ -513,9 +501,12 @@ public class AccessNetworksManager extends Handler { String className = mPhone.getContext().getResources().getString( com.android.internal.R.string.config_qualified_networks_service_class); PersistableBundle b = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId()); if (b != null) { PersistableBundle b; try { b = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId(), CarrierConfigManager .KEY_CARRIER_QUALIFIED_NETWORKS_SERVICE_CLASS_OVERRIDE_STRING); if (!b.isEmpty()) { // If carrier config overrides it, use the one from carrier config String carrierConfigClassName = b.getString(CarrierConfigManager .KEY_CARRIER_QUALIFIED_NETWORKS_SERVICE_CLASS_OVERRIDE_STRING); Loading @@ -524,6 +515,9 @@ public class AccessNetworksManager extends Handler { className = carrierConfigClassName; } } } catch (RuntimeException e) { loge("Carrier config loader is not available."); } return className; } Loading tests/telephonytests/src/com/android/internal/telephony/data/AccessNetworksManagerTest.java +8 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.ComponentName; import android.content.IntentFilter; Loading @@ -35,6 +36,7 @@ import android.os.AsyncResult; import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.PersistableBundle; import android.telephony.AccessNetworkConstants; import android.telephony.AccessNetworkConstants.AccessNetworkType; import android.telephony.NetworkService; Loading Loading @@ -67,6 +69,8 @@ public class AccessNetworksManagerTest extends TelephonyTest { // The real callback passed created by AccessNetworksManager. private IQualifiedNetworksServiceCallback.Stub mQnsCallback; private PersistableBundle mBundle; private void addQnsService() throws Exception { ServiceInfo QnsInfo = new ServiceInfo(); QnsInfo.packageName = "fake.qns"; Loading Loading @@ -97,6 +101,9 @@ public class AccessNetworksManagerTest extends TelephonyTest { mMockedQns = mock(IQualifiedNetworksService.class); mMockedIBinder = mock(IBinder.class); mBundle = mContextFixture.getCarrierConfigBundle(); when(mCarrierConfigManager.getConfigForSubId(anyInt(), any())).thenReturn(mBundle); addQnsService(); mContextFixture.putResource( com.android.internal.R.string.config_qualified_networks_service_package, Loading @@ -121,6 +128,7 @@ public class AccessNetworksManagerTest extends TelephonyTest { @After public void tearDown() throws Exception { mAccessNetworksManager = null; mBundle = null; super.tearDown(); } Loading Loading
src/java/com/android/internal/telephony/data/AccessNetworksManager.java +42 −48 Original line number Diff line number Diff line Loading @@ -19,13 +19,10 @@ package com.android.internal.telephony.data; import android.annotation.CallbackExecutor; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; import android.content.pm.PackageManager; import android.os.AsyncResult; import android.os.Handler; import android.os.IBinder; Loading @@ -35,7 +32,6 @@ import android.os.PersistableBundle; import android.os.Registrant; import android.os.RegistrantList; import android.os.RemoteException; import android.os.UserHandle; import android.telephony.AccessNetworkConstants; import android.telephony.AccessNetworkConstants.AccessNetworkType; import android.telephony.AccessNetworkConstants.RadioAccessNetworkType; Loading Loading @@ -125,22 +121,6 @@ public class AccessNetworksManager extends Handler { private final RegistrantList mQualifiedNetworksChangedRegistrants = new RegistrantList(); private final BroadcastReceiver mConfigChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED.equals(action) && mPhone.getPhoneId() == intent.getIntExtra( CarrierConfigManager.EXTRA_SLOT_INDEX, 0)) { // We should wait for carrier config changed event because the target binding // package name can come from the carrier config. Note that we still get this event // even when SIM is absent. if (DBG) log("Carrier config changed. Try to bind qualified network service."); bindQualifiedNetworksService(); } } }; /** * The preferred transport of the APN type. The key is the APN type, and the value is the * transport. The preferred transports are updated as soon as QNS changes the preference. Loading Loading @@ -366,16 +346,18 @@ public class AccessNetworksManager extends Handler { mApnTypeToQnsChangeNetworkCounter = new SparseArray<>(); mAvailableTransports = new int[]{AccessNetworkConstants.TRANSPORT_TYPE_WWAN, AccessNetworkConstants.TRANSPORT_TYPE_WLAN}; IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); try { Context contextAsUser = phone.getContext().createPackageContextAsUser( phone.getContext().getPackageName(), 0, UserHandle.ALL); contextAsUser.registerReceiver(mConfigChangedReceiver, intentFilter, null /* broadcastPermission */, null); } catch (PackageManager.NameNotFoundException e) { loge("Package name not found: ", e); } // bindQualifiedNetworksService posts real work to handler thread. So here we can // let the callback execute in binder thread to avoid post twice. mCarrierConfigManager.registerCarrierConfigChangeListener(Runnable::run, (slotIndex, subId, carrierId, specificCarrierId) -> { if (slotIndex != mPhone.getPhoneId()) return; // We should wait for carrier config changed event because the target binding // package name can come from the carrier config. Note that we still get this // event even when SIM is absent. if (DBG) log("Carrier config changed. Try to bind qualified network service."); bindQualifiedNetworksService(); }); bindQualifiedNetworksService(); // Using post to delay the registering because data retry manager and data config Loading Loading @@ -488,9 +470,12 @@ public class AccessNetworksManager extends Handler { String packageName = mPhone.getContext().getResources().getString( com.android.internal.R.string.config_qualified_networks_service_package); PersistableBundle b = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId()); if (b != null) { PersistableBundle b; try { b = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId(), CarrierConfigManager .KEY_CARRIER_QUALIFIED_NETWORKS_SERVICE_PACKAGE_OVERRIDE_STRING); if (!b.isEmpty()) { // If carrier config overrides it, use the one from carrier config String carrierConfigPackageName = b.getString(CarrierConfigManager .KEY_CARRIER_QUALIFIED_NETWORKS_SERVICE_PACKAGE_OVERRIDE_STRING); Loading @@ -499,6 +484,9 @@ public class AccessNetworksManager extends Handler { packageName = carrierConfigPackageName; } } } catch (RuntimeException e) { loge("Carrier config loader is not available."); } return packageName; } Loading @@ -513,9 +501,12 @@ public class AccessNetworksManager extends Handler { String className = mPhone.getContext().getResources().getString( com.android.internal.R.string.config_qualified_networks_service_class); PersistableBundle b = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId()); if (b != null) { PersistableBundle b; try { b = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId(), CarrierConfigManager .KEY_CARRIER_QUALIFIED_NETWORKS_SERVICE_CLASS_OVERRIDE_STRING); if (!b.isEmpty()) { // If carrier config overrides it, use the one from carrier config String carrierConfigClassName = b.getString(CarrierConfigManager .KEY_CARRIER_QUALIFIED_NETWORKS_SERVICE_CLASS_OVERRIDE_STRING); Loading @@ -524,6 +515,9 @@ public class AccessNetworksManager extends Handler { className = carrierConfigClassName; } } } catch (RuntimeException e) { loge("Carrier config loader is not available."); } return className; } Loading
tests/telephonytests/src/com/android/internal/telephony/data/AccessNetworksManagerTest.java +8 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.ComponentName; import android.content.IntentFilter; Loading @@ -35,6 +36,7 @@ import android.os.AsyncResult; import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.PersistableBundle; import android.telephony.AccessNetworkConstants; import android.telephony.AccessNetworkConstants.AccessNetworkType; import android.telephony.NetworkService; Loading Loading @@ -67,6 +69,8 @@ public class AccessNetworksManagerTest extends TelephonyTest { // The real callback passed created by AccessNetworksManager. private IQualifiedNetworksServiceCallback.Stub mQnsCallback; private PersistableBundle mBundle; private void addQnsService() throws Exception { ServiceInfo QnsInfo = new ServiceInfo(); QnsInfo.packageName = "fake.qns"; Loading Loading @@ -97,6 +101,9 @@ public class AccessNetworksManagerTest extends TelephonyTest { mMockedQns = mock(IQualifiedNetworksService.class); mMockedIBinder = mock(IBinder.class); mBundle = mContextFixture.getCarrierConfigBundle(); when(mCarrierConfigManager.getConfigForSubId(anyInt(), any())).thenReturn(mBundle); addQnsService(); mContextFixture.putResource( com.android.internal.R.string.config_qualified_networks_service_package, Loading @@ -121,6 +128,7 @@ public class AccessNetworksManagerTest extends TelephonyTest { @After public void tearDown() throws Exception { mAccessNetworksManager = null; mBundle = null; super.tearDown(); } Loading