[Settings] Update EID in background
Access EID in background thread to avoid blocking UI. Bug: 153407357 Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=SimStatusDialogControllerTest Merged-In: Id30851bbd0b0fe080ed703586f9718be8b97abdd Change-Id: I23fc6168d939bb5cb5e281413462176e7221819c
This commit is contained in:
@@ -60,9 +60,11 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
|
|||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||||
|
import com.android.settingslib.utils.ThreadUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
public class SimStatusDialogController implements LifecycleObserver, OnResume, OnPause {
|
public class SimStatusDialogController implements LifecycleObserver, OnResume, OnPause {
|
||||||
|
|
||||||
@@ -220,7 +222,7 @@ public class SimStatusDialogController implements LifecycleObserver, OnResume, O
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
updateEid();
|
requestForUpdateEid();
|
||||||
|
|
||||||
if (mSubscriptionInfo == null) {
|
if (mSubscriptionInfo == null) {
|
||||||
return;
|
return;
|
||||||
@@ -539,25 +541,33 @@ public class SimStatusDialogController implements LifecycleObserver, OnResume, O
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateEid() {
|
@VisibleForTesting
|
||||||
|
void requestForUpdateEid() {
|
||||||
|
ThreadUtils.postOnBackgroundThread(() -> {
|
||||||
|
final AtomicReference<String> eid = getEid(mSlotIndex);
|
||||||
|
ThreadUtils.postOnMainThread(() -> updateEid(eid));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
AtomicReference<String> getEid(int slotIndex) {
|
||||||
boolean shouldHaveEid = false;
|
boolean shouldHaveEid = false;
|
||||||
String eid = null;
|
String eid = null;
|
||||||
|
|
||||||
if (mTelephonyManager.getActiveModemCount() > MAX_PHONE_COUNT_SINGLE_SIM) {
|
if (mTelephonyManager.getActiveModemCount() > MAX_PHONE_COUNT_SINGLE_SIM) {
|
||||||
// Get EID per-SIM in multi-SIM mode
|
// Get EID per-SIM in multi-SIM mode
|
||||||
Map<Integer, Integer> mapping = mTelephonyManager.getLogicalToPhysicalSlotMapping();
|
final Map<Integer, Integer> mapping = mTelephonyManager
|
||||||
int pSlotId = mapping.getOrDefault(mSlotIndex,
|
.getLogicalToPhysicalSlotMapping();
|
||||||
|
final int pSlotId = mapping.getOrDefault(slotIndex,
|
||||||
SubscriptionManager.INVALID_SIM_SLOT_INDEX);
|
SubscriptionManager.INVALID_SIM_SLOT_INDEX);
|
||||||
|
|
||||||
if (pSlotId != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
|
if (pSlotId != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
|
||||||
List<UiccCardInfo> infos = mTelephonyManager.getUiccCardsInfo();
|
final List<UiccCardInfo> infos = mTelephonyManager.getUiccCardsInfo();
|
||||||
|
|
||||||
for (UiccCardInfo info : infos) {
|
for (UiccCardInfo info : infos) {
|
||||||
if (info.getSlotIndex() == pSlotId) {
|
if (info.getSlotIndex() == pSlotId) {
|
||||||
if (info.isEuicc()) {
|
if (info.isEuicc()) {
|
||||||
shouldHaveEid = true;
|
shouldHaveEid = true;
|
||||||
eid = info.getEid();
|
eid = info.getEid();
|
||||||
|
|
||||||
if (TextUtils.isEmpty(eid)) {
|
if (TextUtils.isEmpty(eid)) {
|
||||||
eid = mEuiccManager.createForCardId(info.getCardId()).getEid();
|
eid = mEuiccManager.createForCardId(info.getCardId()).getEid();
|
||||||
}
|
}
|
||||||
@@ -571,12 +581,19 @@ public class SimStatusDialogController implements LifecycleObserver, OnResume, O
|
|||||||
shouldHaveEid = true;
|
shouldHaveEid = true;
|
||||||
eid = mEuiccManager.getEid();
|
eid = mEuiccManager.getEid();
|
||||||
}
|
}
|
||||||
|
if ((!shouldHaveEid) && (eid == null)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new AtomicReference<String>(eid);
|
||||||
|
}
|
||||||
|
|
||||||
if (!shouldHaveEid) {
|
@VisibleForTesting
|
||||||
|
void updateEid(AtomicReference<String> eid) {
|
||||||
|
if (eid == null) {
|
||||||
mDialog.removeSettingFromScreen(EID_INFO_LABEL_ID);
|
mDialog.removeSettingFromScreen(EID_INFO_LABEL_ID);
|
||||||
mDialog.removeSettingFromScreen(EID_INFO_VALUE_ID);
|
mDialog.removeSettingFromScreen(EID_INFO_VALUE_ID);
|
||||||
} else if (!TextUtils.isEmpty(eid)) {
|
} else if (eid.get() != null) {
|
||||||
mDialog.setText(EID_INFO_VALUE_ID, eid);
|
mDialog.setText(EID_INFO_VALUE_ID, eid.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,6 +38,7 @@ import static com.android.settings.deviceinfo.simstatus.SimStatusDialogControlle
|
|||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.doNothing;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
@@ -452,6 +453,8 @@ public class SimStatusDialogControllerTest {
|
|||||||
when(mEuiccManager.isEnabled()).thenReturn(true);
|
when(mEuiccManager.isEnabled()).thenReturn(true);
|
||||||
when(mEuiccManager.getEid()).thenReturn(null);
|
when(mEuiccManager.getEid()).thenReturn(null);
|
||||||
|
|
||||||
|
doNothing().when(mController).requestForUpdateEid();
|
||||||
|
mController.updateEid(mController.getEid(0));
|
||||||
mController.initialize();
|
mController.initialize();
|
||||||
|
|
||||||
// Keep 'Not available' if neither the card nor the associated manager can provide EID.
|
// Keep 'Not available' if neither the card nor the associated manager can provide EID.
|
||||||
@@ -489,7 +492,10 @@ public class SimStatusDialogControllerTest {
|
|||||||
|
|
||||||
when(mEuiccManager.isEnabled()).thenReturn(true);
|
when(mEuiccManager.isEnabled()).thenReturn(true);
|
||||||
when(mEuiccManager.getEid()).thenReturn(TEST_EID_FROM_MANAGER);
|
when(mEuiccManager.getEid()).thenReturn(TEST_EID_FROM_MANAGER);
|
||||||
|
when(mEuiccManager.createForCardId(0)).thenReturn(mEuiccManager);
|
||||||
|
|
||||||
|
doNothing().when(mController).requestForUpdateEid();
|
||||||
|
mController.updateEid(mController.getEid(0));
|
||||||
mController.initialize();
|
mController.initialize();
|
||||||
|
|
||||||
// Set EID retrieved from the card.
|
// Set EID retrieved from the card.
|
||||||
@@ -531,6 +537,8 @@ public class SimStatusDialogControllerTest {
|
|||||||
new RuntimeException("Unexpected card ID was specified"));
|
new RuntimeException("Unexpected card ID was specified"));
|
||||||
when(mEuiccManager.createForCardId(1)).thenReturn(mEuiccManager);
|
when(mEuiccManager.createForCardId(1)).thenReturn(mEuiccManager);
|
||||||
|
|
||||||
|
doNothing().when(mController).requestForUpdateEid();
|
||||||
|
mController.updateEid(mController.getEid(0));
|
||||||
mController.initialize();
|
mController.initialize();
|
||||||
|
|
||||||
// Set EID retrieved from the manager associated with the card which cannot provide EID.
|
// Set EID retrieved from the manager associated with the card which cannot provide EID.
|
||||||
@@ -569,6 +577,8 @@ public class SimStatusDialogControllerTest {
|
|||||||
when(mEuiccManager.isEnabled()).thenReturn(true);
|
when(mEuiccManager.isEnabled()).thenReturn(true);
|
||||||
when(mEuiccManager.getEid()).thenReturn(TEST_EID_FROM_MANAGER);
|
when(mEuiccManager.getEid()).thenReturn(TEST_EID_FROM_MANAGER);
|
||||||
|
|
||||||
|
doNothing().when(mController).requestForUpdateEid();
|
||||||
|
mController.updateEid(mController.getEid(0));
|
||||||
mController.initialize();
|
mController.initialize();
|
||||||
|
|
||||||
// Remove EID if the card is not eUICC.
|
// Remove EID if the card is not eUICC.
|
||||||
@@ -599,6 +609,8 @@ public class SimStatusDialogControllerTest {
|
|||||||
when(mEuiccManager.isEnabled()).thenReturn(true);
|
when(mEuiccManager.isEnabled()).thenReturn(true);
|
||||||
when(mEuiccManager.getEid()).thenReturn(null);
|
when(mEuiccManager.getEid()).thenReturn(null);
|
||||||
|
|
||||||
|
doNothing().when(mController).requestForUpdateEid();
|
||||||
|
mController.updateEid(mController.getEid(0));
|
||||||
mController.initialize();
|
mController.initialize();
|
||||||
|
|
||||||
// Keep 'Not available' if the default eUICC manager cannot provide EID in Single SIM mode.
|
// Keep 'Not available' if the default eUICC manager cannot provide EID in Single SIM mode.
|
||||||
@@ -630,6 +642,8 @@ public class SimStatusDialogControllerTest {
|
|||||||
when(mEuiccManager.createForCardId(anyInt())).thenThrow(
|
when(mEuiccManager.createForCardId(anyInt())).thenThrow(
|
||||||
new RuntimeException("EID shall be retrieved from the default eUICC manager"));
|
new RuntimeException("EID shall be retrieved from the default eUICC manager"));
|
||||||
|
|
||||||
|
doNothing().when(mController).requestForUpdateEid();
|
||||||
|
mController.updateEid(mController.getEid(0));
|
||||||
mController.initialize();
|
mController.initialize();
|
||||||
|
|
||||||
// Set EID retrieved from the default eUICC manager in Single SIM mode.
|
// Set EID retrieved from the default eUICC manager in Single SIM mode.
|
||||||
@@ -661,6 +675,8 @@ public class SimStatusDialogControllerTest {
|
|||||||
when(mEuiccManager.createForCardId(anyInt())).thenThrow(
|
when(mEuiccManager.createForCardId(anyInt())).thenThrow(
|
||||||
new RuntimeException("EID shall be retrieved from the default eUICC manager"));
|
new RuntimeException("EID shall be retrieved from the default eUICC manager"));
|
||||||
|
|
||||||
|
doNothing().when(mController).requestForUpdateEid();
|
||||||
|
mController.updateEid(mController.getEid(0));
|
||||||
mController.initialize();
|
mController.initialize();
|
||||||
|
|
||||||
// Set EID retrieved from the default eUICC manager in Single SIM mode.
|
// Set EID retrieved from the default eUICC manager in Single SIM mode.
|
||||||
@@ -690,6 +706,8 @@ public class SimStatusDialogControllerTest {
|
|||||||
when(mEuiccManager.isEnabled()).thenReturn(false);
|
when(mEuiccManager.isEnabled()).thenReturn(false);
|
||||||
when(mEuiccManager.getEid()).thenReturn(null);
|
when(mEuiccManager.getEid()).thenReturn(null);
|
||||||
|
|
||||||
|
doNothing().when(mController).requestForUpdateEid();
|
||||||
|
mController.updateEid(mController.getEid(0));
|
||||||
mController.initialize();
|
mController.initialize();
|
||||||
|
|
||||||
// Remove EID if the default eUICC manager indicates that eSIM is not enabled.
|
// Remove EID if the default eUICC manager indicates that eSIM is not enabled.
|
||||||
|
Reference in New Issue
Block a user