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; 18 19 import android.os.Binder; 20 import android.os.RemoteException; 21 import android.telecom.DisconnectCause; 22 import android.telecom.Log; 23 import android.telecom.StreamingCall; 24 25 import com.android.internal.telecom.IStreamingCallAdapter; 26 27 /** 28 * Receives call commands and updates from general call streaming app and passes them through to 29 * the original voip call app. {@link android.telecom.CallStreamingService} creates an instance of 30 * this class and passes it to the general call streaming app after binding to it. This adapter can 31 * receive commands and updates until the general call streaming app is unbound. 32 */ 33 public class StreamingCallAdapter extends IStreamingCallAdapter.Stub { 34 private final static String TAG = "StreamingCallAdapter"; 35 36 private final TransactionalServiceWrapper mTransactionalServiceWrapper; 37 private final Call mCall; 38 private final String mOwnerPackageAbbreviation; 39 StreamingCallAdapter(TransactionalServiceWrapper wrapper, Call call, String ownerPackageName)40 public StreamingCallAdapter(TransactionalServiceWrapper wrapper, Call call, 41 String ownerPackageName) { 42 mTransactionalServiceWrapper = wrapper; 43 mCall = call; 44 mOwnerPackageAbbreviation = Log.getPackageAbbreviation(ownerPackageName); 45 } 46 47 @Override setStreamingState(int state)48 public void setStreamingState(int state) throws RemoteException { 49 try { 50 Log.startSession(LogUtils.Sessions.CSA_SET_STATE, mOwnerPackageAbbreviation); 51 long token = Binder.clearCallingIdentity(); 52 try { 53 Log.i(this, "setStreamingState(%d)", state); 54 switch (state) { 55 case StreamingCall.STATE_STREAMING: 56 mTransactionalServiceWrapper.onSetActive(mCall); 57 case StreamingCall.STATE_HOLDING: 58 mTransactionalServiceWrapper.onSetInactive(mCall); 59 case StreamingCall.STATE_DISCONNECTED: 60 mTransactionalServiceWrapper.onDisconnect(mCall, 61 new DisconnectCause(DisconnectCause.LOCAL)); 62 default: 63 // ignore 64 } 65 } finally { 66 Binder.restoreCallingIdentity(token); 67 } 68 } finally { 69 Log.endSession(); 70 } 71 } 72 } 73