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.voip; 18 19 import static com.android.server.telecom.voip.VideoStateTranslation.TransactionalVideoStateToVideoProfileState; 20 21 import android.telecom.CallException; 22 import android.telecom.VideoProfile; 23 import android.util.Log; 24 25 import com.android.server.telecom.CallsManager; 26 import com.android.server.telecom.Call; 27 28 import java.util.concurrent.CompletableFuture; 29 import java.util.concurrent.CompletionStage; 30 31 public class RequestVideoStateTransaction extends VoipCallTransaction { 32 33 private static final String TAG = RequestVideoStateTransaction.class.getSimpleName(); 34 private final Call mCall; 35 private final int mVideoProfileState; 36 RequestVideoStateTransaction(CallsManager callsManager, Call call, int transactionalVideoState)37 public RequestVideoStateTransaction(CallsManager callsManager, Call call, 38 int transactionalVideoState) { 39 super(callsManager.getLock()); 40 mCall = call; 41 mVideoProfileState = TransactionalVideoStateToVideoProfileState(transactionalVideoState); 42 } 43 44 @Override processTransaction(Void v)45 public CompletionStage<VoipCallTransactionResult> processTransaction(Void v) { 46 Log.d(TAG, "processTransaction"); 47 CompletableFuture<VoipCallTransactionResult> future = new CompletableFuture<>(); 48 49 if (isRequestingVideoTransmission(mVideoProfileState) && 50 !mCall.isVideoCallingSupportedByPhoneAccount()) { 51 future.complete(new VoipCallTransactionResult( 52 CallException.CODE_ERROR_UNKNOWN /*TODO:: define error code. b/335703584 */, 53 "Video calling is not supported by the target account")); 54 } else { 55 mCall.setVideoState(mVideoProfileState); 56 future.complete(new VoipCallTransactionResult( 57 VoipCallTransactionResult.RESULT_SUCCEED, 58 "The Video State was changed successfully")); 59 } 60 return future; 61 } 62 isRequestingVideoTransmission(int targetVideoState)63 private boolean isRequestingVideoTransmission(int targetVideoState) { 64 return targetVideoState != VideoProfile.STATE_AUDIO_ONLY; 65 } 66 }