InCallControllerTests.java revision f15dc33f87f88e21ef745952a68af65c86e1bf1e
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
17package com.android.server.telecom.tests;
18
19import android.Manifest;
20import android.content.ComponentName;
21import android.content.Context;
22import android.content.Intent;
23import android.content.ServiceConnection;
24import android.content.pm.PackageManager;
25import android.content.pm.ResolveInfo;
26import android.content.pm.ServiceInfo;
27import android.content.res.Resources;
28import android.os.Bundle;
29import android.os.IBinder;
30import android.os.UserHandle;
31import android.telecom.InCallService;
32import android.telecom.PhoneAccountHandle;
33import android.telecom.TelecomManager;
34import android.test.mock.MockContext;
35import android.test.suitebuilder.annotation.MediumTest;
36import android.text.TextUtils;
37
38import com.android.internal.telecom.IInCallAdapter;
39import com.android.internal.telecom.IInCallService;
40import com.android.server.telecom.BluetoothHeadsetProxy;
41import com.android.server.telecom.Call;
42import com.android.server.telecom.CallsManager;
43import com.android.server.telecom.InCallController;
44import com.android.server.telecom.PhoneAccountRegistrar;
45import com.android.server.telecom.R;
46import com.android.server.telecom.SystemStateProvider;
47import com.android.server.telecom.TelecomServiceImpl.DefaultDialerManagerAdapter;
48import com.android.server.telecom.TelecomSystem;
49
50import org.mockito.ArgumentCaptor;
51import org.mockito.Mock;
52import org.mockito.MockitoAnnotations;
53import org.mockito.invocation.InvocationOnMock;
54import org.mockito.stubbing.Answer;
55
56import java.util.LinkedList;
57
58import static org.mockito.Matchers.any;
59import static org.mockito.Matchers.anyInt;
60import static org.mockito.Matchers.anyString;
61import static org.mockito.Matchers.eq;
62import static org.mockito.Matchers.isNull;
63import static org.mockito.Matchers.isNull;
64import static org.mockito.Mockito.doAnswer;
65import static org.mockito.Mockito.doReturn;
66import static org.mockito.Mockito.mock;
67import static org.mockito.Mockito.never;
68import static org.mockito.Mockito.times;
69import static org.mockito.Mockito.when;
70import static org.mockito.Mockito.verify;
71
72public class InCallControllerTests extends TelecomTestCase {
73    @Mock CallsManager mMockCallsManager;
74    @Mock PhoneAccountRegistrar mMockPhoneAccountRegistrar;
75    @Mock BluetoothHeadsetProxy mMockBluetoothHeadset;
76    @Mock SystemStateProvider mMockSystemStateProvider;
77    @Mock PackageManager mMockPackageManager;
78    @Mock Call mMockCall;
79    @Mock Resources mMockResources;
80    @Mock MockContext mMockContext;
81    @Mock DefaultDialerManagerAdapter mMockDefaultDialerAdapter;
82
83    private static final int CURRENT_USER_ID = 900973;
84    private static final String DEF_PKG = "defpkg";
85    private static final String DEF_CLASS = "defcls";
86    private static final String SYS_PKG = "syspkg";
87    private static final String SYS_CLASS = "syscls";
88    private static final PhoneAccountHandle PA_HANDLE =
89            new PhoneAccountHandle(new ComponentName("pa_pkg", "pa_cls"), "pa_id");
90
91    private UserHandle mUserHandle = UserHandle.of(CURRENT_USER_ID);
92    private InCallController mInCallController;
93    private TelecomSystem.SyncRoot mLock;
94
95    @Override
96    public void setUp() throws Exception {
97        super.setUp();
98        MockitoAnnotations.initMocks(this);
99        doReturn(mMockResources).when(mMockContext).getResources();
100        doReturn(SYS_PKG).when(mMockResources).getString(R.string.ui_default_package);
101        doReturn(SYS_CLASS).when(mMockResources).getString(R.string.incall_default_class);
102        mInCallController = new InCallController(mMockContext, mLock, mMockCallsManager,
103                mMockSystemStateProvider, mMockDefaultDialerAdapter);
104    }
105
106    @Override
107    public void tearDown() throws Exception {
108        super.tearDown();
109    }
110
111    @MediumTest
112    public void testBindToService_NoServicesFound_IncomingCall() throws Exception {
113        when(mMockCallsManager.getCurrentUserHandle()).thenReturn(mUserHandle);
114        when(mMockContext.getPackageManager()).thenReturn(mMockPackageManager);
115        when(mMockCallsManager.hasEmergencyCall()).thenReturn(false);
116        when(mMockCall.isIncoming()).thenReturn(true);
117        when(mMockCall.isExternalCall()).thenReturn(false);
118
119        Intent queryIntent = new Intent(InCallService.SERVICE_INTERFACE);
120        setupMockPackageManager(false /* default */, true /* system */, false /* external calls */);
121        mInCallController.bindToServices(mMockCall);
122
123        ArgumentCaptor<Intent> bindIntentCaptor = ArgumentCaptor.forClass(Intent.class);
124        verify(mMockContext).bindServiceAsUser(
125                bindIntentCaptor.capture(),
126                any(ServiceConnection.class),
127                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE),
128                eq(UserHandle.CURRENT));
129
130        Intent bindIntent = bindIntentCaptor.getValue();
131        assertEquals(InCallService.SERVICE_INTERFACE, bindIntent.getAction());
132        assertEquals(SYS_PKG, bindIntent.getComponent().getPackageName());
133        assertEquals(SYS_CLASS, bindIntent.getComponent().getClassName());
134        assertNull(bindIntent.getExtras());
135    }
136
137    @MediumTest
138    public void testBindToService_NoServicesFound_OutgoingCall() throws Exception {
139        Bundle callExtras = new Bundle();
140        callExtras.putBoolean("whatever", true);
141
142        when(mMockCallsManager.getCurrentUserHandle()).thenReturn(mUserHandle);
143        when(mMockContext.getPackageManager()).thenReturn(mMockPackageManager);
144        when(mMockCallsManager.hasEmergencyCall()).thenReturn(false);
145        when(mMockCall.isIncoming()).thenReturn(false);
146        when(mMockCall.getTargetPhoneAccount()).thenReturn(PA_HANDLE);
147        when(mMockCall.getIntentExtras()).thenReturn(callExtras);
148        when(mMockCall.isExternalCall()).thenReturn(false);
149
150        Intent queryIntent = new Intent(InCallService.SERVICE_INTERFACE);
151        setupMockPackageManager(false /* default */, true /* system */, false /* external calls */);
152        mInCallController.bindToServices(mMockCall);
153
154        ArgumentCaptor<Intent> bindIntentCaptor = ArgumentCaptor.forClass(Intent.class);
155        verify(mMockContext).bindServiceAsUser(
156                bindIntentCaptor.capture(),
157                any(ServiceConnection.class),
158                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE),
159                eq(UserHandle.CURRENT));
160
161        Intent bindIntent = bindIntentCaptor.getValue();
162        assertEquals(InCallService.SERVICE_INTERFACE, bindIntent.getAction());
163        assertEquals(SYS_PKG, bindIntent.getComponent().getPackageName());
164        assertEquals(SYS_CLASS, bindIntent.getComponent().getClassName());
165        assertEquals(PA_HANDLE, bindIntent.getExtras().getParcelable(
166                TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE));
167        assertEquals(callExtras, bindIntent.getExtras().getParcelable(
168                TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS));
169    }
170
171    @MediumTest
172    public void testBindToService_DefaultDialer_NoEmergency() throws Exception {
173        Bundle callExtras = new Bundle();
174        callExtras.putBoolean("whatever", true);
175
176        when(mMockCallsManager.getCurrentUserHandle()).thenReturn(mUserHandle);
177        when(mMockContext.getPackageManager()).thenReturn(mMockPackageManager);
178        when(mMockCallsManager.hasEmergencyCall()).thenReturn(false);
179        when(mMockCall.isIncoming()).thenReturn(false);
180        when(mMockCall.getTargetPhoneAccount()).thenReturn(PA_HANDLE);
181        when(mMockCall.getIntentExtras()).thenReturn(callExtras);
182        when(mMockCall.isExternalCall()).thenReturn(false);
183        when(mMockDefaultDialerAdapter.getDefaultDialerApplication(mMockContext, CURRENT_USER_ID))
184                .thenReturn(DEF_PKG);
185        when(mMockContext.bindServiceAsUser(any(Intent.class), any(ServiceConnection.class),
186                anyInt(), eq(UserHandle.CURRENT))).thenReturn(true);
187
188        setupMockPackageManager(true /* default */, true /* system */, false /* external calls */);
189        mInCallController.bindToServices(mMockCall);
190
191        // Query for the different InCallServices
192        ArgumentCaptor<Intent> queryIntentCaptor = ArgumentCaptor.forClass(Intent.class);
193        verify(mMockPackageManager, times(4)).queryIntentServicesAsUser(
194                queryIntentCaptor.capture(),
195                eq(PackageManager.GET_META_DATA), eq(CURRENT_USER_ID));
196
197        // Verify call for default dialer InCallService
198        assertEquals(DEF_PKG, queryIntentCaptor.getAllValues().get(0).getPackage());
199        // Verify call for car-mode InCallService
200        assertEquals(null, queryIntentCaptor.getAllValues().get(1).getPackage());
201        // Verify call for non-UI InCallServices
202        assertEquals(null, queryIntentCaptor.getAllValues().get(2).getPackage());
203
204        ArgumentCaptor<Intent> bindIntentCaptor = ArgumentCaptor.forClass(Intent.class);
205        verify(mMockContext, times(1)).bindServiceAsUser(
206                bindIntentCaptor.capture(),
207                any(ServiceConnection.class),
208                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE),
209                eq(UserHandle.CURRENT));
210
211        Intent bindIntent = bindIntentCaptor.getValue();
212        assertEquals(InCallService.SERVICE_INTERFACE, bindIntent.getAction());
213        assertEquals(DEF_PKG, bindIntent.getComponent().getPackageName());
214        assertEquals(DEF_CLASS, bindIntent.getComponent().getClassName());
215        assertEquals(PA_HANDLE, bindIntent.getExtras().getParcelable(
216                TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE));
217        assertEquals(callExtras, bindIntent.getExtras().getParcelable(
218                TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS));
219    }
220
221    @MediumTest
222    public void testBindToService_SystemDialer_Emergency() throws Exception {
223        Bundle callExtras = new Bundle();
224        callExtras.putBoolean("whatever", true);
225
226        when(mMockCallsManager.getCurrentUserHandle()).thenReturn(mUserHandle);
227        when(mMockContext.getPackageManager()).thenReturn(mMockPackageManager);
228        when(mMockCallsManager.hasEmergencyCall()).thenReturn(true);
229        when(mMockCall.isIncoming()).thenReturn(false);
230        when(mMockCall.getTargetPhoneAccount()).thenReturn(PA_HANDLE);
231        when(mMockCall.getIntentExtras()).thenReturn(callExtras);
232        when(mMockCall.isExternalCall()).thenReturn(false);
233        when(mMockDefaultDialerAdapter.getDefaultDialerApplication(mMockContext, CURRENT_USER_ID))
234                .thenReturn(DEF_PKG);
235        when(mMockContext.bindServiceAsUser(any(Intent.class), any(ServiceConnection.class),
236                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE),
237                eq(UserHandle.CURRENT))).thenReturn(true);
238
239        setupMockPackageManager(true /* default */, true /* system */, false /* external calls */);
240
241        mInCallController.bindToServices(mMockCall);
242
243        // Query for the different InCallServices
244        ArgumentCaptor<Intent> queryIntentCaptor = ArgumentCaptor.forClass(Intent.class);
245        verify(mMockPackageManager, times(4)).queryIntentServicesAsUser(
246                queryIntentCaptor.capture(),
247                eq(PackageManager.GET_META_DATA), eq(CURRENT_USER_ID));
248
249        // Verify call for default dialer InCallService
250        assertEquals(DEF_PKG, queryIntentCaptor.getAllValues().get(0).getPackage());
251        // Verify call for car-mode InCallService
252        assertEquals(null, queryIntentCaptor.getAllValues().get(1).getPackage());
253        // Verify call for non-UI InCallServices
254        assertEquals(null, queryIntentCaptor.getAllValues().get(2).getPackage());
255
256        ArgumentCaptor<Intent> bindIntentCaptor = ArgumentCaptor.forClass(Intent.class);
257        verify(mMockContext, times(1)).bindServiceAsUser(
258                bindIntentCaptor.capture(),
259                any(ServiceConnection.class),
260                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE),
261                eq(UserHandle.CURRENT));
262
263        Intent bindIntent = bindIntentCaptor.getValue();
264        assertEquals(InCallService.SERVICE_INTERFACE, bindIntent.getAction());
265        assertEquals(SYS_PKG, bindIntent.getComponent().getPackageName());
266        assertEquals(SYS_CLASS, bindIntent.getComponent().getClassName());
267        assertEquals(PA_HANDLE, bindIntent.getExtras().getParcelable(
268                TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE));
269        assertEquals(callExtras, bindIntent.getExtras().getParcelable(
270                TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS));
271    }
272
273    @MediumTest
274    public void testBindToService_DefaultDialer_FallBackToSystem() throws Exception {
275        Bundle callExtras = new Bundle();
276        callExtras.putBoolean("whatever", true);
277
278        when(mMockCallsManager.getCurrentUserHandle()).thenReturn(mUserHandle);
279        when(mMockContext.getPackageManager()).thenReturn(mMockPackageManager);
280        when(mMockCallsManager.hasEmergencyCall()).thenReturn(false);
281        when(mMockCall.isIncoming()).thenReturn(false);
282        when(mMockCall.getTargetPhoneAccount()).thenReturn(PA_HANDLE);
283        when(mMockCall.getIntentExtras()).thenReturn(callExtras);
284        when(mMockCall.isExternalCall()).thenReturn(false);
285        when(mMockDefaultDialerAdapter.getDefaultDialerApplication(mMockContext, CURRENT_USER_ID))
286                .thenReturn(DEF_PKG);
287        when(mMockContext.bindServiceAsUser(
288                any(Intent.class), any(ServiceConnection.class), anyInt(), any(UserHandle.class)))
289                .thenReturn(true);
290
291        setupMockPackageManager(true /* default */, true /* system */, false /* external calls */);
292        mInCallController.bindToServices(mMockCall);
293
294        // Query for the different InCallServices
295        ArgumentCaptor<Intent> queryIntentCaptor = ArgumentCaptor.forClass(Intent.class);
296        verify(mMockPackageManager, times(4)).queryIntentServicesAsUser(
297                queryIntentCaptor.capture(),
298                eq(PackageManager.GET_META_DATA), eq(CURRENT_USER_ID));
299
300        // Verify call for default dialer InCallService
301        assertEquals(DEF_PKG, queryIntentCaptor.getAllValues().get(0).getPackage());
302        // Verify call for car-mode InCallService
303        assertEquals(null, queryIntentCaptor.getAllValues().get(1).getPackage());
304        // Verify call for non-UI InCallServices
305        assertEquals(null, queryIntentCaptor.getAllValues().get(2).getPackage());
306
307        ArgumentCaptor<Intent> bindIntentCaptor = ArgumentCaptor.forClass(Intent.class);
308        ArgumentCaptor<ServiceConnection> serviceConnectionCaptor =
309                ArgumentCaptor.forClass(ServiceConnection.class);
310        verify(mMockContext, times(1)).bindServiceAsUser(
311                bindIntentCaptor.capture(),
312                serviceConnectionCaptor.capture(),
313                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE),
314                eq(UserHandle.CURRENT));
315
316        Intent bindIntent = bindIntentCaptor.getValue();
317        assertEquals(InCallService.SERVICE_INTERFACE, bindIntent.getAction());
318        assertEquals(DEF_PKG, bindIntent.getComponent().getPackageName());
319        assertEquals(DEF_CLASS, bindIntent.getComponent().getClassName());
320        assertEquals(PA_HANDLE, bindIntent.getExtras().getParcelable(
321                TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE));
322        assertEquals(callExtras, bindIntent.getExtras().getParcelable(
323                TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS));
324
325        // We have a ServiceConnection for the default dialer, lets start the connection, and then
326        // simulate a crash so that we fallback to system.
327        ServiceConnection serviceConnection = serviceConnectionCaptor.getValue();
328        ComponentName defDialerComponentName = new ComponentName(DEF_PKG, DEF_CLASS);
329        IBinder mockBinder = mock(IBinder.class);
330        IInCallService mockInCallService = mock(IInCallService.class);
331        when(mockBinder.queryLocalInterface(anyString())).thenReturn(mockInCallService);
332
333
334        // Start the connection with IInCallService
335        serviceConnection.onServiceConnected(defDialerComponentName, mockBinder);
336        verify(mockInCallService).setInCallAdapter(any(IInCallAdapter.class));
337
338        // Now crash the damn thing!
339        serviceConnection.onServiceDisconnected(defDialerComponentName);
340
341        ArgumentCaptor<Intent> bindIntentCaptor2 = ArgumentCaptor.forClass(Intent.class);
342        verify(mMockContext, times(2)).bindServiceAsUser(
343                bindIntentCaptor2.capture(),
344                any(ServiceConnection.class),
345                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE),
346                eq(UserHandle.CURRENT));
347
348        bindIntent = bindIntentCaptor2.getValue();
349        assertEquals(SYS_PKG, bindIntent.getComponent().getPackageName());
350        assertEquals(SYS_CLASS, bindIntent.getComponent().getClassName());
351    }
352
353    /**
354     * Ensures that the {@link InCallController} will bind to an {@link InCallService} which
355     * supports external calls.
356     */
357    @MediumTest
358    public void testBindToService_IncludeExternal() throws Exception {
359        setupMocks(true /* isExternalCall */);
360        setupMockPackageManager(true /* default */, true /* system */, true /* external calls */);
361        mInCallController.bindToServices(mMockCall);
362
363        // Query for the different InCallServices
364        ArgumentCaptor<Intent> queryIntentCaptor = ArgumentCaptor.forClass(Intent.class);
365        verify(mMockPackageManager, times(4)).queryIntentServicesAsUser(
366                queryIntentCaptor.capture(),
367                eq(PackageManager.GET_META_DATA), eq(CURRENT_USER_ID));
368
369        // Verify call for default dialer InCallService
370        assertEquals(DEF_PKG, queryIntentCaptor.getAllValues().get(0).getPackage());
371        // Verify call for car-mode InCallService
372        assertEquals(null, queryIntentCaptor.getAllValues().get(1).getPackage());
373        // Verify call for non-UI InCallServices
374        assertEquals(null, queryIntentCaptor.getAllValues().get(2).getPackage());
375
376        ArgumentCaptor<Intent> bindIntentCaptor = ArgumentCaptor.forClass(Intent.class);
377        verify(mMockContext, times(1)).bindServiceAsUser(
378                bindIntentCaptor.capture(),
379                any(ServiceConnection.class),
380                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE),
381                eq(UserHandle.CURRENT));
382
383        Intent bindIntent = bindIntentCaptor.getValue();
384        assertEquals(InCallService.SERVICE_INTERFACE, bindIntent.getAction());
385        assertEquals(DEF_PKG, bindIntent.getComponent().getPackageName());
386        assertEquals(DEF_CLASS, bindIntent.getComponent().getClassName());
387    }
388
389    /**
390     * Ensures that the {@link InCallController} will not bind to an incall service for an external
391     * call if the incall service does not support it.
392     */
393    @MediumTest
394    public void testBindToService_ExcludeExternal() throws Exception {
395        setupMocks(true /* isExternalCall */);
396        setupMockPackageManager(true /* default */, true /* system */, false /* external calls */);
397        mInCallController.bindToServices(mMockCall);
398
399        // Query for the different InCallServices
400        ArgumentCaptor<Intent> queryIntentCaptor = ArgumentCaptor.forClass(Intent.class);
401        verify(mMockPackageManager, times(4)).queryIntentServicesAsUser(
402                queryIntentCaptor.capture(),
403                eq(PackageManager.GET_META_DATA), eq(CURRENT_USER_ID));
404
405        // Verify call for default dialer InCallService
406        assertEquals(DEF_PKG, queryIntentCaptor.getAllValues().get(0).getPackage());
407        // Verify call for car-mode InCallService
408        assertEquals(null, queryIntentCaptor.getAllValues().get(1).getPackage());
409        // Verify call for non-UI InCallServices
410        assertEquals(null, queryIntentCaptor.getAllValues().get(2).getPackage());
411
412        verify(mMockContext, never()).bindServiceAsUser(
413                any(Intent.class),
414                any(ServiceConnection.class),
415                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE),
416                eq(UserHandle.CURRENT));
417    }
418
419    private void setupMocks(boolean isExternalCall) {
420        when(mMockCallsManager.getCurrentUserHandle()).thenReturn(mUserHandle);
421        when(mMockContext.getPackageManager()).thenReturn(mMockPackageManager);
422        when(mMockCallsManager.hasEmergencyCall()).thenReturn(false);
423        when(mMockCall.isIncoming()).thenReturn(false);
424        when(mMockCall.getTargetPhoneAccount()).thenReturn(PA_HANDLE);
425        when(mMockDefaultDialerAdapter.getDefaultDialerApplication(mMockContext, CURRENT_USER_ID))
426                .thenReturn(DEF_PKG);
427        when(mMockContext.bindServiceAsUser(any(Intent.class), any(ServiceConnection.class),
428                anyInt(), eq(UserHandle.CURRENT))).thenReturn(true);
429        when(mMockCall.isExternalCall()).thenReturn(isExternalCall);
430    }
431
432    private ResolveInfo getDefResolveInfo(final boolean includeExternalCalls) {
433        return new ResolveInfo() {{
434            serviceInfo = new ServiceInfo();
435            serviceInfo.packageName = DEF_PKG;
436            serviceInfo.name = DEF_CLASS;
437            serviceInfo.permission = Manifest.permission.BIND_INCALL_SERVICE;
438            serviceInfo.metaData = new Bundle();
439            serviceInfo.metaData.putBoolean(
440                    TelecomManager.METADATA_IN_CALL_SERVICE_UI, true);
441            if (includeExternalCalls) {
442                serviceInfo.metaData.putBoolean(
443                        TelecomManager.METADATA_INCLUDE_EXTERNAL_CALLS, true);
444            }
445        }};
446    }
447
448    private ResolveInfo getSysResolveinfo() {
449        return new ResolveInfo() {{
450            serviceInfo = new ServiceInfo();
451            serviceInfo.packageName = SYS_PKG;
452            serviceInfo.name = SYS_CLASS;
453            serviceInfo.permission = Manifest.permission.BIND_INCALL_SERVICE;
454        }};
455    }
456
457    private void setupMockPackageManager(final boolean useDefaultDialer,
458            final boolean useSystemDialer, final boolean includeExternalCalls) {
459
460        doAnswer(new Answer() {
461            @Override
462            public Object answer(InvocationOnMock invocation) throws Throwable {
463                Object[] args = invocation.getArguments();
464                Intent intent = (Intent) args[0];
465                String packageName = intent.getPackage();
466                ComponentName componentName = intent.getComponent();
467                if (componentName != null) {
468                    packageName = componentName.getPackageName();
469                }
470                LinkedList<ResolveInfo> resolveInfo = new LinkedList<ResolveInfo>();
471                if (!TextUtils.isEmpty(packageName)) {
472                    if ((TextUtils.isEmpty(packageName) || packageName.equals(DEF_PKG)) &&
473                            useDefaultDialer) {
474                        resolveInfo.add(getDefResolveInfo(includeExternalCalls));
475                    }
476
477                    if ((TextUtils.isEmpty(packageName) || packageName.equals(SYS_PKG)) &&
478                           useSystemDialer) {
479                        resolveInfo.add(getSysResolveinfo());
480                    }
481                }
482                return resolveInfo;
483            }
484        }).when(mMockPackageManager).queryIntentServicesAsUser(
485                any(Intent.class), eq(PackageManager.GET_META_DATA), eq(CURRENT_USER_ID));
486    }
487}
488