diff options
author | Yiqun Wu <yiqunw@google.com> | 2019-08-13 18:03:28 -0700 |
---|---|---|
committer | Yiqun Wu <yiqunw@google.com> | 2019-08-21 16:48:51 -0700 |
commit | d44df179109a20a29abf23b08c30a0f89502876d (patch) | |
tree | bb1d26dff67d89b36ea9872f48a528ff28334623 /tests | |
parent | 09263e652c2dce2ddbfb74aa2876f156cf4f7949 (diff) | |
download | platform_packages_apps_Car_Dialer-d44df179109a20a29abf23b08c30a0f89502876d.tar.gz platform_packages_apps_Car_Dialer-d44df179109a20a29abf23b08c30a0f89502876d.tar.bz2 platform_packages_apps_Car_Dialer-d44df179109a20a29abf23b08c30a0f89502876d.zip |
DO NOT MERGE: Check if telephony service is null before making a call.
Bug: 138866013
Test: mma
Change-Id: I125850a8a66aeb2ee09547e6cf573fd23bdcdfc5
Diffstat (limited to 'tests')
-rw-r--r-- | tests/robotests/src/com/android/car/dialer/telecom/UiCallManagerTest.java | 13 | ||||
-rw-r--r-- | tests/robotests/src/com/android/car/dialer/testutils/ShadowServiceManagerOverride.java | 56 |
2 files changed, 69 insertions, 0 deletions
diff --git a/tests/robotests/src/com/android/car/dialer/telecom/UiCallManagerTest.java b/tests/robotests/src/com/android/car/dialer/telecom/UiCallManagerTest.java index ea5e3153..9c64a111 100644 --- a/tests/robotests/src/com/android/car/dialer/telecom/UiCallManagerTest.java +++ b/tests/robotests/src/com/android/car/dialer/telecom/UiCallManagerTest.java @@ -32,6 +32,7 @@ import android.content.ComponentName; import android.content.Context; import android.net.Uri; import android.os.Bundle; +import android.os.IBinder; import android.telecom.CallAudioState; import android.telecom.PhoneAccountHandle; import android.telecom.TelecomManager; @@ -39,6 +40,8 @@ import android.telecom.TelecomManager; import com.android.car.dialer.CarDialerRobolectricTestRunner; import com.android.car.dialer.R; import com.android.car.dialer.TestDialerApplication; +import com.android.car.dialer.testutils.ShadowServiceManagerOverride; +import com.android.internal.telephony.ITelephony; import org.junit.After; import org.junit.Before; @@ -48,6 +51,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; +import org.robolectric.annotation.Config; import org.robolectric.shadow.api.Shadow; import org.robolectric.shadows.ShadowContextImpl; import org.robolectric.shadows.ShadowToast; @@ -55,6 +59,7 @@ import org.robolectric.shadows.ShadowToast; import java.util.List; @RunWith(CarDialerRobolectricTestRunner.class) +@Config(shadows = ShadowServiceManagerOverride.class) public class UiCallManagerTest { private static final String TEL_SCHEME = "tel"; @@ -65,6 +70,10 @@ public class UiCallManagerTest { private TelecomManager mMockTelecomManager; @Mock private InCallServiceImpl mMockInCallService; + @Mock + private IBinder mMockBinder; + @Mock + private ITelephony mMockITelephony; @Before public void setup() { @@ -74,6 +83,10 @@ public class UiCallManagerTest { ShadowContextImpl shadowContext = Shadow.extract(((Application) mContext).getBaseContext()); shadowContext.setSystemService(Context.TELECOM_SERVICE, mMockTelecomManager); + + when(mMockBinder.queryLocalInterface( + "com.android.internal.telephony.ITelephony")).thenReturn(mMockITelephony); + ShadowServiceManagerOverride.addService(Context.TELEPHONY_SERVICE, mMockBinder); } private void initUiCallManager() { diff --git a/tests/robotests/src/com/android/car/dialer/testutils/ShadowServiceManagerOverride.java b/tests/robotests/src/com/android/car/dialer/testutils/ShadowServiceManagerOverride.java new file mode 100644 index 00000000..22aefdf1 --- /dev/null +++ b/tests/robotests/src/com/android/car/dialer/testutils/ShadowServiceManagerOverride.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.car.dialer.testutils; + +import android.os.IBinder; +import android.os.ServiceManager; + +import org.robolectric.annotation.Implementation; +import org.robolectric.annotation.Implements; +import org.robolectric.shadows.ShadowServiceManager; + +import java.util.HashMap; +import java.util.Map; + +/** + * Derived from {@link org.robolectric.shadows.ShadowServiceManager}. + * + * Needed for {@link com.android.car.dialer.telecom.UiCallManagerTest} which needs to set up the + * ITelephony service. + */ + +@Implements(value = ServiceManager.class, inheritImplementationMethods = true) +public class ShadowServiceManagerOverride extends ShadowServiceManager { + private static final Map<String, IBinder> EXTRA_SERVICES = new HashMap<>(); + + @Implementation + public static IBinder getService(String name) { + IBinder iBinder = ShadowServiceManager.getService(name); + if (iBinder == null) { + return EXTRA_SERVICES.get(name); + } + return iBinder; + } + + /** Sets the service with {@param name} to {@param service}. */ + @Implementation + public static void addService(String name, IBinder service) { + ShadowServiceManager.addService(name, service); + EXTRA_SERVICES.put(name, service); + } + +} |