• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.services.telephony;
18 
19 import android.content.Context;
20 import android.content.res.Resources;
21 import android.os.Bundle;
22 import android.telecom.PhoneAccountHandle;
23 
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.anyInt;
26 import static org.mockito.Mockito.doNothing;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.when;
29 
30 import com.android.internal.telephony.Call;
31 import com.android.internal.telephony.Connection;
32 import com.android.internal.telephony.Phone;
33 import com.android.internal.telephony.PhoneConstants;
34 
35 import org.mockito.Mock;
36 import org.mockito.MockitoAnnotations;
37 
38 import java.util.ArrayList;
39 import java.util.List;
40 
41 /**
42  * Mock Telephony Connection used in TelephonyConferenceController.java for testing purpose
43  */
44 
45 public class TestTelephonyConnection extends TelephonyConnection {
46 
47     @Mock
48     com.android.internal.telephony.Connection mMockRadioConnection;
49 
50     @Mock
51     Call mMockCall;
52 
53     @Mock
54     Context mMockContext;
55 
56     @Mock
57     Resources mMockResources;
58 
59     private Phone mMockPhone;
60     private int mNotifyPhoneAccountChangedCount = 0;
61     private List<String> mLastConnectionEvents = new ArrayList<>();
62     private List<Bundle> mLastConnectionEventExtras = new ArrayList<>();
63 
64     @Override
getOriginalConnection()65     public com.android.internal.telephony.Connection getOriginalConnection() {
66         return mMockRadioConnection;
67     }
68 
TestTelephonyConnection()69     public TestTelephonyConnection() {
70         super(null, null, false);
71         MockitoAnnotations.initMocks(this);
72 
73         mMockPhone = mock(Phone.class);
74         mMockContext = mock(Context.class);
75         mOriginalConnection = mock(Connection.class);
76         // Set up mMockRadioConnection and mMockPhone to contain an active call
77         when(mMockRadioConnection.getState()).thenReturn(Call.State.ACTIVE);
78         when(mMockRadioConnection.getCall()).thenReturn(mMockCall);
79         when(mMockRadioConnection.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_IMS);
80         doNothing().when(mMockRadioConnection).addListener(any(Connection.Listener.class));
81         doNothing().when(mMockRadioConnection).addPostDialListener(
82                 any(Connection.PostDialListener.class));
83         when(mMockPhone.getRingingCall()).thenReturn(mMockCall);
84         when(mMockPhone.getContext()).thenReturn(mMockContext);
85         when(mMockPhone.getCurrentSubscriberUris()).thenReturn(null);
86         when(mMockContext.getResources()).thenReturn(mMockResources);
87         when(mMockResources.getBoolean(anyInt())).thenReturn(false);
88         when(mMockPhone.getDefaultPhone()).thenReturn(mMockPhone);
89         when(mMockPhone.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_IMS);
90         when(mMockCall.getState()).thenReturn(Call.State.ACTIVE);
91         when(mMockCall.getPhone()).thenReturn(mMockPhone);
92     }
93 
94     @Override
isConferenceSupported()95     public boolean isConferenceSupported() {
96         return true;
97     }
98 
setMockPhone(Phone newPhone)99     public void setMockPhone(Phone newPhone) {
100         mMockPhone = newPhone;
101     }
102 
103     @Override
getPhone()104     public Phone getPhone() {
105         return mMockPhone;
106     }
107 
cloneConnection()108     public TelephonyConnection cloneConnection() {
109         return this;
110     }
111 
112     @Override
notifyPhoneAccountChanged(PhoneAccountHandle pHandle)113     public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
114         mNotifyPhoneAccountChangedCount++;
115     }
116 
117     @Override
sendConnectionEvent(String event, Bundle extras)118     public void sendConnectionEvent(String event, Bundle extras) {
119         mLastConnectionEvents.add(event);
120         mLastConnectionEventExtras.add(extras);
121     }
122 
123     @Override
clearOriginalConnection()124     void clearOriginalConnection() {
125         // Do nothing since the original connection is mock object
126     }
127 
getNotifyPhoneAccountChangedCount()128     public int getNotifyPhoneAccountChangedCount() {
129         return mNotifyPhoneAccountChangedCount;
130     }
131 
getLastConnectionEvents()132     public List<String> getLastConnectionEvents() {
133         return mLastConnectionEvents;
134     }
135 
getLastConnectionEventExtras()136     public List<Bundle> getLastConnectionEventExtras() {
137         return mLastConnectionEventExtras;
138     }
139 }
140