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

Commit a0208c4d authored by Thomas Stuart's avatar Thomas Stuart Committed by Android (Google) Code Review
Browse files

Merge "Impl. CallEndpoint changes for TransactionalServiceWrapper"

parents 297d201f d44d19a8
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -1856,15 +1856,10 @@ public class CallAudioRouteStateMachine extends StateMachine {
        Set<Call> calls = mCallsManager.getTrackedCalls();
        for (Call call : calls) {
            if (call != null && call.getConnectionService() != null) {
                if (call.isTransactionalCall() && call.getTransactionServiceWrapper() != null) {
                    call.getTransactionServiceWrapper().onCallAudioStateChanged(call,
                            newCallAudioState);
                } else {
                call.getConnectionService().onCallAudioStateChanged(call, newCallAudioState);
            }
        }
    }
    }

    private int calculateSupportedRoutes() {
        int routeMask = CallAudioState.ROUTE_SPEAKER;
+11 −0
Original line number Diff line number Diff line
@@ -164,6 +164,10 @@ public class CallEndpointController extends CallsManagerListenerBase {
            if (call != null && call.getConnectionService() != null) {
                call.getConnectionService().onCallEndpointChanged(call, mActiveCallEndpoint);
            }
            else if (call != null && call.getTransactionServiceWrapper() != null) {
                call.getTransactionServiceWrapper()
                        .onCallEndpointChanged(call, mActiveCallEndpoint);
            }
        }
    }

@@ -176,6 +180,10 @@ public class CallEndpointController extends CallsManagerListenerBase {
                call.getConnectionService().onAvailableCallEndpointsChanged(call,
                        mAvailableCallEndpoints);
            }
            else if (call != null && call.getTransactionServiceWrapper() != null) {
                call.getTransactionServiceWrapper()
                        .onAvailableCallEndpointsChanged(call, mAvailableCallEndpoints);
            }
        }
    }

@@ -187,6 +195,9 @@ public class CallEndpointController extends CallsManagerListenerBase {
            if (call != null && call.getConnectionService() != null) {
                call.getConnectionService().onMuteStateChanged(call, isMuted);
            }
            else if (call != null && call.getTransactionServiceWrapper() != null) {
                call.getTransactionServiceWrapper().onMuteStateChanged(call, isMuted);
            }
        }
    }

+37 −5
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ import android.os.IBinder;
import android.os.OutcomeReceiver;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.telecom.CallAudioState;
import android.telecom.CallEndpoint;
import android.telecom.CallException;
import android.telecom.CallStreamingService;
import android.telecom.DisconnectCause;
@@ -38,9 +38,10 @@ import androidx.annotation.VisibleForTesting;
import com.android.internal.telecom.ICallControl;
import com.android.internal.telecom.ICallEventCallback;
import com.android.server.telecom.voip.CallEventCallbackAckTransaction;
import com.android.server.telecom.voip.EndpointChangeTransaction;
import com.android.server.telecom.voip.HoldCallTransaction;
import com.android.server.telecom.voip.EndCallTransaction;
import com.android.server.telecom.voip.HoldActiveCallForNewCallTransaction;
import com.android.server.telecom.voip.HoldCallTransaction;
import com.android.server.telecom.voip.ParallelTransaction;
import com.android.server.telecom.voip.RequestFocusTransaction;
import com.android.server.telecom.voip.SerialTransaction;
@@ -52,6 +53,7 @@ import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Locale;
import java.util.Set;

/**
 * Implements {@link android.telecom.CallEventCallback} and {@link android.telecom.CallControl}
@@ -265,6 +267,17 @@ public class TransactionalServiceWrapper implements
                callback.send(CODE_CALL_IS_NOT_BEING_TRACKED, new Bundle());
            }
        }

        @Override
        public void requestCallEndpointChange(CallEndpoint endpoint, ResultReceiver callback) {
            try {
                Log.startSession("TSW.rCEC");
                addTransactionsToManager(new EndpointChangeTransaction(endpoint, mCallsManager),
                        callback);
            } finally {
                Log.endSession();
            }
        }
    };

    private void addTransactionsToManager(VoipCallTransaction transaction,
@@ -363,6 +376,7 @@ public class TransactionalServiceWrapper implements
                        public void onResult(VoipCallTransactionResult result) {
                            mCallsManager.markCallAsOnHold(call);
                        }

                        @Override
                        public void onError(CallException exception) {
                            Log.i(TAG, "onSetInactive: onError: with e=[%e]", exception);
@@ -459,11 +473,29 @@ public class TransactionalServiceWrapper implements
        }
    }

    // TODO:: replace with onCallEndpointChanged when CLs are merged
    public void onCallAudioStateChanged(Call call, CallAudioState callAudioState) {
    public void onCallEndpointChanged(Call call, CallEndpoint endpoint) {
        if (call != null) {
            try {
                mICallEventCallback.onCallEndpointChanged(call.getId(), endpoint);
            } catch (RemoteException e) {
            }
        }
    }

    public void onAvailableCallEndpointsChanged(Call call, Set<CallEndpoint> endpoints) {
        if (call != null) {
            try {
                mICallEventCallback.onAvailableCallEndpointsChanged(call.getId(),
                        endpoints.stream().toList());
            } catch (RemoteException e) {
            }
        }
    }

    public void onMuteStateChanged(Call call, boolean isMuted) {
        if (call != null) {
            try {
                mICallEventCallback.onCallAudioStateChanged(call.getId(), callAudioState);
                mICallEventCallback.onMuteStateChanged(call.getId(), isMuted);
            } catch (RemoteException e) {
            }
        }
+58 −0
Original line number Diff line number Diff line

/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.server.telecom.voip;

import android.os.Bundle;
import android.os.ResultReceiver;
import android.telecom.CallEndpoint;
import android.util.Log;

import com.android.server.telecom.CallsManager;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

public class EndpointChangeTransaction extends VoipCallTransaction {
    private static final String TAG = EndpointChangeTransaction.class.getSimpleName();
    private final CallEndpoint mCallEndpoint;
    private final CallsManager mCallsManager;

    public EndpointChangeTransaction(CallEndpoint endpoint, CallsManager callsManager) {
        mCallEndpoint = endpoint;
        mCallsManager = callsManager;
    }

    @Override
    public CompletionStage<VoipCallTransactionResult> processTransaction(Void v) {
        Log.i(TAG, "processTransaction");
        CompletableFuture<VoipCallTransactionResult> future = new CompletableFuture<>();
        mCallsManager.requestCallEndpointChange(mCallEndpoint, new ResultReceiver(null) {
            @Override
            protected void onReceiveResult(int resultCode, Bundle resultData) {
                Log.i(TAG, "processTransaction: code=" + resultCode);
                if (resultCode == CallEndpoint.ENDPOINT_OPERATION_SUCCESS) {
                    future.complete(new VoipCallTransactionResult(
                            VoipCallTransactionResult.RESULT_SUCCEED, null));
                } else {
                    future.complete(new VoipCallTransactionResult(
                            VoipCallTransactionResult.RESULT_FAILED, null));
                }
            }
        });
        return future;
    }
}
+23 −7
Original line number Diff line number Diff line
@@ -18,9 +18,11 @@ package com.android.server.telecom.transactionalVoipApp;


import android.telecom.CallAudioState;
import android.telecom.CallEndpoint;
import android.telecom.CallControl;
import android.telecom.CallEventCallback;
import android.util.Log;
import java.util.List;

import androidx.annotation.NonNull;

@@ -70,19 +72,33 @@ public class MyVoipCall implements CallEventCallback {
        wasCompleted.accept(Boolean.TRUE);
    }

    @Override
    public void onCallAudioStateChanged(@NonNull CallAudioState callAudioState) {
        Log.i(TAG, String.format("onCallAudioStateChanged: state=[%s]", callAudioState.toString()));
    }

    @Override
    public void onCallStreamingStarted(@NonNull Consumer<Boolean> wasCompleted) {
        Log.i(TAG, String.format("onCallStreamingStarted: callId=[%s]", mCallId));
        wasCompleted.accept(Boolean.TRUE);
    }

    @Override
    public void onCallStreamingFailed(int reason) {
        Log.i(TAG, String.format("onCallStreamingFailed: callId[%s], reason=[%s]", mCallId,
                reason));
        Log.i(TAG, String.format("onCallStreamingFailed: id=[%s], reason=[%d]", mCallId, reason));
    }

    @Override
    public void onCallEndpointChanged(@NonNull CallEndpoint newCallEndpoint) {
        Log.i(TAG, String.format("onCallEndpointChanged: endpoint=[%s]", newCallEndpoint));
    }

    @Override
    public void onAvailableCallEndpointsChanged(
            @NonNull List<CallEndpoint> availableEndpoints) {
        Log.i(TAG, String.format("onAvailableCallEndpointsChanged: callId=[%s]", mCallId));
        for (CallEndpoint endpoint : availableEndpoints) {
            Log.i(TAG, String.format("endpoint=[%s]", endpoint));
        }
    }

    @Override
    public void onMuteStateChanged(boolean isMuted) {

    }
}