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

Commit 90834327 authored by Grace Jia's avatar Grace Jia Committed by Automerger Merge Worker
Browse files

Improve call streaming start transaction logic. am: 09bc1566

parents 75769d0e 09bc1566
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
@@ -39,9 +39,12 @@ import android.telecom.StreamingCall;
import android.telecom.Log;

import com.android.internal.telecom.ICallStreamingService;
import com.android.server.telecom.voip.ParallelTransaction;
import com.android.server.telecom.voip.SerialTransaction;
import com.android.server.telecom.voip.VoipCallTransaction;
import com.android.server.telecom.voip.VoipCallTransactionResult;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
@@ -265,6 +268,51 @@ public class CallStreamingController extends CallsManagerListenerBase {
        }
    }

    public class StartStreamingTransaction extends SerialTransaction {
        private Call mCall;

        public StartStreamingTransaction(List<VoipCallTransaction> subTransactions, Call call,
                TelecomSystem.SyncRoot lock) {
            super(subTransactions, lock);
            mCall = call;
        }

        @Override
        public void handleTransactionFailure() {
            mTransactionalServiceWrapper.stopCallStreaming(mCall);
        }
    }

    public VoipCallTransaction getStartStreamingTransaction(CallsManager callsManager,
            TransactionalServiceWrapper wrapper, Call call, TelecomSystem.SyncRoot lock) {
        // start streaming transaction flow:
        //     1. make sure there's no ongoing streaming call --> bind to EXO
        //     2. change audio mode
        //     3. bind to EXO
        // If bind to EXO failed, add transaction for stop the streaming

        // create list for multiple transactions
        List<VoipCallTransaction> transactions = new ArrayList<>();
        transactions.add(new QueryCallStreamingTransaction(callsManager));
        transactions.add(new AudioInterceptionTransaction(call, true, lock));
        transactions.add(getCallStreamingServiceTransaction(
                callsManager.getContext(), wrapper, call));
        return new StartStreamingTransaction(transactions, call, lock);
    }

    public VoipCallTransaction getStopStreamingTransaction(Call call, TelecomSystem.SyncRoot lock) {
        // TODO: implement this
        // Stop streaming transaction flow:
        List<VoipCallTransaction> transactions = new ArrayList<>();

        // 1. unbind to call streaming service
        transactions.add(getUnbindStreamingServiceTransaction());
        // 2. audio route operations
        transactions.add(new CallStreamingController.AudioInterceptionTransaction(call,
                false, lock));
        return new ParallelTransaction(transactions, lock);
    }

    @Override
    public void onCallRemoved(Call call) {
        if (mStreamingCall == call) {
+5 −42
Original line number Diff line number Diff line
@@ -262,7 +262,8 @@ public class TransactionalServiceWrapper implements
                                new HoldCallTransaction(mCallsManager, call), callback);
                        break;
                    case START_STREAMING:
                        addTransactionsToManager(createStartStreamingTransaction(call), callback);
                        addTransactionsToManager(mStreamingController.getStartStreamingTransaction(mCallsManager,
                                TransactionalServiceWrapper.this, call, mLock), callback);
                        break;
                }
            } else {
@@ -336,7 +337,7 @@ public class TransactionalServiceWrapper implements
        }
    };

    private void addTransactionsToManager(VoipCallTransaction transaction,
    public void addTransactionsToManager(VoipCallTransaction transaction,
            ResultReceiver callback) {
        Log.d(TAG, "addTransactionsToManager");

@@ -642,49 +643,11 @@ public class TransactionalServiceWrapper implements
     *********************************************************************************************
     */

    private SerialTransaction createStartStreamingTransaction(Call call) {
        // start streaming transaction flow:
        //     make sure there's no ongoing streaming call --> bind to EXO
        //                                                 `-> change audio mode
        // create list for multiple transactions
        List<VoipCallTransaction> transactions = new ArrayList<>();

        // add t1. make sure no ongoing streaming call
        transactions.add(new CallStreamingController.QueryCallStreamingTransaction(mCallsManager));

        // create list for parallel transactions
        List<VoipCallTransaction> subTransactions = new ArrayList<>();
        // add t2.1 bind to call streaming service
        subTransactions.add(mStreamingController.getCallStreamingServiceTransaction(
                mCallsManager.getContext(), this, call));
        // add t2.2 audio route operations
        subTransactions.add(new CallStreamingController.AudioInterceptionTransaction(call,
                true, mLock));

        // add t2
        transactions.add(new ParallelTransaction(subTransactions, mLock));
        // send off to Transaction Manager to process
        return new SerialTransaction(transactions, mLock);
    }

    private VoipCallTransaction createStopStreamingTransaction(Call call) {
        // TODO: implement this
        // Stop streaming transaction flow:
        List<VoipCallTransaction> transactions = new ArrayList<>();

        // 1. unbind to call streaming service
        transactions.add(mStreamingController.getUnbindStreamingServiceTransaction());
        // 2. audio route operations
        transactions.add(new CallStreamingController.AudioInterceptionTransaction(call,
                false, mLock));
        return new ParallelTransaction(transactions, mLock);
    }


    public void stopCallStreaming(Call call) {
        Log.i(this, "stopCallStreaming; callid=%s", call.getId());
        if (call != null && call.isStreaming()) {
            VoipCallTransaction stopStreamingTransaction = createStopStreamingTransaction(call);
            VoipCallTransaction stopStreamingTransaction = mStreamingController
                    .getStopStreamingTransaction(call, mLock);
            addTransactionsToManager(stopStreamingTransaction, new ResultReceiver(null));
        }
    }
+4 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ public class SerialTransaction extends VoipCallTransaction {
                        public void onTransactionCompleted(VoipCallTransactionResult result,
                                String transactionName) {
                            if (result.getResult() != VoipCallTransactionResult.RESULT_SUCCEED) {
                                handleTransactionFailure();
                                CompletableFuture.completedFuture(null).thenApplyAsync(
                                        (x) -> {
                                            VoipCallTransactionResult mainResult =
@@ -88,6 +89,7 @@ public class SerialTransaction extends VoipCallTransaction {

                        @Override
                        public void onTransactionTimeout(String transactionName) {
                            handleTransactionFailure();
                            CompletableFuture.completedFuture(null).thenApplyAsync(
                                    (x) -> {
                                        VoipCallTransactionResult mainResult =
@@ -111,4 +113,6 @@ public class SerialTransaction extends VoipCallTransaction {
            scheduleTransaction();
        }
    }

    public void handleTransactionFailure() {}
}