diff options
Diffstat (limited to 'src/java/com/android/internal/telephony/dataconnection/DataServiceManager.java')
-rw-r--r-- | src/java/com/android/internal/telephony/dataconnection/DataServiceManager.java | 76 |
1 files changed, 50 insertions, 26 deletions
diff --git a/src/java/com/android/internal/telephony/dataconnection/DataServiceManager.java b/src/java/com/android/internal/telephony/dataconnection/DataServiceManager.java index 79bd475859..66d30649f3 100644 --- a/src/java/com/android/internal/telephony/dataconnection/DataServiceManager.java +++ b/src/java/com/android/internal/telephony/dataconnection/DataServiceManager.java @@ -44,6 +44,7 @@ import android.telephony.AccessNetworkConstants.TransportType; import android.telephony.AnomalyReporter; import android.telephony.CarrierConfigManager; import android.telephony.Rlog; +import android.telephony.SubscriptionManager; import android.telephony.data.DataCallResponse; import android.telephony.data.DataProfile; import android.telephony.data.DataService; @@ -53,6 +54,7 @@ import android.telephony.data.IDataServiceCallback; import android.text.TextUtils; import com.android.internal.telephony.Phone; +import com.android.internal.telephony.PhoneConfigurationManager; import java.util.HashSet; import java.util.List; @@ -285,8 +287,10 @@ public class DataServiceManager extends Handler { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); - phone.getContext().registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, - intentFilter, null, null); + + PhoneConfigurationManager.registerForMultiSimConfigChange( + this, EVENT_BIND_DATA_SERVICE, null); + sendEmptyMessage(EVENT_BIND_DATA_SERVICE); } @@ -299,7 +303,7 @@ public class DataServiceManager extends Handler { public void handleMessage(Message msg) { switch (msg.what) { case EVENT_BIND_DATA_SERVICE: - bindDataService(); + rebindDataService(); break; case EVENT_WATCHDOG_TIMEOUT: handleRequestUnresponded((CellularDataServiceCallback) msg.obj); @@ -320,41 +324,48 @@ public class DataServiceManager extends Handler { message); } - private void bindDataService() { - Intent intent = null; - String packageName = getDataServicePackageName(); - String className = getDataServiceClassName(); - if (TextUtils.isEmpty(packageName)) { - loge("Can't find the binding package"); - return; - } - - if (TextUtils.isEmpty(className)) { - intent = new Intent(DataService.SERVICE_INTERFACE); - intent.setPackage(packageName); - } else { - ComponentName cm = new ComponentName(packageName, className); - intent = new Intent(DataService.SERVICE_INTERFACE).setComponent(cm); - } - - if (TextUtils.equals(packageName, mTargetBindingPackageName)) { - if (DBG) log("Service " + packageName + " already bound or being bound."); - return; - } - + private void unbindDataService() { // Start by cleaning up all packages that *shouldn't* have permissions. revokePermissionsFromUnusedDataServices(); - if (mIDataService != null && mIDataService.asBinder().isBinderAlive()) { + log("unbinding service"); // Remove the network availability updater and then unbind the service. try { mIDataService.removeDataServiceProvider(mPhone.getPhoneId()); } catch (RemoteException e) { loge("Cannot remove data service provider. " + e); } + } + if (mServiceConnection != null) { mPhone.getContext().unbindService(mServiceConnection); } + mIDataService = null; + mServiceConnection = null; + mTargetBindingPackageName = null; + mBound = false; + } + + private void bindDataService(String packageName) { + if (mPhone == null || !SubscriptionManager.isValidPhoneId(mPhone.getPhoneId())) { + loge("can't bindDataService with invalid phone or phoneId."); + return; + } + + if (TextUtils.isEmpty(packageName)) { + loge("Can't find the binding package"); + return; + } + + Intent intent = null; + String className = getDataServiceClassName(); + if (TextUtils.isEmpty(className)) { + intent = new Intent(DataService.SERVICE_INTERFACE); + intent.setPackage(packageName); + } else { + ComponentName cm = new ComponentName(packageName, className); + intent = new Intent(DataService.SERVICE_INTERFACE).setComponent(cm); + } // Then pre-emptively grant the permissions to the package we will bind. grantPermissionsToService(packageName); @@ -372,6 +383,19 @@ public class DataServiceManager extends Handler { } } + private void rebindDataService() { + String packageName = getDataServicePackageName(); + // Do nothing if no need to rebind. + if (SubscriptionManager.isValidPhoneId(mPhone.getPhoneId()) + && TextUtils.equals(packageName, mTargetBindingPackageName)) { + if (DBG) log("Service " + packageName + " already bound or being bound."); + return; + } + + unbindDataService(); + bindDataService(packageName); + } + @NonNull private Set<String> getAllDataServicePackageNames() { // Cowardly using the public PackageManager interface here. |