Using ACTION_SIM_CARD_STATE_CHANGED to detect simSlotMapping is complete am: e51d8515c0

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/25809891

Change-Id: I0bed6503fbce6204b2da75f6dc25364148f1ce8b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
SongFerng Wang
2024-01-05 07:23:19 +00:00
committed by Automerger Merge Worker
2 changed files with 20 additions and 10 deletions

View File

@@ -58,22 +58,29 @@ public class UiccSlotUtil {
public static final int INVALID_PORT_ID = -1;
@VisibleForTesting
static class SimSlotChangeReceiver extends BroadcastReceiver{
static class SimCardStateChangeReceiver extends BroadcastReceiver{
private final CountDownLatch mLatch;
SimSlotChangeReceiver(CountDownLatch latch) {
SimCardStateChangeReceiver(CountDownLatch latch) {
mLatch = latch;
}
public void registerOn(Context context) {
context.registerReceiver(this,
new IntentFilter(TelephonyManager.ACTION_SIM_SLOT_STATUS_CHANGED),
Context.RECEIVER_EXPORTED/*UNAUDITED*/);
new IntentFilter(TelephonyManager.ACTION_SIM_CARD_STATE_CHANGED),
Context.RECEIVER_NOT_EXPORTED);
}
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "Action: " + intent.getAction());
if (TelephonyManager.ACTION_SIM_SLOT_STATUS_CHANGED.equals(intent.getAction())) {
if (!TelephonyManager.ACTION_SIM_CARD_STATE_CHANGED.equals(intent.getAction())) {
return;
}
final int simState = intent.getIntExtra(
TelephonyManager.EXTRA_SIM_STATE, TelephonyManager.SIM_STATE_UNKNOWN);
Log.i(TAG, "simState: " + simState);
if (simState != TelephonyManager.SIM_STATE_UNKNOWN
&& simState != TelephonyManager.SIM_STATE_ABSENT) {
mLatch.countDown();
}
}
@@ -269,8 +276,8 @@ public class UiccSlotUtil {
try {
CountDownLatch latch = new CountDownLatch(1);
if (isMultipleEnabledProfilesSupported(telMgr)) {
receiver = new SimSlotChangeReceiver(latch);
((SimSlotChangeReceiver) receiver).registerOn(context);
receiver = new SimCardStateChangeReceiver(latch);
((SimCardStateChangeReceiver) receiver).registerOn(context);
} else {
receiver = new CarrierConfigChangedReceiver(latch);
((CarrierConfigChangedReceiver) receiver).registerOn(context);

View File

@@ -752,11 +752,14 @@ public class UiccSlotUtilTest {
}
@Test
public void onReceiveSimSlotChangeReceiver_receiveAction_timerCountDown() {
public void onReceiveSimCardStateChangeReceiver_receiveAction_timerCountDown() {
CountDownLatch latch = spy(new CountDownLatch(1));
UiccSlotUtil.SimSlotChangeReceiver receive = new UiccSlotUtil.SimSlotChangeReceiver(latch);
UiccSlotUtil.SimCardStateChangeReceiver receive =
new UiccSlotUtil.SimCardStateChangeReceiver(latch);
Intent intent = new Intent(TelephonyManager.ACTION_SIM_SLOT_STATUS_CHANGED);
intent.putExtra(TelephonyManager.EXTRA_SIM_STATE, TelephonyManager.SIM_STATE_PRESENT);
receive.onReceive(mContext, new Intent(TelephonyManager.ACTION_SIM_SLOT_STATUS_CHANGED));
receive.onReceive(mContext, intent);
verify(latch).countDown();
}