Loading src/java/com/android/internal/telephony/uicc/UiccProfile.java +52 −14 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static com.android.internal.telephony.TelephonyStatsLog.PIN_STORAGE_EVENT import static com.android.internal.telephony.TelephonyStatsLog.PIN_STORAGE_EVENT__EVENT__PIN_VERIFICATION_FAILURE; import static com.android.internal.telephony.TelephonyStatsLog.PIN_STORAGE_EVENT__EVENT__PIN_VERIFICATION_SUCCESS; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityManager; import android.app.usage.UsageStatsManager; Loading Loading @@ -125,6 +126,8 @@ public class UiccProfile extends IccCard { private final int mPhoneId; private final PinStorage mPinStorage; private final CarrierConfigManager mCarrierConfigManager; private static final int EVENT_RADIO_OFF_OR_UNAVAILABLE = 1; private static final int EVENT_ICC_LOCKED = 2; @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) Loading Loading @@ -185,11 +188,16 @@ public class UiccProfile extends IccCard { }; private boolean mUserUnlockReceiverRegistered; private final BroadcastReceiver mCarrierConfigChangedReceiver = new BroadcastReceiver() { private final CarrierConfigManager.CarrierConfigChangeListener mCarrierConfigChangeListener = new CarrierConfigManager.CarrierConfigChangeListener() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) { mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED)); public void onCarrierConfigChanged(int logicalSlotIndex, int subscriptionId, int carrierId, int specificCarrierId) { if (logicalSlotIndex == mPhoneId) { log("onCarrierConfigChanged: slotIndex=" + logicalSlotIndex + ", subId=" + subscriptionId + ", carrierId=" + carrierId); handleCarrierNameOverride(); handleSimCountryIsoOverride(); } } }; Loading Loading @@ -341,9 +349,10 @@ public class UiccProfile extends IccCard { ci.registerForOffOrNotAvailable(mHandler, EVENT_RADIO_OFF_OR_UNAVAILABLE, null); resetProperties(); IntentFilter intentfilter = new IntentFilter(); intentfilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); c.registerReceiver(mCarrierConfigChangedReceiver, intentfilter); mCarrierConfigManager = c.getSystemService(CarrierConfigManager.class); // Listener callback directly handles config change and thus runs on handler thread mCarrierConfigManager.registerCarrierConfigChangeListener(mHandler::post, mCarrierConfigChangeListener); } /** Loading Loading @@ -376,7 +385,11 @@ public class UiccProfile extends IccCard { InstallCarrierAppUtils.unregisterPackageInstallReceiver(mContext); mCi.unregisterForOffOrNotAvailable(mHandler); mContext.unregisterReceiver(mCarrierConfigChangedReceiver); if (mCarrierConfigManager != null && mCarrierConfigChangeListener != null) { mCarrierConfigManager.unregisterCarrierConfigChangeListener( mCarrierConfigChangeListener); } if (mCatService != null) mCatService.dispose(); for (UiccCardApplication app : mUiccApplications) { Loading Loading @@ -448,7 +461,15 @@ public class UiccProfile extends IccCard { return; } PersistableBundle config = configLoader.getConfigForSubId(subId); PersistableBundle config = getCarrierConfigSubset( subId, CarrierConfigManager.KEY_CARRIER_NAME_OVERRIDE_BOOL, CarrierConfigManager.KEY_CARRIER_NAME_STRING); if (config.isEmpty()) { loge("handleCarrierNameOverride: fail to get carrier configs."); return; } boolean preferCcName = config.getBoolean( CarrierConfigManager.KEY_CARRIER_NAME_OVERRIDE_BOOL, false); String ccName = config.getString(CarrierConfigManager.KEY_CARRIER_NAME_STRING); Loading Loading @@ -512,7 +533,13 @@ public class UiccProfile extends IccCard { return; } PersistableBundle config = configLoader.getConfigForSubId(subId); PersistableBundle config = getCarrierConfigSubset( subId, CarrierConfigManager.KEY_SIM_COUNTRY_ISO_OVERRIDE_STRING); if (config.isEmpty()) { loge("handleSimCountryIsoOverride: fail to get carrier configs."); return; } String iso = config.getString(CarrierConfigManager.KEY_SIM_COUNTRY_ISO_OVERRIDE_STRING); if (!TextUtils.isEmpty(iso) && !iso.equals(TelephonyManager.getSimCountryIsoForPhone(mPhoneId))) { Loading Loading @@ -1790,6 +1817,17 @@ public class UiccProfile extends IccCard { return null; } @NonNull private PersistableBundle getCarrierConfigSubset(int subId, String... keys) { PersistableBundle bundle = new PersistableBundle(); try { bundle = mCarrierConfigManager.getConfigForSubId(subId, keys); } catch (RuntimeException e) { loge("CarrierConfigLoader is not available."); } return bundle; } private static String eventToString(int event) { switch (event) { case EVENT_RADIO_OFF_OR_UNAVAILABLE: return "RADIO_OFF_OR_UNAVAILABLE"; Loading tests/telephonytests/src/com/android/internal/telephony/uicc/UiccProfileTest.java +18 −3 Original line number Diff line number Diff line Loading @@ -32,8 +32,8 @@ import static org.mockito.Mockito.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Intent; import android.content.pm.PackageManager; import android.os.Handler; import android.os.Message; Loading @@ -41,6 +41,7 @@ import android.os.PersistableBundle; import android.telephony.CarrierConfigManager; import android.telephony.ServiceState; import android.telephony.SubscriptionInfo; import android.telephony.TelephonyManager; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; Loading Loading @@ -71,6 +72,8 @@ public class UiccProfileTest extends TelephonyTest { } private IccIoResult mIccIoResult; private PersistableBundle mBundle; private CarrierConfigManager.CarrierConfigChangeListener mCarrierConfigChangeListener; private static final int UICCPROFILE_CARRIER_PRIVILEGE_LOADED_EVENT = 3; Loading Loading @@ -119,8 +122,18 @@ public class UiccProfileTest extends TelephonyTest { mIccCardStatus.mGsmUmtsSubscriptionAppIndex = -1; mIccIoResult = new IccIoResult(0x90, 0x00, IccUtils.hexStringToBytes("FF40")); mSimulatedCommands.setIccIoResultForApduLogicalChannel(mIccIoResult); mBundle = mContextFixture.getCarrierConfigBundle(); when(mCarrierConfigManager.getConfigForSubId(anyInt(), any())).thenReturn(mBundle); // Capture CarrierConfigChangeListener to emulate the carrier config change notification ArgumentCaptor<CarrierConfigManager.CarrierConfigChangeListener> listenerArgumentCaptor = ArgumentCaptor.forClass(CarrierConfigManager.CarrierConfigChangeListener.class); mUiccProfile = new UiccProfile(mContext, mSimulatedCommands, mIccCardStatus, 0 /* phoneId */, mUiccCard, new Object()); verify(mCarrierConfigManager).registerCarrierConfigChangeListener(any(), listenerArgumentCaptor.capture()); mCarrierConfigChangeListener = listenerArgumentCaptor.getAllValues().get(0); processAllMessages(); logd("Create UiccProfile"); Loading @@ -131,6 +144,7 @@ public class UiccProfileTest extends TelephonyTest { public void tearDown() throws Exception { mUiccProfile = null; mIccIoResult = null; mBundle = null; super.tearDown(); } Loading Loading @@ -536,8 +550,9 @@ public class UiccProfileTest extends TelephonyTest { carrierConfigBundle.putString(CarrierConfigManager.KEY_CARRIER_NAME_STRING, fakeCarrierName); // broadcast CARRIER_CONFIG_CHANGED mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); // send carrier config change mCarrierConfigChangeListener.onCarrierConfigChanged(mPhone.getPhoneId(), mPhone.getSubId(), TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); processAllMessages(); // verify that setSimOperatorNameForPhone() is called with fakeCarrierName Loading Loading
src/java/com/android/internal/telephony/uicc/UiccProfile.java +52 −14 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static com.android.internal.telephony.TelephonyStatsLog.PIN_STORAGE_EVENT import static com.android.internal.telephony.TelephonyStatsLog.PIN_STORAGE_EVENT__EVENT__PIN_VERIFICATION_FAILURE; import static com.android.internal.telephony.TelephonyStatsLog.PIN_STORAGE_EVENT__EVENT__PIN_VERIFICATION_SUCCESS; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityManager; import android.app.usage.UsageStatsManager; Loading Loading @@ -125,6 +126,8 @@ public class UiccProfile extends IccCard { private final int mPhoneId; private final PinStorage mPinStorage; private final CarrierConfigManager mCarrierConfigManager; private static final int EVENT_RADIO_OFF_OR_UNAVAILABLE = 1; private static final int EVENT_ICC_LOCKED = 2; @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) Loading Loading @@ -185,11 +188,16 @@ public class UiccProfile extends IccCard { }; private boolean mUserUnlockReceiverRegistered; private final BroadcastReceiver mCarrierConfigChangedReceiver = new BroadcastReceiver() { private final CarrierConfigManager.CarrierConfigChangeListener mCarrierConfigChangeListener = new CarrierConfigManager.CarrierConfigChangeListener() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) { mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED)); public void onCarrierConfigChanged(int logicalSlotIndex, int subscriptionId, int carrierId, int specificCarrierId) { if (logicalSlotIndex == mPhoneId) { log("onCarrierConfigChanged: slotIndex=" + logicalSlotIndex + ", subId=" + subscriptionId + ", carrierId=" + carrierId); handleCarrierNameOverride(); handleSimCountryIsoOverride(); } } }; Loading Loading @@ -341,9 +349,10 @@ public class UiccProfile extends IccCard { ci.registerForOffOrNotAvailable(mHandler, EVENT_RADIO_OFF_OR_UNAVAILABLE, null); resetProperties(); IntentFilter intentfilter = new IntentFilter(); intentfilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); c.registerReceiver(mCarrierConfigChangedReceiver, intentfilter); mCarrierConfigManager = c.getSystemService(CarrierConfigManager.class); // Listener callback directly handles config change and thus runs on handler thread mCarrierConfigManager.registerCarrierConfigChangeListener(mHandler::post, mCarrierConfigChangeListener); } /** Loading Loading @@ -376,7 +385,11 @@ public class UiccProfile extends IccCard { InstallCarrierAppUtils.unregisterPackageInstallReceiver(mContext); mCi.unregisterForOffOrNotAvailable(mHandler); mContext.unregisterReceiver(mCarrierConfigChangedReceiver); if (mCarrierConfigManager != null && mCarrierConfigChangeListener != null) { mCarrierConfigManager.unregisterCarrierConfigChangeListener( mCarrierConfigChangeListener); } if (mCatService != null) mCatService.dispose(); for (UiccCardApplication app : mUiccApplications) { Loading Loading @@ -448,7 +461,15 @@ public class UiccProfile extends IccCard { return; } PersistableBundle config = configLoader.getConfigForSubId(subId); PersistableBundle config = getCarrierConfigSubset( subId, CarrierConfigManager.KEY_CARRIER_NAME_OVERRIDE_BOOL, CarrierConfigManager.KEY_CARRIER_NAME_STRING); if (config.isEmpty()) { loge("handleCarrierNameOverride: fail to get carrier configs."); return; } boolean preferCcName = config.getBoolean( CarrierConfigManager.KEY_CARRIER_NAME_OVERRIDE_BOOL, false); String ccName = config.getString(CarrierConfigManager.KEY_CARRIER_NAME_STRING); Loading Loading @@ -512,7 +533,13 @@ public class UiccProfile extends IccCard { return; } PersistableBundle config = configLoader.getConfigForSubId(subId); PersistableBundle config = getCarrierConfigSubset( subId, CarrierConfigManager.KEY_SIM_COUNTRY_ISO_OVERRIDE_STRING); if (config.isEmpty()) { loge("handleSimCountryIsoOverride: fail to get carrier configs."); return; } String iso = config.getString(CarrierConfigManager.KEY_SIM_COUNTRY_ISO_OVERRIDE_STRING); if (!TextUtils.isEmpty(iso) && !iso.equals(TelephonyManager.getSimCountryIsoForPhone(mPhoneId))) { Loading Loading @@ -1790,6 +1817,17 @@ public class UiccProfile extends IccCard { return null; } @NonNull private PersistableBundle getCarrierConfigSubset(int subId, String... keys) { PersistableBundle bundle = new PersistableBundle(); try { bundle = mCarrierConfigManager.getConfigForSubId(subId, keys); } catch (RuntimeException e) { loge("CarrierConfigLoader is not available."); } return bundle; } private static String eventToString(int event) { switch (event) { case EVENT_RADIO_OFF_OR_UNAVAILABLE: return "RADIO_OFF_OR_UNAVAILABLE"; Loading
tests/telephonytests/src/com/android/internal/telephony/uicc/UiccProfileTest.java +18 −3 Original line number Diff line number Diff line Loading @@ -32,8 +32,8 @@ import static org.mockito.Mockito.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Intent; import android.content.pm.PackageManager; import android.os.Handler; import android.os.Message; Loading @@ -41,6 +41,7 @@ import android.os.PersistableBundle; import android.telephony.CarrierConfigManager; import android.telephony.ServiceState; import android.telephony.SubscriptionInfo; import android.telephony.TelephonyManager; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; Loading Loading @@ -71,6 +72,8 @@ public class UiccProfileTest extends TelephonyTest { } private IccIoResult mIccIoResult; private PersistableBundle mBundle; private CarrierConfigManager.CarrierConfigChangeListener mCarrierConfigChangeListener; private static final int UICCPROFILE_CARRIER_PRIVILEGE_LOADED_EVENT = 3; Loading Loading @@ -119,8 +122,18 @@ public class UiccProfileTest extends TelephonyTest { mIccCardStatus.mGsmUmtsSubscriptionAppIndex = -1; mIccIoResult = new IccIoResult(0x90, 0x00, IccUtils.hexStringToBytes("FF40")); mSimulatedCommands.setIccIoResultForApduLogicalChannel(mIccIoResult); mBundle = mContextFixture.getCarrierConfigBundle(); when(mCarrierConfigManager.getConfigForSubId(anyInt(), any())).thenReturn(mBundle); // Capture CarrierConfigChangeListener to emulate the carrier config change notification ArgumentCaptor<CarrierConfigManager.CarrierConfigChangeListener> listenerArgumentCaptor = ArgumentCaptor.forClass(CarrierConfigManager.CarrierConfigChangeListener.class); mUiccProfile = new UiccProfile(mContext, mSimulatedCommands, mIccCardStatus, 0 /* phoneId */, mUiccCard, new Object()); verify(mCarrierConfigManager).registerCarrierConfigChangeListener(any(), listenerArgumentCaptor.capture()); mCarrierConfigChangeListener = listenerArgumentCaptor.getAllValues().get(0); processAllMessages(); logd("Create UiccProfile"); Loading @@ -131,6 +144,7 @@ public class UiccProfileTest extends TelephonyTest { public void tearDown() throws Exception { mUiccProfile = null; mIccIoResult = null; mBundle = null; super.tearDown(); } Loading Loading @@ -536,8 +550,9 @@ public class UiccProfileTest extends TelephonyTest { carrierConfigBundle.putString(CarrierConfigManager.KEY_CARRIER_NAME_STRING, fakeCarrierName); // broadcast CARRIER_CONFIG_CHANGED mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); // send carrier config change mCarrierConfigChangeListener.onCarrierConfigChanged(mPhone.getPhoneId(), mPhone.getSubId(), TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); processAllMessages(); // verify that setSimOperatorNameForPhone() is called with fakeCarrierName Loading