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.DisconnectCause; 20 import android.util.Log; 21 22 import com.android.server.telecom.Call; 23 import com.android.server.telecom.CallState; 24 import com.android.server.telecom.CallsManager; 25 26 import java.util.concurrent.CompletableFuture; 27 import java.util.concurrent.CompletionStage; 28 29 /** 30 * This transaction should only be created for a CallControl action. 31 */ 32 public class EndCallTransaction extends VoipCallTransaction { 33 private static final String TAG = EndCallTransaction.class.getSimpleName(); 34 private final CallsManager mCallsManager; 35 private final Call mCall; 36 private DisconnectCause mCause; 37 EndCallTransaction(CallsManager callsManager, DisconnectCause cause, Call call)38 public EndCallTransaction(CallsManager callsManager, DisconnectCause cause, Call call) { 39 super(callsManager.getLock()); 40 mCallsManager = callsManager; 41 mCause = cause; 42 mCall = call; 43 } 44 45 @Override processTransaction(Void v)46 public CompletionStage<VoipCallTransactionResult> processTransaction(Void v) { 47 int code = mCause.getCode(); 48 Log.d(TAG, String.format("processTransaction: mCode=[%d], mCall=[%s]", code, mCall)); 49 50 if (mCall.getState() == CallState.RINGING && code == DisconnectCause.LOCAL) { 51 mCause = new DisconnectCause(DisconnectCause.REJECTED, 52 "overrode cause in EndCallTransaction"); 53 } 54 55 mCallsManager.markCallAsDisconnected(mCall, mCause); 56 mCallsManager.markCallAsRemoved(mCall); 57 58 return CompletableFuture.completedFuture( 59 new VoipCallTransactionResult(VoipCallTransactionResult.RESULT_SUCCEED, 60 "EndCallTransaction: RESULT_SUCCEED")); 61 } 62 } 63