summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHall Liu <hallliu@google.com>2021-03-02 17:43:34 -0800
committerHall Liu <hallliu@google.com>2021-03-02 19:07:05 -0800
commit04263bffef30bf1ed424cf16596fe546ebd994b1 (patch)
treebb8f245ca5ecae053ef03f8b4fa44d9b300331b0 /tests
parent67f64a66c0fdc45ee26cb121219b6ca05b1e3b2f (diff)
downloadplatform_packages_services_Telecomm-04263bffef30bf1ed424cf16596fe546ebd994b1.tar.gz
platform_packages_services_Telecomm-04263bffef30bf1ed424cf16596fe546ebd994b1.tar.bz2
platform_packages_services_Telecomm-04263bffef30bf1ed424cf16596fe546ebd994b1.zip
Fix synchronization in SystemStateHelper
Properly acquire the big telecom lock before doing anything after receiving a broadcast. Bug: 181057509 Test: atest CarModeInCallServiceTest Change-Id: Ie4c2311278c7c27560c16c87d1eeed282470f9e8
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/server/telecom/tests/SystemStateHelperTest.java26
1 files changed, 14 insertions, 12 deletions
diff --git a/tests/src/com/android/server/telecom/tests/SystemStateHelperTest.java b/tests/src/com/android/server/telecom/tests/SystemStateHelperTest.java
index ad5262545..94b8463dd 100644
--- a/tests/src/com/android/server/telecom/tests/SystemStateHelperTest.java
+++ b/tests/src/com/android/server/telecom/tests/SystemStateHelperTest.java
@@ -48,6 +48,7 @@ import android.test.suitebuilder.annotation.SmallTest;
import com.android.server.telecom.SystemStateHelper;
import com.android.server.telecom.SystemStateHelper.SystemStateListener;
+import com.android.server.telecom.TelecomSystem;
import org.junit.After;
import org.junit.Before;
@@ -78,6 +79,7 @@ public class SystemStateHelperTest extends TelecomTestCase {
@Mock SensorManager mSensorManager;
@Mock Intent mIntentEnter;
@Mock Intent mIntentExit;
+ TelecomSystem.SyncRoot mLock = new TelecomSystem.SyncRoot() { };
@Override
@Before
@@ -109,7 +111,7 @@ public class SystemStateHelperTest extends TelecomTestCase {
@SmallTest
@Test
public void testListeners() throws Exception {
- SystemStateHelper systemStateHelper = new SystemStateHelper(mContext);
+ SystemStateHelper systemStateHelper = new SystemStateHelper(mContext, mLock);
assertFalse(systemStateHelper.removeListener(mSystemStateListener));
systemStateHelper.addListener(mSystemStateListener);
@@ -121,14 +123,14 @@ public class SystemStateHelperTest extends TelecomTestCase {
@Test
public void testQuerySystemForCarMode_True() {
when(mUiModeManager.getCurrentModeType()).thenReturn(Configuration.UI_MODE_TYPE_CAR);
- assertTrue(new SystemStateHelper(mContext).isCarModeOrProjectionActive());
+ assertTrue(new SystemStateHelper(mContext, mLock).isCarModeOrProjectionActive());
}
@SmallTest
@Test
public void testQuerySystemForCarMode_False() {
when(mUiModeManager.getCurrentModeType()).thenReturn(Configuration.UI_MODE_TYPE_NORMAL);
- assertFalse(new SystemStateHelper(mContext).isCarModeOrProjectionActive());
+ assertFalse(new SystemStateHelper(mContext, mLock).isCarModeOrProjectionActive());
}
@SmallTest
@@ -136,11 +138,11 @@ public class SystemStateHelperTest extends TelecomTestCase {
public void testQuerySystemForAutomotiveProjection_True() {
when(mUiModeManager.getActiveProjectionTypes())
.thenReturn(UiModeManager.PROJECTION_TYPE_AUTOMOTIVE);
- assertTrue(new SystemStateHelper(mContext).isCarModeOrProjectionActive());
+ assertTrue(new SystemStateHelper(mContext, mLock).isCarModeOrProjectionActive());
when(mUiModeManager.getActiveProjectionTypes())
.thenReturn(UiModeManager.PROJECTION_TYPE_ALL);
- assertTrue(new SystemStateHelper(mContext).isCarModeOrProjectionActive());
+ assertTrue(new SystemStateHelper(mContext, mLock).isCarModeOrProjectionActive());
}
@SmallTest
@@ -148,7 +150,7 @@ public class SystemStateHelperTest extends TelecomTestCase {
public void testQuerySystemForAutomotiveProjection_False() {
when(mUiModeManager.getActiveProjectionTypes())
.thenReturn(UiModeManager.PROJECTION_TYPE_NONE);
- assertFalse(new SystemStateHelper(mContext).isCarModeOrProjectionActive());
+ assertFalse(new SystemStateHelper(mContext, mLock).isCarModeOrProjectionActive());
}
@SmallTest
@@ -157,7 +159,7 @@ public class SystemStateHelperTest extends TelecomTestCase {
when(mUiModeManager.getCurrentModeType()).thenReturn(Configuration.UI_MODE_TYPE_CAR);
when(mUiModeManager.getActiveProjectionTypes())
.thenReturn(UiModeManager.PROJECTION_TYPE_AUTOMOTIVE);
- assertTrue(new SystemStateHelper(mContext).isCarModeOrProjectionActive());
+ assertTrue(new SystemStateHelper(mContext, mLock).isCarModeOrProjectionActive());
}
@SmallTest
@@ -166,7 +168,7 @@ public class SystemStateHelperTest extends TelecomTestCase {
when(mContext.getSystemService(UiModeManager.class))
.thenReturn(mUiModeManager) // Without this, class construction will throw NPE.
.thenReturn(null);
- assertFalse(new SystemStateHelper(mContext).isCarModeOrProjectionActive());
+ assertFalse(new SystemStateHelper(mContext, mLock).isCarModeOrProjectionActive());
}
@SmallTest
@@ -174,7 +176,7 @@ public class SystemStateHelperTest extends TelecomTestCase {
public void testPackageRemoved() {
ArgumentCaptor<BroadcastReceiver> receiver =
ArgumentCaptor.forClass(BroadcastReceiver.class);
- new SystemStateHelper(mContext).addListener(mSystemStateListener);
+ new SystemStateHelper(mContext, mLock).addListener(mSystemStateListener);
verify(mContext, atLeastOnce())
.registerReceiver(receiver.capture(), any(IntentFilter.class));
Intent packageRemovedIntent = new Intent(Intent.ACTION_PACKAGE_REMOVED);
@@ -188,7 +190,7 @@ public class SystemStateHelperTest extends TelecomTestCase {
public void testReceiverAndIntentFilter() {
ArgumentCaptor<IntentFilter> intentFilterCaptor =
ArgumentCaptor.forClass(IntentFilter.class);
- new SystemStateHelper(mContext);
+ new SystemStateHelper(mContext, mLock);
verify(mContext, times(2)).registerReceiver(
any(BroadcastReceiver.class), intentFilterCaptor.capture());
@@ -225,7 +227,7 @@ public class SystemStateHelperTest extends TelecomTestCase {
public void testOnEnterExitCarMode() {
ArgumentCaptor<BroadcastReceiver> receiver =
ArgumentCaptor.forClass(BroadcastReceiver.class);
- new SystemStateHelper(mContext).addListener(mSystemStateListener);
+ new SystemStateHelper(mContext, mLock).addListener(mSystemStateListener);
verify(mContext, atLeastOnce())
.registerReceiver(receiver.capture(), any(IntentFilter.class));
@@ -244,7 +246,7 @@ public class SystemStateHelperTest extends TelecomTestCase {
@SmallTest
@Test
public void testOnSetReleaseAutomotiveProjection() {
- SystemStateHelper systemStateHelper = new SystemStateHelper(mContext);
+ SystemStateHelper systemStateHelper = new SystemStateHelper(mContext, mLock);
// We don't care what listener is registered, that's an implementation detail, but we need
// to call methods on whatever it is.
ArgumentCaptor<UiModeManager.OnProjectionStateChangeListener> listenerCaptor =