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.telecom.CallException;
20 import android.util.Log;
21 
22 import com.android.server.telecom.Call;
23 import com.android.server.telecom.CallsManager;
24 
25 import java.util.concurrent.CompletableFuture;
26 import java.util.concurrent.CompletionStage;
27 
28 public class HoldCallTransaction extends VoipCallTransaction {
29 
30     private static final String TAG = HoldCallTransaction.class.getSimpleName();
31     private final CallsManager mCallsManager;
32     private final Call mCall;
33 
HoldCallTransaction(CallsManager callsManager, Call call)34     public HoldCallTransaction(CallsManager callsManager, Call call) {
35         super(callsManager.getLock());
36         mCallsManager = callsManager;
37         mCall = call;
38     }
39 
40     @Override
processTransaction(Void v)41     public CompletionStage<VoipCallTransactionResult> processTransaction(Void v) {
42         Log.d(TAG, "processTransaction");
43         CompletableFuture<VoipCallTransactionResult> future = new CompletableFuture<>();
44 
45         if (mCallsManager.canHold(mCall)) {
46             mCallsManager.markCallAsOnHold(mCall);
47             future.complete(new VoipCallTransactionResult(
48                     VoipCallTransactionResult.RESULT_SUCCEED, null));
49         } else {
50             Log.d(TAG, "processTransaction: onError");
51             future.complete(new VoipCallTransactionResult(
52                     CallException.CODE_CANNOT_HOLD_CURRENT_ACTIVE_CALL, "cannot hold call"));
53         }
54         return future;
55     }
56 }
57