Using ACTION_SIM_CARD_STATE_CHANGED to detect simSlotMapping is complete
Sometime modem can't return the GET_SIM_STATUS immediately, so that the settings send the sim switching too early after simSlotMapping.
Bug: 291733084
Change-Id: If547c8b02020bc86c83915334e29945176a4ee9f
Test: tester will test it manually.
(cherry picked from commit ba2a86ad9f
)
This commit is contained in:
@@ -58,22 +58,29 @@ public class UiccSlotUtil {
|
|||||||
public static final int INVALID_PORT_ID = -1;
|
public static final int INVALID_PORT_ID = -1;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static class SimSlotChangeReceiver extends BroadcastReceiver{
|
static class SimCardStateChangeReceiver extends BroadcastReceiver{
|
||||||
private final CountDownLatch mLatch;
|
private final CountDownLatch mLatch;
|
||||||
SimSlotChangeReceiver(CountDownLatch latch) {
|
SimCardStateChangeReceiver(CountDownLatch latch) {
|
||||||
mLatch = latch;
|
mLatch = latch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerOn(Context context) {
|
public void registerOn(Context context) {
|
||||||
context.registerReceiver(this,
|
context.registerReceiver(this,
|
||||||
new IntentFilter(TelephonyManager.ACTION_SIM_SLOT_STATUS_CHANGED),
|
new IntentFilter(TelephonyManager.ACTION_SIM_CARD_STATE_CHANGED),
|
||||||
Context.RECEIVER_EXPORTED/*UNAUDITED*/);
|
Context.RECEIVER_NOT_EXPORTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Log.i(TAG, "Action: " + intent.getAction());
|
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();
|
mLatch.countDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -269,8 +276,8 @@ public class UiccSlotUtil {
|
|||||||
try {
|
try {
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
if (isMultipleEnabledProfilesSupported(telMgr)) {
|
if (isMultipleEnabledProfilesSupported(telMgr)) {
|
||||||
receiver = new SimSlotChangeReceiver(latch);
|
receiver = new SimCardStateChangeReceiver(latch);
|
||||||
((SimSlotChangeReceiver) receiver).registerOn(context);
|
((SimCardStateChangeReceiver) receiver).registerOn(context);
|
||||||
} else {
|
} else {
|
||||||
receiver = new CarrierConfigChangedReceiver(latch);
|
receiver = new CarrierConfigChangedReceiver(latch);
|
||||||
((CarrierConfigChangedReceiver) receiver).registerOn(context);
|
((CarrierConfigChangedReceiver) receiver).registerOn(context);
|
||||||
|
@@ -752,11 +752,14 @@ public class UiccSlotUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onReceiveSimSlotChangeReceiver_receiveAction_timerCountDown() {
|
public void onReceiveSimCardStateChangeReceiver_receiveAction_timerCountDown() {
|
||||||
CountDownLatch latch = spy(new CountDownLatch(1));
|
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();
|
verify(latch).countDown();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user