aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhaoma <haoma@google.com>2024-01-08 11:08:50 +0800
committerhaoma <haoma@google.com>2024-01-08 11:08:50 +0800
commitefb63fed6a4630cd278d38b823d49a292f0f429c (patch)
tree881ec96f1d9a10a5e4c4fc1832d04fa2bd34003b
parentd270e876f2204e41dd99ec02c910fadf8f29cf29 (diff)
downloadmobly-bundled-snippets-efb63fed6a4630cd278d38b823d49a292f0f429c.tar.gz
Merging functions by employing Default and Optional RPCs
-rw-r--r--src/main/java/com/google/android/mobly/snippet/bundled/TelephonySnippet.java44
1 files changed, 23 insertions, 21 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 f7e5c8a..2380b73 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
@@ -24,6 +24,7 @@ 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.RpcOptional;
/** Snippet class for telephony RPCs. */
public class TelephonySnippet implements Snippet {
@@ -37,9 +38,20 @@ public class TelephonySnippet implements Snippet {
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(@RpcOptional Integer simSlot) {
+ String thisNumber = "";
+
+ if (Build.VERSION.SDK_INT < 33 || simSlot == null) {
+ thisNumber = mTelephonyManager.getLine1Number();
+ } else{
+ SubscriptionInfo mSubscriptionInfo = mSubscriptionManager.getActiveSubscriptionInfoForSimSlotIndex(simSlot.intValue());
+ if (mSubscriptionInfo != null) {
+ thisNumber = mSubscriptionManager.getPhoneNumber(mSubscriptionInfo.getSubscriptionId());
+ }
+ }
+
+ return thisNumber;
}
@Rpc(description = "Gets phone number for the simSlot (slot# start from 0, only valid for API level > 32)."
@@ -65,33 +77,23 @@ 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() {
- if (Build.VERSION.SDK_INT < 31) {
- return mTelephonyManager.getCallState();
- } else {
- return mTelephonyManager.getCallStateForSubscription();
- }
- }
-
- @Rpc(
- description =
- "Gets 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(int simSlot) {
+ "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(@RpcOptional Integer simSlot) {
int thisState = -1;
if (Build.VERSION.SDK_INT < 31) {
- thisState = mTelephonyManager.getCallState();
- } else {
- SubscriptionInfo mSubscriptionInfo = mSubscriptionManager.getActiveSubscriptionInfoForSimSlotIndex(simSlot);
+ return mTelephonyManager.getCallState();
+ } else if(simSlot != null){
+ SubscriptionInfo mSubscriptionInfo = mSubscriptionManager.getActiveSubscriptionInfoForSimSlotIndex(simSlot.intValue());
if (mSubscriptionInfo != null) {
thisState =
mTelephonyManager
.createForSubscriptionId(mSubscriptionInfo.getSubscriptionId())
.getCallStateForSubscription();
}
+ }else{
+ thisState = mTelephonyManager.getCallStateForSubscription();
}
return thisState;