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

Commit 8deef8d2 authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

Call Sequencing initial changes/refactor

This CL refactors the existing transactional logic to be retrofitted to
a more general case that handles regular connection services as well.
This CL mainly just renames existing classes and moves classes around to
different directories for better clarity.

This also inserts the boilerplate code for implementing the call
sequencing related changes. Those classes are as follows:
CallSequencingController, CallsManagerSequencingAdapter,
TransactionalCallSequencingAdapter.

A separate CL will be put up that will be focused around the
actual implementation.

Bug: 327038818
Flag: com.android.server.telecom.flags.enable_call_sequencing
Test: m Telecom
Change-Id: I75bd7954f9c84affcfeff29e0f36fa09e0c56607
parent c5b6918a
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -16,7 +16,8 @@


package com.android.server.telecom;
package com.android.server.telecom;


import static com.android.server.telecom.voip.VideoStateTranslation.TransactionalVideoStateToString;
import static com.android.server.telecom.callsequencing.voip.VideoStateTranslation
        .TransactionalVideoStateToString;


import android.telecom.Log;
import android.telecom.Log;


+8 −6
Original line number Original line Diff line number Diff line
@@ -21,8 +21,10 @@ import static android.telephony.TelephonyManager.EVENT_DISPLAY_EMERGENCY_MESSAGE


import static com.android.server.telecom.CachedCallback.TYPE_QUEUE;
import static com.android.server.telecom.CachedCallback.TYPE_QUEUE;
import static com.android.server.telecom.CachedCallback.TYPE_STATE;
import static com.android.server.telecom.CachedCallback.TYPE_STATE;
import static com.android.server.telecom.voip.VideoStateTranslation.TransactionalVideoStateToString;
import static com.android.server.telecom.callsequencing.voip.VideoStateTranslation
import static com.android.server.telecom.voip.VideoStateTranslation.VideoProfileStateToTransactionalVideoState;
        .TransactionalVideoStateToString;
import static com.android.server.telecom.callsequencing.voip.VideoStateTranslation
        .VideoProfileStateToTransactionalVideoState;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
@@ -78,9 +80,9 @@ import com.android.server.telecom.flags.FeatureFlags;
import com.android.server.telecom.stats.CallFailureCause;
import com.android.server.telecom.stats.CallFailureCause;
import com.android.server.telecom.stats.CallStateChangedAtomWriter;
import com.android.server.telecom.stats.CallStateChangedAtomWriter;
import com.android.server.telecom.ui.ToastFactory;
import com.android.server.telecom.ui.ToastFactory;
import com.android.server.telecom.voip.TransactionManager;
import com.android.server.telecom.callsequencing.TransactionManager;
import com.android.server.telecom.voip.VerifyCallStateChangeTransaction;
import com.android.server.telecom.callsequencing.VerifyCallStateChangeTransaction;
import com.android.server.telecom.voip.VoipCallTransactionResult;
import com.android.server.telecom.callsequencing.CallTransactionResult;


import java.io.IOException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.text.SimpleDateFormat;
@@ -3185,7 +3187,7 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
        tm.addTransaction(new VerifyCallStateChangeTransaction(mCallsManager.getLock(),
        tm.addTransaction(new VerifyCallStateChangeTransaction(mCallsManager.getLock(),
                this, targetCallState), new OutcomeReceiver<>() {
                this, targetCallState), new OutcomeReceiver<>() {
            @Override
            @Override
            public void onResult(VoipCallTransactionResult result) {
            public void onResult(CallTransactionResult result) {
                Log.i(this, "awaitCallStateChangeAndMaybeDisconnectCall: %s: onResult:"
                Log.i(this, "awaitCallStateChangeAndMaybeDisconnectCall: %s: onResult:"
                        + " due to CallException=[%s]", callingMethod, result);
                        + " due to CallException=[%s]", callingMethod, result);
            }
            }
+44 −44
Original line number Original line Diff line number Diff line
@@ -39,10 +39,10 @@ import android.telecom.StreamingCall;
import android.telecom.Log;
import android.telecom.Log;


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


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
@@ -112,7 +112,7 @@ public class CallStreamingController extends CallsManagerListenerBase {
        }
        }
    }
    }


    public static class QueryCallStreamingTransaction extends VoipCallTransaction {
    public static class QueryCallStreamingTransaction extends CallTransaction {
        private final CallsManager mCallsManager;
        private final CallsManager mCallsManager;


        public QueryCallStreamingTransaction(CallsManager callsManager) {
        public QueryCallStreamingTransaction(CallsManager callsManager) {
@@ -121,24 +121,24 @@ public class CallStreamingController extends CallsManagerListenerBase {
        }
        }


        @Override
        @Override
        public CompletableFuture<VoipCallTransactionResult> processTransaction(Void v) {
        public CompletableFuture<CallTransactionResult> processTransaction(Void v) {
            Log.i(this, "processTransaction");
            Log.i(this, "processTransaction");
            CompletableFuture<VoipCallTransactionResult> future = new CompletableFuture<>();
            CompletableFuture<CallTransactionResult> future = new CompletableFuture<>();


            if (mCallsManager.getCallStreamingController().isStreaming()) {
            if (mCallsManager.getCallStreamingController().isStreaming()) {
                future.complete(new VoipCallTransactionResult(
                future.complete(new CallTransactionResult(
                        CallException.CODE_ERROR_UNKNOWN /* TODO:: define error b/335703584 */,
                        CallException.CODE_ERROR_UNKNOWN /* TODO:: define error b/335703584 */,
                        "STREAMING_FAILED_ALREADY_STREAMING"));
                        "STREAMING_FAILED_ALREADY_STREAMING"));
            } else {
            } else {
                future.complete(new VoipCallTransactionResult(
                future.complete(new CallTransactionResult(
                        VoipCallTransactionResult.RESULT_SUCCEED, null));
                        CallTransactionResult.RESULT_SUCCEED, null));
            }
            }


            return future;
            return future;
        }
        }
    }
    }


    public static class AudioInterceptionTransaction extends VoipCallTransaction {
    public static class AudioInterceptionTransaction extends CallTransaction {
        private Call mCall;
        private Call mCall;
        private boolean mEnterInterception;
        private boolean mEnterInterception;


@@ -150,16 +150,16 @@ public class CallStreamingController extends CallsManagerListenerBase {
        }
        }


        @Override
        @Override
        public CompletableFuture<VoipCallTransactionResult> processTransaction(Void v) {
        public CompletableFuture<CallTransactionResult> processTransaction(Void v) {
            Log.i(this, "processTransaction");
            Log.i(this, "processTransaction");
            CompletableFuture<VoipCallTransactionResult> future = new CompletableFuture<>();
            CompletableFuture<CallTransactionResult> future = new CompletableFuture<>();


            if (mEnterInterception) {
            if (mEnterInterception) {
                mCall.startStreaming();
                mCall.startStreaming();
            } else {
            } else {
                mCall.stopStreaming();
                mCall.stopStreaming();
            }
            }
            future.complete(new VoipCallTransactionResult(VoipCallTransactionResult.RESULT_SUCCEED,
            future.complete(new CallTransactionResult(CallTransactionResult.RESULT_SUCCEED,
                    null));
                    null));
            return future;
            return future;
        }
        }
@@ -170,7 +170,7 @@ public class CallStreamingController extends CallsManagerListenerBase {
        return new StreamingServiceTransaction(context, wrapper, call);
        return new StreamingServiceTransaction(context, wrapper, call);
    }
    }


    public class StreamingServiceTransaction extends VoipCallTransaction {
    public class StreamingServiceTransaction extends CallTransaction {
        public static final String MESSAGE = "STREAMING_FAILED_NO_SENDER";
        public static final String MESSAGE = "STREAMING_FAILED_NO_SENDER";
        private final TransactionalServiceWrapper mWrapper;
        private final TransactionalServiceWrapper mWrapper;
        private final Context mContext;
        private final Context mContext;
@@ -188,14 +188,14 @@ public class CallStreamingController extends CallsManagerListenerBase {


        @SuppressLint("LongLogTag")
        @SuppressLint("LongLogTag")
        @Override
        @Override
        public CompletionStage<VoipCallTransactionResult> processTransaction(Void v) {
        public CompletionStage<CallTransactionResult> processTransaction(Void v) {
            Log.i(this, "processTransaction");
            Log.i(this, "processTransaction");
            CompletableFuture<VoipCallTransactionResult> future = new CompletableFuture<>();
            CompletableFuture<CallTransactionResult> future = new CompletableFuture<>();
            RoleManager roleManager = mContext.getSystemService(RoleManager.class);
            RoleManager roleManager = mContext.getSystemService(RoleManager.class);
            PackageManager packageManager = mContext.getPackageManager();
            PackageManager packageManager = mContext.getPackageManager();
            if (roleManager == null || packageManager == null) {
            if (roleManager == null || packageManager == null) {
                Log.w(this, "processTransaction: Can't find system service");
                Log.w(this, "processTransaction: Can't find system service");
                future.complete(new VoipCallTransactionResult(
                future.complete(new CallTransactionResult(
                        CallException.CODE_ERROR_UNKNOWN /* TODO:: define error b/335703584 */,
                        CallException.CODE_ERROR_UNKNOWN /* TODO:: define error b/335703584 */,
                        MESSAGE));
                        MESSAGE));
                return future;
                return future;
@@ -205,7 +205,7 @@ public class CallStreamingController extends CallsManagerListenerBase {
                    RoleManager.ROLE_SYSTEM_CALL_STREAMING, mUserHandle);
                    RoleManager.ROLE_SYSTEM_CALL_STREAMING, mUserHandle);
            if (holders.isEmpty()) {
            if (holders.isEmpty()) {
                Log.w(this, "processTransaction: Can't find streaming app");
                Log.w(this, "processTransaction: Can't find streaming app");
                future.complete(new VoipCallTransactionResult(
                future.complete(new CallTransactionResult(
                        CallException.CODE_ERROR_UNKNOWN /* TODO:: define error b/335703584 */,
                        CallException.CODE_ERROR_UNKNOWN /* TODO:: define error b/335703584 */,
                        MESSAGE));
                        MESSAGE));
                return future;
                return future;
@@ -217,7 +217,7 @@ public class CallStreamingController extends CallsManagerListenerBase {
                    PackageManager.GET_META_DATA, mUserHandle);
                    PackageManager.GET_META_DATA, mUserHandle);
            if (infos.isEmpty()) {
            if (infos.isEmpty()) {
                Log.w(this, "processTransaction: Can't find streaming service");
                Log.w(this, "processTransaction: Can't find streaming service");
                future.complete(new VoipCallTransactionResult(
                future.complete(new CallTransactionResult(
                        CallException.CODE_ERROR_UNKNOWN /* TODO:: define error b/335703584 */,
                        CallException.CODE_ERROR_UNKNOWN /* TODO:: define error b/335703584 */,
                        MESSAGE));
                        MESSAGE));
                return future;
                return future;
@@ -229,7 +229,7 @@ public class CallStreamingController extends CallsManagerListenerBase {
                    Manifest.permission.BIND_CALL_STREAMING_SERVICE)) {
                    Manifest.permission.BIND_CALL_STREAMING_SERVICE)) {
                Log.w(this, "Must require BIND_CALL_STREAMING_SERVICE: " +
                Log.w(this, "Must require BIND_CALL_STREAMING_SERVICE: " +
                        serviceInfo.packageName);
                        serviceInfo.packageName);
                future.complete(new VoipCallTransactionResult(
                future.complete(new CallTransactionResult(
                        CallException.CODE_ERROR_UNKNOWN /* TODO:: define error b/335703584 */,
                        CallException.CODE_ERROR_UNKNOWN /* TODO:: define error b/335703584 */,
                        MESSAGE));
                        MESSAGE));
                return future;
                return future;
@@ -242,7 +242,7 @@ public class CallStreamingController extends CallsManagerListenerBase {
                    | Context.BIND_FOREGROUND_SERVICE
                    | Context.BIND_FOREGROUND_SERVICE
                    | Context.BIND_SCHEDULE_LIKE_TOP_APP, mUserHandle)) {
                    | Context.BIND_SCHEDULE_LIKE_TOP_APP, mUserHandle)) {
                Log.w(this, "Can't bind to streaming service");
                Log.w(this, "Can't bind to streaming service");
                future.complete(new VoipCallTransactionResult(
                future.complete(new CallTransactionResult(
                        CallException.CODE_ERROR_UNKNOWN /* TODO:: define error b/335703584 */,
                        CallException.CODE_ERROR_UNKNOWN /* TODO:: define error b/335703584 */,
                        "STREAMING_FAILED_SENDER_BINDING_ERROR"));
                        "STREAMING_FAILED_SENDER_BINDING_ERROR"));
            }
            }
@@ -254,19 +254,19 @@ public class CallStreamingController extends CallsManagerListenerBase {
        return new UnbindStreamingServiceTransaction();
        return new UnbindStreamingServiceTransaction();
    }
    }


    public class UnbindStreamingServiceTransaction extends VoipCallTransaction {
    public class UnbindStreamingServiceTransaction extends CallTransaction {
        public UnbindStreamingServiceTransaction() {
        public UnbindStreamingServiceTransaction() {
            super(mTelecomLock);
            super(mTelecomLock);
        }
        }


        @SuppressLint("LongLogTag")
        @SuppressLint("LongLogTag")
        @Override
        @Override
        public CompletionStage<VoipCallTransactionResult> processTransaction(Void v) {
        public CompletionStage<CallTransactionResult> processTransaction(Void v) {
            Log.i(this, "processTransaction (unbindStreaming");
            Log.i(this, "processTransaction (unbindStreaming");
            CompletableFuture<VoipCallTransactionResult> future = new CompletableFuture<>();
            CompletableFuture<CallTransactionResult> future = new CompletableFuture<>();


            resetController();
            resetController();
            future.complete(new VoipCallTransactionResult(VoipCallTransactionResult.RESULT_SUCCEED,
            future.complete(new CallTransactionResult(CallTransactionResult.RESULT_SUCCEED,
                    null));
                    null));
            return future;
            return future;
        }
        }
@@ -275,7 +275,7 @@ public class CallStreamingController extends CallsManagerListenerBase {
    public class StartStreamingTransaction extends SerialTransaction {
    public class StartStreamingTransaction extends SerialTransaction {
        private Call mCall;
        private Call mCall;


        public StartStreamingTransaction(List<VoipCallTransaction> subTransactions, Call call,
        public StartStreamingTransaction(List<CallTransaction> subTransactions, Call call,
                TelecomSystem.SyncRoot lock) {
                TelecomSystem.SyncRoot lock) {
            super(subTransactions, lock);
            super(subTransactions, lock);
            mCall = call;
            mCall = call;
@@ -287,7 +287,7 @@ public class CallStreamingController extends CallsManagerListenerBase {
        }
        }
    }
    }


    public VoipCallTransaction getStartStreamingTransaction(CallsManager callsManager,
    public CallTransaction getStartStreamingTransaction(CallsManager callsManager,
            TransactionalServiceWrapper wrapper, Call call, TelecomSystem.SyncRoot lock) {
            TransactionalServiceWrapper wrapper, Call call, TelecomSystem.SyncRoot lock) {
        // start streaming transaction flow:
        // start streaming transaction flow:
        //     1. make sure there's no ongoing streaming call --> bind to EXO
        //     1. make sure there's no ongoing streaming call --> bind to EXO
@@ -296,7 +296,7 @@ public class CallStreamingController extends CallsManagerListenerBase {
        // If bind to EXO failed, add transaction for stop the streaming
        // If bind to EXO failed, add transaction for stop the streaming


        // create list for multiple transactions
        // create list for multiple transactions
        List<VoipCallTransaction> transactions = new ArrayList<>();
        List<CallTransaction> transactions = new ArrayList<>();
        transactions.add(new QueryCallStreamingTransaction(callsManager));
        transactions.add(new QueryCallStreamingTransaction(callsManager));
        transactions.add(new AudioInterceptionTransaction(call, true, lock));
        transactions.add(new AudioInterceptionTransaction(call, true, lock));
        transactions.add(getCallStreamingServiceTransaction(
        transactions.add(getCallStreamingServiceTransaction(
@@ -304,10 +304,10 @@ public class CallStreamingController extends CallsManagerListenerBase {
        return new StartStreamingTransaction(transactions, call, lock);
        return new StartStreamingTransaction(transactions, call, lock);
    }
    }


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


        // 1. unbind to call streaming service
        // 1. unbind to call streaming service
        transactions.add(getUnbindStreamingServiceTransaction());
        transactions.add(getUnbindStreamingServiceTransaction());
@@ -352,7 +352,7 @@ public class CallStreamingController extends CallsManagerListenerBase {
                mTransactionalServiceWrapper.getTransactionManager().addTransaction(transaction,
                mTransactionalServiceWrapper.getTransactionManager().addTransaction(transaction,
                        new OutcomeReceiver<>() {
                        new OutcomeReceiver<>() {
                            @Override
                            @Override
                            public void onResult(VoipCallTransactionResult result) {
                            public void onResult(CallTransactionResult result) {
                                // ignore
                                // ignore
                            }
                            }


@@ -366,7 +366,7 @@ public class CallStreamingController extends CallsManagerListenerBase {
        }
        }
    }
    }


    private class CallStreamingStateChangeTransaction extends VoipCallTransaction {
    private class CallStreamingStateChangeTransaction extends CallTransaction {
        @StreamingCall.StreamingCallState int mState;
        @StreamingCall.StreamingCallState int mState;


        public CallStreamingStateChangeTransaction(@StreamingCall.StreamingCallState int state) {
        public CallStreamingStateChangeTransaction(@StreamingCall.StreamingCallState int state) {
@@ -375,14 +375,14 @@ public class CallStreamingController extends CallsManagerListenerBase {
        }
        }


        @Override
        @Override
        public CompletionStage<VoipCallTransactionResult> processTransaction(Void v) {
        public CompletionStage<CallTransactionResult> processTransaction(Void v) {
            CompletableFuture<VoipCallTransactionResult> future = new CompletableFuture<>();
            CompletableFuture<CallTransactionResult> future = new CompletableFuture<>();
            try {
            try {
                mService.onCallStreamingStateChanged(mState);
                mService.onCallStreamingStateChanged(mState);
                future.complete(new VoipCallTransactionResult(
                future.complete(new CallTransactionResult(
                        VoipCallTransactionResult.RESULT_SUCCEED, null));
                        CallTransactionResult.RESULT_SUCCEED, null));
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                future.complete(new VoipCallTransactionResult(
                future.complete(new CallTransactionResult(
                        CallException.CODE_ERROR_UNKNOWN /* TODO:: define error b/335703584 */,
                        CallException.CODE_ERROR_UNKNOWN /* TODO:: define error b/335703584 */,
                        "Exception when request "
                        "Exception when request "
                        + "setting state to streaming app."));
                        + "setting state to streaming app."));
@@ -395,10 +395,10 @@ public class CallStreamingController extends CallsManagerListenerBase {
            ServiceConnection {
            ServiceConnection {
        private Call mCall;
        private Call mCall;
        private TransactionalServiceWrapper mWrapper;
        private TransactionalServiceWrapper mWrapper;
        private CompletableFuture<VoipCallTransactionResult> mFuture;
        private CompletableFuture<CallTransactionResult> mFuture;


        public CallStreamingServiceConnection(Call call, TransactionalServiceWrapper wrapper,
        public CallStreamingServiceConnection(Call call, TransactionalServiceWrapper wrapper,
                CompletableFuture<VoipCallTransactionResult> future) {
                CompletableFuture<CallTransactionResult> future) {
            mCall = call;
            mCall = call;
            mWrapper = wrapper;
            mWrapper = wrapper;
            mFuture = future;
            mFuture = future;
@@ -409,11 +409,11 @@ public class CallStreamingController extends CallsManagerListenerBase {
            try {
            try {
                Log.i(this, "onServiceConnected: " + name);
                Log.i(this, "onServiceConnected: " + name);
                onConnectedInternal(mCall, mWrapper, service);
                onConnectedInternal(mCall, mWrapper, service);
                mFuture.complete(new VoipCallTransactionResult(
                mFuture.complete(new CallTransactionResult(
                        VoipCallTransactionResult.RESULT_SUCCEED, null));
                        CallTransactionResult.RESULT_SUCCEED, null));
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                resetController();
                resetController();
                mFuture.complete(new VoipCallTransactionResult(
                mFuture.complete(new CallTransactionResult(
                        CallException.CODE_ERROR_UNKNOWN /* TODO:: define error b/335703584 */,
                        CallException.CODE_ERROR_UNKNOWN /* TODO:: define error b/335703584 */,
                        StreamingServiceTransaction.MESSAGE));
                        StreamingServiceTransaction.MESSAGE));
            }
            }
@@ -437,7 +437,7 @@ public class CallStreamingController extends CallsManagerListenerBase {
        private void clearBinding() {
        private void clearBinding() {
            resetController();
            resetController();
            if (!mFuture.isDone()) {
            if (!mFuture.isDone()) {
                mFuture.complete(new VoipCallTransactionResult(
                mFuture.complete(new CallTransactionResult(
                        CallException.CODE_ERROR_UNKNOWN /* TODO:: define error b/335703584 */,
                        CallException.CODE_ERROR_UNKNOWN /* TODO:: define error b/335703584 */,
                        "STREAMING_FAILED_SENDER_BINDING_ERROR"));
                        "STREAMING_FAILED_SENDER_BINDING_ERROR"));
            } else {
            } else {
Loading