• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.callsequencing.voip;
18 
19 import static android.telecom.CallException.CODE_CALL_NOT_PERMITTED_AT_PRESENT_TIME;
20 
21 import android.util.Log;
22 
23 import com.android.internal.annotations.VisibleForTesting;
24 import com.android.server.telecom.Call;
25 import com.android.server.telecom.CallsManager;
26 import com.android.server.telecom.LoggedHandlerExecutor;
27 import com.android.server.telecom.callsequencing.CallTransaction;
28 import com.android.server.telecom.callsequencing.CallTransactionResult;
29 import com.android.server.telecom.flags.FeatureFlags;
30 
31 import java.util.concurrent.CompletableFuture;
32 import java.util.concurrent.CompletionStage;
33 
34 public class OutgoingCallTransactionSequencing extends CallTransaction {
35 
36     private static final String TAG = OutgoingCallTransactionSequencing.class.getSimpleName();
37     private final CompletableFuture<Call> mCallFuture;
38     private final CallsManager mCallsManager;
39     private final boolean mCallNotPermitted;
40     private FeatureFlags mFeatureFlags;
41 
OutgoingCallTransactionSequencing(CallsManager callsManager, CompletableFuture<Call> callFuture, boolean callNotPermitted, FeatureFlags featureFlags)42     public OutgoingCallTransactionSequencing(CallsManager callsManager,
43             CompletableFuture<Call> callFuture, boolean callNotPermitted,
44             FeatureFlags featureFlags) {
45         super(callsManager.getLock());
46         mCallsManager = callsManager;
47         mCallFuture = callFuture;
48         mCallNotPermitted = callNotPermitted;
49         mFeatureFlags = featureFlags;
50     }
51 
52     @Override
processTransaction(Void v)53     public CompletionStage<CallTransactionResult> processTransaction(Void v) {
54         Log.d(TAG, "processTransaction");
55         if (mCallNotPermitted) {
56             return CompletableFuture.completedFuture(
57                     new CallTransactionResult(
58                             CODE_CALL_NOT_PERMITTED_AT_PRESENT_TIME,
59                             "outgoing call not permitted at the current time"));
60         }
61 
62         return mCallFuture.thenComposeAsync(
63                 (call) -> OutgoingCallTransaction.processOutgoingCallTransactionHelper(call, TAG,
64                         mCallsManager, mFeatureFlags)
65                 , new LoggedHandlerExecutor(mHandler, "OCT.pT", null));
66     }
67 
68     @VisibleForTesting
getCallNotPermitted()69     public boolean getCallNotPermitted() {
70         return mCallNotPermitted;
71     }
72 }
73