aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/google/android/mobly/snippet/bundled/TelephonySnippet.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/android/mobly/snippet/bundled/TelephonySnippet.java')
-rw-r--r--src/main/java/com/google/android/mobly/snippet/bundled/TelephonySnippet.java62
1 files changed, 54 insertions, 8 deletions
diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/TelephonySnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/TelephonySnippet.java
index 21c5d1e..e4d33ec 100644
--- a/src/main/java/com/google/android/mobly/snippet/bundled/TelephonySnippet.java
+++ b/src/main/java/com/google/android/mobly/snippet/bundled/TelephonySnippet.java
@@ -17,24 +17,49 @@
package com.google.android.mobly.snippet.bundled;
import android.content.Context;
+import android.os.Build;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import androidx.test.platform.app.InstrumentationRegistry;
import com.google.android.mobly.snippet.Snippet;
import com.google.android.mobly.snippet.rpc.Rpc;
+import com.google.android.mobly.snippet.rpc.RpcDefault;
/** Snippet class for telephony RPCs. */
public class TelephonySnippet implements Snippet {
private final TelephonyManager mTelephonyManager;
+ private final SubscriptionManager mSubscriptionManager;
public TelephonySnippet() {
Context context = InstrumentationRegistry.getInstrumentation().getContext();
mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ mSubscriptionManager =
+ (SubscriptionManager)
+ context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
}
- @Rpc(description = "Gets the line 1 phone number.")
- public String getLine1Number() {
- return mTelephonyManager.getLine1Number();
+ @Rpc(
+ description =
+ "Gets the line 1 phone number, or optionally get phone number for the "
+ + "simSlot (slot# start from 0, only valid for API level > 32)")
+ public String getLine1Number(@RpcDefault("0") Integer simSlot) {
+ String thisNumber = "";
+
+ if (Build.VERSION.SDK_INT < 33) {
+ thisNumber = mTelephonyManager.getLine1Number();
+ } else {
+ SubscriptionInfo mSubscriptionInfo =
+ mSubscriptionManager.getActiveSubscriptionInfoForSimSlotIndex(
+ simSlot.intValue());
+ if (mSubscriptionInfo != null) {
+ thisNumber =
+ mSubscriptionManager.getPhoneNumber(mSubscriptionInfo.getSubscriptionId());
+ }
+ }
+
+ return thisNumber;
}
@Rpc(description = "Returns the unique subscriber ID, for example, the IMSI for a GSM phone.")
@@ -44,10 +69,27 @@ public class TelephonySnippet implements Snippet {
@Rpc(
description =
- "Gets the call state for the default subscription. Call state values are"
- + "0: IDLE, 1: RINGING, 2: OFFHOOK")
- public int getTelephonyCallState() {
- return mTelephonyManager.getCallState();
+ "Gets the call state for the default subscription or optionally get the call"
+ + " state for the simSlot (slot# start from 0, only valid for API"
+ + " level > 30). Call state values are 0: IDLE, 1: RINGING, 2: OFFHOOK")
+ public int getTelephonyCallState(@RpcDefault("0") Integer simSlot) {
+ int thisState = -1;
+
+ if (Build.VERSION.SDK_INT < 31) {
+ return mTelephonyManager.getCallState();
+ } else {
+ SubscriptionInfo mSubscriptionInfo =
+ mSubscriptionManager.getActiveSubscriptionInfoForSimSlotIndex(
+ simSlot.intValue());
+ if (mSubscriptionInfo != null) {
+ thisState =
+ mTelephonyManager
+ .createForSubscriptionId(mSubscriptionInfo.getSubscriptionId())
+ .getCallStateForSubscription();
+ }
+ }
+
+ return thisState;
}
@Rpc(
@@ -55,7 +97,11 @@ public class TelephonySnippet implements Snippet {
"Returns a constant indicating the radio technology (network type) currently"
+ "in use on the device for data transmission.")
public int getDataNetworkType() {
- return mTelephonyManager.getDataNetworkType();
+ if (Build.VERSION.SDK_INT < 30) {
+ return mTelephonyManager.getNetworkType();
+ } else {
+ return mTelephonyManager.getDataNetworkType();
+ }
}
@Rpc(