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