Default to slot 0 when no subs for testing
When there are no subscriptions on the device,
default to slot 0 for testing. This makes testing
on a device without any SIM cards possible.
Bug: 77141737
Test: atest ImsServiceTests
Merged-In: I74fc1827a7abc7dcdc6bbc75ac4f92f050415b5b
Change-Id: I77f7b2e8843032ab00a0ba8f41f5eb0572983201
diff --git a/src/com/android/phone/TelephonyShellCommand.java b/src/com/android/phone/TelephonyShellCommand.java
index fce1086..4acb46b 100644
--- a/src/com/android/phone/TelephonyShellCommand.java
+++ b/src/com/android/phone/TelephonyShellCommand.java
@@ -36,6 +36,7 @@
private static final String LOG_TAG = "TelephonyShellCommand";
// Don't commit with this true.
private static final boolean VDBG = true;
+ private static final int DEFAULT_PHONE_ID = 0;
private static final String IMS_SUBCOMMAND = "ims";
private static final String IMS_SET_CARRIER_SERVICE = "set-ims-service";
@@ -130,7 +131,7 @@
// ims set-ims-service
private int handleImsSetServiceCommand() {
PrintWriter errPw = getErrPrintWriter();
- int slotId = SubscriptionManager.getDefaultVoicePhoneId();
+ int slotId = getDefaultSlot();
Boolean isCarrierService = null;
String opt;
@@ -186,7 +187,7 @@
// ims get-ims-service
private int handleImsGetServiceCommand() {
PrintWriter errPw = getErrPrintWriter();
- int slotId = SubscriptionManager.getDefaultVoicePhoneId();
+ int slotId = getDefaultSlot();
Boolean isCarrierService = null;
String opt;
@@ -232,7 +233,7 @@
}
private int handleEnableIms() {
- int slotId = SubscriptionManager.getDefaultVoicePhoneId();
+ int slotId = getDefaultSlot();
String opt;
while ((opt = getNextOption()) != null) {
switch (opt) {
@@ -259,7 +260,7 @@
}
private int handleDisableIms() {
- int slotId = SubscriptionManager.getDefaultVoicePhoneId();
+ int slotId = getDefaultSlot();
String opt;
while ((opt = getNextOption()) != null) {
switch (opt) {
@@ -285,4 +286,14 @@
}
return 0;
}
+
+ private int getDefaultSlot() {
+ int slotId = SubscriptionManager.getDefaultVoicePhoneId();
+ if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX
+ || slotId == SubscriptionManager.DEFAULT_PHONE_INDEX) {
+ // If there is no default, default to slot 0.
+ slotId = DEFAULT_PHONE_ID;
+ }
+ return slotId;
+ }
}