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