blob: 4c0e76a847054f4979c024738224729400100648 [file] [log] [blame]
Hall Liu220b4192015-12-11 11:33:08 -08001/*
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
17package com.android.server.telecom.tests;
18
19import android.Manifest;
20import android.app.Activity;
21import android.app.AppOpsManager;
22import android.content.BroadcastReceiver;
23import android.content.ComponentName;
24import android.content.Context;
25import android.content.Intent;
26import android.net.Uri;
27import android.os.Bundle;
28import android.os.Handler;
29import android.os.UserHandle;
30import android.telecom.GatewayInfo;
31import android.telecom.TelecomManager;
32import android.telecom.VideoProfile;
33import android.telephony.DisconnectCause;
Hall Liu84b6c872016-02-03 12:19:00 -080034import android.test.suitebuilder.annotation.SmallTest;
Hall Liu220b4192015-12-11 11:33:08 -080035
36import com.android.server.telecom.Call;
37import com.android.server.telecom.CallsManager;
38import com.android.server.telecom.NewOutgoingCallIntentBroadcaster;
39import com.android.server.telecom.PhoneNumberUtilsAdapter;
40import com.android.server.telecom.PhoneNumberUtilsAdapterImpl;
Hall Liuc9cf5442016-06-29 10:08:10 -070041import com.android.server.telecom.TelecomSystem;
Hall Liu220b4192015-12-11 11:33:08 -080042
Hall Liuc8a396b2017-12-27 18:23:28 -080043import org.junit.Before;
44import org.junit.Test;
45import org.junit.runner.RunWith;
46import org.junit.runners.JUnit4;
Hall Liu220b4192015-12-11 11:33:08 -080047import org.mockito.ArgumentCaptor;
48import org.mockito.Mock;
49
Hall Liuc8a396b2017-12-27 18:23:28 -080050import static org.junit.Assert.assertEquals;
51import static org.junit.Assert.assertNull;
52import static org.junit.Assert.assertTrue;
Brad Ebingerd0fe76e2017-03-20 13:17:15 -070053import static org.mockito.ArgumentMatchers.nullable;
Hall Liu220b4192015-12-11 11:33:08 -080054import static org.mockito.Matchers.any;
55import static org.mockito.Matchers.anyBoolean;
56import static org.mockito.Matchers.anyInt;
57import static org.mockito.Matchers.anyString;
58import static org.mockito.Matchers.eq;
59import static org.mockito.Matchers.isNotNull;
60import static org.mockito.Matchers.isNull;
61import static org.mockito.Mockito.doReturn;
62import static org.mockito.Mockito.never;
63import static org.mockito.Mockito.spy;
64import static org.mockito.Mockito.verify;
Hall Liu508b2802016-02-17 17:31:43 -080065import static org.mockito.Mockito.when;
Hall Liu220b4192015-12-11 11:33:08 -080066
Hall Liuc8a396b2017-12-27 18:23:28 -080067@RunWith(JUnit4.class)
Hall Liu220b4192015-12-11 11:33:08 -080068public class NewOutgoingCallIntentBroadcasterTest extends TelecomTestCase {
69 private static class ReceiverIntentPair {
70 public BroadcastReceiver receiver;
71 public Intent intent;
72
73 public ReceiverIntentPair(BroadcastReceiver receiver, Intent intent) {
74 this.receiver = receiver;
75 this.intent = intent;
76 }
77 }
78
79 @Mock private CallsManager mCallsManager;
80 @Mock private Call mCall;
81
82 private PhoneNumberUtilsAdapter mPhoneNumberUtilsAdapterSpy;
83
84 @Override
Hall Liuc8a396b2017-12-27 18:23:28 -080085 @Before
Hall Liu220b4192015-12-11 11:33:08 -080086 public void setUp() throws Exception {
87 super.setUp();
88 mContext = mComponentContextFixture.getTestDouble().getApplicationContext();
89 mPhoneNumberUtilsAdapterSpy = spy(new PhoneNumberUtilsAdapterImpl());
Hall Liu508b2802016-02-17 17:31:43 -080090 when(mCall.getInitiatingUser()).thenReturn(UserHandle.CURRENT);
Hall Liuc9cf5442016-06-29 10:08:10 -070091 when(mCallsManager.getLock()).thenReturn(new TelecomSystem.SyncRoot() { });
Hall Liu220b4192015-12-11 11:33:08 -080092 }
93
Hall Liu84b6c872016-02-03 12:19:00 -080094 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -080095 @Test
Hall Liu220b4192015-12-11 11:33:08 -080096 public void testNullHandle() {
97 Intent intent = new Intent(Intent.ACTION_CALL, null);
98 int result = processIntent(intent, true);
99 assertEquals(DisconnectCause.INVALID_NUMBER, result);
100 verifyNoBroadcastSent();
101 verifyNoCallPlaced();
102 }
103
Hall Liu84b6c872016-02-03 12:19:00 -0800104 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800105 @Test
Hall Liu220b4192015-12-11 11:33:08 -0800106 public void testVoicemailCall() {
107 String voicemailNumber = "voicemail:18005551234";
108 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(voicemailNumber));
109 intent.putExtra(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true);
110
111 int result = processIntent(intent, true);
112
113 assertEquals(DisconnectCause.NOT_DISCONNECTED, result);
114 verify(mCallsManager).placeOutgoingCall(eq(mCall), eq(Uri.parse(voicemailNumber)),
Brad Ebingerd0fe76e2017-03-20 13:17:15 -0700115 nullable(GatewayInfo.class), eq(true), eq(VideoProfile.STATE_AUDIO_ONLY));
Hall Liu220b4192015-12-11 11:33:08 -0800116 }
117
Hall Liu84b6c872016-02-03 12:19:00 -0800118 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800119 @Test
Hall Liu220b4192015-12-11 11:33:08 -0800120 public void testVoicemailCallWithBadAction() {
121 badCallActionHelper(Uri.parse("voicemail:18005551234"), DisconnectCause.OUTGOING_CANCELED);
122 }
123
Hall Liu84b6c872016-02-03 12:19:00 -0800124 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800125 @Test
Hall Liu220b4192015-12-11 11:33:08 -0800126 public void testTelCallWithBadCallAction() {
127 badCallActionHelper(Uri.parse("tel:6505551234"), DisconnectCause.INVALID_NUMBER);
128 }
129
Hall Liu84b6c872016-02-03 12:19:00 -0800130 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800131 @Test
Hall Liu220b4192015-12-11 11:33:08 -0800132 public void testSipCallWithBadCallAction() {
133 badCallActionHelper(Uri.parse("sip:testuser@testsite.com"), DisconnectCause.INVALID_NUMBER);
134 }
135
136 private void badCallActionHelper(Uri handle, int expectedCode) {
137 Intent intent = new Intent(Intent.ACTION_ALARM_CHANGED, handle);
138
139 int result = processIntent(intent, true);
140
141 assertEquals(expectedCode, result);
142 verifyNoBroadcastSent();
143 verifyNoCallPlaced();
144 }
145
Hall Liu84b6c872016-02-03 12:19:00 -0800146 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800147 @Test
Sanket Agarwale6143f52016-05-26 11:22:57 -0700148 public void testAlreadyDisconnectedCall() {
149 Uri handle = Uri.parse("tel:6505551234");
150 doReturn(true).when(mCall).isDisconnected();
151 Intent callIntent = buildIntent(handle, Intent.ACTION_CALL, null);
152 ReceiverIntentPair result = regularCallTestHelper(callIntent, null);
153
154 result.receiver.setResultData(
155 result.intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER));
156
157 result.receiver.onReceive(mContext, result.intent);
158 verifyNoCallPlaced();
159 }
160
161 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800162 @Test
Hall Liu220b4192015-12-11 11:33:08 -0800163 public void testNoNumberSupplied() {
164 Uri handle = Uri.parse("tel:");
165 Intent intent = new Intent(Intent.ACTION_CALL, handle);
166
167 int result = processIntent(intent, true);
168
169 assertEquals(DisconnectCause.NO_PHONE_NUMBER_SUPPLIED, result);
170 verifyNoBroadcastSent();
171 verifyNoCallPlaced();
172 }
173
Hall Liu84b6c872016-02-03 12:19:00 -0800174 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800175 @Test
Hall Liu220b4192015-12-11 11:33:08 -0800176 public void testEmergencyCallWithNonDefaultDialer() {
177 Uri handle = Uri.parse("tel:6505551911");
178 doReturn(true).when(mPhoneNumberUtilsAdapterSpy).isPotentialLocalEmergencyNumber(
179 any(Context.class), eq(handle.getSchemeSpecificPart()));
180 Intent intent = new Intent(Intent.ACTION_CALL, handle);
181
182 String ui_package_string = "sample_string_1";
183 String dialer_default_class_string = "sample_string_2";
184 mComponentContextFixture.putResource(R.string.ui_default_package, ui_package_string);
185 mComponentContextFixture.putResource(R.string.dialer_default_class,
186 dialer_default_class_string);
187
188 int result = processIntent(intent, false);
189
190 assertEquals(DisconnectCause.OUTGOING_CANCELED, result);
191 verifyNoBroadcastSent();
192 verifyNoCallPlaced();
193
194 ArgumentCaptor<Intent> dialerIntentCaptor = ArgumentCaptor.forClass(Intent.class);
195 verify(mContext).startActivityAsUser(dialerIntentCaptor.capture(), any(UserHandle.class));
196 Intent dialerIntent = dialerIntentCaptor.getValue();
197 assertEquals(new ComponentName(ui_package_string, dialer_default_class_string),
198 dialerIntent.getComponent());
199 assertEquals(Intent.ACTION_DIAL, dialerIntent.getAction());
200 assertEquals(handle, dialerIntent.getData());
201 assertEquals(Intent.FLAG_ACTIVITY_NEW_TASK, dialerIntent.getFlags());
202 }
203
Hall Liu84b6c872016-02-03 12:19:00 -0800204 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800205 @Test
Hall Liu220b4192015-12-11 11:33:08 -0800206 public void testActionCallEmergencyCall() {
207 Uri handle = Uri.parse("tel:6505551911");
208 Intent intent = buildIntent(handle, Intent.ACTION_CALL, null);
209 emergencyCallTestHelper(intent, null);
210 }
211
Hall Liu84b6c872016-02-03 12:19:00 -0800212 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800213 @Test
Hall Liu220b4192015-12-11 11:33:08 -0800214 public void testActionEmergencyWithEmergencyNumber() {
215 Uri handle = Uri.parse("tel:6505551911");
216 Intent intent = buildIntent(handle, Intent.ACTION_CALL_EMERGENCY, null);
217 emergencyCallTestHelper(intent, null);
218 }
219
Hall Liu84b6c872016-02-03 12:19:00 -0800220 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800221 @Test
Hall Liu220b4192015-12-11 11:33:08 -0800222 public void testActionPrivCallWithEmergencyNumber() {
223 Uri handle = Uri.parse("tel:6505551911");
224 Intent intent = buildIntent(handle, Intent.ACTION_CALL_PRIVILEGED, null);
225 emergencyCallTestHelper(intent, null);
226 }
227
Hall Liu84b6c872016-02-03 12:19:00 -0800228 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800229 @Test
Hall Liu220b4192015-12-11 11:33:08 -0800230 public void testEmergencyCallWithGatewayExtras() {
231 Uri handle = Uri.parse("tel:6505551911");
232 Bundle gatewayExtras = new Bundle();
233 gatewayExtras.putString(NewOutgoingCallIntentBroadcaster.EXTRA_GATEWAY_PROVIDER_PACKAGE,
234 "sample1");
235 gatewayExtras.putString(NewOutgoingCallIntentBroadcaster.EXTRA_GATEWAY_URI, "sample2");
236
237 Intent intent = buildIntent(handle, Intent.ACTION_CALL, gatewayExtras);
238 emergencyCallTestHelper(intent, gatewayExtras);
239 }
240
Hall Liu84b6c872016-02-03 12:19:00 -0800241 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800242 @Test
Hall Liu220b4192015-12-11 11:33:08 -0800243 public void testActionEmergencyWithNonEmergencyNumber() {
244 Uri handle = Uri.parse("tel:6505551911");
245 doReturn(false).when(mPhoneNumberUtilsAdapterSpy).isPotentialLocalEmergencyNumber(
246 any(Context.class), eq(handle.getSchemeSpecificPart()));
247 Intent intent = new Intent(Intent.ACTION_CALL_EMERGENCY, handle);
248 int result = processIntent(intent, true);
249
250 assertEquals(DisconnectCause.OUTGOING_CANCELED, result);
251 verifyNoCallPlaced();
252 verifyNoBroadcastSent();
253 }
254
255 private void emergencyCallTestHelper(Intent intent, Bundle expectedAdditionalExtras) {
256 Uri handle = intent.getData();
257 int videoState = VideoProfile.STATE_BIDIRECTIONAL;
258 boolean isSpeakerphoneOn = true;
259 doReturn(true).when(mPhoneNumberUtilsAdapterSpy).isPotentialLocalEmergencyNumber(
260 any(Context.class), eq(handle.getSchemeSpecificPart()));
261 intent.putExtra(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, isSpeakerphoneOn);
262 intent.putExtra(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, videoState);
263 int result = processIntent(intent, true);
264
265 assertEquals(DisconnectCause.NOT_DISCONNECTED, result);
266 verify(mCallsManager).placeOutgoingCall(eq(mCall), eq(handle), isNull(GatewayInfo.class),
267 eq(isSpeakerphoneOn), eq(videoState));
268
269 Bundle expectedExtras = createNumberExtras(handle.getSchemeSpecificPart());
270 if (expectedAdditionalExtras != null) {
271 expectedExtras.putAll(expectedAdditionalExtras);
272 }
273 BroadcastReceiver receiver = verifyBroadcastSent(handle.getSchemeSpecificPart(),
274 expectedExtras).receiver;
275 assertNull(receiver);
276 }
277
Hall Liu84b6c872016-02-03 12:19:00 -0800278 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800279 @Test
Hall Liu220b4192015-12-11 11:33:08 -0800280 public void testUnmodifiedRegularCall() {
281 Uri handle = Uri.parse("tel:6505551234");
282 Intent callIntent = buildIntent(handle, Intent.ACTION_CALL, null);
283 ReceiverIntentPair result = regularCallTestHelper(callIntent, null);
284
285 result.receiver.setResultData(
286 result.intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER));
287
288 result.receiver.onReceive(mContext, result.intent);
289
290 verify(mCallsManager).placeOutgoingCall(eq(mCall), eq(handle), isNull(GatewayInfo.class),
291 eq(true), eq(VideoProfile.STATE_BIDIRECTIONAL));
292 }
293
Hall Liu84b6c872016-02-03 12:19:00 -0800294 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800295 @Test
Hall Liu220b4192015-12-11 11:33:08 -0800296 public void testUnmodifiedSipCall() {
297 Uri handle = Uri.parse("sip:test@test.com");
298 Intent callIntent = buildIntent(handle, Intent.ACTION_CALL, null);
299 ReceiverIntentPair result = regularCallTestHelper(callIntent, null);
300
301 result.receiver.setResultData(
302 result.intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER));
303
304 result.receiver.onReceive(mContext, result.intent);
305
306 Uri encHandle = Uri.fromParts(handle.getScheme(),
307 handle.getSchemeSpecificPart(), null);
308 verify(mCallsManager).placeOutgoingCall(eq(mCall), eq(encHandle), isNull(GatewayInfo.class),
309 eq(true), eq(VideoProfile.STATE_BIDIRECTIONAL));
310 }
311
Hall Liu84b6c872016-02-03 12:19:00 -0800312 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800313 @Test
Hall Liu220b4192015-12-11 11:33:08 -0800314 public void testCallWithGatewayInfo() {
315 Uri handle = Uri.parse("tel:6505551234");
316 Intent callIntent = buildIntent(handle, Intent.ACTION_CALL, null);
317
318 callIntent.putExtra(NewOutgoingCallIntentBroadcaster
319 .EXTRA_GATEWAY_PROVIDER_PACKAGE, "sample1");
320 callIntent.putExtra(NewOutgoingCallIntentBroadcaster.EXTRA_GATEWAY_URI, "sample2");
321 ReceiverIntentPair result = regularCallTestHelper(callIntent, callIntent.getExtras());
322
323 result.receiver.setResultData(
324 result.intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER));
325
326 result.receiver.onReceive(mContext, result.intent);
327
328 verify(mCallsManager).placeOutgoingCall(eq(mCall), eq(handle),
329 isNotNull(GatewayInfo.class), eq(true), eq(VideoProfile.STATE_BIDIRECTIONAL));
330 }
331
Hall Liu84b6c872016-02-03 12:19:00 -0800332 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800333 @Test
Hall Liu220b4192015-12-11 11:33:08 -0800334 public void testCallNumberModifiedToNull() {
335 Uri handle = Uri.parse("tel:6505551234");
336 Intent callIntent = buildIntent(handle, Intent.ACTION_CALL, null);
337 ReceiverIntentPair result = regularCallTestHelper(callIntent, null);
338
339 result.receiver.setResultData(null);
340
341 result.receiver.onReceive(mContext, result.intent);
342 verifyNoCallPlaced();
Hall Liu63e690c2017-02-14 18:05:03 -0800343 ArgumentCaptor<Long> timeoutCaptor = ArgumentCaptor.forClass(Long.class);
344 verify(mCall).disconnect(timeoutCaptor.capture());
345 assertTrue(timeoutCaptor.getValue() > 0);
346 }
347
348 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800349 @Test
Hall Liu63e690c2017-02-14 18:05:03 -0800350 public void testCallNumberModifiedToNullWithLongCustomTimeout() {
351 Uri handle = Uri.parse("tel:6505551234");
352 Intent callIntent = buildIntent(handle, Intent.ACTION_CALL, null);
353 ReceiverIntentPair result = regularCallTestHelper(callIntent, null);
354
355 long customTimeout = 100000000;
356 Bundle bundle = new Bundle();
357 bundle.putLong(TelecomManager.EXTRA_NEW_OUTGOING_CALL_CANCEL_TIMEOUT, customTimeout);
358 result.receiver.setResultData(null);
359 result.receiver.setResultExtras(bundle);
360
361 result.receiver.onReceive(mContext, result.intent);
362 verifyNoCallPlaced();
363 ArgumentCaptor<Long> timeoutCaptor = ArgumentCaptor.forClass(Long.class);
364 verify(mCall).disconnect(timeoutCaptor.capture());
365 assertTrue(timeoutCaptor.getValue() < customTimeout);
Hall Liu220b4192015-12-11 11:33:08 -0800366 }
367
Hall Liu84b6c872016-02-03 12:19:00 -0800368 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800369 @Test
Hall Liu220b4192015-12-11 11:33:08 -0800370 public void testCallModifiedToEmergency() {
371 Uri handle = Uri.parse("tel:6505551234");
372 Intent callIntent = buildIntent(handle, Intent.ACTION_CALL, null);
373 ReceiverIntentPair result = regularCallTestHelper(callIntent, null);
374
375 String newEmergencyNumber = "1234567890";
376 result.receiver.setResultData(newEmergencyNumber);
377
378 doReturn(true).when(mPhoneNumberUtilsAdapterSpy).isPotentialLocalEmergencyNumber(
379 any(Context.class), eq(newEmergencyNumber));
380 result.receiver.onReceive(mContext, result.intent);
Hall Liu63e690c2017-02-14 18:05:03 -0800381 verify(mCall).disconnect(eq(0L));
Hall Liu220b4192015-12-11 11:33:08 -0800382 }
383
384 private ReceiverIntentPair regularCallTestHelper(Intent intent,
385 Bundle expectedAdditionalExtras) {
386 Uri handle = intent.getData();
387 int videoState = VideoProfile.STATE_BIDIRECTIONAL;
388 boolean isSpeakerphoneOn = true;
389 intent.putExtra(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, isSpeakerphoneOn);
390 intent.putExtra(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, videoState);
391
392 int result = processIntent(intent, true);
393
394 assertEquals(DisconnectCause.NOT_DISCONNECTED, result);
395 Bundle expectedExtras = createNumberExtras(handle.getSchemeSpecificPart());
396 if (expectedAdditionalExtras != null) {
397 expectedExtras.putAll(expectedAdditionalExtras);
398 }
399 return verifyBroadcastSent(handle.getSchemeSpecificPart(), expectedExtras);
400 }
401
402 private Intent buildIntent(Uri handle, String action, Bundle extras) {
403 Intent i = new Intent(action, handle);
404 if (extras != null) {
405 i.putExtras(extras);
406 }
407 return i;
408 }
409
410 private int processIntent(Intent intent,
411 boolean isDefaultPhoneApp) {
412 NewOutgoingCallIntentBroadcaster b = new NewOutgoingCallIntentBroadcaster(
413 mContext, mCallsManager, mCall, intent, mPhoneNumberUtilsAdapterSpy,
414 isDefaultPhoneApp);
415 return b.processIntent();
416 }
417
418 private ReceiverIntentPair verifyBroadcastSent(String number, Bundle expectedExtras) {
419 ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
420 ArgumentCaptor<BroadcastReceiver> receiverCaptor =
421 ArgumentCaptor.forClass(BroadcastReceiver.class);
422
423 verify(mContext).sendOrderedBroadcastAsUser(
424 intentCaptor.capture(),
425 eq(UserHandle.CURRENT),
426 eq(Manifest.permission.PROCESS_OUTGOING_CALLS),
427 eq(AppOpsManager.OP_PROCESS_OUTGOING_CALLS),
428 receiverCaptor.capture(),
429 isNull(Handler.class),
430 eq(Activity.RESULT_OK),
431 eq(number),
432 isNull(Bundle.class));
433
434 Intent capturedIntent = intentCaptor.getValue();
435 assertEquals(Intent.ACTION_NEW_OUTGOING_CALL, capturedIntent.getAction());
Brad Ebinger68d17c62017-04-11 17:14:11 -0700436 assertEquals(Intent.FLAG_RECEIVER_FOREGROUND | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND,
437 capturedIntent.getFlags());
Hall Liu220b4192015-12-11 11:33:08 -0800438 assertTrue(areBundlesEqual(expectedExtras, capturedIntent.getExtras()));
439
440 BroadcastReceiver receiver = receiverCaptor.getValue();
441 if (receiver != null) {
442 receiver.setPendingResult(
443 new BroadcastReceiver.PendingResult(0, "", null, 0, true, false, null, 0, 0));
444 }
445
446 return new ReceiverIntentPair(receiver, capturedIntent);
447 }
448
449 private Bundle createNumberExtras(String number) {
450 Bundle b = new Bundle();
451 b.putString(Intent.EXTRA_PHONE_NUMBER, number);
452 return b;
453 }
454
455 private void verifyNoCallPlaced() {
456 verify(mCallsManager, never()).placeOutgoingCall(any(Call.class), any(Uri.class),
457 any(GatewayInfo.class), anyBoolean(), anyInt());
458 }
459
460 private void verifyNoBroadcastSent() {
461 verify(mContext, never()).sendOrderedBroadcastAsUser(
462 any(Intent.class),
463 any(UserHandle.class),
464 anyString(),
465 anyInt(),
466 any(BroadcastReceiver.class),
467 any(Handler.class),
468 anyInt(),
469 anyString(),
470 any(Bundle.class));
471 }
472
473 private static boolean areBundlesEqual(Bundle b1, Bundle b2) {
474 for (String key1 : b1.keySet()) {
475 if (!b1.get(key1).equals(b2.get(key1))) {
476 return false;
477 }
478 }
479
480 for (String key2 : b2.keySet()) {
481 if (!b2.get(key2).equals(b1.get(key2))) {
482 return false;
483 }
484 }
485 return true;
486 }
487}