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 import android.telephony.Rlog; 21 22 /** 23 * A holder for IRadioModem. 24 * Use getAidl to get IRadioModem and call the AIDL implementations of the HAL APIs. 25 */ 26 public class RadioModemProxy extends RadioServiceProxy { 27 private static final String TAG = "RadioModemProxy"; 28 private volatile android.hardware.radio.modem.IRadioModem mModemProxy = null; 29 30 /** 31 * Set IRadioModem as the AIDL implementation for RadioServiceProxy 32 * @param halVersion Radio HAL version 33 * @param modem IRadioModem implementation 34 * 35 * @return updated HAL version 36 */ setAidl(HalVersion halVersion, android.hardware.radio.modem.IRadioModem modem)37 public HalVersion setAidl(HalVersion halVersion, 38 android.hardware.radio.modem.IRadioModem modem) { 39 HalVersion version = halVersion; 40 try { 41 version = RIL.getServiceHalVersion(modem.getInterfaceVersion()); 42 } catch (RemoteException e) { 43 Rlog.e(TAG, "setAidl: " + e); 44 } 45 mHalVersion = version; 46 mModemProxy = modem; 47 mIsAidl = true; 48 49 Rlog.d(TAG, "AIDL initialized mHalVersion=" + mHalVersion); 50 return mHalVersion; 51 } 52 53 /** 54 * Get the AIDL implementation of RadioModemProxy 55 * @return IRadioModem implementation 56 */ getAidl()57 public android.hardware.radio.modem.IRadioModem getAidl() { 58 return mModemProxy; 59 } 60 61 /** 62 * Reset RadioModemProxy 63 */ 64 @Override clear()65 public void clear() { 66 super.clear(); 67 mModemProxy = null; 68 } 69 70 /** 71 * Check whether a RadioModem implementation exists 72 * @return true if there is neither a HIDL nor AIDL implementation 73 */ 74 @Override isEmpty()75 public boolean isEmpty() { 76 return mRadioProxy == null && mModemProxy == null; 77 } 78 79 /** 80 * Call IRadioModem#enableModem 81 * @param serial Serial number of request 82 * @param on Whether to enable or disable the modem 83 * @throws RemoteException 84 */ enableModem(int serial, boolean on)85 public void enableModem(int serial, boolean on) throws RemoteException { 86 if (isEmpty()) return; 87 if (isAidl()) { 88 mModemProxy.enableModem(serial, on); 89 } else { 90 mRadioProxy.enableModem(serial, on); 91 } 92 } 93 94 /** 95 * Call IRadioModem#getBasebandVersion 96 * @param serial Serial number of request 97 * @throws RemoteException 98 */ getBasebandVersion(int serial)99 public void getBasebandVersion(int serial) throws RemoteException { 100 if (isEmpty()) return; 101 if (isAidl()) { 102 mModemProxy.getBasebandVersion(serial); 103 } else { 104 mRadioProxy.getBasebandVersion(serial); 105 } 106 } 107 108 /** 109 * Call IRadioModem#getDeviceIdentity 110 * @param serial Serial number of request 111 * @throws RemoteException 112 */ getDeviceIdentity(int serial)113 public void getDeviceIdentity(int serial) throws RemoteException { 114 if (isEmpty()) return; 115 if (isAidl()) { 116 mModemProxy.getDeviceIdentity(serial); 117 } else { 118 mRadioProxy.getDeviceIdentity(serial); 119 } 120 } 121 122 /** 123 * Call IRadioModem#getImei 124 * 125 * @param serial Serial number of request 126 * @throws RemoteException 127 */ getImei(int serial)128 public void getImei(int serial) throws RemoteException { 129 if (isEmpty()) return; 130 if (isAidl()) { 131 mModemProxy.getImei(serial); 132 } 133 } 134 135 /** 136 * Call IRadioModem#getHardwareConfig 137 * @param serial Serial number of request 138 * @throws RemoteException 139 */ getHardwareConfig(int serial)140 public void getHardwareConfig(int serial) throws RemoteException { 141 if (isEmpty()) return; 142 if (isAidl()) { 143 mModemProxy.getHardwareConfig(serial); 144 } else { 145 mRadioProxy.getHardwareConfig(serial); 146 } 147 } 148 149 /** 150 * Call IRadioModem#getModemActivityInfo 151 * @param serial Serial number of request 152 * @throws RemoteException 153 */ getModemActivityInfo(int serial)154 public void getModemActivityInfo(int serial) throws RemoteException { 155 if (isEmpty()) return; 156 if (isAidl()) { 157 mModemProxy.getModemActivityInfo(serial); 158 } else { 159 mRadioProxy.getModemActivityInfo(serial); 160 } 161 } 162 163 /** 164 * Call IRadioModem#getModemStackStatus 165 * @param serial Serial number of request 166 * @throws RemoteException 167 */ getModemStackStatus(int serial)168 public void getModemStackStatus(int serial) throws RemoteException { 169 if (isEmpty()) return; 170 if (isAidl()) { 171 mModemProxy.getModemStackStatus(serial); 172 } else { 173 mRadioProxy.getModemStackStatus(serial); 174 } 175 } 176 177 /** 178 * Call IRadioModem#getRadioCapability 179 * @param serial Serial number of request 180 * @throws RemoteException 181 */ getRadioCapability(int serial)182 public void getRadioCapability(int serial) throws RemoteException { 183 if (isEmpty()) return; 184 if (isAidl()) { 185 mModemProxy.getRadioCapability(serial); 186 } else { 187 mRadioProxy.getRadioCapability(serial); 188 } 189 } 190 191 /** 192 * Call IRadioModem#nvReadItem 193 * @param serial Serial number of request 194 * @param itemId ID of the item to read 195 * @throws RemoteException 196 */ nvReadItem(int serial, int itemId)197 public void nvReadItem(int serial, int itemId) throws RemoteException { 198 if (isEmpty()) return; 199 if (isAidl()) { 200 mModemProxy.nvReadItem(serial, itemId); 201 } else { 202 mRadioProxy.nvReadItem(serial, itemId); 203 } 204 } 205 206 /** 207 * Call IRadioModem#nvResetConfig 208 * @param serial Serial number of request 209 * @param resetType Reset type; 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 210 * @throws RemoteException 211 */ nvResetConfig(int serial, int resetType)212 public void nvResetConfig(int serial, int resetType) throws RemoteException { 213 if (isEmpty()) return; 214 if (isAidl()) { 215 mModemProxy.nvResetConfig(serial, RILUtils.convertToHalResetNvTypeAidl(resetType)); 216 } else { 217 mRadioProxy.nvResetConfig(serial, RILUtils.convertToHalResetNvType(resetType)); 218 } 219 } 220 221 /** 222 * Call IRadioModem#nvWriteCdmaPrl 223 * @param serial Serial number of request 224 * @param prl Preferred roaming list as a byte array 225 * @throws RemoteException 226 */ nvWriteCdmaPrl(int serial, byte[] prl)227 public void nvWriteCdmaPrl(int serial, byte[] prl) throws RemoteException { 228 if (isEmpty()) return; 229 if (isAidl()) { 230 mModemProxy.nvWriteCdmaPrl(serial, prl); 231 } else { 232 mRadioProxy.nvWriteCdmaPrl(serial, RILUtils.primitiveArrayToArrayList(prl)); 233 } 234 } 235 236 /** 237 * Call IRadioModem#nvWriteItem 238 * @param serial Serial number of request 239 * @param itemId ID of the item to write 240 * @param itemValue Value to write as a String 241 * @throws RemoteException 242 */ nvWriteItem(int serial, int itemId, String itemValue)243 public void nvWriteItem(int serial, int itemId, String itemValue) throws RemoteException { 244 if (isEmpty()) return; 245 if (isAidl()) { 246 android.hardware.radio.modem.NvWriteItem item = 247 new android.hardware.radio.modem.NvWriteItem(); 248 item.itemId = itemId; 249 item.value = itemValue; 250 mModemProxy.nvWriteItem(serial, item); 251 } else { 252 android.hardware.radio.V1_0.NvWriteItem item = 253 new android.hardware.radio.V1_0.NvWriteItem(); 254 item.itemId = itemId; 255 item.value = itemValue; 256 mRadioProxy.nvWriteItem(serial, item); 257 } 258 } 259 260 /** 261 * Call IRadioModem#requestShutdown 262 * @param serial Serial number of request 263 * @throws RemoteException 264 */ requestShutdown(int serial)265 public void requestShutdown(int serial) throws RemoteException { 266 if (isEmpty()) return; 267 if (isAidl()) { 268 mModemProxy.requestShutdown(serial); 269 } else { 270 mRadioProxy.requestShutdown(serial); 271 } 272 } 273 274 /** 275 * Call IRadioModem#responseAcknowledgement 276 * @throws RemoteException 277 */ 278 @Override responseAcknowledgement()279 public void responseAcknowledgement() throws RemoteException { 280 if (isEmpty()) return; 281 if (isAidl()) { 282 mModemProxy.responseAcknowledgement(); 283 } else { 284 mRadioProxy.responseAcknowledgement(); 285 } 286 } 287 288 /** 289 * Call IRadioModem#sendDeviceState 290 * @param serial Serial number of request 291 * @param deviceStateType Device state type 292 * @param state True if enabled and false if disabled 293 * @throws RemoteException 294 */ sendDeviceState(int serial, int deviceStateType, boolean state)295 public void sendDeviceState(int serial, int deviceStateType, boolean state) 296 throws RemoteException { 297 if (isEmpty()) return; 298 if (isAidl()) { 299 mModemProxy.sendDeviceState(serial, deviceStateType, state); 300 } else { 301 mRadioProxy.sendDeviceState(serial, deviceStateType, state); 302 } 303 } 304 305 /** 306 * Call IRadioModem#setRadioCapability 307 * @param serial Serial number of request 308 * @param rc The phone radio capability defined in RadioCapability 309 * It's a input object used to transfer parameter to logic modem 310 * @throws RemoteException 311 */ setRadioCapability(int serial, RadioCapability rc)312 public void setRadioCapability(int serial, RadioCapability rc) throws RemoteException { 313 if (isEmpty()) return; 314 if (isAidl()) { 315 android.hardware.radio.modem.RadioCapability halRc = 316 new android.hardware.radio.modem.RadioCapability(); 317 halRc.session = rc.getSession(); 318 halRc.phase = rc.getPhase(); 319 halRc.raf = rc.getRadioAccessFamily(); 320 halRc.logicalModemUuid = RILUtils.convertNullToEmptyString(rc.getLogicalModemUuid()); 321 halRc.status = rc.getStatus(); 322 mModemProxy.setRadioCapability(serial, halRc); 323 } else { 324 android.hardware.radio.V1_0.RadioCapability halRc = 325 new android.hardware.radio.V1_0.RadioCapability(); 326 halRc.session = rc.getSession(); 327 halRc.phase = rc.getPhase(); 328 halRc.raf = rc.getRadioAccessFamily(); 329 halRc.logicalModemUuid = RILUtils.convertNullToEmptyString(rc.getLogicalModemUuid()); 330 halRc.status = rc.getStatus(); 331 mRadioProxy.setRadioCapability(serial, halRc); 332 } 333 } 334 335 /** 336 * Call IRadioModem#setRadioPower 337 * @param serial Serial number of request 338 * @param powerOn True to turn on radio and false to turn off 339 * @param forEmergencyCall Indicates that this request is due to emergency call 340 * No effect if powerOn is false 341 * @param preferredForEmergencyCall Whether or not the following emergency call will be sent 342 * on this modem 343 * No effect if powerOn or forEmergencyCall is false 344 * @throws RemoteException 345 */ setRadioPower(int serial, boolean powerOn, boolean forEmergencyCall, boolean preferredForEmergencyCall)346 public void setRadioPower(int serial, boolean powerOn, boolean forEmergencyCall, 347 boolean preferredForEmergencyCall) throws RemoteException { 348 if (isEmpty()) return; 349 if (isAidl()) { 350 mModemProxy.setRadioPower(serial, powerOn, forEmergencyCall, preferredForEmergencyCall); 351 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) { 352 ((android.hardware.radio.V1_6.IRadio) mRadioProxy).setRadioPower_1_6(serial, powerOn, 353 forEmergencyCall, preferredForEmergencyCall); 354 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) { 355 ((android.hardware.radio.V1_5.IRadio) mRadioProxy).setRadioPower_1_5(serial, powerOn, 356 forEmergencyCall, preferredForEmergencyCall); 357 } else { 358 mRadioProxy.setRadioPower(serial, powerOn); 359 } 360 } 361 } 362