1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.telecom.voip; 18 19 import android.os.OutcomeReceiver; 20 import android.telecom.CallException; 21 import android.util.Log; 22 23 import com.android.server.telecom.Call; 24 import com.android.server.telecom.CallsManager; 25 26 import java.util.concurrent.CompletableFuture; 27 import java.util.concurrent.CompletionStage; 28 29 public class MaybeHoldCallForNewCallTransaction extends VoipCallTransaction { 30 31 private static final String TAG = MaybeHoldCallForNewCallTransaction.class.getSimpleName(); 32 private final CallsManager mCallsManager; 33 private final Call mCall; 34 MaybeHoldCallForNewCallTransaction(CallsManager callsManager, Call call)35 public MaybeHoldCallForNewCallTransaction(CallsManager callsManager, Call call) { 36 super(callsManager.getLock()); 37 mCallsManager = callsManager; 38 mCall = call; 39 } 40 41 @Override processTransaction(Void v)42 public CompletionStage<VoipCallTransactionResult> processTransaction(Void v) { 43 Log.d(TAG, "processTransaction"); 44 CompletableFuture<VoipCallTransactionResult> future = new CompletableFuture<>(); 45 46 mCallsManager.transactionHoldPotentialActiveCallForNewCall(mCall, new OutcomeReceiver<>() { 47 @Override 48 public void onResult(Boolean result) { 49 Log.d(TAG, "processTransaction: onResult"); 50 future.complete(new VoipCallTransactionResult( 51 VoipCallTransactionResult.RESULT_SUCCEED, null)); 52 } 53 54 @Override 55 public void onError(CallException exception) { 56 Log.d(TAG, "processTransaction: onError"); 57 future.complete(new VoipCallTransactionResult( 58 exception.getCode(), exception.getMessage())); 59 } 60 }); 61 62 return future; 63 } 64 } 65