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

Commit b232dc00 authored by Junho's avatar Junho
Browse files

Reconnect InCallService of CarModeUI or NonUI when it crashes.

We auto-reconnect to the default / system dialer app when it crashes but we do not handle that for CarModeUI or NonUI InCallService. Therefore we add the handling of reconnect for CarModeUI or NonUI like that for default / system dialer

Bug: 235225072
Test: atest InCallControllerTest#testBindToService_CarModeUI_Crash
Change-Id: I550e8b242448d206a0ab8d227c9c4cd78b2ef5a7
parent 896da1b6
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -405,11 +405,25 @@ public class InCallController extends CallsManagerListenerBase implements
        }

        protected void onDisconnected() {
            boolean shouldReconnect = mIsConnected;
            InCallController.this.onDisconnected(mInCallServiceInfo);
            disconnect();  // Unbind explicitly if we get disconnected.
            if (mListener != null) {
                mListener.onDisconnect(InCallServiceBindingConnection.this, mCall);
            }
            // Check if we are expected to reconnect
            if (shouldReconnect && shouldHandleReconnect()) {
                connect(mCall);  // reconnect
            }
        }

        private boolean shouldHandleReconnect() {
            int serviceType = mInCallServiceInfo.getType();
            boolean nonUI = (serviceType == IN_CALL_SERVICE_TYPE_NON_UI)
                    || (serviceType == IN_CALL_SERVICE_TYPE_COMPANION);
            boolean carModeUI = (serviceType == IN_CALL_SERVICE_TYPE_CAR_MODE_UI);

            return carModeUI || (nonUI && !mIsNullBinding);
        }
    }

+40 −0
Original line number Diff line number Diff line
@@ -755,6 +755,46 @@ public class InCallControllerTests extends TelecomTestCase {
        assertEquals(sysDialerComponentName, bindIntentCaptor2.getValue().getComponent());
    }

    @Test
    public void testBindToService_CarModeUI_Crash() throws Exception {
        setupMocks(false /* isExternalCall */);
        setupMockPackageManager(true /* default */, true /* system */, true /* external calls */);

        // Enable car mode
        when(mMockSystemStateHelper.isCarModeOrProjectionActive()).thenReturn(true);
        mInCallController.handleCarModeChange(UiModeManager.DEFAULT_PRIORITY, CAR_PKG, true);

        // Now bind; we should only bind to one app.
        mInCallController.bindToServices(mMockCall);

        // Bind InCallServices
        ArgumentCaptor<Intent> bindIntentCaptor = ArgumentCaptor.forClass(Intent.class);
        ArgumentCaptor<ServiceConnection> serviceConnectionCaptor =
                ArgumentCaptor.forClass(ServiceConnection.class);
        verify(mMockContext, times(1)).bindServiceAsUser(
                bindIntentCaptor.capture(),
                serviceConnectionCaptor.capture(),
                eq(serviceBindingFlags),
                eq(UserHandle.CURRENT));

        // Verify bind car mode ui
        assertEquals(1, bindIntentCaptor.getAllValues().size());
        verifyBinding(bindIntentCaptor, 0, CAR_PKG, CAR_CLASS);

        // Emulate a crash in the CarModeUI
        ServiceConnection serviceConnection = serviceConnectionCaptor.getValue();
        serviceConnection.onServiceDisconnected(bindIntentCaptor.getValue().getComponent());

        ArgumentCaptor<Intent> bindIntentCaptor2 = ArgumentCaptor.forClass(Intent.class);
        verify(mMockContext, times(2)).bindServiceAsUser(
                bindIntentCaptor2.capture(),
                any(ServiceConnection.class),
                eq(serviceBindingFlags),
                eq(UserHandle.CURRENT));

        verifyBinding(bindIntentCaptor2, 1, CAR_PKG, CAR_CLASS);
    }

    /**
     * Ensures that the {@link InCallController} will bind to an {@link InCallService} which
     * supports external calls.