summaryrefslogtreecommitdiff
path: root/InCallUI/tests
diff options
context:
space:
mode:
authorEric Erfanian <erfanian@google.com>2017-02-22 16:32:36 -0800
committerEric Erfanian <erfanian@google.com>2017-03-01 09:56:52 -0800
commitccca31529c07970e89419fb85a9e8153a5396838 (patch)
treea7034c0a01672b97728c13282a2672771cd28baa /InCallUI/tests
parente7ae4624ba6f25cb8e648db74e0d64c0113a16ba (diff)
Update dialer sources.
Test: Built package and system image. This change clobbers the old source, and is an export from an internal Google repository. The internal repository was forked form Android in March, and this change includes modifications since then, to near the v8 release. Since the fork, we've moved code from monolithic to independent modules. In addition, we've switched to Blaze/Bazel as the build sysetm. This export, however, still uses make. New dependencies have been added: - Dagger - Auto-Value - Glide - Libshortcutbadger Going forward, development will still be in Google3, and the Gerrit release will become an automated export, with the next drop happening in ~ two weeks. Android.mk includes local modifications from ToT. Abridged changelog: Bug fixes ● Not able to mute, add a call when using Phone app in multiwindow mode ● Double tap on keypad triggering multiple key and tones ● Reported spam numbers not showing as spam in the call log ● Crash when user tries to block number while Phone app is not set as default ● Crash when user picks a number from search auto-complete list Visual Voicemail (VVM) improvements ● Share Voicemail audio via standard exporting mechanisms that support file attachment (email, MMS, etc.) ● Make phone number, email and web sites in VVM transcript clickable ● Set PIN before declining VVM Terms of Service {Carrier} ● Set client type for outbound visual voicemail SMS {Carrier} New incoming call and incall UI on older devices (Android M) ● Updated Phone app icon ● New incall UI (large buttons, button labels) ● New and animated Answer/Reject gestures Accessibility ● Add custom answer/decline call buttons on answer screen for touch exploration accessibility services ● Increase size of touch target ● Add verbal feedback when a Voicemail fails to load ● Fix pressing of Phone buttons while in a phone call using Switch Access ● Fix selecting and opening contacts in talkback mode ● Split focus for ‘Learn More’ link in caller id & spam to help distinguish similar text Other ● Backup & Restore for App Preferences ● Prompt user to enable Wi-Fi calling if the call ends due to out of service and Wi-Fi is connected ● Rename “Dialpad” to “Keypad” ● Show "Private number" for restricted calls ● Delete unused items (vcard, add contact, call history) from Phone menu Change-Id: I2a7e53532a24c21bf308bf0a6d178d7ddbca4958
Diffstat (limited to 'InCallUI/tests')
-rw-r--r--InCallUI/tests/src/com/android/incallui/CallCardPresenterTest.java121
-rw-r--r--InCallUI/tests/src/com/android/incallui/CallTest.java125
-rw-r--r--InCallUI/tests/src/com/android/incallui/CallerInfoUtilsTest.java31
-rw-r--r--InCallUI/tests/src/com/android/incallui/ContactsPreferencesFactoryTest.java51
-rw-r--r--InCallUI/tests/src/com/android/incallui/ExternalCallListTest.java144
-rw-r--r--InCallUI/tests/src/com/android/incallui/ExternalCallNotifierTest.java214
-rw-r--r--InCallUI/tests/src/com/android/incallui/InCallContactInteractionsTest.java325
-rw-r--r--InCallUI/tests/src/com/android/incallui/InCallPresenterTest.java198
-rw-r--r--InCallUI/tests/src/com/android/incallui/LatencyReportTest.java59
-rw-r--r--InCallUI/tests/src/com/android/incallui/MockCallListWrapper.java80
-rw-r--r--InCallUI/tests/src/com/android/incallui/ProximitySensorTest.java66
-rw-r--r--InCallUI/tests/src/com/android/incallui/StatusBarNotifierTest.java98
-rw-r--r--InCallUI/tests/src/com/android/incallui/TestTelecomCall.java161
-rw-r--r--InCallUI/tests/src/com/android/incallui/async/SingleProdThreadExecutor.java69
-rw-r--r--InCallUI/tests/src/com/android/incallui/ringtone/DialerRingtoneManagerTest.java219
-rw-r--r--InCallUI/tests/src/com/android/incallui/ringtone/InCallTonePlayerTest.java148
-rw-r--r--InCallUI/tests/src/com/android/incallui/spam/SpamCallListListenerTest.java206
17 files changed, 0 insertions, 2315 deletions
diff --git a/InCallUI/tests/src/com/android/incallui/CallCardPresenterTest.java b/InCallUI/tests/src/com/android/incallui/CallCardPresenterTest.java
deleted file mode 100644
index 79545ce4b..000000000
--- a/InCallUI/tests/src/com/android/incallui/CallCardPresenterTest.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (C) 2016 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.incallui;
-
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.MediumTest;
-
-import com.android.contacts.common.preference.ContactsPreferences;
-import com.android.incallui.ContactInfoCache.ContactCacheEntry;
-
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-
-@MediumTest
-public class CallCardPresenterTest extends AndroidTestCase {
-
- private static final String NAME_PRIMARY = "Full Name";
- private static final String NAME_ALTERNATIVE = "Name, Full";
- private static final String LOCATION = "US";
- private static final String NUMBER = "8006459001";
-
- @Mock private ContactsPreferences mContactsPreferences;
- private ContactCacheEntry mUnlockedContactInfo;
- private ContactCacheEntry mLockedContactInfo;
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- MockitoAnnotations.initMocks(this);
-
- Mockito.when(mContactsPreferences.getDisplayOrder())
- .thenReturn(ContactsPreferences.DISPLAY_ORDER_PRIMARY);
-
- // Unlocked all contact info is available
- mUnlockedContactInfo = new ContactCacheEntry();
- mUnlockedContactInfo.namePrimary = NAME_PRIMARY;
- mUnlockedContactInfo.nameAlternative = NAME_ALTERNATIVE;
- mUnlockedContactInfo.location = LOCATION;
- mUnlockedContactInfo.number = NUMBER;
-
- // Locked only number and location are available
- mLockedContactInfo = new ContactCacheEntry();
- mLockedContactInfo .location = LOCATION;
- mLockedContactInfo .number = NUMBER;
- }
-
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- ContactsPreferencesFactory.setTestInstance(null);
- }
-
- public void testGetNameForCall_Unlocked() {
- ContactsPreferencesFactory.setTestInstance(mContactsPreferences);
- CallCardPresenter presenter = new CallCardPresenter();
- presenter.init(getContext(), null);
-
- assertEquals(NAME_PRIMARY, presenter.getNameForCall(mUnlockedContactInfo));
- }
-
- public void testGetNameForCall_Locked() {
- ContactsPreferencesFactory.setTestInstance(null);
- CallCardPresenter presenter = new CallCardPresenter();
- presenter.init(getContext(), null);
-
- assertEquals(NUMBER, presenter.getNameForCall(mLockedContactInfo));
- }
-
- public void testGetNameForCall_EmptyPreferredName() {
- ContactCacheEntry contactInfo = new ContactCacheEntry();
- contactInfo.number = NUMBER;
-
- ContactsPreferencesFactory.setTestInstance(null);
- CallCardPresenter presenter = new CallCardPresenter();
- presenter.init(getContext(), null);
-
- assertEquals(NUMBER, presenter.getNameForCall(contactInfo));
- }
-
- public void testGetNumberForCall_Unlocked() {
- ContactsPreferencesFactory.setTestInstance(mContactsPreferences);
- CallCardPresenter presenter = new CallCardPresenter();
- presenter.init(getContext(), null);
-
- assertEquals(NUMBER, presenter.getNumberForCall(mUnlockedContactInfo));
- }
-
- public void testGetNumberForCall_Locked() {
- ContactsPreferencesFactory.setTestInstance(null);
- CallCardPresenter presenter = new CallCardPresenter();
- presenter.init(getContext(), null);
-
- assertEquals(LOCATION, presenter.getNumberForCall(mLockedContactInfo));
- }
-
- public void testGetNumberForCall_EmptyPreferredName() {
- ContactCacheEntry contactInfo = new ContactCacheEntry();
- contactInfo.location = LOCATION;
-
- ContactsPreferencesFactory.setTestInstance(null);
- CallCardPresenter presenter = new CallCardPresenter();
- presenter.init(getContext(), null);
-
- assertEquals(LOCATION, presenter.getNumberForCall(contactInfo));
- }
-}
diff --git a/InCallUI/tests/src/com/android/incallui/CallTest.java b/InCallUI/tests/src/com/android/incallui/CallTest.java
deleted file mode 100644
index 118ec38da..000000000
--- a/InCallUI/tests/src/com/android/incallui/CallTest.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (C) 2016 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.incallui;
-
-import android.os.Bundle;
-import android.telecom.Connection;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-// @formatter:off
-/**
- * Run test with
- * adb shell am instrument -e class com.android.incallui.CallTest -w com.google.android.dialer.tests/android.test.InstrumentationTestRunner
- */
-// @formatter:on
-
-@SmallTest
-public class CallTest extends AndroidTestCase {
-
- private TestCall mCall;
-
- private final static String CHILD_NUMBER = "123";
- private final static ArrayList<String> LAST_FORWARDED_NUMBER_LIST =
- new ArrayList(Arrays.asList("456", "789"));
- private final static String LAST_FORWARDED_NUMBER = "789";
- private final static String CALL_SUBJECT = "foo";
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
-
- mCall = new TestCall();
- }
-
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- }
-
- public void testUpdateFromCallExtras() {
- mCall.updateFromCallExtras(getTestBundle());
- verifyTestBundleResult();
- }
-
- public void testUpdateFromCallExtras_corruptedBundle() {
- mCall.setBundleCorrupted(true);
- mCall.updateFromCallExtras(getTestBundle());
-
- assertEquals(mCall.getChildNumber(), null);
- assertEquals(mCall.getLastForwardedNumber(), null);
- assertEquals(mCall.getCallSubject(), null);
- }
-
- public void testUpdateFromCallExtras_corruptedBundleOverwrite() {
-
- mCall.updateFromCallExtras(getTestBundle());
- mCall.setBundleCorrupted(true);
- Bundle bundle = new Bundle();
- bundle.putString(Connection.EXTRA_CHILD_ADDRESS, "321");
- bundle.putStringArrayList(Connection.EXTRA_LAST_FORWARDED_NUMBER,
- new ArrayList(Arrays.asList("654", "987")));
- bundle.putString(Connection.EXTRA_CALL_SUBJECT, "bar");
- mCall.updateFromCallExtras(bundle);
- //corrupted bundle should not overwrite existing values.
- verifyTestBundleResult();
- }
-
- private Bundle getTestBundle() {
- Bundle bundle = new Bundle();
- bundle.putString(Connection.EXTRA_CHILD_ADDRESS, CHILD_NUMBER);
- bundle.putStringArrayList(Connection.EXTRA_LAST_FORWARDED_NUMBER,
- LAST_FORWARDED_NUMBER_LIST);
- bundle.putString(Connection.EXTRA_CALL_SUBJECT, CALL_SUBJECT);
- return bundle;
- }
-
- private void verifyTestBundleResult() {
- assertEquals(CHILD_NUMBER, mCall.getChildNumber());
- assertEquals(LAST_FORWARDED_NUMBER, mCall.getLastForwardedNumber());
- assertEquals(CALL_SUBJECT, mCall.getCallSubject());
- }
-
- private class TestCall extends Call {
-
- private boolean mBundleCorrupted = false;
-
- public TestCall() {
- super(Call.State.NEW);
- }
-
- @Override
- public void updateFromCallExtras(Bundle bundle) {
- super.updateFromCallExtras(bundle);
- }
-
- public void setBundleCorrupted(boolean value) {
- this.mBundleCorrupted = value;
- }
-
- @Override
- protected boolean areCallExtrasCorrupted(Bundle callExtras) {
- if (mBundleCorrupted) {
- return true;
- }
- return super.areCallExtrasCorrupted(callExtras);
- }
- }
-}
diff --git a/InCallUI/tests/src/com/android/incallui/CallerInfoUtilsTest.java b/InCallUI/tests/src/com/android/incallui/CallerInfoUtilsTest.java
deleted file mode 100644
index de5a0239e..000000000
--- a/InCallUI/tests/src/com/android/incallui/CallerInfoUtilsTest.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2015 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.incallui;
-
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-
-@SmallTest
-public class CallerInfoUtilsTest extends AndroidTestCase {
- public void testToLogSafeNumber_email() {
- assertEquals("xxx@xxx.xxx", CallerInfoUtils.toLogSafePhoneNumber("foo@foo.com"));
- }
-
- public void testToLogSafeNumber_phoneNumber() {
- assertEquals("xxx-xxx-xxxx", CallerInfoUtils.toLogSafePhoneNumber("123-456-6789"));
- }
-}
diff --git a/InCallUI/tests/src/com/android/incallui/ContactsPreferencesFactoryTest.java b/InCallUI/tests/src/com/android/incallui/ContactsPreferencesFactoryTest.java
deleted file mode 100644
index bf915553b..000000000
--- a/InCallUI/tests/src/com/android/incallui/ContactsPreferencesFactoryTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2016 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.incallui;
-
-import com.android.dialer.compat.UserManagerCompat;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-
-import com.android.contacts.common.preference.ContactsPreferences;
-
-import org.mockito.Mockito;
-
-@SmallTest
-public class ContactsPreferencesFactoryTest extends AndroidTestCase {
-
- public void testNewContactsPreferences_Unlocked() {
- if (!UserManagerCompat.isUserUnlocked(getContext())) {
- return;
- }
- assertNotNull(ContactsPreferencesFactory.newContactsPreferences(getContext()));
- }
-
- public void testNewContactsPreferences_Locked() {
- if (UserManagerCompat.isUserUnlocked(getContext())) {
- return;
- }
- assertNull(ContactsPreferencesFactory.newContactsPreferences(getContext()));
- }
-
- public void testNewContactsPreferences_TestInstance() {
- ContactsPreferences testInstance = Mockito.mock(ContactsPreferences.class);
- ContactsPreferencesFactory.setTestInstance(testInstance);
- // Assert that it returns the same object always
- assertSame(testInstance, ContactsPreferencesFactory.newContactsPreferences(getContext()));
- assertSame(testInstance, ContactsPreferencesFactory.newContactsPreferences(getContext()));
- }
-}
diff --git a/InCallUI/tests/src/com/android/incallui/ExternalCallListTest.java b/InCallUI/tests/src/com/android/incallui/ExternalCallListTest.java
deleted file mode 100644
index 59434700c..000000000
--- a/InCallUI/tests/src/com/android/incallui/ExternalCallListTest.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Copyright (C) 2016 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.incallui;
-
-import android.content.ComponentName;
-import android.content.Context;
-import android.net.Uri;
-import android.os.Bundle;
-import android.telecom.*;
-import android.telecom.Call;
-import android.test.AndroidTestCase;
-
-import com.android.contacts.common.compat.CallSdkCompat;
-
-import java.lang.reflect.Constructor;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-public class ExternalCallListTest extends AndroidTestCase {
-
- private static class Listener implements ExternalCallList.ExternalCallListener {
- private CountDownLatch mCallAddedLatch = new CountDownLatch(1);
- private CountDownLatch mCallRemovedLatch = new CountDownLatch(1);
- private CountDownLatch mCallUpdatedLatch = new CountDownLatch(1);
-
- @Override
- public void onExternalCallAdded(Call call) {
- mCallAddedLatch.countDown();
- }
-
- @Override
- public void onExternalCallRemoved(Call call) {
- mCallRemovedLatch.countDown();
- }
-
- @Override
- public void onExternalCallUpdated(Call call) {
- mCallUpdatedLatch.countDown();
- }
-
- public boolean awaitCallAdded() {
- try {
- return mCallAddedLatch.await(WAIT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
- } catch (InterruptedException e) {
- return false;
- }
- }
-
- public boolean awaitCallRemoved() {
- try {
- return mCallRemovedLatch.await(WAIT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
- } catch (InterruptedException e) {
- return false;
- }
- }
-
- public boolean awaitCallUpdated() {
- try {
- return mCallUpdatedLatch.await(WAIT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
- } catch (InterruptedException e) {
- return false;
- }
- }
- }
-
- private static final int WAIT_TIMEOUT_MILLIS = 5000;
-
- private ExternalCallList mExternalCallList = new ExternalCallList();
- private Listener mExternalCallListener = new Listener();
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- mExternalCallList.addExternalCallListener(mExternalCallListener);
- }
-
- public void testAddCallSuccess() {
- TestTelecomCall call = getTestCall(CallSdkCompat.Details.PROPERTY_IS_EXTERNAL_CALL);
- mExternalCallList.onCallAdded(call.getCall());
- assertTrue(mExternalCallListener.awaitCallAdded());
- }
-
- public void testAddCallFail() {
- TestTelecomCall call = getTestCall(0 /* no properties */);
- try {
- mExternalCallList.onCallAdded(call.getCall());
- fail();
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testUpdateCall() {
- TestTelecomCall call = getTestCall(CallSdkCompat.Details.PROPERTY_IS_EXTERNAL_CALL);
- mExternalCallList.onCallAdded(call.getCall());
- assertTrue(mExternalCallListener.awaitCallAdded());
-
- call.forceDetailsUpdate();
- assertTrue(mExternalCallListener.awaitCallUpdated());
- }
-
- public void testRemoveCall() {
- TestTelecomCall call = getTestCall(CallSdkCompat.Details.PROPERTY_IS_EXTERNAL_CALL);
- mExternalCallList.onCallAdded(call.getCall());
- assertTrue(mExternalCallListener.awaitCallAdded());
-
- mExternalCallList.onCallRemoved(call.getCall());
- assertTrue(mExternalCallListener.awaitCallRemoved());
- }
-
- private TestTelecomCall getTestCall(int properties) {
- TestTelecomCall testCall = TestTelecomCall.createInstance(
- "1",
- Uri.parse("tel:650-555-1212"), /* handle */
- TelecomManager.PRESENTATION_ALLOWED, /* handlePresentation */
- "Joe", /* callerDisplayName */
- TelecomManager.PRESENTATION_ALLOWED, /* callerDisplayNamePresentation */
- new PhoneAccountHandle(new ComponentName("test", "class"),
- "handle"), /* accountHandle */
- CallSdkCompat.Details.CAPABILITY_CAN_PULL_CALL, /* capabilities */
- properties, /* properties */
- null, /* disconnectCause */
- 0, /* connectTimeMillis */
- null, /* GatewayInfo */
- VideoProfile.STATE_AUDIO_ONLY, /* videoState */
- null, /* statusHints */
- null, /* extras */
- null /* intentExtras */);
- return testCall;
- }
-}
diff --git a/InCallUI/tests/src/com/android/incallui/ExternalCallNotifierTest.java b/InCallUI/tests/src/com/android/incallui/ExternalCallNotifierTest.java
deleted file mode 100644
index 64ddd2ea5..000000000
--- a/InCallUI/tests/src/com/android/incallui/ExternalCallNotifierTest.java
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * Copyright (C) 2016 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.incallui;
-
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.anyBoolean;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.eq;
-import static org.mockito.Mockito.timeout;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import com.android.contacts.common.preference.ContactsPreferences;
-
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.mockito.Spy;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.res.Resources;
-import android.net.Uri;
-import android.telecom.*;
-import android.telecom.Call;
-import android.telephony.TelephonyManager;
-import android.test.AndroidTestCase;
-import android.test.mock.MockContext;
-
-import com.android.contacts.common.compat.CallSdkCompat;
-
-/**
- * Unit tests for {@link ExternalCallNotifier}.
- */
-public class ExternalCallNotifierTest extends AndroidTestCase {
- private static final int TIMEOUT_MILLIS = 5000;
- private static final String NAME_PRIMARY = "Full Name";
- private static final String NAME_ALTERNATIVE = "Name, Full";
- private static final String LOCATION = "US";
- private static final String NUMBER = "6505551212";
-
- @Mock private ContactsPreferences mContactsPreferences;
- @Mock private NotificationManager mNotificationManager;
- @Mock private MockContext mMockContext;
- @Mock private Resources mResources;
- @Mock private StatusBarNotifier mStatusBarNotifier;
- @Mock private ContactInfoCache mContactInfoCache;
- @Mock private TelecomManager mTelecomManager;
- @Mock private TelephonyManager mTelephonyManager;
- @Mock private ProximitySensor mProximitySensor;
- @Mock private CallList mCallList;
- private InCallPresenter mInCallPresenter;
- private ExternalCallNotifier mExternalCallNotifier;
- private ContactInfoCache.ContactCacheEntry mContactInfo;
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- MockitoAnnotations.initMocks(this);
-
- when(mContactsPreferences.getDisplayOrder())
- .thenReturn(ContactsPreferences.DISPLAY_ORDER_PRIMARY);
-
- // Setup the mock context to return mocks for some of the needed services; the notification
- // service is especially important as we want to be able to intercept calls into it and
- // validate the notifcations.
- when(mMockContext.getSystemService(eq(Context.NOTIFICATION_SERVICE)))
- .thenReturn(mNotificationManager);
- when(mMockContext.getSystemService(eq(Context.TELECOM_SERVICE)))
- .thenReturn(mTelecomManager);
- when(mMockContext.getSystemService(eq(Context.TELEPHONY_SERVICE)))
- .thenReturn(mTelephonyManager);
-
- // These aspects of the context are used by the notification builder to build the actual
- // notification; we will rely on the actual implementations of these.
- when(mMockContext.getPackageManager()).thenReturn(mContext.getPackageManager());
- when(mMockContext.getResources()).thenReturn(mContext.getResources());
- when(mMockContext.getApplicationInfo()).thenReturn(mContext.getApplicationInfo());
- when(mMockContext.getContentResolver()).thenReturn(mContext.getContentResolver());
- when(mMockContext.getPackageName()).thenReturn(mContext.getPackageName());
-
- ContactsPreferencesFactory.setTestInstance(null);
- mExternalCallNotifier = new ExternalCallNotifier(mMockContext, mContactInfoCache);
-
- // We don't directly use the InCallPresenter in the test, or even in ExternalCallNotifier
- // itself. However, ExternalCallNotifier needs to make instances of
- // com.android.incallui.Call for the purpose of performing contact cache lookups. The
- // Call class depends on the static InCallPresenter for a number of things, so we need to
- // set it up here to prevent crashes.
- mInCallPresenter = InCallPresenter.getInstance();
- mInCallPresenter.setUp(mMockContext, mCallList, new ExternalCallList(),
- null, mStatusBarNotifier, mExternalCallNotifier, mContactInfoCache,
- mProximitySensor);
-
- // Unlocked all contact info is available
- mContactInfo = new ContactInfoCache.ContactCacheEntry();
- mContactInfo.namePrimary = NAME_PRIMARY;
- mContactInfo.nameAlternative = NAME_ALTERNATIVE;
- mContactInfo.location = LOCATION;
- mContactInfo.number = NUMBER;
-
- // Given the mock ContactInfoCache cache, we need to mock out what happens when the
- // ExternalCallNotifier calls into the contact info cache to do a lookup. We will always
- // return mock info stored in mContactInfo.
- doAnswer(new Answer() {
- @Override
- public Object answer(InvocationOnMock invocation) throws Throwable {
- Object[] args = invocation.getArguments();
- com.android.incallui.Call call = (com.android.incallui.Call) args[0];
- ContactInfoCache.ContactInfoCacheCallback callback
- = (ContactInfoCache.ContactInfoCacheCallback) args[2];
- callback.onContactInfoComplete(call.getId(), mContactInfo);
- return null;
- }
- }).when(mContactInfoCache).findInfo(any(com.android.incallui.Call.class), anyBoolean(),
- any(ContactInfoCache.ContactInfoCacheCallback.class));
- }
-
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- ContactsPreferencesFactory.setTestInstance(null);
- mInCallPresenter.tearDown();
- }
-
- public void testPostNonPullable() {
- TestTelecomCall call = getTestCall(false);
- mExternalCallNotifier.onExternalCallAdded(call.getCall());
- Notification notification = verifyNotificationPosted();
- assertNull(notification.actions);
- }
-
- public void testPostPullable() {
- TestTelecomCall call = getTestCall(true);
- mExternalCallNotifier.onExternalCallAdded(call.getCall());
- Notification notification = verifyNotificationPosted();
- assertEquals(1, notification.actions.length);
- }
-
- public void testNotificationDismissed() {
- TestTelecomCall call = getTestCall(false);
- mExternalCallNotifier.onExternalCallAdded(call.getCall());
- verifyNotificationPosted();
-
- mExternalCallNotifier.onExternalCallRemoved(call.getCall());
- verify(mNotificationManager, timeout(TIMEOUT_MILLIS)).cancel(eq("EXTERNAL_CALL"), eq(0));
- }
-
- public void testNotificationUpdated() {
- TestTelecomCall call = getTestCall(false);
- mExternalCallNotifier.onExternalCallAdded(call.getCall());
- verifyNotificationPosted();
-
- call.setCapabilities(CallSdkCompat.Details.CAPABILITY_CAN_PULL_CALL);
- mExternalCallNotifier.onExternalCallUpdated(call.getCall());
-
- ArgumentCaptor<Notification> notificationCaptor =
- ArgumentCaptor.forClass(Notification.class);
- verify(mNotificationManager, timeout(TIMEOUT_MILLIS).times(2))
- .notify(eq("EXTERNAL_CALL"), eq(0), notificationCaptor.capture());
- Notification notification1 = notificationCaptor.getAllValues().get(0);
- assertNull(notification1.actions);
- Notification notification2 = notificationCaptor.getAllValues().get(1);
- assertEquals(1, notification2.actions.length);
- }
-
- private Notification verifyNotificationPosted() {
- ArgumentCaptor<Notification> notificationCaptor =
- ArgumentCaptor.forClass(Notification.class);
- verify(mNotificationManager, timeout(TIMEOUT_MILLIS))
- .notify(eq("EXTERNAL_CALL"), eq(0), notificationCaptor.capture());
- return notificationCaptor.getValue();
- }
-
- private TestTelecomCall getTestCall(boolean canPull) {
- TestTelecomCall testCall = TestTelecomCall.createInstance(
- "1",
- Uri.parse("tel:650-555-1212"), /* handle */
- TelecomManager.PRESENTATION_ALLOWED, /* handlePresentation */
- "Joe", /* callerDisplayName */
- TelecomManager.PRESENTATION_ALLOWED, /* callerDisplayNamePresentation */
- new PhoneAccountHandle(new ComponentName("test", "class"),
- "handle"), /* accountHandle */
- canPull ? CallSdkCompat.Details.CAPABILITY_CAN_PULL_CALL : 0, /* capabilities */
- CallSdkCompat.Details.PROPERTY_IS_EXTERNAL_CALL, /* properties */
- null, /* disconnectCause */
- 0, /* connectTimeMillis */
- null, /* GatewayInfo */
- VideoProfile.STATE_AUDIO_ONLY, /* videoState */
- null, /* statusHints */
- null, /* extras */
- null /* intentExtras */);
- return testCall;
- }
-}
diff --git a/InCallUI/tests/src/com/android/incallui/InCallContactInteractionsTest.java b/InCallUI/tests/src/com/android/incallui/InCallContactInteractionsTest.java
deleted file mode 100644
index 625cda448..000000000
--- a/InCallUI/tests/src/com/android/incallui/InCallContactInteractionsTest.java
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
- * Copyright (C) 2015 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.incallui;
-
-import android.location.Address;
-import android.test.AndroidTestCase;
-import android.util.Pair;
-
-import com.android.incallui.InCallContactInteractions.BusinessContextInfo;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.List;
-import java.util.Locale;
-
-/**
- * Tests for InCallContactInteractions class methods for formatting info for display.
- *
- * NOTE: tests assume system settings are set to 12hr time format and US locale. This means that
- * the output of InCallContactInteractions methods are compared against strings in 12hr time format
- * and US locale address formatting unless otherwise specified.
- */
-public class InCallContactInteractionsTest extends AndroidTestCase {
- private InCallContactInteractions mInCallContactInteractions;
- private static final float TEST_DISTANCE = (float) 1234.56;
-
- @Override
- protected void setUp() {
- mInCallContactInteractions = new InCallContactInteractions(mContext, true /* isBusiness */);
- }
-
- public void testIsOpenNow_NowMatchesOpenTime() {
- assertEquals(mContext.getString(R.string.open_now),
- mInCallContactInteractions.constructHoursInfo(
- getTestCalendarWithHour(8),
- Arrays.asList(
- Pair.create(
- getTestCalendarWithHour(8),
- getTestCalendarWithHour(20))))
- .heading);
- }
-
- public void testIsOpenNow_ClosingAfterMidnight() {
- assertEquals(mContext.getString(R.string.open_now),
- mInCallContactInteractions.constructHoursInfo(
- getTestCalendarWithHour(10),
- Arrays.asList(
- Pair.create(
- getTestCalendarWithHour(8),
- getTestCalendarWithHourAndDaysFromToday(1, 1))))
- .heading);
- }
-
- public void testIsOpenNow_Open24Hours() {
- assertEquals(mContext.getString(R.string.open_now),
- mInCallContactInteractions.constructHoursInfo(
- getTestCalendarWithHour(10),
- Arrays.asList(
- Pair.create(
- getTestCalendarWithHour(8),
- getTestCalendarWithHourAndDaysFromToday(8, 1))))
- .heading);
- }
-
- public void testIsOpenNow_AfterMiddayBreak() {
- assertEquals(mContext.getString(R.string.open_now),
- mInCallContactInteractions.constructHoursInfo(
- getTestCalendarWithHour(13),
- Arrays.asList(
- Pair.create(
- getTestCalendarWithHour(8),
- getTestCalendarWithHour(10)),
- Pair.create(
- getTestCalendarWithHour(12),
- getTestCalendarWithHour(15))))
- .heading);
- }
-
- public void testIsClosedNow_DuringMiddayBreak() {
- assertEquals(mContext.getString(R.string.closed_now),
- mInCallContactInteractions.constructHoursInfo(
- getTestCalendarWithHour(11),
- Arrays.asList(
- Pair.create(
- getTestCalendarWithHour(8),
- getTestCalendarWithHour(10)),
- Pair.create(
- getTestCalendarWithHour(12),
- getTestCalendarWithHour(15))))
- .heading);
- }
-
- public void testIsClosedNow_BeforeOpen() {
- assertEquals(mContext.getString(R.string.closed_now),
- mInCallContactInteractions.constructHoursInfo(
- getTestCalendarWithHour(6),
- Arrays.asList(
- Pair.create(
- getTestCalendarWithHour(8),
- getTestCalendarWithHour(20))))
- .heading);
- }
-
- public void testIsClosedNow_NowMatchesClosedTime() {
- assertEquals(mContext.getString(R.string.closed_now),
- mInCallContactInteractions.constructHoursInfo(
- getTestCalendarWithHour(20),
- Arrays.asList(
- Pair.create(
- getTestCalendarWithHour(8),
- getTestCalendarWithHour(20))))
- .heading);
- }
-
- public void testIsClosedNow_AfterClosed() {
- assertEquals(mContext.getString(R.string.closed_now),
- mInCallContactInteractions.constructHoursInfo(
- getTestCalendarWithHour(21),
- Arrays.asList(
- Pair.create(
- getTestCalendarWithHour(8),
- getTestCalendarWithHour(20))))
- .heading);
- }
-
- public void testOpeningHours_SingleOpenRangeWhileOpen() {
- assertEquals("8:00 AM - 8:00 PM",
- mInCallContactInteractions.constructHoursInfo(
- getTestCalendarWithHour(12),
- Arrays.asList(
- Pair.create(
- getTestCalendarWithHour(8),
- getTestCalendarWithHour(20))))
- .detail);
- }
-
- public void testOpeningHours_TwoOpenRangesWhileOpen() {
- assertEquals("8:00 AM - 10:00 AM, 12:00 PM - 3:00 PM",
- mInCallContactInteractions.constructHoursInfo(
- getTestCalendarWithHour(12),
- Arrays.asList(
- Pair.create(
- getTestCalendarWithHour(8),
- getTestCalendarWithHour(10)),
- Pair.create(
- getTestCalendarWithHour(12),
- getTestCalendarWithHour(15))))
- .detail);
- }
-
- public void testOpeningHours_AfterClosedNoTomorrow() {
- assertEquals("Closed today at 8:00 PM",
- mInCallContactInteractions.constructHoursInfo(
- getTestCalendarWithHour(21),
- Arrays.asList(
- Pair.create(
- getTestCalendarWithHour(8),
- getTestCalendarWithHour(20))))
- .detail);
- }
-
- public void testOpeningHours_NotOpenTodayOpenTomorrow() {
- assertEquals("Opens tomorrow at 8:00 AM",
- mInCallContactInteractions.constructHoursInfo(
- getTestCalendarWithHour(21),
- Arrays.asList(
- Pair.create(
- getTestCalendarWithHourAndDaysFromToday(8, 1),
- getTestCalendarWithHourAndDaysFromToday(10, 1))))
- .detail);
- }
-
- public void testMultipleOpenRanges_BeforeOpen() {
- assertEquals("Opens today at 8:00 AM",
- mInCallContactInteractions.constructHoursInfo(
- getTestCalendarWithHour(7),
- getMultipleOpeningHours())
- .detail);
- }
-
- public void testMultipleOpenRanges_DuringFirstRange() {
- assertEquals("Closes at 10:00 AM",
- mInCallContactInteractions.constructHoursInfo(
- getTestCalendarWithHour(9),
- getMultipleOpeningHours())
- .detail);
- }
-
- public void testMultipleOpenRanges_BeforeMiddleRange() {
- assertEquals("Opens today at 12:00 PM",
- mInCallContactInteractions.constructHoursInfo(
- getTestCalendarWithHour(11),
- getMultipleOpeningHours())
- .detail);
- }
-
- public void testMultipleOpeningHours_DuringLastRange() {
- assertEquals("Closes at 9:00 PM",
- mInCallContactInteractions.constructHoursInfo(
- getTestCalendarWithHour(19),
- getMultipleOpeningHours())
- .detail);
- }
-
- public void testMultipleOpeningHours_AfterClose() {
- assertEquals("Opens tomorrow at 8:00 AM",
- mInCallContactInteractions.constructHoursInfo(
- getTestCalendarWithHour(22),
- getMultipleOpeningHours())
- .detail);
- }
-
- public void testNotOpenTodayOrTomorrow() {
- assertEquals(null,
- mInCallContactInteractions.constructHoursInfo(
- getTestCalendarWithHour(21),
- new ArrayList<Pair<Calendar, Calendar>>()));
- }
-
- public void testLocationInfo_ForUS() {
- BusinessContextInfo info =
- mInCallContactInteractions.constructLocationInfo(
- Locale.US,
- getAddressForTest(),
- TEST_DISTANCE);
- assertEquals("0.8 mi away", info.heading);
- assertEquals("Test address, Test locality", info.detail);
- }
-
- public void testLocationInfo_ForNotUS() {
- BusinessContextInfo info =
- mInCallContactInteractions.constructLocationInfo(
- Locale.CANADA,
- getAddressForTest(),
- TEST_DISTANCE);
- assertEquals("1.2 km away", info.heading);
- assertEquals("Test address, Test locality", info.detail);
- }
-
- public void testLocationInfo_NoLocality() {
- Address address = getAddressForTest();
- address.setLocality(null);
- BusinessContextInfo info =
- mInCallContactInteractions.constructLocationInfo(
- Locale.CANADA,
- address,
- TEST_DISTANCE);
- assertEquals("1.2 km away", info.heading);
- assertEquals("Test address", info.detail);
- }
-
- public void testLocationInfo_NoAddress() {
- BusinessContextInfo info =
- mInCallContactInteractions.constructLocationInfo(
- Locale.CANADA,
- null,
- TEST_DISTANCE);
- assertEquals(null, info);
- }
-
- public void testLocationInfo_NoDistance() {
- BusinessContextInfo info =
- mInCallContactInteractions.constructLocationInfo(
- Locale.US,
- getAddressForTest(),
- DistanceHelper.DISTANCE_NOT_FOUND);
- assertEquals(null, info.heading);
- }
-
- private Address getAddressForTest() {
- Address address = new Address(Locale.US);
- address.setAddressLine(0, "Test address");
- address.setLocality("Test locality");
- return address;
- }
-
- private Calendar getTestCalendarWithHour(int hour) {
- Calendar calendar = Calendar.getInstance();
- calendar.set(Calendar.HOUR_OF_DAY, hour);
- calendar.set(Calendar.MINUTE, 0);
- calendar.set(Calendar.SECOND, 0);
- calendar.set(Calendar.MILLISECOND, 0);
- return calendar;
- }
-
- private Calendar getTestCalendarWithHourAndDaysFromToday(int hour, int daysFromToday) {
- Calendar calendar = getTestCalendarWithHour(hour);
- calendar.add(Calendar.DATE, daysFromToday);
- return calendar;
- }
-
- private List<Pair<Calendar, Calendar>> getMultipleOpeningHours() {
- return Arrays.asList(
- Pair.create(
- getTestCalendarWithHour(8),
- getTestCalendarWithHour(10)),
- Pair.create(
- getTestCalendarWithHour(12),
- getTestCalendarWithHour(15)),
- Pair.create(
- getTestCalendarWithHour(17),
- getTestCalendarWithHour(21)),
- Pair.create(
- getTestCalendarWithHourAndDaysFromToday(8, 1),
- getTestCalendarWithHourAndDaysFromToday(10, 1)),
- Pair.create(
- getTestCalendarWithHourAndDaysFromToday(12, 1),
- getTestCalendarWithHourAndDaysFromToday(8, 1)));
- }
-}
diff --git a/InCallUI/tests/src/com/android/incallui/InCallPresenterTest.java b/InCallUI/tests/src/com/android/incallui/InCallPresenterTest.java
deleted file mode 100644
index f0f08ab68..000000000
--- a/InCallUI/tests/src/com/android/incallui/InCallPresenterTest.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Copyright (C) 2015 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.incallui;
-
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.content.Intent;
-import android.telecom.PhoneAccountHandle;
-import android.telephony.TelephonyManager;
-import android.test.InstrumentationTestCase;
-import android.test.suitebuilder.annotation.MediumTest;
-
-import com.android.incallui.InCallPresenter.InCallState;
-
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-
-@MediumTest
-public class InCallPresenterTest extends InstrumentationTestCase {
- private MockCallListWrapper mCallList;
- @Mock private InCallActivity mInCallActivity;
- @Mock private AudioModeProvider mAudioModeProvider;
- @Mock private StatusBarNotifier mStatusBarNotifier;
- @Mock private ExternalCallNotifier mExternalCallNotifier;
- @Mock private ContactInfoCache mContactInfoCache;
- @Mock private ProximitySensor mProximitySensor;
-
- InCallPresenter mInCallPresenter;
- @Mock private Context mContext;
- @Mock private TelephonyManager mTelephonyManager;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- System.setProperty("dexmaker.dexcache",
- getInstrumentation().getTargetContext().getCacheDir().getPath());
- MockitoAnnotations.initMocks(this);
- mCallList = new MockCallListWrapper();
-
- when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
-
- mInCallPresenter = InCallPresenter.getInstance();
- mInCallPresenter.setUp(mContext, mCallList.getCallList(), new ExternalCallList(),
- mAudioModeProvider, mStatusBarNotifier, mExternalCallNotifier, mContactInfoCache,
- mProximitySensor);
- }
-
- @Override
- protected void tearDown() throws Exception {
- // The tear down method needs to run in the main thread since there is an explicit check
- // inside TelecomAdapter.getInstance().
- getInstrumentation().runOnMainSync(new Runnable() {
- @Override
- public void run() {
- mInCallPresenter.unsetActivity(mInCallActivity);
- mInCallPresenter.tearDown();
- InCallPresenter.setInstance(null);
- }
- });
- }
-
- public void testOnActivitySet_finishesActivityWhenNoCalls() {
- mInCallPresenter.setActivity(mInCallActivity);
-
- verify(mInCallActivity).finish();
- }
-
- public void testOnCallListChange_sendsNotificationWhenInCall() {
- mCallList.setHasCall(Call.State.INCOMING, true);
-
- mInCallPresenter.onCallListChange(mCallList.getCallList());
-
- verify(mStatusBarNotifier).updateNotification(InCallState.INCOMING,
- mCallList.getCallList());
- verifyInCallActivityNotStarted();
- }
-
- /**
- * This behavior is required to ensure that the screen is turned on again by the restarting
- * activity.
- */
- public void testOnCallListChange_handlesCallWaitingWhenScreenOffShouldRestartActivity() {
- mCallList.setHasCall(Call.State.ACTIVE, true);
-
- mInCallPresenter.onCallListChange(mCallList.getCallList());
- mInCallPresenter.setActivity(mInCallActivity);
-
- // Pretend that there is a call waiting and the screen is off
- when(mInCallActivity.isDestroyed()).thenReturn(false);
- when(mInCallActivity.isFinishing()).thenReturn(false);
- when(mProximitySensor.isScreenReallyOff()).thenReturn(true);
- mCallList.setHasCall(Call.State.INCOMING, true);
-
- mInCallPresenter.onCallListChange(mCallList.getCallList());
- verify(mInCallActivity).finish();
- }
-
- /**
- * Verifies that the PENDING_OUTGOING -> IN_CALL transition brings up InCallActivity so
- * that it can display an error dialog.
- */
- public void testOnCallListChange_pendingOutgoingToInCallTransitionShowsUiForErrorDialog() {
- mCallList.setHasCall(Call.State.CONNECTING, true);
-
- mInCallPresenter.onCallListChange(mCallList.getCallList());
-
- mCallList.setHasCall(Call.State.CONNECTING, false);
- mCallList.setHasCall(Call.State.ACTIVE, true);
-
- mInCallPresenter.onCallListChange(mCallList.getCallList());
-
- verify(mContext).startActivity(InCallPresenter.getInstance().getInCallIntent(false, false));
- verifyIncomingCallNotificationNotSent();
- }
-
- /**
- * Verifies that if there is a call in the SELECT_PHONE_ACCOUNT state, InCallActivity is displayed
- * to display the account picker.
- */
- public void testOnCallListChange_noAccountProvidedForCallShowsUiForAccountPicker() {
- mCallList.setHasCall(Call.State.SELECT_PHONE_ACCOUNT, true);
- mInCallPresenter.onCallListChange(mCallList.getCallList());
-
- verify(mContext).startActivity(InCallPresenter.getInstance().getInCallIntent(false, false));
- verifyIncomingCallNotificationNotSent();
- }
-
- /**
- * Verifies that for an expected call state change (e.g. NO_CALLS -> PENDING_OUTGOING),
- * InCallActivity is not displayed.
- */
- public void testOnCallListChange_noCallsToPendingOutgoingDoesNotShowUi() {
- mCallList.setHasCall(Call.State.CONNECTING, true);
- mInCallPresenter.onCallListChange(mCallList.getCallList());
-
- verifyInCallActivityNotStarted();
- verifyIncomingCallNotificationNotSent();
- }
-
- public void testOnCallListChange_LastCallDisconnectedNoCallsLeftFinishesUi() {
- mCallList.setHasCall(Call.State.DISCONNECTED, true);
- mInCallPresenter.onCallListChange(mCallList.getCallList());
-
- mInCallPresenter.setActivity(mInCallActivity);
-
- verify(mInCallActivity, never()).finish();
-
- // Last remaining disconnected call is removed from CallList, activity should shut down.
- mCallList.setHasCall(Call.State.DISCONNECTED, false);
- mInCallPresenter.onCallListChange(mCallList.getCallList());
- verify(mInCallActivity).finish();
- }
-
-
- //TODO
- public void testCircularReveal_startsCircularRevealForOutgoingCalls() {
-
- }
-
- public void testCircularReveal_waitTillCircularRevealSentBeforeShowingCallCard() {
- }
-
- public void testHangupOngoingCall_disconnectsCallCorrectly() {
- }
-
- public void testAnswerIncomingCall() {
- }
-
- public void testDeclineIncomingCall() {
- }
-
- private void verifyInCallActivityNotStarted() {
- verify(mContext, never()).startActivity(Mockito.any(Intent.class));
- }
-
- private void verifyIncomingCallNotificationNotSent() {
- verify(mStatusBarNotifier, never()).updateNotification(Mockito.any(InCallState.class),
- Mockito.any(CallList.class));
- }
-}
diff --git a/InCallUI/tests/src/com/android/incallui/LatencyReportTest.java b/InCallUI/tests/src/com/android/incallui/LatencyReportTest.java
deleted file mode 100644
index 9d8a5131b..000000000
--- a/InCallUI/tests/src/com/android/incallui/LatencyReportTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2016 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.incallui;
-
-import static com.android.incallui.LatencyReport.INVALID_TIME;
-
-import android.os.Bundle;
-import android.telecom.Connection;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-public class LatencyReportTest extends AndroidTestCase {
- public void testEmptyInit() {
- LatencyReport report = new LatencyReport();
- assertEquals(INVALID_TIME, report.getCreatedTimeMillis());
- assertEquals(INVALID_TIME, report.getTelecomRoutingStartTimeMillis());
- assertEquals(INVALID_TIME, report.getTelecomRoutingEndTimeMillis());
- assertTrue(report.getCallAddedTimeMillis() > 0);
- }
-
- public void testCallBlocking() {
- LatencyReport report = new LatencyReport();
- assertEquals(INVALID_TIME, report.getCallBlockingTimeMillis());
- report.onCallBlockingDone();
- assertTrue(report.getCallBlockingTimeMillis() > 0);
- }
-
- public void testNotificationShown() {
- LatencyReport report = new LatencyReport();
- assertEquals(INVALID_TIME, report.getCallNotificationTimeMillis());
- report.onNotificationShown();
- assertTrue(report.getCallNotificationTimeMillis() > 0);
- }
-
- public void testInCallUiShown() {
- LatencyReport report = new LatencyReport();
- assertEquals(INVALID_TIME, report.getInCallUiShownTimeMillis());
- report.onInCallUiShown(false);
- assertTrue(report.getInCallUiShownTimeMillis() > 0);
- assertFalse(report.getDidDisplayHeadsUpNotification());
- }
-}
diff --git a/InCallUI/tests/src/com/android/incallui/MockCallListWrapper.java b/InCallUI/tests/src/com/android/incallui/MockCallListWrapper.java
deleted file mode 100644
index 369c4303f..000000000
--- a/InCallUI/tests/src/com/android/incallui/MockCallListWrapper.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2015 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.incallui;
-
-import static org.mockito.Mockito.anyInt;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
-import android.telecom.PhoneAccountHandle;
-
-import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-import java.util.HashSet;
-
-/**
- * Provides an instance of a mock CallList, and provides utility methods to put the CallList into
- * various states (e.g. incoming call, active call, call waiting).
- */
-public class MockCallListWrapper {
- private CallList mCallList;
- private HashSet<Integer> mCallSet = new HashSet<>();
-
- public MockCallListWrapper() {
- mCallList = Mockito.mock(CallList.class);
- mCallList = spy(new CallList());
- when(mCallList.getFirstCallWithState(anyInt())).thenAnswer(new Answer<Call>() {
- @Override
- public Call answer(InvocationOnMock i) throws Throwable {
- Object[] args = i.getArguments();
- final int state = (int) args[0];
- if (mCallSet.contains(state)) {
- return getMockCall(state);
- } else {
- return null;
- }
- }
- });
- }
-
- public CallList getCallList() {
- return mCallList;
- }
-
- public void setHasCall(int state, boolean hasCall) {
- if (hasCall) {
- mCallSet.add(state);
- } else {
- mCallSet.remove(state);
- }
- }
-
- private static Call getMockCall(int state) {
- return getMockCall(state, state != Call.State.SELECT_PHONE_ACCOUNT);
- }
-
- private static Call getMockCall(int state, boolean hasAccountHandle) {
- final Call call = Mockito.mock(Call.class);
- when(call.getState()).thenReturn(Integer.valueOf(state));
- if (hasAccountHandle) {
- when(call.getAccountHandle()).thenReturn(new PhoneAccountHandle(null, null));
- }
- return call;
- }
-}
diff --git a/InCallUI/tests/src/com/android/incallui/ProximitySensorTest.java b/InCallUI/tests/src/com/android/incallui/ProximitySensorTest.java
deleted file mode 100644
index 1c8f34721..000000000
--- a/InCallUI/tests/src/com/android/incallui/ProximitySensorTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) 2015 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.incallui;
-
-import static org.mockito.Mockito.anyBoolean;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-import android.test.InstrumentationTestCase;
-import android.test.suitebuilder.annotation.MediumTest;
-
-import com.android.incallui.InCallPresenter.InCallState;
-
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-
-@MediumTest
-public class ProximitySensorTest extends InstrumentationTestCase {
- @Mock private AccelerometerListener mAccelerometerListener;
- private MockCallListWrapper mCallList;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- System.setProperty("dexmaker.dexcache",
- getInstrumentation().getTargetContext().getCacheDir().getPath());
- MockitoAnnotations.initMocks(this);
- mCallList = new MockCallListWrapper();
- }
-
- public void testAccelerometerBehaviorOnDisplayChange() {
- final ProximitySensor proximitySensor =
- new ProximitySensor(
- getInstrumentation().getContext(),
- new AudioModeProvider(),
- mAccelerometerListener);
- verify(mAccelerometerListener, never()).enable(anyBoolean());
- proximitySensor.onStateChange(null, InCallState.OUTGOING, mCallList.getCallList());
- verify(mAccelerometerListener).enable(true);
- verify(mAccelerometerListener, never()).enable(false);
-
- proximitySensor.onDisplayStateChanged(false);
- verify(mAccelerometerListener).enable(true);
- verify(mAccelerometerListener).enable(false);
-
- proximitySensor.onDisplayStateChanged(true);
- verify(mAccelerometerListener, times(2)).enable(true);
- verify(mAccelerometerListener).enable(false);
- }
-}
diff --git a/InCallUI/tests/src/com/android/incallui/StatusBarNotifierTest.java b/InCallUI/tests/src/com/android/incallui/StatusBarNotifierTest.java
deleted file mode 100644
index 4c55ddcc0..000000000
--- a/InCallUI/tests/src/com/android/incallui/StatusBarNotifierTest.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (C) 2016 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.incallui;
-
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.MediumTest;
-
-import com.android.contacts.common.preference.ContactsPreferences;
-import com.android.incallui.ContactInfoCache.ContactCacheEntry;
-
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-
-@MediumTest
-public class StatusBarNotifierTest extends AndroidTestCase {
-
- private static final String NAME_PRIMARY = "Full Name";
- private static final String NAME_ALTERNATIVE = "Name, Full";
- private static final String LOCATION = "US";
- private static final String NUMBER = "8006459001";
-
- @Mock private Call mCall;
- @Mock private ContactsPreferences mContactsPreferences;
- private ContactCacheEntry mUnlockedContactInfo;
- private ContactCacheEntry mLockedContactInfo;
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- MockitoAnnotations.initMocks(this);
-
- Mockito.when(mContactsPreferences.getDisplayOrder())
- .thenReturn(ContactsPreferences.DISPLAY_ORDER_PRIMARY);
-
- // Unlocked all contact info is available
- mUnlockedContactInfo = new ContactCacheEntry();
- mUnlockedContactInfo.namePrimary = NAME_PRIMARY;
- mUnlockedContactInfo.nameAlternative = NAME_ALTERNATIVE;
- mUnlockedContactInfo.location = LOCATION;
- mUnlockedContactInfo.number = NUMBER;
-
- // Locked only number and location are available
- mLockedContactInfo = new ContactCacheEntry();
- mLockedContactInfo .location = LOCATION;
- mLockedContactInfo .number = NUMBER;
- }
-
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- ContactsPreferencesFactory.setTestInstance(null);
- }
-
- public void testGetContentTitle_ConferenceCall() {
- ContactsPreferencesFactory.setTestInstance(null);
- StatusBarNotifier statusBarNotifier = new StatusBarNotifier(mContext, null);
-
- Mockito.when(mCall.isConferenceCall()).thenReturn(true);
- Mockito.when(mCall.hasProperty(Mockito.anyInt())).thenReturn(false);
-
- assertEquals(mContext.getResources().getString(R.string.card_title_conf_call),
- statusBarNotifier.getContentTitle(null, mCall));
- }
-
- public void testGetContentTitle_Unlocked() {
- ContactsPreferencesFactory.setTestInstance(mContactsPreferences);
- StatusBarNotifier statusBarNotifier = new StatusBarNotifier(mContext, null);
- assertEquals(NAME_PRIMARY, statusBarNotifier.getContentTitle(mUnlockedContactInfo, mCall));
- }
-
- public void testGetContentTitle_Locked() {
- ContactsPreferencesFactory.setTestInstance(null);
- StatusBarNotifier statusBarNotifier = new StatusBarNotifier(mContext, null);
- assertEquals(NUMBER, statusBarNotifier.getContentTitle(mLockedContactInfo, mCall));
- }
-
- public void testGetContentTitle_EmptyPreferredName() {
- ContactCacheEntry contactCacheEntry = new ContactCacheEntry();
- contactCacheEntry.number = NUMBER;
- StatusBarNotifier statusBarNotifier = new StatusBarNotifier(mContext, null);
- assertEquals(NUMBER, statusBarNotifier.getContentTitle(contactCacheEntry, mCall));
- }
-}
diff --git a/InCallUI/tests/src/com/android/incallui/TestTelecomCall.java b/InCallUI/tests/src/com/android/incallui/TestTelecomCall.java
deleted file mode 100644
index 48ac6e18f..000000000
--- a/InCallUI/tests/src/com/android/incallui/TestTelecomCall.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Copyright (C) 2016 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.incallui;
-
-import com.google.common.base.Preconditions;
-
-import android.content.Context;
-import android.net.Uri;
-import android.os.Bundle;
-import android.support.annotation.Nullable;
-import android.telecom.DisconnectCause;
-import android.telecom.GatewayInfo;
-import android.telecom.PhoneAccountHandle;
-import android.telecom.StatusHints;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-/**
- * Wrapper class which uses reflection to create instances of {@link android.telecom.Call} for use
- * with unit testing. Since {@link android.telecom.Call} is final, it cannot be mocked using
- * mockito, and since all setter methods are hidden, it is necessary to use reflection. In the
- * future, it would be desirable to replace this if a different mocking solution is used.
- */
-public class TestTelecomCall {
-
- private android.telecom.Call mCall;
-
- public static @Nullable TestTelecomCall createInstance(String callId,
- Uri handle,
- int handlePresentation,
- String callerDisplayName,
- int callerDisplayNamePresentation,
- PhoneAccountHandle accountHandle,
- int capabilities,
- int properties,
- DisconnectCause disconnectCause,
- long connectTimeMillis,
- GatewayInfo gatewayInfo,
- int videoState,
- StatusHints statusHints,
- Bundle extras,
- Bundle intentExtras) {
-
- try {
- // Phone and InCall adapter are @hide, so we cannot refer to them directly.
- Class<?> phoneClass = Class.forName("android.telecom.Phone");
- Class<?> incallAdapterClass = Class.forName("android.telecom.InCallAdapter");
- Class<?> callClass = android.telecom.Call.class;
- Constructor<?> cons = callClass
- .getDeclaredConstructor(phoneClass, String.class, incallAdapterClass);
- cons.setAccessible(true);
-
- android.telecom.Call call = (android.telecom.Call) cons.newInstance(null, callId, null);
-
- // Create an instance of the call details.
- Class<?> callDetailsClass = android.telecom.Call.Details.class;
- Constructor<?> detailsCons = callDetailsClass.getDeclaredConstructor(
- String.class, /* telecomCallId */
- Uri.class, /* handle */
- int.class, /* handlePresentation */
- String.class, /* callerDisplayName */
- int.class, /* callerDisplayNamePresentation */
- PhoneAccountHandle.class, /* accountHandle */
- int.class, /* capabilities */
- int.class, /* properties */
- DisconnectCause.class, /* disconnectCause */
- long.class, /* connectTimeMillis */
- GatewayInfo.class, /* gatewayInfo */
- int.class, /* videoState */
- StatusHints.class, /* statusHints */
- Bundle.class, /* extras */
- Bundle.class /* intentExtras */);
- detailsCons.setAccessible(true);
-
- android.telecom.Call.Details details = (android.telecom.Call.Details)
- detailsCons.newInstance(callId, handle, handlePresentation, callerDisplayName,
- callerDisplayNamePresentation, accountHandle, capabilities, properties,
- disconnectCause, connectTimeMillis, gatewayInfo, videoState,
- statusHints,
- extras, intentExtras);
-
- // Finally, set this as the details of the call.
- Field detailsField = call.getClass().getDeclaredField("mDetails");
- detailsField.setAccessible(true);
- detailsField.set(call, details);
-
- return new TestTelecomCall(call);
- } catch (NoSuchMethodException nsm) {
- return null;
- } catch (ClassNotFoundException cnf) {
- return null;
- } catch (IllegalAccessException e) {
- return null;
- } catch (InstantiationException e) {
- return null;
- } catch (InvocationTargetException e) {
- return null;
- } catch (NoSuchFieldException e) {
- return null;
- }
- }
-
- private TestTelecomCall(android.telecom.Call call) {
- mCall = call;
- }
-
- public android.telecom.Call getCall() {
- return mCall;
- }
-
- public void forceDetailsUpdate() {
- Preconditions.checkNotNull(mCall);
-
- try {
- Method method = mCall.getClass().getDeclaredMethod("fireDetailsChanged",
- android.telecom.Call.Details.class);
- method.setAccessible(true);
- method.invoke(mCall, mCall.getDetails());
- } catch (NoSuchMethodException e) {
- Log.e(this, "forceDetailsUpdate", e);
- } catch (InvocationTargetException e) {
- Log.e(this, "forceDetailsUpdate", e);
- } catch (IllegalAccessException e) {
- Log.e(this, "forceDetailsUpdate", e);
- }
- }
-
- public void setCapabilities(int capabilities) {
- Preconditions.checkNotNull(mCall);
- try {
- Field field = mCall.getDetails().getClass().getDeclaredField("mCallCapabilities");
- field.setAccessible(true);
- field.set(mCall.getDetails(), capabilities);
- } catch (IllegalAccessException e) {
- Log.e(this, "setProperties", e);
- } catch (NoSuchFieldException e) {
- Log.e(this, "setProperties", e);
- }
- }
-
- public void setCall(android.telecom.Call call) {
- mCall = call;
- }
-}
diff --git a/InCallUI/tests/src/com/android/incallui/async/SingleProdThreadExecutor.java b/InCallUI/tests/src/com/android/incallui/async/SingleProdThreadExecutor.java
deleted file mode 100644
index 5717c9478..000000000
--- a/InCallUI/tests/src/com/android/incallui/async/SingleProdThreadExecutor.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2016 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.incallui.async;
-
-import java.util.concurrent.Executors;
-
-import javax.annotation.concurrent.ThreadSafe;
-
-/**
- * {@link PausableExecutor} for use in tests. It is intended to be used between one test thread
- * and one prod thread. See {@link com.android.incallui.ringtone.InCallTonePlayerTest} for example
- * usage.
- */
-@ThreadSafe
-public final class SingleProdThreadExecutor implements PausableExecutor {
-
- private int mMilestonesReached;
- private int mMilestonesAcked;
- private boolean mHasAckedAllMilestones;
-
- @Override
- public synchronized void milestone() {
- ++mMilestonesReached;
- notify();
- while (!mHasAckedAllMilestones && mMilestonesReached > mMilestonesAcked) {
- try {
- wait();
- } catch (InterruptedException e) {}
- }
- }
-
- @Override
- public synchronized void ackMilestoneForTesting() {
- ++mMilestonesAcked;
- notify();
- }
-
- @Override
- public synchronized void ackAllMilestonesForTesting() {
- mHasAckedAllMilestones = true;
- notify();
- }
-
- @Override
- public synchronized void awaitMilestoneForTesting() throws InterruptedException {
- while (!mHasAckedAllMilestones && mMilestonesReached <= mMilestonesAcked) {
- wait();
- }
- }
-
- @Override
- public synchronized void execute(Runnable command) {
- Executors.newSingleThreadExecutor().execute(command);
- }
-}
diff --git a/InCallUI/tests/src/com/android/incallui/ringtone/DialerRingtoneManagerTest.java b/InCallUI/tests/src/com/android/incallui/ringtone/DialerRingtoneManagerTest.java
deleted file mode 100644
index 01db20272..000000000
--- a/InCallUI/tests/src/com/android/incallui/ringtone/DialerRingtoneManagerTest.java
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * Copyright (C) 2016 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.incallui.ringtone;
-
-import android.media.RingtoneManager;
-import android.net.Uri;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-
-import com.android.contacts.common.compat.CompatUtils;
-import com.android.incallui.Call;
-import com.android.incallui.Call.State;
-import com.android.incallui.CallList;
-
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-
-@SmallTest
-public class DialerRingtoneManagerTest extends AndroidTestCase {
-
- private static final Uri RINGTONE_URI = RingtoneManager
- .getDefaultUri(RingtoneManager.TYPE_RINGTONE);
-
- @Mock private InCallTonePlayer mInCallTonePlayer;
- @Mock private CallList mCallList;
- @Mock private Call mCall;
- private DialerRingtoneManager mRingtoneManagerEnabled;
- private DialerRingtoneManager mRingtoneManagerDisabled;
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- MockitoAnnotations.initMocks(this);
- mRingtoneManagerEnabled = new DialerRingtoneManager(mInCallTonePlayer, mCallList);
- mRingtoneManagerEnabled.setDialerRingingEnabledForTesting(true);
- mRingtoneManagerDisabled = new DialerRingtoneManager(mInCallTonePlayer, mCallList);
- mRingtoneManagerDisabled.setDialerRingingEnabledForTesting(false);
- }
-
- public void testNullInCallTonePlayer() {
- try {
- new DialerRingtoneManager(null, mCallList);
- fail();
- } catch (NullPointerException e) {}
- }
-
- public void testNullCallList() {
- try {
- new DialerRingtoneManager(mInCallTonePlayer, null);
- fail();
- } catch (NullPointerException e) {}
- }
-
- public void testShouldPlayRingtone_M() {
- if (CompatUtils.isNCompatible()) {
- return;
- }
- assertFalse(mRingtoneManagerEnabled.shouldPlayRingtone(0, RINGTONE_URI));
- }
-
- public void testShouldPlayRingtone_N_NullUri() {
- if (!CompatUtils.isNCompatible()) {
- return;
- }
- assertFalse(mRingtoneManagerEnabled.shouldPlayRingtone(State.INCOMING, null));
- }
-
- public void testShouldPlayRingtone_N_Disabled() {
- if (!CompatUtils.isNCompatible()) {
- return;
- }
- assertFalse(mRingtoneManagerDisabled.shouldPlayRingtone(State.INCOMING, RINGTONE_URI));
- }
-
- public void testShouldPlayRingtone_N_NotIncoming() {
- if (!CompatUtils.isNCompatible()) {
- return;
- }
- assertFalse(mRingtoneManagerEnabled.shouldPlayRingtone(State.ACTIVE, RINGTONE_URI));
- }
-
- // Specific case for call waiting since that needs its own sound
- public void testShouldPlayRingtone_N_CallWaitingByState() {
- if (!CompatUtils.isNCompatible()) {
- return;
- }
- assertFalse(mRingtoneManagerEnabled.shouldPlayRingtone(State.CALL_WAITING, RINGTONE_URI));
- }
-
- public void testShouldPlayRingtone_N_CallWaitingByActiveCall() {
- if (!CompatUtils.isNCompatible()) {
- return;
- }
- Mockito.when(mCallList.getActiveCall()).thenReturn(mCall);
- assertFalse(mRingtoneManagerEnabled.shouldPlayRingtone(State.INCOMING, RINGTONE_URI));
- }
-
- public void testShouldPlayRingtone_N() {
- if (!CompatUtils.isNCompatible()) {
- return;
- }
- assertTrue(mRingtoneManagerEnabled.shouldPlayRingtone(State.INCOMING, RINGTONE_URI));
- }
-
- public void testShouldPlayCallWaitingTone_M() {
- if (CompatUtils.isNCompatible()) {
- return;
- }
- assertFalse(mRingtoneManagerEnabled.shouldPlayCallWaitingTone(0));
- }
-
- public void testShouldPlayCallWaitingTone_N_Disabled() {
- if (!CompatUtils.isNCompatible()) {
- return;
- }
- assertFalse(mRingtoneManagerDisabled.shouldPlayCallWaitingTone(State.CALL_WAITING));
- }
-
- public void testShouldPlayCallWaitingTone_N_NotCallWaiting() {
- if (!CompatUtils.isNCompatible()) {
- return;
- }
- assertFalse(mRingtoneManagerEnabled.shouldPlayCallWaitingTone(State.ACTIVE));
- }
-
- // Specific case for incoming since it plays its own sound
- public void testShouldPlayCallWaitingTone_N_Incoming() {
- if (!CompatUtils.isNCompatible()) {
- return;
- }
- assertFalse(mRingtoneManagerEnabled.shouldPlayCallWaitingTone(State.INCOMING));
- }
-
- public void testShouldPlayCallWaitingTone_N_AlreadyPlaying() {
- if (!CompatUtils.isNCompatible()) {
- return;
- }
- Mockito.when(mInCallTonePlayer.isPlayingTone()).thenReturn(true);
- assertFalse(mRingtoneManagerEnabled.shouldPlayCallWaitingTone(State.CALL_WAITING));
- }
-
- public void testShouldPlayCallWaitingTone_N_ByState() {
- if (!CompatUtils.isNCompatible()) {
- return;
- }
- assertTrue(mRingtoneManagerEnabled.shouldPlayCallWaitingTone(State.CALL_WAITING));
- }
-
- public void testShouldPlayCallWaitingTone_N_ByActiveCall() {
- if (!CompatUtils.isNCompatible()) {
- return;
- }
- Mockito.when(mCallList.getActiveCall()).thenReturn(mCall);
- assertTrue(mRingtoneManagerEnabled.shouldPlayCallWaitingTone(State.INCOMING));
- }
-
- public void testPlayCallWaitingTone_M() {
- if (CompatUtils.isNCompatible()) {
- return;
- }
- mRingtoneManagerEnabled.playCallWaitingTone();
- Mockito.verify(mInCallTonePlayer, Mockito.never()).play(Mockito.anyInt());
- }
-
- public void testPlayCallWaitingTone_N_NotEnabled() {
- if (!CompatUtils.isNCompatible()) {
- return;
- }
- mRingtoneManagerDisabled.playCallWaitingTone();
- Mockito.verify(mInCallTonePlayer, Mockito.never()).play(Mockito.anyInt());
- }
-
- public void testPlayCallWaitingTone_N() {
- if (!CompatUtils.isNCompatible()) {
- return;
- }
- mRingtoneManagerEnabled.playCallWaitingTone();
- Mockito.verify(mInCallTonePlayer).play(Mockito.anyInt());
- }
-
- public void testStopCallWaitingTone_M() {
- if (CompatUtils.isNCompatible()) {
- return;
- }
- mRingtoneManagerEnabled.stopCallWaitingTone();
- Mockito.verify(mInCallTonePlayer, Mockito.never()).stop();
- }
-
- public void testStopCallWaitingTone_N_NotEnabled() {
- if (!CompatUtils.isNCompatible()) {
- return;
- }
- mRingtoneManagerDisabled.stopCallWaitingTone();
- Mockito.verify(mInCallTonePlayer, Mockito.never()).stop();
- }
-
- public void testStopCallWaitingTone_N() {
- if (!CompatUtils.isNCompatible()) {
- return;
- }
- mRingtoneManagerEnabled.stopCallWaitingTone();
- Mockito.verify(mInCallTonePlayer).stop();
- }
-}
diff --git a/InCallUI/tests/src/com/android/incallui/ringtone/InCallTonePlayerTest.java b/InCallUI/tests/src/com/android/incallui/ringtone/InCallTonePlayerTest.java
deleted file mode 100644
index bde5c50e4..000000000
--- a/InCallUI/tests/src/com/android/incallui/ringtone/InCallTonePlayerTest.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (C) 2016 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.incallui.ringtone;
-
-import android.media.AudioManager;
-import android.media.ToneGenerator;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-
-import com.android.incallui.async.PausableExecutor;
-import com.android.incallui.async.SingleProdThreadExecutor;
-
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-
-@SmallTest
-public class InCallTonePlayerTest extends AndroidTestCase {
-
- @Mock private ToneGeneratorFactory mToneGeneratorFactory;
- @Mock private ToneGenerator mToneGenerator;
- private InCallTonePlayer mInCallTonePlayer;
-
- /*
- * InCallTonePlayer milestones:
- * 1) After tone starts playing
- * 2) After tone finishes waiting (could have timed out)
- * 3) After cleaning up state to allow new tone to play
- */
- private PausableExecutor mExecutor;
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- MockitoAnnotations.initMocks(this);
- Mockito.when(mToneGeneratorFactory.newInCallToneGenerator(Mockito.anyInt(),
- Mockito.anyInt())).thenReturn(mToneGenerator);
- mExecutor = new SingleProdThreadExecutor();
- mInCallTonePlayer = new InCallTonePlayer(mToneGeneratorFactory, mExecutor);
- }
-
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- // Stop any playing so the InCallTonePlayer isn't stuck waiting for the tone to complete
- mInCallTonePlayer.stop();
- // Ack all milestones to ensure that the prod thread doesn't block forever
- mExecutor.ackAllMilestonesForTesting();
- }
-
- public void testIsPlayingTone_False() {
- assertFalse(mInCallTonePlayer.isPlayingTone());
- }
-
- public void testIsPlayingTone_True() throws InterruptedException {
- mInCallTonePlayer.play(InCallTonePlayer.TONE_CALL_WAITING);
- mExecutor.awaitMilestoneForTesting();
-
- assertTrue(mInCallTonePlayer.isPlayingTone());
- }
-
- public void testPlay_InvalidTone() {
- try {
- mInCallTonePlayer.play(Integer.MIN_VALUE);
- fail();
- } catch (IllegalArgumentException e) {}
- }
-
- public void testPlay_CurrentlyPlaying() throws InterruptedException {
- mInCallTonePlayer.play(InCallTonePlayer.TONE_CALL_WAITING);
- mExecutor.awaitMilestoneForTesting();
- try {
- mInCallTonePlayer.play(InCallTonePlayer.TONE_CALL_WAITING);
- fail();
- } catch (IllegalStateException e) {}
- }
-
- public void testPlay_VoiceCallStream() throws InterruptedException {
- mInCallTonePlayer.play(InCallTonePlayer.TONE_CALL_WAITING);
- mExecutor.awaitMilestoneForTesting();
- Mockito.verify(mToneGeneratorFactory).newInCallToneGenerator(AudioManager.STREAM_VOICE_CALL,
- InCallTonePlayer.VOLUME_RELATIVE_HIGH_PRIORITY);
- }
-
- public void testPlay_Single() throws InterruptedException {
- mInCallTonePlayer.play(InCallTonePlayer.TONE_CALL_WAITING);
- mExecutor.awaitMilestoneForTesting();
- mExecutor.ackMilestoneForTesting();
- mInCallTonePlayer.stop();
- mExecutor.ackMilestoneForTesting();
- mExecutor.awaitMilestoneForTesting();
- mExecutor.ackMilestoneForTesting();
-
- Mockito.verify(mToneGenerator).startTone(ToneGenerator.TONE_SUP_CALL_WAITING);
- }
-
- public void testPlay_Consecutive() throws InterruptedException {
- mInCallTonePlayer.play(InCallTonePlayer.TONE_CALL_WAITING);
- mExecutor.awaitMilestoneForTesting();
- mExecutor.ackMilestoneForTesting();
- // Prevent waiting forever
- mInCallTonePlayer.stop();
- mExecutor.ackMilestoneForTesting();
- mExecutor.awaitMilestoneForTesting();
- mExecutor.ackMilestoneForTesting();
-
- mInCallTonePlayer.play(InCallTonePlayer.TONE_CALL_WAITING);
- mExecutor.awaitMilestoneForTesting();
- mExecutor.ackMilestoneForTesting();
- mInCallTonePlayer.stop();
- mExecutor.ackMilestoneForTesting();
- mExecutor.awaitMilestoneForTesting();
- mExecutor.ackMilestoneForTesting();
-
- Mockito.verify(mToneGenerator, Mockito.times(2))
- .startTone(ToneGenerator.TONE_SUP_CALL_WAITING);
- }
-
- public void testStop_NotPlaying() {
- // No crash
- mInCallTonePlayer.stop();
- }
-
- public void testStop() throws InterruptedException {
- mInCallTonePlayer.play(InCallTonePlayer.TONE_CALL_WAITING);
- mExecutor.awaitMilestoneForTesting();
-
- mInCallTonePlayer.stop();
- mExecutor.ackMilestoneForTesting();
- mExecutor.awaitMilestoneForTesting();
-
- assertFalse(mInCallTonePlayer.isPlayingTone());
- }
-}
diff --git a/InCallUI/tests/src/com/android/incallui/spam/SpamCallListListenerTest.java b/InCallUI/tests/src/com/android/incallui/spam/SpamCallListListenerTest.java
deleted file mode 100644
index fb0b460b6..000000000
--- a/InCallUI/tests/src/com/android/incallui/spam/SpamCallListListenerTest.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright (C) 2016 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.incallui.spam;
-
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Mockito.doCallRealMethod;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.eq;
-import static org.mockito.Mockito.any;
-
-import android.content.ContentValues;
-import android.content.Context;
-import android.provider.CallLog;
-import android.telecom.DisconnectCause;
-import android.test.InstrumentationTestCase;
-
-import com.android.contacts.common.test.mocks.ContactsMockContext;
-import com.android.contacts.common.test.mocks.MockContentProvider;
-import com.android.dialer.calllog.CallLogAsyncTaskUtil;
-import com.android.dialer.util.AsyncTaskExecutors;
-import com.android.dialer.util.FakeAsyncTaskExecutor;
-import com.android.dialer.util.TelecomUtil;
-import com.android.incallui.Call;
-import com.android.incallui.Call.CallHistoryStatus;
-import com.android.incallui.Call.LogState;
-
-public class SpamCallListListenerTest extends InstrumentationTestCase {
- private static final String NUMBER = "+18005657862";
- private static final int DURATION = 100;
-
- private TestSpamCallListListener mListener;
- private FakeAsyncTaskExecutor mFakeAsyncTaskExecutor;
- private ContactsMockContext mContext;
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- mContext = new ContactsMockContext(getInstrumentation().getContext(), CallLog.AUTHORITY);
- mListener = new TestSpamCallListListener(mContext);
- mFakeAsyncTaskExecutor = new FakeAsyncTaskExecutor(getInstrumentation());
- AsyncTaskExecutors.setFactoryForTest(mFakeAsyncTaskExecutor.getFactory());
- }
-
- @Override
- public void tearDown() throws Exception {
- AsyncTaskExecutors.setFactoryForTest(null);
- CallLogAsyncTaskUtil.resetForTest();
- super.tearDown();
- }
-
- public void testOutgoingCall() {
- Call call = getMockCall(NUMBER, false, 0, Call.CALL_HISTORY_STATUS_NOT_PRESENT,
- LogState.LOOKUP_UNKNOWN, DisconnectCause.REMOTE);
- mListener.onDisconnect(call);
- assertFalse(mListener.mShowNotificationCalled);
- }
-
- public void testIncomingCall_UnknownNumber() {
- Call call = getMockCall(null, true, DURATION, Call.CALL_HISTORY_STATUS_NOT_PRESENT,
- LogState.LOOKUP_UNKNOWN, DisconnectCause.REMOTE);
- mListener.onDisconnect(call);
- assertFalse(mListener.mShowNotificationCalled);
- }
-
- public void testIncomingCall_Rejected() {
- Call call = getMockCall(NUMBER, true, 0, Call.CALL_HISTORY_STATUS_NOT_PRESENT,
- LogState.LOOKUP_UNKNOWN, DisconnectCause.REJECTED);
- mListener.onDisconnect(call);
- assertFalse(mListener.mShowNotificationCalled);
- }
- public void testIncomingCall_HangUpLocal() {
- Call call = getMockCall(NUMBER, true, DURATION, Call.CALL_HISTORY_STATUS_NOT_PRESENT,
- LogState.LOOKUP_UNKNOWN, DisconnectCause.LOCAL);
- mListener.onDisconnect(call);
- assertTrue(mListener.mShowNotificationCalled);
- }
-
- public void testIncomingCall_HangUpRemote() {
- Call call = getMockCall(NUMBER, true, DURATION, Call.CALL_HISTORY_STATUS_NOT_PRESENT,
- LogState.LOOKUP_UNKNOWN, DisconnectCause.REMOTE);
- mListener.onDisconnect(call);
- assertTrue(mListener.mShowNotificationCalled);
- }
-
- public void testIncomingCall_ValidNumber_NotInCallHistory_InContacts() {
- Call call = getMockCall(NUMBER, true, 0, Call.CALL_HISTORY_STATUS_NOT_PRESENT,
- LogState.LOOKUP_LOCAL_CONTACT, DisconnectCause.REJECTED);
- mListener.onDisconnect(call);
- assertFalse(mListener.mShowNotificationCalled);
- }
-
- public void testIncomingCall_ValidNumber_InCallHistory_InContacts() {
- Call call = getMockCall(NUMBER, true, 0, Call.CALL_HISTORY_STATUS_PRESENT,
- LogState.LOOKUP_LOCAL_CONTACT, DisconnectCause.REJECTED);
- mListener.onDisconnect(call);
- assertFalse(mListener.mShowNotificationCalled);
- }
-
- public void testIncomingCall_ValidNumber_InCallHistory_NotInContacts() {
- Call call = getMockCall(NUMBER, true, 0, Call.CALL_HISTORY_STATUS_PRESENT,
- LogState.LOOKUP_UNKNOWN, DisconnectCause.REJECTED);
- mListener.onDisconnect(call);
- assertFalse(mListener.mShowNotificationCalled);
- }
-
- public void testIncomingCall_ValidNumber_NotInCallHistory_NotInContacts() throws Throwable {
- Call call = getMockCall(NUMBER, true, DURATION, Call.CALL_HISTORY_STATUS_NOT_PRESENT,
- LogState.LOOKUP_UNKNOWN, DisconnectCause.LOCAL);
- mListener.onDisconnect(call);
- assertTrue(mListener.mShowNotificationCalled);
- }
-
- public void testIncomingCall_CheckCallHistory_NumberExists() throws Throwable {
- final Call call = getMockCall(NUMBER, true, DURATION, Call.CALL_HISTORY_STATUS_UNKNOWN,
- LogState.LOOKUP_UNKNOWN, DisconnectCause.LOCAL);
- expectCallLogQuery(NUMBER, true);
- incomingCall(call);
- verify(call).setCallHistoryStatus(eq(Call.CALL_HISTORY_STATUS_PRESENT));
- assertFalse(mListener.mShowNotificationCalled);
- }
-
- public void testIncomingCall_CheckCallHistory_NumberNotExists() throws Throwable {
- final Call call = getMockCall(NUMBER, true, DURATION, Call.CALL_HISTORY_STATUS_UNKNOWN,
- LogState.LOOKUP_UNKNOWN, DisconnectCause.LOCAL);
- expectCallLogQuery(NUMBER, false);
- incomingCall(call);
- verify(call).setCallHistoryStatus(eq(Call.CALL_HISTORY_STATUS_NOT_PRESENT));
- assertTrue(mListener.mShowNotificationCalled);
- }
-
- private void incomingCall(final Call call) throws Throwable {
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- mListener.onIncomingCall(call);
- }
- });
- getInstrumentation().waitForIdleSync();
- mFakeAsyncTaskExecutor.runTask(CallLogAsyncTaskUtil.Tasks.GET_NUMBER_IN_CALL_HISTORY);
- mListener.onDisconnect(call);
- }
-
- private void expectCallLogQuery(String number, boolean inCallHistory) {
- MockContentProvider.Query query = mContext.getContactsProvider()
- .expectQuery(TelecomUtil.getCallLogUri(mContext))
- .withSelection(CallLog.Calls.NUMBER + " = ?", number)
- .withProjection(CallLog.Calls._ID)
- .withAnySortOrder();
- ContentValues values = new ContentValues();
- values.put(CallLog.Calls.NUMBER, number);
- if (inCallHistory) {
- query.returnRow(values);
- } else {
- query.returnEmptyCursor();
- }
- }
-
- private static Call getMockCall(String number,
- boolean isIncoming,
- int duration,
- @CallHistoryStatus int callHistoryStatus,
- int contactLookupResult,
- int disconnectCause) {
- Call call = mock(Call.class);
- LogState logState = new LogState();
- logState.isIncoming = isIncoming;
- logState.duration = duration;
- logState.contactLookupResult = contactLookupResult;
- when(call.getDisconnectCause()).thenReturn(new DisconnectCause(disconnectCause));
- when(call.getLogState()).thenReturn(logState);
- when(call.getNumber()).thenReturn(number);
- doCallRealMethod().when(call).setCallHistoryStatus(anyInt());
- when(call.getCallHistoryStatus()).thenCallRealMethod();
- call.setCallHistoryStatus(callHistoryStatus);
- return call;
- }
-
- private static class TestSpamCallListListener extends SpamCallListListener {
- private boolean mShowNotificationCalled;
-
- public TestSpamCallListListener(Context context) {
- super(context);
- }
-
- void showNotification(String number) {
- mShowNotificationCalled = true;
- }
- }
-} \ No newline at end of file