Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0bee0ffb authored by Brad Ebinger's avatar Brad Ebinger
Browse files

Cache setDefaultDialer value to fix CTS failures

When CTS tests call setDefaultDialer, they expect the changes to be made
synchronously, because they require these permissions later in the test.
The new DefaultDialerCache didn't update the cache synchronously, instead
it would update the cache when the ContentProvider updated, after a short
delay. This caused CTS tests to be flaky or fail.

I also fixed some of the Telecom Unit Test failures that were occuring.

Test: Run CTS tests.
Bug: 34094508
Change-Id: I6324c84a15c4087ff8acccaf8aae93ea586823d3
parent b29a6fd3
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -175,9 +175,15 @@ public class DefaultDialerCache {
    }

    public boolean setDefaultDialer(String packageName, int userId) {
        // No need to update cache -- this'll trigger the content observer.
        return mDefaultDialerManagerAdapter.setDefaultDialerApplication(
        boolean isChanged = mDefaultDialerManagerAdapter.setDefaultDialerApplication(
                mContext, packageName, userId);
        if(isChanged) {
            synchronized (mLock) {
                // Update the cache synchronously so that there is no delay in cache update.
                mCurrentDefaultDialerPerUser.put(userId, packageName);
            }
        }
        return isChanged;
    }

    private String refreshCacheForUser(int userId) {
+21 −21
Original line number Diff line number Diff line
@@ -246,7 +246,7 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {
        mBluetoothPhoneService.mBinder.listCurrentCalls();

        verify(mMockBluetoothHeadset).clccResponse(eq(1), eq(0), eq(0), eq(0), eq(false),
                eq("555-000"), eq(PhoneNumberUtils.TOA_Unknown));
                eq("555000"), eq(PhoneNumberUtils.TOA_Unknown));
        verify(mMockBluetoothHeadset).clccResponse(0, 0, 0, 0, false, null, 0);
    }

@@ -335,9 +335,9 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {
        mBluetoothPhoneService.mBinder.listCurrentCalls();

        verify(mMockBluetoothHeadset).clccResponse(eq(1), eq(0), eq(CALL_STATE_ACTIVE), eq(0),
                eq(false), eq("555-0000"), eq(PhoneNumberUtils.TOA_Unknown));
                eq(false), eq("5550000"), eq(PhoneNumberUtils.TOA_Unknown));
        verify(mMockBluetoothHeadset).clccResponse(eq(2), eq(1), eq(CALL_STATE_HELD), eq(0),
                eq(false), eq("555-0001"), eq(PhoneNumberUtils.TOA_Unknown));
                eq(false), eq("5550001"), eq(PhoneNumberUtils.TOA_Unknown));
        verify(mMockBluetoothHeadset).clccResponse(0, 0, 0, 0, false, null, 0);
    }

@@ -376,9 +376,9 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {
        mBluetoothPhoneService.mBinder.listCurrentCalls();

        verify(mMockBluetoothHeadset).clccResponse(eq(1), eq(0), eq(CALL_STATE_ACTIVE), eq(0),
                eq(true), eq("555-0000"), eq(PhoneNumberUtils.TOA_Unknown));
                eq(true), eq("5550000"), eq(PhoneNumberUtils.TOA_Unknown));
        verify(mMockBluetoothHeadset).clccResponse(eq(2), eq(1), eq(CALL_STATE_ACTIVE), eq(0),
                eq(true), eq("555-0001"), eq(PhoneNumberUtils.TOA_Unknown));
                eq(true), eq("5550001"), eq(PhoneNumberUtils.TOA_Unknown));
        verify(mMockBluetoothHeadset).clccResponse(0, 0, 0, 0, false, null, 0);
    }

@@ -398,7 +398,7 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {

        mBluetoothPhoneService.mBinder.listCurrentCalls();
        verify(mMockBluetoothHeadset).clccResponse(1, 1, CALL_STATE_WAITING, 0, false,
                "555-0000", PhoneNumberUtils.TOA_Unknown);
                "5550000", PhoneNumberUtils.TOA_Unknown);
        verify(mMockBluetoothHeadset).clccResponse(0, 0, 0, 0, false, null, 0);
        verify(mMockBluetoothHeadset, times(2)).clccResponse(anyInt(),
                anyInt(), anyInt(), anyInt(), anyBoolean(), anyString(), anyInt());
@@ -433,7 +433,7 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {

        mBluetoothPhoneService.mBinder.listCurrentCalls();
        verify(mMockBluetoothHeadset).clccResponse(1, 1, CALL_STATE_INCOMING, 0, false,
                "555-0000", PhoneNumberUtils.TOA_Unknown);
                "5550000", PhoneNumberUtils.TOA_Unknown);
        verify(mMockBluetoothHeadset).clccResponse(0, 0, 0, 0, false, null, 0);
        verify(mMockBluetoothHeadset, times(2)).clccResponse(anyInt(),
                anyInt(), anyInt(), anyInt(), anyBoolean(), anyString(), anyInt());
@@ -449,11 +449,11 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {
        when(ringingCall.isIncoming()).thenReturn(true);
        when(ringingCall.isConference()).thenReturn(false);
        when(ringingCall.getGatewayInfo()).thenReturn(new GatewayInfo(null, null,
                Uri.parse("tel:555-0000")));
                Uri.parse("tel:5550000")));

        mBluetoothPhoneService.mBinder.listCurrentCalls();
        verify(mMockBluetoothHeadset).clccResponse(1, 1, CALL_STATE_INCOMING, 0, false,
                "555-0000", PhoneNumberUtils.TOA_Unknown);
                "5550000", PhoneNumberUtils.TOA_Unknown);

        // Test Caching of old call indicies in clcc
        when(ringingCall.getState()).thenReturn(CallState.ACTIVE);
@@ -467,9 +467,9 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {

        mBluetoothPhoneService.mBinder.listCurrentCalls();
        verify(mMockBluetoothHeadset).clccResponse(1, 1, CALL_STATE_ACTIVE, 0, false,
                "555-0000", PhoneNumberUtils.TOA_Unknown);
                "5550000", PhoneNumberUtils.TOA_Unknown);
        verify(mMockBluetoothHeadset).clccResponse(2, 1, CALL_STATE_HELD, 0, false,
                "555-0001", PhoneNumberUtils.TOA_Unknown);
                "5550001", PhoneNumberUtils.TOA_Unknown);
        verify(mMockBluetoothHeadset, times(2)).clccResponse(0, 0, 0, 0, false, null, 0);
    }

@@ -487,7 +487,7 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {

        mBluetoothPhoneService.mBinder.listCurrentCalls();
        verify(mMockBluetoothHeadset).clccResponse(1, 0, CALL_STATE_ALERTING, 0, false,
                "555-0000", PhoneNumberUtils.TOA_Unknown);
                "5550000", PhoneNumberUtils.TOA_Unknown);
        verify(mMockBluetoothHeadset).clccResponse(0, 0, 0, 0, false, null, 0);
        verify(mMockBluetoothHeadset, times(2)).clccResponse(anyInt(),
                anyInt(), anyInt(), anyInt(), anyBoolean(), anyString(), anyInt());
@@ -514,9 +514,9 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {

        mBluetoothPhoneService.mBinder.listCurrentCalls();
        verify(mMockBluetoothHeadset).clccResponse(1, 0, CALL_STATE_ALERTING, 0, false,
                "555-0000", PhoneNumberUtils.TOA_Unknown);
                "5550000", PhoneNumberUtils.TOA_Unknown);
        verify(mMockBluetoothHeadset).clccResponse(2, 1, CALL_STATE_HELD, 0, false,
                "555-0001", PhoneNumberUtils.TOA_Unknown);
                "5550001", PhoneNumberUtils.TOA_Unknown);
        verify(mMockBluetoothHeadset).clccResponse(0, 0, 0, 0, false, null, 0);
        verify(mMockBluetoothHeadset, times(3)).clccResponse(anyInt(),
                anyInt(), anyInt(), anyInt(), anyBoolean(), anyString(), anyInt());
@@ -543,12 +543,12 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {
    @MediumTest
    public void testQueryPhoneState() throws Exception {
        Call ringingCall = createRingingCall();
        when(ringingCall.getHandle()).thenReturn(Uri.parse("tel:555-0000"));
        when(ringingCall.getHandle()).thenReturn(Uri.parse("tel:5550000"));

        mBluetoothPhoneService.mBinder.queryPhoneState();

        verify(mMockBluetoothHeadset).phoneStateChanged(eq(0), eq(0), eq(CALL_STATE_INCOMING),
                eq("555-0000"), eq(PhoneNumberUtils.TOA_Unknown));
                eq("5550000"), eq(PhoneNumberUtils.TOA_Unknown));
    }

    @MediumTest
@@ -705,12 +705,12 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {
    @MediumTest
    public void testOnCallAddedRinging() throws Exception {
        Call ringingCall = createRingingCall();
        when(ringingCall.getHandle()).thenReturn(Uri.parse("tel:555-000"));
        when(ringingCall.getHandle()).thenReturn(Uri.parse("tel:555000"));

        mBluetoothPhoneService.mCallsManagerListener.onCallAdded(ringingCall);

        verify(mMockBluetoothHeadset).phoneStateChanged(eq(0), eq(0), eq(CALL_STATE_INCOMING),
                eq("555-000"), eq(PhoneNumberUtils.TOA_Unknown));
                eq("555000"), eq(PhoneNumberUtils.TOA_Unknown));

    }

@@ -814,7 +814,7 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {
                CallState.ACTIVE, CallState.ON_HOLD);

        verify(mMockBluetoothHeadset, never()).phoneStateChanged(eq(0), eq(2), eq(CALL_STATE_HELD),
                eq("555-0000"), eq(PhoneNumberUtils.TOA_Unknown));
                eq("5550000"), eq(PhoneNumberUtils.TOA_Unknown));
    }

    @MediumTest
@@ -856,14 +856,14 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {
    @MediumTest
    public void testBluetoothAdapterReceiver() throws Exception {
        Call ringingCall = createRingingCall();
        when(ringingCall.getHandle()).thenReturn(Uri.parse("tel:555-0000"));
        when(ringingCall.getHandle()).thenReturn(Uri.parse("tel:5550000"));

        Intent intent = new Intent();
        intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_ON);
        mBluetoothPhoneService.mBluetoothAdapterReceiver.onReceive(mContext, intent);

        verify(mMockBluetoothHeadset).phoneStateChanged(eq(0), eq(0), eq(CALL_STATE_INCOMING),
                eq("555-0000"), eq(PhoneNumberUtils.TOA_Unknown));
                eq("5550000"), eq(PhoneNumberUtils.TOA_Unknown));
    }

    private void addCallCapability(Call call, int capability) {
+2 −0
Original line number Diff line number Diff line
@@ -235,6 +235,8 @@ public class CallAudioRouteStateMachineTest
        CallAudioState expectedMiddleState = new CallAudioState(false,
                CallAudioState.ROUTE_WIRED_HEADSET,
                CallAudioState.ROUTE_WIRED_HEADSET | CallAudioState.ROUTE_SPEAKER);
        waitForHandlerAction(stateMachine.getHandler(), TEST_TIMEOUT);
        waitForHandlerAction(stateMachine.getHandler(), TEST_TIMEOUT);
        verifyNewSystemCallAudioState(initState, expectedMiddleState);
        resetMocks(true);

+3 −2
Original line number Diff line number Diff line
@@ -64,10 +64,11 @@ public class DefaultDialerCacheTest extends TelecomTestCase {
        mDefaultDialerCache = new DefaultDialerCache(
                mContext, mMockDefaultDialerManager, new TelecomSystem.SyncRoot() { });

        verify(mContext).registerReceiverAsUser(
        verify(mContext, times(2)).registerReceiverAsUser(
                receiverCaptor.capture(), eq(UserHandle.ALL), any(IntentFilter.class),
                isNull(String.class), isNull(Handler.class));
        mPackageChangeReceiver = receiverCaptor.getValue();
        // Receive the first receiver that was captured, the package change receiver.
        mPackageChangeReceiver = receiverCaptor.getAllValues().get(0);
        mDefaultDialerSettingObserver = mDefaultDialerCache.getContentObserver();

        when(mMockDefaultDialerManager.getDefaultDialerApplication(any(Context.class), eq(USER0)))