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

Commit 79dbb49e authored by Thomas Stuart's avatar Thomas Stuart
Browse files

add capability to send and receive events

bug: 269512817
Test: CTS
Change-Id: Ib14482d0c1abee53dfb44184c277da8707c5bd57
parent 69c948cc
Loading
Loading
Loading
Loading
+16 −8
Original line number Diff line number Diff line
@@ -3205,9 +3205,7 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
     * @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 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
                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 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
                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 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
                    ));
                }
                Log.addEvent(this, LogUtils.Events.CALL_EVENT, event);
                mConnectionService.sendCallEvent(this, event, extras);
                sendEventToService(this, event, extras);
            }
        } else {
            Log.e(this, new NullPointerException(),
@@ -3271,6 +3268,17 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
        }
    }

    /**
     *  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.
+31 −0
Original line number Diff line number Diff line
@@ -273,6 +273,28 @@ public class TransactionalServiceWrapper implements
                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 class TransactionalServiceWrapper implements
        }
    }

    public void onEvent(Call call, String event, Bundle extras){
        if (call != null) {
            try {
                mICallEventCallback.onEvent(call.getId(), event, extras);
            } catch (RemoteException e) {
            }
        }
    }

    /***
     *********************************************************************************************
     **                                Helpers                                                  **
+8 −0
Original line number Diff line number Diff line
@@ -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;
@@ -82,6 +84,12 @@ public class MyVoipCall implements CallControlCallback, CallEventCallback {
        Log.i(TAG, String.format("onCallStreamingFailed: id=[%s], reason=[%d]", mCallId, reason));
    }

    @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));