Merge changes Idf0ce198,Ibd324b78,I6daa38f5,I242402e4
* changes: [MEP] Modify the comments Unable to enable the removable esim Reuse the active esim slot stop show preferred SIM card dialog during sim switch
This commit is contained in:
@@ -475,7 +475,7 @@ public class SubscriptionUtil {
|
|||||||
.stream()
|
.stream()
|
||||||
.filter(subInfo -> subInfo.getSubscriptionId() == subId)
|
.filter(subInfo -> subInfo.getSubscriptionId() == subId)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.get();
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -21,12 +21,18 @@ import android.app.PendingIntent;
|
|||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.UiccCardInfo;
|
import android.telephony.UiccCardInfo;
|
||||||
|
import android.telephony.UiccPortInfo;
|
||||||
|
import android.telephony.UiccSlotInfo;
|
||||||
|
import android.telephony.UiccSlotMapping;
|
||||||
import android.telephony.euicc.EuiccManager;
|
import android.telephony.euicc.EuiccManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.SidecarFragment;
|
import com.android.settings.SidecarFragment;
|
||||||
import com.android.settings.network.telephony.EuiccOperationSidecar;
|
import com.android.settings.network.telephony.EuiccOperationSidecar;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -42,6 +48,7 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
|
|||||||
private int mPort;
|
private int mPort;
|
||||||
private SubscriptionInfo mRemovedSubInfo;
|
private SubscriptionInfo mRemovedSubInfo;
|
||||||
private boolean mIsDuringSimSlotMapping;
|
private boolean mIsDuringSimSlotMapping;
|
||||||
|
private List<SubscriptionInfo> mActiveSubInfos;
|
||||||
|
|
||||||
/** Returns a SwitchToEuiccSubscriptionSidecar sidecar instance. */
|
/** Returns a SwitchToEuiccSubscriptionSidecar sidecar instance. */
|
||||||
public static SwitchToEuiccSubscriptionSidecar get(FragmentManager fm) {
|
public static SwitchToEuiccSubscriptionSidecar get(FragmentManager fm) {
|
||||||
@@ -85,6 +92,7 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
|
|||||||
setState(State.RUNNING, Substate.UNUSED);
|
setState(State.RUNNING, Substate.UNUSED);
|
||||||
mCallbackIntent = createCallbackIntent();
|
mCallbackIntent = createCallbackIntent();
|
||||||
mSubId = subscriptionId;
|
mSubId = subscriptionId;
|
||||||
|
|
||||||
int targetSlot = getTargetSlot();
|
int targetSlot = getTargetSlot();
|
||||||
if (targetSlot < 0) {
|
if (targetSlot < 0) {
|
||||||
Log.d(TAG, "There is no esim, the TargetSlot is " + targetSlot);
|
Log.d(TAG, "There is no esim, the TargetSlot is " + targetSlot);
|
||||||
@@ -92,20 +100,37 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SubscriptionManager subscriptionManager = getContext().getSystemService(
|
||||||
|
SubscriptionManager.class);
|
||||||
|
mActiveSubInfos = SubscriptionUtil.getActiveSubscriptions(subscriptionManager);
|
||||||
|
|
||||||
// To check whether the esim slot's port is active. If yes, skip setSlotMapping. If no,
|
// To check whether the esim slot's port is active. If yes, skip setSlotMapping. If no,
|
||||||
// set this slot+port into setSimSlotMapping.
|
// set this slot+port into setSimSlotMapping.
|
||||||
mPort = (port < 0) ? getTargetPortId(removedSubInfo) : port;
|
mPort = (port < 0) ? getTargetPortId(targetSlot, removedSubInfo) : port;
|
||||||
mRemovedSubInfo = removedSubInfo;
|
mRemovedSubInfo = removedSubInfo;
|
||||||
Log.d(TAG,
|
Log.d(TAG,
|
||||||
String.format("set esim into the SubId%d Slot%d:Port%d",
|
String.format("Set esim into the SubId%d Physical Slot%d:Port%d",
|
||||||
mSubId, targetSlot, mPort));
|
mSubId, targetSlot, mPort));
|
||||||
|
if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||||
if (mTelephonyManager.isMultiSimEnabled() && removedSubInfo != null
|
// If the subId is INVALID_SUBSCRIPTION_ID, disable the esim (the default esim slot
|
||||||
&& removedSubInfo.isEmbedded()) {
|
// which is selected by the framework).
|
||||||
// In DSDS mode+MEP, if the replaced esim is active, then it should be disabled esim
|
switchToSubscription();
|
||||||
// profile before changing SimSlotMapping process.
|
} else if ((mTelephonyManager.isMultiSimEnabled() && removedSubInfo != null
|
||||||
// Use INVALID_SUBSCRIPTION_ID to disable the esim profile.
|
&& removedSubInfo.isEmbedded())
|
||||||
// The SimSlotMapping is ready, then to execute activate/inactivate esim.
|
|| isEsimEnabledAtTargetSlotPort(targetSlot, mPort)) {
|
||||||
|
// Case 1: In DSDS mode+MEP, if the replaced esim is active, then the replaced esim
|
||||||
|
// should be disabled before changing SimSlotMapping process.
|
||||||
|
//
|
||||||
|
// Case 2: If the user enables the esim A on the target slot:port which is active
|
||||||
|
// and there is an active esim B on target slot:port, then the settings disables the
|
||||||
|
// esim B before the settings enables the esim A on the target slot:port.
|
||||||
|
//
|
||||||
|
// Step:
|
||||||
|
// 1) Disables the replaced esim.
|
||||||
|
// 2) Switches the SimSlotMapping if the target slot:port is not active.
|
||||||
|
// 3) Enables the target esim.
|
||||||
|
// Note: Use INVALID_SUBSCRIPTION_ID to disable the esim profile.
|
||||||
|
Log.d(TAG, "Disable the enabled esim before the settings enables the target esim");
|
||||||
mIsDuringSimSlotMapping = true;
|
mIsDuringSimSlotMapping = true;
|
||||||
mEuiccManager.switchToSubscription(SubscriptionManager.INVALID_SUBSCRIPTION_ID, mPort,
|
mEuiccManager.switchToSubscription(SubscriptionManager.INVALID_SUBSCRIPTION_ID, mPort,
|
||||||
mCallbackIntent);
|
mCallbackIntent);
|
||||||
@@ -114,12 +139,24 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getTargetPortId(SubscriptionInfo removedSubInfo) {
|
private int getTargetPortId(int physicalEsimSlotIndex, SubscriptionInfo removedSubInfo) {
|
||||||
if (!mTelephonyManager.isMultiSimEnabled() || !isMultipleEnabledProfilesSupported()) {
|
if (!isMultipleEnabledProfilesSupported(physicalEsimSlotIndex)) {
|
||||||
// In the 'SS mode' or 'DSDS+no MEP', the port is 0.
|
Log.d(TAG, "The slotId" + physicalEsimSlotIndex + " is no MEP, port is 0");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mTelephonyManager.isMultiSimEnabled()) {
|
||||||
|
// In the 'SS mode'
|
||||||
|
// If there is the esim slot is active, the port is from the current esim slot.
|
||||||
|
// If there is no esim slot in device, then the esim's port is 0.
|
||||||
|
Collection<UiccSlotMapping> uiccSlotMappings = mTelephonyManager.getSimSlotMapping();
|
||||||
|
Log.d(TAG, "In SS mode, the UiccSlotMapping: " + uiccSlotMappings);
|
||||||
|
return uiccSlotMappings.stream()
|
||||||
|
.filter(i -> i.getPhysicalSlotIndex() == physicalEsimSlotIndex)
|
||||||
|
.mapToInt(i -> i.getPortIndex())
|
||||||
|
.findFirst().orElse(0);
|
||||||
|
}
|
||||||
|
|
||||||
// In the 'DSDS+MEP', if the removedSubInfo is esim, then the port is
|
// In the 'DSDS+MEP', if the removedSubInfo is esim, then the port is
|
||||||
// removedSubInfo's port.
|
// removedSubInfo's port.
|
||||||
if (removedSubInfo != null && removedSubInfo.isEmbedded()) {
|
if (removedSubInfo != null && removedSubInfo.isEmbedded()) {
|
||||||
@@ -136,11 +173,12 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
|
|||||||
// port is 0.
|
// port is 0.
|
||||||
|
|
||||||
int port = 0;
|
int port = 0;
|
||||||
SubscriptionManager subscriptionManager = getContext().getSystemService(
|
if(mActiveSubInfos == null){
|
||||||
SubscriptionManager.class);
|
Log.d(TAG, "mActiveSubInfos is null.");
|
||||||
|
return port;
|
||||||
|
}
|
||||||
List<SubscriptionInfo> activeEsimSubInfos =
|
List<SubscriptionInfo> activeEsimSubInfos =
|
||||||
SubscriptionUtil.getActiveSubscriptions(subscriptionManager)
|
mActiveSubInfos.stream()
|
||||||
.stream()
|
|
||||||
.filter(i -> i.isEmbedded())
|
.filter(i -> i.isEmbedded())
|
||||||
.sorted(Comparator.comparingInt(SubscriptionInfo::getPortIndex))
|
.sorted(Comparator.comparingInt(SubscriptionInfo::getPortIndex))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@@ -153,7 +191,31 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getTargetSlot() {
|
private int getTargetSlot() {
|
||||||
return UiccSlotUtil.getEsimSlotId(getContext());
|
return UiccSlotUtil.getEsimSlotId(getContext(), mSubId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isEsimEnabledAtTargetSlotPort(int physicalSlotIndex, int portIndex) {
|
||||||
|
int logicalSlotId = getLogicalSlotIndex(physicalSlotIndex, portIndex);
|
||||||
|
if (logicalSlotId == SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return mActiveSubInfos != null
|
||||||
|
&& mActiveSubInfos.stream()
|
||||||
|
.anyMatch(i -> i.isEmbedded() && i.getSimSlotIndex() == logicalSlotId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getLogicalSlotIndex(int physicalSlotIndex, int portIndex) {
|
||||||
|
ImmutableList<UiccSlotInfo> slotInfos = UiccSlotUtil.getSlotInfos(mTelephonyManager);
|
||||||
|
if (slotInfos != null && physicalSlotIndex >= 0 && physicalSlotIndex < slotInfos.size()
|
||||||
|
&& slotInfos.get(physicalSlotIndex) != null) {
|
||||||
|
for (UiccPortInfo portInfo : slotInfos.get(physicalSlotIndex).getPorts()) {
|
||||||
|
if (portInfo.getPortIndex() == portIndex) {
|
||||||
|
return portInfo.getLogicalSlotIndex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onSwitchSlotSidecarStateChange() {
|
private void onSwitchSlotSidecarStateChange() {
|
||||||
@@ -171,14 +233,11 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMultipleEnabledProfilesSupported() {
|
private boolean isMultipleEnabledProfilesSupported(int physicalEsimSlotIndex) {
|
||||||
List<UiccCardInfo> cardInfos = mTelephonyManager.getUiccCardsInfo();
|
List<UiccCardInfo> cardInfos = mTelephonyManager.getUiccCardsInfo();
|
||||||
if (cardInfos == null) {
|
return cardInfos.stream()
|
||||||
Log.w(TAG, "UICC cards info list is empty.");
|
.anyMatch(cardInfo -> cardInfo.getPhysicalSlotIndex() == physicalEsimSlotIndex
|
||||||
return false;
|
&& cardInfo.isMultipleEnabledProfilesSupported());
|
||||||
}
|
|
||||||
return cardInfos.stream().anyMatch(
|
|
||||||
cardInfo -> cardInfo.isMultipleEnabledProfilesSupported());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void switchToSubscription() {
|
private void switchToSubscription() {
|
||||||
|
@@ -22,11 +22,13 @@ import android.provider.Settings;
|
|||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
import android.telephony.UiccCardInfo;
|
||||||
import android.telephony.UiccSlotInfo;
|
import android.telephony.UiccSlotInfo;
|
||||||
import android.telephony.UiccSlotMapping;
|
import android.telephony.UiccSlotMapping;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
|
import com.android.internal.telephony.uicc.UiccController;
|
||||||
import com.android.settingslib.utils.ThreadUtils;
|
import com.android.settingslib.utils.ThreadUtils;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
@@ -36,6 +38,7 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -183,9 +186,27 @@ public class UiccSlotUtil {
|
|||||||
* @param context the application context.
|
* @param context the application context.
|
||||||
* @return the esim slot. If the value is -1, there is not the esim.
|
* @return the esim slot. If the value is -1, there is not the esim.
|
||||||
*/
|
*/
|
||||||
public static int getEsimSlotId(Context context) {
|
public static int getEsimSlotId(Context context, int subId) {
|
||||||
TelephonyManager telMgr = context.getSystemService(TelephonyManager.class);
|
TelephonyManager telMgr = context.getSystemService(TelephonyManager.class);
|
||||||
|
List<UiccCardInfo> uiccCardInfos = telMgr.getUiccCardsInfo();
|
||||||
ImmutableList<UiccSlotInfo> slotInfos = UiccSlotUtil.getSlotInfos(telMgr);
|
ImmutableList<UiccSlotInfo> slotInfos = UiccSlotUtil.getSlotInfos(telMgr);
|
||||||
|
SubscriptionManager subscriptionManager = context.getSystemService(
|
||||||
|
SubscriptionManager.class);
|
||||||
|
SubscriptionInfo subInfo = SubscriptionUtil.getSubById(subscriptionManager, subId);
|
||||||
|
|
||||||
|
// checking whether this is the removable esim. If it is, then return the removable slot id.
|
||||||
|
if (subInfo != null && subInfo.isEmbedded()) {
|
||||||
|
for (UiccCardInfo uiccCardInfo : uiccCardInfos) {
|
||||||
|
if (uiccCardInfo.getCardId() == subInfo.getCardId()
|
||||||
|
&& uiccCardInfo.getCardId() > TelephonyManager.UNSUPPORTED_CARD_ID
|
||||||
|
&& uiccCardInfo.isEuicc()
|
||||||
|
&& uiccCardInfo.isRemovable()) {
|
||||||
|
Log.d(TAG, "getEsimSlotId: This subInfo is a removable esim.");
|
||||||
|
return uiccCardInfo.getPhysicalSlotIndex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int firstEsimSlot = IntStream.range(0, slotInfos.size())
|
int firstEsimSlot = IntStream.range(0, slotInfos.size())
|
||||||
.filter(
|
.filter(
|
||||||
index -> {
|
index -> {
|
||||||
@@ -282,6 +303,21 @@ public class UiccSlotUtil {
|
|||||||
// 1. pSIM's logical slots always is [RIL 0].
|
// 1. pSIM's logical slots always is [RIL 0].
|
||||||
// 2. assign the new active port to the same stack that will be de-activated
|
// 2. assign the new active port to the same stack that will be de-activated
|
||||||
// For example: mode#3->mode#4
|
// For example: mode#3->mode#4
|
||||||
|
// 3. Add an eSIM carrier or enable eSIM carrier. The cases are at the below.
|
||||||
|
// 1) 1 => 2 / 2.1 / 3 / 3.1
|
||||||
|
// 2) 2 => 1 / 3 / 3.2
|
||||||
|
// 3) 2.1 => 3.1 / 4
|
||||||
|
// 4) 3 => 4
|
||||||
|
// 5) 3.1 => 3.2
|
||||||
|
// Note:
|
||||||
|
// 1) 2 <=> 2.1 blocked by LPA (reason: existing active port in SS so just re-use)
|
||||||
|
// 2) 3 <=> 3.1 blocked by LPA (reason: if pSIM+an active port, re-use the active port)
|
||||||
|
// 4. pSIM insertion or enabling
|
||||||
|
// 1) 2 => 1 / 3
|
||||||
|
// 2) 2.1 => 1 / 3.1
|
||||||
|
// 3) 3.2 => 3 / 3.1
|
||||||
|
// 4) 4 => 3 / 3.1
|
||||||
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static Collection<UiccSlotMapping> prepareUiccSlotMappings(
|
static Collection<UiccSlotMapping> prepareUiccSlotMappings(
|
||||||
|
@@ -16,8 +16,12 @@
|
|||||||
|
|
||||||
package com.android.settings.network.telephony;
|
package com.android.settings.network.telephony;
|
||||||
|
|
||||||
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
|
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
@@ -27,14 +31,27 @@ public class SubscriptionActionDialogActivity extends FragmentActivity {
|
|||||||
private static final String TAG = "SubscriptionActionDialogActivity";
|
private static final String TAG = "SubscriptionActionDialogActivity";
|
||||||
// Arguments
|
// Arguments
|
||||||
protected static final String ARG_SUB_ID = "sub_id";
|
protected static final String ARG_SUB_ID = "sub_id";
|
||||||
|
|
||||||
protected SubscriptionManager mSubscriptionManager;
|
protected SubscriptionManager mSubscriptionManager;
|
||||||
|
|
||||||
|
public static final String SIM_ACTION_DIALOG_PREFS = "sim_action_dialog_prefs";
|
||||||
|
// Shared preference keys
|
||||||
|
public static final String KEY_PROGRESS_STATE = "progress_state";
|
||||||
|
public static final int PROGRESS_IS_NOT_SHOWING = 0;
|
||||||
|
public static final int PROGRESS_IS_SHOWING = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
mSubscriptionManager = getSystemService(SubscriptionManager.class);
|
mSubscriptionManager = getSystemService(SubscriptionManager.class);
|
||||||
|
setProgressState(PROGRESS_IS_NOT_SHOWING);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void finish() {
|
||||||
|
setProgressState(PROGRESS_IS_NOT_SHOWING);
|
||||||
|
super.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,11 +61,13 @@ public class SubscriptionActionDialogActivity extends FragmentActivity {
|
|||||||
*/
|
*/
|
||||||
protected void showProgressDialog(String message) {
|
protected void showProgressDialog(String message) {
|
||||||
ProgressDialogFragment.show(getFragmentManager(), message, null);
|
ProgressDialogFragment.show(getFragmentManager(), message, null);
|
||||||
|
setProgressState(PROGRESS_IS_SHOWING);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dismisses the loading dialog. */
|
/** Dismisses the loading dialog. */
|
||||||
protected void dismissProgressDialog() {
|
protected void dismissProgressDialog() {
|
||||||
ProgressDialogFragment.dismiss(getFragmentManager());
|
ProgressDialogFragment.dismiss(getFragmentManager());
|
||||||
|
setProgressState(PROGRESS_IS_NOT_SHOWING);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,4 +79,10 @@ public class SubscriptionActionDialogActivity extends FragmentActivity {
|
|||||||
protected void showErrorDialog(String title, String message) {
|
protected void showErrorDialog(String title, String message) {
|
||||||
AlertDialogFragment.show(this, title, message);
|
AlertDialogFragment.show(this, title, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setProgressState(int state) {
|
||||||
|
final SharedPreferences prefs = getSharedPreferences(SIM_ACTION_DIALOG_PREFS, MODE_PRIVATE);
|
||||||
|
prefs.edit().putInt(KEY_PROGRESS_STATE, state).apply();
|
||||||
|
Log.i(TAG, "setProgressState:" + state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,8 +16,11 @@
|
|||||||
|
|
||||||
package com.android.settings.sim;
|
package com.android.settings.sim;
|
||||||
|
|
||||||
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.telecom.PhoneAccountHandle;
|
import android.telecom.PhoneAccountHandle;
|
||||||
import android.telecom.TelecomManager;
|
import android.telecom.TelecomManager;
|
||||||
@@ -32,6 +35,7 @@ import androidx.fragment.app.FragmentActivity;
|
|||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.network.telephony.SubscriptionActionDialogActivity;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -60,6 +64,7 @@ public class SimDialogActivity extends FragmentActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
getWindow().addSystemFlags(
|
getWindow().addSystemFlags(
|
||||||
WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
|
WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
|
||||||
showOrUpdateDialog();
|
showOrUpdateDialog();
|
||||||
@@ -72,6 +77,13 @@ public class SimDialogActivity extends FragmentActivity {
|
|||||||
showOrUpdateDialog();
|
showOrUpdateDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getProgressState() {
|
||||||
|
final SharedPreferences prefs = getSharedPreferences(
|
||||||
|
SubscriptionActionDialogActivity.SIM_ACTION_DIALOG_PREFS, MODE_PRIVATE);
|
||||||
|
return prefs.getInt(SubscriptionActionDialogActivity.KEY_PROGRESS_STATE,
|
||||||
|
SubscriptionActionDialogActivity.PROGRESS_IS_NOT_SHOWING);
|
||||||
|
}
|
||||||
|
|
||||||
private void showOrUpdateDialog() {
|
private void showOrUpdateDialog() {
|
||||||
final int dialogType = getIntent().getIntExtra(DIALOG_TYPE_KEY, INVALID_PICK);
|
final int dialogType = getIntent().getIntExtra(DIALOG_TYPE_KEY, INVALID_PICK);
|
||||||
|
|
||||||
@@ -80,6 +92,13 @@ public class SimDialogActivity extends FragmentActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dialogType == PREFERRED_PICK
|
||||||
|
&& getProgressState() == SubscriptionActionDialogActivity.PROGRESS_IS_SHOWING) {
|
||||||
|
Log.d(TAG, "Finish the sim dialog since the sim action dialog is showing the progress");
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final String tag = Integer.toString(dialogType);
|
final String tag = Integer.toString(dialogType);
|
||||||
final FragmentManager fragmentManager = getSupportFragmentManager();
|
final FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
SimDialogFragment fragment = (SimDialogFragment) fragmentManager.findFragmentByTag(tag);
|
SimDialogFragment fragment = (SimDialogFragment) fragmentManager.findFragmentByTag(tag);
|
||||||
|
@@ -25,7 +25,9 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
import android.telephony.UiccCardInfo;
|
||||||
import android.telephony.UiccPortInfo;
|
import android.telephony.UiccPortInfo;
|
||||||
import android.telephony.UiccSlotInfo;
|
import android.telephony.UiccSlotInfo;
|
||||||
import android.telephony.UiccSlotMapping;
|
import android.telephony.UiccSlotMapping;
|
||||||
@@ -50,19 +52,28 @@ import java.util.List;
|
|||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class UiccSlotUtilTest {
|
public class UiccSlotUtilTest {
|
||||||
private Context mContext;
|
|
||||||
@Mock
|
@Mock
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
|
@Mock
|
||||||
|
private SubscriptionManager mSubscriptionManager;
|
||||||
|
|
||||||
private static final int ESIM_PHYSICAL_SLOT = 0;
|
private static final int ESIM_PHYSICAL_SLOT = 0;
|
||||||
private static final int PSIM_PHYSICAL_SLOT = 1;
|
private static final int PSIM_PHYSICAL_SLOT = 1;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private List<SubscriptionInfo> mSubscriptionInfoList = new ArrayList<>();
|
||||||
|
private List<UiccCardInfo> mUiccCardInfo = new ArrayList<>();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
||||||
|
when(mTelephonyManager.getUiccCardsInfo()).thenReturn(mUiccCardInfo);
|
||||||
|
|
||||||
|
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
||||||
|
when(mSubscriptionManager.getAllSubscriptionInfoList()).thenReturn(mSubscriptionInfoList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -88,15 +99,38 @@ public class UiccSlotUtilTest {
|
|||||||
public void getEsimSlotId_twoSimSlotsDeviceAndEsimIsSlot0_returnTheCorrectEsimSlot() {
|
public void getEsimSlotId_twoSimSlotsDeviceAndEsimIsSlot0_returnTheCorrectEsimSlot() {
|
||||||
when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
|
when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
|
||||||
twoSimSlotsDeviceActiveEsimActivePsim());
|
twoSimSlotsDeviceActiveEsimActivePsim());
|
||||||
int testSlot = UiccSlotUtil.getEsimSlotId(mContext);
|
|
||||||
|
int testSlot = UiccSlotUtil.getEsimSlotId(mContext, 0);
|
||||||
|
|
||||||
assertThat(testSlot).isEqualTo(0);
|
assertThat(testSlot).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEsimSlotId_twoSimSlotsDeviceAndRemovableEsimIsSlot1_returnTheCorrectEsimSlot() {
|
public void getEsimSlotId_simIsRemovableEsimAndRemovableEsimIsSlot1_returnRemovableEsimSlot1() {
|
||||||
|
int subId = 0;
|
||||||
|
int cardId = 0;
|
||||||
|
mSubscriptionInfoList.add(createSubscriptionInfo(subId,-1, -1, true, cardId));
|
||||||
|
mUiccCardInfo.add(createUiccCardInfo(true, 3, 0, false, -1, -1));
|
||||||
|
mUiccCardInfo.add(createUiccCardInfo(true, cardId, 1, true, -1, -1));
|
||||||
|
when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
|
||||||
|
twoSimSlotsDeviceActiveEsimActiveRemovableEsim());
|
||||||
|
|
||||||
|
int testSlot = UiccSlotUtil.getEsimSlotId(mContext, subId);
|
||||||
|
|
||||||
|
assertThat(testSlot).isEqualTo(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getEsimSlotId_simIsRemovableEsimAndTwoRemovableSlots_returnRemovableEsimSlot1() {
|
||||||
|
int subId = 0;
|
||||||
|
int cardId = 0;
|
||||||
|
mSubscriptionInfoList.add(createSubscriptionInfo(subId,-1, -1, true, cardId));
|
||||||
|
mUiccCardInfo.add(createUiccCardInfo(false, 4, 0, true, -1, -1));
|
||||||
|
mUiccCardInfo.add(createUiccCardInfo(true, cardId, 1, true, -1, -1));
|
||||||
when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
|
when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
|
||||||
twoSimSlotsDeviceActivePsimActiveRemovableEsim());
|
twoSimSlotsDeviceActivePsimActiveRemovableEsim());
|
||||||
int testSlot = UiccSlotUtil.getEsimSlotId(mContext);
|
|
||||||
|
int testSlot = UiccSlotUtil.getEsimSlotId(mContext, subId);
|
||||||
|
|
||||||
assertThat(testSlot).isEqualTo(1);
|
assertThat(testSlot).isEqualTo(1);
|
||||||
}
|
}
|
||||||
@@ -105,7 +139,8 @@ public class UiccSlotUtilTest {
|
|||||||
public void getEsimSlotId_twoSimSlotsDeviceAndEsimIsSlot1_returnTheCorrectEsimSlot() {
|
public void getEsimSlotId_twoSimSlotsDeviceAndEsimIsSlot1_returnTheCorrectEsimSlot() {
|
||||||
when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
|
when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
|
||||||
twoSimSlotsDeviceActivePsimActiveEsim());
|
twoSimSlotsDeviceActivePsimActiveEsim());
|
||||||
int testSlot = UiccSlotUtil.getEsimSlotId(mContext);
|
|
||||||
|
int testSlot = UiccSlotUtil.getEsimSlotId(mContext, 0);
|
||||||
|
|
||||||
assertThat(testSlot).isEqualTo(1);
|
assertThat(testSlot).isEqualTo(1);
|
||||||
}
|
}
|
||||||
@@ -114,7 +149,8 @@ public class UiccSlotUtilTest {
|
|||||||
public void getEsimSlotId_noEimSlotDevice_returnTheCorrectEsimSlot() {
|
public void getEsimSlotId_noEimSlotDevice_returnTheCorrectEsimSlot() {
|
||||||
when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
|
when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
|
||||||
oneSimSlotDeviceActivePsim());
|
oneSimSlotDeviceActivePsim());
|
||||||
int testSlot = UiccSlotUtil.getEsimSlotId(mContext);
|
|
||||||
|
int testSlot = UiccSlotUtil.getEsimSlotId(mContext, 0);
|
||||||
|
|
||||||
assertThat(testSlot).isEqualTo(-1);
|
assertThat(testSlot).isEqualTo(-1);
|
||||||
}
|
}
|
||||||
@@ -620,13 +656,38 @@ public class UiccSlotUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private SubscriptionInfo createSubscriptionInfo(int logicalSlotIndex, int portIndex) {
|
private SubscriptionInfo createSubscriptionInfo(int logicalSlotIndex, int portIndex) {
|
||||||
|
return createSubscriptionInfo(0, logicalSlotIndex, portIndex, true, 25);
|
||||||
|
}
|
||||||
|
|
||||||
|
private SubscriptionInfo createSubscriptionInfo(int subId, int logicalSlotIndex, int portIndex,
|
||||||
|
boolean isEmbedded, int cardId) {
|
||||||
return new SubscriptionInfo(
|
return new SubscriptionInfo(
|
||||||
0, "", logicalSlotIndex, "", "", 0, 0, "", 0, null, "", "", "",
|
subId, "",
|
||||||
true /* isEmbedded */,
|
logicalSlotIndex, "", "", 0, 0, "", 0, null, "", "", "",
|
||||||
null, "", 25,
|
isEmbedded /* isEmbedded */,
|
||||||
|
null, "",
|
||||||
|
cardId,
|
||||||
false, null, false, 0, 0, 0, null, null, true, portIndex);
|
false, null, false, 0, 0, 0, null, null, true, portIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private UiccCardInfo createUiccCardInfo(boolean isEuicc, int cardId, int physicalSlotIndex,
|
||||||
|
boolean isRemovable, int logicalSlotIndex, int portIndex) {
|
||||||
|
return new UiccCardInfo(
|
||||||
|
isEuicc /* isEuicc */,
|
||||||
|
cardId /* cardId */,
|
||||||
|
null /* eid */,
|
||||||
|
physicalSlotIndex /* physicalSlotIndex */,
|
||||||
|
isRemovable /* isRemovable */,
|
||||||
|
false /* isMultipleEnabledProfileSupported */,
|
||||||
|
Collections.singletonList(
|
||||||
|
new UiccPortInfo(
|
||||||
|
"123451234567890" /* iccId */,
|
||||||
|
portIndex /* portIdx */,
|
||||||
|
logicalSlotIndex /* logicalSlotIdx */,
|
||||||
|
true /* isActive */)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
private List<SubscriptionInfo> createActiveSubscriptionInfoListOneSim(int logicalSlotIndex,
|
private List<SubscriptionInfo> createActiveSubscriptionInfoListOneSim(int logicalSlotIndex,
|
||||||
int portIndex) {
|
int portIndex) {
|
||||||
List<SubscriptionInfo> subscriptionInfoList = new ArrayList<>();
|
List<SubscriptionInfo> subscriptionInfoList = new ArrayList<>();
|
||||||
@@ -737,6 +798,12 @@ public class UiccSlotUtilTest {
|
|||||||
createUiccSlotInfo(true, false, 1, true)};
|
createUiccSlotInfo(true, false, 1, true)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private UiccSlotInfo[] twoSimSlotsDeviceActiveEsimActiveRemovableEsim() {
|
||||||
|
return new UiccSlotInfo[]{
|
||||||
|
createUiccSlotInfo(true, false, 0, true),
|
||||||
|
createUiccSlotInfo(true, true, 1, true)};
|
||||||
|
}
|
||||||
|
|
||||||
private UiccSlotInfo[] twoSimSlotsDeviceActivePsimActiveRemovableEsim() {
|
private UiccSlotInfo[] twoSimSlotsDeviceActivePsimActiveRemovableEsim() {
|
||||||
return new UiccSlotInfo[]{
|
return new UiccSlotInfo[]{
|
||||||
createUiccSlotInfo(false, true, 0, true),
|
createUiccSlotInfo(false, true, 0, true),
|
||||||
|
Reference in New Issue
Block a user