Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
Brad Ebinger | 2c93c50 | 2015-10-28 00:23:54 +0000 | [diff] [blame] | 17 | package com.android.server.telecom.tests; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 18 | |
Ihab Awad | 32dd7c3 | 2015-05-28 10:52:20 -0700 | [diff] [blame] | 19 | |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame^] | 20 | import static org.junit.Assert.assertEquals; |
| 21 | import static org.junit.Assert.assertNotNull; |
| 22 | import static org.junit.Assert.assertTrue; |
| 23 | import static org.junit.Assert.fail; |
Brad Ebinger | d0fe76e | 2017-03-20 13:17:15 -0700 | [diff] [blame] | 24 | import static org.mockito.ArgumentMatchers.nullable; |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 25 | import static org.mockito.Matchers.any; |
| 26 | import static org.mockito.Matchers.anyBoolean; |
| 27 | import static org.mockito.Matchers.anyInt; |
| 28 | import static org.mockito.Matchers.anyString; |
| 29 | import static org.mockito.Matchers.eq; |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 30 | import static org.mockito.Matchers.isNull; |
Hall Liu | 8fb1fb7 | 2015-10-22 15:24:40 -0700 | [diff] [blame] | 31 | import static org.mockito.Mockito.doAnswer; |
Tyler Gunn | 93dc55f | 2017-04-18 13:23:18 -0700 | [diff] [blame] | 32 | import static org.mockito.Mockito.doNothing; |
Hall Liu | 8fb1fb7 | 2015-10-22 15:24:40 -0700 | [diff] [blame] | 33 | import static org.mockito.Mockito.doReturn; |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 34 | import static org.mockito.Mockito.mock; |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 35 | import static org.mockito.Mockito.reset; |
Tyler Gunn | ae694b1 | 2015-11-11 17:46:03 -0800 | [diff] [blame] | 36 | import static org.mockito.Mockito.spy; |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 37 | import static org.mockito.Mockito.timeout; |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 38 | import static org.mockito.Mockito.times; |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 39 | import static org.mockito.Mockito.verify; |
Hall Liu | 6d4b66d | 2016-04-01 16:31:13 -0700 | [diff] [blame] | 40 | import static org.mockito.Mockito.when; |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 41 | |
| 42 | import android.content.BroadcastReceiver; |
| 43 | import android.content.ComponentName; |
Hall Liu | 6d4b66d | 2016-04-01 16:31:13 -0700 | [diff] [blame] | 44 | import android.content.ContentResolver; |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 45 | import android.content.Context; |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 46 | import android.content.IContentProvider; |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 47 | import android.content.Intent; |
Ihab Awad | b60f006 | 2015-05-26 16:20:32 -0700 | [diff] [blame] | 48 | import android.media.AudioManager; |
Hall Liu | 8fb1fb7 | 2015-10-22 15:24:40 -0700 | [diff] [blame] | 49 | import android.media.IAudioService; |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 50 | import android.media.ToneGenerator; |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 51 | import android.net.Uri; |
| 52 | import android.os.Bundle; |
| 53 | import android.os.Handler; |
Brad Ebinger | 84771f8 | 2016-05-18 16:57:30 -0700 | [diff] [blame] | 54 | import android.os.Looper; |
Tony Mak | 578a4e6 | 2015-11-23 11:18:51 +0000 | [diff] [blame] | 55 | import android.os.Process; |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 56 | import android.os.UserHandle; |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 57 | import android.provider.BlockedNumberContract; |
Ihab Awad | 0a4b95f | 2015-05-18 10:15:38 -0700 | [diff] [blame] | 58 | import android.telecom.Call; |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 59 | import android.telecom.ConnectionRequest; |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 60 | import android.telecom.DisconnectCause; |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 61 | import android.telecom.ParcelableCall; |
| 62 | import android.telecom.PhoneAccount; |
| 63 | import android.telecom.PhoneAccountHandle; |
| 64 | import android.telecom.TelecomManager; |
Ihab Awad | 32dd7c3 | 2015-05-28 10:52:20 -0700 | [diff] [blame] | 65 | import android.telecom.VideoProfile; |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 66 | |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 67 | import com.android.internal.telecom.IInCallAdapter; |
Brad Ebinger | 7ade5e2 | 2016-04-05 18:43:50 -0700 | [diff] [blame] | 68 | import com.android.server.telecom.AsyncRingtonePlayer; |
Hall Liu | b3979ee | 2015-11-11 16:21:25 -0800 | [diff] [blame] | 69 | import com.android.server.telecom.BluetoothPhoneServiceImpl; |
Abhijith Shastry | b7853c0 | 2016-02-03 12:56:59 -0800 | [diff] [blame] | 70 | import com.android.server.telecom.CallAudioManager; |
Hall Liu | 3037ac6 | 2016-09-22 14:40:03 -0700 | [diff] [blame] | 71 | import com.android.server.telecom.CallerInfoLookupHelper; |
Brad Ebinger | 2c93c50 | 2015-10-28 00:23:54 +0000 | [diff] [blame] | 72 | import com.android.server.telecom.CallsManager; |
Tyler Gunn | ae694b1 | 2015-11-11 17:46:03 -0800 | [diff] [blame] | 73 | import com.android.server.telecom.CallsManagerListenerBase; |
Tyler Gunn | 8bb2b01 | 2017-08-04 09:28:59 -0700 | [diff] [blame] | 74 | import com.android.server.telecom.ClockProxy; |
Hall Liu | 7c92832 | 2016-12-06 18:15:39 -0800 | [diff] [blame] | 75 | import com.android.server.telecom.DefaultDialerCache; |
Brad Ebinger | 2c93c50 | 2015-10-28 00:23:54 +0000 | [diff] [blame] | 76 | import com.android.server.telecom.HeadsetMediaButton; |
| 77 | import com.android.server.telecom.HeadsetMediaButtonFactory; |
| 78 | import com.android.server.telecom.InCallWakeLockController; |
| 79 | import com.android.server.telecom.InCallWakeLockControllerFactory; |
Brad Ebinger | 2c93c50 | 2015-10-28 00:23:54 +0000 | [diff] [blame] | 80 | import com.android.server.telecom.MissedCallNotifier; |
Hall Liu | b3979ee | 2015-11-11 16:21:25 -0800 | [diff] [blame] | 81 | import com.android.server.telecom.PhoneAccountRegistrar; |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 82 | import com.android.server.telecom.PhoneNumberUtilsAdapter; |
| 83 | import com.android.server.telecom.PhoneNumberUtilsAdapterImpl; |
Brad Ebinger | 2c93c50 | 2015-10-28 00:23:54 +0000 | [diff] [blame] | 84 | import com.android.server.telecom.ProximitySensorManager; |
| 85 | import com.android.server.telecom.ProximitySensorManagerFactory; |
| 86 | import com.android.server.telecom.TelecomSystem; |
Hall Liu | 6d4b66d | 2016-04-01 16:31:13 -0700 | [diff] [blame] | 87 | import com.android.server.telecom.Timeouts; |
Tony Mak | 578a4e6 | 2015-11-23 11:18:51 +0000 | [diff] [blame] | 88 | import com.android.server.telecom.components.UserCallIntentProcessor; |
Tyler Gunn | 2b17f23 | 2017-03-08 08:51:00 -0800 | [diff] [blame] | 89 | import com.android.server.telecom.ui.IncomingCallNotifier; |
Tony Mak | a993094 | 2016-01-15 10:57:14 +0000 | [diff] [blame] | 90 | import com.android.server.telecom.ui.MissedCallNotifierImpl.MissedCallNotifierImplFactory; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 91 | |
Hall Liu | 8fb1fb7 | 2015-10-22 15:24:40 -0700 | [diff] [blame] | 92 | import com.google.common.base.Predicate; |
| 93 | |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 94 | import org.mockito.ArgumentCaptor; |
| 95 | import org.mockito.Mock; |
Hall Liu | 8fb1fb7 | 2015-10-22 15:24:40 -0700 | [diff] [blame] | 96 | import org.mockito.invocation.InvocationOnMock; |
| 97 | import org.mockito.stubbing.Answer; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 98 | |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 99 | import java.util.ArrayList; |
| 100 | import java.util.List; |
Hall Liu | 609992b | 2016-08-31 15:48:51 -0700 | [diff] [blame] | 101 | import java.util.concurrent.CountDownLatch; |
| 102 | import java.util.concurrent.TimeUnit; |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 103 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 104 | /** |
| 105 | * Implements mocks and functionality required to implement telecom system tests. |
| 106 | */ |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 107 | public class TelecomSystemTest extends TelecomTestCase { |
| 108 | |
Ihab Awad | 32dd7c3 | 2015-05-28 10:52:20 -0700 | [diff] [blame] | 109 | static final int TEST_POLL_INTERVAL = 10; // milliseconds |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 110 | static final int TEST_TIMEOUT = 1000; // milliseconds |
| 111 | |
Tyler Gunn | 8bb2b01 | 2017-08-04 09:28:59 -0700 | [diff] [blame] | 112 | // Purposely keep the connect time (which is wall clock) and elapsed time (which is time since |
| 113 | // boot) different to test that wall clock time operations and elapsed time operations perform |
| 114 | // as they individually should. |
| 115 | static final long TEST_CREATE_TIME = 100; |
| 116 | static final long TEST_CREATE_ELAPSED_TIME = 200; |
| 117 | static final long TEST_CONNECT_TIME = 1000; |
| 118 | static final long TEST_CONNECT_ELAPSED_TIME = 2000; |
| 119 | static final long TEST_DISCONNECT_TIME = 8000; |
| 120 | static final long TEST_DISCONNECT_ELAPSED_TIME = 4000; |
| 121 | |
Tyler Gunn | ae694b1 | 2015-11-11 17:46:03 -0800 | [diff] [blame] | 122 | public class HeadsetMediaButtonFactoryF implements HeadsetMediaButtonFactory { |
| 123 | @Override |
| 124 | public HeadsetMediaButton create(Context context, CallsManager callsManager, |
| 125 | TelecomSystem.SyncRoot lock) { |
| 126 | return mHeadsetMediaButton; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | public class ProximitySensorManagerFactoryF implements ProximitySensorManagerFactory { |
| 131 | @Override |
| 132 | public ProximitySensorManager create(Context context, CallsManager callsManager) { |
| 133 | return mProximitySensorManager; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | public class InCallWakeLockControllerFactoryF implements InCallWakeLockControllerFactory { |
| 138 | @Override |
| 139 | public InCallWakeLockController create(Context context, CallsManager callsManager) { |
| 140 | return mInCallWakeLockController; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | public static class MissedCallNotifierFakeImpl extends CallsManagerListenerBase |
| 145 | implements MissedCallNotifier { |
Hall Liu | 3037ac6 | 2016-09-22 14:40:03 -0700 | [diff] [blame] | 146 | List<CallInfo> missedCallsNotified = new ArrayList<>(); |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 147 | |
Tyler Gunn | ae694b1 | 2015-11-11 17:46:03 -0800 | [diff] [blame] | 148 | @Override |
Tony Mak | a993094 | 2016-01-15 10:57:14 +0000 | [diff] [blame] | 149 | public void clearMissedCalls(UserHandle userHandle) { |
Tyler Gunn | ae694b1 | 2015-11-11 17:46:03 -0800 | [diff] [blame] | 150 | |
| 151 | } |
| 152 | |
| 153 | @Override |
Hall Liu | 3037ac6 | 2016-09-22 14:40:03 -0700 | [diff] [blame] | 154 | public void showMissedCallNotification(CallInfo call) { |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 155 | missedCallsNotified.add(call); |
Tyler Gunn | ae694b1 | 2015-11-11 17:46:03 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | @Override |
Hall Liu | 3037ac6 | 2016-09-22 14:40:03 -0700 | [diff] [blame] | 159 | public void reloadAfterBootComplete(CallerInfoLookupHelper callerInfoLookupHelper, |
| 160 | CallInfoFactory callInfoFactory) { } |
Tony Mak | a993094 | 2016-01-15 10:57:14 +0000 | [diff] [blame] | 161 | |
Hall Liu | 3037ac6 | 2016-09-22 14:40:03 -0700 | [diff] [blame] | 162 | @Override |
| 163 | public void reloadFromDatabase(CallerInfoLookupHelper callerInfoLookupHelper, |
| 164 | CallInfoFactory callInfoFactory, UserHandle userHandle) { } |
Tony Mak | a993094 | 2016-01-15 10:57:14 +0000 | [diff] [blame] | 165 | |
| 166 | @Override |
| 167 | public void setCurrentUserHandle(UserHandle userHandle) { |
Tyler Gunn | ae694b1 | 2015-11-11 17:46:03 -0800 | [diff] [blame] | 168 | |
| 169 | } |
| 170 | } |
| 171 | |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 172 | MissedCallNotifierFakeImpl mMissedCallNotifier = new MissedCallNotifierFakeImpl(); |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 173 | private class EmergencyNumberUtilsAdapter extends PhoneNumberUtilsAdapterImpl { |
| 174 | |
| 175 | @Override |
| 176 | public boolean isLocalEmergencyNumber(Context context, String number) { |
| 177 | return mIsEmergencyCall; |
| 178 | } |
| 179 | |
| 180 | @Override |
| 181 | public boolean isPotentialLocalEmergencyNumber(Context context, String number) { |
| 182 | return mIsEmergencyCall; |
| 183 | } |
| 184 | } |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 185 | |
| 186 | private class IncomingCallAddedListener extends CallsManagerListenerBase { |
| 187 | |
| 188 | private final CountDownLatch mCountDownLatch; |
| 189 | |
| 190 | public IncomingCallAddedListener(CountDownLatch latch) { |
| 191 | mCountDownLatch = latch; |
| 192 | } |
| 193 | |
| 194 | @Override |
| 195 | public void onCallAdded(com.android.server.telecom.Call call) { |
| 196 | mCountDownLatch.countDown(); |
| 197 | } |
| 198 | } |
| 199 | |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 200 | PhoneNumberUtilsAdapter mPhoneNumberUtilsAdapter = new EmergencyNumberUtilsAdapter(); |
Tyler Gunn | eaaf074 | 2016-09-15 15:36:38 -0700 | [diff] [blame] | 201 | |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 202 | @Mock HeadsetMediaButton mHeadsetMediaButton; |
| 203 | @Mock ProximitySensorManager mProximitySensorManager; |
| 204 | @Mock InCallWakeLockController mInCallWakeLockController; |
Hall Liu | b3979ee | 2015-11-11 16:21:25 -0800 | [diff] [blame] | 205 | @Mock BluetoothPhoneServiceImpl mBluetoothPhoneServiceImpl; |
Brad Ebinger | 7ade5e2 | 2016-04-05 18:43:50 -0700 | [diff] [blame] | 206 | @Mock AsyncRingtonePlayer mAsyncRingtonePlayer; |
Tyler Gunn | 2b17f23 | 2017-03-08 08:51:00 -0800 | [diff] [blame] | 207 | @Mock IncomingCallNotifier mIncomingCallNotifier; |
Tyler Gunn | 8bb2b01 | 2017-08-04 09:28:59 -0700 | [diff] [blame] | 208 | @Mock ClockProxy mClockProxy; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 209 | |
| 210 | final ComponentName mInCallServiceComponentNameX = |
| 211 | new ComponentName( |
| 212 | "incall-service-package-X", |
| 213 | "incall-service-class-X"); |
| 214 | final ComponentName mInCallServiceComponentNameY = |
| 215 | new ComponentName( |
| 216 | "incall-service-package-Y", |
| 217 | "incall-service-class-Y"); |
| 218 | |
| 219 | InCallServiceFixture mInCallServiceFixtureX; |
| 220 | InCallServiceFixture mInCallServiceFixtureY; |
| 221 | |
| 222 | final ComponentName mConnectionServiceComponentNameA = |
| 223 | new ComponentName( |
| 224 | "connection-service-package-A", |
| 225 | "connection-service-class-A"); |
| 226 | final ComponentName mConnectionServiceComponentNameB = |
| 227 | new ComponentName( |
| 228 | "connection-service-package-B", |
| 229 | "connection-service-class-B"); |
| 230 | |
| 231 | final PhoneAccount mPhoneAccountA0 = |
| 232 | PhoneAccount.builder( |
| 233 | new PhoneAccountHandle( |
| 234 | mConnectionServiceComponentNameA, |
| 235 | "id A 0"), |
| 236 | "Phone account service A ID 0") |
| 237 | .addSupportedUriScheme("tel") |
| 238 | .setCapabilities( |
| 239 | PhoneAccount.CAPABILITY_CALL_PROVIDER | |
Hall Liu | 609992b | 2016-08-31 15:48:51 -0700 | [diff] [blame] | 240 | PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION | |
| 241 | PhoneAccount.CAPABILITY_VIDEO_CALLING) |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 242 | .build(); |
| 243 | final PhoneAccount mPhoneAccountA1 = |
| 244 | PhoneAccount.builder( |
| 245 | new PhoneAccountHandle( |
| 246 | mConnectionServiceComponentNameA, |
| 247 | "id A 1"), |
| 248 | "Phone account service A ID 1") |
| 249 | .addSupportedUriScheme("tel") |
| 250 | .setCapabilities( |
| 251 | PhoneAccount.CAPABILITY_CALL_PROVIDER | |
Tyler Gunn | eaaf074 | 2016-09-15 15:36:38 -0700 | [diff] [blame] | 252 | PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION | |
| 253 | PhoneAccount.CAPABILITY_VIDEO_CALLING) |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 254 | .build(); |
Tyler Gunn | ddec589 | 2016-09-28 10:26:13 -0700 | [diff] [blame] | 255 | final PhoneAccount mPhoneAccountA2 = |
| 256 | PhoneAccount.builder( |
| 257 | new PhoneAccountHandle( |
| 258 | mConnectionServiceComponentNameA, |
| 259 | "id A 2"), |
| 260 | "Phone account service A ID 2") |
| 261 | .addSupportedUriScheme("tel") |
| 262 | .setCapabilities( |
| 263 | PhoneAccount.CAPABILITY_CALL_PROVIDER | |
| 264 | PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION) |
| 265 | .build(); |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 266 | final PhoneAccount mPhoneAccountSelfManaged = |
| 267 | PhoneAccount.builder( |
| 268 | new PhoneAccountHandle( |
| 269 | mConnectionServiceComponentNameA, |
| 270 | "id SM"), |
| 271 | "Phone account service A SM") |
| 272 | .addSupportedUriScheme("tel") |
| 273 | .setCapabilities( |
| 274 | PhoneAccount.CAPABILITY_SELF_MANAGED) |
| 275 | .build(); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 276 | final PhoneAccount mPhoneAccountB0 = |
| 277 | PhoneAccount.builder( |
| 278 | new PhoneAccountHandle( |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 279 | mConnectionServiceComponentNameB, |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 280 | "id B 0"), |
| 281 | "Phone account service B ID 0") |
| 282 | .addSupportedUriScheme("tel") |
| 283 | .setCapabilities( |
| 284 | PhoneAccount.CAPABILITY_CALL_PROVIDER | |
Tyler Gunn | eaaf074 | 2016-09-15 15:36:38 -0700 | [diff] [blame] | 285 | PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION | |
| 286 | PhoneAccount.CAPABILITY_VIDEO_CALLING) |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 287 | .build(); |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 288 | final PhoneAccount mPhoneAccountE0 = |
| 289 | PhoneAccount.builder( |
| 290 | new PhoneAccountHandle( |
| 291 | mConnectionServiceComponentNameA, |
| 292 | "id E 0"), |
| 293 | "Phone account service E ID 0") |
| 294 | .addSupportedUriScheme("tel") |
| 295 | .setCapabilities( |
| 296 | PhoneAccount.CAPABILITY_CALL_PROVIDER | |
| 297 | PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION | |
Brad Ebinger | d1b3669 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 298 | PhoneAccount.CAPABILITY_PLACE_EMERGENCY_CALLS) |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 299 | .build(); |
| 300 | |
| 301 | final PhoneAccount mPhoneAccountE1 = |
| 302 | PhoneAccount.builder( |
| 303 | new PhoneAccountHandle( |
| 304 | mConnectionServiceComponentNameA, |
| 305 | "id E 1"), |
| 306 | "Phone account service E ID 1") |
| 307 | .addSupportedUriScheme("tel") |
| 308 | .setCapabilities( |
| 309 | PhoneAccount.CAPABILITY_CALL_PROVIDER | |
| 310 | PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION | |
Brad Ebinger | d1b3669 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 311 | PhoneAccount.CAPABILITY_PLACE_EMERGENCY_CALLS) |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 312 | .build(); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 313 | |
| 314 | ConnectionServiceFixture mConnectionServiceFixtureA; |
| 315 | ConnectionServiceFixture mConnectionServiceFixtureB; |
Hall Liu | 6d4b66d | 2016-04-01 16:31:13 -0700 | [diff] [blame] | 316 | Timeouts.Adapter mTimeoutsAdapter; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 317 | |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 318 | CallerInfoAsyncQueryFactoryFixture mCallerInfoAsyncQueryFactoryFixture; |
| 319 | |
Hall Liu | 8fb1fb7 | 2015-10-22 15:24:40 -0700 | [diff] [blame] | 320 | IAudioService mAudioService; |
| 321 | |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 322 | TelecomSystem mTelecomSystem; |
| 323 | |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 324 | Context mSpyContext; |
| 325 | |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 326 | private int mNumOutgoingCallsMade; |
| 327 | |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 328 | private boolean mIsEmergencyCall; |
| 329 | |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 330 | class IdPair { |
| 331 | final String mConnectionId; |
| 332 | final String mCallId; |
| 333 | |
| 334 | public IdPair(String connectionId, String callId) { |
| 335 | this.mConnectionId = connectionId; |
| 336 | this.mCallId = callId; |
| 337 | } |
| 338 | } |
| 339 | |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 340 | @Override |
| 341 | public void setUp() throws Exception { |
| 342 | super.setUp(); |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 343 | mSpyContext = mComponentContextFixture.getTestDouble().getApplicationContext(); |
| 344 | doReturn(mSpyContext).when(mSpyContext).getApplicationContext(); |
Tyler Gunn | 93dc55f | 2017-04-18 13:23:18 -0700 | [diff] [blame] | 345 | doNothing().when(mSpyContext).sendBroadcastAsUser(any(), any(), any()); |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 346 | |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 347 | mNumOutgoingCallsMade = 0; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 348 | |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 349 | mIsEmergencyCall = false; |
| 350 | |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 351 | // First set up information about the In-Call services in the mock Context, since |
| 352 | // Telecom will search for these as soon as it is instantiated |
| 353 | setupInCallServices(); |
| 354 | |
| 355 | // Next, create the TelecomSystem, our system under test |
| 356 | setupTelecomSystem(); |
| 357 | |
| 358 | // Finally, register the ConnectionServices with the PhoneAccountRegistrar of the |
| 359 | // now-running TelecomSystem |
| 360 | setupConnectionServices(); |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 361 | |
| 362 | waitForHandlerAction(new Handler(Looper.getMainLooper()), TEST_TIMEOUT); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | @Override |
| 366 | public void tearDown() throws Exception { |
Hall Liu | 486cb19 | 2016-10-21 18:23:33 -0700 | [diff] [blame] | 367 | mTelecomSystem.getCallsManager().getCallAudioManager() |
| 368 | .getCallAudioRouteStateMachine().quitNow(); |
| 369 | mTelecomSystem.getCallsManager().getCallAudioManager() |
| 370 | .getCallAudioModeStateMachine().quitNow(); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 371 | mTelecomSystem = null; |
| 372 | super.tearDown(); |
| 373 | } |
| 374 | |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 375 | protected ParcelableCall makeConferenceCall() throws Exception { |
| 376 | IdPair callId1 = startAndMakeActiveOutgoingCall("650-555-1212", |
| 377 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 378 | |
| 379 | IdPair callId2 = startAndMakeActiveOutgoingCall("650-555-1213", |
| 380 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 381 | |
| 382 | IInCallAdapter inCallAdapter = mInCallServiceFixtureX.getInCallAdapter(); |
| 383 | inCallAdapter.conference(callId1.mCallId, callId2.mCallId); |
| 384 | // Wait for wacky non-deterministic behavior |
| 385 | Thread.sleep(200); |
| 386 | ParcelableCall call1 = mInCallServiceFixtureX.getCall(callId1.mCallId); |
| 387 | ParcelableCall call2 = mInCallServiceFixtureX.getCall(callId2.mCallId); |
| 388 | // Check that the two calls end up with a parent in the end |
| 389 | assertNotNull(call1.getParentCallId()); |
| 390 | assertNotNull(call2.getParentCallId()); |
| 391 | assertEquals(call1.getParentCallId(), call2.getParentCallId()); |
| 392 | |
| 393 | // Check to make sure that the parent call made it to the in-call service |
| 394 | String parentCallId = call1.getParentCallId(); |
| 395 | ParcelableCall conferenceCall = mInCallServiceFixtureX.getCall(parentCallId); |
| 396 | assertEquals(2, conferenceCall.getChildCallIds().size()); |
| 397 | assertTrue(conferenceCall.getChildCallIds().contains(callId1.mCallId)); |
| 398 | assertTrue(conferenceCall.getChildCallIds().contains(callId2.mCallId)); |
| 399 | return conferenceCall; |
| 400 | } |
| 401 | |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 402 | private void setupTelecomSystem() throws Exception { |
Tyler Gunn | ae694b1 | 2015-11-11 17:46:03 -0800 | [diff] [blame] | 403 | // Use actual implementations instead of mocking the interface out. |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 404 | HeadsetMediaButtonFactory headsetMediaButtonFactory = |
Tyler Gunn | ae694b1 | 2015-11-11 17:46:03 -0800 | [diff] [blame] | 405 | spy(new HeadsetMediaButtonFactoryF()); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 406 | ProximitySensorManagerFactory proximitySensorManagerFactory = |
Tyler Gunn | ae694b1 | 2015-11-11 17:46:03 -0800 | [diff] [blame] | 407 | spy(new ProximitySensorManagerFactoryF()); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 408 | InCallWakeLockControllerFactory inCallWakeLockControllerFactory = |
Tyler Gunn | ae694b1 | 2015-11-11 17:46:03 -0800 | [diff] [blame] | 409 | spy(new InCallWakeLockControllerFactoryF()); |
Hall Liu | 8fb1fb7 | 2015-10-22 15:24:40 -0700 | [diff] [blame] | 410 | mAudioService = setupAudioService(); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 411 | |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 412 | mCallerInfoAsyncQueryFactoryFixture = new CallerInfoAsyncQueryFactoryFixture(); |
| 413 | |
Hall Liu | 6d4b66d | 2016-04-01 16:31:13 -0700 | [diff] [blame] | 414 | mTimeoutsAdapter = mock(Timeouts.Adapter.class); |
| 415 | when(mTimeoutsAdapter.getCallScreeningTimeoutMillis(any(ContentResolver.class))) |
Hall Liu | 609992b | 2016-08-31 15:48:51 -0700 | [diff] [blame] | 416 | .thenReturn(TEST_TIMEOUT / 5L); |
Tyler Gunn | 2b17f23 | 2017-03-08 08:51:00 -0800 | [diff] [blame] | 417 | mIncomingCallNotifier = mock(IncomingCallNotifier.class); |
Tyler Gunn | 8bb2b01 | 2017-08-04 09:28:59 -0700 | [diff] [blame] | 418 | mClockProxy = mock(ClockProxy.class); |
| 419 | when(mClockProxy.currentTimeMillis()).thenReturn(TEST_CREATE_TIME); |
| 420 | when(mClockProxy.elapsedRealtime()).thenReturn(TEST_CREATE_ELAPSED_TIME); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 421 | mTelecomSystem = new TelecomSystem( |
| 422 | mComponentContextFixture.getTestDouble(), |
Tony Mak | a993094 | 2016-01-15 10:57:14 +0000 | [diff] [blame] | 423 | new MissedCallNotifierImplFactory() { |
| 424 | @Override |
| 425 | public MissedCallNotifier makeMissedCallNotifierImpl(Context context, |
Hall Liu | 7c92832 | 2016-12-06 18:15:39 -0800 | [diff] [blame] | 426 | PhoneAccountRegistrar phoneAccountRegistrar, |
| 427 | DefaultDialerCache defaultDialerCache) { |
Tony Mak | a993094 | 2016-01-15 10:57:14 +0000 | [diff] [blame] | 428 | return mMissedCallNotifier; |
| 429 | } |
| 430 | }, |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 431 | mCallerInfoAsyncQueryFactoryFixture.getTestDouble(), |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 432 | headsetMediaButtonFactory, |
| 433 | proximitySensorManagerFactory, |
Hall Liu | 8fb1fb7 | 2015-10-22 15:24:40 -0700 | [diff] [blame] | 434 | inCallWakeLockControllerFactory, |
| 435 | new CallAudioManager.AudioServiceFactory() { |
| 436 | @Override |
| 437 | public IAudioService getAudioService() { |
| 438 | return mAudioService; |
| 439 | } |
Hall Liu | b3979ee | 2015-11-11 16:21:25 -0800 | [diff] [blame] | 440 | }, |
| 441 | new BluetoothPhoneServiceImpl.BluetoothPhoneServiceImplFactory() { |
| 442 | @Override |
| 443 | public BluetoothPhoneServiceImpl makeBluetoothPhoneServiceImpl(Context context, |
| 444 | TelecomSystem.SyncRoot lock, CallsManager callsManager, |
| 445 | PhoneAccountRegistrar phoneAccountRegistrar) { |
| 446 | return mBluetoothPhoneServiceImpl; |
| 447 | } |
Brad Ebinger | 7ade5e2 | 2016-04-05 18:43:50 -0700 | [diff] [blame] | 448 | }, |
Hall Liu | 6d4b66d | 2016-04-01 16:31:13 -0700 | [diff] [blame] | 449 | mTimeoutsAdapter, |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 450 | mAsyncRingtonePlayer, |
Tyler Gunn | eaaf074 | 2016-09-15 15:36:38 -0700 | [diff] [blame] | 451 | mPhoneNumberUtilsAdapter, |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 452 | mIncomingCallNotifier, |
Tyler Gunn | 02e00dd | 2017-08-24 15:44:02 -0700 | [diff] [blame] | 453 | (streamType, volume) -> mock(ToneGenerator.class), |
Tyler Gunn | 8bb2b01 | 2017-08-04 09:28:59 -0700 | [diff] [blame] | 454 | mClockProxy); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 455 | |
Hall Liu | 1d903dd | 2015-10-09 15:56:44 -0700 | [diff] [blame] | 456 | mComponentContextFixture.setTelecomManager(new TelecomManager( |
| 457 | mComponentContextFixture.getTestDouble(), |
| 458 | mTelecomSystem.getTelecomServiceImpl().getBinder())); |
| 459 | |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 460 | verify(headsetMediaButtonFactory).create( |
| 461 | eq(mComponentContextFixture.getTestDouble().getApplicationContext()), |
Ihab Awad | 731369c | 2015-05-19 09:23:21 -0700 | [diff] [blame] | 462 | any(CallsManager.class), |
| 463 | any(TelecomSystem.SyncRoot.class)); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 464 | verify(proximitySensorManagerFactory).create( |
| 465 | eq(mComponentContextFixture.getTestDouble().getApplicationContext()), |
| 466 | any(CallsManager.class)); |
| 467 | verify(inCallWakeLockControllerFactory).create( |
| 468 | eq(mComponentContextFixture.getTestDouble().getApplicationContext()), |
| 469 | any(CallsManager.class)); |
| 470 | } |
| 471 | |
| 472 | private void setupConnectionServices() throws Exception { |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame^] | 473 | mConnectionServiceFixtureA = new ConnectionServiceFixture(mContext); |
| 474 | mConnectionServiceFixtureB = new ConnectionServiceFixture(mContext); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 475 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 476 | mComponentContextFixture.addConnectionService(mConnectionServiceComponentNameA, |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 477 | mConnectionServiceFixtureA.getTestDouble()); |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 478 | mComponentContextFixture.addConnectionService(mConnectionServiceComponentNameB, |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 479 | mConnectionServiceFixtureB.getTestDouble()); |
| 480 | |
| 481 | mTelecomSystem.getPhoneAccountRegistrar().registerPhoneAccount(mPhoneAccountA0); |
| 482 | mTelecomSystem.getPhoneAccountRegistrar().registerPhoneAccount(mPhoneAccountA1); |
Tyler Gunn | ddec589 | 2016-09-28 10:26:13 -0700 | [diff] [blame] | 483 | mTelecomSystem.getPhoneAccountRegistrar().registerPhoneAccount(mPhoneAccountA2); |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 484 | mTelecomSystem.getPhoneAccountRegistrar().registerPhoneAccount(mPhoneAccountSelfManaged); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 485 | mTelecomSystem.getPhoneAccountRegistrar().registerPhoneAccount(mPhoneAccountB0); |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 486 | mTelecomSystem.getPhoneAccountRegistrar().registerPhoneAccount(mPhoneAccountE0); |
| 487 | mTelecomSystem.getPhoneAccountRegistrar().registerPhoneAccount(mPhoneAccountE1); |
Ihab Awad | 0a4b95f | 2015-05-18 10:15:38 -0700 | [diff] [blame] | 488 | |
| 489 | mTelecomSystem.getPhoneAccountRegistrar().setUserSelectedOutgoingPhoneAccount( |
Tony Mak | 4a3e2fd | 2015-12-04 11:58:38 +0000 | [diff] [blame] | 490 | mPhoneAccountA0.getAccountHandle(), Process.myUserHandle()); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | private void setupInCallServices() throws Exception { |
| 494 | mComponentContextFixture.putResource( |
| 495 | com.android.server.telecom.R.string.ui_default_package, |
| 496 | mInCallServiceComponentNameX.getPackageName()); |
| 497 | mComponentContextFixture.putResource( |
| 498 | com.android.server.telecom.R.string.incall_default_class, |
| 499 | mInCallServiceComponentNameX.getClassName()); |
Brad Ebinger | f4745b6 | 2015-12-08 17:57:59 -0800 | [diff] [blame] | 500 | mComponentContextFixture.putBooleanResource( |
| 501 | com.android.internal.R.bool.config_voice_capable, true); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 502 | |
| 503 | mInCallServiceFixtureX = new InCallServiceFixture(); |
| 504 | mInCallServiceFixtureY = new InCallServiceFixture(); |
| 505 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 506 | mComponentContextFixture.addInCallService(mInCallServiceComponentNameX, |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 507 | mInCallServiceFixtureX.getTestDouble()); |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 508 | mComponentContextFixture.addInCallService(mInCallServiceComponentNameY, |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 509 | mInCallServiceFixtureY.getTestDouble()); |
| 510 | } |
| 511 | |
Hall Liu | 8fb1fb7 | 2015-10-22 15:24:40 -0700 | [diff] [blame] | 512 | /** |
| 513 | * Helper method for setting up the fake audio service. |
| 514 | * Calls to the fake audio service need to toggle the return |
| 515 | * value of AudioManager#isMicrophoneMute. |
| 516 | * @return mock of IAudioService |
| 517 | */ |
| 518 | private IAudioService setupAudioService() { |
| 519 | IAudioService audioService = mock(IAudioService.class); |
Tyler Gunn | ae694b1 | 2015-11-11 17:46:03 -0800 | [diff] [blame] | 520 | |
Hall Liu | 8fb1fb7 | 2015-10-22 15:24:40 -0700 | [diff] [blame] | 521 | final AudioManager fakeAudioManager = |
| 522 | (AudioManager) mComponentContextFixture.getTestDouble() |
| 523 | .getApplicationContext().getSystemService(Context.AUDIO_SERVICE); |
| 524 | |
| 525 | try { |
| 526 | doAnswer(new Answer() { |
| 527 | @Override |
| 528 | public Object answer(InvocationOnMock i) { |
| 529 | Object[] args = i.getArguments(); |
| 530 | doReturn(args[0]).when(fakeAudioManager).isMicrophoneMute(); |
| 531 | return null; |
| 532 | } |
| 533 | }).when(audioService) |
| 534 | .setMicrophoneMute(any(Boolean.class), any(String.class), any(Integer.class)); |
| 535 | |
| 536 | } catch (android.os.RemoteException e) { |
| 537 | // Do nothing, leave the faked microphone state as-is |
| 538 | } |
| 539 | return audioService; |
| 540 | } |
| 541 | |
Brad Ebinger | c301b51 | 2016-03-16 18:27:57 -0700 | [diff] [blame] | 542 | protected String startOutgoingPhoneCallWithNoPhoneAccount(String number, |
| 543 | ConnectionServiceFixture connectionServiceFixture) |
| 544 | throws Exception { |
| 545 | |
| 546 | return startOutgoingPhoneCallPendingCreateConnection(number, null, |
| 547 | connectionServiceFixture, Process.myUserHandle(), VideoProfile.STATE_AUDIO_ONLY); |
| 548 | } |
| 549 | |
| 550 | protected IdPair outgoingCallPhoneAccountSelected(PhoneAccountHandle phoneAccountHandle, |
| 551 | int startingNumConnections, int startingNumCalls, |
| 552 | ConnectionServiceFixture connectionServiceFixture) throws Exception { |
| 553 | |
| 554 | IdPair ids = outgoingCallCreateConnectionComplete(startingNumConnections, startingNumCalls, |
| 555 | phoneAccountHandle, connectionServiceFixture); |
| 556 | |
| 557 | connectionServiceFixture.sendSetDialing(ids.mConnectionId); |
| 558 | assertEquals(Call.STATE_DIALING, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 559 | assertEquals(Call.STATE_DIALING, mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
| 560 | |
| 561 | connectionServiceFixture.sendSetVideoState(ids.mConnectionId); |
| 562 | |
| 563 | connectionServiceFixture.sendSetActive(ids.mConnectionId); |
| 564 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 565 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
| 566 | |
| 567 | return ids; |
| 568 | } |
| 569 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 570 | protected IdPair startOutgoingPhoneCall(String number, PhoneAccountHandle phoneAccountHandle, |
| 571 | ConnectionServiceFixture connectionServiceFixture, UserHandle initiatingUser) |
| 572 | throws Exception { |
Brad Ebinger | c301b51 | 2016-03-16 18:27:57 -0700 | [diff] [blame] | 573 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 574 | return startOutgoingPhoneCall(number, phoneAccountHandle, connectionServiceFixture, |
| 575 | initiatingUser, VideoProfile.STATE_AUDIO_ONLY); |
| 576 | } |
| 577 | |
| 578 | protected IdPair startOutgoingPhoneCall(String number, PhoneAccountHandle phoneAccountHandle, |
| 579 | ConnectionServiceFixture connectionServiceFixture, UserHandle initiatingUser, |
| 580 | int videoState) throws Exception { |
Brad Ebinger | c301b51 | 2016-03-16 18:27:57 -0700 | [diff] [blame] | 581 | int startingNumConnections = connectionServiceFixture.mConnectionById.size(); |
| 582 | int startingNumCalls = mInCallServiceFixtureX.mCallById.size(); |
| 583 | |
Hall Liu | 130209c | 2017-11-17 17:17:57 -0800 | [diff] [blame] | 584 | startOutgoingPhoneCallPendingCreateConnection(number, phoneAccountHandle, |
Brad Ebinger | c301b51 | 2016-03-16 18:27:57 -0700 | [diff] [blame] | 585 | connectionServiceFixture, initiatingUser, videoState); |
| 586 | |
| 587 | return outgoingCallCreateConnectionComplete(startingNumConnections, startingNumCalls, |
| 588 | phoneAccountHandle, connectionServiceFixture); |
| 589 | } |
| 590 | |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 591 | protected IdPair triggerEmergencyRedial(PhoneAccountHandle phoneAccountHandle, |
| 592 | ConnectionServiceFixture connectionServiceFixture, IdPair emergencyIds) |
| 593 | throws Exception { |
| 594 | int startingNumConnections = connectionServiceFixture.mConnectionById.size(); |
| 595 | int startingNumCalls = mInCallServiceFixtureX.mCallById.size(); |
| 596 | |
| 597 | // Send the message to disconnect the Emergency call due to an error. |
| 598 | // CreateConnectionProcessor should now try the second SIM account |
| 599 | connectionServiceFixture.sendSetDisconnected(emergencyIds.mConnectionId, |
| 600 | DisconnectCause.ERROR); |
| 601 | waitForHandlerAction(new Handler(Looper.getMainLooper()), TEST_TIMEOUT); |
| 602 | assertEquals(Call.STATE_DIALING, mInCallServiceFixtureX.getCall( |
| 603 | emergencyIds.mCallId).getState()); |
| 604 | assertEquals(Call.STATE_DIALING, mInCallServiceFixtureY.getCall( |
| 605 | emergencyIds.mCallId).getState()); |
| 606 | |
| 607 | return redialingCallCreateConnectionComplete(startingNumConnections, startingNumCalls, |
| 608 | phoneAccountHandle, connectionServiceFixture); |
| 609 | } |
| 610 | |
| 611 | protected IdPair startOutgoingEmergencyCall(String number, |
Brad Ebinger | c301b51 | 2016-03-16 18:27:57 -0700 | [diff] [blame] | 612 | PhoneAccountHandle phoneAccountHandle, |
| 613 | ConnectionServiceFixture connectionServiceFixture, UserHandle initiatingUser, |
| 614 | int videoState) throws Exception { |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 615 | int startingNumConnections = connectionServiceFixture.mConnectionById.size(); |
| 616 | int startingNumCalls = mInCallServiceFixtureX.mCallById.size(); |
| 617 | |
| 618 | mIsEmergencyCall = true; |
| 619 | // Call will not use the ordered broadcaster, since it is an Emergency Call |
| 620 | startOutgoingPhoneCallWaitForBroadcaster(number, phoneAccountHandle, |
| 621 | connectionServiceFixture, initiatingUser, videoState, true /*isEmergency*/); |
| 622 | |
| 623 | return outgoingCallCreateConnectionComplete(startingNumConnections, startingNumCalls, |
| 624 | phoneAccountHandle, connectionServiceFixture); |
| 625 | } |
| 626 | |
| 627 | protected void startOutgoingPhoneCallWaitForBroadcaster(String number, |
| 628 | PhoneAccountHandle phoneAccountHandle, |
| 629 | ConnectionServiceFixture connectionServiceFixture, UserHandle initiatingUser, |
| 630 | int videoState, boolean isEmergency) throws Exception { |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 631 | reset(connectionServiceFixture.getTestDouble(), mInCallServiceFixtureX.getTestDouble(), |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 632 | mInCallServiceFixtureY.getTestDouble()); |
| 633 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 634 | assertEquals(mInCallServiceFixtureX.mCallById.size(), |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 635 | mInCallServiceFixtureY.mCallById.size()); |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 636 | assertEquals((mInCallServiceFixtureX.mInCallAdapter != null), |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 637 | (mInCallServiceFixtureY.mInCallAdapter != null)); |
| 638 | |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 639 | mNumOutgoingCallsMade++; |
Brad Ebinger | c301b51 | 2016-03-16 18:27:57 -0700 | [diff] [blame] | 640 | |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 641 | boolean hasInCallAdapter = mInCallServiceFixtureX.mInCallAdapter != null; |
| 642 | |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 643 | Intent actionCallIntent = new Intent(); |
| 644 | actionCallIntent.setData(Uri.parse("tel:" + number)); |
| 645 | actionCallIntent.putExtra(Intent.EXTRA_PHONE_NUMBER, number); |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 646 | if(isEmergency) { |
| 647 | actionCallIntent.setAction(Intent.ACTION_CALL_EMERGENCY); |
| 648 | } else { |
| 649 | actionCallIntent.setAction(Intent.ACTION_CALL); |
| 650 | } |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 651 | if (phoneAccountHandle != null) { |
| 652 | actionCallIntent.putExtra( |
| 653 | TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, |
| 654 | phoneAccountHandle); |
| 655 | } |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 656 | if (videoState != VideoProfile.STATE_AUDIO_ONLY) { |
| 657 | actionCallIntent.putExtra(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, videoState); |
| 658 | } |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 659 | |
Tony Mak | 578a4e6 | 2015-11-23 11:18:51 +0000 | [diff] [blame] | 660 | final UserHandle userHandle = initiatingUser; |
Brad Ebinger | f4745b6 | 2015-12-08 17:57:59 -0800 | [diff] [blame] | 661 | Context localAppContext = mComponentContextFixture.getTestDouble().getApplicationContext(); |
| 662 | new UserCallIntentProcessor(localAppContext, userHandle).processIntent( |
| 663 | actionCallIntent, null, true /* hasCallAppOp*/); |
| 664 | // UserCallIntentProcessor's mContext.sendBroadcastAsUser(...) will call to an empty method |
| 665 | // as to not actually try to send an intent to PrimaryCallReceiver. We verify that it was |
| 666 | // called correctly in order to continue. |
| 667 | verify(localAppContext).sendBroadcastAsUser(actionCallIntent, UserHandle.SYSTEM); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 668 | mTelecomSystem.getCallIntentProcessor().processIntent(actionCallIntent); |
Brad Ebinger | c37ddf1 | 2016-10-18 13:43:23 -0700 | [diff] [blame] | 669 | // Wait for handler to start CallerInfo lookup. |
| 670 | waitForHandlerAction(new Handler(Looper.getMainLooper()), TEST_TIMEOUT); |
| 671 | // Send the CallerInfo lookup reply. |
| 672 | mCallerInfoAsyncQueryFactoryFixture.mRequests.forEach( |
| 673 | CallerInfoAsyncQueryFactoryFixture.Request::reply); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 674 | |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 675 | boolean isSelfManaged = phoneAccountHandle == mPhoneAccountSelfManaged.getAccountHandle(); |
| 676 | if (!hasInCallAdapter && !isSelfManaged) { |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 677 | verify(mInCallServiceFixtureX.getTestDouble()) |
| 678 | .setInCallAdapter( |
| 679 | any(IInCallAdapter.class)); |
| 680 | verify(mInCallServiceFixtureY.getTestDouble()) |
| 681 | .setInCallAdapter( |
| 682 | any(IInCallAdapter.class)); |
| 683 | } |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | protected String startOutgoingPhoneCallPendingCreateConnection(String number, |
| 687 | PhoneAccountHandle phoneAccountHandle, |
| 688 | ConnectionServiceFixture connectionServiceFixture, UserHandle initiatingUser, |
| 689 | int videoState) throws Exception { |
| 690 | startOutgoingPhoneCallWaitForBroadcaster(number,phoneAccountHandle, |
| 691 | connectionServiceFixture, initiatingUser, videoState, false /*isEmergency*/); |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 692 | |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 693 | ArgumentCaptor<Intent> newOutgoingCallIntent = |
| 694 | ArgumentCaptor.forClass(Intent.class); |
| 695 | ArgumentCaptor<BroadcastReceiver> newOutgoingCallReceiver = |
| 696 | ArgumentCaptor.forClass(BroadcastReceiver.class); |
| 697 | |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 698 | if (phoneAccountHandle != mPhoneAccountSelfManaged.getAccountHandle()) { |
| 699 | verify(mComponentContextFixture.getTestDouble().getApplicationContext(), |
| 700 | times(mNumOutgoingCallsMade)) |
| 701 | .sendOrderedBroadcastAsUser( |
| 702 | newOutgoingCallIntent.capture(), |
| 703 | any(UserHandle.class), |
| 704 | anyString(), |
| 705 | anyInt(), |
| 706 | newOutgoingCallReceiver.capture(), |
| 707 | nullable(Handler.class), |
| 708 | anyInt(), |
| 709 | anyString(), |
| 710 | nullable(Bundle.class)); |
| 711 | // Pass on the new outgoing call Intent |
| 712 | // Set a dummy PendingResult so the BroadcastReceiver agrees to accept onReceive() |
| 713 | newOutgoingCallReceiver.getValue().setPendingResult( |
| 714 | new BroadcastReceiver.PendingResult(0, "", null, 0, true, false, null, 0, 0)); |
| 715 | newOutgoingCallReceiver.getValue().setResultData( |
| 716 | newOutgoingCallIntent.getValue().getStringExtra(Intent.EXTRA_PHONE_NUMBER)); |
| 717 | newOutgoingCallReceiver.getValue().onReceive(mComponentContextFixture.getTestDouble(), |
| 718 | newOutgoingCallIntent.getValue()); |
| 719 | } |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 720 | |
Brad Ebinger | c301b51 | 2016-03-16 18:27:57 -0700 | [diff] [blame] | 721 | return mInCallServiceFixtureX.mLatestCallId; |
| 722 | } |
| 723 | |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 724 | // When Telecom is redialing due to an error, we need to make sure the number of connections |
| 725 | // increase, but not the number of Calls in the InCallService. |
| 726 | protected IdPair redialingCallCreateConnectionComplete(int startingNumConnections, |
| 727 | int startingNumCalls, PhoneAccountHandle phoneAccountHandle, |
| 728 | ConnectionServiceFixture connectionServiceFixture) throws Exception { |
| 729 | |
| 730 | assertEquals(startingNumConnections + 1, connectionServiceFixture.mConnectionById.size()); |
| 731 | |
| 732 | verify(connectionServiceFixture.getTestDouble()) |
| 733 | .createConnection(eq(phoneAccountHandle), anyString(), any(ConnectionRequest.class), |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 734 | eq(false)/*isIncoming*/, anyBoolean(), any()); |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 735 | // Wait for handleCreateConnectionComplete |
| 736 | waitForHandlerAction(new Handler(Looper.getMainLooper()), TEST_TIMEOUT); |
| 737 | |
| 738 | // Make sure the number of registered InCallService Calls stays the same. |
| 739 | assertEquals(startingNumCalls, mInCallServiceFixtureX.mCallById.size()); |
| 740 | assertEquals(startingNumCalls, mInCallServiceFixtureY.mCallById.size()); |
| 741 | |
| 742 | assertEquals(mInCallServiceFixtureX.mLatestCallId, mInCallServiceFixtureY.mLatestCallId); |
| 743 | |
| 744 | return new IdPair(connectionServiceFixture.mLatestConnectionId, |
| 745 | mInCallServiceFixtureX.mLatestCallId); |
| 746 | } |
| 747 | |
Brad Ebinger | c301b51 | 2016-03-16 18:27:57 -0700 | [diff] [blame] | 748 | protected IdPair outgoingCallCreateConnectionComplete(int startingNumConnections, |
| 749 | int startingNumCalls, PhoneAccountHandle phoneAccountHandle, |
| 750 | ConnectionServiceFixture connectionServiceFixture) throws Exception { |
| 751 | |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 752 | assertEquals(startingNumConnections + 1, connectionServiceFixture.mConnectionById.size()); |
| 753 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 754 | verify(connectionServiceFixture.getTestDouble()) |
| 755 | .createConnection(eq(phoneAccountHandle), anyString(), any(ConnectionRequest.class), |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 756 | eq(false)/*isIncoming*/, anyBoolean(), any()); |
Brad Ebinger | 84771f8 | 2016-05-18 16:57:30 -0700 | [diff] [blame] | 757 | // Wait for handleCreateConnectionComplete |
| 758 | waitForHandlerAction(new Handler(Looper.getMainLooper()), TEST_TIMEOUT); |
Hall Liu | b3ce510 | 2016-07-14 12:53:08 -0700 | [diff] [blame] | 759 | // Wait for the callback in ConnectionService#onAdapterAttached to execute. |
| 760 | waitForHandlerAction(new Handler(Looper.getMainLooper()), TEST_TIMEOUT); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 761 | |
Tyler Gunn | ddb03e1 | 2017-05-12 11:54:41 -0700 | [diff] [blame] | 762 | // Ensure callback to CS on successful creation happened. |
| 763 | verify(connectionServiceFixture.getTestDouble(), timeout(TEST_TIMEOUT)) |
| 764 | .createConnectionComplete(anyString(), any()); |
| 765 | |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 766 | if (phoneAccountHandle == mPhoneAccountSelfManaged.getAccountHandle()) { |
| 767 | assertEquals(startingNumCalls, mInCallServiceFixtureX.mCallById.size()); |
| 768 | assertEquals(startingNumCalls, mInCallServiceFixtureY.mCallById.size()); |
| 769 | } else { |
| 770 | assertEquals(startingNumCalls + 1, mInCallServiceFixtureX.mCallById.size()); |
| 771 | assertEquals(startingNumCalls + 1, mInCallServiceFixtureY.mCallById.size()); |
| 772 | } |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 773 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 774 | assertEquals(mInCallServiceFixtureX.mLatestCallId, mInCallServiceFixtureY.mLatestCallId); |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 775 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 776 | return new IdPair(connectionServiceFixture.mLatestConnectionId, |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 777 | mInCallServiceFixtureX.mLatestCallId); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 780 | protected IdPair startIncomingPhoneCall( |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 781 | String number, |
| 782 | PhoneAccountHandle phoneAccountHandle, |
Ihab Awad | 32dd7c3 | 2015-05-28 10:52:20 -0700 | [diff] [blame] | 783 | final ConnectionServiceFixture connectionServiceFixture) throws Exception { |
Tyler Gunn | 42ef808 | 2015-11-24 15:34:34 -0800 | [diff] [blame] | 784 | return startIncomingPhoneCall(number, phoneAccountHandle, VideoProfile.STATE_AUDIO_ONLY, |
| 785 | connectionServiceFixture); |
| 786 | } |
| 787 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 788 | protected IdPair startIncomingPhoneCall( |
Tyler Gunn | 42ef808 | 2015-11-24 15:34:34 -0800 | [diff] [blame] | 789 | String number, |
| 790 | PhoneAccountHandle phoneAccountHandle, |
| 791 | int videoState, |
| 792 | final ConnectionServiceFixture connectionServiceFixture) throws Exception { |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 793 | reset(connectionServiceFixture.getTestDouble(), mInCallServiceFixtureX.getTestDouble(), |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 794 | mInCallServiceFixtureY.getTestDouble()); |
| 795 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 796 | assertEquals(mInCallServiceFixtureX.mCallById.size(), |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 797 | mInCallServiceFixtureY.mCallById.size()); |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 798 | assertEquals((mInCallServiceFixtureX.mInCallAdapter != null), |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 799 | (mInCallServiceFixtureY.mInCallAdapter != null)); |
Ihab Awad | 32dd7c3 | 2015-05-28 10:52:20 -0700 | [diff] [blame] | 800 | final int startingNumConnections = connectionServiceFixture.mConnectionById.size(); |
| 801 | final int startingNumCalls = mInCallServiceFixtureX.mCallById.size(); |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 802 | boolean hasInCallAdapter = mInCallServiceFixtureX.mInCallAdapter != null; |
Abhijith Shastry | b7853c0 | 2016-02-03 12:56:59 -0800 | [diff] [blame] | 803 | connectionServiceFixture.mConnectionServiceDelegate.mVideoState = videoState; |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 804 | CountDownLatch incomingCallAddedLatch = new CountDownLatch(1); |
| 805 | IncomingCallAddedListener callAddedListener = |
| 806 | new IncomingCallAddedListener(incomingCallAddedLatch); |
| 807 | mTelecomSystem.getCallsManager().addListener(callAddedListener); |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 808 | |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 809 | Bundle extras = new Bundle(); |
| 810 | extras.putParcelable( |
Yorke Lee | 69fa897 | 2015-06-08 11:25:32 -0700 | [diff] [blame] | 811 | TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 812 | Uri.fromParts(PhoneAccount.SCHEME_TEL, number, null)); |
| 813 | mTelecomSystem.getTelecomServiceImpl().getBinder() |
| 814 | .addNewIncomingCall(phoneAccountHandle, extras); |
| 815 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 816 | verify(connectionServiceFixture.getTestDouble()) |
| 817 | .createConnection(any(PhoneAccountHandle.class), anyString(), |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 818 | any(ConnectionRequest.class), eq(true), eq(false), any()); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 819 | |
Brad Ebinger | c37ddf1 | 2016-10-18 13:43:23 -0700 | [diff] [blame] | 820 | // Wait for the handler to start the CallerInfo lookup |
| 821 | waitForHandlerAction(new Handler(Looper.getMainLooper()), TEST_TIMEOUT); |
Tyler Gunn | ddb03e1 | 2017-05-12 11:54:41 -0700 | [diff] [blame] | 822 | |
| 823 | // Ensure callback to CS on successful creation happened. |
| 824 | verify(connectionServiceFixture.getTestDouble(), timeout(TEST_TIMEOUT)) |
| 825 | .createConnectionComplete(anyString(), any()); |
| 826 | |
| 827 | |
Brad Ebinger | c37ddf1 | 2016-10-18 13:43:23 -0700 | [diff] [blame] | 828 | // Process the CallerInfo lookup reply |
| 829 | mCallerInfoAsyncQueryFactoryFixture.mRequests.forEach( |
| 830 | CallerInfoAsyncQueryFactoryFixture.Request::reply); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 831 | |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 832 | //Wait for/Verify call blocking happened asynchronously |
| 833 | incomingCallAddedLatch.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS); |
| 834 | |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 835 | IContentProvider blockedNumberProvider = |
| 836 | mSpyContext.getContentResolver().acquireProvider(BlockedNumberContract.AUTHORITY); |
| 837 | verify(blockedNumberProvider, timeout(TEST_TIMEOUT)).call( |
| 838 | anyString(), |
| 839 | eq(BlockedNumberContract.SystemContract.METHOD_SHOULD_SYSTEM_BLOCK_NUMBER), |
| 840 | eq(number), |
| 841 | isNull(Bundle.class)); |
| 842 | |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 843 | // For the case of incoming calls, Telecom connecting the InCall services and adding the |
| 844 | // Call is triggered by the async completion of the CallerInfoAsyncQuery. Once the Call |
| 845 | // is added, future interactions as triggered by the ConnectionService, through the various |
| 846 | // test fixtures, will be synchronous. |
| 847 | |
Hall Liu | 130209c | 2017-11-17 17:17:57 -0800 | [diff] [blame] | 848 | if (phoneAccountHandle != mPhoneAccountSelfManaged.getAccountHandle()) { |
| 849 | if (!hasInCallAdapter) { |
| 850 | verify(mInCallServiceFixtureX.getTestDouble(), timeout(TEST_TIMEOUT)) |
| 851 | .setInCallAdapter(any(IInCallAdapter.class)); |
| 852 | verify(mInCallServiceFixtureY.getTestDouble(), timeout(TEST_TIMEOUT)) |
| 853 | .setInCallAdapter(any(IInCallAdapter.class)); |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 854 | |
Hall Liu | 130209c | 2017-11-17 17:17:57 -0800 | [diff] [blame] | 855 | // Give the InCallService time to respond |
| 856 | assertTrueWithTimeout(new Predicate<Void>() { |
| 857 | @Override |
| 858 | public boolean apply(Void v) { |
| 859 | return mInCallServiceFixtureX.mInCallAdapter != null; |
| 860 | } |
| 861 | }); |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 862 | |
Hall Liu | 130209c | 2017-11-17 17:17:57 -0800 | [diff] [blame] | 863 | assertTrueWithTimeout(new Predicate<Void>() { |
| 864 | @Override |
| 865 | public boolean apply(Void v) { |
| 866 | return mInCallServiceFixtureY.mInCallAdapter != null; |
| 867 | } |
| 868 | }); |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 869 | |
Hall Liu | 130209c | 2017-11-17 17:17:57 -0800 | [diff] [blame] | 870 | verify(mInCallServiceFixtureX.getTestDouble(), timeout(TEST_TIMEOUT)) |
| 871 | .addCall(any(ParcelableCall.class)); |
| 872 | verify(mInCallServiceFixtureY.getTestDouble(), timeout(TEST_TIMEOUT)) |
| 873 | .addCall(any(ParcelableCall.class)); |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 874 | |
Hall Liu | 130209c | 2017-11-17 17:17:57 -0800 | [diff] [blame] | 875 | // Give the InCallService time to respond |
| 876 | } |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 877 | |
| 878 | assertTrueWithTimeout(new Predicate<Void>() { |
| 879 | @Override |
| 880 | public boolean apply(Void v) { |
| 881 | return startingNumConnections + 1 == |
| 882 | connectionServiceFixture.mConnectionById.size(); |
| 883 | } |
| 884 | }); |
Hall Liu | 130209c | 2017-11-17 17:17:57 -0800 | [diff] [blame] | 885 | |
| 886 | mInCallServiceFixtureX.waitUntilNumCalls(startingNumCalls + 1); |
| 887 | mInCallServiceFixtureY.waitUntilNumCalls(startingNumCalls + 1); |
| 888 | assertEquals(startingNumCalls + 1, mInCallServiceFixtureX.mCallById.size()); |
| 889 | assertEquals(startingNumCalls + 1, mInCallServiceFixtureY.mCallById.size()); |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 890 | |
| 891 | assertEquals(mInCallServiceFixtureX.mLatestCallId, |
| 892 | mInCallServiceFixtureY.mLatestCallId); |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 893 | } |
| 894 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 895 | return new IdPair(connectionServiceFixture.mLatestConnectionId, |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 896 | mInCallServiceFixtureX.mLatestCallId); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 897 | } |
| 898 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 899 | protected IdPair startAndMakeActiveOutgoingCall( |
| 900 | String number, |
| 901 | PhoneAccountHandle phoneAccountHandle, |
| 902 | ConnectionServiceFixture connectionServiceFixture) throws Exception { |
| 903 | return startAndMakeActiveOutgoingCall(number, phoneAccountHandle, connectionServiceFixture, |
| 904 | VideoProfile.STATE_AUDIO_ONLY); |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 905 | } |
| 906 | |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 907 | // A simple outgoing call, verifying that the appropriate connection service is contacted, |
| 908 | // the proper lifecycle is followed, and both In-Call Services are updated correctly. |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 909 | protected IdPair startAndMakeActiveOutgoingCall( |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 910 | String number, |
| 911 | PhoneAccountHandle phoneAccountHandle, |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 912 | ConnectionServiceFixture connectionServiceFixture, int videoState) throws Exception { |
Tony Mak | 578a4e6 | 2015-11-23 11:18:51 +0000 | [diff] [blame] | 913 | IdPair ids = startOutgoingPhoneCall(number, phoneAccountHandle, connectionServiceFixture, |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 914 | Process.myUserHandle(), videoState); |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 915 | |
| 916 | connectionServiceFixture.sendSetDialing(ids.mConnectionId); |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 917 | if (phoneAccountHandle != mPhoneAccountSelfManaged.getAccountHandle()) { |
| 918 | assertEquals(Call.STATE_DIALING, |
| 919 | mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 920 | assertEquals(Call.STATE_DIALING, |
| 921 | mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
| 922 | } |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 923 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 924 | connectionServiceFixture.sendSetVideoState(ids.mConnectionId); |
| 925 | |
Tyler Gunn | 8bb2b01 | 2017-08-04 09:28:59 -0700 | [diff] [blame] | 926 | when(mClockProxy.currentTimeMillis()).thenReturn(TEST_CONNECT_TIME); |
| 927 | when(mClockProxy.elapsedRealtime()).thenReturn(TEST_CONNECT_ELAPSED_TIME); |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 928 | connectionServiceFixture.sendSetActive(ids.mConnectionId); |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 929 | if (phoneAccountHandle != mPhoneAccountSelfManaged.getAccountHandle()) { |
| 930 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 931 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
| 932 | } |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 933 | return ids; |
| 934 | } |
| 935 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 936 | protected IdPair startAndMakeActiveIncomingCall( |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 937 | String number, |
| 938 | PhoneAccountHandle phoneAccountHandle, |
| 939 | ConnectionServiceFixture connectionServiceFixture) throws Exception { |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 940 | return startAndMakeActiveIncomingCall(number, phoneAccountHandle, connectionServiceFixture, |
| 941 | VideoProfile.STATE_AUDIO_ONLY); |
| 942 | } |
| 943 | |
| 944 | // A simple incoming call, similar in scope to the previous test |
| 945 | protected IdPair startAndMakeActiveIncomingCall( |
| 946 | String number, |
| 947 | PhoneAccountHandle phoneAccountHandle, |
| 948 | ConnectionServiceFixture connectionServiceFixture, |
| 949 | int videoState) throws Exception { |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 950 | IdPair ids = startIncomingPhoneCall(number, phoneAccountHandle, connectionServiceFixture); |
| 951 | |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 952 | if (phoneAccountHandle != mPhoneAccountSelfManaged.getAccountHandle()) { |
| 953 | assertEquals(Call.STATE_RINGING, |
| 954 | mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 955 | assertEquals(Call.STATE_RINGING, |
| 956 | mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 957 | |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 958 | mInCallServiceFixtureX.mInCallAdapter |
| 959 | .answerCall(ids.mCallId, videoState); |
Ihab Awad | 32dd7c3 | 2015-05-28 10:52:20 -0700 | [diff] [blame] | 960 | |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 961 | if (!VideoProfile.isVideo(videoState)) { |
| 962 | verify(connectionServiceFixture.getTestDouble()) |
| 963 | .answer(eq(ids.mConnectionId), any()); |
| 964 | } else { |
| 965 | verify(connectionServiceFixture.getTestDouble()) |
| 966 | .answerVideo(eq(ids.mConnectionId), eq(videoState), any()); |
| 967 | } |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 968 | } |
Ihab Awad | 32dd7c3 | 2015-05-28 10:52:20 -0700 | [diff] [blame] | 969 | |
Tyler Gunn | 8bb2b01 | 2017-08-04 09:28:59 -0700 | [diff] [blame] | 970 | when(mClockProxy.currentTimeMillis()).thenReturn(TEST_CONNECT_TIME); |
| 971 | when(mClockProxy.elapsedRealtime()).thenReturn(TEST_CONNECT_ELAPSED_TIME); |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 972 | connectionServiceFixture.sendSetActive(ids.mConnectionId); |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 973 | |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 974 | if (phoneAccountHandle != mPhoneAccountSelfManaged.getAccountHandle()) { |
| 975 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 976 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
| 977 | } |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 978 | return ids; |
| 979 | } |
| 980 | |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 981 | protected IdPair startAndMakeDialingEmergencyCall( |
| 982 | String number, |
| 983 | PhoneAccountHandle phoneAccountHandle, |
| 984 | ConnectionServiceFixture connectionServiceFixture) throws Exception { |
| 985 | IdPair ids = startOutgoingEmergencyCall(number, phoneAccountHandle, |
| 986 | connectionServiceFixture, Process.myUserHandle(), VideoProfile.STATE_AUDIO_ONLY); |
| 987 | |
| 988 | connectionServiceFixture.sendSetDialing(ids.mConnectionId); |
| 989 | assertEquals(Call.STATE_DIALING, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 990 | assertEquals(Call.STATE_DIALING, mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
| 991 | |
| 992 | return ids; |
| 993 | } |
| 994 | |
Ihab Awad | 32dd7c3 | 2015-05-28 10:52:20 -0700 | [diff] [blame] | 995 | protected static void assertTrueWithTimeout(Predicate<Void> predicate) { |
| 996 | int elapsed = 0; |
| 997 | while (elapsed < TEST_TIMEOUT) { |
| 998 | if (predicate.apply(null)) { |
| 999 | return; |
| 1000 | } else { |
| 1001 | try { |
| 1002 | Thread.sleep(TEST_POLL_INTERVAL); |
| 1003 | elapsed += TEST_POLL_INTERVAL; |
| 1004 | } catch (InterruptedException e) { |
| 1005 | fail(e.toString()); |
| 1006 | } |
| 1007 | } |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 1008 | } |
Ihab Awad | 32dd7c3 | 2015-05-28 10:52:20 -0700 | [diff] [blame] | 1009 | fail("Timeout in assertTrueWithTimeout"); |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 1010 | } |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 1011 | } |