1 /* 2 * Copyright (C) 2021 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.internal.telephony; 18 19 import android.os.RemoteException; 20 21 /** 22 * A holder for IRadio services. 23 * Use getHidl to get the HIDL IRadio service or getAidl to get the corresponding AIDL service. 24 */ 25 public abstract class RadioServiceProxy { 26 boolean mIsAidl; 27 HalVersion mHalVersion = RIL.RADIO_HAL_VERSION_UNKNOWN; 28 volatile android.hardware.radio.V1_4.IRadio mRadioProxy = null; 29 30 /** 31 * Whether RadioServiceProxy is an AIDL or HIDL implementation 32 * @return true if AIDL, false if HIDL 33 */ isAidl()34 public boolean isAidl() { 35 return mIsAidl; 36 } 37 38 /** 39 * Set IRadio as the HIDL implementation for RadioServiceProxy 40 * @param halVersion Radio HAL version 41 * @param radio IRadio implementation 42 */ setHidl(HalVersion halVersion, android.hardware.radio.V1_4.IRadio radio)43 public void setHidl(HalVersion halVersion, android.hardware.radio.V1_4.IRadio radio) { 44 mHalVersion = halVersion; 45 mRadioProxy = radio; 46 mIsAidl = false; 47 } 48 49 /** 50 * Get the HIDL implementation of RadioServiceProxy 51 * @return IRadio implementation 52 */ getHidl()53 public android.hardware.radio.V1_4.IRadio getHidl() { 54 return mRadioProxy; 55 } 56 57 /** 58 * Reset RadioServiceProxy 59 */ clear()60 public void clear() { 61 mHalVersion = RIL.RADIO_HAL_VERSION_UNKNOWN; 62 mRadioProxy = null; 63 } 64 65 /** 66 * Check whether an implementation exists for this service 67 * @return false if there is neither a HIDL nor AIDL implementation 68 */ isEmpty()69 public boolean isEmpty() { 70 return mRadioProxy == null; 71 } 72 73 /** 74 * Call responseAcknowledgement for the service 75 * @throws RemoteException 76 */ responseAcknowledgement()77 public void responseAcknowledgement() throws RemoteException { 78 if (isEmpty()) return; 79 if (!isAidl()) mRadioProxy.responseAcknowledgement(); 80 } 81 82 @Override toString()83 public String toString() { 84 return getClass().getSimpleName() + "[mHalVersion=" + mHalVersion + ']'; 85 } 86 } 87