diff options
Diffstat (limited to 'src/java/com/android/internal/telephony/NetworkRegistrationManager.java')
-rw-r--r-- | src/java/com/android/internal/telephony/NetworkRegistrationManager.java | 66 |
1 files changed, 45 insertions, 21 deletions
diff --git a/src/java/com/android/internal/telephony/NetworkRegistrationManager.java b/src/java/com/android/internal/telephony/NetworkRegistrationManager.java index 4b2b690e0d..1b28be4b74 100644 --- a/src/java/com/android/internal/telephony/NetworkRegistrationManager.java +++ b/src/java/com/android/internal/telephony/NetworkRegistrationManager.java @@ -38,6 +38,7 @@ import android.telephony.INetworkServiceCallback; import android.telephony.NetworkRegistrationInfo; import android.telephony.NetworkService; import android.telephony.Rlog; +import android.telephony.SubscriptionManager; import android.text.TextUtils; import java.util.Hashtable; @@ -100,6 +101,9 @@ public class NetworkRegistrationManager extends Handler { intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); phone.getContext().registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, intentFilter, null, null); + PhoneConfigurationManager.registerForMultiSimConfigChange( + this, EVENT_BIND_NETWORK_SERVICE, null); + sendEmptyMessage(EVENT_BIND_NETWORK_SERVICE); } @@ -112,7 +116,7 @@ public class NetworkRegistrationManager extends Handler { public void handleMessage(Message msg) { switch (msg.what) { case EVENT_BIND_NETWORK_SERVICE: - bindService(); + rebindService(); break; default: loge("Unhandled event " + msg.what); @@ -231,15 +235,38 @@ public class NetworkRegistrationManager extends Handler { } } - private void bindService() { - Intent intent = null; - String packageName = getPackageName(); - String className = getClassName(); + private void unbindService() { + if (mINetworkService != null && mINetworkService.asBinder().isBinderAlive()) { + logd("unbinding service"); + // Remove the network availability updater and then unbind the service. + try { + mINetworkService.removeNetworkServiceProvider(mPhone.getPhoneId()); + } catch (RemoteException e) { + loge("Cannot remove data service provider. " + e); + } + } + + if (mServiceConnection != null) { + mPhone.getContext().unbindService(mServiceConnection); + } + mINetworkService = null; + mServiceConnection = null; + mTargetBindingPackageName = null; + } + + private void bindService(String packageName) { + if (mPhone == null || !SubscriptionManager.isValidPhoneId(mPhone.getPhoneId())) { + loge("can't bindService with invalid phone or phoneId."); + return; + } + if (TextUtils.isEmpty(packageName)) { loge("Can't find the binding package"); return; } + Intent intent = null; + String className = getClassName(); if (TextUtils.isEmpty(className)) { intent = new Intent(NetworkService.SERVICE_INTERFACE); intent.setPackage(packageName); @@ -248,22 +275,6 @@ public class NetworkRegistrationManager extends Handler { intent = new Intent(NetworkService.SERVICE_INTERFACE).setComponent(cm); } - if (TextUtils.equals(packageName, mTargetBindingPackageName)) { - logd("Service " + packageName + " already bound or being bound."); - return; - } - - if (mINetworkService != null && mINetworkService.asBinder().isBinderAlive()) { - // Remove the network availability updater and then unbind the service. - try { - mINetworkService.removeNetworkServiceProvider(mPhone.getPhoneId()); - } catch (RemoteException e) { - loge("Cannot remove data service provider. " + e); - } - - mPhone.getContext().unbindService(mServiceConnection); - } - try { // We bind this as a foreground service because it is operating directly on the SIM, // and we do not want it subjected to power-savings restrictions while doing so. @@ -281,6 +292,19 @@ public class NetworkRegistrationManager extends Handler { } } + private void rebindService() { + String packageName = getPackageName(); + // Do nothing if no need to rebind. + if (SubscriptionManager.isValidPhoneId(mPhone.getPhoneId()) + && TextUtils.equals(packageName, mTargetBindingPackageName)) { + logd("Service " + packageName + " already bound or being bound."); + return; + } + + unbindService(); + bindService(packageName); + } + private String getPackageName() { String packageName; int resourceId; |