diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java index 6919afae1..661cf2525 100644 --- a/src/com/android/server/telecom/CallsManager.java +++ b/src/com/android/server/telecom/CallsManager.java @@ -224,6 +224,7 @@ public class CallsManager extends Call.ListenerBase implements VideoProviderProx new ConnectionServiceRepository(mPhoneAccountRegistrar, mContext, mLock, this); mInCallWakeLockController = inCallWakeLockControllerFactory.create(context, this); + mListeners.add(mInCallWakeLockController); mListeners.add(statusBarNotifier); mListeners.add(mCallLogManager); mListeners.add(mPhoneStateBroadcaster); diff --git a/src/com/android/server/telecom/InCallWakeLockController.java b/src/com/android/server/telecom/InCallWakeLockController.java index a6c63c342..8abacd971 100644 --- a/src/com/android/server/telecom/InCallWakeLockController.java +++ b/src/com/android/server/telecom/InCallWakeLockController.java @@ -41,8 +41,6 @@ public class InCallWakeLockController extends CallsManagerListenerBase { PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); mFullWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG); mFullWakeLock.setReferenceCounted(false); - - callsManager.addListener(this); } @Override diff --git a/src/com/android/server/telecom/TelecomSystem.java b/src/com/android/server/telecom/TelecomSystem.java index e7acf5240..8e017d6a4 100644 --- a/src/com/android/server/telecom/TelecomSystem.java +++ b/src/com/android/server/telecom/TelecomSystem.java @@ -128,7 +128,6 @@ public final class TelecomSystem { BluetoothManager bluetoothManager = new BluetoothManager(mContext); WiredHeadsetManager wiredHeadsetManager = new WiredHeadsetManager(mContext); - mCallsManager = new CallsManager( mContext, mLock, diff --git a/tests/Android.mk b/tests/Android.mk index a802768cd..317bfe31e 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -39,6 +39,9 @@ LOCAL_AAPT_FLAGS := \ --auto-add-overlay \ --extra-packages com.android.server.telecom +LOCAL_JACK_ENABLED := disabled +LOCAL_PROGUARD_ENABLED := disabled + LOCAL_PACKAGE_NAME := TelecomUnitTests LOCAL_CERTIFICATE := platform diff --git a/tests/src/com/android/server/telecom/tests/MockitoHelper.java b/tests/src/com/android/server/telecom/tests/MockitoHelper.java index 5193bbab0..3425b0e5a 100644 --- a/tests/src/com/android/server/telecom/tests/MockitoHelper.java +++ b/tests/src/com/android/server/telecom/tests/MockitoHelper.java @@ -18,9 +18,7 @@ package com.android.server.telecom.tests; import com.android.server.telecom.Log; -import android.annotation.TargetApi; import android.content.Context; -import android.os.Looper; /** * Helper for Mockito-based test cases. @@ -28,10 +26,6 @@ import android.os.Looper; public final class MockitoHelper { private static final String DEXCACHE = "dexmaker.dexcache"; - private Thread mRequestThread; - private ClassLoader mRequestThreadOriginalClassLoader; - private ClassLoader mMainThreadOriginalClassLoader; - /** * Creates a new helper, which in turn will set the context classloader so * it can load Mockito resources. @@ -39,24 +33,6 @@ public final class MockitoHelper { * @param packageClass test case class */ public void setUp(Context context, Class packageClass) throws Exception { - // makes a copy of the context classloader - mRequestThread = Thread.currentThread(); - mRequestThreadOriginalClassLoader = mRequestThread.getContextClassLoader(); - mMainThreadOriginalClassLoader = Looper.getMainLooper().getThread().getContextClassLoader(); - - ClassLoader newClassLoader = packageClass.getClassLoader(); - - Log.v(this, "Changing context classloader for thread %s from %s to %s", - mRequestThread.getName(), - mRequestThreadOriginalClassLoader, - newClassLoader); - mRequestThread.setContextClassLoader(newClassLoader); - - Log.v(this, "Changing context classloader for MAIN thread from %s to %s", - mMainThreadOriginalClassLoader, - newClassLoader); - Looper.getMainLooper().getThread().setContextClassLoader(newClassLoader); - String dexCache = context.getCacheDir().toString(); Log.v(this, "Setting property %s to %s", DEXCACHE, dexCache); System.setProperty(DEXCACHE, dexCache); @@ -67,7 +43,6 @@ public final class MockitoHelper { */ public void tearDown() throws Exception { Log.v(this, "Restoring context classloaders"); - mRequestThread.setContextClassLoader(mRequestThreadOriginalClassLoader); Log.v(this, "Clearing property %s", DEXCACHE); System.clearProperty(DEXCACHE); } diff --git a/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java b/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java index f3f4e5b42..881064531 100644 --- a/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java +++ b/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java @@ -26,9 +26,9 @@ import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import android.content.BroadcastReceiver; import android.content.ComponentName; @@ -56,7 +56,10 @@ import com.android.internal.telecom.IInCallAdapter; import com.android.server.telecom.BluetoothPhoneServiceImpl; import com.android.server.telecom.CallAudioManager; import com.android.server.telecom.CallIntentProcessor; +import com.android.server.telecom.CallerInfoAsyncQueryFactory; import com.android.server.telecom.CallsManager; +import com.android.server.telecom.CallsManagerListenerBase; +import com.android.server.telecom.ContactsAsyncHelper; import com.android.server.telecom.HeadsetMediaButton; import com.android.server.telecom.HeadsetMediaButtonFactory; import com.android.server.telecom.InCallWakeLockController; @@ -85,7 +88,49 @@ public class TelecomSystemTest extends TelecomTestCase { static final int TEST_POLL_INTERVAL = 10; // milliseconds static final int TEST_TIMEOUT = 1000; // milliseconds - @Mock MissedCallNotifier mMissedCallNotifier; + public class HeadsetMediaButtonFactoryF implements HeadsetMediaButtonFactory { + @Override + public HeadsetMediaButton create(Context context, CallsManager callsManager, + TelecomSystem.SyncRoot lock) { + return mHeadsetMediaButton; + } + } + + public class ProximitySensorManagerFactoryF implements ProximitySensorManagerFactory { + @Override + public ProximitySensorManager create(Context context, CallsManager callsManager) { + return mProximitySensorManager; + } + } + + public class InCallWakeLockControllerFactoryF implements InCallWakeLockControllerFactory { + @Override + public InCallWakeLockController create(Context context, CallsManager callsManager) { + return mInCallWakeLockController; + } + } + + public static class MissedCallNotifierFakeImpl extends CallsManagerListenerBase + implements MissedCallNotifier { + @Override + public void clearMissedCalls() { + + } + + @Override + public void showMissedCallNotification(com.android.server.telecom.Call call) { + + } + + @Override + public void updateOnStartup(TelecomSystem.SyncRoot lock, CallsManager callsManager, + ContactsAsyncHelper contactsAsyncHelper, + CallerInfoAsyncQueryFactory callerInfoAsyncQueryFactory) { + + } + } + + MissedCallNotifier mMissedCallNotifier = new MissedCallNotifierFakeImpl(); @Mock HeadsetMediaButton mHeadsetMediaButton; @Mock ProximitySensorManager mProximitySensorManager; @Mock InCallWakeLockController mInCallWakeLockController; @@ -188,30 +233,17 @@ public class TelecomSystemTest extends TelecomTestCase { } private void setupTelecomSystem() throws Exception { + // Use actual implementations instead of mocking the interface out. HeadsetMediaButtonFactory headsetMediaButtonFactory = - mock(HeadsetMediaButtonFactory.class); + spy(new HeadsetMediaButtonFactoryF()); ProximitySensorManagerFactory proximitySensorManagerFactory = - mock(ProximitySensorManagerFactory.class); + spy(new ProximitySensorManagerFactoryF()); InCallWakeLockControllerFactory inCallWakeLockControllerFactory = - mock(InCallWakeLockControllerFactory.class); + spy(new InCallWakeLockControllerFactoryF()); mAudioService = setupAudioService(); mCallerInfoAsyncQueryFactoryFixture = new CallerInfoAsyncQueryFactoryFixture(); - when(headsetMediaButtonFactory.create( - any(Context.class), - any(CallsManager.class), - any(TelecomSystem.SyncRoot.class))) - .thenReturn(mHeadsetMediaButton); - when(proximitySensorManagerFactory.create( - any(Context.class), - any(CallsManager.class))) - .thenReturn(mProximitySensorManager); - when(inCallWakeLockControllerFactory.create( - any(Context.class), - any(CallsManager.class))) - .thenReturn(mInCallWakeLockController); - mTelecomSystem = new TelecomSystem( mComponentContextFixture.getTestDouble(), mMissedCallNotifier, @@ -296,6 +328,7 @@ public class TelecomSystemTest extends TelecomTestCase { */ private IAudioService setupAudioService() { IAudioService audioService = mock(IAudioService.class); + final AudioManager fakeAudioManager = (AudioManager) mComponentContextFixture.getTestDouble() .getApplicationContext().getSystemService(Context.AUDIO_SERVICE);