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