import static android.content.Context.CARRIER_CONFIG_SERVICE;
import static android.content.Context.EUICC_SERVICE;
import static android.content.Context.TELEPHONY_SERVICE;
+import static android.content.Context.TELEPHONY_SUBSCRIPTION_SERVICE;
import android.Manifest;
import android.content.BroadcastReceiver;
import android.telephony.SignalStrength;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
+import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
import android.telephony.TelephonyManager;
import android.telephony.euicc.EuiccManager;
import android.text.BidiFormatter;
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
-import java.util.List;
-
public class SimStatusDialogController implements LifecycleObserver, OnResume, OnPause {
private final static String TAG = "SimStatusDialogCtrl";
"com.android.cellbroadcastreceiver.GET_LATEST_CB_AREA_INFO";
private final static String CELL_BROADCAST_RECEIVER_APP = "com.android.cellbroadcastreceiver";
+ private final OnSubscriptionsChangedListener mOnSubscriptionsChangedListener =
+ new OnSubscriptionsChangedListener() {
+ @Override
+ public void onSubscriptionsChanged() {
+ mSubscriptionInfo = mSubscriptionManager.getActiveSubscriptionInfo(
+ mSubscriptionInfo.getSubscriptionId());
+ updateNetworkProvider();
+ }
+ };
+
+ private SubscriptionInfo mSubscriptionInfo;
+
private final SimStatusDialogFragment mDialog;
- private final SubscriptionInfo mSubscriptionInfo;
private final TelephonyManager mTelephonyManager;
+ private final SubscriptionManager mSubscriptionManager;
private final CarrierConfigManager mCarrierConfigManager;
private final EuiccManager mEuiccManager;
private final Resources mRes;
mDialog = dialog;
mContext = dialog.getContext();
mSubscriptionInfo = getPhoneSubscriptionInfo(slotId);
- mTelephonyManager = (TelephonyManager) mContext.getSystemService(
- TELEPHONY_SERVICE);
- mCarrierConfigManager = (CarrierConfigManager) mContext.getSystemService(
- CARRIER_CONFIG_SERVICE);
- mEuiccManager = (EuiccManager) mContext.getSystemService(EUICC_SERVICE);
+ mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
+ mCarrierConfigManager = mContext.getSystemService(CarrierConfigManager.class);
+ mEuiccManager = mContext.getSystemService(EuiccManager.class);
+ mSubscriptionManager = mContext.getSystemService(SubscriptionManager.class);
mRes = mContext.getResources();
}
mPhoneStateListener = getPhoneStateListener();
+ updateNetworkProvider();
final ServiceState serviceState = getCurrentServiceState();
- updateNetworkProvider(serviceState);
updatePhoneNumber();
updateLatestAreaInfo();
updateServiceState(serviceState);
PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
| PhoneStateListener.LISTEN_SERVICE_STATE);
+ mSubscriptionManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener);
if (mShowLatestAreaInfo) {
mContext.registerReceiver(mAreaInfoReceiver,
return;
}
+ mSubscriptionManager.removeOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener);
mTelephonyManager.createForSubscriptionId(mSubscriptionInfo.getSubscriptionId())
.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
}
}
- private void updateNetworkProvider(ServiceState serviceState) {
- mDialog.setText(NETWORK_PROVIDER_VALUE_ID, serviceState.getOperatorAlphaLong());
+ private void updateNetworkProvider() {
+ final CharSequence carrierName =
+ mSubscriptionInfo != null ? mSubscriptionInfo.getCarrierName() : null;
+ mDialog.setText(NETWORK_PROVIDER_VALUE_ID, carrierName);
}
private void updatePhoneNumber() {
@Override
public void onServiceStateChanged(ServiceState serviceState) {
- updateNetworkProvider(serviceState);
+ updateNetworkProvider();
updateServiceState(serviceState);
updateRoamingStatus(serviceState);
}
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.euicc.EuiccManager;
private PersistableBundle mPersistableBundle;
@Mock
private EuiccManager mEuiccManager;
+ @Mock
+ private SubscriptionManager mSubscriptionManager;
private SimStatusDialogController mController;
private Context mContext;
doReturn(mPhoneStateListener).when(mController).getPhoneStateListener();
doReturn("").when(mController).getPhoneNumber();
doReturn(mSignalStrength).when(mController).getSignalStrength();
+ doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt());
when(mEuiccManager.isEnabled()).thenReturn(true);
when(mEuiccManager.getEid()).thenReturn("");
ReflectionHelpers.setField(mController, "mCarrierConfigManager", mCarrierConfigManager);
ReflectionHelpers.setField(mController, "mSubscriptionInfo", mSubscriptionInfo);
ReflectionHelpers.setField(mController, "mEuiccManager", mEuiccManager);
+ ReflectionHelpers.setField(mController, "mSubscriptionManager", mSubscriptionManager);
when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(mPersistableBundle);
final ShadowPackageManager shadowPackageManager =
@Test
public void initialize_updateNetworkProviderWithFoobarCarrier_shouldUpdateCarrierWithFoobar() {
- final String carrierName = "foobar";
- when(mServiceState.getOperatorAlphaLong()).thenReturn(carrierName);
+ final CharSequence carrierName = "foobar";
+ doReturn(carrierName).when(mSubscriptionInfo).getCarrierName();
mController.initialize();