Loading src/java/com/android/internal/telephony/uicc/SIMRecords.java +0 −80 Original line number Diff line number Diff line Loading @@ -16,10 +16,7 @@ package com.android.internal.telephony.uicc; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.res.Resources; import android.os.AsyncResult; import android.os.Message; Loading @@ -30,7 +27,6 @@ import android.telephony.Rlog; import android.telephony.ServiceState; import android.telephony.SmsMessage; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.text.TextUtils; import com.android.internal.telephony.CommandsInterface; Loading Loading @@ -172,7 +168,6 @@ public class SIMRecords extends IccRecords { // TODO: Possibly move these to IccRecords.java private static final int SYSTEM_EVENT_BASE = 0x100; private static final int EVENT_CARRIER_CONFIG_CHANGED = 1 + SYSTEM_EVENT_BASE; private static final int EVENT_APP_LOCKED = 2 + SYSTEM_EVENT_BASE; private static final int EVENT_APP_NETWORK_LOCKED = 3 + SYSTEM_EVENT_BASE; Loading Loading @@ -225,20 +220,7 @@ public class SIMRecords extends IccRecords { mParentApp.registerForLocked(this, EVENT_APP_LOCKED, null); mParentApp.registerForNetworkLocked(this, EVENT_APP_NETWORK_LOCKED, null); if (DBG) log("SIMRecords X ctor this=" + this); IntentFilter intentfilter = new IntentFilter(); intentfilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); c.registerReceiver(mReceiver, intentfilter); } private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) { sendMessage(obtainMessage(EVENT_CARRIER_CONFIG_CHANGED)); } } }; @Override public void dispose() { Loading @@ -248,7 +230,6 @@ public class SIMRecords extends IccRecords { mParentApp.unregisterForReady(this); mParentApp.unregisterForLocked(this); mParentApp.unregisterForNetworkLocked(this); mContext.unregisterReceiver(mReceiver); resetRecords(); super.dispose(); } Loading Loading @@ -1365,10 +1346,6 @@ public class SIMRecords extends IccRecords { } break; case EVENT_CARRIER_CONFIG_CHANGED: handleCarrierNameOverride(); break; default: super.handleMessage(msg); // IccRecords handles generic record load responses } Loading Loading @@ -1607,63 +1584,6 @@ public class SIMRecords extends IccRecords { //***** Private methods /** * Override the carrier name with either carrier config or SPN * if an override is provided. */ private void handleCarrierNameOverride() { final int phoneId = mParentApp.getPhoneId(); SubscriptionController subCon = SubscriptionController.getInstance(); final int subId = subCon.getSubIdUsingPhoneId(phoneId); if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { loge("subId not valid for Phone " + phoneId); return; } CarrierConfigManager configLoader = (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE); if (configLoader == null) { loge("Failed to load a Carrier Config"); return; } PersistableBundle config = configLoader.getConfigForSubId(subId); boolean preferCcName = config.getBoolean( CarrierConfigManager.KEY_CARRIER_NAME_OVERRIDE_BOOL, false); String ccName = config.getString(CarrierConfigManager.KEY_CARRIER_NAME_STRING); // If carrier config is priority, use it regardless - the preference // and the name were both set by the carrier, so this is safe; // otherwise, if the SPN is priority but we don't have one *and* we have // a name in carrier config, use the carrier config name as a backup. if (preferCcName || (TextUtils.isEmpty(getServiceProviderName()) && !TextUtils.isEmpty(ccName))) { setServiceProviderName(ccName); mTelephonyManager.setSimOperatorNameForPhone(phoneId, ccName); } updateCarrierNameForSubscription(subCon, subId); } private void updateCarrierNameForSubscription(SubscriptionController subCon, int subId) { /* update display name with carrier override */ SubscriptionInfo subInfo = subCon.getActiveSubscriptionInfo( subId, mContext.getOpPackageName()); if (subInfo == null || subInfo.getNameSource() == SubscriptionManager.NAME_SOURCE_USER_INPUT) { // either way, there is no subinfo to update return; } CharSequence oldSubName = subInfo.getDisplayName(); String newCarrierName = mTelephonyManager.getSimOperatorName(subId); if (!TextUtils.isEmpty(newCarrierName) && !newCarrierName.equals(oldSubName)) { log("sim name[" + mParentApp.getPhoneId() + "] = " + newCarrierName); subCon.setDisplayName(newCarrierName, subId); } } private void setVoiceMailByCountry (String spn) { if (mVmConfig.containsCarrier(spn)) { mIsVoiceMailFixed = true; Loading src/java/com/android/internal/telephony/uicc/UiccProfile.java +95 −20 Original line number Diff line number Diff line Loading @@ -18,9 +18,11 @@ package com.android.internal.telephony.uicc; import android.app.AlertDialog; import android.app.usage.UsageStatsManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; Loading Loading @@ -102,25 +104,23 @@ public class UiccProfile extends Handler implements IccCard { private RegistrantList mCarrierPrivilegeRegistrants = new RegistrantList(); private static final int EVENT_OPEN_LOGICAL_CHANNEL_DONE = 15; private static final int EVENT_CLOSE_LOGICAL_CHANNEL_DONE = 16; private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 17; private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 18; private static final int EVENT_SIM_IO_DONE = 19; private static final int EVENT_CARRIER_PRIVILEGES_LOADED = 20; private final int mPhoneId; /*----------------------------------------------------*/ // logic moved over from IccCardProxy private static final int EVENT_RADIO_OFF_OR_UNAVAILABLE = 1; private static final int EVENT_ICC_LOCKED = 5; private static final int EVENT_APP_READY = 6; private static final int EVENT_RECORDS_LOADED = 7; private static final int EVENT_NETWORK_LOCKED = 9; private static final int EVENT_EID_READY = 10; private static final int EVENT_ICC_RECORD_EVENTS = 500; private static final int EVENT_ICC_LOCKED = 2; @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) public static final int EVENT_APP_READY = 3; private static final int EVENT_RECORDS_LOADED = 4; private static final int EVENT_NETWORK_LOCKED = 5; private static final int EVENT_EID_READY = 6; private static final int EVENT_ICC_RECORD_EVENTS = 7; private static final int EVENT_OPEN_LOGICAL_CHANNEL_DONE = 8; private static final int EVENT_CLOSE_LOGICAL_CHANNEL_DONE = 9; private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 10; private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 11; private static final int EVENT_SIM_IO_DONE = 12; private static final int EVENT_CARRIER_PRIVILEGES_LOADED = 13; private static final int EVENT_CARRIER_CONFIG_CHANGED = 14; private TelephonyManager mTelephonyManager; Loading @@ -131,7 +131,15 @@ public class UiccProfile extends Handler implements IccCard { private IccRecords mIccRecords = null; private IccCardConstants.State mExternalState = IccCardConstants.State.UNKNOWN; /*----------------------------------------------------*/ private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) { sendMessage(obtainMessage(EVENT_CARRIER_CONFIG_CHANGED)); } } }; public UiccProfile(Context c, CommandsInterface ci, IccCardStatus ics, int phoneId, UiccCard uiccCard) { Loading @@ -152,6 +160,10 @@ public class UiccProfile extends Handler implements IccCard { update(c, ci, ics); ci.registerForOffOrNotAvailable(this, EVENT_RADIO_OFF_OR_UNAVAILABLE, null); resetProperties(); IntentFilter intentfilter = new IntentFilter(); intentfilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); c.registerReceiver(mReceiver, intentfilter); } /** Loading @@ -169,6 +181,7 @@ public class UiccProfile extends Handler implements IccCard { } mCi.unregisterForOffOrNotAvailable(this); mContext.unregisterReceiver(mReceiver); if (mCatService != null) mCatService.dispose(); for (UiccCardApplication app : mUiccApplications) { Loading Loading @@ -253,6 +266,10 @@ public class UiccProfile extends Handler implements IccCard { updateExternalState(); break; case EVENT_CARRIER_CONFIG_CHANGED: handleCarrierNameOverride(); break; case EVENT_OPEN_LOGICAL_CHANNEL_DONE: case EVENT_CLOSE_LOGICAL_CHANNEL_DONE: case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: Loading @@ -273,6 +290,64 @@ public class UiccProfile extends Handler implements IccCard { } } /** * Override the carrier name with either carrier config or SPN * if an override is provided. */ private void handleCarrierNameOverride() { SubscriptionController subCon = SubscriptionController.getInstance(); final int subId = subCon.getSubIdUsingPhoneId(mPhoneId); if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { loge("subId not valid for Phone " + mPhoneId); return; } CarrierConfigManager configLoader = (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE); if (configLoader == null) { loge("Failed to load a Carrier Config"); return; } PersistableBundle config = configLoader.getConfigForSubId(subId); boolean preferCcName = config.getBoolean( CarrierConfigManager.KEY_CARRIER_NAME_OVERRIDE_BOOL, false); String ccName = config.getString(CarrierConfigManager.KEY_CARRIER_NAME_STRING); // If carrier config is priority, use it regardless - the preference // and the name were both set by the carrier, so this is safe; // otherwise, if the SPN is priority but we don't have one *and* we have // a name in carrier config, use the carrier config name as a backup. if (preferCcName || (TextUtils.isEmpty(getServiceProviderName()) && !TextUtils.isEmpty(ccName))) { if (mIccRecords != null) { mIccRecords.setServiceProviderName(ccName); } mTelephonyManager.setSimOperatorNameForPhone(mPhoneId, ccName); } updateCarrierNameForSubscription(subCon, subId); } private void updateCarrierNameForSubscription(SubscriptionController subCon, int subId) { /* update display name with carrier override */ SubscriptionInfo subInfo = subCon.getActiveSubscriptionInfo( subId, mContext.getOpPackageName()); if (subInfo == null || subInfo.getNameSource() == SubscriptionManager.NAME_SOURCE_USER_INPUT) { // either way, there is no subinfo to update return; } CharSequence oldSubName = subInfo.getDisplayName(); String newCarrierName = mTelephonyManager.getSimOperatorName(subId); if (!TextUtils.isEmpty(newCarrierName) && !newCarrierName.equals(oldSubName)) { log("sim name[" + mPhoneId + "] = " + newCarrierName); subCon.setDisplayName(newCarrierName, subId); } } private void updateIccAvailability(boolean allAppsChanged) { synchronized (mLock) { UiccCardApplication newApp; Loading Loading @@ -487,7 +562,7 @@ public class UiccProfile extends Handler implements IccCard { // Update the MCC/MNC. if (mIccRecords != null) { String operator = mIccRecords.getOperatorNumeric(); log("operator=" + operator + " mPhoneId=" + mPhoneId); log("setExternalState: operator=" + operator + " mPhoneId=" + mPhoneId); if (!TextUtils.isEmpty(operator)) { mTelephonyManager.setSimOperatorNumericForPhone(mPhoneId, operator); Loading @@ -496,10 +571,10 @@ public class UiccProfile extends Handler implements IccCard { mTelephonyManager.setSimCountryIsoForPhone(mPhoneId, MccTable.countryCodeForMcc(Integer.parseInt(countryCode))); } else { loge("EVENT_RECORDS_LOADED Country code is null"); loge("setExternalState: state LOADED; Country code is null"); } } else { loge("EVENT_RECORDS_LOADED Operator name is null"); loge("setExternalState: state LOADED; Operator name is null"); } } } Loading tests/telephonytests/src/com/android/internal/telephony/uicc/UiccProfileTest.java +38 −7 Original line number Diff line number Diff line Loading @@ -29,10 +29,13 @@ import static org.mockito.Mockito.isA; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import android.content.Intent; import android.os.Handler; import android.os.HandlerThread; import android.os.Message; import android.os.PersistableBundle; import android.support.test.filters.SmallTest; import android.telephony.CarrierConfigManager; import com.android.internal.telephony.IccCardConstants.State; import com.android.internal.telephony.TelephonyTest; Loading @@ -52,8 +55,6 @@ public class UiccProfileTest extends TelephonyTest { } private IccIoResult mIccIoResult; // Must match UiccProfile.EVENT_APP_READY private static final int EVENT_APP_READY = 6; private static final int SCARY_SLEEP_MS = 200; private UiccProfileHandlerThread mTestHandlerThread; Loading Loading @@ -285,7 +286,7 @@ public class UiccProfileTest extends TelephonyTest { waitForMs(50); assertEquals(3, mUiccProfile.getNumApplications()); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(EVENT_APP_READY)); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(UiccProfile.EVENT_APP_READY)); waitForMs(SCARY_SLEEP_MS); assertEquals(mUiccProfile.getState(), State.NOT_READY); } Loading Loading @@ -317,7 +318,7 @@ public class UiccProfileTest extends TelephonyTest { waitForMs(50); assertEquals(3, mUiccProfile.getNumApplications()); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(EVENT_APP_READY)); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(UiccProfile.EVENT_APP_READY)); waitForMs(SCARY_SLEEP_MS); // state is loaded as all records are loaded right away as SimulatedCommands returns // response for them right away. Ideally applications and records should be mocked. Loading Loading @@ -351,7 +352,7 @@ public class UiccProfileTest extends TelephonyTest { waitForMs(50); assertEquals(3, mUiccProfile.getNumApplications()); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(EVENT_APP_READY)); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(UiccProfile.EVENT_APP_READY)); waitForMs(SCARY_SLEEP_MS); // state is loaded as all records are loaded right away as SimulatedCommands returns // response for them right away. Ideally applications and records should be mocked. Loading @@ -375,7 +376,7 @@ public class UiccProfileTest extends TelephonyTest { waitForMs(50); assertEquals(0, mUiccProfile.getNumApplications()); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(EVENT_APP_READY)); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(UiccProfile.EVENT_APP_READY)); waitForMs(SCARY_SLEEP_MS); // state is loaded since there is no applications. assertEquals(State.NOT_READY, mUiccProfile.getState()); Loading @@ -401,7 +402,7 @@ public class UiccProfileTest extends TelephonyTest { waitForMs(50); assertEquals(1, mUiccProfile.getNumApplications()); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(EVENT_APP_READY)); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(UiccProfile.EVENT_APP_READY)); waitForMs(SCARY_SLEEP_MS); // state is loaded since there is no applications. assertEquals(State.NOT_READY, mUiccProfile.getState()); Loading Loading @@ -430,4 +431,34 @@ public class UiccProfileTest extends TelephonyTest { mUiccProfile.updateExternalState(); assertEquals(State.LOADED, mUiccProfile.getState()); } @Test @SmallTest public void testCarrierConfigHandling() { testUpdateUiccProfileApplication(); // Fake carrier name String fakeCarrierName = "fakeCarrierName"; PersistableBundle carrierConfigBundle = mContextFixture.getCarrierConfigBundle(); carrierConfigBundle.putBoolean(CarrierConfigManager.KEY_CARRIER_NAME_OVERRIDE_BOOL, true); carrierConfigBundle.putString(CarrierConfigManager.KEY_CARRIER_NAME_STRING, fakeCarrierName); // broadcast CARRIER_CONFIG_CHANGED mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); waitForMs(200); // verify that setSimOperatorNameForPhone() is called with fakeCarrierName ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class); verify(mTelephonyManager, atLeast(1)).setSimOperatorNameForPhone(anyInt(), stringArgumentCaptor.capture()); boolean carrierFound = false; for (String carrierName : stringArgumentCaptor.getAllValues()) { if (fakeCarrierName.equals(carrierName)) { carrierFound = true; break; } } assertTrue(carrierFound); } } Loading
src/java/com/android/internal/telephony/uicc/SIMRecords.java +0 −80 Original line number Diff line number Diff line Loading @@ -16,10 +16,7 @@ package com.android.internal.telephony.uicc; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.res.Resources; import android.os.AsyncResult; import android.os.Message; Loading @@ -30,7 +27,6 @@ import android.telephony.Rlog; import android.telephony.ServiceState; import android.telephony.SmsMessage; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.text.TextUtils; import com.android.internal.telephony.CommandsInterface; Loading Loading @@ -172,7 +168,6 @@ public class SIMRecords extends IccRecords { // TODO: Possibly move these to IccRecords.java private static final int SYSTEM_EVENT_BASE = 0x100; private static final int EVENT_CARRIER_CONFIG_CHANGED = 1 + SYSTEM_EVENT_BASE; private static final int EVENT_APP_LOCKED = 2 + SYSTEM_EVENT_BASE; private static final int EVENT_APP_NETWORK_LOCKED = 3 + SYSTEM_EVENT_BASE; Loading Loading @@ -225,20 +220,7 @@ public class SIMRecords extends IccRecords { mParentApp.registerForLocked(this, EVENT_APP_LOCKED, null); mParentApp.registerForNetworkLocked(this, EVENT_APP_NETWORK_LOCKED, null); if (DBG) log("SIMRecords X ctor this=" + this); IntentFilter intentfilter = new IntentFilter(); intentfilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); c.registerReceiver(mReceiver, intentfilter); } private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) { sendMessage(obtainMessage(EVENT_CARRIER_CONFIG_CHANGED)); } } }; @Override public void dispose() { Loading @@ -248,7 +230,6 @@ public class SIMRecords extends IccRecords { mParentApp.unregisterForReady(this); mParentApp.unregisterForLocked(this); mParentApp.unregisterForNetworkLocked(this); mContext.unregisterReceiver(mReceiver); resetRecords(); super.dispose(); } Loading Loading @@ -1365,10 +1346,6 @@ public class SIMRecords extends IccRecords { } break; case EVENT_CARRIER_CONFIG_CHANGED: handleCarrierNameOverride(); break; default: super.handleMessage(msg); // IccRecords handles generic record load responses } Loading Loading @@ -1607,63 +1584,6 @@ public class SIMRecords extends IccRecords { //***** Private methods /** * Override the carrier name with either carrier config or SPN * if an override is provided. */ private void handleCarrierNameOverride() { final int phoneId = mParentApp.getPhoneId(); SubscriptionController subCon = SubscriptionController.getInstance(); final int subId = subCon.getSubIdUsingPhoneId(phoneId); if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { loge("subId not valid for Phone " + phoneId); return; } CarrierConfigManager configLoader = (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE); if (configLoader == null) { loge("Failed to load a Carrier Config"); return; } PersistableBundle config = configLoader.getConfigForSubId(subId); boolean preferCcName = config.getBoolean( CarrierConfigManager.KEY_CARRIER_NAME_OVERRIDE_BOOL, false); String ccName = config.getString(CarrierConfigManager.KEY_CARRIER_NAME_STRING); // If carrier config is priority, use it regardless - the preference // and the name were both set by the carrier, so this is safe; // otherwise, if the SPN is priority but we don't have one *and* we have // a name in carrier config, use the carrier config name as a backup. if (preferCcName || (TextUtils.isEmpty(getServiceProviderName()) && !TextUtils.isEmpty(ccName))) { setServiceProviderName(ccName); mTelephonyManager.setSimOperatorNameForPhone(phoneId, ccName); } updateCarrierNameForSubscription(subCon, subId); } private void updateCarrierNameForSubscription(SubscriptionController subCon, int subId) { /* update display name with carrier override */ SubscriptionInfo subInfo = subCon.getActiveSubscriptionInfo( subId, mContext.getOpPackageName()); if (subInfo == null || subInfo.getNameSource() == SubscriptionManager.NAME_SOURCE_USER_INPUT) { // either way, there is no subinfo to update return; } CharSequence oldSubName = subInfo.getDisplayName(); String newCarrierName = mTelephonyManager.getSimOperatorName(subId); if (!TextUtils.isEmpty(newCarrierName) && !newCarrierName.equals(oldSubName)) { log("sim name[" + mParentApp.getPhoneId() + "] = " + newCarrierName); subCon.setDisplayName(newCarrierName, subId); } } private void setVoiceMailByCountry (String spn) { if (mVmConfig.containsCarrier(spn)) { mIsVoiceMailFixed = true; Loading
src/java/com/android/internal/telephony/uicc/UiccProfile.java +95 −20 Original line number Diff line number Diff line Loading @@ -18,9 +18,11 @@ package com.android.internal.telephony.uicc; import android.app.AlertDialog; import android.app.usage.UsageStatsManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; Loading Loading @@ -102,25 +104,23 @@ public class UiccProfile extends Handler implements IccCard { private RegistrantList mCarrierPrivilegeRegistrants = new RegistrantList(); private static final int EVENT_OPEN_LOGICAL_CHANNEL_DONE = 15; private static final int EVENT_CLOSE_LOGICAL_CHANNEL_DONE = 16; private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 17; private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 18; private static final int EVENT_SIM_IO_DONE = 19; private static final int EVENT_CARRIER_PRIVILEGES_LOADED = 20; private final int mPhoneId; /*----------------------------------------------------*/ // logic moved over from IccCardProxy private static final int EVENT_RADIO_OFF_OR_UNAVAILABLE = 1; private static final int EVENT_ICC_LOCKED = 5; private static final int EVENT_APP_READY = 6; private static final int EVENT_RECORDS_LOADED = 7; private static final int EVENT_NETWORK_LOCKED = 9; private static final int EVENT_EID_READY = 10; private static final int EVENT_ICC_RECORD_EVENTS = 500; private static final int EVENT_ICC_LOCKED = 2; @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) public static final int EVENT_APP_READY = 3; private static final int EVENT_RECORDS_LOADED = 4; private static final int EVENT_NETWORK_LOCKED = 5; private static final int EVENT_EID_READY = 6; private static final int EVENT_ICC_RECORD_EVENTS = 7; private static final int EVENT_OPEN_LOGICAL_CHANNEL_DONE = 8; private static final int EVENT_CLOSE_LOGICAL_CHANNEL_DONE = 9; private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 10; private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 11; private static final int EVENT_SIM_IO_DONE = 12; private static final int EVENT_CARRIER_PRIVILEGES_LOADED = 13; private static final int EVENT_CARRIER_CONFIG_CHANGED = 14; private TelephonyManager mTelephonyManager; Loading @@ -131,7 +131,15 @@ public class UiccProfile extends Handler implements IccCard { private IccRecords mIccRecords = null; private IccCardConstants.State mExternalState = IccCardConstants.State.UNKNOWN; /*----------------------------------------------------*/ private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) { sendMessage(obtainMessage(EVENT_CARRIER_CONFIG_CHANGED)); } } }; public UiccProfile(Context c, CommandsInterface ci, IccCardStatus ics, int phoneId, UiccCard uiccCard) { Loading @@ -152,6 +160,10 @@ public class UiccProfile extends Handler implements IccCard { update(c, ci, ics); ci.registerForOffOrNotAvailable(this, EVENT_RADIO_OFF_OR_UNAVAILABLE, null); resetProperties(); IntentFilter intentfilter = new IntentFilter(); intentfilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); c.registerReceiver(mReceiver, intentfilter); } /** Loading @@ -169,6 +181,7 @@ public class UiccProfile extends Handler implements IccCard { } mCi.unregisterForOffOrNotAvailable(this); mContext.unregisterReceiver(mReceiver); if (mCatService != null) mCatService.dispose(); for (UiccCardApplication app : mUiccApplications) { Loading Loading @@ -253,6 +266,10 @@ public class UiccProfile extends Handler implements IccCard { updateExternalState(); break; case EVENT_CARRIER_CONFIG_CHANGED: handleCarrierNameOverride(); break; case EVENT_OPEN_LOGICAL_CHANNEL_DONE: case EVENT_CLOSE_LOGICAL_CHANNEL_DONE: case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: Loading @@ -273,6 +290,64 @@ public class UiccProfile extends Handler implements IccCard { } } /** * Override the carrier name with either carrier config or SPN * if an override is provided. */ private void handleCarrierNameOverride() { SubscriptionController subCon = SubscriptionController.getInstance(); final int subId = subCon.getSubIdUsingPhoneId(mPhoneId); if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { loge("subId not valid for Phone " + mPhoneId); return; } CarrierConfigManager configLoader = (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE); if (configLoader == null) { loge("Failed to load a Carrier Config"); return; } PersistableBundle config = configLoader.getConfigForSubId(subId); boolean preferCcName = config.getBoolean( CarrierConfigManager.KEY_CARRIER_NAME_OVERRIDE_BOOL, false); String ccName = config.getString(CarrierConfigManager.KEY_CARRIER_NAME_STRING); // If carrier config is priority, use it regardless - the preference // and the name were both set by the carrier, so this is safe; // otherwise, if the SPN is priority but we don't have one *and* we have // a name in carrier config, use the carrier config name as a backup. if (preferCcName || (TextUtils.isEmpty(getServiceProviderName()) && !TextUtils.isEmpty(ccName))) { if (mIccRecords != null) { mIccRecords.setServiceProviderName(ccName); } mTelephonyManager.setSimOperatorNameForPhone(mPhoneId, ccName); } updateCarrierNameForSubscription(subCon, subId); } private void updateCarrierNameForSubscription(SubscriptionController subCon, int subId) { /* update display name with carrier override */ SubscriptionInfo subInfo = subCon.getActiveSubscriptionInfo( subId, mContext.getOpPackageName()); if (subInfo == null || subInfo.getNameSource() == SubscriptionManager.NAME_SOURCE_USER_INPUT) { // either way, there is no subinfo to update return; } CharSequence oldSubName = subInfo.getDisplayName(); String newCarrierName = mTelephonyManager.getSimOperatorName(subId); if (!TextUtils.isEmpty(newCarrierName) && !newCarrierName.equals(oldSubName)) { log("sim name[" + mPhoneId + "] = " + newCarrierName); subCon.setDisplayName(newCarrierName, subId); } } private void updateIccAvailability(boolean allAppsChanged) { synchronized (mLock) { UiccCardApplication newApp; Loading Loading @@ -487,7 +562,7 @@ public class UiccProfile extends Handler implements IccCard { // Update the MCC/MNC. if (mIccRecords != null) { String operator = mIccRecords.getOperatorNumeric(); log("operator=" + operator + " mPhoneId=" + mPhoneId); log("setExternalState: operator=" + operator + " mPhoneId=" + mPhoneId); if (!TextUtils.isEmpty(operator)) { mTelephonyManager.setSimOperatorNumericForPhone(mPhoneId, operator); Loading @@ -496,10 +571,10 @@ public class UiccProfile extends Handler implements IccCard { mTelephonyManager.setSimCountryIsoForPhone(mPhoneId, MccTable.countryCodeForMcc(Integer.parseInt(countryCode))); } else { loge("EVENT_RECORDS_LOADED Country code is null"); loge("setExternalState: state LOADED; Country code is null"); } } else { loge("EVENT_RECORDS_LOADED Operator name is null"); loge("setExternalState: state LOADED; Operator name is null"); } } } Loading
tests/telephonytests/src/com/android/internal/telephony/uicc/UiccProfileTest.java +38 −7 Original line number Diff line number Diff line Loading @@ -29,10 +29,13 @@ import static org.mockito.Mockito.isA; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import android.content.Intent; import android.os.Handler; import android.os.HandlerThread; import android.os.Message; import android.os.PersistableBundle; import android.support.test.filters.SmallTest; import android.telephony.CarrierConfigManager; import com.android.internal.telephony.IccCardConstants.State; import com.android.internal.telephony.TelephonyTest; Loading @@ -52,8 +55,6 @@ public class UiccProfileTest extends TelephonyTest { } private IccIoResult mIccIoResult; // Must match UiccProfile.EVENT_APP_READY private static final int EVENT_APP_READY = 6; private static final int SCARY_SLEEP_MS = 200; private UiccProfileHandlerThread mTestHandlerThread; Loading Loading @@ -285,7 +286,7 @@ public class UiccProfileTest extends TelephonyTest { waitForMs(50); assertEquals(3, mUiccProfile.getNumApplications()); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(EVENT_APP_READY)); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(UiccProfile.EVENT_APP_READY)); waitForMs(SCARY_SLEEP_MS); assertEquals(mUiccProfile.getState(), State.NOT_READY); } Loading Loading @@ -317,7 +318,7 @@ public class UiccProfileTest extends TelephonyTest { waitForMs(50); assertEquals(3, mUiccProfile.getNumApplications()); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(EVENT_APP_READY)); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(UiccProfile.EVENT_APP_READY)); waitForMs(SCARY_SLEEP_MS); // state is loaded as all records are loaded right away as SimulatedCommands returns // response for them right away. Ideally applications and records should be mocked. Loading Loading @@ -351,7 +352,7 @@ public class UiccProfileTest extends TelephonyTest { waitForMs(50); assertEquals(3, mUiccProfile.getNumApplications()); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(EVENT_APP_READY)); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(UiccProfile.EVENT_APP_READY)); waitForMs(SCARY_SLEEP_MS); // state is loaded as all records are loaded right away as SimulatedCommands returns // response for them right away. Ideally applications and records should be mocked. Loading @@ -375,7 +376,7 @@ public class UiccProfileTest extends TelephonyTest { waitForMs(50); assertEquals(0, mUiccProfile.getNumApplications()); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(EVENT_APP_READY)); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(UiccProfile.EVENT_APP_READY)); waitForMs(SCARY_SLEEP_MS); // state is loaded since there is no applications. assertEquals(State.NOT_READY, mUiccProfile.getState()); Loading @@ -401,7 +402,7 @@ public class UiccProfileTest extends TelephonyTest { waitForMs(50); assertEquals(1, mUiccProfile.getNumApplications()); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(EVENT_APP_READY)); mUiccProfile.sendMessage(mUiccProfile.obtainMessage(UiccProfile.EVENT_APP_READY)); waitForMs(SCARY_SLEEP_MS); // state is loaded since there is no applications. assertEquals(State.NOT_READY, mUiccProfile.getState()); Loading Loading @@ -430,4 +431,34 @@ public class UiccProfileTest extends TelephonyTest { mUiccProfile.updateExternalState(); assertEquals(State.LOADED, mUiccProfile.getState()); } @Test @SmallTest public void testCarrierConfigHandling() { testUpdateUiccProfileApplication(); // Fake carrier name String fakeCarrierName = "fakeCarrierName"; PersistableBundle carrierConfigBundle = mContextFixture.getCarrierConfigBundle(); carrierConfigBundle.putBoolean(CarrierConfigManager.KEY_CARRIER_NAME_OVERRIDE_BOOL, true); carrierConfigBundle.putString(CarrierConfigManager.KEY_CARRIER_NAME_STRING, fakeCarrierName); // broadcast CARRIER_CONFIG_CHANGED mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); waitForMs(200); // verify that setSimOperatorNameForPhone() is called with fakeCarrierName ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class); verify(mTelephonyManager, atLeast(1)).setSimOperatorNameForPhone(anyInt(), stringArgumentCaptor.capture()); boolean carrierFound = false; for (String carrierName : stringArgumentCaptor.getAllValues()) { if (fakeCarrierName.equals(carrierName)) { carrierFound = true; break; } } assertTrue(carrierFound); } }