add capability to send and receive events
bug: 269512817
Test: CTS
Change-Id: Ib14482d0c1abee53dfb44184c277da8707c5bd57
diff --git a/src/com/android/server/telecom/Call.java b/src/com/android/server/telecom/Call.java
index 5847960..a076799 100644
--- a/src/com/android/server/telecom/Call.java
+++ b/src/com/android/server/telecom/Call.java
@@ -3205,9 +3205,7 @@
* @param extras Associated extras.
*/
public void sendCallEvent(String event, int targetSdkVer, Bundle extras) {
- if (mTransactionalService != null) {
- Log.i(this, "sendCallEvent: called on TransactionalService. doing nothing");
- } else if (mConnectionService != null) {
+ if (mConnectionService != null || mTransactionalService != null) {
if (android.telecom.Call.EVENT_REQUEST_HANDOVER.equals(event)) {
if (targetSdkVer > Build.VERSION_CODES.P) {
Log.e(this, new Exception(), "sendCallEvent failed. Use public api handoverTo" +
@@ -3230,8 +3228,8 @@
if (extras == null) {
Log.w(this, "sendCallEvent: %s event received with null extras.",
android.telecom.Call.EVENT_REQUEST_HANDOVER);
- mConnectionService.sendCallEvent(this,
- android.telecom.Call.EVENT_HANDOVER_FAILED, null);
+ sendEventToService(this, android.telecom.Call.EVENT_HANDOVER_FAILED,
+ null);
return;
}
Parcelable parcelable = extras.getParcelable(
@@ -3239,8 +3237,7 @@
if (!(parcelable instanceof PhoneAccountHandle) || parcelable == null) {
Log.w(this, "sendCallEvent: %s event received with invalid handover acct.",
android.telecom.Call.EVENT_REQUEST_HANDOVER);
- mConnectionService.sendCallEvent(this,
- android.telecom.Call.EVENT_HANDOVER_FAILED, null);
+ sendEventToService(this, android.telecom.Call.EVENT_HANDOVER_FAILED, null);
return;
}
PhoneAccountHandle phoneAccountHandle = (PhoneAccountHandle) parcelable;
@@ -3263,7 +3260,7 @@
));
}
Log.addEvent(this, LogUtils.Events.CALL_EVENT, event);
- mConnectionService.sendCallEvent(this, event, extras);
+ sendEventToService(this, event, extras);
}
} else {
Log.e(this, new NullPointerException(),
@@ -3272,6 +3269,17 @@
}
/**
+ * This method should only be called from sendCallEvent(String, int, Bundle).
+ */
+ private void sendEventToService(Call call, String event, Bundle extras) {
+ if (mConnectionService != null) {
+ mConnectionService.sendCallEvent(call, event, extras);
+ } else if (mTransactionalService != null) {
+ mTransactionalService.onEvent(call, event, extras);
+ }
+ }
+
+ /**
* Notifies listeners when a bluetooth quality report is received.
* @param report The bluetooth quality report.
*/
diff --git a/src/com/android/server/telecom/TransactionalServiceWrapper.java b/src/com/android/server/telecom/TransactionalServiceWrapper.java
index 6931996..42e8f2a 100644
--- a/src/com/android/server/telecom/TransactionalServiceWrapper.java
+++ b/src/com/android/server/telecom/TransactionalServiceWrapper.java
@@ -273,6 +273,28 @@
Log.endSession();
}
}
+
+ /**
+ * Application would like to inform InCallServices of an event
+ */
+ @Override
+ public void sendEvent(String callId, String event, Bundle extras) {
+ try {
+ Log.startSession("TSW.sE");
+ Call call = mTrackedCalls.get(callId);
+ if (call != null) {
+ call.onConnectionEvent(event, extras);
+ }
+ else{
+ Log.i(TAG,
+ "sendEvent: was called but there is no call with id=[%s] cannot be "
+ + "found. Most likely the call has been disconnected");
+ }
+ }
+ finally {
+ Log.endSession();
+ }
+ }
};
private void addTransactionsToManager(VoipCallTransaction transaction,
@@ -508,6 +530,15 @@
}
}
+ public void onEvent(Call call, String event, Bundle extras){
+ if (call != null) {
+ try {
+ mICallEventCallback.onEvent(call.getId(), event, extras);
+ } catch (RemoteException e) {
+ }
+ }
+ }
+
/***
*********************************************************************************************
** Helpers **
diff --git a/testapps/transactionalVoipApp/src/com/android/server/telecom/transactionalVoipApp/MyVoipCall.java b/testapps/transactionalVoipApp/src/com/android/server/telecom/transactionalVoipApp/MyVoipCall.java
index cdf2efa..bf24513 100644
--- a/testapps/transactionalVoipApp/src/com/android/server/telecom/transactionalVoipApp/MyVoipCall.java
+++ b/testapps/transactionalVoipApp/src/com/android/server/telecom/transactionalVoipApp/MyVoipCall.java
@@ -16,11 +16,13 @@
package com.android.server.telecom.transactionalVoipApp;
+import android.os.Bundle;
import android.telecom.CallControlCallback;
import android.telecom.CallEndpoint;
import android.telecom.CallControl;
import android.telecom.CallEventCallback;
import android.util.Log;
+
import java.util.List;
import androidx.annotation.NonNull;
@@ -83,6 +85,12 @@
}
@Override
+ public void onEvent(String event, Bundle extras) {
+ Log.i(TAG, String.format("onEvent: id=[%s], event=[%s], extras=[%s]",
+ mCallId, event, extras));
+ }
+
+ @Override
public void onCallEndpointChanged(@NonNull CallEndpoint newCallEndpoint) {
Log.i(TAG, String.format("onCallEndpointChanged: endpoint=[%s]", newCallEndpoint));
}