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

Commit 655d1897 authored by Grace Jia's avatar Grace Jia
Browse files

TransactionManager lock cleanup.

1. Using telecom system lock when create the LoggedHandlerExecutor in
   VoipCallTransaction.
2. Pass TransactionManager instance created in TelecomSystem to
   CallsManager

Bug: 273769677
Test: unit tests and CTS tests
Change-Id: Id2e2a8ad24f3bf7fc3ed11cd451b9c6a9c174936
Merged-In: Id2e2a8ad24f3bf7fc3ed11cd451b9c6a9c174936
parent f5eb21c3
Loading
Loading
Loading
Loading
+10 −2
Original line number Original line Diff line number Diff line
@@ -54,10 +54,12 @@ public class CallStreamingController extends CallsManagerListenerBase {
    private CallStreamingServiceConnection mConnection;
    private CallStreamingServiceConnection mConnection;
    private boolean mIsStreaming;
    private boolean mIsStreaming;
    private final Object mLock;
    private final Object mLock;
    private TelecomSystem.SyncRoot mTelecomLock;


    public CallStreamingController(Context context) {
    public CallStreamingController(Context context, TelecomSystem.SyncRoot telecomLock) {
        mLock = new Object();
        mLock = new Object();
        mContext = context;
        mContext = context;
        mTelecomLock = telecomLock;
    }
    }


    private void onConnectedInternal(Call call, TransactionalServiceWrapper wrapper,
    private void onConnectedInternal(Call call, TransactionalServiceWrapper wrapper,
@@ -101,6 +103,7 @@ public class CallStreamingController extends CallsManagerListenerBase {
        private final CallsManager mCallsManager;
        private final CallsManager mCallsManager;


        public QueryCallStreamingTransaction(CallsManager callsManager) {
        public QueryCallStreamingTransaction(CallsManager callsManager) {
            super(callsManager.getLock());
            mCallsManager = callsManager;
            mCallsManager = callsManager;
        }
        }


@@ -128,7 +131,9 @@ public class CallStreamingController extends CallsManagerListenerBase {
        private Call mCall;
        private Call mCall;
        private boolean mEnterInterception;
        private boolean mEnterInterception;


        public AudioInterceptionTransaction(Call call, boolean enterInterception) {
        public AudioInterceptionTransaction(Call call, boolean enterInterception,
                TelecomSystem.SyncRoot lock) {
            super(lock);
            mCall = call;
            mCall = call;
            mEnterInterception = enterInterception;
            mEnterInterception = enterInterception;
        }
        }
@@ -164,6 +169,7 @@ public class CallStreamingController extends CallsManagerListenerBase {


        public StreamingServiceTransaction(Context context, TransactionalServiceWrapper wrapper,
        public StreamingServiceTransaction(Context context, TransactionalServiceWrapper wrapper,
                Call call) {
                Call call) {
            super(mTelecomLock);
            mWrapper = wrapper;
            mWrapper = wrapper;
            mCall = call;
            mCall = call;
            mUserHandle = mCall.getInitiatingUser();
            mUserHandle = mCall.getInitiatingUser();
@@ -240,6 +246,7 @@ public class CallStreamingController extends CallsManagerListenerBase {
        private static final String TAG = "UnbindStreamingServiceTransaction";
        private static final String TAG = "UnbindStreamingServiceTransaction";


        public UnbindStreamingServiceTransaction() {
        public UnbindStreamingServiceTransaction() {
            super(mTelecomLock);
        }
        }


        @SuppressLint("LongLogTag")
        @SuppressLint("LongLogTag")
@@ -305,6 +312,7 @@ public class CallStreamingController extends CallsManagerListenerBase {
        @StreamingCall.StreamingCallState int mState;
        @StreamingCall.StreamingCallState int mState;


        public CallStreamingStateChangeTransaction(@StreamingCall.StreamingCallState int state) {
        public CallStreamingStateChangeTransaction(@StreamingCall.StreamingCallState int state) {
            super(mTelecomLock);
            mState = state;
            mState = state;
        }
        }


+6 −2
Original line number Original line Diff line number Diff line
@@ -136,6 +136,7 @@ import com.android.server.telecom.ui.ConfirmCallDialogActivity;
import com.android.server.telecom.ui.DisconnectedCallNotifier;
import com.android.server.telecom.ui.DisconnectedCallNotifier;
import com.android.server.telecom.ui.IncomingCallNotifier;
import com.android.server.telecom.ui.IncomingCallNotifier;
import com.android.server.telecom.ui.ToastFactory;
import com.android.server.telecom.ui.ToastFactory;
import com.android.server.telecom.voip.TransactionManager;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
@@ -441,6 +442,7 @@ public class CallsManager extends Call.ListenerBase
    private final CallAnomalyWatchdog mCallAnomalyWatchdog;
    private final CallAnomalyWatchdog mCallAnomalyWatchdog;
    private final CallStreamingController mCallStreamingController;
    private final CallStreamingController mCallStreamingController;
    private final BlockedNumbersAdapter mBlockedNumbersAdapter;
    private final BlockedNumbersAdapter mBlockedNumbersAdapter;
    private final TransactionManager mTransactionManager;


    private final ConnectionServiceFocusManager.CallsManagerRequester mRequester =
    private final ConnectionServiceFocusManager.CallsManagerRequester mRequester =
            new ConnectionServiceFocusManager.CallsManagerRequester() {
            new ConnectionServiceFocusManager.CallsManagerRequester() {
@@ -549,7 +551,8 @@ public class CallsManager extends Call.ListenerBase
            CallAnomalyWatchdog callAnomalyWatchdog,
            CallAnomalyWatchdog callAnomalyWatchdog,
            Ringer.AccessibilityManagerAdapter accessibilityManagerAdapter,
            Ringer.AccessibilityManagerAdapter accessibilityManagerAdapter,
            Executor asyncTaskExecutor,
            Executor asyncTaskExecutor,
            BlockedNumbersAdapter blockedNumbersAdapter) {
            BlockedNumbersAdapter blockedNumbersAdapter,
            TransactionManager transactionManager) {
        mContext = context;
        mContext = context;
        mLock = lock;
        mLock = lock;
        mPhoneNumberUtilsAdapter = phoneNumberUtilsAdapter;
        mPhoneNumberUtilsAdapter = phoneNumberUtilsAdapter;
@@ -632,8 +635,9 @@ public class CallsManager extends Call.ListenerBase
        mClockProxy = clockProxy;
        mClockProxy = clockProxy;
        mToastFactory = toastFactory;
        mToastFactory = toastFactory;
        mRoleManagerAdapter = roleManagerAdapter;
        mRoleManagerAdapter = roleManagerAdapter;
        mCallStreamingController = new CallStreamingController(mContext);
        mTransactionManager = transactionManager;
        mBlockedNumbersAdapter = blockedNumbersAdapter;
        mBlockedNumbersAdapter = blockedNumbersAdapter;
        mCallStreamingController = new CallStreamingController(mContext, mLock);


        mListeners.add(mInCallWakeLockController);
        mListeners.add(mInCallWakeLockController);
        mListeners.add(statusBarNotifier);
        mListeners.add(statusBarNotifier);
+4 −2
Original line number Original line Diff line number Diff line
@@ -49,6 +49,7 @@ import com.android.server.telecom.ui.DisconnectedCallNotifier;
import com.android.server.telecom.ui.IncomingCallNotifier;
import com.android.server.telecom.ui.IncomingCallNotifier;
import com.android.server.telecom.ui.MissedCallNotifierImpl.MissedCallNotifierImplFactory;
import com.android.server.telecom.ui.MissedCallNotifierImpl.MissedCallNotifierImplFactory;
import com.android.server.telecom.ui.ToastFactory;
import com.android.server.telecom.ui.ToastFactory;
import com.android.server.telecom.voip.TransactionManager;


import java.io.FileNotFoundException;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStream;
@@ -337,6 +338,7 @@ public class TelecomSystem {
            CallAnomalyWatchdog callAnomalyWatchdog = new CallAnomalyWatchdog(
            CallAnomalyWatchdog callAnomalyWatchdog = new CallAnomalyWatchdog(
                    Executors.newSingleThreadScheduledExecutor(),
                    Executors.newSingleThreadScheduledExecutor(),
                    mLock, timeoutsAdapter, clockProxy);
                    mLock, timeoutsAdapter, clockProxy);
            TransactionManager transactionManager = TransactionManager.getInstance();


            mCallsManager = new CallsManager(
            mCallsManager = new CallsManager(
                    mContext,
                    mContext,
@@ -372,8 +374,8 @@ public class TelecomSystem {
                    callAnomalyWatchdog,
                    callAnomalyWatchdog,
                    accessibilityManagerAdapter,
                    accessibilityManagerAdapter,
                    asyncTaskExecutor,
                    asyncTaskExecutor,
                    blockedNumbersAdapter);
                    blockedNumbersAdapter,

                    transactionManager);
            mIncomingCallNotifier = incomingCallNotifier;
            mIncomingCallNotifier = incomingCallNotifier;
            incomingCallNotifier.setCallsManagerProxy(new IncomingCallNotifier.CallsManagerProxy() {
            incomingCallNotifier.setCallsManagerProxy(new IncomingCallNotifier.CallsManagerProxy() {
                @Override
                @Override
+15 −13
Original line number Original line Diff line number Diff line
@@ -86,7 +86,7 @@ public class TransactionalServiceWrapper implements
    private ConnectionServiceFocusManager.ConnectionServiceFocusListener mConnSvrFocusListener;
    private ConnectionServiceFocusManager.ConnectionServiceFocusListener mConnSvrFocusListener;
    // init when constructor is called
    // init when constructor is called
    private final Hashtable<String, Call> mTrackedCalls = new Hashtable<>();
    private final Hashtable<String, Call> mTrackedCalls = new Hashtable<>();
    private final Object mLock;
    private final TelecomSystem.SyncRoot mLock;
    private final String mPackageName;
    private final String mPackageName;
    // needs to be non-final for testing
    // needs to be non-final for testing
    private TransactionManager mTransactionManager;
    private TransactionManager mTransactionManager;
@@ -105,7 +105,7 @@ public class TransactionalServiceWrapper implements
        mPackageName = phoneAccountHandle.getComponentName().getPackageName();
        mPackageName = phoneAccountHandle.getComponentName().getPackageName();
        mTransactionManager = TransactionManager.getInstance();
        mTransactionManager = TransactionManager.getInstance();
        mStreamingController = mCallsManager.getCallStreamingController();
        mStreamingController = mCallsManager.getCallStreamingController();
        mLock = new Object();
        mLock = mCallsManager.getLock();
    }
    }


    @VisibleForTesting
    @VisibleForTesting
@@ -378,7 +378,7 @@ public class TransactionalServiceWrapper implements
        SerialTransaction serialTransactions = createSetActiveTransactions(call);
        SerialTransaction serialTransactions = createSetActiveTransactions(call);
        serialTransactions.appendTransaction(
        serialTransactions.appendTransaction(
                new CallEventCallbackAckTransaction(mICallEventCallback,
                new CallEventCallbackAckTransaction(mICallEventCallback,
                        action, call.getId(), videoState));
                        action, call.getId(), videoState, mLock));


        // do CallsManager workload before asking client and
        // do CallsManager workload before asking client and
        //   reset CallsManager state if client does NOT ack
        //   reset CallsManager state if client does NOT ack
@@ -403,7 +403,7 @@ public class TransactionalServiceWrapper implements
            Log.i(TAG, String.format(Locale.US, "onSetInactive: callId=[%s]", call.getId()));
            Log.i(TAG, String.format(Locale.US, "onSetInactive: callId=[%s]", call.getId()));
            mTransactionManager.addTransaction(
            mTransactionManager.addTransaction(
                    new CallEventCallbackAckTransaction(mICallEventCallback,
                    new CallEventCallbackAckTransaction(mICallEventCallback,
                            ON_SET_INACTIVE, call.getId()), new OutcomeReceiver<>() {
                            ON_SET_INACTIVE, call.getId(), mLock), new OutcomeReceiver<>() {
                        @Override
                        @Override
                        public void onResult(VoipCallTransactionResult result) {
                        public void onResult(VoipCallTransactionResult result) {
                            mCallsManager.markCallAsOnHold(call);
                            mCallsManager.markCallAsOnHold(call);
@@ -426,7 +426,7 @@ public class TransactionalServiceWrapper implements


            mTransactionManager.addTransaction(
            mTransactionManager.addTransaction(
                    new CallEventCallbackAckTransaction(mICallEventCallback, ON_DISCONNECT,
                    new CallEventCallbackAckTransaction(mICallEventCallback, ON_DISCONNECT,
                            call.getId(), cause), new OutcomeReceiver<>() {
                            call.getId(), cause, mLock), new OutcomeReceiver<>() {
                        @Override
                        @Override
                        public void onResult(VoipCallTransactionResult result) {
                        public void onResult(VoipCallTransactionResult result) {
                            removeCallFromCallsManager(call, cause);
                            removeCallFromCallsManager(call, cause);
@@ -451,7 +451,7 @@ public class TransactionalServiceWrapper implements


            mTransactionManager.addTransaction(
            mTransactionManager.addTransaction(
                    new CallEventCallbackAckTransaction(mICallEventCallback, ON_STREAMING_STARTED,
                    new CallEventCallbackAckTransaction(mICallEventCallback, ON_STREAMING_STARTED,
                            call.getId()), new OutcomeReceiver<>() {
                            call.getId(), mLock), new OutcomeReceiver<>() {
                        @Override
                        @Override
                        public void onResult(VoipCallTransactionResult result) {
                        public void onResult(VoipCallTransactionResult result) {
                        }
                        }
@@ -560,7 +560,7 @@ public class TransactionalServiceWrapper implements
        transactions.add(new RequestFocusTransaction(mCallsManager, call));
        transactions.add(new RequestFocusTransaction(mCallsManager, call));


        // send off to Transaction Manager to process
        // send off to Transaction Manager to process
        return new SerialTransaction(transactions);
        return new SerialTransaction(transactions, mLock);
    }
    }


    private SerialTransaction createSetAnswerTransactions(Call call, int videoState) {
    private SerialTransaction createSetAnswerTransactions(Call call, int videoState) {
@@ -574,7 +574,7 @@ public class TransactionalServiceWrapper implements
        transactions.add(new AnswerCallTransaction(mCallsManager, call, videoState));
        transactions.add(new AnswerCallTransaction(mCallsManager, call, videoState));


        // send off to Transaction Manager to process
        // send off to Transaction Manager to process
        return new SerialTransaction(transactions);
        return new SerialTransaction(transactions, mLock);
    }
    }


    /***
    /***
@@ -631,12 +631,13 @@ public class TransactionalServiceWrapper implements
        subTransactions.add(mStreamingController.getCallStreamingServiceTransaction(
        subTransactions.add(mStreamingController.getCallStreamingServiceTransaction(
                mCallsManager.getContext(), this, call));
                mCallsManager.getContext(), this, call));
        // add t2.2 audio route operations
        // add t2.2 audio route operations
        subTransactions.add(new CallStreamingController.AudioInterceptionTransaction(call, true));
        subTransactions.add(new CallStreamingController.AudioInterceptionTransaction(call,
                true, mLock));


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


    private VoipCallTransaction createStopStreamingTransaction(Call call) {
    private VoipCallTransaction createStopStreamingTransaction(Call call) {
@@ -647,8 +648,9 @@ public class TransactionalServiceWrapper implements
        // 1. unbind to call streaming service
        // 1. unbind to call streaming service
        transactions.add(mStreamingController.getUnbindStreamingServiceTransaction());
        transactions.add(mStreamingController.getUnbindStreamingServiceTransaction());
        // 2. audio route operations
        // 2. audio route operations
        transactions.add(new CallStreamingController.AudioInterceptionTransaction(call, false));
        transactions.add(new CallStreamingController.AudioInterceptionTransaction(call,
        return new ParallelTransaction(transactions);
                false, mLock));
        return new ParallelTransaction(transactions, mLock);
    }
    }




+1 −0
Original line number Original line Diff line number Diff line
@@ -41,6 +41,7 @@ public class AnswerCallTransaction extends VoipCallTransaction {
    private final int mVideoState;
    private final int mVideoState;


    public AnswerCallTransaction(CallsManager callsManager, Call call, int videoState) {
    public AnswerCallTransaction(CallsManager callsManager, Call call, int videoState) {
        super(callsManager.getLock());
        mCallsManager = callsManager;
        mCallsManager = callsManager;
        mCall = call;
        mCall = call;
        mVideoState = videoState;
        mVideoState = videoState;
Loading