1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of 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,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.bedstead.nene.telephony;
18 
19 import android.telephony.TelephonyManager
20 import com.android.bedstead.nene.TestApis
21 import com.android.bedstead.nene.annotations.Experimental
22 import com.android.bedstead.permissions.CommonPermissions.READ_PRIVILEGED_PHONE_STATE
23 
24 /** Test APIs related to telephony. */
25 @Experimental
26 object Telephony {
27 
28     private val telephonyManager =
29         TestApis.context().instrumentedContext()
30             .getSystemService(TelephonyManager::class.java)!!
31 
32     /** See [TelephonyManager#getDeviceId]. */
getDeviceIdnull33     fun getDeviceId(): String? {
34         TestApis.permissions().withPermission(READ_PRIVILEGED_PHONE_STATE).use {
35             return telephonyManager.getDeviceId()
36         }
37     }
38 
39     /** See [TelephonyManager#getImei]. */
getImeinull40     fun getImei(): String? {
41         TestApis.permissions().withPermission(READ_PRIVILEGED_PHONE_STATE).use {
42             return telephonyManager.getImei()
43         }
44     }
45 
46     /** See [TelephonyManager#getMeid]. */
getMeidnull47     fun getMeid(): String? {
48         TestApis.permissions().withPermission(READ_PRIVILEGED_PHONE_STATE).use {
49             return telephonyManager.getMeid()
50         }
51     }
52 
53     /** See [TelephonyManager#getSubscriberId]. */
getSubscriberIdnull54     fun getSubscriberId(): String? {
55         TestApis.permissions().withPermission(READ_PRIVILEGED_PHONE_STATE).use {
56             return telephonyManager.getSubscriberId()
57         }
58     }
59 
60     /** See [TelephonyManager#getSimSerialNumber]. */
getSimSerialNumbernull61     fun getSimSerialNumber(): String? {
62         TestApis.permissions().withPermission(READ_PRIVILEGED_PHONE_STATE).use {
63             return telephonyManager.getSimSerialNumber()
64         }
65     }
66 
67     /** See [TelephonyManager#getNai]. */
getNainull68     fun getNai(): String? {
69         TestApis.permissions().withPermission(READ_PRIVILEGED_PHONE_STATE).use {
70             return telephonyManager.getNai()
71         }
72     }
73 }
74