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

Commit 7a736e67 authored by Sandeep Samdaria's avatar Sandeep Samdaria Committed by Gerrit Code Review
Browse files

Merge "Handle NPE in HFPClientConnectionService"

parents 8d4daea0 d0575ab8
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -325,6 +325,9 @@ public class HfpClientConnectionService extends ConnectionService {
    private BluetoothDevice getDevice(PhoneAccountHandle handle) {
        BluetoothAdapter adapter = getSystemService(BluetoothManager.class).getAdapter();
        PhoneAccount account = mTelecomManager.getPhoneAccount(handle);
        if (account == null) {
            return null;
        }
        String btAddr = account.getAddress().getSchemeSpecificPart();
        return adapter.getRemoteDevice(btAddr);
    }
+80 −0
Original line number Diff line number Diff line
@@ -282,4 +282,84 @@ public class HfpClientConnectionServiceTest {
        assertThat(((HfpClientConnection) connection).getDevice()).isEqualTo(TEST_DEVICE);
        assertThat(((HfpClientConnection) connection).getUUID()).isEqualTo(call.getUUID());
    }

    @Test
    public void onCreateIncomingConnection_phoneAccountIsNull_returnsNull() throws Exception{
        doReturn(null).when(mMockTelecomManager).getPhoneAccount(any());
        createService();
        setupDeviceConnection(TEST_DEVICE);

        HfpClientCall call = new HfpClientCall(TEST_DEVICE, /* id= */0,
                HfpClientCall.CALL_STATE_ACTIVE, /* number= */ TEST_NUMBER,
                /* multiParty= */ false, /* outgoing= */false, /* inBandRing= */true);

        Bundle extras = new Bundle();
        extras.putParcelable(TelecomManager.EXTRA_INCOMING_CALL_EXTRAS,
                new ParcelUuid(call.getUUID()));
        ConnectionRequest connectionRequest = new ConnectionRequest.Builder().setExtras(
                extras).build();

        HfpClientConnectionService.onCallChanged(TEST_DEVICE, call);

        Connection connection = mHfpClientConnectionService.onCreateIncomingConnection(
                getPhoneAccountHandle(TEST_DEVICE),
                connectionRequest);

        assertThat(connection).isNull();
    }


    @Test
    public void onCreateOutgoingConnection_phoneAccountIsNull_returnsNull() throws Exception{
        doReturn(null).when(mMockTelecomManager).getPhoneAccount(any());
        createService();
        setupDeviceConnection(TEST_DEVICE);

        HfpClientCall call = new HfpClientCall(TEST_DEVICE, /* id= */0,
                HfpClientCall.CALL_STATE_ACTIVE, /* number= */ TEST_NUMBER,
                /* multiParty= */ false, /* outgoing= */true, /* inBandRing= */true);

        doReturn(call).when(mMockHeadsetClientService).dial(TEST_DEVICE, TEST_NUMBER);

        Bundle extras = new Bundle();
        extras.putParcelable(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS,
                new ParcelUuid(call.getUUID()));
        ConnectionRequest connectionRequest = new ConnectionRequest.Builder().setExtras(
                extras).setAddress(Uri.fromParts(
                PhoneAccount.SCHEME_TEL, TEST_NUMBER, null)).build();

        Connection connection = mHfpClientConnectionService.onCreateOutgoingConnection(
                getPhoneAccountHandle(TEST_DEVICE),
                connectionRequest);

        assertThat(connection).isNull();
    }


    @Test
    public void onCreateUnknownConnection_phoneAccountIsNull_returnsNull() throws Exception{
        doReturn(null).when(mMockTelecomManager).getPhoneAccount(any());
        createService();
        setupDeviceConnection(TEST_DEVICE);

        HfpClientCall call = new HfpClientCall(TEST_DEVICE, /* id= */0,
                HfpClientCall.CALL_STATE_ACTIVE, /* number= */ TEST_NUMBER,
                /* multiParty= */ false, /* outgoing= */true, /* inBandRing= */true);

        Bundle extras = new Bundle();
        extras.putParcelable(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS,
                new ParcelUuid(call.getUUID()));
        ConnectionRequest connectionRequest = new ConnectionRequest.Builder().setExtras(
                extras).setAddress(Uri.fromParts(
                PhoneAccount.SCHEME_TEL, TEST_NUMBER, null)).build();

        HfpClientConnectionService.onCallChanged(TEST_DEVICE, call);

        Connection connection = mHfpClientConnectionService.onCreateUnknownConnection(
                getPhoneAccountHandle(TEST_DEVICE),
                connectionRequest);

        assertThat(connection).isNull();
    }

}