• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.phone;
18 
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
21 import static org.mockito.Mockito.eq;
22 import static org.mockito.Mockito.when;
23 
24 import android.content.ComponentName;
25 import android.os.UserHandle;
26 import android.telecom.PhoneAccountHandle;
27 import android.telephony.SubscriptionInfo;
28 import android.telephony.SubscriptionManager;
29 
30 import androidx.test.runner.AndroidJUnit4;
31 
32 import com.android.TelephonyTestBase;
33 
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.mockito.Mock;
38 
39 @RunWith(AndroidJUnit4.class)
40 public class PhoneUtilsTest extends TelephonyTestBase {
41     @Mock
42     private SubscriptionManager mMockSubscriptionManager;
43     @Mock
44     private SubscriptionInfo mMockSubscriptionInfo;
45 
46     private final int mPhoneAccountHandleIdInteger = 123;
47     private final String mPhoneAccountHandleIdString = "123";
48     private static final ComponentName PSTN_CONNECTION_SERVICE_COMPONENT = new ComponentName(
49             "com.android.phone", "com.android.services.telephony.TelephonyConnectionService");
50     private PhoneAccountHandle mPhoneAccountHandleTest = new PhoneAccountHandle(
51             PSTN_CONNECTION_SERVICE_COMPONENT, mPhoneAccountHandleIdString);
52 
53     @Before
setUp()54     public void setUp() throws Exception {
55         super.setUp();
56         when(mMockSubscriptionManager.getActiveSubscriptionInfo(
57                 eq(mPhoneAccountHandleIdInteger))).thenReturn(mMockSubscriptionInfo);
58         when(mPhone.getSubId()).thenReturn(mPhoneAccountHandleIdInteger);
59     }
60 
61     @Test
testIsPhoneAccountActive()62     public void testIsPhoneAccountActive() throws Exception {
63         assertTrue(PhoneUtils.isPhoneAccountActive(
64                 mMockSubscriptionManager, mPhoneAccountHandleTest));
65     }
66 
67     @Test
testGetPhoneForPhoneAccountHandle()68     public void testGetPhoneForPhoneAccountHandle() throws Exception {
69         assertEquals(mPhone, PhoneUtils.getPhoneForPhoneAccountHandle(
70                 mPhoneAccountHandleTest));
71     }
72 
73     @Test
testMakePstnPhoneAccountHandleWithPrefix()74     public void testMakePstnPhoneAccountHandleWithPrefix() throws Exception {
75         PhoneAccountHandle phoneAccountHandleTest = new PhoneAccountHandle(
76                 PSTN_CONNECTION_SERVICE_COMPONENT, mPhoneAccountHandleIdString);
77         assertEquals(phoneAccountHandleTest, PhoneUtils.makePstnPhoneAccountHandleWithId(
78                 mPhoneAccountHandleIdString, null));
79     }
80 
81     @Test
testMakePstnPhoneAccountHandleWithPrefixForAnotherUser()82     public void testMakePstnPhoneAccountHandleWithPrefixForAnotherUser() throws Exception {
83         UserHandle userHandle = new UserHandle(10);
84         PhoneAccountHandle phoneAccountHandleTest = new PhoneAccountHandle(
85                 PSTN_CONNECTION_SERVICE_COMPONENT, mPhoneAccountHandleIdString, userHandle);
86         assertEquals(phoneAccountHandleTest, PhoneUtils.makePstnPhoneAccountHandleWithId(
87                 mPhoneAccountHandleIdString, userHandle));
88     }
89 }
90