1 /* 2 * Copyright (C) 2017 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 android.telephony.ims.stub; 18 19 import android.annotation.SystemApi; 20 import android.os.RemoteException; 21 import android.telephony.ims.ImsExternalCallState; 22 import android.util.Log; 23 24 import com.android.ims.internal.IImsExternalCallStateListener; 25 import com.android.ims.internal.IImsMultiEndpoint; 26 27 import java.util.List; 28 import java.util.Objects; 29 30 /** 31 * Base implementation of ImsMultiEndpoint, which implements stub versions of the methods 32 * in the IImsMultiEndpoint AIDL. Override the methods that your implementation of 33 * ImsMultiEndpoint supports. 34 * 35 * DO NOT remove or change the existing APIs, only add new ones to this Base implementation or you 36 * will break other implementations of ImsMultiEndpoint maintained by other ImsServices. 37 * 38 * @hide 39 */ 40 @SystemApi 41 public class ImsMultiEndpointImplBase { 42 private static final String TAG = "MultiEndpointImplBase"; 43 44 private IImsExternalCallStateListener mListener; 45 private final Object mLock = new Object(); 46 private final IImsMultiEndpoint mImsMultiEndpoint = new IImsMultiEndpoint.Stub() { 47 48 @Override 49 public void setListener(IImsExternalCallStateListener listener) throws RemoteException { 50 synchronized (mLock) { 51 if (mListener != null && !mListener.asBinder().isBinderAlive()) { 52 Log.w(TAG, "setListener: discarding dead Binder"); 53 mListener = null; 54 } 55 if (mListener != null && listener != null && Objects.equals( 56 mListener.asBinder(), listener.asBinder())) { 57 return; 58 } 59 60 if (listener == null) { 61 mListener = null; 62 } else if (listener != null && mListener == null) { 63 mListener = listener; 64 } else { 65 // Warn that the listener is being replaced while active 66 Log.w(TAG, "setListener is being called when there is already an active " 67 + "listener"); 68 mListener = listener; 69 } 70 } 71 } 72 73 @Override 74 public void requestImsExternalCallStateInfo() throws RemoteException { 75 ImsMultiEndpointImplBase.this.requestImsExternalCallStateInfo(); 76 } 77 }; 78 79 /** @hide */ getIImsMultiEndpoint()80 public IImsMultiEndpoint getIImsMultiEndpoint() { 81 return mImsMultiEndpoint; 82 } 83 84 /** 85 * Notifies framework when Dialog Event Package update is received 86 * 87 * @throws RuntimeException if the connection to the framework is not available. 88 */ onImsExternalCallStateUpdate(List<ImsExternalCallState> externalCallDialogs)89 public final void onImsExternalCallStateUpdate(List<ImsExternalCallState> externalCallDialogs) { 90 Log.d(TAG, "ims external call state update triggered."); 91 IImsExternalCallStateListener listener; 92 synchronized (mLock) { 93 listener = mListener; 94 } 95 if (listener != null) { 96 try { 97 listener.onImsExternalCallStateUpdate(externalCallDialogs); 98 } catch (RemoteException e) { 99 throw new RuntimeException(e); 100 } 101 } 102 } 103 104 /** 105 * This method should be implemented by the IMS provider. Framework will trigger this to get the 106 * latest Dialog Event Package information. Should 107 */ requestImsExternalCallStateInfo()108 public void requestImsExternalCallStateInfo() { 109 Log.d(TAG, "requestImsExternalCallStateInfo() not implemented"); 110 } 111 } 112