Loading android/app/src/com/android/bluetooth/hfpclient/connserv/HfpClientConnectionService.java +3 −0 Original line number Diff line number Diff line Loading @@ -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); } Loading android/app/tests/unit/src/com/android/bluetooth/hfpclient/connserv/HfpClientConnectionServiceTest.java +80 −0 Original line number Diff line number Diff line Loading @@ -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(); } } Loading
android/app/src/com/android/bluetooth/hfpclient/connserv/HfpClientConnectionService.java +3 −0 Original line number Diff line number Diff line Loading @@ -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); } Loading
android/app/tests/unit/src/com/android/bluetooth/hfpclient/connserv/HfpClientConnectionServiceTest.java +80 −0 Original line number Diff line number Diff line Loading @@ -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(); } }