1 /* 2 * Copyright (C) 2022 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17 package com.google.android.mobly.snippet.gft; 18 19 import android.content.Context; 20 import android.telephony.TelephonyManager; 21 import androidx.test.platform.app.InstrumentationRegistry; 22 import com.google.android.mobly.snippet.Snippet; 23 import com.google.android.mobly.snippet.rpc.Rpc; 24 25 /** Snippet class for telephony RPCs. */ 26 public class SampleTelephonySnippet implements Snippet { 27 28 private final TelephonyManager mTelephonyManager; 29 SampleTelephonySnippet()30 public SampleTelephonySnippet() { 31 Context context = InstrumentationRegistry.getInstrumentation().getContext(); 32 mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 33 } 34 35 @Rpc(description = "Gets the line 1 phone number.") getLine1Number()36 public String getLine1Number() { 37 return mTelephonyManager.getLine1Number(); 38 } 39 40 @Rpc(description = "Returns the unique subscriber ID, for example, the IMSI for a GSM phone.") getSubscriberId()41 public String getSubscriberId() { 42 return mTelephonyManager.getSubscriberId(); 43 } 44 45 @Rpc( 46 description = 47 "Gets the call state for the default subscription. Call state values are" 48 + "0: IDLE, 1: RINGING, 2: OFFHOOK") getTelephonyCallState()49 public int getTelephonyCallState() { 50 return mTelephonyManager.getCallState(); 51 } 52 53 @Rpc( 54 description = 55 "Returns a constant indicating the radio technology (network type) currently" 56 + "in use on the device for data transmission.") getDataNetworkType()57 public int getDataNetworkType() { 58 return mTelephonyManager.getDataNetworkType(); 59 } 60 61 @Rpc( 62 description = 63 "Returns a constant indicating the radio technology (network type) currently" 64 + "in use on the device for voice transmission.") getVoiceNetworkType()65 public int getVoiceNetworkType() { 66 return mTelephonyManager.getVoiceNetworkType(); 67 } 68 69 // Hidden APIs accessed here 70 71 @Rpc(description = "Return current modem state.") getRadioPowerState()72 public int getRadioPowerState() { return mTelephonyManager.getRadioPowerState(); } 73 74 @Rpc(description = "Return the Electronic Serial Number.") getEsn()75 public String getEsn() { return mTelephonyManager.getEsn(); } 76 77 @Rpc(description = "Return the baseband version for the default phone.") getBasebandVersion()78 public String getBasebandVersion() { return mTelephonyManager.getBasebandVersion(); } 79 80 @Rpc(description = "Returns a constant indicating the state of the default SIM card.") getSimCardState()81 public int getSimCardState() { return mTelephonyManager.getSimCardState(); } 82 83 @Rpc(description = "Returns an array of all valid network types.") getAllNetworkTypes()84 public int[] getAllNetworkTypes() { return mTelephonyManager.getAllNetworkTypes(); } 85 86 @Override shutdown()87 public void shutdown() {} 88 } 89