HFP: Send caller ID in +CLIP command (4/4)
* Get caller display name during incoming call
* Use BluetoothHeadset.phoneStateChanged() API to pass caller display
name
Bug: 111378831
Test: runtest bluetooth, runtest -x BluetoothPhoneServiceTest.java
Change-Id: Ibc345fa40d0c3e843f932454882e4abca8d5985d
diff --git a/src/com/android/server/telecom/BluetoothHeadsetProxy.java b/src/com/android/server/telecom/BluetoothHeadsetProxy.java
index 0f492df..a43b3cd 100644
--- a/src/com/android/server/telecom/BluetoothHeadsetProxy.java
+++ b/src/com/android/server/telecom/BluetoothHeadsetProxy.java
@@ -43,9 +43,10 @@
}
public void phoneStateChanged(int numActive, int numHeld, int callState, String number,
- int type) {
+ int type, String name) {
- mBluetoothHeadset.phoneStateChanged(numActive, numHeld, callState, number, type);
+ mBluetoothHeadset.phoneStateChanged(numActive, numHeld, callState, number, type,
+ name);
}
public List<BluetoothDevice> getConnectedDevices() {
@@ -83,4 +84,4 @@
public boolean isInbandRingingEnabled() {
return mBluetoothHeadset.isInbandRingingEnabled();
}
-}
\ No newline at end of file
+}
diff --git a/src/com/android/server/telecom/BluetoothPhoneServiceImpl.java b/src/com/android/server/telecom/BluetoothPhoneServiceImpl.java
index 2154f4c..ff358d5 100644
--- a/src/com/android/server/telecom/BluetoothPhoneServiceImpl.java
+++ b/src/com/android/server/telecom/BluetoothPhoneServiceImpl.java
@@ -706,11 +706,16 @@
String ringingAddress = null;
int ringingAddressType = 128;
+ String ringingName = null;
if (ringingCall != null && ringingCall.getHandle() != null) {
ringingAddress = ringingCall.getHandle().getSchemeSpecificPart();
if (ringingAddress != null) {
ringingAddressType = PhoneNumberUtils.toaFromString(ringingAddress);
}
+ ringingName = ringingCall.getCallerDisplayName();
+ if (TextUtils.isEmpty(ringingName)) {
+ ringingName = ringingCall.getName();
+ }
}
if (ringingAddress == null) {
ringingAddress = "";
@@ -782,18 +787,21 @@
"numHeld %s, " +
"callState %s, " +
"ringing number %s, " +
- "ringing type %s",
+ "ringing type %s, " +
+ "ringing name %s",
mNumActiveCalls,
mNumHeldCalls,
CALL_STATE_DIALING,
Log.pii(mRingingAddress),
- mRingingAddressType);
+ mRingingAddressType,
+ Log.pii(ringingName));
mBluetoothHeadset.phoneStateChanged(
mNumActiveCalls,
mNumHeldCalls,
CALL_STATE_DIALING,
mRingingAddress,
- mRingingAddressType);
+ mRingingAddressType,
+ ringingName);
}
Log.i(TAG, "updateHeadsetWithCallState " +
@@ -801,19 +809,22 @@
"numHeld %s, " +
"callState %s, " +
"ringing number %s, " +
- "ringing type %s",
+ "ringing type %s, " +
+ "ringing name %s",
mNumActiveCalls,
mNumHeldCalls,
mBluetoothCallState,
Log.pii(mRingingAddress),
- mRingingAddressType);
+ mRingingAddressType,
+ Log.pii(ringingName));
mBluetoothHeadset.phoneStateChanged(
mNumActiveCalls,
mNumHeldCalls,
mBluetoothCallState,
mRingingAddress,
- mRingingAddressType);
+ mRingingAddressType,
+ ringingName);
mHeadsetUpdatedRecently = true;
}
diff --git a/tests/src/com/android/server/telecom/tests/BluetoothPhoneServiceTest.java b/tests/src/com/android/server/telecom/tests/BluetoothPhoneServiceTest.java
index bf6154b..a960d91 100644
--- a/tests/src/com/android/server/telecom/tests/BluetoothPhoneServiceTest.java
+++ b/tests/src/com/android/server/telecom/tests/BluetoothPhoneServiceTest.java
@@ -309,17 +309,18 @@
mBluetoothPhoneService.mBinder.queryPhoneState();
verify(mMockBluetoothHeadset).phoneStateChanged(eq(1), eq(1), eq(CALL_STATE_IDLE),
- eq(""), eq(128));
+ eq(""), eq(128), nullable(String.class));
when(parentCall.wasConferencePreviouslyMerged()).thenReturn(true);
mBluetoothPhoneService.mCallsManagerListener.onIsConferencedChanged(parentCall);
verify(mMockBluetoothHeadset).phoneStateChanged(eq(1), eq(0), eq(CALL_STATE_IDLE),
- eq(""), eq(128));
+ eq(""), eq(128), nullable(String.class));
when(mMockCallsManager.getHeldCall()).thenReturn(null);
// Spurious call to onIsConferencedChanged.
mBluetoothPhoneService.mCallsManagerListener.onIsConferencedChanged(parentCall);
// Make sure the call has only occurred collectively 2 times (not on the third)
verify(mMockBluetoothHeadset, times(2)).phoneStateChanged(any(int.class),
- any(int.class), any(int.class), nullable(String.class), any(int.class));
+ any(int.class), any(int.class), nullable(String.class), any(int.class),
+ nullable(String.class));
}
@MediumTest
@@ -611,7 +612,7 @@
mBluetoothPhoneService.mBinder.queryPhoneState();
verify(mMockBluetoothHeadset).phoneStateChanged(eq(0), eq(0), eq(CALL_STATE_INCOMING),
- eq("5550000"), eq(PhoneNumberUtils.TOA_Unknown));
+ eq("5550000"), eq(PhoneNumberUtils.TOA_Unknown), nullable(String.class));
}
@MediumTest
@@ -632,7 +633,7 @@
mBluetoothPhoneService.mBinder.queryPhoneState();
verify(mMockBluetoothHeadset).phoneStateChanged(eq(1), eq(0), eq(CALL_STATE_IDLE),
- eq(""), eq(128));
+ eq(""), eq(128), nullable(String.class));
}
@MediumTest
@@ -772,7 +773,7 @@
verify(parentCall).swapConference();
verify(mMockBluetoothHeadset).phoneStateChanged(eq(1), eq(1), eq(CALL_STATE_IDLE), eq(""),
- eq(128));
+ eq(128), nullable(String.class));
assertEquals(didProcess, true);
}
@@ -786,7 +787,7 @@
mBluetoothPhoneService.mCallsManagerListener.onCallAdded(ringingCall);
verify(mMockBluetoothHeadset).phoneStateChanged(eq(0), eq(0), eq(CALL_STATE_INCOMING),
- eq("555000"), eq(PhoneNumberUtils.TOA_Unknown));
+ eq("555000"), eq(PhoneNumberUtils.TOA_Unknown), nullable(String.class));
}
@@ -808,7 +809,7 @@
mBluetoothPhoneService.mCallsManagerListener.onCallAdded(parentCall);
verify(mMockBluetoothHeadset).phoneStateChanged(eq(1), eq(1), eq(CALL_STATE_IDLE),
- eq(""), eq(128));
+ eq(""), eq(128), nullable(String.class));
}
@@ -821,7 +822,7 @@
mBluetoothPhoneService.mCallsManagerListener.onCallRemoved(activeCall);
verify(mMockBluetoothHeadset).phoneStateChanged(eq(0), eq(0), eq(CALL_STATE_IDLE),
- eq(""), eq(128));
+ eq(""), eq(128), nullable(String.class));
}
@MediumTest
@@ -839,7 +840,7 @@
CallState.ACTIVE, CallState.ON_HOLD);
verify(mMockBluetoothHeadset, never()).phoneStateChanged(anyInt(), anyInt(), anyInt(),
- anyString(), anyInt());
+ anyString(), anyInt(), nullable(String.class));
}
@MediumTest
@@ -851,7 +852,7 @@
CallState.CONNECTING, CallState.DIALING);
verify(mMockBluetoothHeadset, never()).phoneStateChanged(anyInt(), anyInt(), anyInt(),
- anyString(), anyInt());
+ anyString(), anyInt(), nullable(String.class));
}
@MediumTest
@@ -862,8 +863,10 @@
mBluetoothPhoneService.mCallsManagerListener.onCallStateChanged(outgoingCall,
CallState.NEW, CallState.DIALING);
- verify(mMockBluetoothHeadset).phoneStateChanged(0, 0, CALL_STATE_DIALING, "", 128);
- verify(mMockBluetoothHeadset).phoneStateChanged(0, 0, CALL_STATE_ALERTING, "", 128);
+ verify(mMockBluetoothHeadset).phoneStateChanged(eq(0), eq(0), eq(CALL_STATE_DIALING),
+ eq(""), eq(128), nullable(String.class));
+ verify(mMockBluetoothHeadset).phoneStateChanged(eq(0), eq(0), eq(CALL_STATE_ALERTING),
+ eq(""), eq(128), nullable(String.class));
}
@MediumTest
@@ -874,16 +877,16 @@
mBluetoothPhoneService.mCallsManagerListener.onCallStateChanged(disconnectedCall,
CallState.DISCONNECTING, CallState.DISCONNECTED);
verify(mMockBluetoothHeadset).phoneStateChanged(eq(0), eq(0), eq(CALL_STATE_DISCONNECTED),
- eq(""), eq(128));
+ eq(""), eq(128), nullable(String.class));
doReturn(false).when(mMockCallsManager).hasOnlyDisconnectedCalls();
mBluetoothPhoneService.mCallsManagerListener.onDisconnectedTonePlaying(true);
verify(mMockBluetoothHeadset).phoneStateChanged(eq(0), eq(0), eq(CALL_STATE_DISCONNECTED),
- eq(""), eq(128));
+ eq(""), eq(128), nullable(String.class));
mBluetoothPhoneService.mCallsManagerListener.onDisconnectedTonePlaying(false);
verify(mMockBluetoothHeadset).phoneStateChanged(eq(0), eq(0), eq(CALL_STATE_IDLE),
- eq(""), eq(128));
+ eq(""), eq(128), nullable(String.class));
}
@MediumTest
@@ -894,7 +897,7 @@
mBluetoothPhoneService.mCallsManagerListener.onCallAdded(ringingCall);
verify(mMockBluetoothHeadset).phoneStateChanged(eq(0), eq(0), eq(CALL_STATE_INCOMING),
- eq("555-0000"), eq(PhoneNumberUtils.TOA_Unknown));
+ eq("555-0000"), eq(PhoneNumberUtils.TOA_Unknown), nullable(String.class));
//Switch to active
doReturn(null).when(mMockCallsManager).getRingingCall();
@@ -904,7 +907,7 @@
CallState.RINGING, CallState.ACTIVE);
verify(mMockBluetoothHeadset).phoneStateChanged(eq(1), eq(0), eq(CALL_STATE_IDLE),
- eq(""), eq(128));
+ eq(""), eq(128), nullable(String.class));
}
@MediumTest
@@ -917,7 +920,7 @@
CallState.ACTIVE, CallState.ON_HOLD);
verify(mMockBluetoothHeadset, never()).phoneStateChanged(eq(0), eq(2), eq(CALL_STATE_HELD),
- eq("5550000"), eq(PhoneNumberUtils.TOA_Unknown));
+ eq("5550000"), eq(PhoneNumberUtils.TOA_Unknown), nullable(String.class));
}
@MediumTest
@@ -943,18 +946,18 @@
// CDMA "conference"
mBluetoothPhoneService.mCallsManagerListener.onIsConferencedChanged(activeCall);
verify(mMockBluetoothHeadset, never()).phoneStateChanged(anyInt(), anyInt(), anyInt(),
- anyString(), anyInt());
+ anyString(), anyInt(), nullable(String.class));
mBluetoothPhoneService.mCallsManagerListener.onIsConferencedChanged(heldCall);
verify(mMockBluetoothHeadset, never()).phoneStateChanged(anyInt(), anyInt(), anyInt(),
- anyString(), anyInt());
+ anyString(), anyInt(), nullable(String.class));
mBluetoothPhoneService.mCallsManagerListener.onIsConferencedChanged(parentCall);
verify(mMockBluetoothHeadset, never()).phoneStateChanged(anyInt(), anyInt(), anyInt(),
- anyString(), anyInt());
+ anyString(), anyInt(), nullable(String.class));
calls.add(heldCall);
mBluetoothPhoneService.mCallsManagerListener.onIsConferencedChanged(parentCall);
verify(mMockBluetoothHeadset).phoneStateChanged(eq(1), eq(1), eq(CALL_STATE_IDLE),
- eq(""), eq(128));
+ eq(""), eq(128), nullable(String.class));
}
@MediumTest
@@ -968,7 +971,7 @@
mBluetoothPhoneService.mBluetoothAdapterReceiver.onReceive(mContext, intent);
verify(mMockBluetoothHeadset).phoneStateChanged(eq(0), eq(0), eq(CALL_STATE_INCOMING),
- eq("5550000"), eq(PhoneNumberUtils.TOA_Unknown));
+ eq("5550000"), eq(PhoneNumberUtils.TOA_Unknown), nullable(String.class));
}
private void addCallCapability(Call call, int capability) {