Loading src/java/com/android/internal/telephony/data/DataServiceManager.java +27 −34 Original line number Diff line number Diff line Loading @@ -22,11 +22,9 @@ import static android.text.format.DateUtils.SECOND_IN_MILLIS; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.AppOpsManager; 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.content.pm.ResolveInfo; Loading Loading @@ -121,22 +119,6 @@ public class DataServiceManager extends Handler { private List<DataCallResponse> mLastDataCallResponseList = Collections.EMPTY_LIST; private final BroadcastReceiver mBroadcastReceiver = 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 data service."); sendEmptyMessage(EVENT_BIND_DATA_SERVICE); } } }; private class DataServiceManagerDeathRecipient implements IBinder.DeathRecipient { @Override public void binderDied() { Loading Loading @@ -409,16 +391,18 @@ public class DataServiceManager extends Handler { Context.LEGACY_PERMISSION_SERVICE); mAppOps = (AppOpsManager) phone.getContext().getSystemService(Context.APP_OPS_SERVICE); 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(mBroadcastReceiver, intentFilter, null /* broadcastPermission */, null); } catch (PackageManager.NameNotFoundException e) { loge("Package name not found: " + e.getMessage()); // Callback is executed in handler thread to directly handle config change. mCarrierConfigManager.registerCarrierConfigChangeListener(this::post, (slotIndex, subId, carrierId, specificCarrierId) -> { if (slotIndex == mPhone.getPhoneId()) { // 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 data service."); rebindDataService(); } }); PhoneConfigurationManager.registerForMultiSimConfigChange( this, EVENT_BIND_DATA_SERVICE, null); Loading Loading @@ -587,9 +571,8 @@ public class DataServiceManager extends Handler { // Read package name from resource overlay packageName = mPhone.getContext().getResources().getString(resourceId); PersistableBundle b = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId()); if (b != null && !TextUtils.isEmpty(b.getString(carrierConfig))) { PersistableBundle b = getCarrierConfigSubset(carrierConfig); if (!b.isEmpty() && !TextUtils.isEmpty(b.getString(carrierConfig))) { // If carrier config overrides it, use the one from carrier config packageName = b.getString(carrierConfig, packageName); } Loading Loading @@ -636,9 +619,8 @@ public class DataServiceManager extends Handler { // Read package name from resource overlay className = mPhone.getContext().getResources().getString(resourceId); PersistableBundle b = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId()); if (b != null && !TextUtils.isEmpty(b.getString(carrierConfig))) { PersistableBundle b = getCarrierConfigSubset(carrierConfig); if (!b.isEmpty() && !TextUtils.isEmpty(b.getString(carrierConfig))) { // If carrier config overrides it, use the one from carrier config className = b.getString(carrierConfig, className); } Loading @@ -646,6 +628,17 @@ public class DataServiceManager extends Handler { return className; } @NonNull private PersistableBundle getCarrierConfigSubset(String key) { PersistableBundle configs = new PersistableBundle(); try { configs = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId(), key); } catch (RuntimeException e) { loge("CarrierConfigLoader is not available."); } return configs; } private void sendCompleteMessage(Message msg, @DataServiceCallback.ResultCode int code) { if (msg != null) { msg.arg1 = code; Loading tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkControllerTest.java +5 −2 Original line number Diff line number Diff line Loading @@ -634,6 +634,7 @@ public class DataNetworkControllerTest extends TelephonyTest { private void initializeConfig() { mCarrierConfig = mContextFixture.getCarrierConfigBundle(); when(mCarrierConfigManager.getConfigForSubId(anyInt(), any())).thenReturn(mCarrierConfig); mCarrierConfig.putStringArray( CarrierConfigManager.KEY_TELEPHONY_NETWORK_CAPABILITY_PRIORITIES_STRING_ARRAY, new String[]{ Loading Loading @@ -788,9 +789,11 @@ public class DataNetworkControllerTest extends TelephonyTest { // between DataNetworkController and its sub-modules, we intend to make those modules "real" // as well, except some modules below we replaced with mocks. mDataNetworkControllerUT = new DataNetworkController(mPhone, Looper.myLooper()); verify(mCarrierConfigManager).registerCarrierConfigChangeListener(any(), // First two come from DataServiceManager and the third comes from DataConfigManager which // is what we want to capture and assign to mCarrierConfigChangeListener verify(mCarrierConfigManager, times(3)).registerCarrierConfigChangeListener(any(), listenerArgumentCaptor.capture()); mCarrierConfigChangeListener = listenerArgumentCaptor.getAllValues().get(0); mCarrierConfigChangeListener = listenerArgumentCaptor.getAllValues().get(2); assertThat(mCarrierConfigChangeListener).isNotNull(); doReturn(mDataNetworkControllerUT).when(mPhone).getDataNetworkController(); Loading tests/telephonytests/src/com/android/internal/telephony/data/DataServiceManagerTest.java +6 −0 Original line number Diff line number Diff line Loading @@ -25,12 +25,14 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.IntentFilter; import android.content.pm.ServiceInfo; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.PersistableBundle; import android.telephony.AccessNetworkConstants; import android.telephony.AccessNetworkConstants.AccessNetworkType; import android.telephony.TelephonyManager; Loading Loading @@ -89,15 +91,19 @@ public class DataServiceManagerTest extends TelephonyTest { private Handler mHandler; private Handler mDataServiceHandler; private PersistableBundle mBundle; @Before public void setUp() throws Exception { super.setUp(getClass().getSimpleName()); mBundle = mContextFixture.getCarrierConfigBundle(); when(mCarrierConfigManager.getConfigForSubId(anyInt(), any())).thenReturn(mBundle); } @After public void tearDown() throws Exception { mDataServiceManagerUT = null; mBundle = null; super.tearDown(); } Loading Loading
src/java/com/android/internal/telephony/data/DataServiceManager.java +27 −34 Original line number Diff line number Diff line Loading @@ -22,11 +22,9 @@ import static android.text.format.DateUtils.SECOND_IN_MILLIS; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.AppOpsManager; 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.content.pm.ResolveInfo; Loading Loading @@ -121,22 +119,6 @@ public class DataServiceManager extends Handler { private List<DataCallResponse> mLastDataCallResponseList = Collections.EMPTY_LIST; private final BroadcastReceiver mBroadcastReceiver = 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 data service."); sendEmptyMessage(EVENT_BIND_DATA_SERVICE); } } }; private class DataServiceManagerDeathRecipient implements IBinder.DeathRecipient { @Override public void binderDied() { Loading Loading @@ -409,16 +391,18 @@ public class DataServiceManager extends Handler { Context.LEGACY_PERMISSION_SERVICE); mAppOps = (AppOpsManager) phone.getContext().getSystemService(Context.APP_OPS_SERVICE); 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(mBroadcastReceiver, intentFilter, null /* broadcastPermission */, null); } catch (PackageManager.NameNotFoundException e) { loge("Package name not found: " + e.getMessage()); // Callback is executed in handler thread to directly handle config change. mCarrierConfigManager.registerCarrierConfigChangeListener(this::post, (slotIndex, subId, carrierId, specificCarrierId) -> { if (slotIndex == mPhone.getPhoneId()) { // 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 data service."); rebindDataService(); } }); PhoneConfigurationManager.registerForMultiSimConfigChange( this, EVENT_BIND_DATA_SERVICE, null); Loading Loading @@ -587,9 +571,8 @@ public class DataServiceManager extends Handler { // Read package name from resource overlay packageName = mPhone.getContext().getResources().getString(resourceId); PersistableBundle b = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId()); if (b != null && !TextUtils.isEmpty(b.getString(carrierConfig))) { PersistableBundle b = getCarrierConfigSubset(carrierConfig); if (!b.isEmpty() && !TextUtils.isEmpty(b.getString(carrierConfig))) { // If carrier config overrides it, use the one from carrier config packageName = b.getString(carrierConfig, packageName); } Loading Loading @@ -636,9 +619,8 @@ public class DataServiceManager extends Handler { // Read package name from resource overlay className = mPhone.getContext().getResources().getString(resourceId); PersistableBundle b = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId()); if (b != null && !TextUtils.isEmpty(b.getString(carrierConfig))) { PersistableBundle b = getCarrierConfigSubset(carrierConfig); if (!b.isEmpty() && !TextUtils.isEmpty(b.getString(carrierConfig))) { // If carrier config overrides it, use the one from carrier config className = b.getString(carrierConfig, className); } Loading @@ -646,6 +628,17 @@ public class DataServiceManager extends Handler { return className; } @NonNull private PersistableBundle getCarrierConfigSubset(String key) { PersistableBundle configs = new PersistableBundle(); try { configs = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId(), key); } catch (RuntimeException e) { loge("CarrierConfigLoader is not available."); } return configs; } private void sendCompleteMessage(Message msg, @DataServiceCallback.ResultCode int code) { if (msg != null) { msg.arg1 = code; Loading
tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkControllerTest.java +5 −2 Original line number Diff line number Diff line Loading @@ -634,6 +634,7 @@ public class DataNetworkControllerTest extends TelephonyTest { private void initializeConfig() { mCarrierConfig = mContextFixture.getCarrierConfigBundle(); when(mCarrierConfigManager.getConfigForSubId(anyInt(), any())).thenReturn(mCarrierConfig); mCarrierConfig.putStringArray( CarrierConfigManager.KEY_TELEPHONY_NETWORK_CAPABILITY_PRIORITIES_STRING_ARRAY, new String[]{ Loading Loading @@ -788,9 +789,11 @@ public class DataNetworkControllerTest extends TelephonyTest { // between DataNetworkController and its sub-modules, we intend to make those modules "real" // as well, except some modules below we replaced with mocks. mDataNetworkControllerUT = new DataNetworkController(mPhone, Looper.myLooper()); verify(mCarrierConfigManager).registerCarrierConfigChangeListener(any(), // First two come from DataServiceManager and the third comes from DataConfigManager which // is what we want to capture and assign to mCarrierConfigChangeListener verify(mCarrierConfigManager, times(3)).registerCarrierConfigChangeListener(any(), listenerArgumentCaptor.capture()); mCarrierConfigChangeListener = listenerArgumentCaptor.getAllValues().get(0); mCarrierConfigChangeListener = listenerArgumentCaptor.getAllValues().get(2); assertThat(mCarrierConfigChangeListener).isNotNull(); doReturn(mDataNetworkControllerUT).when(mPhone).getDataNetworkController(); Loading
tests/telephonytests/src/com/android/internal/telephony/data/DataServiceManagerTest.java +6 −0 Original line number Diff line number Diff line Loading @@ -25,12 +25,14 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.IntentFilter; import android.content.pm.ServiceInfo; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.PersistableBundle; import android.telephony.AccessNetworkConstants; import android.telephony.AccessNetworkConstants.AccessNetworkType; import android.telephony.TelephonyManager; Loading Loading @@ -89,15 +91,19 @@ public class DataServiceManagerTest extends TelephonyTest { private Handler mHandler; private Handler mDataServiceHandler; private PersistableBundle mBundle; @Before public void setUp() throws Exception { super.setUp(getClass().getSimpleName()); mBundle = mContextFixture.getCarrierConfigBundle(); when(mCarrierConfigManager.getConfigForSubId(anyInt(), any())).thenReturn(mBundle); } @After public void tearDown() throws Exception { mDataServiceManagerUT = null; mBundle = null; super.tearDown(); } Loading