1 /*
2  * Copyright (C) 2006 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 static com.android.internal.telephony.RILConstants.*;
20 import static com.android.internal.util.Preconditions.checkNotNull;
21 
22 import android.annotation.NonNull;
23 import android.annotation.Nullable;
24 import android.compat.annotation.UnsupportedAppUsage;
25 import android.content.Context;
26 import android.hardware.radio.V1_0.Carrier;
27 import android.hardware.radio.V1_0.CarrierRestrictions;
28 import android.hardware.radio.V1_0.CdmaBroadcastSmsConfigInfo;
29 import android.hardware.radio.V1_0.CdmaSmsAck;
30 import android.hardware.radio.V1_0.CdmaSmsMessage;
31 import android.hardware.radio.V1_0.CdmaSmsWriteArgs;
32 import android.hardware.radio.V1_0.DataProfileId;
33 import android.hardware.radio.V1_0.Dial;
34 import android.hardware.radio.V1_0.GsmBroadcastSmsConfigInfo;
35 import android.hardware.radio.V1_0.GsmSmsMessage;
36 import android.hardware.radio.V1_0.HardwareConfigModem;
37 import android.hardware.radio.V1_0.IRadio;
38 import android.hardware.radio.V1_0.IccIo;
39 import android.hardware.radio.V1_0.ImsSmsMessage;
40 import android.hardware.radio.V1_0.LceDataInfo;
41 import android.hardware.radio.V1_0.MvnoType;
42 import android.hardware.radio.V1_0.NvWriteItem;
43 import android.hardware.radio.V1_0.RadioError;
44 import android.hardware.radio.V1_0.RadioIndicationType;
45 import android.hardware.radio.V1_0.RadioResponseInfo;
46 import android.hardware.radio.V1_0.RadioResponseType;
47 import android.hardware.radio.V1_0.RadioTechnologyFamily;
48 import android.hardware.radio.V1_0.ResetNvType;
49 import android.hardware.radio.V1_0.SelectUiccSub;
50 import android.hardware.radio.V1_0.SimApdu;
51 import android.hardware.radio.V1_0.SmsWriteArgs;
52 import android.hardware.radio.V1_0.UusInfo;
53 import android.hardware.radio.V1_4.CarrierRestrictionsWithPriority;
54 import android.hardware.radio.V1_4.SimLockMultiSimPolicy;
55 import android.hardware.radio.V1_5.AccessNetwork;
56 import android.hardware.radio.V1_5.IndicationFilter;
57 import android.hardware.radio.V1_5.PersoSubstate;
58 import android.hardware.radio.V1_5.RadioAccessNetworks;
59 import android.hardware.radio.V1_6.OptionalDnn;
60 import android.hardware.radio.V1_6.OptionalOsAppId;
61 import android.hardware.radio.V1_6.OptionalSliceInfo;
62 import android.hardware.radio.V1_6.OptionalTrafficDescriptor;
63 import android.net.InetAddresses;
64 import android.net.KeepalivePacketData;
65 import android.net.LinkAddress;
66 import android.net.LinkProperties;
67 import android.os.AsyncResult;
68 import android.os.Build;
69 import android.os.Handler;
70 import android.os.HwBinder;
71 import android.os.Message;
72 import android.os.PowerManager;
73 import android.os.PowerManager.WakeLock;
74 import android.os.RemoteException;
75 import android.os.SystemClock;
76 import android.os.SystemProperties;
77 import android.os.WorkSource;
78 import android.provider.Settings;
79 import android.service.carrier.CarrierIdentifier;
80 import android.sysprop.TelephonyProperties;
81 import android.telephony.AccessNetworkConstants.AccessNetworkType;
82 import android.telephony.CarrierRestrictionRules;
83 import android.telephony.CellInfo;
84 import android.telephony.CellSignalStrengthCdma;
85 import android.telephony.CellSignalStrengthGsm;
86 import android.telephony.CellSignalStrengthLte;
87 import android.telephony.CellSignalStrengthNr;
88 import android.telephony.CellSignalStrengthTdscdma;
89 import android.telephony.CellSignalStrengthWcdma;
90 import android.telephony.ClientRequestStats;
91 import android.telephony.ImsiEncryptionInfo;
92 import android.telephony.LinkCapacityEstimate;
93 import android.telephony.ModemActivityInfo;
94 import android.telephony.NeighboringCellInfo;
95 import android.telephony.NetworkScanRequest;
96 import android.telephony.PhoneNumberUtils;
97 import android.telephony.RadioAccessFamily;
98 import android.telephony.RadioAccessSpecifier;
99 import android.telephony.ServiceState;
100 import android.telephony.SignalStrength;
101 import android.telephony.SignalThresholdInfo;
102 import android.telephony.SmsManager;
103 import android.telephony.SubscriptionManager;
104 import android.telephony.TelephonyHistogram;
105 import android.telephony.TelephonyManager;
106 import android.telephony.TelephonyManager.PrefNetworkMode;
107 import android.telephony.data.ApnSetting;
108 import android.telephony.data.DataCallResponse;
109 import android.telephony.data.DataCallResponse.HandoverFailureMode;
110 import android.telephony.data.DataProfile;
111 import android.telephony.data.DataService;
112 import android.telephony.data.NetworkSliceInfo;
113 import android.telephony.data.Qos;
114 import android.telephony.data.QosBearerSession;
115 import android.telephony.data.TrafficDescriptor;
116 import android.telephony.emergency.EmergencyNumber;
117 import android.text.TextUtils;
118 import android.util.Log;
119 import android.util.SparseArray;
120 
121 import com.android.internal.annotations.VisibleForTesting;
122 import com.android.internal.telephony.cat.ComprehensionTlv;
123 import com.android.internal.telephony.cat.ComprehensionTlvTag;
124 import com.android.internal.telephony.cdma.CdmaInformationRecords;
125 import com.android.internal.telephony.cdma.CdmaSmsBroadcastConfigInfo;
126 import com.android.internal.telephony.gsm.SmsBroadcastConfigInfo;
127 import com.android.internal.telephony.metrics.ModemRestartStats;
128 import com.android.internal.telephony.metrics.TelephonyMetrics;
129 import com.android.internal.telephony.nano.TelephonyProto.SmsSession;
130 import com.android.internal.telephony.uicc.IccCardApplicationStatus.PersoSubState;
131 import com.android.internal.telephony.uicc.IccUtils;
132 import com.android.internal.telephony.uicc.SimPhonebookRecord;
133 import com.android.internal.telephony.util.TelephonyUtils;
134 import com.android.telephony.Rlog;
135 
136 import java.io.ByteArrayInputStream;
137 import java.io.DataInputStream;
138 import java.io.FileDescriptor;
139 import java.io.IOException;
140 import java.io.PrintWriter;
141 import java.net.Inet4Address;
142 import java.net.Inet6Address;
143 import java.net.InetAddress;
144 import java.util.ArrayList;
145 import java.util.Arrays;
146 import java.util.HashSet;
147 import java.util.List;
148 import java.util.NoSuchElementException;
149 import java.util.Set;
150 import java.util.concurrent.ConcurrentHashMap;
151 import java.util.concurrent.atomic.AtomicBoolean;
152 import java.util.concurrent.atomic.AtomicLong;
153 import java.util.stream.Collectors;
154 
155 /**
156  * RIL implementation of the CommandsInterface.
157  *
158  * {@hide}
159  */
160 public class RIL extends BaseCommands implements CommandsInterface {
161     static final String RILJ_LOG_TAG = "RILJ";
162     static final String RILJ_WAKELOCK_TAG = "*telephony-radio*";
163     // Have a separate wakelock instance for Ack
164     static final String RILJ_ACK_WAKELOCK_NAME = "RILJ_ACK_WL";
165     static final boolean RILJ_LOGD = true;
166     static final boolean RILJ_LOGV = false; // STOPSHIP if true
167     static final int RIL_HISTOGRAM_BUCKET_COUNT = 5;
168 
169     /**
170      * Wake lock timeout should be longer than the longest timeout in
171      * the vendor ril.
172      */
173     private static final int DEFAULT_WAKE_LOCK_TIMEOUT_MS = 60000;
174 
175     // Wake lock default timeout associated with ack
176     private static final int DEFAULT_ACK_WAKE_LOCK_TIMEOUT_MS = 200;
177 
178     private static final int DEFAULT_BLOCKING_MESSAGE_RESPONSE_TIMEOUT_MS = 2000;
179 
180     // Variables used to differentiate ack messages from request while calling clearWakeLock()
181     public static final int INVALID_WAKELOCK = -1;
182     public static final int FOR_WAKELOCK = 0;
183     public static final int FOR_ACK_WAKELOCK = 1;
184     private final ClientWakelockTracker mClientWakelockTracker = new ClientWakelockTracker();
185 
186     /** @hide */
187     public static final HalVersion RADIO_HAL_VERSION_UNKNOWN = HalVersion.UNKNOWN;
188 
189     /** @hide */
190     public static final HalVersion RADIO_HAL_VERSION_1_0 = new HalVersion(1, 0);
191 
192     /** @hide */
193     public static final HalVersion RADIO_HAL_VERSION_1_1 = new HalVersion(1, 1);
194 
195     /** @hide */
196     public static final HalVersion RADIO_HAL_VERSION_1_2 = new HalVersion(1, 2);
197 
198     /** @hide */
199     public static final HalVersion RADIO_HAL_VERSION_1_3 = new HalVersion(1, 3);
200 
201     /** @hide */
202     public static final HalVersion RADIO_HAL_VERSION_1_4 = new HalVersion(1, 4);
203 
204     /** @hide */
205     public static final HalVersion RADIO_HAL_VERSION_1_5 = new HalVersion(1, 5);
206 
207     /** @hide */
208     public static final HalVersion RADIO_HAL_VERSION_1_6 = new HalVersion(1, 6);
209 
210     // IRadio version
211     private HalVersion mRadioVersion = RADIO_HAL_VERSION_UNKNOWN;
212 
213     private static final int INDICATION_FILTERS_ALL_V1_0 =
214             IndicationFilter.SIGNAL_STRENGTH
215             | IndicationFilter.FULL_NETWORK_STATE
216             | IndicationFilter.DATA_CALL_DORMANCY_CHANGED;
217     private static final int INDICATION_FILTERS_ALL_V1_2 =
218             INDICATION_FILTERS_ALL_V1_0
219             | IndicationFilter.LINK_CAPACITY_ESTIMATE
220             | IndicationFilter.PHYSICAL_CHANNEL_CONFIG;
221     private static final  int INDICATION_FILTERS_ALL_V1_5 =
222             INDICATION_FILTERS_ALL_V1_2
223             | IndicationFilter.REGISTRATION_FAILURE
224             | IndicationFilter.BARRING_INFO;
225 
226     //***** Instance Variables
227 
228     @UnsupportedAppUsage
229     @VisibleForTesting
230     public final WakeLock mWakeLock;           // Wake lock associated with request/response
231     @VisibleForTesting
232     public final WakeLock mAckWakeLock;        // Wake lock associated with ack sent
233     final int mWakeLockTimeout;         // Timeout associated with request/response
234     final int mAckWakeLockTimeout;      // Timeout associated with ack sent
235     // The number of wakelock requests currently active.  Don't release the lock
236     // until dec'd to 0
237     int mWakeLockCount;
238 
239     // Variables used to identify releasing of WL on wakelock timeouts
240     volatile int mWlSequenceNum = 0;
241     volatile int mAckWlSequenceNum = 0;
242 
243     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
244     SparseArray<RILRequest> mRequestList = new SparseArray<RILRequest>();
245     static SparseArray<TelephonyHistogram> mRilTimeHistograms = new
246             SparseArray<TelephonyHistogram>();
247 
248     Object[] mLastNITZTimeInfo;
249 
250     int mLastRadioPowerResult = RadioError.NONE;
251 
252     // When we are testing emergency calls using ril.test.emergencynumber, this will trigger test
253     // ECbM when the call is ended.
254     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
255     AtomicBoolean mTestingEmergencyCall = new AtomicBoolean(false);
256 
257     final Integer mPhoneId;
258 
259     private static final String PROPERTY_IS_VONR_ENABLED = "persist.radio.is_vonr_enabled_";
260 
261     /**
262      * A set that records if radio service is disabled in hal for
263      * a specific phone id slot to avoid further getService request.
264      */
265     Set<Integer> mDisabledRadioServices = new HashSet();
266 
267     /* default work source which will blame phone process */
268     private WorkSource mRILDefaultWorkSource;
269 
270     /* Worksource containing all applications causing wakelock to be held */
271     private WorkSource mActiveWakelockWorkSource;
272 
273     /** Telephony metrics instance for logging metrics event */
274     private TelephonyMetrics mMetrics = TelephonyMetrics.getInstance();
275     /** Radio bug detector instance */
276     private RadioBugDetector mRadioBugDetector = null;
277 
278     boolean mIsCellularSupported;
279     RadioResponse mRadioResponse;
280     RadioIndication mRadioIndication;
281     volatile IRadio mRadioProxy = null;
282     final AtomicLong mRadioProxyCookie = new AtomicLong(0);
283     final RadioProxyDeathRecipient mRadioProxyDeathRecipient;
284     final RilHandler mRilHandler;
285 
286     // Thread-safe HashMap to map from RIL_REQUEST_XXX constant to HalVersion.
287     // This is for Radio HAL Fallback Compatibility feature. When a RIL request
288     // is received, the HAL method from the mapping HalVersion here (if present),
289     // instead of the latest HalVersion, will be invoked.
290     private ConcurrentHashMap<Integer, HalVersion> mCompatOverrides =
291             new ConcurrentHashMap<>();
292 
293     //***** Events
294     static final int EVENT_WAKE_LOCK_TIMEOUT    = 2;
295     static final int EVENT_ACK_WAKE_LOCK_TIMEOUT    = 4;
296     static final int EVENT_BLOCKING_RESPONSE_TIMEOUT = 5;
297     static final int EVENT_RADIO_PROXY_DEAD     = 6;
298 
299     //***** Constants
300 
301     static final String[] HIDL_SERVICE_NAME = {"slot1", "slot2", "slot3"};
302 
303     static final int IRADIO_GET_SERVICE_DELAY_MILLIS = 4 * 1000;
304 
305     static final String EMPTY_ALPHA_LONG = "";
306     static final String EMPTY_ALPHA_SHORT = "";
307 
getTelephonyRILTimingHistograms()308     public static List<TelephonyHistogram> getTelephonyRILTimingHistograms() {
309         List<TelephonyHistogram> list;
310         synchronized (mRilTimeHistograms) {
311             list = new ArrayList<>(mRilTimeHistograms.size());
312             for (int i = 0; i < mRilTimeHistograms.size(); i++) {
313                 TelephonyHistogram entry = new TelephonyHistogram(mRilTimeHistograms.valueAt(i));
314                 list.add(entry);
315             }
316         }
317         return list;
318     }
319 
320     /** The handler used to handle the internal event of RIL. */
321     @VisibleForTesting
322     public class RilHandler extends Handler {
323 
324         //***** Handler implementation
325         @Override
handleMessage(Message msg)326         public void handleMessage(Message msg) {
327             RILRequest rr;
328 
329             switch (msg.what) {
330                 case EVENT_WAKE_LOCK_TIMEOUT:
331                     // Haven't heard back from the last request.  Assume we're
332                     // not getting a response and  release the wake lock.
333 
334                     // The timer of WAKE_LOCK_TIMEOUT is reset with each
335                     // new send request. So when WAKE_LOCK_TIMEOUT occurs
336                     // all requests in mRequestList already waited at
337                     // least DEFAULT_WAKE_LOCK_TIMEOUT_MS but no response.
338                     //
339                     // Note: Keep mRequestList so that delayed response
340                     // can still be handled when response finally comes.
341 
342                     synchronized (mRequestList) {
343                         if (msg.arg1 == mWlSequenceNum && clearWakeLock(FOR_WAKELOCK)) {
344                             if (mRadioBugDetector != null) {
345                                 mRadioBugDetector.processWakelockTimeout();
346                             }
347                             if (RILJ_LOGD) {
348                                 int count = mRequestList.size();
349                                 Rlog.d(RILJ_LOG_TAG, "WAKE_LOCK_TIMEOUT " +
350                                         " mRequestList=" + count);
351                                 for (int i = 0; i < count; i++) {
352                                     rr = mRequestList.valueAt(i);
353                                     Rlog.d(RILJ_LOG_TAG, i + ": [" + rr.mSerial + "] "
354                                             + requestToString(rr.mRequest));
355                                 }
356                             }
357                         }
358                     }
359                     break;
360 
361                 case EVENT_ACK_WAKE_LOCK_TIMEOUT:
362                     if (msg.arg1 == mAckWlSequenceNum && clearWakeLock(FOR_ACK_WAKELOCK)) {
363                         if (RILJ_LOGV) {
364                             Rlog.d(RILJ_LOG_TAG, "ACK_WAKE_LOCK_TIMEOUT");
365                         }
366                     }
367                     break;
368 
369                 case EVENT_BLOCKING_RESPONSE_TIMEOUT:
370                     int serial = msg.arg1;
371                     rr = findAndRemoveRequestFromList(serial);
372                     // If the request has already been processed, do nothing
373                     if(rr == null) {
374                         break;
375                     }
376 
377                     //build a response if expected
378                     if (rr.mResult != null) {
379                         Object timeoutResponse = getResponseForTimedOutRILRequest(rr);
380                         AsyncResult.forMessage( rr.mResult, timeoutResponse, null);
381                         rr.mResult.sendToTarget();
382                         mMetrics.writeOnRilTimeoutResponse(mPhoneId, rr.mSerial, rr.mRequest);
383                     }
384 
385                     decrementWakeLock(rr);
386                     rr.release();
387                     break;
388 
389                 case EVENT_RADIO_PROXY_DEAD:
390                     riljLog("handleMessage: EVENT_RADIO_PROXY_DEAD cookie = " + msg.obj +
391                             " mRadioProxyCookie = " + mRadioProxyCookie.get());
392                     if ((long) msg.obj == mRadioProxyCookie.get()) {
393                         resetProxyAndRequestList();
394                     }
395                     break;
396             }
397         }
398     }
399 
400     /** Return RadioBugDetector instance for testing. */
401     @VisibleForTesting
getRadioBugDetector()402     public RadioBugDetector getRadioBugDetector() {
403         if (mRadioBugDetector == null) {
404             mRadioBugDetector = new RadioBugDetector(mContext, mPhoneId);
405         }
406         return mRadioBugDetector;
407     }
408 
409     /**
410      * In order to prevent calls to Telephony from waiting indefinitely
411      * low-latency blocking calls will eventually time out. In the event of
412      * a timeout, this function generates a response that is returned to the
413      * higher layers to unblock the call. This is in lieu of a meaningful
414      * response.
415      * @param rr The RIL Request that has timed out.
416      * @return A default object, such as the one generated by a normal response
417      * that is returned to the higher layers.
418      **/
419     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
getResponseForTimedOutRILRequest(RILRequest rr)420     private static Object getResponseForTimedOutRILRequest(RILRequest rr) {
421         if (rr == null ) return null;
422 
423         Object timeoutResponse = null;
424         switch(rr.mRequest) {
425             case RIL_REQUEST_GET_ACTIVITY_INFO:
426                 timeoutResponse = new ModemActivityInfo(
427                         0, 0, 0, new int [ModemActivityInfo.getNumTxPowerLevels()], 0);
428                 break;
429         };
430         return timeoutResponse;
431     }
432 
433     final class RadioProxyDeathRecipient implements HwBinder.DeathRecipient {
434         @Override
serviceDied(long cookie)435         public void serviceDied(long cookie) {
436             // Deal with service going away
437             riljLog("serviceDied");
438             mRilHandler.sendMessage(mRilHandler.obtainMessage(EVENT_RADIO_PROXY_DEAD, cookie));
439         }
440     }
441 
resetProxyAndRequestList()442     private synchronized void resetProxyAndRequestList() {
443         mRadioProxy = null;
444 
445         // increment the cookie so that death notification can be ignored
446         mRadioProxyCookie.incrementAndGet();
447 
448         setRadioState(TelephonyManager.RADIO_POWER_UNAVAILABLE, true /* forceNotifyRegistrants */);
449 
450         RILRequest.resetSerial();
451         // Clear request list on close
452         clearRequestList(RADIO_NOT_AVAILABLE, false);
453 
454         getRadioProxy(null);
455     }
456 
457     /** Set a radio HAL fallback compatibility override. */
458     @VisibleForTesting
setCompatVersion(int rilRequest, @NonNull HalVersion halVersion)459     public void setCompatVersion(int rilRequest, @NonNull HalVersion halVersion) {
460         HalVersion oldVersion = getCompatVersion(rilRequest);
461         // Do not allow to set same or greater verions
462         if (oldVersion != null && halVersion.greaterOrEqual(oldVersion)) {
463             riljLoge("setCompatVersion with equal or greater one, ignored, halVerion=" + halVersion
464                     + ", oldVerion=" + oldVersion);
465             return;
466         }
467         mCompatOverrides.put(rilRequest, halVersion);
468     }
469 
470     /** Get a radio HAL fallback compatibility override, or null if not exist. */
471     @VisibleForTesting
getCompatVersion(int rilRequest)472     public @Nullable HalVersion getCompatVersion(int rilRequest) {
473         return mCompatOverrides.getOrDefault(rilRequest, null);
474     }
475 
476     /** Returns a {@link IRadio} instance or null if the service is not available. */
477     @VisibleForTesting
getRadioProxy(Message result)478     public synchronized IRadio getRadioProxy(Message result) {
479         if (!SubscriptionManager.isValidPhoneId(mPhoneId)) return null;
480         if (!mIsCellularSupported) {
481             if (RILJ_LOGV) riljLog("getRadioProxy: Not calling getService(): wifi-only");
482             if (result != null) {
483                 AsyncResult.forMessage(result, null,
484                         CommandException.fromRilErrno(RADIO_NOT_AVAILABLE));
485                 result.sendToTarget();
486             }
487             return null;
488         }
489 
490         if (mRadioProxy != null) {
491             return mRadioProxy;
492         }
493 
494         try {
495             if (mDisabledRadioServices.contains(mPhoneId)) {
496                 riljLoge("getRadioProxy: mRadioProxy for " + HIDL_SERVICE_NAME[mPhoneId]
497                         + " is disabled");
498             } else {
499                 try {
500                     mRadioProxy = android.hardware.radio.V1_6.IRadio.getService(
501                             HIDL_SERVICE_NAME[mPhoneId], true);
502                     mRadioVersion = RADIO_HAL_VERSION_1_6;
503                 } catch (NoSuchElementException e) {
504                 }
505 
506                 if (mRadioProxy == null) {
507                     try {
508                         mRadioProxy = android.hardware.radio.V1_5.IRadio.getService(
509                                 HIDL_SERVICE_NAME[mPhoneId], true);
510                         mRadioVersion = RADIO_HAL_VERSION_1_5;
511                     } catch (NoSuchElementException e) {
512                     }
513                 }
514 
515                 if (mRadioProxy == null) {
516                     try {
517                         mRadioProxy = android.hardware.radio.V1_4.IRadio.getService(
518                                 HIDL_SERVICE_NAME[mPhoneId], true);
519                         mRadioVersion = RADIO_HAL_VERSION_1_4;
520                     } catch (NoSuchElementException e) {
521                     }
522                 }
523 
524                 if (mRadioProxy == null) {
525                     try {
526                         mRadioProxy = android.hardware.radio.V1_3.IRadio.getService(
527                                 HIDL_SERVICE_NAME[mPhoneId], true);
528                         mRadioVersion = RADIO_HAL_VERSION_1_3;
529                     } catch (NoSuchElementException e) {
530                     }
531                 }
532 
533                 if (mRadioProxy == null) {
534                     try {
535                         mRadioProxy = android.hardware.radio.V1_2.IRadio.getService(
536                                 HIDL_SERVICE_NAME[mPhoneId], true);
537                         mRadioVersion = RADIO_HAL_VERSION_1_2;
538                     } catch (NoSuchElementException e) {
539                     }
540                 }
541 
542                 if (mRadioProxy == null) {
543                     try {
544                         mRadioProxy = android.hardware.radio.V1_1.IRadio.getService(
545                                 HIDL_SERVICE_NAME[mPhoneId], true);
546                         mRadioVersion = RADIO_HAL_VERSION_1_1;
547                     } catch (NoSuchElementException e) {
548                     }
549                 }
550 
551                 if (mRadioProxy == null) {
552                     try {
553                         mRadioProxy = android.hardware.radio.V1_0.IRadio.getService(
554                                 HIDL_SERVICE_NAME[mPhoneId], true);
555                         mRadioVersion = RADIO_HAL_VERSION_1_0;
556                     } catch (NoSuchElementException e) {
557                     }
558                 }
559 
560                 if (mRadioProxy != null) {
561                     mRadioProxy.linkToDeath(mRadioProxyDeathRecipient,
562                             mRadioProxyCookie.incrementAndGet());
563                     mRadioProxy.setResponseFunctions(mRadioResponse, mRadioIndication);
564                 } else {
565                     mDisabledRadioServices.add(mPhoneId);
566                     riljLoge("getRadioProxy: mRadioProxy for "
567                             + HIDL_SERVICE_NAME[mPhoneId] + " is disabled");
568                 }
569             }
570         } catch (RemoteException e) {
571             mRadioProxy = null;
572             riljLoge("RadioProxy getService/setResponseFunctions: " + e);
573         }
574 
575         if (mRadioProxy == null) {
576             // getService() is a blocking call, so this should never happen
577             riljLoge("getRadioProxy: mRadioProxy == null");
578             if (result != null) {
579                 AsyncResult.forMessage(result, null,
580                         CommandException.fromRilErrno(RADIO_NOT_AVAILABLE));
581                 result.sendToTarget();
582             }
583         }
584 
585         return mRadioProxy;
586     }
587 
588     @Override
onSlotActiveStatusChange(boolean active)589     public synchronized void onSlotActiveStatusChange(boolean active) {
590         if (active) {
591             // Try to connect to RIL services and set response functions.
592             getRadioProxy(null);
593         } else {
594             resetProxyAndRequestList();
595         }
596     }
597 
598     //***** Constructors
599 
600     @UnsupportedAppUsage
RIL(Context context, int allowedNetworkTypes, int cdmaSubscription)601     public RIL(Context context, int allowedNetworkTypes, int cdmaSubscription) {
602         this(context, allowedNetworkTypes, cdmaSubscription, null);
603     }
604 
605     @UnsupportedAppUsage
RIL(Context context, int allowedNetworkTypes, int cdmaSubscription, Integer instanceId)606     public RIL(Context context, int allowedNetworkTypes,
607             int cdmaSubscription, Integer instanceId) {
608         super(context);
609         if (RILJ_LOGD) {
610             riljLog("RIL: init allowedNetworkTypes=" + allowedNetworkTypes
611                     + " cdmaSubscription=" + cdmaSubscription + ")");
612         }
613 
614         mContext = context;
615         mCdmaSubscription  = cdmaSubscription;
616         mAllowedNetworkTypesBitmask = allowedNetworkTypes;
617         mPhoneType = RILConstants.NO_PHONE;
618         mPhoneId = instanceId == null ? 0 : instanceId;
619         if (isRadioBugDetectionEnabled()) {
620             mRadioBugDetector = new RadioBugDetector(context, mPhoneId);
621         }
622 
623         TelephonyManager tm = (TelephonyManager) context.getSystemService(
624                 Context.TELEPHONY_SERVICE);
625         mIsCellularSupported = tm.isVoiceCapable() || tm.isSmsCapable() || tm.isDataCapable();
626 
627         mRadioResponse = new RadioResponse(this);
628         mRadioIndication = new RadioIndication(this);
629         mRilHandler = new RilHandler();
630         mRadioProxyDeathRecipient = new RadioProxyDeathRecipient();
631 
632         PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
633         mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, RILJ_WAKELOCK_TAG);
634         mWakeLock.setReferenceCounted(false);
635         mAckWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, RILJ_ACK_WAKELOCK_NAME);
636         mAckWakeLock.setReferenceCounted(false);
637         mWakeLockTimeout = TelephonyProperties.wake_lock_timeout()
638                 .orElse(DEFAULT_WAKE_LOCK_TIMEOUT_MS);
639         mAckWakeLockTimeout = TelephonyProperties.wake_lock_timeout()
640                 .orElse(DEFAULT_ACK_WAKE_LOCK_TIMEOUT_MS);
641         mWakeLockCount = 0;
642         mRILDefaultWorkSource = new WorkSource(context.getApplicationInfo().uid,
643                 context.getPackageName());
644         mActiveWakelockWorkSource = new WorkSource();
645 
646         TelephonyDevController tdc = TelephonyDevController.getInstance();
647         tdc.registerRIL(this);
648 
649         // set radio callback; needed to set RadioIndication callback (should be done after
650         // wakelock stuff is initialized above as callbacks are received on separate binder threads)
651         getRadioProxy(null);
652 
653         if (RILJ_LOGD) {
654             riljLog("Radio HAL version: " + mRadioVersion);
655         }
656     }
657 
isRadioBugDetectionEnabled()658     private boolean isRadioBugDetectionEnabled() {
659         return Settings.Global.getInt(
660                 mContext.getContentResolver(),
661                 Settings.Global.ENABLE_RADIO_BUG_DETECTION,
662                 1) != 0;
663     }
664 
665     @Override
setOnNITZTime(Handler h, int what, Object obj)666     public void setOnNITZTime(Handler h, int what, Object obj) {
667         super.setOnNITZTime(h, what, obj);
668 
669         // Send the last NITZ time if we have it
670         if (mLastNITZTimeInfo != null) {
671             mNITZTimeRegistrant
672                 .notifyRegistrant(
673                     new AsyncResult (null, mLastNITZTimeInfo, null));
674         }
675     }
676 
addRequest(RILRequest rr)677     private void addRequest(RILRequest rr) {
678         acquireWakeLock(rr, FOR_WAKELOCK);
679         synchronized (mRequestList) {
680             rr.mStartTimeMs = SystemClock.elapsedRealtime();
681             mRequestList.append(rr.mSerial, rr);
682         }
683     }
684 
obtainRequest(int request, Message result, WorkSource workSource)685     private RILRequest obtainRequest(int request, Message result, WorkSource workSource) {
686         RILRequest rr = RILRequest.obtain(request, result, workSource);
687         addRequest(rr);
688         return rr;
689     }
690 
obtainRequest(int request, Message result, WorkSource workSource, Object... args)691     private RILRequest obtainRequest(int request, Message result, WorkSource workSource,
692             Object... args) {
693         RILRequest rr = RILRequest.obtain(request, result, workSource, args);
694         addRequest(rr);
695         return rr;
696     }
697 
handleRadioProxyExceptionForRR(RILRequest rr, String caller, Exception e)698     private void handleRadioProxyExceptionForRR(RILRequest rr, String caller, Exception e) {
699         riljLoge(caller + ": " + e);
700         resetProxyAndRequestList();
701     }
702 
convertNullToEmptyString(String string)703     private static String convertNullToEmptyString(String string) {
704         return string != null ? string : "";
705     }
706 
707     @Override
getIccCardStatus(Message result)708     public void getIccCardStatus(Message result) {
709         IRadio radioProxy = getRadioProxy(result);
710         if (radioProxy != null) {
711             RILRequest rr = obtainRequest(RIL_REQUEST_GET_SIM_STATUS, result,
712                     mRILDefaultWorkSource);
713 
714             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
715 
716             try {
717                 radioProxy.getIccCardStatus(rr.mSerial);
718             } catch (RemoteException | RuntimeException e) {
719                 handleRadioProxyExceptionForRR(rr, "getIccCardStatus", e);
720             }
721         }
722     }
723 
724     @Override
getIccSlotsStatus(Message result)725     public void getIccSlotsStatus(Message result) {
726         if (result != null) {
727             AsyncResult.forMessage(result, null,
728                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
729             result.sendToTarget();
730         }
731     }
732 
733     @Override
setLogicalToPhysicalSlotMapping(int[] physicalSlots, Message result)734     public void setLogicalToPhysicalSlotMapping(int[] physicalSlots, Message result) {
735         if (result != null) {
736             AsyncResult.forMessage(result, null,
737                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
738             result.sendToTarget();
739         }
740     }
741 
742     @Override
supplyIccPin(String pin, Message result)743     public void supplyIccPin(String pin, Message result) {
744         supplyIccPinForApp(pin, null, result);
745     }
746 
747     @Override
supplyIccPinForApp(String pin, String aid, Message result)748     public void supplyIccPinForApp(String pin, String aid, Message result) {
749         IRadio radioProxy = getRadioProxy(result);
750         if (radioProxy != null) {
751             RILRequest rr = obtainRequest(RIL_REQUEST_ENTER_SIM_PIN, result,
752                     mRILDefaultWorkSource);
753 
754             if (RILJ_LOGD) {
755                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
756                         + " aid = " + aid);
757             }
758 
759             try {
760                 radioProxy.supplyIccPinForApp(rr.mSerial,
761                         convertNullToEmptyString(pin),
762                         convertNullToEmptyString(aid));
763             } catch (RemoteException | RuntimeException e) {
764                 handleRadioProxyExceptionForRR(rr, "supplyIccPinForApp", e);
765             }
766         }
767     }
768 
769     @Override
supplyIccPuk(String puk, String newPin, Message result)770     public void supplyIccPuk(String puk, String newPin, Message result) {
771         supplyIccPukForApp(puk, newPin, null, result);
772     }
773 
774     @Override
supplyIccPukForApp(String puk, String newPin, String aid, Message result)775     public void supplyIccPukForApp(String puk, String newPin, String aid, Message result) {
776         IRadio radioProxy = getRadioProxy(result);
777         if (radioProxy != null) {
778             RILRequest rr = obtainRequest(RIL_REQUEST_ENTER_SIM_PUK, result,
779                     mRILDefaultWorkSource);
780 
781             String pukStr = convertNullToEmptyString(puk);
782             if (RILJ_LOGD) {
783                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
784                         + " isPukEmpty = " + pukStr.isEmpty()
785                         + " aid = " + aid);
786             }
787 
788             try {
789                 radioProxy.supplyIccPukForApp(rr.mSerial,
790                         pukStr,
791                         convertNullToEmptyString(newPin),
792                         convertNullToEmptyString(aid));
793             } catch (RemoteException | RuntimeException e) {
794                 handleRadioProxyExceptionForRR(rr, "supplyIccPukForApp", e);
795             }
796         }
797     }
798 
799     @Override
supplyIccPin2(String pin, Message result)800     public void supplyIccPin2(String pin, Message result) {
801         supplyIccPin2ForApp(pin, null, result);
802     }
803 
804     @Override
supplyIccPin2ForApp(String pin, String aid, Message result)805     public void supplyIccPin2ForApp(String pin, String aid, Message result) {
806         IRadio radioProxy = getRadioProxy(result);
807         if (radioProxy != null) {
808             RILRequest rr = obtainRequest(RIL_REQUEST_ENTER_SIM_PIN2, result,
809                     mRILDefaultWorkSource);
810 
811             if (RILJ_LOGD) {
812                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
813                         + " aid = " + aid);
814             }
815 
816             try {
817                 radioProxy.supplyIccPin2ForApp(rr.mSerial,
818                         convertNullToEmptyString(pin),
819                         convertNullToEmptyString(aid));
820             } catch (RemoteException | RuntimeException e) {
821                 handleRadioProxyExceptionForRR(rr, "supplyIccPin2ForApp", e);
822             }
823         }
824     }
825 
826     @Override
supplyIccPuk2(String puk2, String newPin2, Message result)827     public void supplyIccPuk2(String puk2, String newPin2, Message result) {
828         supplyIccPuk2ForApp(puk2, newPin2, null, result);
829     }
830 
831     @Override
supplyIccPuk2ForApp(String puk, String newPin2, String aid, Message result)832     public void supplyIccPuk2ForApp(String puk, String newPin2, String aid, Message result) {
833         IRadio radioProxy = getRadioProxy(result);
834         if (radioProxy != null) {
835             RILRequest rr = obtainRequest(RIL_REQUEST_ENTER_SIM_PUK2, result,
836                     mRILDefaultWorkSource);
837 
838             if (RILJ_LOGD) {
839                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
840                         + " aid = " + aid);
841             }
842 
843             try {
844                 radioProxy.supplyIccPuk2ForApp(rr.mSerial,
845                         convertNullToEmptyString(puk),
846                         convertNullToEmptyString(newPin2),
847                         convertNullToEmptyString(aid));
848             } catch (RemoteException | RuntimeException e) {
849                 handleRadioProxyExceptionForRR(rr, "supplyIccPuk2ForApp", e);
850             }
851         }
852     }
853 
854     @Override
changeIccPin(String oldPin, String newPin, Message result)855     public void changeIccPin(String oldPin, String newPin, Message result) {
856         changeIccPinForApp(oldPin, newPin, null, result);
857     }
858 
859     @Override
changeIccPinForApp(String oldPin, String newPin, String aid, Message result)860     public void changeIccPinForApp(String oldPin, String newPin, String aid, Message result) {
861         IRadio radioProxy = getRadioProxy(result);
862         if (radioProxy != null) {
863             RILRequest rr = obtainRequest(RIL_REQUEST_CHANGE_SIM_PIN, result,
864                     mRILDefaultWorkSource);
865 
866             if (RILJ_LOGD) {
867                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " oldPin = "
868                         + oldPin + " newPin = " + newPin + " aid = " + aid);
869             }
870 
871             try {
872                 radioProxy.changeIccPinForApp(rr.mSerial,
873                         convertNullToEmptyString(oldPin),
874                         convertNullToEmptyString(newPin),
875                         convertNullToEmptyString(aid));
876             } catch (RemoteException | RuntimeException e) {
877                 handleRadioProxyExceptionForRR(rr, "changeIccPinForApp", e);
878             }
879         }
880     }
881 
882     @Override
changeIccPin2(String oldPin2, String newPin2, Message result)883     public void changeIccPin2(String oldPin2, String newPin2, Message result) {
884         changeIccPin2ForApp(oldPin2, newPin2, null, result);
885     }
886 
887     @Override
changeIccPin2ForApp(String oldPin2, String newPin2, String aid, Message result)888     public void changeIccPin2ForApp(String oldPin2, String newPin2, String aid, Message result) {
889         IRadio radioProxy = getRadioProxy(result);
890         if (radioProxy != null) {
891             RILRequest rr = obtainRequest(RIL_REQUEST_CHANGE_SIM_PIN2, result,
892                     mRILDefaultWorkSource);
893 
894             if (RILJ_LOGD) {
895                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " oldPin = "
896                         + oldPin2 + " newPin = " + newPin2 + " aid = " + aid);
897             }
898 
899             try {
900                 radioProxy.changeIccPin2ForApp(rr.mSerial,
901                         convertNullToEmptyString(oldPin2),
902                         convertNullToEmptyString(newPin2),
903                         convertNullToEmptyString(aid));
904             } catch (RemoteException | RuntimeException e) {
905                 handleRadioProxyExceptionForRR(rr, "changeIccPin2ForApp", e);
906             }
907         }
908     }
909 
910     @Override
supplyNetworkDepersonalization(String netpin, Message result)911     public void supplyNetworkDepersonalization(String netpin, Message result) {
912         IRadio radioProxy = getRadioProxy(result);
913         if (radioProxy != null) {
914             RILRequest rr = obtainRequest(RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION, result,
915                     mRILDefaultWorkSource);
916 
917             if (RILJ_LOGD) {
918                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " netpin = "
919                         + netpin);
920             }
921 
922             try {
923                 radioProxy.supplyNetworkDepersonalization(rr.mSerial,
924                         convertNullToEmptyString(netpin));
925             } catch (RemoteException | RuntimeException e) {
926                 handleRadioProxyExceptionForRR(rr, "supplyNetworkDepersonalization", e);
927             }
928         }
929     }
930 
931     @Override
supplySimDepersonalization(PersoSubState persoType, String controlKey, Message result)932     public void supplySimDepersonalization(PersoSubState persoType,
933             String controlKey, Message result) {
934         IRadio radioProxy = getRadioProxy(result);
935         // IRadio V1.5
936         if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
937             android.hardware.radio.V1_5.IRadio radioProxy15 =
938                 (android.hardware.radio.V1_5.IRadio) radioProxy;
939             if (radioProxy15 != null) {
940                 RILRequest rr = obtainRequest(RIL_REQUEST_ENTER_SIM_DEPERSONALIZATION, result,
941                         mRILDefaultWorkSource);
942                 if (RILJ_LOGD) {
943                     riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " controlKey = "
944                         + controlKey + " persoType" + persoType);
945                 }
946                 try {
947                     radioProxy15.supplySimDepersonalization(rr.mSerial,
948                             convertPersoTypeToHalPersoType(persoType),
949                             convertNullToEmptyString(controlKey));
950                 } catch (RemoteException | RuntimeException e) {
951                     handleRadioProxyExceptionForRR(rr, "supplySimDepersonalization", e);
952                 }
953             }
954         } else {
955             if (result != null) {
956                 AsyncResult.forMessage(result, null,
957                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
958                 result.sendToTarget();
959             }
960         }
961     }
962 
convertPersoTypeToHalPersoType(PersoSubState persoType)963     private static int convertPersoTypeToHalPersoType(PersoSubState persoType) {
964 
965         switch(persoType) {
966 
967             case PERSOSUBSTATE_IN_PROGRESS:
968                 return PersoSubstate.IN_PROGRESS;
969             case  PERSOSUBSTATE_READY:
970                 return PersoSubstate.READY;
971             case PERSOSUBSTATE_SIM_NETWORK:
972                 return PersoSubstate.SIM_NETWORK;
973             case PERSOSUBSTATE_SIM_NETWORK_SUBSET:
974                 return PersoSubstate.SIM_NETWORK_SUBSET;
975             case PERSOSUBSTATE_SIM_CORPORATE:
976                 return PersoSubstate.SIM_CORPORATE;
977             case PERSOSUBSTATE_SIM_SERVICE_PROVIDER:
978                 return PersoSubstate.SIM_SERVICE_PROVIDER;
979             case PERSOSUBSTATE_SIM_SIM:
980                 return PersoSubstate.SIM_SIM;
981             case PERSOSUBSTATE_SIM_NETWORK_PUK:
982                 return PersoSubstate.SIM_NETWORK_PUK;
983             case PERSOSUBSTATE_SIM_NETWORK_SUBSET_PUK:
984                 return PersoSubstate.SIM_NETWORK_SUBSET_PUK;
985             case PERSOSUBSTATE_SIM_CORPORATE_PUK:
986                 return PersoSubstate.SIM_CORPORATE_PUK;
987             case PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK:
988                 return PersoSubstate.SIM_SERVICE_PROVIDER_PUK;
989             case PERSOSUBSTATE_SIM_SIM_PUK:
990                 return PersoSubstate.SIM_SIM_PUK;
991             case PERSOSUBSTATE_RUIM_NETWORK1:
992                 return PersoSubstate.RUIM_NETWORK1;
993             case PERSOSUBSTATE_RUIM_NETWORK2:
994                 return PersoSubstate.RUIM_NETWORK2;
995             case PERSOSUBSTATE_RUIM_HRPD:
996                 return PersoSubstate.RUIM_HRPD;
997             case PERSOSUBSTATE_RUIM_CORPORATE:
998                 return PersoSubstate.RUIM_CORPORATE;
999             case PERSOSUBSTATE_RUIM_SERVICE_PROVIDER:
1000                 return PersoSubstate.RUIM_SERVICE_PROVIDER;
1001             case PERSOSUBSTATE_RUIM_RUIM:
1002                 return PersoSubstate.RUIM_RUIM;
1003             case PERSOSUBSTATE_RUIM_NETWORK1_PUK:
1004                 return PersoSubstate.RUIM_NETWORK1_PUK;
1005             case PERSOSUBSTATE_RUIM_NETWORK2_PUK:
1006                 return PersoSubstate.RUIM_NETWORK2_PUK;
1007             case PERSOSUBSTATE_RUIM_HRPD_PUK:
1008                 return PersoSubstate.RUIM_HRPD_PUK;
1009             case PERSOSUBSTATE_RUIM_CORPORATE_PUK:
1010                 return PersoSubstate.RUIM_CORPORATE_PUK;
1011             case PERSOSUBSTATE_RUIM_SERVICE_PROVIDER_PUK:
1012                 return PersoSubstate.RUIM_SERVICE_PROVIDER_PUK;
1013             case PERSOSUBSTATE_RUIM_RUIM_PUK:
1014                 return PersoSubstate.RUIM_RUIM_PUK;
1015             case PERSOSUBSTATE_SIM_SPN:
1016                 return PersoSubstate.SIM_SPN;
1017             case PERSOSUBSTATE_SIM_SPN_PUK:
1018                 return PersoSubstate.SIM_SPN_PUK;
1019             case PERSOSUBSTATE_SIM_SP_EHPLMN:
1020                 return PersoSubstate.SIM_SP_EHPLMN;
1021             case PERSOSUBSTATE_SIM_SP_EHPLMN_PUK:
1022                 return PersoSubstate.SIM_SP_EHPLMN_PUK;
1023             case PERSOSUBSTATE_SIM_ICCID:
1024                 return PersoSubstate.SIM_ICCID;
1025             case PERSOSUBSTATE_SIM_ICCID_PUK:
1026                 return PersoSubstate.SIM_ICCID_PUK;
1027             case PERSOSUBSTATE_SIM_IMPI:
1028                 return PersoSubstate.SIM_IMPI;
1029             case PERSOSUBSTATE_SIM_IMPI_PUK:
1030                 return PersoSubstate.SIM_IMPI_PUK;
1031             case PERSOSUBSTATE_SIM_NS_SP:
1032                 return PersoSubstate.SIM_NS_SP;
1033             case PERSOSUBSTATE_SIM_NS_SP_PUK:
1034                 return PersoSubstate.SIM_NS_SP_PUK;
1035             default:
1036                 return PersoSubstate.UNKNOWN;
1037         }
1038     }
1039 
1040     @Override
getCurrentCalls(Message result)1041     public void getCurrentCalls(Message result) {
1042         IRadio radioProxy = getRadioProxy(result);
1043         if (radioProxy != null) {
1044             RILRequest rr = obtainRequest(RIL_REQUEST_GET_CURRENT_CALLS, result,
1045                     mRILDefaultWorkSource);
1046 
1047             if (RILJ_LOGD) {
1048                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1049             }
1050 
1051             try {
1052                 if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
1053                     // IRadio V1.6
1054                     android.hardware.radio.V1_6.IRadio radioProxy16 =
1055                             (android.hardware.radio.V1_6.IRadio) radioProxy;
1056                     radioProxy16.getCurrentCalls_1_6(rr.mSerial);
1057                 } else {
1058                     radioProxy.getCurrentCalls(rr.mSerial);
1059                 }
1060             } catch (RemoteException | RuntimeException e) {
1061                 handleRadioProxyExceptionForRR(rr, "getCurrentCalls", e);
1062             }
1063         }
1064     }
1065 
1066     @Override
dial(String address, boolean isEmergencyCall, EmergencyNumber emergencyNumberInfo, boolean hasKnownUserIntentEmergency, int clirMode, Message result)1067     public void dial(String address, boolean isEmergencyCall, EmergencyNumber emergencyNumberInfo,
1068                      boolean hasKnownUserIntentEmergency, int clirMode, Message result) {
1069         dial(address, isEmergencyCall, emergencyNumberInfo, hasKnownUserIntentEmergency,
1070                 clirMode, null, result);
1071     }
1072 
1073     @Override
enableModem(boolean enable, Message result)1074     public void enableModem(boolean enable, Message result) {
1075         IRadio radioProxy = getRadioProxy(result);
1076         if (mRadioVersion.less(RADIO_HAL_VERSION_1_3)) {
1077             if (RILJ_LOGV) riljLog("enableModem: not supported.");
1078             if (result != null) {
1079                 AsyncResult.forMessage(result, null,
1080                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
1081                 result.sendToTarget();
1082             }
1083             return;
1084         }
1085 
1086         android.hardware.radio.V1_3.IRadio radioProxy13 =
1087                 (android.hardware.radio.V1_3.IRadio) radioProxy;
1088         if (radioProxy13 != null) {
1089             RILRequest rr = obtainRequest(RIL_REQUEST_ENABLE_MODEM, result,
1090                     mRILDefaultWorkSource);
1091 
1092             if (RILJ_LOGD) {
1093                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " enable = "
1094                         + enable);
1095             }
1096 
1097             try {
1098                 radioProxy13.enableModem(rr.mSerial, enable);
1099             } catch (RemoteException | RuntimeException e) {
1100                 handleRadioProxyExceptionForRR(rr, "enableModem", e);
1101             }
1102         }
1103     }
1104 
1105     @Override
setSystemSelectionChannels(@onNull List<RadioAccessSpecifier> specifiers, Message onComplete)1106     public void setSystemSelectionChannels(@NonNull List<RadioAccessSpecifier> specifiers,
1107             Message onComplete) {
1108         IRadio radioProxy = getRadioProxy(onComplete);
1109         if (mRadioVersion.less(RADIO_HAL_VERSION_1_3)) {
1110             if (RILJ_LOGV) riljLog("setSystemSelectionChannels: not supported.");
1111             if (onComplete != null) {
1112                 AsyncResult.forMessage(onComplete, null,
1113                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
1114                 onComplete.sendToTarget();
1115             }
1116             return;
1117         }
1118 
1119         RILRequest rr = obtainRequest(RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS, onComplete,
1120                 mRILDefaultWorkSource);
1121 
1122         if (mRadioVersion.less(RADIO_HAL_VERSION_1_5)) {
1123             android.hardware.radio.V1_3.IRadio radioProxy13 =
1124                     (android.hardware.radio.V1_3.IRadio) radioProxy;
1125             if (radioProxy13 != null) {
1126                 if (RILJ_LOGD) {
1127                     riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1128                             + " setSystemSelectionChannels_1.3= "
1129                             + specifiers);
1130                 }
1131 
1132                 ArrayList<android.hardware.radio.V1_1.RadioAccessSpecifier> halSpecifiers =
1133                         specifiers.stream()
1134                                 .map(this::convertRadioAccessSpecifierToRadioHAL)
1135                                 .collect(Collectors.toCollection(ArrayList::new));
1136 
1137                 try {
1138                     radioProxy13.setSystemSelectionChannels(rr.mSerial,
1139                             !halSpecifiers.isEmpty(),
1140                             halSpecifiers);
1141                 } catch (RemoteException | RuntimeException e) {
1142                     handleRadioProxyExceptionForRR(rr, "setSystemSelectionChannels", e);
1143                 }
1144             }
1145         }
1146 
1147         if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
1148             android.hardware.radio.V1_5.IRadio radioProxy15 =
1149                     (android.hardware.radio.V1_5.IRadio) radioProxy;
1150 
1151             if (radioProxy15 != null) {
1152                 if (RILJ_LOGD) {
1153                     riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1154                             + " setSystemSelectionChannels_1.5= "
1155                             + specifiers);
1156                 }
1157 
1158                 ArrayList<android.hardware.radio.V1_5.RadioAccessSpecifier> halSpecifiers =
1159                         specifiers.stream()
1160                                 .map(this::convertRadioAccessSpecifierToRadioHAL_1_5)
1161                                 .collect(Collectors.toCollection(ArrayList::new));
1162 
1163                 try {
1164                     radioProxy15.setSystemSelectionChannels_1_5(rr.mSerial,
1165                             !halSpecifiers.isEmpty(),
1166                             halSpecifiers);
1167                 } catch (RemoteException | RuntimeException e) {
1168                     handleRadioProxyExceptionForRR(rr, "setSystemSelectionChannels", e);
1169                 }
1170             }
1171         }
1172     }
1173 
1174     @Override
getSystemSelectionChannels(Message onComplete)1175     public void getSystemSelectionChannels(Message onComplete) {
1176         IRadio radioProxy = getRadioProxy(onComplete);
1177         if (mRadioVersion.less(RADIO_HAL_VERSION_1_6)) {
1178             if (RILJ_LOGV) riljLog("getSystemSelectionChannels: not supported.");
1179             if (onComplete != null) {
1180                 AsyncResult.forMessage(onComplete, null,
1181                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
1182                 onComplete.sendToTarget();
1183             }
1184             return;
1185         }
1186 
1187         RILRequest rr = obtainRequest(RIL_REQUEST_GET_SYSTEM_SELECTION_CHANNELS, onComplete,
1188                 mRILDefaultWorkSource);
1189 
1190         android.hardware.radio.V1_6.IRadio radioProxy16 =
1191                 (android.hardware.radio.V1_6.IRadio) radioProxy;
1192 
1193         if (radioProxy16 != null) {
1194             if (RILJ_LOGD) {
1195                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1196                         + " getSystemSelectionChannels");
1197             }
1198 
1199             try {
1200                 radioProxy16.getSystemSelectionChannels(rr.mSerial);
1201             } catch (RemoteException | RuntimeException e) {
1202                 handleRadioProxyExceptionForRR(rr, "getSystemSelectionChannels", e);
1203             }
1204         }
1205     }
1206 
1207     @Override
getModemStatus(Message result)1208     public void getModemStatus(Message result) {
1209         IRadio radioProxy = getRadioProxy(result);
1210         if (mRadioVersion.less(RADIO_HAL_VERSION_1_3)) {
1211             if (RILJ_LOGV) riljLog("getModemStatus: not supported.");
1212             if (result != null) {
1213                 AsyncResult.forMessage(result, null,
1214                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
1215                 result.sendToTarget();
1216             }
1217             return;
1218         }
1219 
1220         android.hardware.radio.V1_3.IRadio radioProxy13 =
1221                 (android.hardware.radio.V1_3.IRadio) radioProxy;
1222         if (radioProxy13 != null) {
1223             RILRequest rr = obtainRequest(RIL_REQUEST_GET_MODEM_STATUS, result,
1224                     mRILDefaultWorkSource);
1225 
1226             if (RILJ_LOGD) {
1227                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1228             }
1229 
1230             try {
1231                 radioProxy13.getModemStackStatus(rr.mSerial);
1232             } catch (RemoteException | RuntimeException e) {
1233                 handleRadioProxyExceptionForRR(rr, "getModemStatus", e);
1234             }
1235         }
1236     }
1237 
1238     @Override
dial(String address, boolean isEmergencyCall, EmergencyNumber emergencyNumberInfo, boolean hasKnownUserIntentEmergency, int clirMode, UUSInfo uusInfo, Message result)1239     public void dial(String address, boolean isEmergencyCall, EmergencyNumber emergencyNumberInfo,
1240                      boolean hasKnownUserIntentEmergency, int clirMode, UUSInfo uusInfo,
1241                      Message result) {
1242         if (isEmergencyCall && mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_4)
1243                 && emergencyNumberInfo != null) {
1244             emergencyDial(address, emergencyNumberInfo, hasKnownUserIntentEmergency, clirMode,
1245                     uusInfo, result);
1246             return;
1247         }
1248         IRadio radioProxy = getRadioProxy(result);
1249         if (radioProxy != null) {
1250             RILRequest rr = obtainRequest(RIL_REQUEST_DIAL, result,
1251                     mRILDefaultWorkSource);
1252 
1253             Dial dialInfo = new Dial();
1254             dialInfo.address = convertNullToEmptyString(address);
1255             dialInfo.clir = clirMode;
1256             if (uusInfo != null) {
1257                 UusInfo info = new UusInfo();
1258                 info.uusType = uusInfo.getType();
1259                 info.uusDcs = uusInfo.getDcs();
1260                 info.uusData = new String(uusInfo.getUserData());
1261                 dialInfo.uusInfo.add(info);
1262             }
1263 
1264             if (RILJ_LOGD) {
1265                 // Do not log function arg for privacy
1266                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1267             }
1268 
1269             try {
1270                 radioProxy.dial(rr.mSerial, dialInfo);
1271             } catch (RemoteException | RuntimeException e) {
1272                 handleRadioProxyExceptionForRR(rr, "dial", e);
1273             }
1274         }
1275     }
1276 
emergencyDial(String address, EmergencyNumber emergencyNumberInfo, boolean hasKnownUserIntentEmergency, int clirMode, UUSInfo uusInfo, Message result)1277     private void emergencyDial(String address, EmergencyNumber emergencyNumberInfo,
1278             boolean hasKnownUserIntentEmergency, int clirMode, UUSInfo uusInfo, Message result) {
1279         IRadio radioProxy = getRadioProxy(result);
1280         if (radioProxy != null) {
1281             RILRequest rr = obtainRequest(RIL_REQUEST_EMERGENCY_DIAL, result,
1282                     mRILDefaultWorkSource);
1283             Dial dialInfo = new Dial();
1284             dialInfo.address = convertNullToEmptyString(address);
1285             dialInfo.clir = clirMode;
1286             if (uusInfo != null) {
1287                 UusInfo info = new UusInfo();
1288                 info.uusType = uusInfo.getType();
1289                 info.uusDcs = uusInfo.getDcs();
1290                 info.uusData = new String(uusInfo.getUserData());
1291                 dialInfo.uusInfo.add(info);
1292             }
1293 
1294             if (RILJ_LOGD) {
1295                 // Do not log function arg for privacy
1296                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1297             }
1298 
1299             if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
1300                 android.hardware.radio.V1_6.IRadio radioProxy16 =
1301                         (android.hardware.radio.V1_6.IRadio) radioProxy;
1302                 try {
1303                     radioProxy16.emergencyDial_1_6(rr.mSerial, dialInfo,
1304                         emergencyNumberInfo.getEmergencyServiceCategoryBitmaskInternalDial(),
1305                         emergencyNumberInfo.getEmergencyUrns() != null
1306                                 ? new ArrayList(emergencyNumberInfo.getEmergencyUrns())
1307                                         : new ArrayList<>(),
1308                         emergencyNumberInfo.getEmergencyCallRouting(),
1309                         hasKnownUserIntentEmergency,
1310                         emergencyNumberInfo.getEmergencyNumberSourceBitmask()
1311                                 == EmergencyNumber.EMERGENCY_NUMBER_SOURCE_TEST);
1312                 } catch (RemoteException | RuntimeException e) {
1313                     handleRadioProxyExceptionForRR(rr, "emergencyDial_1_6", e);
1314                 }
1315             } else if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_4)) {
1316                 android.hardware.radio.V1_4.IRadio radioProxy14 =
1317                         (android.hardware.radio.V1_4.IRadio) radioProxy;
1318                 try {
1319                     radioProxy14.emergencyDial(rr.mSerial, dialInfo,
1320                             emergencyNumberInfo.getEmergencyServiceCategoryBitmaskInternalDial(),
1321                             emergencyNumberInfo.getEmergencyUrns() != null
1322                                     ? new ArrayList(emergencyNumberInfo.getEmergencyUrns())
1323                                             : new ArrayList<>(),
1324                             emergencyNumberInfo.getEmergencyCallRouting(),
1325                             hasKnownUserIntentEmergency,
1326                             emergencyNumberInfo.getEmergencyNumberSourceBitmask()
1327                                     == EmergencyNumber.EMERGENCY_NUMBER_SOURCE_TEST);
1328                 } catch (RemoteException | RuntimeException e) {
1329                     handleRadioProxyExceptionForRR(rr, "emergencyDial", e);
1330                 }
1331             } else {
1332                 riljLoge("emergencyDial is not supported with 1.4 below IRadio");
1333             }
1334         }
1335     }
1336 
1337     @Override
getIMSI(Message result)1338     public void getIMSI(Message result) {
1339         getIMSIForApp(null, result);
1340     }
1341 
1342     @Override
getIMSIForApp(String aid, Message result)1343     public void getIMSIForApp(String aid, Message result) {
1344         IRadio radioProxy = getRadioProxy(result);
1345         if (radioProxy != null) {
1346             RILRequest rr = obtainRequest(RIL_REQUEST_GET_IMSI, result,
1347                     mRILDefaultWorkSource);
1348 
1349             if (RILJ_LOGD) {
1350                 riljLog(rr.serialString()
1351                         + ">  " + requestToString(rr.mRequest) + " aid = " + aid);
1352             }
1353             try {
1354                 radioProxy.getImsiForApp(rr.mSerial, convertNullToEmptyString(aid));
1355             } catch (RemoteException | RuntimeException e) {
1356                 handleRadioProxyExceptionForRR(rr, "getIMSIForApp", e);
1357             }
1358         }
1359     }
1360 
1361     @Override
hangupConnection(int gsmIndex, Message result)1362     public void hangupConnection(int gsmIndex, Message result) {
1363         IRadio radioProxy = getRadioProxy(result);
1364         if (radioProxy != null) {
1365             RILRequest rr = obtainRequest(RIL_REQUEST_HANGUP, result,
1366                     mRILDefaultWorkSource);
1367 
1368             if (RILJ_LOGD) {
1369                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " gsmIndex = "
1370                         + gsmIndex);
1371             }
1372 
1373             try {
1374                 radioProxy.hangup(rr.mSerial, gsmIndex);
1375             } catch (RemoteException | RuntimeException e) {
1376                 handleRadioProxyExceptionForRR(rr, "hangupConnection", e);
1377             }
1378         }
1379     }
1380 
1381     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
1382     @Override
hangupWaitingOrBackground(Message result)1383     public void hangupWaitingOrBackground(Message result) {
1384         IRadio radioProxy = getRadioProxy(result);
1385         if (radioProxy != null) {
1386             RILRequest rr = obtainRequest(RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND, result,
1387                     mRILDefaultWorkSource);
1388 
1389             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1390 
1391             try {
1392                 radioProxy.hangupWaitingOrBackground(rr.mSerial);
1393             } catch (RemoteException | RuntimeException e) {
1394                 handleRadioProxyExceptionForRR(rr, "hangupWaitingOrBackground", e);
1395             }
1396         }
1397     }
1398 
1399     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
1400     @Override
hangupForegroundResumeBackground(Message result)1401     public void hangupForegroundResumeBackground(Message result) {
1402         IRadio radioProxy = getRadioProxy(result);
1403         if (radioProxy != null) {
1404             RILRequest rr = obtainRequest(RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND, result,
1405                     mRILDefaultWorkSource);
1406 
1407             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1408 
1409             try {
1410                 radioProxy.hangupForegroundResumeBackground(rr.mSerial);
1411             } catch (RemoteException | RuntimeException e) {
1412                 handleRadioProxyExceptionForRR(rr, "hangupForegroundResumeBackground", e);
1413             }
1414         }
1415     }
1416 
1417     @Override
switchWaitingOrHoldingAndActive(Message result)1418     public void switchWaitingOrHoldingAndActive(Message result) {
1419         IRadio radioProxy = getRadioProxy(result);
1420         if (radioProxy != null) {
1421             RILRequest rr = obtainRequest(RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE, result,
1422                     mRILDefaultWorkSource);
1423 
1424             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1425 
1426             try {
1427                 radioProxy.switchWaitingOrHoldingAndActive(rr.mSerial);
1428             } catch (RemoteException | RuntimeException e) {
1429                 handleRadioProxyExceptionForRR(rr, "switchWaitingOrHoldingAndActive", e);
1430             }
1431         }
1432     }
1433 
1434     @Override
conference(Message result)1435     public void conference(Message result) {
1436         IRadio radioProxy = getRadioProxy(result);
1437         if (radioProxy != null) {
1438             RILRequest rr = obtainRequest(RIL_REQUEST_CONFERENCE, result,
1439                     mRILDefaultWorkSource);
1440 
1441             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1442 
1443             try {
1444                 radioProxy.conference(rr.mSerial);
1445             } catch (RemoteException | RuntimeException e) {
1446                 handleRadioProxyExceptionForRR(rr, "conference", e);
1447             }
1448         }
1449     }
1450 
1451     @Override
rejectCall(Message result)1452     public void rejectCall(Message result) {
1453         IRadio radioProxy = getRadioProxy(result);
1454         if (radioProxy != null) {
1455             RILRequest rr = obtainRequest(RIL_REQUEST_UDUB, result,
1456                     mRILDefaultWorkSource);
1457 
1458             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1459 
1460             try {
1461                 radioProxy.rejectCall(rr.mSerial);
1462             } catch (RemoteException | RuntimeException e) {
1463                 handleRadioProxyExceptionForRR(rr, "rejectCall", e);
1464             }
1465         }
1466     }
1467 
1468     @Override
getLastCallFailCause(Message result)1469     public void getLastCallFailCause(Message result) {
1470         IRadio radioProxy = getRadioProxy(result);
1471         if (radioProxy != null) {
1472             RILRequest rr = obtainRequest(RIL_REQUEST_LAST_CALL_FAIL_CAUSE, result,
1473                     mRILDefaultWorkSource);
1474 
1475             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1476 
1477             try {
1478                 radioProxy.getLastCallFailCause(rr.mSerial);
1479             } catch (RemoteException | RuntimeException e) {
1480                 handleRadioProxyExceptionForRR(rr, "getLastCallFailCause", e);
1481             }
1482         }
1483     }
1484 
1485     @Override
getSignalStrength(Message result)1486     public void getSignalStrength(Message result) {
1487         IRadio radioProxy = getRadioProxy(result);
1488         if (radioProxy != null) {
1489             RILRequest rr = obtainRequest(RIL_REQUEST_SIGNAL_STRENGTH, result,
1490                     mRILDefaultWorkSource);
1491 
1492             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1493 
1494             if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
1495                 android.hardware.radio.V1_6.IRadio radioProxy16 =
1496                         (android.hardware.radio.V1_6.IRadio) radioProxy;
1497                 try {
1498                     radioProxy16.getSignalStrength_1_6(rr.mSerial);
1499                 } catch (RemoteException | RuntimeException e) {
1500                     handleRadioProxyExceptionForRR(rr, "getSignalStrength_1_6", e);
1501                 }
1502             } else if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_4)) {
1503                 android.hardware.radio.V1_4.IRadio radioProxy14 =
1504                         (android.hardware.radio.V1_4.IRadio) radioProxy;
1505                 try {
1506                     radioProxy14.getSignalStrength_1_4(rr.mSerial);
1507                 } catch (RemoteException | RuntimeException e) {
1508                     handleRadioProxyExceptionForRR(rr, "getSignalStrength_1_4", e);
1509                 }
1510             } else {
1511                 try {
1512                     radioProxy.getSignalStrength(rr.mSerial);
1513                 } catch (RemoteException | RuntimeException e) {
1514                     handleRadioProxyExceptionForRR(rr, "getSignalStrength", e);
1515                 }
1516             }
1517         }
1518     }
1519 
1520     @Override
getVoiceRegistrationState(Message result)1521     public void getVoiceRegistrationState(Message result) {
1522         IRadio radioProxy = getRadioProxy(result);
1523         if (radioProxy != null) {
1524             RILRequest rr = obtainRequest(RIL_REQUEST_VOICE_REGISTRATION_STATE, result,
1525                     mRILDefaultWorkSource);
1526 
1527             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1528 
1529             HalVersion overrideHalVersion = getCompatVersion(RIL_REQUEST_VOICE_REGISTRATION_STATE);
1530             if (RILJ_LOGD) {
1531                 riljLog("getVoiceRegistrationState: overrideHalVersion=" + overrideHalVersion);
1532             }
1533 
1534             if ((overrideHalVersion == null
1535                         || overrideHalVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6))
1536                     && mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
1537                 final android.hardware.radio.V1_6.IRadio radioProxy16 =
1538                         (android.hardware.radio.V1_6.IRadio) radioProxy;
1539                 try {
1540                     radioProxy16.getVoiceRegistrationState_1_6(rr.mSerial);
1541                 } catch (RemoteException | RuntimeException e) {
1542                     handleRadioProxyExceptionForRR(rr, "getVoiceRegistrationState_1_6", e);
1543                 }
1544             } else if ((overrideHalVersion == null
1545                         || overrideHalVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5))
1546                     && mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
1547                 final android.hardware.radio.V1_5.IRadio radioProxy15 =
1548                         (android.hardware.radio.V1_5.IRadio) radioProxy;
1549                 try {
1550                     radioProxy15.getVoiceRegistrationState_1_5(rr.mSerial);
1551                 } catch (RemoteException | RuntimeException e) {
1552                     handleRadioProxyExceptionForRR(rr, "getVoiceRegistrationState_1_5", e);
1553                 }
1554             } else {
1555                 try {
1556                     radioProxy.getVoiceRegistrationState(rr.mSerial);
1557                 } catch (RemoteException | RuntimeException e) {
1558                     handleRadioProxyExceptionForRR(rr, "getVoiceRegistrationState", e);
1559                 }
1560             }
1561         }
1562     }
1563 
1564     @Override
getDataRegistrationState(Message result)1565     public void getDataRegistrationState(Message result) {
1566         IRadio radioProxy = getRadioProxy(result);
1567         if (radioProxy != null) {
1568             RILRequest rr = obtainRequest(RIL_REQUEST_DATA_REGISTRATION_STATE, result,
1569                     mRILDefaultWorkSource);
1570 
1571             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1572 
1573             HalVersion overrideHalVersion = getCompatVersion(RIL_REQUEST_DATA_REGISTRATION_STATE);
1574             if (RILJ_LOGD) {
1575                 riljLog("getDataRegistrationState: overrideHalVersion=" + overrideHalVersion);
1576             }
1577 
1578             if ((overrideHalVersion == null
1579                         || overrideHalVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6))
1580                     && mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
1581                 final android.hardware.radio.V1_6.IRadio radioProxy16 =
1582                         (android.hardware.radio.V1_6.IRadio) radioProxy;
1583                 try {
1584                     radioProxy16.getDataRegistrationState_1_6(rr.mSerial);
1585                 } catch (RemoteException | RuntimeException e) {
1586                     handleRadioProxyExceptionForRR(rr, "getDataRegistrationState_1_6", e);
1587                 }
1588             } else if ((overrideHalVersion == null
1589                         || overrideHalVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5))
1590                     && mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
1591                 final android.hardware.radio.V1_5.IRadio radioProxy15 =
1592                         (android.hardware.radio.V1_5.IRadio) radioProxy;
1593                 try {
1594                     radioProxy15.getDataRegistrationState_1_5(rr.mSerial);
1595                 } catch (RemoteException | RuntimeException e) {
1596                     handleRadioProxyExceptionForRR(rr, "getDataRegistrationState_1_5", e);
1597                 }
1598             } else {
1599                 try {
1600                     radioProxy.getDataRegistrationState(rr.mSerial);
1601                 } catch (RemoteException | RuntimeException e) {
1602                     handleRadioProxyExceptionForRR(rr, "getDataRegistrationState", e);
1603                 }
1604             }
1605         }
1606     }
1607 
1608     @Override
getOperator(Message result)1609     public void getOperator(Message result) {
1610         IRadio radioProxy = getRadioProxy(result);
1611         if (radioProxy != null) {
1612             RILRequest rr = obtainRequest(RIL_REQUEST_OPERATOR, result,
1613                     mRILDefaultWorkSource);
1614 
1615             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1616 
1617             try {
1618                 radioProxy.getOperator(rr.mSerial);
1619             } catch (RemoteException | RuntimeException e) {
1620                 handleRadioProxyExceptionForRR(rr, "getOperator", e);
1621             }
1622         }
1623     }
1624 
1625     @UnsupportedAppUsage
1626     @Override
setRadioPower(boolean on, boolean forEmergencyCall, boolean preferredForEmergencyCall, Message result)1627     public void setRadioPower(boolean on, boolean forEmergencyCall,
1628             boolean preferredForEmergencyCall, Message result) {
1629         IRadio radioProxy = getRadioProxy(result);
1630         if (radioProxy != null) {
1631             RILRequest rr = obtainRequest(RIL_REQUEST_RADIO_POWER, result,
1632                     mRILDefaultWorkSource);
1633 
1634             if (RILJ_LOGD) {
1635                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1636                         + " on = " + on + " forEmergencyCall= " + forEmergencyCall
1637                         + " preferredForEmergencyCall="  + preferredForEmergencyCall);
1638             }
1639 
1640             if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
1641                 android.hardware.radio.V1_6.IRadio radioProxy16 =
1642                         (android.hardware.radio.V1_6.IRadio) radioProxy;
1643                 try {
1644                     radioProxy16.setRadioPower_1_6(rr.mSerial, on, forEmergencyCall,
1645                             preferredForEmergencyCall);
1646                 } catch (RemoteException | RuntimeException e) {
1647                     handleRadioProxyExceptionForRR(rr, "setRadioPower_1_6", e);
1648                 }
1649             } else if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
1650                 android.hardware.radio.V1_5.IRadio radioProxy15 =
1651                         (android.hardware.radio.V1_5.IRadio) radioProxy;
1652                 try {
1653                     radioProxy15.setRadioPower_1_5(rr.mSerial, on, forEmergencyCall,
1654                             preferredForEmergencyCall);
1655                 } catch (RemoteException | RuntimeException e) {
1656                     handleRadioProxyExceptionForRR(rr, "setRadioPower_1_5", e);
1657                 }
1658             } else {
1659                 try {
1660                     radioProxy.setRadioPower(rr.mSerial, on);
1661                 } catch (RemoteException | RuntimeException e) {
1662                     handleRadioProxyExceptionForRR(rr, "setRadioPower", e);
1663                 }
1664             }
1665         }
1666     }
1667 
1668     @Override
sendDtmf(char c, Message result)1669     public void sendDtmf(char c, Message result) {
1670         IRadio radioProxy = getRadioProxy(result);
1671         if (radioProxy != null) {
1672             RILRequest rr = obtainRequest(RIL_REQUEST_DTMF, result,
1673                     mRILDefaultWorkSource);
1674 
1675             if (RILJ_LOGD) {
1676                 // Do not log function arg for privacy
1677                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1678             }
1679 
1680             try {
1681                 radioProxy.sendDtmf(rr.mSerial, c + "");
1682             } catch (RemoteException | RuntimeException e) {
1683                 handleRadioProxyExceptionForRR(rr, "sendDtmf", e);
1684             }
1685         }
1686     }
1687 
constructGsmSendSmsRilRequest(String smscPdu, String pdu)1688     private GsmSmsMessage constructGsmSendSmsRilRequest(String smscPdu, String pdu) {
1689         GsmSmsMessage msg = new GsmSmsMessage();
1690         msg.smscPdu = smscPdu == null ? "" : smscPdu;
1691         msg.pdu = pdu == null ? "" : pdu;
1692         return msg;
1693     }
1694 
1695     @Override
sendSMS(String smscPdu, String pdu, Message result)1696     public void sendSMS(String smscPdu, String pdu, Message result) {
1697         IRadio radioProxy = getRadioProxy(result);
1698         if (radioProxy != null) {
1699             RILRequest rr = obtainRequest(RIL_REQUEST_SEND_SMS, result,
1700                     mRILDefaultWorkSource);
1701 
1702             // Do not log function args for privacy
1703             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1704 
1705             GsmSmsMessage msg = constructGsmSendSmsRilRequest(smscPdu, pdu);
1706             if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
1707                 try {
1708                     android.hardware.radio.V1_6.IRadio radioProxy16 =
1709                             (android.hardware.radio.V1_6.IRadio) radioProxy;
1710                     radioProxy16.sendSms_1_6(rr.mSerial, msg);
1711                     mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_GSM,
1712                             SmsSession.Event.Format.SMS_FORMAT_3GPP,
1713                             getOutgoingSmsMessageId(result));
1714                 } catch (RemoteException | RuntimeException e) {
1715                     handleRadioProxyExceptionForRR(rr, "sendSMS", e);
1716                 }
1717             } else {
1718                 try {
1719                     radioProxy.sendSms(rr.mSerial, msg);
1720                     mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_GSM,
1721                             SmsSession.Event.Format.SMS_FORMAT_3GPP,
1722                             getOutgoingSmsMessageId(result));
1723                 } catch (RemoteException | RuntimeException e) {
1724                     handleRadioProxyExceptionForRR(rr, "sendSMS", e);
1725                 }
1726             }
1727         }
1728     }
1729 
1730     /**
1731      * Extract the outgoing sms messageId from the tracker, if there is one. This is specifically
1732      * for SMS related APIs.
1733      * @param result the result Message
1734      * @return messageId unique identifier or 0 if there is no message id
1735      */
getOutgoingSmsMessageId(Message result)1736     public static long getOutgoingSmsMessageId(Message result) {
1737         if (result == null || !(result.obj instanceof SMSDispatcher.SmsTracker)) {
1738             return 0L;
1739         }
1740         long messageId = ((SMSDispatcher.SmsTracker) result.obj).mMessageId;
1741         if (RILJ_LOGV) {
1742             Rlog.d(RILJ_LOG_TAG, "getOutgoingSmsMessageId "
1743                     + SmsController.formatCrossStackMessageId(messageId));
1744         }
1745         return messageId;
1746     }
1747 
1748     @Override
sendSMSExpectMore(String smscPdu, String pdu, Message result)1749     public void sendSMSExpectMore(String smscPdu, String pdu, Message result) {
1750         IRadio radioProxy = getRadioProxy(result);
1751         if (radioProxy != null) {
1752             RILRequest rr = obtainRequest(RIL_REQUEST_SEND_SMS_EXPECT_MORE, result,
1753                     mRILDefaultWorkSource);
1754 
1755             // Do not log function arg for privacy
1756             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1757 
1758             GsmSmsMessage msg = constructGsmSendSmsRilRequest(smscPdu, pdu);
1759             if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
1760                 try {
1761                     android.hardware.radio.V1_6.IRadio radioProxy16 =
1762                             (android.hardware.radio.V1_6.IRadio) radioProxy;
1763                     radioProxy16.sendSmsExpectMore_1_6(rr.mSerial, msg);
1764                     mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_GSM,
1765                             SmsSession.Event.Format.SMS_FORMAT_3GPP,
1766                             getOutgoingSmsMessageId(result));
1767                 } catch (RemoteException | RuntimeException e) {
1768                     handleRadioProxyExceptionForRR(rr, "sendSMSExpectMore", e);
1769                 }
1770             } else {
1771                 try {
1772                     radioProxy.sendSMSExpectMore(rr.mSerial, msg);
1773                     mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_GSM,
1774                             SmsSession.Event.Format.SMS_FORMAT_3GPP,
1775                             getOutgoingSmsMessageId(result));
1776                 } catch (RemoteException | RuntimeException e) {
1777                     handleRadioProxyExceptionForRR(rr, "sendSMSExpectMore", e);
1778                 }
1779             }
1780         }
1781     }
1782 
1783     /**
1784      * Convert MVNO type string into MvnoType defined in types.hal.
1785      * @param mvnoType MVNO type
1786      * @return MVNO type in integer
1787      */
convertToHalMvnoType(String mvnoType)1788     private static int convertToHalMvnoType(String mvnoType) {
1789         switch (mvnoType) {
1790             case "imsi" : return MvnoType.IMSI;
1791             case "gid" : return MvnoType.GID;
1792             case "spn" : return MvnoType.SPN;
1793             default: return MvnoType.NONE;
1794         }
1795     }
1796 
1797     /**
1798      * Convert to DataProfileInfo defined in radio/1.0/types.hal
1799      * @param dp Data profile
1800      * @return A converted data profile
1801      */
convertToHalDataProfile10( DataProfile dp)1802     private static android.hardware.radio.V1_0.DataProfileInfo convertToHalDataProfile10(
1803             DataProfile dp) {
1804         android.hardware.radio.V1_0.DataProfileInfo dpi =
1805                 new android.hardware.radio.V1_0.DataProfileInfo();
1806 
1807         dpi.profileId = dp.getProfileId();
1808         dpi.apn = dp.getApn();
1809         dpi.protocol = ApnSetting.getProtocolStringFromInt(dp.getProtocolType());
1810         dpi.roamingProtocol = ApnSetting.getProtocolStringFromInt(dp.getRoamingProtocolType());
1811         dpi.authType = dp.getAuthType();
1812         dpi.user = dp.getUserName();
1813         dpi.password = dp.getPassword();
1814         dpi.type = dp.getType();
1815         dpi.maxConnsTime = dp.getMaxConnectionsTime();
1816         dpi.maxConns = dp.getMaxConnections();
1817         dpi.waitTime = dp.getWaitTime();
1818         dpi.enabled = dp.isEnabled();
1819         dpi.supportedApnTypesBitmap = dp.getSupportedApnTypesBitmask();
1820         // Shift by 1 bit due to the discrepancy between
1821         // android.hardware.radio.V1_0.RadioAccessFamily and the bitmask version of
1822         // ServiceState.RIL_RADIO_TECHNOLOGY_XXXX.
1823         dpi.bearerBitmap = ServiceState.convertNetworkTypeBitmaskToBearerBitmask(
1824                 dp.getBearerBitmask()) << 1;
1825         dpi.mtu = dp.getMtuV4();
1826         dpi.mvnoType = MvnoType.NONE;
1827         dpi.mvnoMatchData = "";
1828 
1829         return dpi;
1830     }
1831 
1832     /**
1833      * Convert to DataProfileInfo defined in radio/1.4/types.hal
1834      * @param dp Data profile
1835      * @return A converted data profile
1836      */
convertToHalDataProfile14( DataProfile dp)1837     private static android.hardware.radio.V1_4.DataProfileInfo convertToHalDataProfile14(
1838             DataProfile dp) {
1839         android.hardware.radio.V1_4.DataProfileInfo dpi =
1840                 new android.hardware.radio.V1_4.DataProfileInfo();
1841 
1842         dpi.apn = dp.getApn();
1843         dpi.protocol = dp.getProtocolType();
1844         dpi.roamingProtocol = dp.getRoamingProtocolType();
1845         dpi.authType = dp.getAuthType();
1846         dpi.user = dp.getUserName();
1847         dpi.password = dp.getPassword();
1848         dpi.type = dp.getType();
1849         dpi.maxConnsTime = dp.getMaxConnectionsTime();
1850         dpi.maxConns = dp.getMaxConnections();
1851         dpi.waitTime = dp.getWaitTime();
1852         dpi.enabled = dp.isEnabled();
1853         dpi.supportedApnTypesBitmap = dp.getSupportedApnTypesBitmask();
1854         // Shift by 1 bit due to the discrepancy between
1855         // android.hardware.radio.V1_0.RadioAccessFamily and the bitmask version of
1856         // ServiceState.RIL_RADIO_TECHNOLOGY_XXXX.
1857         dpi.bearerBitmap = ServiceState.convertNetworkTypeBitmaskToBearerBitmask(
1858                 dp.getBearerBitmask()) << 1;
1859         dpi.mtu = dp.getMtuV4();
1860         dpi.persistent = dp.isPersistent();
1861         dpi.preferred = dp.isPreferred();
1862 
1863         // profile id is only meaningful when it's persistent on the modem.
1864         dpi.profileId = (dpi.persistent) ? dp.getProfileId() : DataProfileId.INVALID;
1865 
1866         return dpi;
1867     }
1868 
convertToHalSliceInfo(@ullable NetworkSliceInfo sliceInfo)1869     private static OptionalSliceInfo convertToHalSliceInfo(@Nullable NetworkSliceInfo sliceInfo) {
1870         OptionalSliceInfo optionalSliceInfo = new OptionalSliceInfo();
1871         if (sliceInfo == null) {
1872             return optionalSliceInfo;
1873         }
1874 
1875         android.hardware.radio.V1_6.SliceInfo si = new android.hardware.radio.V1_6.SliceInfo();
1876         si.sst = (byte) sliceInfo.getSliceServiceType();
1877         si.mappedHplmnSst = (byte) sliceInfo.getMappedHplmnSliceServiceType();
1878         si.sliceDifferentiator = sliceInfo.getSliceDifferentiator();
1879         si.mappedHplmnSD = sliceInfo.getMappedHplmnSliceDifferentiator();
1880         optionalSliceInfo.value(si);
1881         return optionalSliceInfo;
1882     }
1883 
convertToHalTrafficDescriptor( @ullable TrafficDescriptor trafficDescriptor)1884     private static OptionalTrafficDescriptor convertToHalTrafficDescriptor(
1885             @Nullable TrafficDescriptor trafficDescriptor) {
1886         OptionalTrafficDescriptor optionalTrafficDescriptor = new OptionalTrafficDescriptor();
1887         if (trafficDescriptor == null) {
1888             return optionalTrafficDescriptor;
1889         }
1890 
1891         android.hardware.radio.V1_6.TrafficDescriptor td =
1892                 new android.hardware.radio.V1_6.TrafficDescriptor();
1893 
1894         OptionalDnn optionalDnn = new OptionalDnn();
1895         if (trafficDescriptor.getDataNetworkName() != null) {
1896             optionalDnn.value(trafficDescriptor.getDataNetworkName());
1897         }
1898         td.dnn = optionalDnn;
1899 
1900         OptionalOsAppId optionalOsAppId = new OptionalOsAppId();
1901         if (trafficDescriptor.getOsAppId() != null) {
1902             android.hardware.radio.V1_6.OsAppId osAppId = new android.hardware.radio.V1_6.OsAppId();
1903             osAppId.osAppId = primitiveArrayToArrayList(trafficDescriptor.getOsAppId());
1904             optionalOsAppId.value(osAppId);
1905         }
1906         td.osAppId = optionalOsAppId;
1907 
1908         optionalTrafficDescriptor.value(td);
1909         return optionalTrafficDescriptor;
1910     }
1911 
convertToHalLinkProperties15( LinkProperties linkProperties)1912     private static ArrayList<android.hardware.radio.V1_5.LinkAddress> convertToHalLinkProperties15(
1913             LinkProperties linkProperties) {
1914         ArrayList<android.hardware.radio.V1_5.LinkAddress> addresses15 = new ArrayList<>();
1915         if (linkProperties != null) {
1916             for (LinkAddress la : linkProperties.getAllLinkAddresses()) {
1917                 android.hardware.radio.V1_5.LinkAddress linkAddress =
1918                         new android.hardware.radio.V1_5.LinkAddress();
1919                 linkAddress.address = la.getAddress().getHostAddress();
1920                 linkAddress.properties = la.getFlags();
1921                 linkAddress.deprecationTime = la.getDeprecationTime();
1922                 linkAddress.expirationTime = la.getExpirationTime();
1923                 addresses15.add(linkAddress);
1924             }
1925         }
1926         return addresses15;
1927     }
1928 
1929     /**
1930      * Convert to DataProfileInfo defined in radio/1.5/types.hal
1931      * @param dp Data profile
1932      * @return A converted data profile
1933      */
convertToHalDataProfile15( DataProfile dp)1934     private static android.hardware.radio.V1_5.DataProfileInfo convertToHalDataProfile15(
1935             DataProfile dp) {
1936         android.hardware.radio.V1_5.DataProfileInfo dpi =
1937                 new android.hardware.radio.V1_5.DataProfileInfo();
1938 
1939         dpi.apn = dp.getApn();
1940         dpi.protocol = dp.getProtocolType();
1941         dpi.roamingProtocol = dp.getRoamingProtocolType();
1942         dpi.authType = dp.getAuthType();
1943         dpi.user = dp.getUserName();
1944         dpi.password = dp.getPassword();
1945         dpi.type = dp.getType();
1946         dpi.maxConnsTime = dp.getMaxConnectionsTime();
1947         dpi.maxConns = dp.getMaxConnections();
1948         dpi.waitTime = dp.getWaitTime();
1949         dpi.enabled = dp.isEnabled();
1950         dpi.supportedApnTypesBitmap = dp.getSupportedApnTypesBitmask();
1951         // Shift by 1 bit due to the discrepancy between
1952         // android.hardware.radio.V1_0.RadioAccessFamily and the bitmask version of
1953         // ServiceState.RIL_RADIO_TECHNOLOGY_XXXX.
1954         dpi.bearerBitmap = ServiceState.convertNetworkTypeBitmaskToBearerBitmask(
1955             dp.getBearerBitmask()) << 1;
1956         dpi.mtuV4 = dp.getMtuV4();
1957         dpi.mtuV6 = dp.getMtuV6();
1958         dpi.persistent = dp.isPersistent();
1959         dpi.preferred = dp.isPreferred();
1960 
1961         // profile id is only meaningful when it's persistent on the modem.
1962         dpi.profileId = (dpi.persistent) ? dp.getProfileId() : DataProfileId.INVALID;
1963 
1964         return dpi;
1965     }
1966 
1967     /**
1968      * Convert NV reset type into ResetNvType defined in types.hal.
1969      * @param resetType NV reset type.
1970      * @return Converted reset type in integer or -1 if param is invalid.
1971      */
convertToHalResetNvType(int resetType)1972     private static int convertToHalResetNvType(int resetType) {
1973         /**
1974          * resetType values
1975          * 1 - reload all NV items
1976          * 2 - erase NV reset (SCRTN)
1977          * 3 - factory reset (RTN)
1978          */
1979         switch (resetType) {
1980             case 1: return ResetNvType.RELOAD;
1981             case 2: return ResetNvType.ERASE;
1982             case 3: return ResetNvType.FACTORY_RESET;
1983         }
1984         return -1;
1985     }
1986 
1987     @Override
setupDataCall(int accessNetworkType, DataProfile dataProfile, boolean isRoaming, boolean allowRoaming, int reason, LinkProperties linkProperties, int pduSessionId, NetworkSliceInfo sliceInfo, TrafficDescriptor trafficDescriptor, boolean matchAllRuleAllowed, Message result)1988     public void setupDataCall(int accessNetworkType, DataProfile dataProfile, boolean isRoaming,
1989             boolean allowRoaming, int reason, LinkProperties linkProperties, int pduSessionId,
1990             NetworkSliceInfo sliceInfo, TrafficDescriptor trafficDescriptor,
1991             boolean matchAllRuleAllowed, Message result) {
1992         IRadio radioProxy = getRadioProxy(result);
1993 
1994         if (radioProxy != null) {
1995 
1996             RILRequest rr = obtainRequest(RIL_REQUEST_SETUP_DATA_CALL, result,
1997                     mRILDefaultWorkSource);
1998 
1999             ArrayList<String> addresses = new ArrayList<>();
2000             ArrayList<String> dnses = new ArrayList<>();
2001             if (linkProperties != null) {
2002                 for (InetAddress address : linkProperties.getAddresses()) {
2003                     addresses.add(address.getHostAddress());
2004                 }
2005                 for (InetAddress dns : linkProperties.getDnsServers()) {
2006                     dnses.add(dns.getHostAddress());
2007                 }
2008             }
2009 
2010             try {
2011                 if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
2012                     // IRadio V1.6
2013                     android.hardware.radio.V1_6.IRadio radioProxy16 =
2014                             (android.hardware.radio.V1_6.IRadio) radioProxy;
2015 
2016                     // Convert to HAL data profile
2017                     android.hardware.radio.V1_5.DataProfileInfo dpi =
2018                             convertToHalDataProfile15(dataProfile);
2019 
2020                     OptionalSliceInfo si = convertToHalSliceInfo(sliceInfo);
2021 
2022                     ArrayList<android.hardware.radio.V1_5.LinkAddress> addresses15 =
2023                             convertToHalLinkProperties15(linkProperties);
2024 
2025                     OptionalTrafficDescriptor td = convertToHalTrafficDescriptor(trafficDescriptor);
2026 
2027                     if (RILJ_LOGD) {
2028                         riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2029                                 + ",accessNetworkType="
2030                                 + AccessNetworkType.toString(accessNetworkType) + ",isRoaming="
2031                                 + isRoaming + ",allowRoaming=" + allowRoaming + "," + dataProfile
2032                                 + ",addresses=" + addresses15 + ",dnses=" + dnses
2033                                 + ",pduSessionId=" + pduSessionId + ",sliceInfo=" + si
2034                                 + ",trafficDescriptor=" + td + ",matchAllRuleAllowed="
2035                                 + matchAllRuleAllowed);
2036                     }
2037 
2038                     radioProxy16.setupDataCall_1_6(rr.mSerial, accessNetworkType, dpi, allowRoaming,
2039                             reason, addresses15, dnses, pduSessionId, si, td, matchAllRuleAllowed);
2040                 } else if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
2041                     // IRadio V1.5
2042                     android.hardware.radio.V1_5.IRadio radioProxy15 =
2043                             (android.hardware.radio.V1_5.IRadio) radioProxy;
2044 
2045                     // Convert to HAL data profile
2046                     android.hardware.radio.V1_5.DataProfileInfo dpi =
2047                             convertToHalDataProfile15(dataProfile);
2048 
2049                     ArrayList<android.hardware.radio.V1_5.LinkAddress> addresses15 =
2050                             convertToHalLinkProperties15(linkProperties);
2051 
2052                     if (RILJ_LOGD) {
2053                         riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2054                                 + ",accessNetworkType="
2055                                 + AccessNetworkType.toString(accessNetworkType) + ",isRoaming="
2056                                 + isRoaming + ",allowRoaming=" + allowRoaming + "," + dataProfile
2057                                 + ",addresses=" + addresses15 + ",dnses=" + dnses);
2058                     }
2059 
2060                     radioProxy15.setupDataCall_1_5(rr.mSerial, accessNetworkType, dpi, allowRoaming,
2061                              reason, addresses15, dnses);
2062                 } else if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_4)) {
2063                     // IRadio V1.4
2064                     android.hardware.radio.V1_4.IRadio radioProxy14 =
2065                             (android.hardware.radio.V1_4.IRadio) radioProxy;
2066 
2067                     // Convert to HAL data profile
2068                     android.hardware.radio.V1_4.DataProfileInfo dpi =
2069                             convertToHalDataProfile14(dataProfile);
2070 
2071                     if (RILJ_LOGD) {
2072                         riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2073                                 + ",accessNetworkType="
2074                                 + AccessNetworkType.toString(accessNetworkType) + ",isRoaming="
2075                                 + isRoaming + ",allowRoaming=" + allowRoaming + "," + dataProfile
2076                                 + ",addresses=" + addresses + ",dnses=" + dnses);
2077                     }
2078 
2079                     radioProxy14.setupDataCall_1_4(rr.mSerial, accessNetworkType, dpi, allowRoaming,
2080                             reason, addresses, dnses);
2081                 } else if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_2)) {
2082                     // IRadio V1.2 and IRadio V1.3
2083                     android.hardware.radio.V1_2.IRadio radioProxy12 =
2084                             (android.hardware.radio.V1_2.IRadio) radioProxy;
2085 
2086                     // Convert to HAL data profile
2087                     android.hardware.radio.V1_0.DataProfileInfo dpi =
2088                             convertToHalDataProfile10(dataProfile);
2089 
2090                     if (RILJ_LOGD) {
2091                         riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2092                                 + ",accessNetworkType="
2093                                 + AccessNetworkType.toString(accessNetworkType) + ",isRoaming="
2094                                 + isRoaming + ",allowRoaming=" + allowRoaming + ","
2095                                 + dataProfile + ",addresses=" + addresses + ",dnses=" + dnses);
2096                     }
2097 
2098                     radioProxy12.setupDataCall_1_2(rr.mSerial, accessNetworkType, dpi,
2099                             dataProfile.isPersistent(), allowRoaming, isRoaming, reason,
2100                             addresses, dnses);
2101                 } else {
2102                     // IRadio V1.0 and IRadio V1.1
2103 
2104                     // Convert to HAL data profile
2105                     android.hardware.radio.V1_0.DataProfileInfo dpi =
2106                             convertToHalDataProfile10(dataProfile);
2107 
2108                     // Getting data RAT here is just a workaround to support the older 1.0
2109                     // vendor RIL. The new data service interface passes access network type
2110                     // instead of RAT for setup data request. It is impossible to convert access
2111                     // network type back to RAT here, so we directly get the data RAT from
2112                     // phone.
2113                     int dataRat = ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN;
2114                     Phone phone = PhoneFactory.getPhone(mPhoneId);
2115                     if (phone != null) {
2116                         ServiceState ss = phone.getServiceState();
2117                         if (ss != null) {
2118                             dataRat = ss.getRilDataRadioTechnology();
2119                         }
2120                     }
2121                     if (RILJ_LOGD) {
2122                         riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2123                                 + ",dataRat=" + dataRat + ",isRoaming=" + isRoaming
2124                                 + ",allowRoaming=" + allowRoaming + "," + dataProfile);
2125                     }
2126 
2127                     radioProxy.setupDataCall(rr.mSerial, dataRat, dpi,
2128                             dataProfile.isPersistent(), allowRoaming, isRoaming);
2129                 }
2130             } catch (RemoteException | RuntimeException e) {
2131                 handleRadioProxyExceptionForRR(rr, "setupDataCall", e);
2132             }
2133         }
2134     }
2135 
2136     @Override
iccIO(int command, int fileId, String path, int p1, int p2, int p3, String data, String pin2, Message result)2137     public void iccIO(int command, int fileId, String path, int p1, int p2, int p3,
2138                       String data, String pin2, Message result) {
2139         iccIOForApp(command, fileId, path, p1, p2, p3, data, pin2, null, result);
2140     }
2141 
2142     @Override
iccIOForApp(int command, int fileId, String path, int p1, int p2, int p3, String data, String pin2, String aid, Message result)2143     public void iccIOForApp(int command, int fileId, String path, int p1, int p2, int p3,
2144                  String data, String pin2, String aid, Message result) {
2145         IRadio radioProxy = getRadioProxy(result);
2146         if (radioProxy != null) {
2147             RILRequest rr = obtainRequest(RIL_REQUEST_SIM_IO, result,
2148                     mRILDefaultWorkSource);
2149 
2150             if (RILJ_LOGD) {
2151                 if (TelephonyUtils.IS_DEBUGGABLE) {
2152                     riljLog(rr.serialString() + "> iccIO: "
2153                             + requestToString(rr.mRequest) + " command = 0x"
2154                             + Integer.toHexString(command) + " fileId = 0x"
2155                             + Integer.toHexString(fileId) + " path = " + path + " p1 = "
2156                             + p1 + " p2 = " + p2 + " p3 = " + " data = " + data
2157                             + " aid = " + aid);
2158                 } else {
2159                     riljLog(rr.serialString() + "> iccIO: " + requestToString(rr.mRequest));
2160                 }
2161             }
2162 
2163             IccIo iccIo = new IccIo();
2164             iccIo.command = command;
2165             iccIo.fileId = fileId;
2166             iccIo.path = convertNullToEmptyString(path);
2167             iccIo.p1 = p1;
2168             iccIo.p2 = p2;
2169             iccIo.p3 = p3;
2170             iccIo.data = convertNullToEmptyString(data);
2171             iccIo.pin2 = convertNullToEmptyString(pin2);
2172             iccIo.aid = convertNullToEmptyString(aid);
2173 
2174             try {
2175                 radioProxy.iccIOForApp(rr.mSerial, iccIo);
2176             } catch (RemoteException | RuntimeException e) {
2177                 handleRadioProxyExceptionForRR(rr, "iccIOForApp", e);
2178             }
2179         }
2180     }
2181 
2182     @Override
sendUSSD(String ussd, Message result)2183     public void sendUSSD(String ussd, Message result) {
2184         IRadio radioProxy = getRadioProxy(result);
2185         if (radioProxy != null) {
2186             RILRequest rr = obtainRequest(RIL_REQUEST_SEND_USSD, result,
2187                     mRILDefaultWorkSource);
2188 
2189             if (RILJ_LOGD) {
2190                 String logUssd = "*******";
2191                 if (RILJ_LOGV) logUssd = ussd;
2192                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2193                         + " ussd = " + logUssd);
2194             }
2195 
2196             try {
2197                 radioProxy.sendUssd(rr.mSerial, convertNullToEmptyString(ussd));
2198             } catch (RemoteException | RuntimeException e) {
2199                 handleRadioProxyExceptionForRR(rr, "sendUSSD", e);
2200             }
2201         }
2202     }
2203 
2204     @Override
cancelPendingUssd(Message result)2205     public void cancelPendingUssd(Message result) {
2206         IRadio radioProxy = getRadioProxy(result);
2207         if (radioProxy != null) {
2208             RILRequest rr = obtainRequest(RIL_REQUEST_CANCEL_USSD, result,
2209                     mRILDefaultWorkSource);
2210 
2211             if (RILJ_LOGD) {
2212                 riljLog(rr.serialString()
2213                         + "> " + requestToString(rr.mRequest));
2214             }
2215 
2216             try {
2217                 radioProxy.cancelPendingUssd(rr.mSerial);
2218             } catch (RemoteException | RuntimeException e) {
2219                 handleRadioProxyExceptionForRR(rr, "cancelPendingUssd", e);
2220             }
2221         }
2222     }
2223 
2224     @Override
getCLIR(Message result)2225     public void getCLIR(Message result) {
2226         IRadio radioProxy = getRadioProxy(result);
2227         if (radioProxy != null) {
2228             RILRequest rr = obtainRequest(RIL_REQUEST_GET_CLIR, result,
2229                     mRILDefaultWorkSource);
2230 
2231             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2232 
2233             try {
2234                 radioProxy.getClir(rr.mSerial);
2235             } catch (RemoteException | RuntimeException e) {
2236                 handleRadioProxyExceptionForRR(rr, "getCLIR", e);
2237             }
2238         }
2239     }
2240 
2241     @Override
setCLIR(int clirMode, Message result)2242     public void setCLIR(int clirMode, Message result) {
2243         IRadio radioProxy = getRadioProxy(result);
2244         if (radioProxy != null) {
2245             RILRequest rr = obtainRequest(RIL_REQUEST_SET_CLIR, result, mRILDefaultWorkSource);
2246 
2247             if (RILJ_LOGD) {
2248                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2249                         + " clirMode = " + clirMode);
2250             }
2251 
2252             try {
2253                 radioProxy.setClir(rr.mSerial, clirMode);
2254             } catch (RemoteException | RuntimeException e) {
2255                 handleRadioProxyExceptionForRR(rr, "setCLIR", e);
2256             }
2257         }
2258     }
2259 
2260     @Override
queryCallForwardStatus(int cfReason, int serviceClass, String number, Message result)2261     public void queryCallForwardStatus(int cfReason, int serviceClass,
2262                            String number, Message result) {
2263         IRadio radioProxy = getRadioProxy(result);
2264         if (radioProxy != null) {
2265             RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_CALL_FORWARD_STATUS, result,
2266                     mRILDefaultWorkSource);
2267 
2268             if (RILJ_LOGD) {
2269                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2270                         + " cfreason = " + cfReason + " serviceClass = " + serviceClass);
2271             }
2272 
2273             android.hardware.radio.V1_0.CallForwardInfo cfInfo =
2274                     new android.hardware.radio.V1_0.CallForwardInfo();
2275             cfInfo.reason = cfReason;
2276             cfInfo.serviceClass = serviceClass;
2277             cfInfo.toa = PhoneNumberUtils.toaFromString(number);
2278             cfInfo.number = convertNullToEmptyString(number);
2279             cfInfo.timeSeconds = 0;
2280 
2281             try {
2282                 radioProxy.getCallForwardStatus(rr.mSerial, cfInfo);
2283             } catch (RemoteException | RuntimeException e) {
2284                 handleRadioProxyExceptionForRR(rr, "queryCallForwardStatus", e);
2285             }
2286         }
2287     }
2288 
2289     @Override
setCallForward(int action, int cfReason, int serviceClass, String number, int timeSeconds, Message result)2290     public void setCallForward(int action, int cfReason, int serviceClass,
2291                    String number, int timeSeconds, Message result) {
2292         IRadio radioProxy = getRadioProxy(result);
2293         if (radioProxy != null) {
2294             RILRequest rr = obtainRequest(RIL_REQUEST_SET_CALL_FORWARD, result,
2295                     mRILDefaultWorkSource);
2296 
2297             if (RILJ_LOGD) {
2298                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2299                         + " action = " + action + " cfReason = " + cfReason + " serviceClass = "
2300                         + serviceClass + " timeSeconds = " + timeSeconds);
2301             }
2302 
2303             android.hardware.radio.V1_0.CallForwardInfo cfInfo =
2304                     new android.hardware.radio.V1_0.CallForwardInfo();
2305             cfInfo.status = action;
2306             cfInfo.reason = cfReason;
2307             cfInfo.serviceClass = serviceClass;
2308             cfInfo.toa = PhoneNumberUtils.toaFromString(number);
2309             cfInfo.number = convertNullToEmptyString(number);
2310             cfInfo.timeSeconds = timeSeconds;
2311 
2312             try {
2313                 radioProxy.setCallForward(rr.mSerial, cfInfo);
2314             } catch (RemoteException | RuntimeException e) {
2315                 handleRadioProxyExceptionForRR(rr, "setCallForward", e);
2316 
2317             }
2318         }
2319     }
2320 
2321     @Override
queryCallWaiting(int serviceClass, Message result)2322     public void queryCallWaiting(int serviceClass, Message result) {
2323         IRadio radioProxy = getRadioProxy(result);
2324         if (radioProxy != null) {
2325             RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_CALL_WAITING, result,
2326                     mRILDefaultWorkSource);
2327 
2328             if (RILJ_LOGD) {
2329                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2330                         + " serviceClass = " + serviceClass);
2331             }
2332 
2333             try {
2334                 radioProxy.getCallWaiting(rr.mSerial, serviceClass);
2335             } catch (RemoteException | RuntimeException e) {
2336                 handleRadioProxyExceptionForRR(rr, "queryCallWaiting", e);
2337             }
2338         }
2339     }
2340 
2341     @Override
setCallWaiting(boolean enable, int serviceClass, Message result)2342     public void setCallWaiting(boolean enable, int serviceClass, Message result) {
2343         IRadio radioProxy = getRadioProxy(result);
2344         if (radioProxy != null) {
2345             RILRequest rr = obtainRequest(RIL_REQUEST_SET_CALL_WAITING, result,
2346                     mRILDefaultWorkSource);
2347 
2348             if (RILJ_LOGD) {
2349                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2350                         + " enable = " + enable + " serviceClass = " + serviceClass);
2351             }
2352 
2353             try {
2354                 radioProxy.setCallWaiting(rr.mSerial, enable, serviceClass);
2355             } catch (RemoteException | RuntimeException e) {
2356                 handleRadioProxyExceptionForRR(rr, "setCallWaiting", e);
2357             }
2358         }
2359     }
2360 
2361     @Override
acknowledgeLastIncomingGsmSms(boolean success, int cause, Message result)2362     public void acknowledgeLastIncomingGsmSms(boolean success, int cause, Message result) {
2363         IRadio radioProxy = getRadioProxy(result);
2364         if (radioProxy != null) {
2365             RILRequest rr = obtainRequest(RIL_REQUEST_SMS_ACKNOWLEDGE, result,
2366                     mRILDefaultWorkSource);
2367 
2368             if (RILJ_LOGD) {
2369                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2370                         + " success = " + success + " cause = " + cause);
2371             }
2372 
2373             try {
2374                 radioProxy.acknowledgeLastIncomingGsmSms(rr.mSerial, success, cause);
2375             } catch (RemoteException | RuntimeException e) {
2376                 handleRadioProxyExceptionForRR(rr, "acknowledgeLastIncomingGsmSms", e);
2377             }
2378         }
2379     }
2380 
2381     @Override
acceptCall(Message result)2382     public void acceptCall(Message result) {
2383         IRadio radioProxy = getRadioProxy(result);
2384         if (radioProxy != null) {
2385             RILRequest rr = obtainRequest(RIL_REQUEST_ANSWER, result,
2386                     mRILDefaultWorkSource);
2387 
2388             if (RILJ_LOGD) {
2389                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2390             }
2391 
2392             try {
2393                 radioProxy.acceptCall(rr.mSerial);
2394                 mMetrics.writeRilAnswer(mPhoneId, rr.mSerial);
2395             } catch (RemoteException | RuntimeException e) {
2396                 handleRadioProxyExceptionForRR(rr, "acceptCall", e);
2397             }
2398         }
2399     }
2400 
2401     @Override
deactivateDataCall(int cid, int reason, Message result)2402     public void deactivateDataCall(int cid, int reason, Message result) {
2403         IRadio radioProxy = getRadioProxy(result);
2404         if (radioProxy != null) {
2405             RILRequest rr = obtainRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, result,
2406                     mRILDefaultWorkSource);
2407 
2408             if (RILJ_LOGD) {
2409                 riljLog(rr.serialString() + "> "
2410                         + requestToString(rr.mRequest) + " cid = " + cid + " reason = " + reason);
2411             }
2412 
2413             try {
2414                 if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_2)) {
2415                     android.hardware.radio.V1_2.IRadio radioProxy12 =
2416                             (android.hardware.radio.V1_2.IRadio) radioProxy;
2417 
2418                     radioProxy12.deactivateDataCall_1_2(rr.mSerial, cid, reason);
2419                 } else {
2420                     radioProxy.deactivateDataCall(rr.mSerial, cid,
2421                             (reason == DataService.REQUEST_REASON_SHUTDOWN));
2422                 }
2423                 mMetrics.writeRilDeactivateDataCall(mPhoneId, rr.mSerial, cid, reason);
2424             } catch (RemoteException | RuntimeException e) {
2425                 handleRadioProxyExceptionForRR(rr, "deactivateDataCall", e);
2426             }
2427         }
2428     }
2429 
2430     @Override
queryFacilityLock(String facility, String password, int serviceClass, Message result)2431     public void queryFacilityLock(String facility, String password, int serviceClass,
2432                                   Message result) {
2433         queryFacilityLockForApp(facility, password, serviceClass, null, result);
2434     }
2435 
2436     @Override
queryFacilityLockForApp(String facility, String password, int serviceClass, String appId, Message result)2437     public void queryFacilityLockForApp(String facility, String password, int serviceClass,
2438                                         String appId, Message result) {
2439         IRadio radioProxy = getRadioProxy(result);
2440         if (radioProxy != null) {
2441             RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_FACILITY_LOCK, result,
2442                     mRILDefaultWorkSource);
2443 
2444             if (RILJ_LOGD) {
2445                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2446                         + " facility = " + facility + " serviceClass = " + serviceClass
2447                         + " appId = " + appId);
2448             }
2449 
2450             try {
2451                 radioProxy.getFacilityLockForApp(rr.mSerial,
2452                         convertNullToEmptyString(facility),
2453                         convertNullToEmptyString(password),
2454                         serviceClass,
2455                         convertNullToEmptyString(appId));
2456             } catch (RemoteException | RuntimeException e) {
2457                 handleRadioProxyExceptionForRR(rr, "getFacilityLockForApp", e);
2458             }
2459         }
2460     }
2461 
2462     @Override
setFacilityLock(String facility, boolean lockState, String password, int serviceClass, Message result)2463     public void setFacilityLock(String facility, boolean lockState, String password,
2464                                 int serviceClass, Message result) {
2465         setFacilityLockForApp(facility, lockState, password, serviceClass, null, result);
2466     }
2467 
2468     @Override
setFacilityLockForApp(String facility, boolean lockState, String password, int serviceClass, String appId, Message result)2469     public void setFacilityLockForApp(String facility, boolean lockState, String password,
2470                                       int serviceClass, String appId, Message result) {
2471         IRadio radioProxy = getRadioProxy(result);
2472         if (radioProxy != null) {
2473             RILRequest rr = obtainRequest(RIL_REQUEST_SET_FACILITY_LOCK, result,
2474                     mRILDefaultWorkSource);
2475 
2476             if (RILJ_LOGD) {
2477                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2478                         + " facility = " + facility + " lockstate = " + lockState
2479                         + " serviceClass = " + serviceClass + " appId = " + appId);
2480             }
2481 
2482             try {
2483                 radioProxy.setFacilityLockForApp(rr.mSerial,
2484                         convertNullToEmptyString(facility),
2485                         lockState,
2486                         convertNullToEmptyString(password),
2487                         serviceClass,
2488                         convertNullToEmptyString(appId));
2489             } catch (RemoteException | RuntimeException e) {
2490                 handleRadioProxyExceptionForRR(rr, "setFacilityLockForApp", e);
2491             }
2492         }
2493     }
2494 
2495     @Override
changeBarringPassword(String facility, String oldPwd, String newPwd, Message result)2496     public void changeBarringPassword(String facility, String oldPwd, String newPwd,
2497                                       Message result) {
2498         IRadio radioProxy = getRadioProxy(result);
2499         if (radioProxy != null) {
2500             RILRequest rr = obtainRequest(RIL_REQUEST_CHANGE_BARRING_PASSWORD, result,
2501                     mRILDefaultWorkSource);
2502 
2503             // Do not log all function args for privacy
2504             if (RILJ_LOGD) {
2505                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2506                         + "facility = " + facility);
2507             }
2508 
2509             try {
2510                 radioProxy.setBarringPassword(rr.mSerial,
2511                         convertNullToEmptyString(facility),
2512                         convertNullToEmptyString(oldPwd),
2513                         convertNullToEmptyString(newPwd));
2514             } catch (RemoteException | RuntimeException e) {
2515                 handleRadioProxyExceptionForRR(rr, "changeBarringPassword", e);
2516             }
2517         }
2518     }
2519 
2520     @Override
getNetworkSelectionMode(Message result)2521     public void getNetworkSelectionMode(Message result) {
2522         IRadio radioProxy = getRadioProxy(result);
2523         if (radioProxy != null) {
2524             RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE, result,
2525                     mRILDefaultWorkSource);
2526 
2527             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2528 
2529             try {
2530                 radioProxy.getNetworkSelectionMode(rr.mSerial);
2531             } catch (RemoteException | RuntimeException e) {
2532                 handleRadioProxyExceptionForRR(rr, "getNetworkSelectionMode", e);
2533             }
2534         }
2535     }
2536 
2537     @Override
setNetworkSelectionModeAutomatic(Message result)2538     public void setNetworkSelectionModeAutomatic(Message result) {
2539         IRadio radioProxy = getRadioProxy(result);
2540         if (radioProxy != null) {
2541             RILRequest rr = obtainRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, result,
2542                     mRILDefaultWorkSource);
2543 
2544             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2545 
2546             try {
2547                 radioProxy.setNetworkSelectionModeAutomatic(rr.mSerial);
2548             } catch (RemoteException | RuntimeException e) {
2549                 handleRadioProxyExceptionForRR(rr, "setNetworkSelectionModeAutomatic", e);
2550             }
2551         }
2552     }
2553 
2554     @Override
setNetworkSelectionModeManual(String operatorNumeric, int ran, Message result)2555     public void setNetworkSelectionModeManual(String operatorNumeric, int ran, Message result) {
2556         IRadio radioProxy = getRadioProxy(result);
2557         if (radioProxy != null) {
2558             RILRequest rr = obtainRequest(RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL, result,
2559                     mRILDefaultWorkSource);
2560             try {
2561                 int halRan = convertAntToRan(ran);
2562                 if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
2563                     android.hardware.radio.V1_5.IRadio radioProxy15 =
2564                             (android.hardware.radio.V1_5.IRadio) radioProxy;
2565                     if (RILJ_LOGD) {
2566                         riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2567                                 + " operatorNumeric = " + operatorNumeric
2568                                 + ", ran = " + halRan);
2569                     }
2570                     radioProxy15.setNetworkSelectionModeManual_1_5(rr.mSerial,
2571                             convertNullToEmptyString(operatorNumeric), halRan);
2572                 } else {
2573                     if (RILJ_LOGD) {
2574                         riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2575                                 + " operatorNumeric = " + operatorNumeric);
2576                     }
2577                     radioProxy.setNetworkSelectionModeManual(rr.mSerial,
2578                             convertNullToEmptyString(operatorNumeric));
2579                 }
2580             } catch (RemoteException | RuntimeException e) {
2581                 handleRadioProxyExceptionForRR(rr, "setNetworkSelectionModeManual", e);
2582             }
2583         }
2584     }
2585 
2586     @Override
getAvailableNetworks(Message result)2587     public void getAvailableNetworks(Message result) {
2588         IRadio radioProxy = getRadioProxy(result);
2589         if (radioProxy != null) {
2590             RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_AVAILABLE_NETWORKS, result,
2591                     mRILDefaultWorkSource);
2592 
2593             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2594 
2595             try {
2596                 radioProxy.getAvailableNetworks(rr.mSerial);
2597             } catch (RemoteException | RuntimeException e) {
2598                 handleRadioProxyExceptionForRR(rr, "getAvailableNetworks", e);
2599             }
2600         }
2601     }
2602 
convertRadioAccessSpecifierToRadioHAL( RadioAccessSpecifier ras)2603     private android.hardware.radio.V1_1.RadioAccessSpecifier convertRadioAccessSpecifierToRadioHAL(
2604             RadioAccessSpecifier ras) {
2605         android.hardware.radio.V1_1.RadioAccessSpecifier rasInHalFormat =
2606                 new android.hardware.radio.V1_1.RadioAccessSpecifier();
2607         rasInHalFormat.radioAccessNetwork = ras.getRadioAccessNetwork();
2608         ArrayList<Integer> bands = new ArrayList<>();
2609         if (ras.getBands() != null) {
2610             for (int band : ras.getBands()) {
2611                 bands.add(band);
2612             }
2613         }
2614         switch (ras.getRadioAccessNetwork()) {
2615             case AccessNetworkType.GERAN:
2616                 rasInHalFormat.geranBands = bands;
2617                 break;
2618             case AccessNetworkType.UTRAN:
2619                 rasInHalFormat.utranBands = bands;
2620                 break;
2621             case AccessNetworkType.EUTRAN:
2622                 rasInHalFormat.eutranBands = bands;
2623                 break;
2624             default:
2625                 Log.wtf(RILJ_LOG_TAG, "radioAccessNetwork " + ras.getRadioAccessNetwork()
2626                         + " not supported on IRadio < 1.5!");
2627                 return null;
2628         }
2629 
2630         if (ras.getChannels() != null) {
2631             for (int channel : ras.getChannels()) {
2632                 rasInHalFormat.channels.add(channel);
2633             }
2634         }
2635 
2636         return rasInHalFormat;
2637     }
2638 
2639     private android.hardware.radio.V1_5.RadioAccessSpecifier
convertRadioAccessSpecifierToRadioHAL_1_5(RadioAccessSpecifier ras)2640             convertRadioAccessSpecifierToRadioHAL_1_5(RadioAccessSpecifier ras) {
2641         android.hardware.radio.V1_5.RadioAccessSpecifier rasInHalFormat =
2642                 new android.hardware.radio.V1_5.RadioAccessSpecifier();
2643         android.hardware.radio.V1_5.RadioAccessSpecifier.Bands bandsInHalFormat =
2644                 new android.hardware.radio.V1_5.RadioAccessSpecifier.Bands();
2645         rasInHalFormat.radioAccessNetwork = convertAntToRan(ras.getRadioAccessNetwork());
2646         ArrayList<Integer> bands = new ArrayList<>();
2647         if (ras.getBands() != null) {
2648             for (int band : ras.getBands()) {
2649                 bands.add(band);
2650             }
2651         }
2652         switch (ras.getRadioAccessNetwork()) {
2653             case AccessNetworkType.GERAN:
2654                 bandsInHalFormat.geranBands(bands);
2655                 break;
2656             case AccessNetworkType.UTRAN:
2657                 bandsInHalFormat.utranBands(bands);
2658                 break;
2659             case AccessNetworkType.EUTRAN:
2660                 bandsInHalFormat.eutranBands(bands);
2661                 break;
2662             case AccessNetworkType.NGRAN:
2663                 bandsInHalFormat.ngranBands(bands);
2664                 break;
2665             default:
2666                 Log.wtf(RILJ_LOG_TAG, "radioAccessNetwork " + ras.getRadioAccessNetwork()
2667                         + " not supported on IRadio 1.5!");
2668                 return null;
2669         }
2670         rasInHalFormat.bands = bandsInHalFormat;
2671 
2672         if (ras.getChannels() != null) {
2673             for (int channel : ras.getChannels()) {
2674                 rasInHalFormat.channels.add(channel);
2675             }
2676         }
2677 
2678         return rasInHalFormat;
2679     }
2680 
2681     /**
2682      * Radio HAL fallback compatibility feature (b/151106728) assumes that the input parameter
2683      * networkScanRequest is immutable (read-only) here. Once the caller invokes the method, the
2684      * parameter networkScanRequest should not be modified. This helps us keep a consistent and
2685      * simple data model that avoid copying it in the scan result.
2686      */
2687     @Override
startNetworkScan(NetworkScanRequest networkScanRequest, Message result)2688     public void startNetworkScan(NetworkScanRequest networkScanRequest, Message result) {
2689         final NetworkScanRequest nsr = networkScanRequest;
2690         IRadio radioProxy = getRadioProxy(result);
2691         if (radioProxy != null) {
2692 
2693             HalVersion overrideHalVersion = getCompatVersion(RIL_REQUEST_START_NETWORK_SCAN);
2694             if (RILJ_LOGD) {
2695                 riljLog("startNetworkScan: overrideHalVersion=" + overrideHalVersion);
2696             }
2697             if ((overrideHalVersion == null
2698                         || overrideHalVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5))
2699                     && mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
2700                 android.hardware.radio.V1_5.NetworkScanRequest request =
2701                         new android.hardware.radio.V1_5.NetworkScanRequest();
2702                 request.type = nsr.getScanType();
2703                 request.interval = nsr.getSearchPeriodicity();
2704                 request.maxSearchTime = nsr.getMaxSearchTime();
2705                 request.incrementalResultsPeriodicity = nsr.getIncrementalResultsPeriodicity();
2706                 request.incrementalResults = nsr.getIncrementalResults();
2707 
2708                 for (RadioAccessSpecifier ras : nsr.getSpecifiers()) {
2709                     android.hardware.radio.V1_5.RadioAccessSpecifier rasInHalFormat =
2710                             convertRadioAccessSpecifierToRadioHAL_1_5(ras);
2711                     if (rasInHalFormat == null) {
2712                         AsyncResult.forMessage(result, null,
2713                                 CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
2714                         result.sendToTarget();
2715                         return;
2716                     }
2717                     request.specifiers.add(rasInHalFormat);
2718                 }
2719 
2720                 request.mccMncs.addAll(nsr.getPlmns());
2721                 RILRequest rr = obtainRequest(RIL_REQUEST_START_NETWORK_SCAN, result,
2722                         mRILDefaultWorkSource, nsr);
2723 
2724                 if (RILJ_LOGD) {
2725                     riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2726                 }
2727 
2728                 try {
2729                     android.hardware.radio.V1_5.IRadio radioProxy15 =
2730                             (android.hardware.radio.V1_5.IRadio) radioProxy;
2731                     radioProxy15.startNetworkScan_1_5(rr.mSerial, request);
2732                 } catch (RemoteException | RuntimeException e) {
2733                     handleRadioProxyExceptionForRR(rr, "startNetworkScan", e);
2734                 }
2735             } else if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_2)) {
2736                 android.hardware.radio.V1_2.NetworkScanRequest request =
2737                         new android.hardware.radio.V1_2.NetworkScanRequest();
2738                 request.type = nsr.getScanType();
2739                 request.interval = nsr.getSearchPeriodicity();
2740                 request.maxSearchTime = nsr.getMaxSearchTime();
2741                 request.incrementalResultsPeriodicity = nsr.getIncrementalResultsPeriodicity();
2742                 request.incrementalResults = nsr.getIncrementalResults();
2743 
2744                 for (RadioAccessSpecifier ras : nsr.getSpecifiers()) {
2745 
2746                     android.hardware.radio.V1_1.RadioAccessSpecifier rasInHalFormat =
2747                             convertRadioAccessSpecifierToRadioHAL(ras);
2748                     if (rasInHalFormat == null) {
2749                         AsyncResult.forMessage(result, null,
2750                                 CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
2751                         result.sendToTarget();
2752                         return;
2753                     }
2754 
2755                     request.specifiers.add(rasInHalFormat);
2756                 }
2757 
2758                 request.mccMncs.addAll(nsr.getPlmns());
2759                 RILRequest rr = obtainRequest(RIL_REQUEST_START_NETWORK_SCAN, result,
2760                         mRILDefaultWorkSource);
2761 
2762                 if (RILJ_LOGD) {
2763                     riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2764                 }
2765 
2766                 try {
2767                     if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_4)) {
2768                         android.hardware.radio.V1_4.IRadio radioProxy14 =
2769                                 (android.hardware.radio.V1_4.IRadio) radioProxy;
2770                         radioProxy14.startNetworkScan_1_4(rr.mSerial, request);
2771                     } else {
2772                         android.hardware.radio.V1_2.IRadio radioProxy12 =
2773                                 (android.hardware.radio.V1_2.IRadio) radioProxy;
2774                         radioProxy12.startNetworkScan_1_2(rr.mSerial, request);
2775                     }
2776                 } catch (RemoteException | RuntimeException e) {
2777                     handleRadioProxyExceptionForRR(rr, "startNetworkScan", e);
2778                 }
2779             } else if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_1)) {
2780                 android.hardware.radio.V1_1.IRadio radioProxy11 =
2781                         (android.hardware.radio.V1_1.IRadio) radioProxy;
2782 
2783                 android.hardware.radio.V1_1.NetworkScanRequest request =
2784                         new android.hardware.radio.V1_1.NetworkScanRequest();
2785                 request.type = nsr.getScanType();
2786                 request.interval = nsr.getSearchPeriodicity();
2787                 for (RadioAccessSpecifier ras : nsr.getSpecifiers()) {
2788                     android.hardware.radio.V1_1.RadioAccessSpecifier rasInHalFormat =
2789                             convertRadioAccessSpecifierToRadioHAL(ras);
2790                     if (rasInHalFormat == null) {
2791                         AsyncResult.forMessage(result, null,
2792                                 CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
2793                         result.sendToTarget();
2794                         return;
2795                     }
2796 
2797                     request.specifiers.add(rasInHalFormat);
2798                 }
2799 
2800                 RILRequest rr = obtainRequest(RIL_REQUEST_START_NETWORK_SCAN, result,
2801                         mRILDefaultWorkSource);
2802 
2803                 if (RILJ_LOGD) {
2804                     riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2805                 }
2806 
2807                 try {
2808                     radioProxy11.startNetworkScan(rr.mSerial, request);
2809                 } catch (RemoteException | RuntimeException e) {
2810                     handleRadioProxyExceptionForRR(rr, "startNetworkScan", e);
2811                 }
2812             } else if (result != null) {
2813                 AsyncResult.forMessage(result, null,
2814                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
2815                 result.sendToTarget();
2816             }
2817         }
2818     }
2819 
2820     @Override
stopNetworkScan(Message result)2821     public void stopNetworkScan(Message result) {
2822         IRadio radioProxy = getRadioProxy(result);
2823         if (radioProxy != null) {
2824             if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_1)) {
2825                 android.hardware.radio.V1_1.IRadio radioProxy11 =
2826                         (android.hardware.radio.V1_1.IRadio) radioProxy;
2827 
2828                 RILRequest rr = obtainRequest(RIL_REQUEST_STOP_NETWORK_SCAN, result,
2829                         mRILDefaultWorkSource);
2830 
2831                 if (RILJ_LOGD) {
2832                     riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2833                 }
2834 
2835                 try {
2836                     radioProxy11.stopNetworkScan(rr.mSerial);
2837                 } catch (RemoteException | RuntimeException e) {
2838                     handleRadioProxyExceptionForRR(rr, "stopNetworkScan", e);
2839                 }
2840             } else if (result != null) {
2841                 AsyncResult.forMessage(result, null,
2842                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
2843                 result.sendToTarget();
2844             }
2845         }
2846     }
2847 
2848     @Override
startDtmf(char c, Message result)2849     public void startDtmf(char c, Message result) {
2850         IRadio radioProxy = getRadioProxy(result);
2851         if (radioProxy != null) {
2852             RILRequest rr = obtainRequest(RIL_REQUEST_DTMF_START, result,
2853                     mRILDefaultWorkSource);
2854 
2855             // Do not log function arg for privacy
2856             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2857 
2858             try {
2859                 radioProxy.startDtmf(rr.mSerial, c + "");
2860             } catch (RemoteException | RuntimeException e) {
2861                 handleRadioProxyExceptionForRR(rr, "startDtmf", e);
2862             }
2863         }
2864     }
2865 
2866     @Override
stopDtmf(Message result)2867     public void stopDtmf(Message result) {
2868         IRadio radioProxy = getRadioProxy(result);
2869         if (radioProxy != null) {
2870             RILRequest rr = obtainRequest(RIL_REQUEST_DTMF_STOP, result,
2871                     mRILDefaultWorkSource);
2872 
2873             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2874 
2875             try {
2876                 radioProxy.stopDtmf(rr.mSerial);
2877             } catch (RemoteException | RuntimeException e) {
2878                 handleRadioProxyExceptionForRR(rr, "stopDtmf", e);
2879             }
2880         }
2881     }
2882 
2883     @Override
separateConnection(int gsmIndex, Message result)2884     public void separateConnection(int gsmIndex, Message result) {
2885         IRadio radioProxy = getRadioProxy(result);
2886         if (radioProxy != null) {
2887             RILRequest rr = obtainRequest(RIL_REQUEST_SEPARATE_CONNECTION, result,
2888                     mRILDefaultWorkSource);
2889 
2890             if (RILJ_LOGD) {
2891                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2892                         + " gsmIndex = " + gsmIndex);
2893             }
2894 
2895             try {
2896                 radioProxy.separateConnection(rr.mSerial, gsmIndex);
2897             } catch (RemoteException | RuntimeException e) {
2898                 handleRadioProxyExceptionForRR(rr, "separateConnection", e);
2899             }
2900         }
2901     }
2902 
2903     @Override
getBasebandVersion(Message result)2904     public void getBasebandVersion(Message result) {
2905         IRadio radioProxy = getRadioProxy(result);
2906         if (radioProxy != null) {
2907             RILRequest rr = obtainRequest(RIL_REQUEST_BASEBAND_VERSION, result,
2908                     mRILDefaultWorkSource);
2909 
2910             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2911 
2912             try {
2913                 radioProxy.getBasebandVersion(rr.mSerial);
2914             } catch (RemoteException | RuntimeException e) {
2915                 handleRadioProxyExceptionForRR(rr, "getBasebandVersion", e);
2916             }
2917         }
2918     }
2919 
2920     @Override
setMute(boolean enableMute, Message result)2921     public void setMute(boolean enableMute, Message result) {
2922         IRadio radioProxy = getRadioProxy(result);
2923         if (radioProxy != null) {
2924             RILRequest rr = obtainRequest(RIL_REQUEST_SET_MUTE, result,
2925                     mRILDefaultWorkSource);
2926 
2927             if (RILJ_LOGD) {
2928                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2929                         + " enableMute = " + enableMute);
2930             }
2931 
2932             try {
2933                 radioProxy.setMute(rr.mSerial, enableMute);
2934             } catch (RemoteException | RuntimeException e) {
2935                 handleRadioProxyExceptionForRR(rr, "setMute", e);
2936             }
2937         }
2938     }
2939 
2940     @Override
getMute(Message result)2941     public void getMute(Message result) {
2942         IRadio radioProxy = getRadioProxy(result);
2943         if (radioProxy != null) {
2944             RILRequest rr = obtainRequest(RIL_REQUEST_GET_MUTE, result,
2945                     mRILDefaultWorkSource);
2946 
2947             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2948 
2949             try {
2950                 radioProxy.getMute(rr.mSerial);
2951             } catch (RemoteException | RuntimeException e) {
2952                 handleRadioProxyExceptionForRR(rr, "getMute", e);
2953             }
2954         }
2955     }
2956 
2957     @Override
queryCLIP(Message result)2958     public void queryCLIP(Message result) {
2959         IRadio radioProxy = getRadioProxy(result);
2960         if (radioProxy != null) {
2961             RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_CLIP, result,
2962                     mRILDefaultWorkSource);
2963 
2964             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2965 
2966             try {
2967                 radioProxy.getClip(rr.mSerial);
2968             } catch (RemoteException | RuntimeException e) {
2969                 handleRadioProxyExceptionForRR(rr, "queryCLIP", e);
2970             }
2971         }
2972     }
2973 
2974     /**
2975      * @deprecated
2976      */
2977     @Override
2978     @Deprecated
getPDPContextList(Message result)2979     public void getPDPContextList(Message result) {
2980         getDataCallList(result);
2981     }
2982 
2983     @Override
getDataCallList(Message result)2984     public void getDataCallList(Message result) {
2985         IRadio radioProxy = getRadioProxy(result);
2986         if (radioProxy != null) {
2987             RILRequest rr = obtainRequest(RIL_REQUEST_DATA_CALL_LIST, result,
2988                     mRILDefaultWorkSource);
2989 
2990             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2991 
2992             try {
2993                 if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
2994                     android.hardware.radio.V1_6.IRadio radioProxy16 =
2995                             (android.hardware.radio.V1_6.IRadio) radioProxy;
2996                     radioProxy16.getDataCallList_1_6(rr.mSerial);
2997                 } else {
2998                     radioProxy.getDataCallList(rr.mSerial);
2999                 }
3000             } catch (RemoteException | RuntimeException e) {
3001                 handleRadioProxyExceptionForRR(rr, "getDataCallList", e);
3002             }
3003         }
3004     }
3005 
3006     // TODO(b/171260715) Remove when HAL definition is removed
3007     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
3008     @Override
invokeOemRilRequestRaw(byte[] data, Message response)3009     public void invokeOemRilRequestRaw(byte[] data, Message response) {
3010     }
3011 
3012     // TODO(b/171260715) Remove when HAL definition is removed
3013     @Override
invokeOemRilRequestStrings(String[] strings, Message result)3014     public void invokeOemRilRequestStrings(String[] strings, Message result) {
3015     }
3016 
3017     @Override
setSuppServiceNotifications(boolean enable, Message result)3018     public void setSuppServiceNotifications(boolean enable, Message result) {
3019         IRadio radioProxy = getRadioProxy(result);
3020         if (radioProxy != null) {
3021             RILRequest rr = obtainRequest(RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION, result,
3022                     mRILDefaultWorkSource);
3023 
3024             if (RILJ_LOGD) {
3025                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " enable = "
3026                         + enable);
3027             }
3028 
3029             try {
3030                 radioProxy.setSuppServiceNotifications(rr.mSerial, enable);
3031             } catch (RemoteException | RuntimeException e) {
3032                 handleRadioProxyExceptionForRR(rr, "setSuppServiceNotifications", e);
3033             }
3034         }
3035     }
3036 
3037     @Override
writeSmsToSim(int status, String smsc, String pdu, Message result)3038     public void writeSmsToSim(int status, String smsc, String pdu, Message result) {
3039         status = translateStatus(status);
3040         IRadio radioProxy = getRadioProxy(result);
3041         if (radioProxy != null) {
3042             RILRequest rr = obtainRequest(RIL_REQUEST_WRITE_SMS_TO_SIM, result,
3043                     mRILDefaultWorkSource);
3044 
3045             if (RILJ_LOGV) {
3046                 riljLog(rr.serialString() + "> "
3047                         + requestToString(rr.mRequest)
3048                         + " " + status);
3049             }
3050 
3051             SmsWriteArgs args = new SmsWriteArgs();
3052             args.status = status;
3053             args.smsc = convertNullToEmptyString(smsc);
3054             args.pdu = convertNullToEmptyString(pdu);
3055 
3056             try {
3057                 radioProxy.writeSmsToSim(rr.mSerial, args);
3058             } catch (RemoteException | RuntimeException e) {
3059                 handleRadioProxyExceptionForRR(rr, "writeSmsToSim", e);
3060             }
3061         }
3062     }
3063 
3064     @Override
deleteSmsOnSim(int index, Message result)3065     public void deleteSmsOnSim(int index, Message result) {
3066         IRadio radioProxy = getRadioProxy(result);
3067         if (radioProxy != null) {
3068             RILRequest rr = obtainRequest(RIL_REQUEST_DELETE_SMS_ON_SIM, result,
3069                     mRILDefaultWorkSource);
3070 
3071             if (RILJ_LOGV) {
3072                 riljLog(rr.serialString() + "> "
3073                         + requestToString(rr.mRequest) + " index = " + index);
3074             }
3075 
3076             try {
3077                 radioProxy.deleteSmsOnSim(rr.mSerial, index);
3078             } catch (RemoteException | RuntimeException e) {
3079                 handleRadioProxyExceptionForRR(rr, "deleteSmsOnSim", e);
3080             }
3081         }
3082     }
3083 
3084     @Override
setBandMode(int bandMode, Message result)3085     public void setBandMode(int bandMode, Message result) {
3086         IRadio radioProxy = getRadioProxy(result);
3087         if (radioProxy != null) {
3088             RILRequest rr = obtainRequest(RIL_REQUEST_SET_BAND_MODE, result,
3089                     mRILDefaultWorkSource);
3090 
3091             if (RILJ_LOGD) {
3092                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
3093                         + " bandMode = " + bandMode);
3094             }
3095 
3096             try {
3097                 radioProxy.setBandMode(rr.mSerial, bandMode);
3098             } catch (RemoteException | RuntimeException e) {
3099                 handleRadioProxyExceptionForRR(rr, "setBandMode", e);
3100             }
3101         }
3102     }
3103 
3104     @Override
queryAvailableBandMode(Message result)3105     public void queryAvailableBandMode(Message result) {
3106         IRadio radioProxy = getRadioProxy(result);
3107         if (radioProxy != null) {
3108             RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE, result,
3109                     mRILDefaultWorkSource);
3110 
3111             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
3112 
3113             try {
3114                 radioProxy.getAvailableBandModes(rr.mSerial);
3115             } catch (RemoteException | RuntimeException e) {
3116                 handleRadioProxyExceptionForRR(rr, "queryAvailableBandMode", e);
3117             }
3118         }
3119     }
3120 
3121     @Override
sendEnvelope(String contents, Message result)3122     public void sendEnvelope(String contents, Message result) {
3123         IRadio radioProxy = getRadioProxy(result);
3124         if (radioProxy != null) {
3125             RILRequest rr = obtainRequest(RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND, result,
3126                     mRILDefaultWorkSource);
3127 
3128             if (RILJ_LOGD) {
3129                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " contents = "
3130                         + contents);
3131             }
3132 
3133             try {
3134                 radioProxy.sendEnvelope(rr.mSerial, convertNullToEmptyString(contents));
3135             } catch (RemoteException | RuntimeException e) {
3136                 handleRadioProxyExceptionForRR(rr, "sendEnvelope", e);
3137             }
3138         }
3139     }
3140 
3141     @Override
sendTerminalResponse(String contents, Message result)3142     public void sendTerminalResponse(String contents, Message result) {
3143         IRadio radioProxy = getRadioProxy(result);
3144         if (radioProxy != null) {
3145             RILRequest rr = obtainRequest(RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE, result,
3146                     mRILDefaultWorkSource);
3147 
3148             if (RILJ_LOGD) {
3149                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " contents = "
3150                         + (TelephonyUtils.IS_DEBUGGABLE
3151                             ? contents : censoredTerminalResponse(contents)));
3152             }
3153 
3154             try {
3155                 radioProxy.sendTerminalResponseToSim(rr.mSerial,
3156                         convertNullToEmptyString(contents));
3157             } catch (RemoteException | RuntimeException e) {
3158                 handleRadioProxyExceptionForRR(rr, "sendTerminalResponse", e);
3159             }
3160         }
3161     }
3162 
censoredTerminalResponse(String terminalResponse)3163     private String censoredTerminalResponse(String terminalResponse) {
3164         try {
3165             byte[] bytes = IccUtils.hexStringToBytes(terminalResponse);
3166             if (bytes != null) {
3167                 List<ComprehensionTlv> ctlvs = ComprehensionTlv.decodeMany(bytes, 0);
3168                 int from = 0;
3169                 for (ComprehensionTlv ctlv : ctlvs) {
3170                     // Find text strings which might be personal information input by user,
3171                     // then replace it with "********".
3172                     if (ComprehensionTlvTag.TEXT_STRING.value() == ctlv.getTag()) {
3173                         byte[] target = Arrays.copyOfRange(ctlv.getRawValue(), from,
3174                                 ctlv.getValueIndex() + ctlv.getLength());
3175                         terminalResponse = terminalResponse.toLowerCase().replace(
3176                                 IccUtils.bytesToHexString(target).toLowerCase(), "********");
3177                     }
3178                     // The text string tag and the length field should also be hidden.
3179                     from = ctlv.getValueIndex() + ctlv.getLength();
3180                 }
3181             }
3182         } catch (Exception e) {
3183             Rlog.e(RILJ_LOG_TAG, "Could not censor the terminal response: " + e);
3184             terminalResponse = null;
3185         }
3186 
3187         return terminalResponse;
3188     }
3189 
3190     @Override
sendEnvelopeWithStatus(String contents, Message result)3191     public void sendEnvelopeWithStatus(String contents, Message result) {
3192         IRadio radioProxy = getRadioProxy(result);
3193         if (radioProxy != null) {
3194             RILRequest rr = obtainRequest(RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS, result,
3195                     mRILDefaultWorkSource);
3196 
3197             if (RILJ_LOGD) {
3198                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " contents = "
3199                         + contents);
3200             }
3201 
3202             try {
3203                 radioProxy.sendEnvelopeWithStatus(rr.mSerial, convertNullToEmptyString(contents));
3204             } catch (RemoteException | RuntimeException e) {
3205                 handleRadioProxyExceptionForRR(rr, "sendEnvelopeWithStatus", e);
3206             }
3207         }
3208     }
3209 
3210     @Override
explicitCallTransfer(Message result)3211     public void explicitCallTransfer(Message result) {
3212         IRadio radioProxy = getRadioProxy(result);
3213         if (radioProxy != null) {
3214             RILRequest rr = obtainRequest(RIL_REQUEST_EXPLICIT_CALL_TRANSFER, result,
3215                     mRILDefaultWorkSource);
3216 
3217             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
3218 
3219             try {
3220                 radioProxy.explicitCallTransfer(rr.mSerial);
3221             } catch (RemoteException | RuntimeException e) {
3222                 handleRadioProxyExceptionForRR(rr, "explicitCallTransfer", e);
3223             }
3224         }
3225     }
3226 
3227     @Override
setPreferredNetworkType(@refNetworkMode int networkType , Message result)3228     public void setPreferredNetworkType(@PrefNetworkMode int networkType , Message result) {
3229         IRadio radioProxy = getRadioProxy(result);
3230         if (radioProxy != null) {
3231             RILRequest rr = obtainRequest(RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE, result,
3232                     mRILDefaultWorkSource);
3233 
3234             if (RILJ_LOGD) {
3235                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
3236                         + " networkType = " + networkType);
3237             }
3238             mAllowedNetworkTypesBitmask = RadioAccessFamily.getRafFromNetworkType(networkType);
3239             mMetrics.writeSetPreferredNetworkType(mPhoneId, networkType);
3240 
3241             if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_4)) {
3242                 android.hardware.radio.V1_4.IRadio radioProxy14 =
3243                         (android.hardware.radio.V1_4.IRadio) radioProxy;
3244                 try {
3245                     radioProxy14.setPreferredNetworkTypeBitmap(
3246                             rr.mSerial, convertToHalRadioAccessFamily(mAllowedNetworkTypesBitmask));
3247                 } catch (RemoteException | RuntimeException e) {
3248                     handleRadioProxyExceptionForRR(rr, "setPreferredNetworkTypeBitmap", e);
3249                 }
3250             } else {
3251                 try {
3252                     radioProxy.setPreferredNetworkType(rr.mSerial, networkType);
3253                 } catch (RemoteException | RuntimeException e) {
3254                     handleRadioProxyExceptionForRR(rr, "setPreferredNetworkType", e);
3255                 }
3256             }
3257         }
3258     }
3259 
3260     /**
3261      * convert RAF from {@link android.hardware.radio.V1_0.RadioAccessFamily} to
3262      * {@link TelephonyManager.NetworkTypeBitMask}, the bitmask represented by
3263      * {@link android.telephony.Annotation.NetworkType}.
3264      *
3265      * @param raf {@link android.hardware.radio.V1_0.RadioAccessFamily}
3266      * @return {@link TelephonyManager.NetworkTypeBitMask}
3267      */
3268     @TelephonyManager.NetworkTypeBitMask
convertToNetworkTypeBitMask(int raf)3269     public static int convertToNetworkTypeBitMask(int raf) {
3270         int networkTypeRaf = 0;
3271 
3272         if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.GSM) != 0) {
3273             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_GSM;
3274         }
3275         if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.GPRS) != 0) {
3276             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_GPRS;
3277         }
3278         if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.EDGE) != 0) {
3279             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_EDGE;
3280         }
3281         // convert both IS95A/IS95B to CDMA as network mode doesn't support CDMA
3282         if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.IS95A) != 0) {
3283             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_CDMA;
3284         }
3285         if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.IS95B) != 0) {
3286             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_CDMA;
3287         }
3288         if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.ONE_X_RTT) != 0) {
3289             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_1xRTT;
3290         }
3291         if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.EVDO_0) != 0) {
3292             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_0;
3293         }
3294         if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.EVDO_A) != 0) {
3295             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_A;
3296         }
3297         if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.EVDO_B) != 0) {
3298             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_B;
3299         }
3300         if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.EHRPD) != 0) {
3301             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_EHRPD;
3302         }
3303         if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.HSUPA) != 0) {
3304             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_HSUPA;
3305         }
3306         if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.HSDPA) != 0) {
3307             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_HSDPA;
3308         }
3309         if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.HSPA) != 0) {
3310             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_HSPA;
3311         }
3312         if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.HSPAP) != 0) {
3313             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_HSPAP;
3314         }
3315         if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.UMTS) != 0) {
3316             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_UMTS;
3317         }
3318         if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.TD_SCDMA) != 0) {
3319             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA;
3320         }
3321         if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.LTE) != 0) {
3322             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_LTE;
3323         }
3324         if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.LTE_CA) != 0) {
3325             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_LTE_CA;
3326         }
3327         if ((raf & android.hardware.radio.V1_4.RadioAccessFamily.NR) != 0) {
3328             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_NR;
3329         }
3330         // TODO: need hal definition
3331         if ((raf & (1 << ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN)) != 0) {
3332             networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_IWLAN;
3333         }
3334         return (networkTypeRaf == 0) ? TelephonyManager.NETWORK_TYPE_UNKNOWN : networkTypeRaf;
3335     }
3336 
3337     // convert to android.hardware.radio.V1_0.RadioAccessFamily
convertToHalRadioAccessFamily( @elephonyManager.NetworkTypeBitMask int networkTypeBitmask)3338     private static int convertToHalRadioAccessFamily(
3339             @TelephonyManager.NetworkTypeBitMask int networkTypeBitmask) {
3340         int raf = 0;
3341 
3342         if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_GSM) != 0) {
3343             raf |= android.hardware.radio.V1_0.RadioAccessFamily.GSM;
3344         }
3345         if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_GPRS) != 0) {
3346             raf |= android.hardware.radio.V1_0.RadioAccessFamily.GPRS;
3347         }
3348         if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_EDGE) != 0) {
3349             raf |= android.hardware.radio.V1_0.RadioAccessFamily.EDGE;
3350         }
3351         // convert CDMA to IS95A, consistent with ServiceState.networkTypeToRilRadioTechnology
3352         if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_CDMA) != 0) {
3353             raf |= android.hardware.radio.V1_0.RadioAccessFamily.IS95A;
3354         }
3355         if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_1xRTT) != 0) {
3356             raf |= android.hardware.radio.V1_0.RadioAccessFamily.ONE_X_RTT;
3357         }
3358         if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_0) != 0) {
3359             raf |= android.hardware.radio.V1_0.RadioAccessFamily.EVDO_0;
3360         }
3361         if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_A) != 0) {
3362             raf |= android.hardware.radio.V1_0.RadioAccessFamily.EVDO_A;
3363         }
3364         if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_B) != 0) {
3365             raf |= android.hardware.radio.V1_0.RadioAccessFamily.EVDO_B;
3366         }
3367         if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_EHRPD) != 0) {
3368             raf |= android.hardware.radio.V1_0.RadioAccessFamily.EHRPD;
3369         }
3370         if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_HSUPA) != 0) {
3371             raf |= android.hardware.radio.V1_0.RadioAccessFamily.HSUPA;
3372         }
3373         if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_HSDPA) != 0) {
3374             raf |= android.hardware.radio.V1_0.RadioAccessFamily.HSDPA;
3375         }
3376         if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_HSPA) != 0) {
3377             raf |= android.hardware.radio.V1_0.RadioAccessFamily.HSPA;
3378         }
3379         if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_HSPAP) != 0) {
3380             raf |= android.hardware.radio.V1_0.RadioAccessFamily.HSPAP;
3381         }
3382         if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_UMTS) != 0) {
3383             raf |= android.hardware.radio.V1_0.RadioAccessFamily.UMTS;
3384         }
3385         if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA) != 0) {
3386             raf |= android.hardware.radio.V1_0.RadioAccessFamily.TD_SCDMA;
3387         }
3388         if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_LTE) != 0) {
3389             raf |= android.hardware.radio.V1_0.RadioAccessFamily.LTE;
3390         }
3391         if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_LTE_CA) != 0) {
3392             raf |= android.hardware.radio.V1_0.RadioAccessFamily.LTE_CA;
3393         }
3394         if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_NR) != 0) {
3395             raf |= android.hardware.radio.V1_4.RadioAccessFamily.NR;
3396         }
3397         // TODO: need hal definition for IWLAN
3398         return (raf == 0) ? android.hardware.radio.V1_4.RadioAccessFamily.UNKNOWN : raf;
3399     }
3400 
3401     @Override
getPreferredNetworkType(Message result)3402     public void getPreferredNetworkType(Message result) {
3403         IRadio radioProxy = getRadioProxy(result);
3404         if (radioProxy != null) {
3405             RILRequest rr = obtainRequest(RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE, result,
3406                     mRILDefaultWorkSource);
3407             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
3408             if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_4)) {
3409                 android.hardware.radio.V1_4.IRadio radioProxy14 =
3410                         (android.hardware.radio.V1_4.IRadio) radioProxy;
3411                 try {
3412                     radioProxy14.getPreferredNetworkTypeBitmap(rr.mSerial);
3413                 } catch (RemoteException | RuntimeException e) {
3414                     handleRadioProxyExceptionForRR(rr, "getPreferredNetworkTypeBitmap", e);
3415                 }
3416             } else {
3417                 try {
3418                     radioProxy.getPreferredNetworkType(rr.mSerial);
3419                 } catch (RemoteException | RuntimeException e) {
3420                     handleRadioProxyExceptionForRR(rr, "getPreferredNetworkType", e);
3421                 }
3422             }
3423         }
3424     }
3425 
3426     @Override
setAllowedNetworkTypesBitmap( @elephonyManager.NetworkTypeBitMask int networkTypeBitmask, Message result)3427     public void setAllowedNetworkTypesBitmap(
3428             @TelephonyManager.NetworkTypeBitMask int networkTypeBitmask, Message result) {
3429         IRadio radioProxy = getRadioProxy(result);
3430         if (radioProxy != null) {
3431             if (mRadioVersion.less(RADIO_HAL_VERSION_1_6)) {
3432                 // For older HAL, redirects the call to setPreferredNetworkType.
3433                 setPreferredNetworkType(
3434                         RadioAccessFamily.getNetworkTypeFromRaf(networkTypeBitmask), result);
3435                 return;
3436             }
3437 
3438             android.hardware.radio.V1_6.IRadio radioProxy16 =
3439                     (android.hardware.radio.V1_6.IRadio) radioProxy;
3440             RILRequest rr = obtainRequest(RIL_REQUEST_SET_ALLOWED_NETWORK_TYPES_BITMAP, result,
3441                     mRILDefaultWorkSource);
3442 
3443             if (RILJ_LOGD) {
3444                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
3445             }
3446             mAllowedNetworkTypesBitmask = networkTypeBitmask;
3447             try {
3448                 radioProxy16.setAllowedNetworkTypesBitmap(rr.mSerial,
3449                         convertToHalRadioAccessFamily(mAllowedNetworkTypesBitmask));
3450             } catch (RemoteException | RuntimeException e) {
3451                 handleRadioProxyExceptionForRR(rr, "setAllowedNetworkTypeBitmask", e);
3452             }
3453         }
3454     }
3455 
3456     @Override
getAllowedNetworkTypesBitmap(Message result)3457     public void getAllowedNetworkTypesBitmap(Message result) {
3458         IRadio radioProxy = getRadioProxy(result);
3459         if (radioProxy != null) {
3460             if (mRadioVersion.less(RADIO_HAL_VERSION_1_6)) {
3461                 // For older HAL, redirects the call to getPreferredNetworkType.
3462                 getPreferredNetworkType(result);
3463                 return;
3464             }
3465 
3466             android.hardware.radio.V1_6.IRadio radioProxy16 =
3467                     (android.hardware.radio.V1_6.IRadio) radioProxy;
3468             RILRequest rr = obtainRequest(RIL_REQUEST_GET_ALLOWED_NETWORK_TYPES_BITMAP, result,
3469                     mRILDefaultWorkSource);
3470 
3471             if (RILJ_LOGD) {
3472                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
3473             }
3474 
3475             try {
3476                 radioProxy16.getAllowedNetworkTypesBitmap(rr.mSerial);
3477             } catch (RemoteException | RuntimeException e) {
3478                 handleRadioProxyExceptionForRR(rr, "getAllowedNetworkTypeBitmask", e);
3479             }
3480         }
3481     }
3482 
3483     @Override
setLocationUpdates(boolean enable, WorkSource workSource, Message result)3484     public void setLocationUpdates(boolean enable, WorkSource workSource, Message result) {
3485         IRadio radioProxy = getRadioProxy(result);
3486         if (radioProxy != null) {
3487             RILRequest rr = obtainRequest(RIL_REQUEST_SET_LOCATION_UPDATES, result,
3488                     workSource == null ? mRILDefaultWorkSource : workSource);
3489 
3490             if (RILJ_LOGD) {
3491                 riljLog(rr.serialString() + "> "
3492                         + requestToString(rr.mRequest) + " enable = " + enable);
3493             }
3494 
3495             try {
3496                 radioProxy.setLocationUpdates(rr.mSerial, enable);
3497             } catch (RemoteException | RuntimeException e) {
3498                 handleRadioProxyExceptionForRR(rr, "setLocationUpdates", e);
3499             }
3500         }
3501     }
3502 
3503     /**
3504      * Is E-UTRA-NR Dual Connectivity enabled
3505      */
3506     @Override
isNrDualConnectivityEnabled(Message result, WorkSource workSource)3507     public void isNrDualConnectivityEnabled(Message result, WorkSource workSource) {
3508         IRadio radioProxy = getRadioProxy(result);
3509         if (radioProxy != null) {
3510             if (mRadioVersion.less(RADIO_HAL_VERSION_1_6)) {
3511                 if (result != null) {
3512                     AsyncResult.forMessage(result, null,
3513                             CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
3514                     result.sendToTarget();
3515                 }
3516                 return;
3517             }
3518 
3519             android.hardware.radio.V1_6.IRadio radioProxy16 =
3520                     (android.hardware.radio.V1_6.IRadio) radioProxy;
3521 
3522             RILRequest rr = obtainRequest(RIL_REQUEST_IS_NR_DUAL_CONNECTIVITY_ENABLED, result,
3523                     workSource == null ? mRILDefaultWorkSource : workSource);
3524 
3525             if (RILJ_LOGD) {
3526                 riljLog(rr.serialString() + "> "
3527                         + requestToString(rr.mRequest));
3528             }
3529 
3530             try {
3531                 radioProxy16.isNrDualConnectivityEnabled(rr.mSerial);
3532             } catch (RemoteException | RuntimeException e) {
3533                 handleRadioProxyExceptionForRR(rr, "isNRDualConnectivityEnabled", e);
3534             }
3535         }
3536     }
3537 
3538     /**
3539      * Enable/Disable E-UTRA-NR Dual Connectivity
3540      * @param nrDualConnectivityState expected NR dual connectivity state
3541      * This can be passed following states
3542      * <ol>
3543      * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
3544      * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
3545      * <li>Disable NR dual connectivity and force secondary cell to be released
3546      * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
3547      * </ol>
3548      */
3549     @Override
setNrDualConnectivityState(int nrDualConnectivityState, Message result, WorkSource workSource)3550     public void setNrDualConnectivityState(int nrDualConnectivityState,
3551             Message result, WorkSource workSource) {
3552         IRadio radioProxy = getRadioProxy(result);
3553         if (radioProxy != null) {
3554             if (mRadioVersion.less(RADIO_HAL_VERSION_1_6)) {
3555                 if (result != null) {
3556                     AsyncResult.forMessage(result, null,
3557                             CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
3558                     result.sendToTarget();
3559                 }
3560                 return;
3561             }
3562 
3563             android.hardware.radio.V1_6.IRadio radioProxy16 =
3564                     (android.hardware.radio.V1_6.IRadio) radioProxy;
3565             RILRequest rr = obtainRequest(RIL_REQUEST_ENABLE_NR_DUAL_CONNECTIVITY, result,
3566                     workSource == null ? mRILDefaultWorkSource : workSource);
3567 
3568             if (RILJ_LOGD) {
3569                 riljLog(rr.serialString() + "> "
3570                         + requestToString(rr.mRequest) + " enable = " + nrDualConnectivityState);
3571             }
3572 
3573             try {
3574                 radioProxy16.setNrDualConnectivityState(rr.mSerial,
3575                         (byte) nrDualConnectivityState);
3576             } catch (RemoteException | RuntimeException e) {
3577                 handleRadioProxyExceptionForRR(rr, "enableNRDualConnectivity", e);
3578             }
3579         }
3580     }
3581 
setVoNrEnabled(boolean enabled)3582     private void setVoNrEnabled(boolean enabled) {
3583         SystemProperties.set(PROPERTY_IS_VONR_ENABLED + mPhoneId, String.valueOf(enabled));
3584     }
3585 
isVoNrEnabled()3586     private boolean isVoNrEnabled() {
3587         return SystemProperties.getBoolean(PROPERTY_IS_VONR_ENABLED + mPhoneId, true);
3588     }
3589 
3590     /**
3591      * Is voice over NR enabled
3592      */
3593     @Override
isVoNrEnabled(Message result, WorkSource workSource)3594     public void isVoNrEnabled(Message result, WorkSource workSource) {
3595         boolean isEnabled = isVoNrEnabled();
3596         if (result != null) {
3597             AsyncResult.forMessage(result, isEnabled, null);
3598             result.sendToTarget();
3599         }
3600     }
3601 
3602     /**
3603      * Enable or disable Voice over NR (VoNR)
3604      * @param enabled enable or disable VoNR.
3605      */
3606     @Override
setVoNrEnabled(boolean enabled, Message result, WorkSource workSource)3607     public void setVoNrEnabled(boolean enabled, Message result, WorkSource workSource) {
3608         setVoNrEnabled(enabled);
3609         /* calling a query api to let HAL know that VoNREnabled state is updated.
3610            This is a temporary work around as new HIDL API is not allowed.
3611            HAL can check the value of PROPERTY_IS_VONR_ENABLED property to determine
3612            if there is any change whenever it receives isNrDualConnectivityEnabled request.
3613            This behavior will be removed in Android T.
3614          */
3615         isNrDualConnectivityEnabled(null, workSource);
3616         if (result != null) {
3617             AsyncResult.forMessage(result, null, null);
3618             result.sendToTarget();
3619         }
3620     }
3621 
3622     @Override
setCdmaSubscriptionSource(int cdmaSubscription , Message result)3623     public void setCdmaSubscriptionSource(int cdmaSubscription , Message result) {
3624         IRadio radioProxy = getRadioProxy(result);
3625         if (radioProxy != null) {
3626             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE, result,
3627                     mRILDefaultWorkSource);
3628 
3629             if (RILJ_LOGD) {
3630                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
3631                         + " cdmaSubscription = " + cdmaSubscription);
3632             }
3633 
3634             try {
3635                 radioProxy.setCdmaSubscriptionSource(rr.mSerial, cdmaSubscription);
3636             } catch (RemoteException | RuntimeException e) {
3637                 handleRadioProxyExceptionForRR(rr, "setCdmaSubscriptionSource", e);
3638             }
3639         }
3640     }
3641 
3642     @Override
queryCdmaRoamingPreference(Message result)3643     public void queryCdmaRoamingPreference(Message result) {
3644         IRadio radioProxy = getRadioProxy(result);
3645         if (radioProxy != null) {
3646             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE, result,
3647                     mRILDefaultWorkSource);
3648 
3649             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
3650 
3651             try {
3652                 radioProxy.getCdmaRoamingPreference(rr.mSerial);
3653             } catch (RemoteException | RuntimeException e) {
3654                 handleRadioProxyExceptionForRR(rr, "queryCdmaRoamingPreference", e);
3655             }
3656         }
3657     }
3658 
3659     @Override
setCdmaRoamingPreference(int cdmaRoamingType, Message result)3660     public void setCdmaRoamingPreference(int cdmaRoamingType, Message result) {
3661         IRadio radioProxy = getRadioProxy(result);
3662         if (radioProxy != null) {
3663             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE, result,
3664                     mRILDefaultWorkSource);
3665 
3666             if (RILJ_LOGD) {
3667                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
3668                         + " cdmaRoamingType = " + cdmaRoamingType);
3669             }
3670 
3671             try {
3672                 radioProxy.setCdmaRoamingPreference(rr.mSerial, cdmaRoamingType);
3673             } catch (RemoteException | RuntimeException e) {
3674                 handleRadioProxyExceptionForRR(rr, "setCdmaRoamingPreference", e);
3675             }
3676         }
3677     }
3678 
3679     @Override
queryTTYMode(Message result)3680     public void queryTTYMode(Message result) {
3681         IRadio radioProxy = getRadioProxy(result);
3682         if (radioProxy != null) {
3683             RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_TTY_MODE, result,
3684                     mRILDefaultWorkSource);
3685 
3686             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
3687 
3688             try {
3689                 radioProxy.getTTYMode(rr.mSerial);
3690             } catch (RemoteException | RuntimeException e) {
3691                 handleRadioProxyExceptionForRR(rr, "queryTTYMode", e);
3692             }
3693         }
3694     }
3695 
3696     @Override
setTTYMode(int ttyMode, Message result)3697     public void setTTYMode(int ttyMode, Message result) {
3698         IRadio radioProxy = getRadioProxy(result);
3699         if (radioProxy != null) {
3700             RILRequest rr = obtainRequest(RIL_REQUEST_SET_TTY_MODE, result,
3701                     mRILDefaultWorkSource);
3702 
3703             if (RILJ_LOGD) {
3704                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
3705                         + " ttyMode = " + ttyMode);
3706             }
3707 
3708             try {
3709                 radioProxy.setTTYMode(rr.mSerial, ttyMode);
3710             } catch (RemoteException | RuntimeException e) {
3711                 handleRadioProxyExceptionForRR(rr, "setTTYMode", e);
3712             }
3713         }
3714     }
3715 
3716     @Override
setPreferredVoicePrivacy(boolean enable, Message result)3717     public void setPreferredVoicePrivacy(boolean enable, Message result) {
3718         IRadio radioProxy = getRadioProxy(result);
3719         if (radioProxy != null) {
3720             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE, result,
3721                     mRILDefaultWorkSource);
3722 
3723             if (RILJ_LOGD) {
3724                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
3725                         + " enable = " + enable);
3726             }
3727 
3728             try {
3729                 radioProxy.setPreferredVoicePrivacy(rr.mSerial, enable);
3730             } catch (RemoteException | RuntimeException e) {
3731                 handleRadioProxyExceptionForRR(rr, "setPreferredVoicePrivacy", e);
3732             }
3733         }
3734     }
3735 
3736     @Override
getPreferredVoicePrivacy(Message result)3737     public void getPreferredVoicePrivacy(Message result) {
3738         IRadio radioProxy = getRadioProxy(result);
3739         if (radioProxy != null) {
3740             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE,
3741                     result, mRILDefaultWorkSource);
3742 
3743             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
3744 
3745             try {
3746                 radioProxy.getPreferredVoicePrivacy(rr.mSerial);
3747             } catch (RemoteException | RuntimeException e) {
3748                 handleRadioProxyExceptionForRR(rr, "getPreferredVoicePrivacy", e);
3749             }
3750         }
3751     }
3752 
3753     @Override
sendCDMAFeatureCode(String featureCode, Message result)3754     public void sendCDMAFeatureCode(String featureCode, Message result) {
3755         IRadio radioProxy = getRadioProxy(result);
3756         if (radioProxy != null) {
3757             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_FLASH, result,
3758                     mRILDefaultWorkSource);
3759 
3760             if (RILJ_LOGD) {
3761                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
3762                         + " featureCode = " + featureCode);
3763             }
3764 
3765             try {
3766                 radioProxy.sendCDMAFeatureCode(rr.mSerial, convertNullToEmptyString(featureCode));
3767             } catch (RemoteException | RuntimeException e) {
3768                 handleRadioProxyExceptionForRR(rr, "sendCDMAFeatureCode", e);
3769             }
3770         }
3771     }
3772 
3773     @Override
sendBurstDtmf(String dtmfString, int on, int off, Message result)3774     public void sendBurstDtmf(String dtmfString, int on, int off, Message result) {
3775         IRadio radioProxy = getRadioProxy(result);
3776         if (radioProxy != null) {
3777             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_BURST_DTMF, result,
3778                     mRILDefaultWorkSource);
3779 
3780             if (RILJ_LOGD) {
3781                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
3782                         + " dtmfString = " + dtmfString + " on = " + on + " off = " + off);
3783             }
3784 
3785             try {
3786                 radioProxy.sendBurstDtmf(rr.mSerial, convertNullToEmptyString(dtmfString), on, off);
3787             } catch (RemoteException | RuntimeException e) {
3788                 handleRadioProxyExceptionForRR(rr, "sendBurstDtmf", e);
3789             }
3790         }
3791     }
3792 
constructCdmaSendSmsRilRequest(CdmaSmsMessage msg, byte[] pdu)3793     private void constructCdmaSendSmsRilRequest(CdmaSmsMessage msg, byte[] pdu) {
3794         int addrNbrOfDigits;
3795         int subaddrNbrOfDigits;
3796         int bearerDataLength;
3797         ByteArrayInputStream bais = new ByteArrayInputStream(pdu);
3798         DataInputStream dis = new DataInputStream(bais);
3799 
3800         try {
3801             msg.teleserviceId = dis.readInt(); // teleServiceId
3802             msg.isServicePresent = (byte) dis.readInt() == 1 ? true : false; // servicePresent
3803             msg.serviceCategory = dis.readInt(); // serviceCategory
3804             msg.address.digitMode = dis.read();  // address digit mode
3805             msg.address.numberMode = dis.read(); // address number mode
3806             msg.address.numberType = dis.read(); // address number type
3807             msg.address.numberPlan = dis.read(); // address number plan
3808             addrNbrOfDigits = (byte) dis.read();
3809             for (int i = 0; i < addrNbrOfDigits; i++) {
3810                 msg.address.digits.add(dis.readByte()); // address_orig_bytes[i]
3811             }
3812             msg.subAddress.subaddressType = dis.read(); //subaddressType
3813             msg.subAddress.odd = (byte) dis.read() == 1 ? true : false; //subaddr odd
3814             subaddrNbrOfDigits = (byte) dis.read();
3815             for (int i = 0; i < subaddrNbrOfDigits; i++) {
3816                 msg.subAddress.digits.add(dis.readByte()); //subaddr_orig_bytes[i]
3817             }
3818 
3819             bearerDataLength = dis.read();
3820             for (int i = 0; i < bearerDataLength; i++) {
3821                 msg.bearerData.add(dis.readByte()); //bearerData[i]
3822             }
3823         } catch (IOException ex) {
3824             if (RILJ_LOGD) {
3825                 riljLog("sendSmsCdma: conversion from input stream to object failed: "
3826                         + ex);
3827             }
3828         }
3829     }
3830 
3831     @Override
sendCdmaSMSExpectMore(byte[] pdu, Message result)3832     public void sendCdmaSMSExpectMore(byte[] pdu, Message result) {
3833         IRadio radioProxy = getRadioProxy(result);
3834         if (radioProxy != null) {
3835             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SEND_SMS_EXPECT_MORE, result,
3836                     mRILDefaultWorkSource);
3837 
3838             // Do not log function arg for privacy
3839             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
3840 
3841             CdmaSmsMessage msg = new CdmaSmsMessage();
3842             constructCdmaSendSmsRilRequest(msg, pdu);
3843             if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
3844                 android.hardware.radio.V1_6.IRadio radioProxy16 =
3845                         (android.hardware.radio.V1_6.IRadio) radioProxy;
3846                 try {
3847                     radioProxy16.sendCdmaSmsExpectMore_1_6(rr.mSerial, msg);
3848                     mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_CDMA,
3849                             SmsSession.Event.Format.SMS_FORMAT_3GPP2,
3850                             getOutgoingSmsMessageId(result));
3851                 } catch (RemoteException | RuntimeException e) {
3852                     handleRadioProxyExceptionForRR(rr, "sendCdmaSMSExpectMore", e);
3853                 }
3854             } else if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
3855                 android.hardware.radio.V1_5.IRadio radioProxy15 =
3856                         (android.hardware.radio.V1_5.IRadio) radioProxy;
3857                 try {
3858                     radioProxy15.sendCdmaSmsExpectMore(rr.mSerial, msg);
3859                     mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_CDMA,
3860                             SmsSession.Event.Format.SMS_FORMAT_3GPP2,
3861                             getOutgoingSmsMessageId(result));
3862                 } catch (RemoteException | RuntimeException e) {
3863                     handleRadioProxyExceptionForRR(rr, "sendCdmaSMSExpectMore", e);
3864                 }
3865             } else {
3866                 sendCdmaSms(pdu, result);
3867             }
3868         }
3869     }
3870 
3871     @Override
sendCdmaSms(byte[] pdu, Message result)3872     public void sendCdmaSms(byte[] pdu, Message result) {
3873         IRadio radioProxy = getRadioProxy(result);
3874         if (radioProxy != null) {
3875             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SEND_SMS, result,
3876                     mRILDefaultWorkSource);
3877 
3878             // Do not log function arg for privacy
3879             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
3880 
3881             CdmaSmsMessage msg = new CdmaSmsMessage();
3882             constructCdmaSendSmsRilRequest(msg, pdu);
3883             if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
3884                 try {
3885                     android.hardware.radio.V1_6.IRadio radioProxy16 =
3886                             (android.hardware.radio.V1_6.IRadio) radioProxy;
3887                     radioProxy16.sendCdmaSms_1_6(rr.mSerial, msg);
3888                     mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_CDMA,
3889                             SmsSession.Event.Format.SMS_FORMAT_3GPP2,
3890                             getOutgoingSmsMessageId(result));
3891                 } catch (RemoteException | RuntimeException e) {
3892                     handleRadioProxyExceptionForRR(rr, "sendCdmaSms", e);
3893                 }
3894             } else {
3895                 try {
3896                     radioProxy.sendCdmaSms(rr.mSerial, msg);
3897                     mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_CDMA,
3898                             SmsSession.Event.Format.SMS_FORMAT_3GPP2,
3899                             getOutgoingSmsMessageId(result));
3900                 } catch (RemoteException | RuntimeException e) {
3901                     handleRadioProxyExceptionForRR(rr, "sendCdmaSms", e);
3902                 }
3903             }
3904         }
3905     }
3906 
3907     @Override
acknowledgeLastIncomingCdmaSms(boolean success, int cause, Message result)3908     public void acknowledgeLastIncomingCdmaSms(boolean success, int cause, Message result) {
3909         IRadio radioProxy = getRadioProxy(result);
3910         if (radioProxy != null) {
3911             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE, result,
3912                     mRILDefaultWorkSource);
3913 
3914             if (RILJ_LOGD) {
3915                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
3916                         + " success = " + success + " cause = " + cause);
3917             }
3918 
3919             CdmaSmsAck msg = new CdmaSmsAck();
3920             msg.errorClass = success ? 0 : 1;
3921             msg.smsCauseCode = cause;
3922 
3923             try {
3924                 radioProxy.acknowledgeLastIncomingCdmaSms(rr.mSerial, msg);
3925             } catch (RemoteException | RuntimeException e) {
3926                 handleRadioProxyExceptionForRR(rr, "acknowledgeLastIncomingCdmaSms", e);
3927             }
3928         }
3929     }
3930 
3931     @Override
getGsmBroadcastConfig(Message result)3932     public void getGsmBroadcastConfig(Message result) {
3933         IRadio radioProxy = getRadioProxy(result);
3934         if (radioProxy != null) {
3935             RILRequest rr = obtainRequest(RIL_REQUEST_GSM_GET_BROADCAST_CONFIG, result,
3936                     mRILDefaultWorkSource);
3937 
3938             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
3939 
3940             try {
3941                 radioProxy.getGsmBroadcastConfig(rr.mSerial);
3942             } catch (RemoteException | RuntimeException e) {
3943                 handleRadioProxyExceptionForRR(rr, "getGsmBroadcastConfig", e);
3944             }
3945         }
3946     }
3947 
3948     @Override
setGsmBroadcastConfig(SmsBroadcastConfigInfo[] config, Message result)3949     public void setGsmBroadcastConfig(SmsBroadcastConfigInfo[] config, Message result) {
3950         IRadio radioProxy = getRadioProxy(result);
3951         if (radioProxy != null) {
3952             RILRequest rr = obtainRequest(RIL_REQUEST_GSM_SET_BROADCAST_CONFIG, result,
3953                     mRILDefaultWorkSource);
3954 
3955             if (RILJ_LOGD) {
3956                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
3957                         + " with " + config.length + " configs : ");
3958                 for (int i = 0; i < config.length; i++) {
3959                     riljLog(config[i].toString());
3960                 }
3961             }
3962 
3963             ArrayList<GsmBroadcastSmsConfigInfo> configs = new ArrayList<>();
3964 
3965             int numOfConfig = config.length;
3966             GsmBroadcastSmsConfigInfo info;
3967 
3968             for (int i = 0; i < numOfConfig; i++) {
3969                 info = new GsmBroadcastSmsConfigInfo();
3970                 info.fromServiceId = config[i].getFromServiceId();
3971                 info.toServiceId = config[i].getToServiceId();
3972                 info.fromCodeScheme = config[i].getFromCodeScheme();
3973                 info.toCodeScheme = config[i].getToCodeScheme();
3974                 info.selected = config[i].isSelected();
3975                 configs.add(info);
3976             }
3977 
3978             try {
3979                 radioProxy.setGsmBroadcastConfig(rr.mSerial, configs);
3980             } catch (RemoteException | RuntimeException e) {
3981                 handleRadioProxyExceptionForRR(rr, "setGsmBroadcastConfig", e);
3982             }
3983         }
3984     }
3985 
3986     @Override
setGsmBroadcastActivation(boolean activate, Message result)3987     public void setGsmBroadcastActivation(boolean activate, Message result) {
3988         IRadio radioProxy = getRadioProxy(result);
3989         if (radioProxy != null) {
3990             RILRequest rr = obtainRequest(RIL_REQUEST_GSM_BROADCAST_ACTIVATION, result,
3991                     mRILDefaultWorkSource);
3992 
3993             if (RILJ_LOGD) {
3994                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
3995                         + " activate = " + activate);
3996             }
3997 
3998             try {
3999                 radioProxy.setGsmBroadcastActivation(rr.mSerial, activate);
4000             } catch (RemoteException | RuntimeException e) {
4001                 handleRadioProxyExceptionForRR(rr, "setGsmBroadcastActivation", e);
4002             }
4003         }
4004     }
4005 
4006     @Override
getCdmaBroadcastConfig(Message result)4007     public void getCdmaBroadcastConfig(Message result) {
4008         IRadio radioProxy = getRadioProxy(result);
4009         if (radioProxy != null) {
4010             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG, result,
4011                     mRILDefaultWorkSource);
4012 
4013             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4014 
4015             try {
4016                 radioProxy.getCdmaBroadcastConfig(rr.mSerial);
4017             } catch (RemoteException | RuntimeException e) {
4018                 handleRadioProxyExceptionForRR(rr, "getCdmaBroadcastConfig", e);
4019             }
4020         }
4021     }
4022 
4023     @Override
setCdmaBroadcastConfig(CdmaSmsBroadcastConfigInfo[] configs, Message result)4024     public void setCdmaBroadcastConfig(CdmaSmsBroadcastConfigInfo[] configs, Message result) {
4025         IRadio radioProxy = getRadioProxy(result);
4026         if (radioProxy != null) {
4027             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG, result,
4028                     mRILDefaultWorkSource);
4029 
4030             ArrayList<CdmaBroadcastSmsConfigInfo> halConfigs = new ArrayList<>();
4031 
4032             for (CdmaSmsBroadcastConfigInfo config: configs) {
4033                 for (int i = config.getFromServiceCategory();
4034                         i <= config.getToServiceCategory();
4035                         i++) {
4036                     CdmaBroadcastSmsConfigInfo info = new CdmaBroadcastSmsConfigInfo();
4037                     info.serviceCategory = i;
4038                     info.language = config.getLanguage();
4039                     info.selected = config.isSelected();
4040                     halConfigs.add(info);
4041                 }
4042             }
4043 
4044             if (RILJ_LOGD) {
4045                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4046                         + " with " + halConfigs.size() + " configs : ");
4047                 for (CdmaBroadcastSmsConfigInfo config : halConfigs) {
4048                     riljLog(config.toString());
4049                 }
4050             }
4051 
4052             try {
4053                 radioProxy.setCdmaBroadcastConfig(rr.mSerial, halConfigs);
4054             } catch (RemoteException | RuntimeException e) {
4055                 handleRadioProxyExceptionForRR(rr, "setCdmaBroadcastConfig", e);
4056             }
4057         }
4058     }
4059 
4060     @Override
setCdmaBroadcastActivation(boolean activate, Message result)4061     public void setCdmaBroadcastActivation(boolean activate, Message result) {
4062         IRadio radioProxy = getRadioProxy(result);
4063         if (radioProxy != null) {
4064             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_BROADCAST_ACTIVATION, result,
4065                     mRILDefaultWorkSource);
4066 
4067             if (RILJ_LOGD) {
4068                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4069                         + " activate = " + activate);
4070             }
4071 
4072             try {
4073                 radioProxy.setCdmaBroadcastActivation(rr.mSerial, activate);
4074             } catch (RemoteException | RuntimeException e) {
4075                 handleRadioProxyExceptionForRR(rr, "setCdmaBroadcastActivation", e);
4076             }
4077         }
4078     }
4079 
4080     @Override
getCDMASubscription(Message result)4081     public void getCDMASubscription(Message result) {
4082         IRadio radioProxy = getRadioProxy(result);
4083         if (radioProxy != null) {
4084             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SUBSCRIPTION, result,
4085                     mRILDefaultWorkSource);
4086 
4087             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4088 
4089             try {
4090                 radioProxy.getCDMASubscription(rr.mSerial);
4091             } catch (RemoteException | RuntimeException e) {
4092                 handleRadioProxyExceptionForRR(rr, "getCDMASubscription", e);
4093             }
4094         }
4095     }
4096 
4097     @Override
writeSmsToRuim(int status, byte[] pdu, Message result)4098     public void writeSmsToRuim(int status, byte[] pdu, Message result) {
4099         status = translateStatus(status);
4100         IRadio radioProxy = getRadioProxy(result);
4101         if (radioProxy != null) {
4102             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM, result,
4103                     mRILDefaultWorkSource);
4104 
4105             if (RILJ_LOGV) {
4106                 riljLog(rr.serialString() + "> "
4107                         + requestToString(rr.mRequest)
4108                         + " status = " + status);
4109             }
4110 
4111             CdmaSmsWriteArgs args = new CdmaSmsWriteArgs();
4112             args.status = status;
4113             constructCdmaSendSmsRilRequest(args.message, pdu);
4114 
4115             try {
4116                 radioProxy.writeSmsToRuim(rr.mSerial, args);
4117             } catch (RemoteException | RuntimeException e) {
4118                 handleRadioProxyExceptionForRR(rr, "writeSmsToRuim", e);
4119             }
4120         }
4121     }
4122 
4123     @Override
deleteSmsOnRuim(int index, Message result)4124     public void deleteSmsOnRuim(int index, Message result) {
4125         IRadio radioProxy = getRadioProxy(result);
4126         if (radioProxy != null) {
4127             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM, result,
4128                     mRILDefaultWorkSource);
4129 
4130             if (RILJ_LOGV) {
4131                 riljLog(rr.serialString() + "> "
4132                         + requestToString(rr.mRequest)
4133                         + " index = " + index);
4134             }
4135 
4136             try {
4137                 radioProxy.deleteSmsOnRuim(rr.mSerial, index);
4138             } catch (RemoteException | RuntimeException e) {
4139                 handleRadioProxyExceptionForRR(rr, "deleteSmsOnRuim", e);
4140             }
4141         }
4142     }
4143 
4144     @Override
getDeviceIdentity(Message result)4145     public void getDeviceIdentity(Message result) {
4146         IRadio radioProxy = getRadioProxy(result);
4147         if (radioProxy != null) {
4148             RILRequest rr = obtainRequest(RIL_REQUEST_DEVICE_IDENTITY, result,
4149                     mRILDefaultWorkSource);
4150 
4151             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4152 
4153             try {
4154                 radioProxy.getDeviceIdentity(rr.mSerial);
4155             } catch (RemoteException | RuntimeException e) {
4156                 handleRadioProxyExceptionForRR(rr, "getDeviceIdentity", e);
4157             }
4158         }
4159     }
4160 
4161     @Override
exitEmergencyCallbackMode(Message result)4162     public void exitEmergencyCallbackMode(Message result) {
4163         IRadio radioProxy = getRadioProxy(result);
4164         if (radioProxy != null) {
4165             RILRequest rr = obtainRequest(RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE, result,
4166                     mRILDefaultWorkSource);
4167 
4168             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4169 
4170             try {
4171                 radioProxy.exitEmergencyCallbackMode(rr.mSerial);
4172             } catch (RemoteException | RuntimeException e) {
4173                 handleRadioProxyExceptionForRR(rr, "exitEmergencyCallbackMode", e);
4174             }
4175         }
4176     }
4177 
4178     @Override
getSmscAddress(Message result)4179     public void getSmscAddress(Message result) {
4180         IRadio radioProxy = getRadioProxy(result);
4181         if (radioProxy != null) {
4182             RILRequest rr = obtainRequest(RIL_REQUEST_GET_SMSC_ADDRESS, result,
4183                     mRILDefaultWorkSource);
4184 
4185             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4186 
4187             try {
4188                 radioProxy.getSmscAddress(rr.mSerial);
4189             } catch (RemoteException | RuntimeException e) {
4190                 handleRadioProxyExceptionForRR(rr, "getSmscAddress", e);
4191             }
4192         }
4193     }
4194 
4195     @Override
setSmscAddress(String address, Message result)4196     public void setSmscAddress(String address, Message result) {
4197         IRadio radioProxy = getRadioProxy(result);
4198         if (radioProxy != null) {
4199             RILRequest rr = obtainRequest(RIL_REQUEST_SET_SMSC_ADDRESS, result,
4200                     mRILDefaultWorkSource);
4201 
4202             if (RILJ_LOGD) {
4203                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4204                         + " address = " + address);
4205             }
4206 
4207             try {
4208                 radioProxy.setSmscAddress(rr.mSerial, convertNullToEmptyString(address));
4209             } catch (RemoteException | RuntimeException e) {
4210                 handleRadioProxyExceptionForRR(rr, "setSmscAddress", e);
4211             }
4212         }
4213     }
4214 
4215     @Override
reportSmsMemoryStatus(boolean available, Message result)4216     public void reportSmsMemoryStatus(boolean available, Message result) {
4217         IRadio radioProxy = getRadioProxy(result);
4218         if (radioProxy != null) {
4219             RILRequest rr = obtainRequest(RIL_REQUEST_REPORT_SMS_MEMORY_STATUS, result,
4220                     mRILDefaultWorkSource);
4221 
4222             if (RILJ_LOGD) {
4223                 riljLog(rr.serialString() + "> "
4224                         + requestToString(rr.mRequest) + " available = " + available);
4225             }
4226 
4227             try {
4228                 radioProxy.reportSmsMemoryStatus(rr.mSerial, available);
4229             } catch (RemoteException | RuntimeException e) {
4230                 handleRadioProxyExceptionForRR(rr, "reportSmsMemoryStatus", e);
4231             }
4232         }
4233     }
4234 
4235     @Override
reportStkServiceIsRunning(Message result)4236     public void reportStkServiceIsRunning(Message result) {
4237         IRadio radioProxy = getRadioProxy(result);
4238         if (radioProxy != null) {
4239             RILRequest rr = obtainRequest(RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING, result,
4240                     mRILDefaultWorkSource);
4241 
4242             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4243 
4244             try {
4245                 radioProxy.reportStkServiceIsRunning(rr.mSerial);
4246             } catch (RemoteException | RuntimeException e) {
4247                 handleRadioProxyExceptionForRR(rr, "reportStkServiceIsRunning", e);
4248             }
4249         }
4250     }
4251 
4252     @Override
getCdmaSubscriptionSource(Message result)4253     public void getCdmaSubscriptionSource(Message result) {
4254         IRadio radioProxy = getRadioProxy(result);
4255         if (radioProxy != null) {
4256             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE, result,
4257                     mRILDefaultWorkSource);
4258 
4259             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4260 
4261             try {
4262                 radioProxy.getCdmaSubscriptionSource(rr.mSerial);
4263             } catch (RemoteException | RuntimeException e) {
4264                 handleRadioProxyExceptionForRR(rr, "getCdmaSubscriptionSource", e);
4265             }
4266         }
4267     }
4268 
4269     @Override
acknowledgeIncomingGsmSmsWithPdu(boolean success, String ackPdu, Message result)4270     public void acknowledgeIncomingGsmSmsWithPdu(boolean success, String ackPdu, Message result) {
4271         IRadio radioProxy = getRadioProxy(result);
4272         if (radioProxy != null) {
4273             RILRequest rr = obtainRequest(RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU, result,
4274                     mRILDefaultWorkSource);
4275 
4276             if (RILJ_LOGD) {
4277                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4278                         + " success = " + success);
4279             }
4280 
4281             try {
4282                 radioProxy.acknowledgeIncomingGsmSmsWithPdu(rr.mSerial, success,
4283                         convertNullToEmptyString(ackPdu));
4284             } catch (RemoteException | RuntimeException e) {
4285                 handleRadioProxyExceptionForRR(rr, "acknowledgeIncomingGsmSmsWithPdu", e);
4286             }
4287         }
4288     }
4289 
4290     @Override
getVoiceRadioTechnology(Message result)4291     public void getVoiceRadioTechnology(Message result) {
4292         IRadio radioProxy = getRadioProxy(result);
4293         if (radioProxy != null) {
4294             RILRequest rr = obtainRequest(RIL_REQUEST_VOICE_RADIO_TECH, result,
4295                     mRILDefaultWorkSource);
4296 
4297             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4298 
4299             try {
4300                 radioProxy.getVoiceRadioTechnology(rr.mSerial);
4301             } catch (RemoteException | RuntimeException e) {
4302                 handleRadioProxyExceptionForRR(rr, "getVoiceRadioTechnology", e);
4303             }
4304         }
4305     }
4306 
4307     @Override
getCellInfoList(Message result, WorkSource workSource)4308     public void getCellInfoList(Message result, WorkSource workSource) {
4309         workSource = getDefaultWorkSourceIfInvalid(workSource);
4310         IRadio radioProxy = getRadioProxy(result);
4311         if (radioProxy != null) {
4312             RILRequest rr = obtainRequest(RIL_REQUEST_GET_CELL_INFO_LIST, result,
4313                     workSource);
4314 
4315             if (RILJ_LOGD) {
4316                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4317             }
4318 
4319             try {
4320                 if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
4321                     android.hardware.radio.V1_6.IRadio radioProxy16 =
4322                             (android.hardware.radio.V1_6.IRadio) radioProxy;
4323                     radioProxy16.getCellInfoList_1_6(rr.mSerial);
4324 
4325                 } else {
4326                     radioProxy.getCellInfoList(rr.mSerial);
4327                 }
4328             } catch (RemoteException | RuntimeException e) {
4329                 handleRadioProxyExceptionForRR(rr, "getCellInfoList", e);
4330             }
4331         }
4332     }
4333 
4334     @Override
setCellInfoListRate(int rateInMillis, Message result, WorkSource workSource)4335     public void setCellInfoListRate(int rateInMillis, Message result, WorkSource workSource) {
4336         workSource = getDefaultWorkSourceIfInvalid(workSource);
4337         IRadio radioProxy = getRadioProxy(result);
4338         if (radioProxy != null) {
4339             RILRequest rr = obtainRequest(RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE, result,
4340                     workSource);
4341 
4342             if (RILJ_LOGD) {
4343                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4344                         + " rateInMillis = " + rateInMillis);
4345             }
4346 
4347             try {
4348                 radioProxy.setCellInfoListRate(rr.mSerial, rateInMillis);
4349             } catch (RemoteException | RuntimeException e) {
4350                 handleRadioProxyExceptionForRR(rr, "setCellInfoListRate", e);
4351             }
4352         }
4353     }
4354 
4355     @Override
setInitialAttachApn(DataProfile dataProfile, boolean isRoaming, Message result)4356     public void setInitialAttachApn(DataProfile dataProfile, boolean isRoaming, Message result) {
4357         IRadio radioProxy = getRadioProxy(result);
4358         if (radioProxy != null) {
4359             RILRequest rr = obtainRequest(RIL_REQUEST_SET_INITIAL_ATTACH_APN, result,
4360                     mRILDefaultWorkSource);
4361 
4362             if (RILJ_LOGD) {
4363                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + dataProfile);
4364             }
4365 
4366             try {
4367                 if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
4368                     // v1.5
4369                     android.hardware.radio.V1_5.IRadio radioProxy15 =
4370                             (android.hardware.radio.V1_5.IRadio) radioProxy;
4371                     radioProxy15.setInitialAttachApn_1_5(rr.mSerial,
4372                             convertToHalDataProfile15(dataProfile));
4373                 } else if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_4)) {
4374                     // v1.4
4375                     android.hardware.radio.V1_4.IRadio radioProxy14 =
4376                             (android.hardware.radio.V1_4.IRadio) radioProxy;
4377                     radioProxy14.setInitialAttachApn_1_4(rr.mSerial,
4378                             convertToHalDataProfile14(dataProfile));
4379                 } else {
4380                     // v1.3, v1.2, v1.1, and v1.0
4381                     radioProxy.setInitialAttachApn(rr.mSerial,
4382                             convertToHalDataProfile10(dataProfile), dataProfile.isPersistent(),
4383                             isRoaming);
4384                 }
4385             } catch (RemoteException | RuntimeException e) {
4386                 handleRadioProxyExceptionForRR(rr, "setInitialAttachApn", e);
4387             }
4388         }
4389     }
4390 
4391     @Override
getImsRegistrationState(Message result)4392     public void getImsRegistrationState(Message result) {
4393         IRadio radioProxy = getRadioProxy(result);
4394         if (radioProxy != null) {
4395             RILRequest rr = obtainRequest(RIL_REQUEST_IMS_REGISTRATION_STATE, result,
4396                     mRILDefaultWorkSource);
4397 
4398             if (RILJ_LOGD) {
4399                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4400             }
4401 
4402             try {
4403                 radioProxy.getImsRegistrationState(rr.mSerial);
4404             } catch (RemoteException | RuntimeException e) {
4405                 handleRadioProxyExceptionForRR(rr, "getImsRegistrationState", e);
4406             }
4407         }
4408     }
4409 
4410     @Override
sendImsGsmSms(String smscPdu, String pdu, int retry, int messageRef, Message result)4411     public void sendImsGsmSms(String smscPdu, String pdu, int retry, int messageRef,
4412                    Message result) {
4413         IRadio radioProxy = getRadioProxy(result);
4414         if (radioProxy != null) {
4415             RILRequest rr = obtainRequest(RIL_REQUEST_IMS_SEND_SMS, result,
4416                     mRILDefaultWorkSource);
4417 
4418             // Do not log function args for privacy
4419             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4420 
4421             ImsSmsMessage msg = new ImsSmsMessage();
4422             msg.tech = RadioTechnologyFamily.THREE_GPP;
4423             msg.retry = (byte) retry >= 1 ? true : false;
4424             msg.messageRef = messageRef;
4425 
4426             GsmSmsMessage gsmMsg = constructGsmSendSmsRilRequest(smscPdu, pdu);
4427             msg.gsmMessage.add(gsmMsg);
4428             try {
4429                 radioProxy.sendImsSms(rr.mSerial, msg);
4430                 mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_IMS,
4431                         SmsSession.Event.Format.SMS_FORMAT_3GPP, getOutgoingSmsMessageId(result));
4432             } catch (RemoteException | RuntimeException e) {
4433                 handleRadioProxyExceptionForRR(rr, "sendImsGsmSms", e);
4434             }
4435         }
4436     }
4437 
4438     @Override
sendImsCdmaSms(byte[] pdu, int retry, int messageRef, Message result)4439     public void sendImsCdmaSms(byte[] pdu, int retry, int messageRef, Message result) {
4440         IRadio radioProxy = getRadioProxy(result);
4441         if (radioProxy != null) {
4442             RILRequest rr = obtainRequest(RIL_REQUEST_IMS_SEND_SMS, result,
4443                     mRILDefaultWorkSource);
4444 
4445             // Do not log function args for privacy
4446             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4447 
4448             ImsSmsMessage msg = new ImsSmsMessage();
4449             msg.tech = RadioTechnologyFamily.THREE_GPP2;
4450             msg.retry = (byte) retry >= 1 ? true : false;
4451             msg.messageRef = messageRef;
4452 
4453             CdmaSmsMessage cdmaMsg = new CdmaSmsMessage();
4454             constructCdmaSendSmsRilRequest(cdmaMsg, pdu);
4455             msg.cdmaMessage.add(cdmaMsg);
4456 
4457             try {
4458                 radioProxy.sendImsSms(rr.mSerial, msg);
4459                 mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_IMS,
4460                         SmsSession.Event.Format.SMS_FORMAT_3GPP2, getOutgoingSmsMessageId(result));
4461             } catch (RemoteException | RuntimeException e) {
4462                 handleRadioProxyExceptionForRR(rr, "sendImsCdmaSms", e);
4463             }
4464         }
4465     }
4466 
createSimApdu(int channel, int cla, int instruction, int p1, int p2, int p3, String data)4467     private SimApdu createSimApdu(int channel, int cla, int instruction, int p1, int p2, int p3,
4468                                   String data) {
4469         SimApdu msg = new SimApdu();
4470         msg.sessionId = channel;
4471         msg.cla = cla;
4472         msg.instruction = instruction;
4473         msg.p1 = p1;
4474         msg.p2 = p2;
4475         msg.p3 = p3;
4476         msg.data = convertNullToEmptyString(data);
4477         return msg;
4478     }
4479 
4480     @Override
iccTransmitApduBasicChannel(int cla, int instruction, int p1, int p2, int p3, String data, Message result)4481     public void iccTransmitApduBasicChannel(int cla, int instruction, int p1, int p2,
4482                                             int p3, String data, Message result) {
4483         IRadio radioProxy = getRadioProxy(result);
4484         if (radioProxy != null) {
4485             RILRequest rr = obtainRequest(RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC, result,
4486                     mRILDefaultWorkSource);
4487 
4488             if (RILJ_LOGD) {
4489                 if (TelephonyUtils.IS_DEBUGGABLE) {
4490                     riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4491                             + String.format(" cla = 0x%02X ins = 0x%02X", cla, instruction)
4492                             + String.format(" p1 = 0x%02X p2 = 0x%02X p3 = 0x%02X", p1, p2, p3)
4493                             + " data = " + data);
4494                 } else {
4495                     riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4496                 }
4497             }
4498 
4499             SimApdu msg = createSimApdu(0, cla, instruction, p1, p2, p3, data);
4500             try {
4501                 radioProxy.iccTransmitApduBasicChannel(rr.mSerial, msg);
4502             } catch (RemoteException | RuntimeException e) {
4503                 handleRadioProxyExceptionForRR(rr, "iccTransmitApduBasicChannel", e);
4504             }
4505         }
4506     }
4507 
4508     @Override
iccOpenLogicalChannel(String aid, int p2, Message result)4509     public void iccOpenLogicalChannel(String aid, int p2, Message result) {
4510         IRadio radioProxy = getRadioProxy(result);
4511         if (radioProxy != null) {
4512             RILRequest rr = obtainRequest(RIL_REQUEST_SIM_OPEN_CHANNEL, result,
4513                     mRILDefaultWorkSource);
4514 
4515             if (RILJ_LOGD) {
4516                 if (TelephonyUtils.IS_DEBUGGABLE) {
4517                     riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " aid = " + aid
4518                             + " p2 = " + p2);
4519                 } else {
4520                     riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4521                 }
4522             }
4523 
4524             try {
4525                 radioProxy.iccOpenLogicalChannel(rr.mSerial, convertNullToEmptyString(aid), p2);
4526             } catch (RemoteException | RuntimeException e) {
4527                 handleRadioProxyExceptionForRR(rr, "iccOpenLogicalChannel", e);
4528             }
4529         }
4530     }
4531 
4532     @Override
iccCloseLogicalChannel(int channel, Message result)4533     public void iccCloseLogicalChannel(int channel, Message result) {
4534         IRadio radioProxy = getRadioProxy(result);
4535         if (radioProxy != null) {
4536             RILRequest rr = obtainRequest(RIL_REQUEST_SIM_CLOSE_CHANNEL, result,
4537                     mRILDefaultWorkSource);
4538 
4539             if (RILJ_LOGD) {
4540                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " channel = "
4541                         + channel);
4542             }
4543 
4544             try {
4545                 radioProxy.iccCloseLogicalChannel(rr.mSerial, channel);
4546             } catch (RemoteException | RuntimeException e) {
4547                 handleRadioProxyExceptionForRR(rr, "iccCloseLogicalChannel", e);
4548             }
4549         }
4550     }
4551 
4552     @Override
iccTransmitApduLogicalChannel(int channel, int cla, int instruction, int p1, int p2, int p3, String data, Message result)4553     public void iccTransmitApduLogicalChannel(int channel, int cla, int instruction,
4554                                               int p1, int p2, int p3, String data,
4555                                               Message result) {
4556         if (channel <= 0) {
4557             throw new RuntimeException(
4558                     "Invalid channel in iccTransmitApduLogicalChannel: " + channel);
4559         }
4560 
4561         IRadio radioProxy = getRadioProxy(result);
4562         if (radioProxy != null) {
4563             RILRequest rr = obtainRequest(RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL, result,
4564                     mRILDefaultWorkSource);
4565 
4566             if (RILJ_LOGD) {
4567                 if (TelephonyUtils.IS_DEBUGGABLE) {
4568                     riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4569                             + String.format(" channel = %d", channel)
4570                             + String.format(" cla = 0x%02X ins = 0x%02X", cla, instruction)
4571                             + String.format(" p1 = 0x%02X p2 = 0x%02X p3 = 0x%02X", p1, p2, p3)
4572                             + " data = " + data);
4573                 } else {
4574                     riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4575                 }
4576             }
4577 
4578             SimApdu msg = createSimApdu(channel, cla, instruction, p1, p2, p3, data);
4579 
4580             try {
4581                 radioProxy.iccTransmitApduLogicalChannel(rr.mSerial, msg);
4582             } catch (RemoteException | RuntimeException e) {
4583                 handleRadioProxyExceptionForRR(rr, "iccTransmitApduLogicalChannel", e);
4584             }
4585         }
4586     }
4587 
4588     @Override
nvReadItem(int itemID, Message result, WorkSource workSource)4589     public void nvReadItem(int itemID, Message result, WorkSource workSource) {
4590         workSource = getDefaultWorkSourceIfInvalid(workSource);
4591         IRadio radioProxy = getRadioProxy(result);
4592         if (radioProxy != null) {
4593             RILRequest rr = obtainRequest(RIL_REQUEST_NV_READ_ITEM, result,
4594                     workSource);
4595 
4596             if (RILJ_LOGD) {
4597                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4598                         + " itemId = " + itemID);
4599             }
4600 
4601             try {
4602                 radioProxy.nvReadItem(rr.mSerial, itemID);
4603             } catch (RemoteException | RuntimeException e) {
4604                 handleRadioProxyExceptionForRR(rr, "nvReadItem", e);
4605             }
4606         }
4607     }
4608 
4609     @Override
nvWriteItem(int itemId, String itemValue, Message result, WorkSource workSource)4610     public void nvWriteItem(int itemId, String itemValue, Message result, WorkSource workSource) {
4611         workSource = getDefaultWorkSourceIfInvalid(workSource);
4612         IRadio radioProxy = getRadioProxy(result);
4613         if (radioProxy != null) {
4614             RILRequest rr = obtainRequest(RIL_REQUEST_NV_WRITE_ITEM, result,
4615                     workSource);
4616 
4617             if (RILJ_LOGD) {
4618                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4619                         + " itemId = " + itemId + " itemValue = " + itemValue);
4620             }
4621 
4622             NvWriteItem item = new NvWriteItem();
4623             item.itemId = itemId;
4624             item.value = convertNullToEmptyString(itemValue);
4625 
4626             try {
4627                 radioProxy.nvWriteItem(rr.mSerial, item);
4628             } catch (RemoteException | RuntimeException e) {
4629                 handleRadioProxyExceptionForRR(rr, "nvWriteItem", e);
4630             }
4631         }
4632     }
4633 
4634     @Override
nvWriteCdmaPrl(byte[] preferredRoamingList, Message result)4635     public void nvWriteCdmaPrl(byte[] preferredRoamingList, Message result) {
4636         IRadio radioProxy = getRadioProxy(result);
4637         if (radioProxy != null) {
4638             RILRequest rr = obtainRequest(RIL_REQUEST_NV_WRITE_CDMA_PRL, result,
4639                     mRILDefaultWorkSource);
4640 
4641             if (RILJ_LOGD) {
4642                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4643                         + " PreferredRoamingList = 0x"
4644                         + IccUtils.bytesToHexString(preferredRoamingList));
4645             }
4646 
4647             ArrayList<Byte> arrList = new ArrayList<>();
4648             for (int i = 0; i < preferredRoamingList.length; i++) {
4649                 arrList.add(preferredRoamingList[i]);
4650             }
4651 
4652             try {
4653                 radioProxy.nvWriteCdmaPrl(rr.mSerial, arrList);
4654             } catch (RemoteException | RuntimeException e) {
4655                 handleRadioProxyExceptionForRR(rr, "nvWriteCdmaPrl", e);
4656             }
4657         }
4658     }
4659 
4660     @Override
nvResetConfig(int resetType, Message result)4661     public void nvResetConfig(int resetType, Message result) {
4662         IRadio radioProxy = getRadioProxy(result);
4663         if (radioProxy != null) {
4664             RILRequest rr = obtainRequest(RIL_REQUEST_NV_RESET_CONFIG, result,
4665                     mRILDefaultWorkSource);
4666 
4667             if (RILJ_LOGD) {
4668                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4669                         + " resetType = " + resetType);
4670             }
4671 
4672             try {
4673                 radioProxy.nvResetConfig(rr.mSerial, convertToHalResetNvType(resetType));
4674             } catch (RemoteException | RuntimeException e) {
4675                 handleRadioProxyExceptionForRR(rr, "nvResetConfig", e);
4676             }
4677         }
4678     }
4679 
4680     @Override
setUiccSubscription(int slotId, int appIndex, int subId, int subStatus, Message result)4681     public void setUiccSubscription(int slotId, int appIndex, int subId,
4682                                     int subStatus, Message result) {
4683         IRadio radioProxy = getRadioProxy(result);
4684         if (radioProxy != null) {
4685             RILRequest rr = obtainRequest(RIL_REQUEST_SET_UICC_SUBSCRIPTION, result,
4686                     mRILDefaultWorkSource);
4687 
4688             if (RILJ_LOGD) {
4689                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4690                         + " slot = " + slotId + " appIndex = " + appIndex
4691                         + " subId = " + subId + " subStatus = " + subStatus);
4692             }
4693 
4694             SelectUiccSub info = new SelectUiccSub();
4695             info.slot = slotId;
4696             info.appIndex = appIndex;
4697             info.subType = subId;
4698             info.actStatus = subStatus;
4699 
4700             try {
4701                 radioProxy.setUiccSubscription(rr.mSerial, info);
4702             } catch (RemoteException | RuntimeException e) {
4703                 handleRadioProxyExceptionForRR(rr, "setUiccSubscription", e);
4704             }
4705         }
4706     }
4707 
4708     /**
4709      * Whether the device modem supports reporting the EID in either the slot or card status or
4710      * through ATR.
4711      * @return true if the modem supports EID.
4712      */
4713     @Override
supportsEid()4714     public boolean supportsEid() {
4715         // EID should be supported as long as HAL >= 1.2.
4716         //  - in HAL 1.2 we have EID through ATR
4717         //  - in later HAL versions we also have EID through slot / card status.
4718         return mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_2);
4719     }
4720 
4721     @Override
setDataAllowed(boolean allowed, Message result)4722     public void setDataAllowed(boolean allowed, Message result) {
4723         IRadio radioProxy = getRadioProxy(result);
4724         if (radioProxy != null) {
4725             RILRequest rr = obtainRequest(RIL_REQUEST_ALLOW_DATA, result,
4726                     mRILDefaultWorkSource);
4727 
4728             if (RILJ_LOGD) {
4729                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4730                         + " allowed = " + allowed);
4731             }
4732 
4733             try {
4734                 radioProxy.setDataAllowed(rr.mSerial, allowed);
4735             } catch (RemoteException | RuntimeException e) {
4736                 handleRadioProxyExceptionForRR(rr, "setDataAllowed", e);
4737             }
4738         }
4739     }
4740 
4741     @Override
getHardwareConfig(Message result)4742     public void getHardwareConfig(Message result) {
4743         IRadio radioProxy = getRadioProxy(result);
4744         if (radioProxy != null) {
4745             RILRequest rr = obtainRequest(RIL_REQUEST_GET_HARDWARE_CONFIG, result,
4746                     mRILDefaultWorkSource);
4747 
4748             // Do not log function args for privacy
4749             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4750 
4751             try {
4752                 radioProxy.getHardwareConfig(rr.mSerial);
4753             } catch (RemoteException | RuntimeException e) {
4754                 handleRadioProxyExceptionForRR(rr, "getHardwareConfig", e);
4755             }
4756         }
4757     }
4758 
4759     @Override
requestIccSimAuthentication(int authContext, String data, String aid, Message result)4760     public void requestIccSimAuthentication(int authContext, String data, String aid,
4761                                             Message result) {
4762         IRadio radioProxy = getRadioProxy(result);
4763         if (radioProxy != null) {
4764             RILRequest rr = obtainRequest(RIL_REQUEST_SIM_AUTHENTICATION, result,
4765                     mRILDefaultWorkSource);
4766 
4767             // Do not log function args for privacy
4768             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4769 
4770             try {
4771                 radioProxy.requestIccSimAuthentication(rr.mSerial,
4772                         authContext,
4773                         convertNullToEmptyString(data),
4774                         convertNullToEmptyString(aid));
4775             } catch (RemoteException | RuntimeException e) {
4776                 handleRadioProxyExceptionForRR(rr, "requestIccSimAuthentication", e);
4777             }
4778         }
4779     }
4780 
4781     @Override
setDataProfile(DataProfile[] dps, boolean isRoaming, Message result)4782     public void setDataProfile(DataProfile[] dps, boolean isRoaming, Message result) {
4783         IRadio radioProxy = getRadioProxy(result);
4784         if (radioProxy != null) {
4785             RILRequest rr = obtainRequest(RIL_REQUEST_SET_DATA_PROFILE, result,
4786                     mRILDefaultWorkSource);
4787             try {
4788                 if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
4789                     // V1.5
4790                     android.hardware.radio.V1_5.IRadio radioProxy15 =
4791                             (android.hardware.radio.V1_5.IRadio) radioProxy;
4792 
4793                     ArrayList<android.hardware.radio.V1_5.DataProfileInfo> dpis = new ArrayList<>();
4794                     for (DataProfile dp : dps) {
4795                         dpis.add(convertToHalDataProfile15(dp));
4796                     }
4797 
4798                     if (RILJ_LOGD) {
4799                         riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4800                                 + " with data profiles : ");
4801                         for (DataProfile profile : dps) {
4802                             riljLog(profile.toString());
4803                         }
4804                     }
4805 
4806                     radioProxy15.setDataProfile_1_5(rr.mSerial, dpis);
4807                 } else if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_4)) {
4808                     // V1.4
4809                     android.hardware.radio.V1_4.IRadio radioProxy14 =
4810                             (android.hardware.radio.V1_4.IRadio) radioProxy;
4811 
4812                     ArrayList<android.hardware.radio.V1_4.DataProfileInfo> dpis = new ArrayList<>();
4813                     for (DataProfile dp : dps) {
4814                         dpis.add(convertToHalDataProfile14(dp));
4815                     }
4816 
4817                     if (RILJ_LOGD) {
4818                         riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4819                                 + " with data profiles : ");
4820                         for (DataProfile profile : dps) {
4821                             riljLog(profile.toString());
4822                         }
4823                     }
4824 
4825                     radioProxy14.setDataProfile_1_4(rr.mSerial, dpis);
4826                 } else {
4827                     // V1.0, 1.1, 1,2 and 1.3
4828                     ArrayList<android.hardware.radio.V1_0.DataProfileInfo> dpis = new ArrayList<>();
4829                     for (DataProfile dp : dps) {
4830                         // For v1.0 to v1.2, we only send data profiles that has the persistent
4831                         // (a.k.a modem cognitive) bit set to true.
4832                         if (dp.isPersistent()) {
4833                             dpis.add(convertToHalDataProfile10(dp));
4834                         }
4835                     }
4836 
4837                     if (!dpis.isEmpty()) {
4838                         if (RILJ_LOGD) {
4839                             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4840                                     + " with data profiles : ");
4841                             for (DataProfile profile : dps) {
4842                                 riljLog(profile.toString());
4843                             }
4844                         }
4845 
4846                         radioProxy.setDataProfile(rr.mSerial, dpis, isRoaming);
4847                     }
4848                 }
4849             } catch (RemoteException | RuntimeException e) {
4850                 handleRadioProxyExceptionForRR(rr, "setDataProfile", e);
4851             }
4852         }
4853     }
4854 
4855     @Override
requestShutdown(Message result)4856     public void requestShutdown(Message result) {
4857         IRadio radioProxy = getRadioProxy(result);
4858         if (radioProxy != null) {
4859             RILRequest rr = obtainRequest(RIL_REQUEST_SHUTDOWN, result,
4860                     mRILDefaultWorkSource);
4861 
4862             if (RILJ_LOGD) {
4863                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4864             }
4865 
4866             try {
4867                 radioProxy.requestShutdown(rr.mSerial);
4868             } catch (RemoteException | RuntimeException e) {
4869                 handleRadioProxyExceptionForRR(rr, "requestShutdown", e);
4870             }
4871         }
4872     }
4873 
4874     @Override
getRadioCapability(Message response)4875     public void getRadioCapability(Message response) {
4876         IRadio radioProxy = getRadioProxy(response);
4877         if (radioProxy != null) {
4878             RILRequest rr = obtainRequest(RIL_REQUEST_GET_RADIO_CAPABILITY, response,
4879                     mRILDefaultWorkSource);
4880 
4881             if (RILJ_LOGD) {
4882                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4883             }
4884 
4885             try {
4886                 radioProxy.getRadioCapability(rr.mSerial);
4887             } catch (RemoteException | RuntimeException e) {
4888                 handleRadioProxyExceptionForRR(rr, "getRadioCapability", e);
4889             }
4890         }
4891     }
4892 
4893     @Override
setRadioCapability(RadioCapability rc, Message response)4894     public void setRadioCapability(RadioCapability rc, Message response) {
4895         IRadio radioProxy = getRadioProxy(response);
4896         if (radioProxy != null) {
4897             RILRequest rr = obtainRequest(RIL_REQUEST_SET_RADIO_CAPABILITY, response,
4898                     mRILDefaultWorkSource);
4899 
4900             if (RILJ_LOGD) {
4901                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4902                         + " RadioCapability = " + rc.toString());
4903             }
4904 
4905             android.hardware.radio.V1_0.RadioCapability halRc =
4906                     new android.hardware.radio.V1_0.RadioCapability();
4907 
4908             halRc.session = rc.getSession();
4909             halRc.phase = rc.getPhase();
4910             halRc.raf = rc.getRadioAccessFamily();
4911             halRc.logicalModemUuid = convertNullToEmptyString(rc.getLogicalModemUuid());
4912             halRc.status = rc.getStatus();
4913 
4914             try {
4915                 radioProxy.setRadioCapability(rr.mSerial, halRc);
4916             } catch (Exception e) {
4917                 handleRadioProxyExceptionForRR(rr, "setRadioCapability", e);
4918             }
4919         }
4920     }
4921 
4922     @Override
startLceService(int reportIntervalMs, boolean pullMode, Message result)4923     public void startLceService(int reportIntervalMs, boolean pullMode, Message result) {
4924         IRadio radioProxy = getRadioProxy(result);
4925 
4926         if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_2)) {
4927             // We have a 1.2 or later radio, so the LCE 1.0 LCE service control path is unused.
4928             // Instead the LCE functionality is always-on and provides unsolicited indications.
4929             return;
4930         }
4931 
4932         if (radioProxy != null) {
4933             RILRequest rr = obtainRequest(RIL_REQUEST_START_LCE, result,
4934                     mRILDefaultWorkSource);
4935 
4936             if (RILJ_LOGD) {
4937                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4938                         + " reportIntervalMs = " + reportIntervalMs + " pullMode = " + pullMode);
4939             }
4940 
4941             try {
4942                 radioProxy.startLceService(rr.mSerial, reportIntervalMs, pullMode);
4943             } catch (RemoteException | RuntimeException e) {
4944                 handleRadioProxyExceptionForRR(rr, "startLceService", e);
4945             }
4946         }
4947     }
4948 
4949     @Override
stopLceService(Message result)4950     public void stopLceService(Message result) {
4951         IRadio radioProxy = getRadioProxy(result);
4952         if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_2)) {
4953             // We have a 1.2 or later radio, so the LCE 1.0 LCE service control is unused.
4954             // Instead the LCE functionality is always-on and provides unsolicited indications.
4955             return;
4956         }
4957 
4958         if (radioProxy != null) {
4959             RILRequest rr = obtainRequest(RIL_REQUEST_STOP_LCE, result,
4960                     mRILDefaultWorkSource);
4961 
4962             if (RILJ_LOGD) {
4963                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4964             }
4965 
4966             try {
4967                 radioProxy.stopLceService(rr.mSerial);
4968             } catch (RemoteException | RuntimeException e) {
4969                 handleRadioProxyExceptionForRR(rr, "stopLceService", e);
4970             }
4971         }
4972     }
4973 
4974     /**
4975      * Control the data throttling at modem.
4976      *
4977      * @param result Message that will be sent back to the requester
4978      * @param workSource calling Worksource
4979      * @param dataThrottlingAction the DataThrottlingAction that is being requested. Defined in
4980      *      android.hardware.radio@1.6.types.
4981      * @param completionWindowMillis milliseconds in which full throttling has to be achieved.
4982      */
4983     @Override
setDataThrottling(Message result, WorkSource workSource, int dataThrottlingAction, long completionWindowMillis)4984     public void setDataThrottling(Message result, WorkSource workSource, int dataThrottlingAction,
4985             long completionWindowMillis) {
4986         IRadio radioProxy = getRadioProxy(result);
4987         if (radioProxy != null) {
4988             if (mRadioVersion.less(RADIO_HAL_VERSION_1_6)) {
4989                 if (result != null) {
4990                     AsyncResult.forMessage(result, null,
4991                             CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
4992                     result.sendToTarget();
4993                 }
4994                 return;
4995             }
4996 
4997             android.hardware.radio.V1_6.IRadio radioProxy16 =
4998                     (android.hardware.radio.V1_6.IRadio) radioProxy;
4999             RILRequest rr = obtainRequest(RIL_REQUEST_SET_DATA_THROTTLING, result,
5000                     workSource == null ? mRILDefaultWorkSource : workSource);
5001 
5002             if (RILJ_LOGD) {
5003                 riljLog(rr.serialString() + "> "
5004                         + requestToString(rr.mRequest)
5005                         + " dataThrottlingAction = " + dataThrottlingAction
5006                         + " completionWindowMillis " + completionWindowMillis);
5007             }
5008 
5009             try {
5010                 radioProxy16.setDataThrottling(rr.mSerial, (byte) dataThrottlingAction,
5011                         completionWindowMillis);
5012             } catch (RemoteException | RuntimeException e) {
5013                 handleRadioProxyExceptionForRR(rr, "setDataThrottling", e);
5014             }
5015         }
5016     }
5017 
5018     /**
5019      * This will only be called if the LCE service is started in PULL mode, which is
5020      * only enabled when using Radio HAL versions 1.1 and earlier.
5021      *
5022      * It is still possible for vendors to override this behavior and use the 1.1 version
5023      * of LCE; however, this is strongly discouraged and this functionality will be removed
5024      * when HAL 1.x support is dropped.
5025      *
5026      * @deprecated HAL 1.2 and later use an always-on LCE that relies on indications.
5027      */
5028     @Deprecated
5029     @Override
pullLceData(Message response)5030     public void pullLceData(Message response) {
5031         IRadio radioProxy = getRadioProxy(response);
5032         if (radioProxy != null) {
5033             RILRequest rr = obtainRequest(RIL_REQUEST_PULL_LCEDATA, response,
5034                     mRILDefaultWorkSource);
5035 
5036             if (RILJ_LOGD) {
5037                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5038             }
5039 
5040             try {
5041                 radioProxy.pullLceData(rr.mSerial);
5042             } catch (RemoteException | RuntimeException e) {
5043                 handleRadioProxyExceptionForRR(rr, "pullLceData", e);
5044             }
5045         }
5046     }
5047 
5048     @Override
getModemActivityInfo(Message result, WorkSource workSource)5049     public void getModemActivityInfo(Message result, WorkSource workSource) {
5050         workSource = getDefaultWorkSourceIfInvalid(workSource);
5051         IRadio radioProxy = getRadioProxy(result);
5052         if (radioProxy != null) {
5053             RILRequest rr = obtainRequest(RIL_REQUEST_GET_ACTIVITY_INFO, result,
5054                     workSource);
5055 
5056             if (RILJ_LOGD) {
5057                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5058             }
5059 
5060             try {
5061                 radioProxy.getModemActivityInfo(rr.mSerial);
5062 
5063                 Message msg = mRilHandler.obtainMessage(EVENT_BLOCKING_RESPONSE_TIMEOUT);
5064                 msg.obj = null;
5065                 msg.arg1 = rr.mSerial;
5066                 mRilHandler.sendMessageDelayed(msg, DEFAULT_BLOCKING_MESSAGE_RESPONSE_TIMEOUT_MS);
5067             } catch (RemoteException | RuntimeException e) {
5068                 handleRadioProxyExceptionForRR(rr, "getModemActivityInfo", e);
5069             }
5070         }
5071 
5072 
5073     }
5074 
5075     /**
5076      * Convert a list of CarrierIdentifier into a list of Carrier defined in 1.0/types.hal.
5077      * @param carriers List of CarrierIdentifier
5078      * @return List of converted objects
5079      */
5080     @VisibleForTesting
createCarrierRestrictionList( List<CarrierIdentifier> carriers)5081     public static ArrayList<Carrier> createCarrierRestrictionList(
5082             List<CarrierIdentifier> carriers) {
5083         ArrayList<Carrier> result = new ArrayList<>();
5084         for (CarrierIdentifier ci : carriers) {
5085             Carrier c = new Carrier();
5086             c.mcc = convertNullToEmptyString(ci.getMcc());
5087             c.mnc = convertNullToEmptyString(ci.getMnc());
5088             int matchType = CarrierIdentifier.MatchType.ALL;
5089             String matchData = null;
5090             if (!TextUtils.isEmpty(ci.getSpn())) {
5091                 matchType = CarrierIdentifier.MatchType.SPN;
5092                 matchData = ci.getSpn();
5093             } else if (!TextUtils.isEmpty(ci.getImsi())) {
5094                 matchType = CarrierIdentifier.MatchType.IMSI_PREFIX;
5095                 matchData = ci.getImsi();
5096             } else if (!TextUtils.isEmpty(ci.getGid1())) {
5097                 matchType = CarrierIdentifier.MatchType.GID1;
5098                 matchData = ci.getGid1();
5099             } else if (!TextUtils.isEmpty(ci.getGid2())) {
5100                 matchType = CarrierIdentifier.MatchType.GID2;
5101                 matchData = ci.getGid2();
5102             }
5103             c.matchType = matchType;
5104             c.matchData = convertNullToEmptyString(matchData);
5105             result.add(c);
5106         }
5107         return result;
5108     }
5109 
5110     @Override
setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules, Message result, WorkSource workSource)5111     public void setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules,
5112             Message result, WorkSource workSource) {
5113         riljLog("RIL.java - setAllowedCarriers");
5114 
5115         checkNotNull(carrierRestrictionRules, "Carrier restriction cannot be null.");
5116         workSource = getDefaultWorkSourceIfInvalid(workSource);
5117 
5118         IRadio radioProxy = getRadioProxy(result);
5119         if (radioProxy == null) return;
5120 
5121         RILRequest rr = obtainRequest(RIL_REQUEST_SET_ALLOWED_CARRIERS, result, workSource);
5122 
5123         if (RILJ_LOGD) {
5124             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " params: "
5125                     + carrierRestrictionRules);
5126         }
5127 
5128         // Extract multisim policy
5129         int policy = SimLockMultiSimPolicy.NO_MULTISIM_POLICY;
5130         switch (carrierRestrictionRules.getMultiSimPolicy()) {
5131             case CarrierRestrictionRules.MULTISIM_POLICY_ONE_VALID_SIM_MUST_BE_PRESENT:
5132                 policy = SimLockMultiSimPolicy.ONE_VALID_SIM_MUST_BE_PRESENT;
5133                 break;
5134         }
5135 
5136         if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_4)) {
5137             riljLog("RIL.java - Using IRadio 1.4 or greater");
5138 
5139             android.hardware.radio.V1_4.IRadio radioProxy14 =
5140                     (android.hardware.radio.V1_4.IRadio) radioProxy;
5141 
5142             // Prepare structure with allowed list, excluded list and priority
5143             CarrierRestrictionsWithPriority carrierRestrictions =
5144                     new CarrierRestrictionsWithPriority();
5145             carrierRestrictions.allowedCarriers =
5146                     createCarrierRestrictionList(carrierRestrictionRules.getAllowedCarriers());
5147             carrierRestrictions.excludedCarriers =
5148                     createCarrierRestrictionList(carrierRestrictionRules.getExcludedCarriers());
5149             carrierRestrictions.allowedCarriersPrioritized =
5150                     (carrierRestrictionRules.getDefaultCarrierRestriction()
5151                         == CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED);
5152 
5153             try {
5154                 radioProxy14.setAllowedCarriers_1_4(rr.mSerial, carrierRestrictions, policy);
5155             } catch (RemoteException | RuntimeException e) {
5156                 handleRadioProxyExceptionForRR(rr, "setAllowedCarriers_1_4", e);
5157             }
5158         } else {
5159             boolean isAllCarriersAllowed = carrierRestrictionRules.isAllCarriersAllowed();
5160 
5161             boolean supported = (isAllCarriersAllowed
5162                     || (carrierRestrictionRules.getExcludedCarriers().isEmpty()
5163                         && (carrierRestrictionRules.getDefaultCarrierRestriction()
5164                             == CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED)));
5165             supported = supported && (policy == SimLockMultiSimPolicy.NO_MULTISIM_POLICY);
5166 
5167             if (!supported) {
5168                 // Feature is not supported by IRadio interface
5169                 riljLoge("setAllowedCarriers does not support excluded list on IRadio version"
5170                         + " less than 1.4");
5171                 if (result != null) {
5172                     AsyncResult.forMessage(result, null,
5173                             CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5174                     result.sendToTarget();
5175                 }
5176                 return;
5177             }
5178             riljLog("RIL.java - Using IRadio 1.3 or lower");
5179 
5180             // Prepare structure with allowed list
5181             CarrierRestrictions carrierRestrictions = new CarrierRestrictions();
5182             carrierRestrictions.allowedCarriers =
5183                     createCarrierRestrictionList(carrierRestrictionRules.getAllowedCarriers());
5184 
5185             try {
5186                 radioProxy.setAllowedCarriers(rr.mSerial, isAllCarriersAllowed,
5187                         carrierRestrictions);
5188             } catch (RemoteException | RuntimeException e) {
5189                 handleRadioProxyExceptionForRR(rr, "setAllowedCarriers", e);
5190             }
5191         }
5192     }
5193 
5194     @Override
getAllowedCarriers(Message result, WorkSource workSource)5195     public void getAllowedCarriers(Message result, WorkSource workSource) {
5196         workSource = getDefaultWorkSourceIfInvalid(workSource);
5197 
5198         IRadio radioProxy = getRadioProxy(result);
5199         if (radioProxy == null) return;
5200 
5201         RILRequest rr = obtainRequest(RIL_REQUEST_GET_ALLOWED_CARRIERS, result,
5202                 workSource);
5203 
5204         if (RILJ_LOGD) {
5205             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5206         }
5207 
5208         if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_4)) {
5209             riljLog("RIL.java - Using IRadio 1.4 or greater");
5210 
5211             android.hardware.radio.V1_4.IRadio radioProxy14 =
5212                     (android.hardware.radio.V1_4.IRadio) radioProxy;
5213 
5214             try {
5215                 radioProxy14.getAllowedCarriers_1_4(rr.mSerial);
5216             } catch (RemoteException | RuntimeException e) {
5217                 handleRadioProxyExceptionForRR(rr, "getAllowedCarriers_1_4", e);
5218             }
5219         } else {
5220             riljLog("RIL.java - Using IRadio 1.3 or lower");
5221 
5222             try {
5223                 radioProxy.getAllowedCarriers(rr.mSerial);
5224             } catch (RemoteException | RuntimeException e) {
5225                 handleRadioProxyExceptionForRR(rr, "getAllowedCarriers", e);
5226             }
5227         }
5228     }
5229 
5230     @Override
sendDeviceState(int stateType, boolean state, Message result)5231     public void sendDeviceState(int stateType, boolean state,
5232                                 Message result) {
5233         IRadio radioProxy = getRadioProxy(result);
5234         if (radioProxy != null) {
5235             RILRequest rr = obtainRequest(RIL_REQUEST_SEND_DEVICE_STATE, result,
5236                     mRILDefaultWorkSource);
5237 
5238             if (RILJ_LOGD) {
5239                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " "
5240                         + stateType + ":" + state);
5241             }
5242 
5243             try {
5244                 radioProxy.sendDeviceState(rr.mSerial, stateType, state);
5245             } catch (RemoteException | RuntimeException e) {
5246                 handleRadioProxyExceptionForRR(rr, "sendDeviceState", e);
5247             }
5248         }
5249     }
5250 
5251     @Override
setUnsolResponseFilter(int filter, Message result)5252     public void setUnsolResponseFilter(int filter, Message result) {
5253         IRadio radioProxy = getRadioProxy(result);
5254         if (radioProxy != null) {
5255             RILRequest rr = obtainRequest(RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER, result,
5256                     mRILDefaultWorkSource);
5257 
5258             if (RILJ_LOGD) {
5259                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " " + filter);
5260             }
5261 
5262             if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
5263                 try {
5264                     android.hardware.radio.V1_5.IRadio radioProxy15 =
5265                             (android.hardware.radio.V1_5.IRadio) radioProxy;
5266 
5267                     filter &= INDICATION_FILTERS_ALL_V1_5;
5268                     radioProxy15.setIndicationFilter_1_5(rr.mSerial, filter);
5269                 } catch (RemoteException | RuntimeException e) {
5270                     handleRadioProxyExceptionForRR(rr, "setIndicationFilter_1_5", e);
5271                 }
5272             } else if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_2)) {
5273                 try {
5274                     android.hardware.radio.V1_2.IRadio radioProxy12 =
5275                             (android.hardware.radio.V1_2.IRadio) radioProxy;
5276 
5277                     filter &= INDICATION_FILTERS_ALL_V1_2;
5278                     radioProxy12.setIndicationFilter_1_2(rr.mSerial, filter);
5279                 } catch (RemoteException | RuntimeException e) {
5280                     handleRadioProxyExceptionForRR(rr, "setIndicationFilter_1_2", e);
5281                 }
5282             } else {
5283                 try {
5284                     filter &= INDICATION_FILTERS_ALL_V1_0;
5285                     radioProxy.setIndicationFilter(rr.mSerial, filter);
5286                 } catch (RemoteException | RuntimeException e) {
5287                     handleRadioProxyExceptionForRR(rr, "setIndicationFilter", e);
5288                 }
5289             }
5290         }
5291     }
5292 
5293     @Override
setSignalStrengthReportingCriteria(SignalThresholdInfo signalThresholdInfo, int ran, Message result)5294     public void setSignalStrengthReportingCriteria(SignalThresholdInfo signalThresholdInfo,
5295             int ran, Message result) {
5296         IRadio radioProxy = getRadioProxy(result);
5297         if (radioProxy != null) {
5298             if (mRadioVersion.less(RADIO_HAL_VERSION_1_2)) {
5299                 riljLoge("setSignalStrengthReportingCriteria ignored on IRadio version less "
5300                         + "than 1.2");
5301                 return;
5302             }
5303             if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_2)
5304                     && mRadioVersion.less(RADIO_HAL_VERSION_1_5)) {
5305                 RILRequest rr = obtainRequest(RIL_REQUEST_SET_SIGNAL_STRENGTH_REPORTING_CRITERIA,
5306                         result, mRILDefaultWorkSource);
5307                 if (RILJ_LOGD) {
5308                     riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5309                 }
5310                 try {
5311                     android.hardware.radio.V1_2.IRadio radioProxy12 =
5312                         (android.hardware.radio.V1_2.IRadio) radioProxy;
5313                     radioProxy12.setSignalStrengthReportingCriteria(rr.mSerial,
5314                             signalThresholdInfo.getHysteresisMs(),
5315                             signalThresholdInfo.getHysteresisDb(),
5316                             primitiveArrayToArrayList(signalThresholdInfo.getThresholds()),
5317                             convertAntToHalAnt(ran));
5318                 } catch (RemoteException | RuntimeException e) {
5319                     handleRadioProxyExceptionForRR(rr, "setSignalStrengthReportingCriteria", e);
5320                 }
5321             }
5322             if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
5323                 RILRequest rr = obtainRequest(RIL_REQUEST_SET_SIGNAL_STRENGTH_REPORTING_CRITERIA,
5324                         result, mRILDefaultWorkSource);
5325                 if (RILJ_LOGD) {
5326                     riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5327                 }
5328                 try {
5329                     android.hardware.radio.V1_5.IRadio radioProxy15 =
5330                             (android.hardware.radio.V1_5.IRadio) radioProxy;
5331                     radioProxy15.setSignalStrengthReportingCriteria_1_5(rr.mSerial,
5332                             convertToHalSignalThresholdInfo(signalThresholdInfo),
5333                             convertAntToHalAnt(ran));
5334                 } catch (RemoteException | RuntimeException e) {
5335                     handleRadioProxyExceptionForRR(
5336                             rr, "setSignalStrengthReportingCriteria_1_5", e);
5337                 }
5338             }
5339         }
5340     }
5341 
convertToHalSignalThresholdInfo( SignalThresholdInfo signalThresholdInfo)5342     private static android.hardware.radio.V1_5.SignalThresholdInfo convertToHalSignalThresholdInfo(
5343             SignalThresholdInfo signalThresholdInfo) {
5344         android.hardware.radio.V1_5.SignalThresholdInfo signalThresholdInfoHal =
5345                 new android.hardware.radio.V1_5.SignalThresholdInfo();
5346         signalThresholdInfoHal.signalMeasurement = signalThresholdInfo.getSignalMeasurementType();
5347         signalThresholdInfoHal.hysteresisMs = signalThresholdInfo.getHysteresisMs();
5348         signalThresholdInfoHal.hysteresisDb = signalThresholdInfo.getHysteresisDb();
5349         signalThresholdInfoHal.thresholds = primitiveArrayToArrayList(
5350                 signalThresholdInfo.getThresholds());
5351         signalThresholdInfoHal.isEnabled = signalThresholdInfo.isEnabled();
5352         return signalThresholdInfoHal;
5353     }
5354 
5355     @Override
setLinkCapacityReportingCriteria(int hysteresisMs, int hysteresisDlKbps, int hysteresisUlKbps, int[] thresholdsDlKbps, int[] thresholdsUlKbps, int ran, Message result)5356     public void setLinkCapacityReportingCriteria(int hysteresisMs, int hysteresisDlKbps,
5357             int hysteresisUlKbps, int[] thresholdsDlKbps, int[] thresholdsUlKbps, int ran,
5358             Message result) {
5359         IRadio radioProxy = getRadioProxy(result);
5360         if (radioProxy != null) {
5361             RILRequest rr = obtainRequest(RIL_REQUEST_SET_LINK_CAPACITY_REPORTING_CRITERIA, result,
5362                     mRILDefaultWorkSource);
5363             if (RILJ_LOGD) {
5364                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5365             }
5366             try {
5367                 if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
5368                     android.hardware.radio.V1_5.IRadio radioProxy15 =
5369                             (android.hardware.radio.V1_5.IRadio) radioProxy;
5370                     radioProxy15.setLinkCapacityReportingCriteria_1_5(rr.mSerial, hysteresisMs,
5371                             hysteresisDlKbps, hysteresisUlKbps,
5372                             primitiveArrayToArrayList(thresholdsDlKbps),
5373                             primitiveArrayToArrayList(thresholdsUlKbps), convertAntToHalAnt(ran));
5374                 } else if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_2)) {
5375                     android.hardware.radio.V1_2.IRadio radioProxy12 =
5376                             (android.hardware.radio.V1_2.IRadio) radioProxy;
5377                     if (ran == AccessNetworkType.NGRAN) {
5378                         throw new RuntimeException("NGRAN unsupported on IRadio version 1.2.");
5379                     }
5380                     radioProxy12.setLinkCapacityReportingCriteria(rr.mSerial, hysteresisMs,
5381                             hysteresisDlKbps, hysteresisUlKbps,
5382                             primitiveArrayToArrayList(thresholdsDlKbps),
5383                             primitiveArrayToArrayList(thresholdsUlKbps), convertAntToHalAnt(ran));
5384                 } else {
5385                     riljLoge("setLinkCapacityReportingCriteria ignored on IRadio version less "
5386                             + "than 1.2");
5387                 }
5388             } catch (RemoteException | RuntimeException e) {
5389                 handleRadioProxyExceptionForRR(rr, "setLinkCapacityReportingCriteria", e);
5390             }
5391         }
5392     }
5393 
5394     /** Converts from AccessNetworkType in frameworks to AccessNetwork in HAL. */
convertAntToHalAnt(int radioAccessNetwork)5395     private static int convertAntToHalAnt(int radioAccessNetwork) {
5396         switch (radioAccessNetwork) {
5397             case AccessNetworkType.GERAN:
5398                 return AccessNetwork.GERAN;
5399             case AccessNetworkType.UTRAN:
5400                 return AccessNetwork.UTRAN;
5401             case AccessNetworkType.EUTRAN:
5402                 return AccessNetwork.EUTRAN;
5403             case AccessNetworkType.CDMA2000:
5404                 return AccessNetwork.CDMA2000;
5405             case AccessNetworkType.IWLAN:
5406                 return AccessNetwork.IWLAN;
5407             case AccessNetworkType.NGRAN:
5408                 return AccessNetwork.NGRAN;
5409             case AccessNetworkType.UNKNOWN:
5410             default:
5411                 return AccessNetwork.UNKNOWN;
5412         }
5413     }
5414 
5415     /** Converts from AccessNetworkType in frameworks to RadioAccessNetworks in HAL. */
convertAntToRan(int accessNetworkType)5416     private static int convertAntToRan(int accessNetworkType) {
5417         switch (accessNetworkType) {
5418             case AccessNetworkType.GERAN:
5419                 return RadioAccessNetworks.GERAN;
5420             case AccessNetworkType.UTRAN:
5421                 return RadioAccessNetworks.UTRAN;
5422             case AccessNetworkType.EUTRAN:
5423                 return RadioAccessNetworks.EUTRAN;
5424             case AccessNetworkType.NGRAN:
5425                 return RadioAccessNetworks.NGRAN;
5426             case AccessNetworkType.CDMA2000:
5427                 return RadioAccessNetworks.CDMA2000;
5428             case AccessNetworkType.UNKNOWN:
5429             default:
5430                 return RadioAccessNetworks.UNKNOWN;
5431         }
5432     }
5433 
5434     @Override
setSimCardPower(int state, Message result, WorkSource workSource)5435     public void setSimCardPower(int state, Message result, WorkSource workSource) {
5436         workSource = getDefaultWorkSourceIfInvalid(workSource);
5437         IRadio radioProxy = getRadioProxy(result);
5438         if (radioProxy != null) {
5439             RILRequest rr = obtainRequest(RIL_REQUEST_SET_SIM_CARD_POWER, result,
5440                     workSource);
5441 
5442             if (RILJ_LOGD) {
5443                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " " + state);
5444             }
5445 
5446             if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
5447                 try {
5448                     android.hardware.radio.V1_6.IRadio radioProxy16 =
5449                             (android.hardware.radio.V1_6.IRadio) radioProxy;
5450                     radioProxy16.setSimCardPower_1_6(rr.mSerial, state);
5451                 } catch (RemoteException | RuntimeException e) {
5452                     handleRadioProxyExceptionForRR(rr, "setSimCardPower", e);
5453                 }
5454             } else if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_1)) {
5455                 try {
5456                     android.hardware.radio.V1_1.IRadio radioProxy11 =
5457                             (android.hardware.radio.V1_1.IRadio) radioProxy;
5458                     radioProxy11.setSimCardPower_1_1(rr.mSerial, state);
5459                 } catch (RemoteException | RuntimeException e) {
5460                     handleRadioProxyExceptionForRR(rr, "setSimCardPower", e);
5461                 }
5462             } else {
5463                 try {
5464                     switch (state) {
5465                         case TelephonyManager.CARD_POWER_DOWN: {
5466                             radioProxy.setSimCardPower(rr.mSerial, false);
5467                             break;
5468                         }
5469                         case TelephonyManager.CARD_POWER_UP: {
5470                             radioProxy.setSimCardPower(rr.mSerial, true);
5471                             break;
5472                         }
5473                         default: {
5474                             if (result != null) {
5475                                 AsyncResult.forMessage(result, null,
5476                                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5477                                 result.sendToTarget();
5478                             }
5479                         }
5480                     }
5481                 } catch (RemoteException | RuntimeException e) {
5482                     handleRadioProxyExceptionForRR(rr, "setSimCardPower", e);
5483                 }
5484             }
5485         }
5486     }
5487 
5488     @Override
setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo, Message result)5489     public void setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo,
5490                                                 Message result) {
5491         checkNotNull(imsiEncryptionInfo, "ImsiEncryptionInfo cannot be null.");
5492         IRadio radioProxy = getRadioProxy(result);
5493         if (radioProxy != null) {
5494             if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
5495                 android.hardware.radio.V1_6.IRadio radioProxy16 =
5496                         (android.hardware.radio.V1_6.IRadio ) radioProxy;
5497 
5498                 RILRequest rr = obtainRequest(RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION, result,
5499                         mRILDefaultWorkSource);
5500                 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5501 
5502                 try {
5503                     android.hardware.radio.V1_6.ImsiEncryptionInfo halImsiInfo =
5504                             new android.hardware.radio.V1_6.ImsiEncryptionInfo();
5505                     halImsiInfo.base.mnc = imsiEncryptionInfo.getMnc();
5506                     halImsiInfo.base.mcc = imsiEncryptionInfo.getMcc();
5507                     halImsiInfo.base.keyIdentifier = imsiEncryptionInfo.getKeyIdentifier();
5508                     if (imsiEncryptionInfo.getExpirationTime() != null) {
5509                         halImsiInfo.base.expirationTime =
5510                                 imsiEncryptionInfo.getExpirationTime().getTime();
5511                     }
5512                     for (byte b : imsiEncryptionInfo.getPublicKey().getEncoded()) {
5513                         halImsiInfo.base.carrierKey.add(new Byte(b));
5514                     }
5515                     halImsiInfo.keyType = (byte) imsiEncryptionInfo.getKeyType();
5516 
5517                     radioProxy16.setCarrierInfoForImsiEncryption_1_6(
5518                             rr.mSerial, halImsiInfo);
5519                 } catch (RemoteException | RuntimeException e) {
5520                     handleRadioProxyExceptionForRR(rr, "setCarrierInfoForImsiEncryption", e);
5521                 }
5522             } else if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_1)) {
5523                 android.hardware.radio.V1_1.IRadio radioProxy11 =
5524                         (android.hardware.radio.V1_1.IRadio ) radioProxy;
5525 
5526                 RILRequest rr = obtainRequest(RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION, result,
5527                         mRILDefaultWorkSource);
5528                 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5529 
5530                 try {
5531                     android.hardware.radio.V1_1.ImsiEncryptionInfo halImsiInfo =
5532                             new android.hardware.radio.V1_1.ImsiEncryptionInfo();
5533                     halImsiInfo.mnc = imsiEncryptionInfo.getMnc();
5534                     halImsiInfo.mcc = imsiEncryptionInfo.getMcc();
5535                     halImsiInfo.keyIdentifier = imsiEncryptionInfo.getKeyIdentifier();
5536                     if (imsiEncryptionInfo.getExpirationTime() != null) {
5537                         halImsiInfo.expirationTime =
5538                                 imsiEncryptionInfo.getExpirationTime().getTime();
5539                     }
5540                     for (byte b : imsiEncryptionInfo.getPublicKey().getEncoded()) {
5541                         halImsiInfo.carrierKey.add(new Byte(b));
5542                     }
5543 
5544                     radioProxy11.setCarrierInfoForImsiEncryption(
5545                             rr.mSerial, halImsiInfo);
5546                 } catch (RemoteException | RuntimeException e) {
5547                     handleRadioProxyExceptionForRR(rr, "setCarrierInfoForImsiEncryption", e);
5548                 }
5549             } else if (result != null) {
5550                 AsyncResult.forMessage(result, null,
5551                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5552                 result.sendToTarget();
5553             }
5554         }
5555     }
5556 
5557     @Override
startNattKeepalive( int contextId, KeepalivePacketData packetData, int intervalMillis, Message result)5558     public void startNattKeepalive(
5559             int contextId, KeepalivePacketData packetData, int intervalMillis, Message result) {
5560         checkNotNull(packetData, "KeepaliveRequest cannot be null.");
5561         IRadio radioProxy = getRadioProxy(result);
5562         if (radioProxy == null) return;
5563 
5564         if (mRadioVersion.less(RADIO_HAL_VERSION_1_1)) {
5565             if (result != null) {
5566                 AsyncResult.forMessage(result, null,
5567                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5568                 result.sendToTarget();
5569             }
5570             return;
5571         }
5572 
5573         android.hardware.radio.V1_1.IRadio radioProxy11 =
5574                 (android.hardware.radio.V1_1.IRadio) radioProxy;
5575 
5576         RILRequest rr = obtainRequest(
5577                 RIL_REQUEST_START_KEEPALIVE, result, mRILDefaultWorkSource);
5578 
5579         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5580 
5581         try {
5582             android.hardware.radio.V1_1.KeepaliveRequest req =
5583                     new android.hardware.radio.V1_1.KeepaliveRequest();
5584 
5585             req.cid = contextId;
5586 
5587             if (packetData.getDstAddress() instanceof Inet4Address) {
5588                 req.type = android.hardware.radio.V1_1.KeepaliveType.NATT_IPV4;
5589             } else if (packetData.getDstAddress() instanceof Inet6Address) {
5590                 req.type = android.hardware.radio.V1_1.KeepaliveType.NATT_IPV6;
5591             } else {
5592                 AsyncResult.forMessage(result, null,
5593                         CommandException.fromRilErrno(INVALID_ARGUMENTS));
5594                 result.sendToTarget();
5595                 return;
5596             }
5597 
5598             final InetAddress srcAddress = packetData.getSrcAddress();
5599             final InetAddress dstAddress = packetData.getDstAddress();
5600             appendPrimitiveArrayToArrayList(
5601                     srcAddress.getAddress(), req.sourceAddress);
5602             req.sourcePort = packetData.getSrcPort();
5603             appendPrimitiveArrayToArrayList(
5604                     dstAddress.getAddress(), req.destinationAddress);
5605             req.destinationPort = packetData.getDstPort();
5606             req.maxKeepaliveIntervalMillis = intervalMillis;
5607 
5608             radioProxy11.startKeepalive(rr.mSerial, req);
5609         } catch (RemoteException | RuntimeException e) {
5610             handleRadioProxyExceptionForRR(rr, "startNattKeepalive", e);
5611         }
5612     }
5613 
5614     @Override
stopNattKeepalive(int sessionHandle, Message result)5615     public void stopNattKeepalive(int sessionHandle, Message result) {
5616         IRadio radioProxy = getRadioProxy(result);
5617         if (radioProxy == null) return;
5618 
5619         if (mRadioVersion.less(RADIO_HAL_VERSION_1_1)) {
5620             if (result != null) {
5621                 AsyncResult.forMessage(result, null,
5622                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5623                 result.sendToTarget();
5624             }
5625             return;
5626         }
5627 
5628         android.hardware.radio.V1_1.IRadio radioProxy11 =
5629                 (android.hardware.radio.V1_1.IRadio) radioProxy;
5630 
5631         RILRequest rr = obtainRequest(
5632                 RIL_REQUEST_STOP_KEEPALIVE, result, mRILDefaultWorkSource);
5633 
5634         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5635 
5636         try {
5637             radioProxy11.stopKeepalive(rr.mSerial, sessionHandle);
5638         } catch (RemoteException | RuntimeException e) {
5639             handleRadioProxyExceptionForRR(rr, "stopNattKeepalive", e);
5640         }
5641     }
5642 
5643     @Override
getIMEI(Message result)5644     public void getIMEI(Message result) {
5645         throw new RuntimeException("getIMEI not expected to be called");
5646     }
5647 
5648     @Override
getIMEISV(Message result)5649     public void getIMEISV(Message result) {
5650         throw new RuntimeException("getIMEISV not expected to be called");
5651     }
5652 
5653     /**
5654      * @deprecated
5655      */
5656     @Deprecated
5657     @Override
getLastPdpFailCause(Message result)5658     public void getLastPdpFailCause(Message result) {
5659         throw new RuntimeException("getLastPdpFailCause not expected to be called");
5660     }
5661 
5662     /**
5663      * The preferred new alternative to getLastPdpFailCause
5664      */
5665     @Override
getLastDataCallFailCause(Message result)5666     public void getLastDataCallFailCause(Message result) {
5667         throw new RuntimeException("getLastDataCallFailCause not expected to be called");
5668     }
5669 
5670     /**
5671      * Enable or disable uicc applications on the SIM.
5672      *
5673      * @param enable whether to enable or disable uicc applications.
5674      * @param onCompleteMessage a Message to return to the requester
5675      */
5676     @Override
enableUiccApplications(boolean enable, Message onCompleteMessage)5677     public void enableUiccApplications(boolean enable, Message onCompleteMessage) {
5678         IRadio radioProxy = getRadioProxy(onCompleteMessage);
5679         if (radioProxy == null) return;
5680 
5681         if (mRadioVersion.less(RADIO_HAL_VERSION_1_5)) {
5682             if (onCompleteMessage != null) {
5683                 AsyncResult.forMessage(onCompleteMessage, null,
5684                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5685                 onCompleteMessage.sendToTarget();
5686             }
5687             return;
5688         }
5689 
5690         android.hardware.radio.V1_5.IRadio radioProxy15 =
5691                 (android.hardware.radio.V1_5.IRadio) radioProxy;
5692 
5693         RILRequest rr = obtainRequest(RIL_REQUEST_ENABLE_UICC_APPLICATIONS,
5694                 onCompleteMessage, mRILDefaultWorkSource);
5695 
5696         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5697 
5698         try {
5699             radioProxy15.enableUiccApplications(rr.mSerial, enable);
5700         } catch (RemoteException | RuntimeException e) {
5701             handleRadioProxyExceptionForRR(rr, "enableUiccApplications", e);
5702         }
5703     }
5704 
5705     /**
5706      * Whether uicc applications are enabled or not.
5707      *
5708      * @param onCompleteMessage a Message to return to the requester
5709      */
5710     @Override
areUiccApplicationsEnabled(Message onCompleteMessage)5711     public void areUiccApplicationsEnabled(Message onCompleteMessage) {
5712         IRadio radioProxy = getRadioProxy(onCompleteMessage);
5713         if (radioProxy == null) return;
5714 
5715         if (mRadioVersion.less(RADIO_HAL_VERSION_1_5)) {
5716             if (onCompleteMessage != null) {
5717                 AsyncResult.forMessage(onCompleteMessage, null,
5718                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5719                 onCompleteMessage.sendToTarget();
5720             }
5721             return;
5722         }
5723 
5724         android.hardware.radio.V1_5.IRadio radioProxy15 =
5725                 (android.hardware.radio.V1_5.IRadio) radioProxy;
5726 
5727         RILRequest rr = obtainRequest(RIL_REQUEST_GET_UICC_APPLICATIONS_ENABLEMENT,
5728                 onCompleteMessage, mRILDefaultWorkSource);
5729 
5730         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5731 
5732         try {
5733             radioProxy15.areUiccApplicationsEnabled(rr.mSerial);
5734         } catch (RemoteException | RuntimeException e) {
5735             handleRadioProxyExceptionForRR(rr, "areUiccApplicationsEnabled", e);
5736         }
5737     }
5738 
5739     /**
5740      * Whether {@link #enableUiccApplications} is supported, which is supported in 1.5 version.
5741      */
5742     @Override
canToggleUiccApplicationsEnablement()5743     public boolean canToggleUiccApplicationsEnablement() {
5744         return getRadioProxy(null) != null && mRadioVersion
5745                 .greaterOrEqual(RADIO_HAL_VERSION_1_5);
5746     }
5747 
5748     /**
5749      *  Translates EF_SMS status bits to a status value compatible with
5750      *  SMS AT commands.  See TS 27.005 3.1.
5751      */
translateStatus(int status)5752     private int translateStatus(int status) {
5753         switch(status & 0x7) {
5754             case SmsManager.STATUS_ON_ICC_READ:
5755                 return 1;
5756             case SmsManager.STATUS_ON_ICC_UNREAD:
5757                 return 0;
5758             case SmsManager.STATUS_ON_ICC_SENT:
5759                 return 3;
5760             case SmsManager.STATUS_ON_ICC_UNSENT:
5761                 return 2;
5762         }
5763 
5764         // Default to READ.
5765         return 1;
5766     }
5767 
5768     @Override
resetRadio(Message result)5769     public void resetRadio(Message result) {
5770         throw new RuntimeException("resetRadio not expected to be called");
5771     }
5772 
5773     /**
5774      * {@inheritDoc}
5775      */
5776     @Override
handleCallSetupRequestFromSim(boolean accept, Message result)5777     public void handleCallSetupRequestFromSim(boolean accept, Message result) {
5778         IRadio radioProxy = getRadioProxy(result);
5779         if (radioProxy != null) {
5780             RILRequest rr = obtainRequest(RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM,
5781                     result, mRILDefaultWorkSource);
5782 
5783             if (RILJ_LOGD) {
5784                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5785             }
5786 
5787             try {
5788                 radioProxy.handleStkCallSetupRequestFromSim(rr.mSerial, accept);
5789             } catch (RemoteException | RuntimeException e) {
5790                 handleRadioProxyExceptionForRR(rr, "getAllowedCarriers", e);
5791             }
5792         }
5793     }
5794 
5795     /**
5796      * {@inheritDoc}
5797      */
5798     @Override
getBarringInfo(Message result)5799     public void getBarringInfo(Message result) {
5800         IRadio radioProxy = getRadioProxy(result);
5801         if (radioProxy == null) return;
5802 
5803         if (mRadioVersion.less(RADIO_HAL_VERSION_1_5)) {
5804             if (result != null) {
5805                 AsyncResult.forMessage(result, null,
5806                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5807                 result.sendToTarget();
5808             }
5809             return;
5810         }
5811 
5812         android.hardware.radio.V1_5.IRadio radioProxy15 =
5813                 (android.hardware.radio.V1_5.IRadio) radioProxy;
5814         if (radioProxy15 != null) {
5815             RILRequest rr = obtainRequest(RIL_REQUEST_GET_BARRING_INFO, result,
5816                     mRILDefaultWorkSource);
5817 
5818             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5819 
5820             try {
5821                 radioProxy15.getBarringInfo(rr.mSerial);
5822             } catch (RemoteException | RuntimeException e) {
5823                 handleRadioProxyExceptionForRR(rr, "getBarringInfo", e);
5824             }
5825         }
5826     }
5827 
5828     /**
5829      * {@inheritDoc}
5830      */
5831     @Override
allocatePduSessionId(Message result)5832     public void allocatePduSessionId(Message result) {
5833         android.hardware.radio.V1_6.IRadio radioProxy16 = getRadioV16(result);
5834 
5835         if (radioProxy16 != null) {
5836             RILRequest rr = obtainRequest(RIL_REQUEST_ALLOCATE_PDU_SESSION_ID, result,
5837                     mRILDefaultWorkSource);
5838             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5839 
5840             try {
5841                 radioProxy16.allocatePduSessionId(rr.mSerial);
5842             } catch (RemoteException e) {
5843                 handleRadioProxyExceptionForRR(rr, "allocatePduSessionId", e);
5844             }
5845         } else {
5846             AsyncResult.forMessage(result, null,
5847                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5848             result.sendToTarget();
5849         }
5850     }
5851 
5852     /**
5853      * {@inheritDoc}
5854      */
5855     @Override
releasePduSessionId(Message result, int pduSessionId)5856     public void releasePduSessionId(Message result, int pduSessionId) {
5857         android.hardware.radio.V1_6.IRadio radioProxy16 = getRadioV16(result);
5858 
5859         if (radioProxy16 != null) {
5860             RILRequest rr = obtainRequest(RIL_REQUEST_RELEASE_PDU_SESSION_ID, result,
5861                     mRILDefaultWorkSource);
5862             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5863 
5864             try {
5865                 radioProxy16.releasePduSessionId(rr.mSerial, pduSessionId);
5866             } catch (RemoteException e) {
5867                 handleRadioProxyExceptionForRR(rr, "releasePduSessionId", e);
5868             }
5869         } else {
5870             AsyncResult.forMessage(result, null,
5871                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5872             result.sendToTarget();
5873         }
5874     }
5875 
5876     /**
5877      * {@inheritDoc}
5878      */
5879     @Override
startHandover(Message result, int callId)5880     public void startHandover(Message result, int callId) {
5881         android.hardware.radio.V1_6.IRadio radioProxy16 = getRadioV16(result);
5882 
5883         if (radioProxy16 != null) {
5884             RILRequest rr = obtainRequest(RIL_REQUEST_START_HANDOVER, result,
5885                     mRILDefaultWorkSource);
5886             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5887 
5888             try {
5889                 radioProxy16.startHandover(rr.mSerial, callId);
5890             } catch (RemoteException e) {
5891                 handleRadioProxyExceptionForRR(rr, "startHandover", e);
5892             }
5893         } else {
5894             if (RILJ_LOGD) Rlog.d(RILJ_LOG_TAG, "startHandover: REQUEST_NOT_SUPPORTED");
5895             AsyncResult.forMessage(result, null,
5896                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5897             result.sendToTarget();
5898         }
5899     }
5900 
5901     /**
5902      * {@inheritDoc}
5903      */
5904     @Override
cancelHandover(Message result, int callId)5905     public void cancelHandover(Message result, int callId) {
5906         android.hardware.radio.V1_6.IRadio radioProxy16 = getRadioV16(result);
5907 
5908         if (radioProxy16 != null) {
5909             RILRequest rr = obtainRequest(RIL_REQUEST_CANCEL_HANDOVER, result,
5910                     mRILDefaultWorkSource);
5911             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5912 
5913             try {
5914                 radioProxy16.cancelHandover(rr.mSerial, callId);
5915             } catch (RemoteException e) {
5916                 handleRadioProxyExceptionForRR(rr, "cancelHandover", e);
5917             }
5918         } else {
5919             if (RILJ_LOGD) Rlog.d(RILJ_LOG_TAG, "cancelHandover: REQUEST_NOT_SUPPORTED");
5920             AsyncResult.forMessage(result, null,
5921                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5922             result.sendToTarget();
5923         }
5924     }
5925 
5926     /**
5927      * {@inheritDoc}
5928      */
5929     @Override
getSlicingConfig(Message result)5930     public void getSlicingConfig(Message result) {
5931         android.hardware.radio.V1_6.IRadio radioProxy16 = getRadioV16(result);
5932 
5933         if (radioProxy16 != null) {
5934             RILRequest rr = obtainRequest(RIL_REQUEST_GET_SLICING_CONFIG, result,
5935                     mRILDefaultWorkSource);
5936 
5937             if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5938 
5939             try {
5940                 radioProxy16.getSlicingConfig(rr.mSerial);
5941             } catch (RemoteException | RuntimeException e) {
5942                 handleRadioProxyExceptionForRR(rr, "getSlicingConfig", e);
5943             }
5944         } else {
5945             if (RILJ_LOGD) Rlog.d(RILJ_LOG_TAG, "getSlicingConfig: REQUEST_NOT_SUPPORTED");
5946             AsyncResult.forMessage(result, null,
5947                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5948             result.sendToTarget();
5949         }
5950     }
5951 
5952     @Override
getSimPhonebookRecords(Message result)5953     public void getSimPhonebookRecords(Message result) {
5954         IRadio radioProxy = getRadioProxy(result);
5955         if (radioProxy != null) {
5956             RILRequest rr = obtainRequest(RIL_REQUEST_GET_SIM_PHONEBOOK_RECORDS, result,
5957                     mRILDefaultWorkSource);
5958 
5959             if (RILJ_LOGD) {
5960                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5961             }
5962 
5963             if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
5964                 android.hardware.radio.V1_6.IRadio radioProxy16 =
5965                             android.hardware.radio.V1_6.IRadio.castFrom(radioProxy);
5966                 try {
5967                     radioProxy16.getSimPhonebookRecords(rr.mSerial);
5968                 } catch (RemoteException | RuntimeException e) {
5969                     handleRadioProxyExceptionForRR(rr, "getPhonebookRecords", e);
5970                 }
5971             } else {
5972                 riljLog("Unsupported API in lower than version 1.6 radio HAL" );
5973                 if (result != null) {
5974                     AsyncResult.forMessage(result, null,
5975                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5976                     result.sendToTarget();
5977                 }
5978             }
5979         }
5980     }
5981 
5982     @Override
getSimPhonebookCapacity(Message result)5983     public void getSimPhonebookCapacity(Message result) {
5984         IRadio radioProxy = getRadioProxy(result);
5985         if (radioProxy != null) {
5986             RILRequest rr = obtainRequest(RIL_REQUEST_GET_SIM_PHONEBOOK_CAPACITY, result,
5987                     mRILDefaultWorkSource);
5988 
5989             if (RILJ_LOGD) {
5990                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
5991             }
5992 
5993             if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
5994                 android.hardware.radio.V1_6.IRadio radioProxy16 =
5995                             android.hardware.radio.V1_6.IRadio.castFrom(radioProxy);
5996                 try {
5997                     radioProxy16.getSimPhonebookCapacity(rr.mSerial);
5998                 } catch (RemoteException | RuntimeException e) {
5999                     handleRadioProxyExceptionForRR(rr, "getPhonebookRecords", e);
6000                 }
6001             } else {
6002                 riljLog("Unsupported API in lower than version 1.6 radio HAL" );
6003                 if (result != null) {
6004                     AsyncResult.forMessage(result, null,
6005                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
6006                     result.sendToTarget();
6007                 }
6008             }
6009         }
6010     }
6011 
6012     @Override
updateSimPhonebookRecord(SimPhonebookRecord phonebookRecord, Message result)6013     public void updateSimPhonebookRecord(SimPhonebookRecord phonebookRecord, Message result) {
6014         IRadio radioProxy = getRadioProxy(result);
6015         if (radioProxy != null) {
6016             RILRequest rr = obtainRequest(RIL_REQUEST_UPDATE_SIM_PHONEBOOK_RECORD, result,
6017                     mRILDefaultWorkSource);
6018 
6019             if (RILJ_LOGD) {
6020                 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
6021                         + " with " + phonebookRecord.toString());
6022             }
6023 
6024             if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
6025                 android.hardware.radio.V1_6.IRadio radioProxy16 =
6026                         android.hardware.radio.V1_6.IRadio.castFrom(radioProxy);
6027 
6028                 android.hardware.radio.V1_6.PhonebookRecordInfo pbRecordInfo =
6029                         phonebookRecord.toPhonebookRecordInfo();
6030                 try {
6031                      radioProxy16.updateSimPhonebookRecords(rr.mSerial, pbRecordInfo);
6032                 } catch (RemoteException | RuntimeException e) {
6033                     handleRadioProxyExceptionForRR(rr, "updatePhonebookRecord", e);
6034                 }
6035             } else {
6036                 riljLog("Unsupported API in lower than version 1.6 radio HAL" );
6037                 if (result != null) {
6038                     AsyncResult.forMessage(result, null,
6039                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
6040                     result.sendToTarget();
6041                 }
6042             }
6043         }
6044     }
6045 
6046     //***** Private Methods
6047     /** Helper that gets V1.6 of the radio interface OR sends back REQUEST_NOT_SUPPORTED */
getRadioV16(Message msg)6048     @Nullable private android.hardware.radio.V1_6.IRadio getRadioV16(Message msg) {
6049         IRadio radioProxy = getRadioProxy(msg);
6050         if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
6051             return (android.hardware.radio.V1_6.IRadio) radioProxy;
6052         } else {
6053             return (android.hardware.radio.V1_6.IRadio) null;
6054         }
6055     }
6056 
6057 
6058     /**
6059      * This is a helper function to be called when a RadioIndication callback is called.
6060      * It takes care of acquiring wakelock and sending ack if needed.
6061      * @param indicationType RadioIndicationType received
6062      */
processIndication(int indicationType)6063     void processIndication(int indicationType) {
6064         if (indicationType == RadioIndicationType.UNSOLICITED_ACK_EXP) {
6065             sendAck();
6066             if (RILJ_LOGD) riljLog("Unsol response received; Sending ack to ril.cpp");
6067         } else {
6068             // ack is not expected to be sent back. Nothing is required to be done here.
6069         }
6070     }
6071 
processRequestAck(int serial)6072     void processRequestAck(int serial) {
6073         RILRequest rr;
6074         synchronized (mRequestList) {
6075             rr = mRequestList.get(serial);
6076         }
6077         if (rr == null) {
6078             Rlog.w(RIL.RILJ_LOG_TAG, "processRequestAck: Unexpected solicited ack response! "
6079                     + "serial: " + serial);
6080         } else {
6081             decrementWakeLock(rr);
6082             if (RIL.RILJ_LOGD) {
6083                 riljLog(rr.serialString() + " Ack < " + RIL.requestToString(rr.mRequest));
6084             }
6085         }
6086     }
6087 
6088     /**
6089      * This is a helper function to be called when a RadioResponse callback is called.
6090      * It takes care of acks, wakelocks, and finds and returns RILRequest corresponding to the
6091      * response if one is found.
6092      * @param responseInfo RadioResponseInfo received in response callback
6093      * @return RILRequest corresponding to the response
6094      */
6095     @VisibleForTesting
processResponse(RadioResponseInfo responseInfo)6096     public RILRequest processResponse(RadioResponseInfo responseInfo) {
6097         return processResponseInternal(responseInfo.serial, responseInfo.error, responseInfo.type);
6098     }
6099 
6100     /**
6101      * This is a helper function for V1_6.RadioResponseInfo to be called when a RadioResponse
6102      * callback is called.
6103      * It takes care of acks, wakelocks, and finds and returns RILRequest corresponding to the
6104      * response if one is found.
6105      * @param responseInfo RadioResponseInfo received in response callback
6106      * @return RILRequest corresponding to the response
6107      */
6108     @VisibleForTesting
processResponse_1_6( android.hardware.radio.V1_6.RadioResponseInfo responseInfo)6109     public RILRequest processResponse_1_6(
6110                     android.hardware.radio.V1_6.RadioResponseInfo responseInfo) {
6111         return processResponseInternal(responseInfo.serial, responseInfo.error, responseInfo.type);
6112     }
6113 
processResponseInternal(int serial, int error, int type)6114     private RILRequest processResponseInternal(int serial, int error, int type) {
6115         RILRequest rr = null;
6116 
6117         if (type == RadioResponseType.SOLICITED_ACK) {
6118             synchronized (mRequestList) {
6119                 rr = mRequestList.get(serial);
6120             }
6121             if (rr == null) {
6122                 Rlog.w(RILJ_LOG_TAG, "Unexpected solicited ack response! sn: " + serial);
6123             } else {
6124                 decrementWakeLock(rr);
6125                 if (mRadioBugDetector != null) {
6126                     mRadioBugDetector.detectRadioBug(rr.mRequest, error);
6127                 }
6128                 if (RILJ_LOGD) {
6129                     riljLog(rr.serialString() + " Ack < " + requestToString(rr.mRequest));
6130                 }
6131             }
6132             return rr;
6133         }
6134 
6135         rr = findAndRemoveRequestFromList(serial);
6136         if (rr == null) {
6137             Rlog.e(RIL.RILJ_LOG_TAG, "processResponse: Unexpected response! serial: " + serial
6138                     + " error: " + error);
6139             return null;
6140         }
6141 
6142         // Time logging for RIL command and storing it in TelephonyHistogram.
6143         addToRilHistogram(rr);
6144         if (mRadioBugDetector != null) {
6145             mRadioBugDetector.detectRadioBug(rr.mRequest, error);
6146         }
6147         if (type == RadioResponseType.SOLICITED_ACK_EXP) {
6148             sendAck();
6149             if (RIL.RILJ_LOGD) {
6150                 riljLog("Response received for " + rr.serialString() + " "
6151                         + RIL.requestToString(rr.mRequest) + " Sending ack to ril.cpp");
6152             }
6153         } else {
6154             // ack sent for SOLICITED_ACK_EXP above; nothing to do for SOLICITED response
6155         }
6156 
6157         // Here and below fake RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, see b/7255789.
6158         // This is needed otherwise we don't automatically transition to the main lock
6159         // screen when the pin or puk is entered incorrectly.
6160         switch (rr.mRequest) {
6161             case RIL_REQUEST_ENTER_SIM_PUK:
6162             case RIL_REQUEST_ENTER_SIM_PUK2:
6163                 if (mIccStatusChangedRegistrants != null) {
6164                     if (RILJ_LOGD) {
6165                         riljLog("ON enter sim puk fakeSimStatusChanged: reg count="
6166                                 + mIccStatusChangedRegistrants.size());
6167                     }
6168                     mIccStatusChangedRegistrants.notifyRegistrants();
6169                 }
6170                 break;
6171             case RIL_REQUEST_SHUTDOWN:
6172                 setRadioState(TelephonyManager.RADIO_POWER_UNAVAILABLE,
6173                         false /* forceNotifyRegistrants */);
6174                 break;
6175         }
6176 
6177         if (error != RadioError.NONE) {
6178             switch (rr.mRequest) {
6179                 case RIL_REQUEST_ENTER_SIM_PIN:
6180                 case RIL_REQUEST_ENTER_SIM_PIN2:
6181                 case RIL_REQUEST_CHANGE_SIM_PIN:
6182                 case RIL_REQUEST_CHANGE_SIM_PIN2:
6183                 case RIL_REQUEST_SET_FACILITY_LOCK:
6184                     if (mIccStatusChangedRegistrants != null) {
6185                         if (RILJ_LOGD) {
6186                             riljLog("ON some errors fakeSimStatusChanged: reg count="
6187                                     + mIccStatusChangedRegistrants.size());
6188                         }
6189                         mIccStatusChangedRegistrants.notifyRegistrants();
6190                     }
6191                     break;
6192 
6193             }
6194         } else {
6195             switch (rr.mRequest) {
6196                 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND:
6197                 if (mTestingEmergencyCall.getAndSet(false)) {
6198                     if (mEmergencyCallbackModeRegistrant != null) {
6199                         riljLog("testing emergency call, notify ECM Registrants");
6200                         mEmergencyCallbackModeRegistrant.notifyRegistrant();
6201                     }
6202                 }
6203             }
6204         }
6205         return rr;
6206     }
6207 
6208     /**
6209      * This is a helper function to be called at the end of all RadioResponse callbacks.
6210      * It takes care of sending error response, logging, decrementing wakelock if needed, and
6211      * releases the request from memory pool.
6212      * @param rr RILRequest for which response callback was called
6213      * @param responseInfo RadioResponseInfo received in the callback
6214      * @param ret object to be returned to request sender
6215      */
6216     @VisibleForTesting
processResponseDone(RILRequest rr, RadioResponseInfo responseInfo, Object ret)6217     public void processResponseDone(RILRequest rr, RadioResponseInfo responseInfo, Object ret) {
6218         processResponseDoneInternal(rr, responseInfo.error, responseInfo.type, ret);
6219     }
6220 
6221     /**
6222      * This is a helper function to be called at the end of the RadioResponse callbacks using for
6223      * V1_6.RadioResponseInfo.
6224      * It takes care of sending error response, logging, decrementing wakelock if needed, and
6225      * releases the request from memory pool.
6226      * @param rr RILRequest for which response callback was called
6227      * @param responseInfo RadioResponseInfo received in the callback
6228      * @param ret object to be returned to request sender
6229      */
6230     @VisibleForTesting
processResponseDone_1_6( RILRequest rr, android.hardware.radio.V1_6.RadioResponseInfo responseInfo, Object ret)6231     public void processResponseDone_1_6(
6232                     RILRequest rr, android.hardware.radio.V1_6.RadioResponseInfo responseInfo,
6233                     Object ret) {
6234         processResponseDoneInternal(rr, responseInfo.error, responseInfo.type, ret);
6235     }
6236 
processResponseDoneInternal( RILRequest rr, int rilError, int responseType, Object ret)6237     private void processResponseDoneInternal(
6238             RILRequest rr, int rilError, int responseType, Object ret) {
6239         if (rilError == 0) {
6240             if (RILJ_LOGD) {
6241                 riljLog(rr.serialString() + "< " + requestToString(rr.mRequest)
6242                         + " " + retToString(rr.mRequest, ret));
6243             }
6244         } else {
6245             if (RILJ_LOGD) {
6246                 riljLog(rr.serialString() + "< " + requestToString(rr.mRequest)
6247                         + " error " + rilError);
6248             }
6249             rr.onError(rilError, ret);
6250         }
6251         processResponseCleanUp(rr, rilError, responseType, ret);
6252     }
6253 
6254     /**
6255      * This is a helper function to be called at the end of all RadioResponse callbacks for
6256      * radio HAL fallback cases. It takes care of logging, decrementing wakelock if needed, and
6257      * releases the request from memory pool. Unlike processResponseDone, it will not send
6258      * error response to caller.
6259      * @param rr RILRequest for which response callback was called
6260      * @param responseInfo RadioResponseInfo received in the callback
6261      * @param ret object to be returned to request sender
6262      */
6263     @VisibleForTesting
processResponseFallback(RILRequest rr, RadioResponseInfo responseInfo, Object ret)6264     public void processResponseFallback(RILRequest rr, RadioResponseInfo responseInfo, Object ret) {
6265         if (responseInfo.error == REQUEST_NOT_SUPPORTED && RILJ_LOGD) {
6266             riljLog(rr.serialString() + "< " + requestToString(rr.mRequest)
6267                     + " request not supported, falling back");
6268         }
6269         processResponseCleanUp(rr, responseInfo.error, responseInfo.type, ret);
6270     }
6271 
processResponseCleanUp(RILRequest rr, int rilError, int responseType, Object ret)6272     private void processResponseCleanUp(RILRequest rr, int rilError, int responseType, Object ret) {
6273         if (rr != null) {
6274             mMetrics.writeOnRilSolicitedResponse(mPhoneId, rr.mSerial, rilError, rr.mRequest, ret);
6275             if (responseType == RadioResponseType.SOLICITED) {
6276                 decrementWakeLock(rr);
6277             }
6278             rr.release();
6279         }
6280     }
6281 
6282     /**
6283      * Function to send ack and acquire related wakelock
6284      */
sendAck()6285     private void sendAck() {
6286         // TODO: Remove rr and clean up acquireWakelock for response and ack
6287         RILRequest rr = RILRequest.obtain(RIL_RESPONSE_ACKNOWLEDGEMENT, null,
6288                 mRILDefaultWorkSource);
6289         acquireWakeLock(rr, RIL.FOR_ACK_WAKELOCK);
6290         IRadio radioProxy = getRadioProxy(null);
6291         if (radioProxy != null) {
6292             try {
6293                 radioProxy.responseAcknowledgement();
6294             } catch (RemoteException | RuntimeException e) {
6295                 handleRadioProxyExceptionForRR(rr, "sendAck", e);
6296                 riljLoge("sendAck: " + e);
6297             }
6298         } else {
6299             Rlog.e(RILJ_LOG_TAG, "Error trying to send ack, radioProxy = null");
6300         }
6301         rr.release();
6302     }
6303 
getDefaultWorkSourceIfInvalid(WorkSource workSource)6304     private WorkSource getDefaultWorkSourceIfInvalid(WorkSource workSource) {
6305         if (workSource == null) {
6306             workSource = mRILDefaultWorkSource;
6307         }
6308 
6309         return workSource;
6310     }
6311 
6312 
6313     /**
6314      * Holds a PARTIAL_WAKE_LOCK whenever
6315      * a) There is outstanding RIL request sent to RIL deamon and no replied
6316      * b) There is a request pending to be sent out.
6317      *
6318      * There is a WAKE_LOCK_TIMEOUT to release the lock, though it shouldn't
6319      * happen often.
6320      */
6321     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
acquireWakeLock(RILRequest rr, int wakeLockType)6322     private void acquireWakeLock(RILRequest rr, int wakeLockType) {
6323         synchronized (rr) {
6324             if (rr.mWakeLockType != INVALID_WAKELOCK) {
6325                 Rlog.d(RILJ_LOG_TAG, "Failed to aquire wakelock for " + rr.serialString());
6326                 return;
6327             }
6328 
6329             switch(wakeLockType) {
6330                 case FOR_WAKELOCK:
6331                     synchronized (mWakeLock) {
6332                         mWakeLock.acquire();
6333                         mWakeLockCount++;
6334                         mWlSequenceNum++;
6335 
6336                         String clientId = rr.getWorkSourceClientId();
6337                         if (!mClientWakelockTracker.isClientActive(clientId)) {
6338                             mActiveWakelockWorkSource.add(rr.mWorkSource);
6339                             mWakeLock.setWorkSource(mActiveWakelockWorkSource);
6340                         }
6341 
6342                         mClientWakelockTracker.startTracking(rr.mClientId,
6343                                 rr.mRequest, rr.mSerial, mWakeLockCount);
6344 
6345                         Message msg = mRilHandler.obtainMessage(EVENT_WAKE_LOCK_TIMEOUT);
6346                         msg.arg1 = mWlSequenceNum;
6347                         mRilHandler.sendMessageDelayed(msg, mWakeLockTimeout);
6348                     }
6349                     break;
6350                 case FOR_ACK_WAKELOCK:
6351                     synchronized (mAckWakeLock) {
6352                         mAckWakeLock.acquire();
6353                         mAckWlSequenceNum++;
6354 
6355                         Message msg = mRilHandler.obtainMessage(EVENT_ACK_WAKE_LOCK_TIMEOUT);
6356                         msg.arg1 = mAckWlSequenceNum;
6357                         mRilHandler.sendMessageDelayed(msg, mAckWakeLockTimeout);
6358                     }
6359                     break;
6360                 default: //WTF
6361                     Rlog.w(RILJ_LOG_TAG, "Acquiring Invalid Wakelock type " + wakeLockType);
6362                     return;
6363             }
6364             rr.mWakeLockType = wakeLockType;
6365         }
6366     }
6367 
6368     /** Returns the wake lock of the given type. */
6369     @VisibleForTesting
getWakeLock(int wakeLockType)6370     public WakeLock getWakeLock(int wakeLockType) {
6371         return wakeLockType == FOR_WAKELOCK ? mWakeLock : mAckWakeLock;
6372     }
6373 
6374     /** Returns the {@link RilHandler} instance. */
6375     @VisibleForTesting
getRilHandler()6376     public RilHandler getRilHandler() {
6377         return mRilHandler;
6378     }
6379 
6380     /** Returns the Ril request list. */
6381     @VisibleForTesting
getRilRequestList()6382     public SparseArray<RILRequest> getRilRequestList() {
6383         return mRequestList;
6384     }
6385 
6386     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
decrementWakeLock(RILRequest rr)6387     private void decrementWakeLock(RILRequest rr) {
6388         synchronized (rr) {
6389             switch(rr.mWakeLockType) {
6390                 case FOR_WAKELOCK:
6391                     synchronized (mWakeLock) {
6392                         mClientWakelockTracker.stopTracking(rr.mClientId,
6393                                 rr.mRequest, rr.mSerial,
6394                                 (mWakeLockCount > 1) ? mWakeLockCount - 1 : 0);
6395                         String clientId = rr.getWorkSourceClientId();
6396                         if (!mClientWakelockTracker.isClientActive(clientId)) {
6397                             mActiveWakelockWorkSource.remove(rr.mWorkSource);
6398                             mWakeLock.setWorkSource(mActiveWakelockWorkSource);
6399                         }
6400 
6401                         if (mWakeLockCount > 1) {
6402                             mWakeLockCount--;
6403                         } else {
6404                             mWakeLockCount = 0;
6405                             mWakeLock.release();
6406                         }
6407                     }
6408                     break;
6409                 case FOR_ACK_WAKELOCK:
6410                     //We do not decrement the ACK wakelock
6411                     break;
6412                 case INVALID_WAKELOCK:
6413                     break;
6414                 default:
6415                     Rlog.w(RILJ_LOG_TAG, "Decrementing Invalid Wakelock type " + rr.mWakeLockType);
6416             }
6417             rr.mWakeLockType = INVALID_WAKELOCK;
6418         }
6419     }
6420 
6421     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
clearWakeLock(int wakeLockType)6422     private boolean clearWakeLock(int wakeLockType) {
6423         if (wakeLockType == FOR_WAKELOCK) {
6424             synchronized (mWakeLock) {
6425                 if (mWakeLockCount == 0 && !mWakeLock.isHeld()) return false;
6426                 Rlog.d(RILJ_LOG_TAG, "NOTE: mWakeLockCount is " + mWakeLockCount
6427                         + "at time of clearing");
6428                 mWakeLockCount = 0;
6429                 mWakeLock.release();
6430                 mClientWakelockTracker.stopTrackingAll();
6431                 mActiveWakelockWorkSource = new WorkSource();
6432                 return true;
6433             }
6434         } else {
6435             synchronized (mAckWakeLock) {
6436                 if (!mAckWakeLock.isHeld()) return false;
6437                 mAckWakeLock.release();
6438                 return true;
6439             }
6440         }
6441     }
6442 
6443     /**
6444      * Release each request in mRequestList then clear the list
6445      * @param error is the RIL_Errno sent back
6446      * @param loggable true means to print all requests in mRequestList
6447      */
6448     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
clearRequestList(int error, boolean loggable)6449     private void clearRequestList(int error, boolean loggable) {
6450         RILRequest rr;
6451         synchronized (mRequestList) {
6452             int count = mRequestList.size();
6453             if (RILJ_LOGD && loggable) {
6454                 Rlog.d(RILJ_LOG_TAG, "clearRequestList " + " mWakeLockCount="
6455                         + mWakeLockCount + " mRequestList=" + count);
6456             }
6457 
6458             for (int i = 0; i < count; i++) {
6459                 rr = mRequestList.valueAt(i);
6460                 if (RILJ_LOGD && loggable) {
6461                     Rlog.d(RILJ_LOG_TAG, i + ": [" + rr.mSerial + "] "
6462                             + requestToString(rr.mRequest));
6463                 }
6464                 rr.onError(error, null);
6465                 decrementWakeLock(rr);
6466                 rr.release();
6467             }
6468             mRequestList.clear();
6469         }
6470     }
6471 
6472     @UnsupportedAppUsage
findAndRemoveRequestFromList(int serial)6473     private RILRequest findAndRemoveRequestFromList(int serial) {
6474         RILRequest rr = null;
6475         synchronized (mRequestList) {
6476             rr = mRequestList.get(serial);
6477             if (rr != null) {
6478                 mRequestList.remove(serial);
6479             }
6480         }
6481 
6482         return rr;
6483     }
6484 
addToRilHistogram(RILRequest rr)6485     private void addToRilHistogram(RILRequest rr) {
6486         long endTime = SystemClock.elapsedRealtime();
6487         int totalTime = (int) (endTime - rr.mStartTimeMs);
6488 
6489         synchronized (mRilTimeHistograms) {
6490             TelephonyHistogram entry = mRilTimeHistograms.get(rr.mRequest);
6491             if (entry == null) {
6492                 // We would have total #RIL_HISTOGRAM_BUCKET_COUNT range buckets for RIL commands
6493                 entry = new TelephonyHistogram(TelephonyHistogram.TELEPHONY_CATEGORY_RIL,
6494                         rr.mRequest, RIL_HISTOGRAM_BUCKET_COUNT);
6495                 mRilTimeHistograms.put(rr.mRequest, entry);
6496             }
6497             entry.addTimeTaken(totalTime);
6498         }
6499     }
6500 
6501     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
makeStaticRadioCapability()6502     RadioCapability makeStaticRadioCapability() {
6503         // default to UNKNOWN so we fail fast.
6504         int raf = RadioAccessFamily.RAF_UNKNOWN;
6505 
6506         String rafString = mContext.getResources().getString(
6507                 com.android.internal.R.string.config_radio_access_family);
6508         if (!TextUtils.isEmpty(rafString)) {
6509             raf = RadioAccessFamily.rafTypeFromString(rafString);
6510         }
6511         RadioCapability rc = new RadioCapability(mPhoneId.intValue(), 0, 0, raf,
6512                 "", RadioCapability.RC_STATUS_SUCCESS);
6513         if (RILJ_LOGD) riljLog("Faking RIL_REQUEST_GET_RADIO_CAPABILITY response using " + raf);
6514         return rc;
6515     }
6516 
6517     @UnsupportedAppUsage
retToString(int req, Object ret)6518     static String retToString(int req, Object ret) {
6519         if (ret == null) return "";
6520         switch (req) {
6521             // Don't log these return values, for privacy's sake.
6522             case RIL_REQUEST_GET_IMSI:
6523             case RIL_REQUEST_GET_IMEI:
6524             case RIL_REQUEST_GET_IMEISV:
6525             case RIL_REQUEST_SIM_OPEN_CHANNEL:
6526             case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL:
6527 
6528                 if (!RILJ_LOGV) {
6529                     // If not versbose logging just return and don't display IMSI and IMEI, IMEISV
6530                     return "";
6531                 }
6532         }
6533 
6534         StringBuilder sb;
6535         String s;
6536         int length;
6537         if (ret instanceof int[]) {
6538             int[] intArray = (int[]) ret;
6539             length = intArray.length;
6540             sb = new StringBuilder("{");
6541             if (length > 0) {
6542                 int i = 0;
6543                 sb.append(intArray[i++]);
6544                 while (i < length) {
6545                     sb.append(", ").append(intArray[i++]);
6546                 }
6547             }
6548             sb.append("}");
6549             s = sb.toString();
6550         } else if (ret instanceof String[]) {
6551             String[] strings = (String[]) ret;
6552             length = strings.length;
6553             sb = new StringBuilder("{");
6554             if (length > 0) {
6555                 int i = 0;
6556                 // position 0 is IMEI in RIL_REQUEST_DEVICE_IDENTITY
6557                 if (req == RIL_REQUEST_DEVICE_IDENTITY) {
6558                     sb.append(Rlog.pii(RILJ_LOG_TAG, strings[i++]));
6559                 } else {
6560                     sb.append(strings[i++]);
6561                 }
6562                 while (i < length) {
6563                     sb.append(", ").append(strings[i++]);
6564                 }
6565             }
6566             sb.append("}");
6567             s = sb.toString();
6568         } else if (req == RIL_REQUEST_GET_CURRENT_CALLS) {
6569             ArrayList<DriverCall> calls = (ArrayList<DriverCall>) ret;
6570             sb = new StringBuilder("{");
6571             for (DriverCall dc : calls) {
6572                 sb.append("[").append(dc).append("] ");
6573             }
6574             sb.append("}");
6575             s = sb.toString();
6576         } else if (req == RIL_REQUEST_GET_NEIGHBORING_CELL_IDS) {
6577             ArrayList<NeighboringCellInfo> cells = (ArrayList<NeighboringCellInfo>) ret;
6578             sb = new StringBuilder("{");
6579             for (NeighboringCellInfo cell : cells) {
6580                 sb.append("[").append(cell).append("] ");
6581             }
6582             sb.append("}");
6583             s = sb.toString();
6584         } else if (req == RIL_REQUEST_QUERY_CALL_FORWARD_STATUS) {
6585             CallForwardInfo[] cinfo = (CallForwardInfo[]) ret;
6586             length = cinfo.length;
6587             sb = new StringBuilder("{");
6588             for (int i = 0; i < length; i++) {
6589                 sb.append("[").append(cinfo[i]).append("] ");
6590             }
6591             sb.append("}");
6592             s = sb.toString();
6593         } else if (req == RIL_REQUEST_GET_HARDWARE_CONFIG) {
6594             ArrayList<HardwareConfig> hwcfgs = (ArrayList<HardwareConfig>) ret;
6595             sb = new StringBuilder(" ");
6596             for (HardwareConfig hwcfg : hwcfgs) {
6597                 sb.append("[").append(hwcfg).append("] ");
6598             }
6599             s = sb.toString();
6600         } else {
6601             s = ret.toString();
6602         }
6603         return s;
6604     }
6605 
writeMetricsCallRing(char[] response)6606     void writeMetricsCallRing(char[] response) {
6607         mMetrics.writeRilCallRing(mPhoneId, response);
6608     }
6609 
writeMetricsSrvcc(int state)6610     void writeMetricsSrvcc(int state) {
6611         mMetrics.writeRilSrvcc(mPhoneId, state);
6612         PhoneFactory.getPhone(mPhoneId).getVoiceCallSessionStats().onRilSrvccStateChanged(state);
6613     }
6614 
writeMetricsModemRestartEvent(String reason)6615     void writeMetricsModemRestartEvent(String reason) {
6616         mMetrics.writeModemRestartEvent(mPhoneId, reason);
6617         // Write metrics to statsd. Generate metric only when modem reset is detected by the
6618         // first instance of RIL to avoid duplicated events.
6619         if (mPhoneId == 0) {
6620             ModemRestartStats.onModemRestart(reason);
6621         }
6622     }
6623 
6624     /**
6625      * Notify all registrants that the ril has connected or disconnected.
6626      *
6627      * @param rilVer is the version of the ril or -1 if disconnected.
6628      */
6629     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
notifyRegistrantsRilConnectionChanged(int rilVer)6630     void notifyRegistrantsRilConnectionChanged(int rilVer) {
6631         mRilVersion = rilVer;
6632         if (mRilConnectedRegistrants != null) {
6633             mRilConnectedRegistrants.notifyRegistrants(
6634                     new AsyncResult(null, new Integer(rilVer), null));
6635         }
6636     }
6637 
6638     @UnsupportedAppUsage
6639     void
notifyRegistrantsCdmaInfoRec(CdmaInformationRecords infoRec)6640     notifyRegistrantsCdmaInfoRec(CdmaInformationRecords infoRec) {
6641         int response = RIL_UNSOL_CDMA_INFO_REC;
6642         if (infoRec.record instanceof CdmaInformationRecords.CdmaDisplayInfoRec) {
6643             if (mDisplayInfoRegistrants != null) {
6644                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
6645                 mDisplayInfoRegistrants.notifyRegistrants(
6646                         new AsyncResult(null, infoRec.record, null));
6647             }
6648         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaSignalInfoRec) {
6649             if (mSignalInfoRegistrants != null) {
6650                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
6651                 mSignalInfoRegistrants.notifyRegistrants(
6652                         new AsyncResult(null, infoRec.record, null));
6653             }
6654         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaNumberInfoRec) {
6655             if (mNumberInfoRegistrants != null) {
6656                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
6657                 mNumberInfoRegistrants.notifyRegistrants(
6658                         new AsyncResult(null, infoRec.record, null));
6659             }
6660         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaRedirectingNumberInfoRec) {
6661             if (mRedirNumInfoRegistrants != null) {
6662                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
6663                 mRedirNumInfoRegistrants.notifyRegistrants(
6664                         new AsyncResult(null, infoRec.record, null));
6665             }
6666         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaLineControlInfoRec) {
6667             if (mLineControlInfoRegistrants != null) {
6668                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
6669                 mLineControlInfoRegistrants.notifyRegistrants(
6670                         new AsyncResult(null, infoRec.record, null));
6671             }
6672         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaT53ClirInfoRec) {
6673             if (mT53ClirInfoRegistrants != null) {
6674                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
6675                 mT53ClirInfoRegistrants.notifyRegistrants(
6676                         new AsyncResult(null, infoRec.record, null));
6677             }
6678         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaT53AudioControlInfoRec) {
6679             if (mT53AudCntrlInfoRegistrants != null) {
6680                 if (RILJ_LOGD) {
6681                     unsljLogRet(response, infoRec.record);
6682                 }
6683                 mT53AudCntrlInfoRegistrants.notifyRegistrants(
6684                         new AsyncResult(null, infoRec.record, null));
6685             }
6686         }
6687     }
6688 
6689     @UnsupportedAppUsage
requestToString(int request)6690     static String requestToString(int request) {
6691         switch(request) {
6692             case RIL_REQUEST_GET_SIM_STATUS:
6693                 return "GET_SIM_STATUS";
6694             case RIL_REQUEST_ENTER_SIM_PIN:
6695                 return "ENTER_SIM_PIN";
6696             case RIL_REQUEST_ENTER_SIM_PUK:
6697                 return "ENTER_SIM_PUK";
6698             case RIL_REQUEST_ENTER_SIM_PIN2:
6699                 return "ENTER_SIM_PIN2";
6700             case RIL_REQUEST_ENTER_SIM_PUK2:
6701                 return "ENTER_SIM_PUK2";
6702             case RIL_REQUEST_CHANGE_SIM_PIN:
6703                 return "CHANGE_SIM_PIN";
6704             case RIL_REQUEST_CHANGE_SIM_PIN2:
6705                 return "CHANGE_SIM_PIN2";
6706             case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION:
6707                 return "ENTER_NETWORK_DEPERSONALIZATION";
6708             case RIL_REQUEST_GET_CURRENT_CALLS:
6709                 return "GET_CURRENT_CALLS";
6710             case RIL_REQUEST_DIAL:
6711                 return "DIAL";
6712             case RIL_REQUEST_GET_IMSI:
6713                 return "GET_IMSI";
6714             case RIL_REQUEST_HANGUP:
6715                 return "HANGUP";
6716             case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND:
6717                 return "HANGUP_WAITING_OR_BACKGROUND";
6718             case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND:
6719                 return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
6720             case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE:
6721                 return "REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
6722             case RIL_REQUEST_CONFERENCE:
6723                 return "CONFERENCE";
6724             case RIL_REQUEST_UDUB:
6725                 return "UDUB";
6726             case RIL_REQUEST_LAST_CALL_FAIL_CAUSE:
6727                 return "LAST_CALL_FAIL_CAUSE";
6728             case RIL_REQUEST_SIGNAL_STRENGTH:
6729                 return "SIGNAL_STRENGTH";
6730             case RIL_REQUEST_VOICE_REGISTRATION_STATE:
6731                 return "VOICE_REGISTRATION_STATE";
6732             case RIL_REQUEST_DATA_REGISTRATION_STATE:
6733                 return "DATA_REGISTRATION_STATE";
6734             case RIL_REQUEST_OPERATOR:
6735                 return "OPERATOR";
6736             case RIL_REQUEST_RADIO_POWER:
6737                 return "RADIO_POWER";
6738             case RIL_REQUEST_DTMF:
6739                 return "DTMF";
6740             case RIL_REQUEST_SEND_SMS:
6741                 return "SEND_SMS";
6742             case RIL_REQUEST_SEND_SMS_EXPECT_MORE:
6743                 return "SEND_SMS_EXPECT_MORE";
6744             case RIL_REQUEST_SETUP_DATA_CALL:
6745                 return "SETUP_DATA_CALL";
6746             case RIL_REQUEST_SIM_IO:
6747                 return "SIM_IO";
6748             case RIL_REQUEST_SEND_USSD:
6749                 return "SEND_USSD";
6750             case RIL_REQUEST_CANCEL_USSD:
6751                 return "CANCEL_USSD";
6752             case RIL_REQUEST_GET_CLIR:
6753                 return "GET_CLIR";
6754             case RIL_REQUEST_SET_CLIR:
6755                 return "SET_CLIR";
6756             case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS:
6757                 return "QUERY_CALL_FORWARD_STATUS";
6758             case RIL_REQUEST_SET_CALL_FORWARD:
6759                 return "SET_CALL_FORWARD";
6760             case RIL_REQUEST_QUERY_CALL_WAITING:
6761                 return "QUERY_CALL_WAITING";
6762             case RIL_REQUEST_SET_CALL_WAITING:
6763                 return "SET_CALL_WAITING";
6764             case RIL_REQUEST_SMS_ACKNOWLEDGE:
6765                 return "SMS_ACKNOWLEDGE";
6766             case RIL_REQUEST_GET_IMEI:
6767                 return "GET_IMEI";
6768             case RIL_REQUEST_GET_IMEISV:
6769                 return "GET_IMEISV";
6770             case RIL_REQUEST_ANSWER:
6771                 return "ANSWER";
6772             case RIL_REQUEST_DEACTIVATE_DATA_CALL:
6773                 return "DEACTIVATE_DATA_CALL";
6774             case RIL_REQUEST_QUERY_FACILITY_LOCK:
6775                 return "QUERY_FACILITY_LOCK";
6776             case RIL_REQUEST_SET_FACILITY_LOCK:
6777                 return "SET_FACILITY_LOCK";
6778             case RIL_REQUEST_CHANGE_BARRING_PASSWORD:
6779                 return "CHANGE_BARRING_PASSWORD";
6780             case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE:
6781                 return "QUERY_NETWORK_SELECTION_MODE";
6782             case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC:
6783                 return "SET_NETWORK_SELECTION_AUTOMATIC";
6784             case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL:
6785                 return "SET_NETWORK_SELECTION_MANUAL";
6786             case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS :
6787                 return "QUERY_AVAILABLE_NETWORKS ";
6788             case RIL_REQUEST_DTMF_START:
6789                 return "DTMF_START";
6790             case RIL_REQUEST_DTMF_STOP:
6791                 return "DTMF_STOP";
6792             case RIL_REQUEST_BASEBAND_VERSION:
6793                 return "BASEBAND_VERSION";
6794             case RIL_REQUEST_SEPARATE_CONNECTION:
6795                 return "SEPARATE_CONNECTION";
6796             case RIL_REQUEST_SET_MUTE:
6797                 return "SET_MUTE";
6798             case RIL_REQUEST_GET_MUTE:
6799                 return "GET_MUTE";
6800             case RIL_REQUEST_QUERY_CLIP:
6801                 return "QUERY_CLIP";
6802             case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE:
6803                 return "LAST_DATA_CALL_FAIL_CAUSE";
6804             case RIL_REQUEST_DATA_CALL_LIST:
6805                 return "DATA_CALL_LIST";
6806             case RIL_REQUEST_RESET_RADIO:
6807                 return "RESET_RADIO";
6808             case RIL_REQUEST_OEM_HOOK_RAW:
6809                 return "OEM_HOOK_RAW";
6810             case RIL_REQUEST_OEM_HOOK_STRINGS:
6811                 return "OEM_HOOK_STRINGS";
6812             case RIL_REQUEST_SCREEN_STATE:
6813                 return "SCREEN_STATE";
6814             case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION:
6815                 return "SET_SUPP_SVC_NOTIFICATION";
6816             case RIL_REQUEST_WRITE_SMS_TO_SIM:
6817                 return "WRITE_SMS_TO_SIM";
6818             case RIL_REQUEST_DELETE_SMS_ON_SIM:
6819                 return "DELETE_SMS_ON_SIM";
6820             case RIL_REQUEST_SET_BAND_MODE:
6821                 return "SET_BAND_MODE";
6822             case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE:
6823                 return "QUERY_AVAILABLE_BAND_MODE";
6824             case RIL_REQUEST_STK_GET_PROFILE:
6825                 return "STK_GET_PROFILE";
6826             case RIL_REQUEST_STK_SET_PROFILE:
6827                 return "STK_SET_PROFILE";
6828             case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND:
6829                 return "STK_SEND_ENVELOPE_COMMAND";
6830             case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE:
6831                 return "STK_SEND_TERMINAL_RESPONSE";
6832             case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM:
6833                 return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
6834             case RIL_REQUEST_EXPLICIT_CALL_TRANSFER:
6835                 return "EXPLICIT_CALL_TRANSFER";
6836             case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE:
6837                 return "SET_PREFERRED_NETWORK_TYPE";
6838             case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE:
6839                 return "GET_PREFERRED_NETWORK_TYPE";
6840             case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS:
6841                 return "GET_NEIGHBORING_CELL_IDS";
6842             case RIL_REQUEST_SET_LOCATION_UPDATES:
6843                 return "SET_LOCATION_UPDATES";
6844             case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:
6845                 return "CDMA_SET_SUBSCRIPTION_SOURCE";
6846             case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:
6847                 return "CDMA_SET_ROAMING_PREFERENCE";
6848             case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:
6849                 return "CDMA_QUERY_ROAMING_PREFERENCE";
6850             case RIL_REQUEST_SET_TTY_MODE:
6851                 return "SET_TTY_MODE";
6852             case RIL_REQUEST_QUERY_TTY_MODE:
6853                 return "QUERY_TTY_MODE";
6854             case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:
6855                 return "CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
6856             case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:
6857                 return "CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
6858             case RIL_REQUEST_CDMA_FLASH:
6859                 return "CDMA_FLASH";
6860             case RIL_REQUEST_CDMA_BURST_DTMF:
6861                 return "CDMA_BURST_DTMF";
6862             case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY:
6863                 return "CDMA_VALIDATE_AND_WRITE_AKEY";
6864             case RIL_REQUEST_CDMA_SEND_SMS:
6865                 return "CDMA_SEND_SMS";
6866             case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:
6867                 return "CDMA_SMS_ACKNOWLEDGE";
6868             case RIL_REQUEST_GSM_GET_BROADCAST_CONFIG:
6869                 return "GSM_GET_BROADCAST_CONFIG";
6870             case RIL_REQUEST_GSM_SET_BROADCAST_CONFIG:
6871                 return "GSM_SET_BROADCAST_CONFIG";
6872             case RIL_REQUEST_GSM_BROADCAST_ACTIVATION:
6873                 return "GSM_BROADCAST_ACTIVATION";
6874             case RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG:
6875                 return "CDMA_GET_BROADCAST_CONFIG";
6876             case RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG:
6877                 return "CDMA_SET_BROADCAST_CONFIG";
6878             case RIL_REQUEST_CDMA_BROADCAST_ACTIVATION:
6879                 return "CDMA_BROADCAST_ACTIVATION";
6880             case RIL_REQUEST_CDMA_SUBSCRIPTION:
6881                 return "CDMA_SUBSCRIPTION";
6882             case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM:
6883                 return "CDMA_WRITE_SMS_TO_RUIM";
6884             case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM:
6885                 return "CDMA_DELETE_SMS_ON_RUIM";
6886             case RIL_REQUEST_DEVICE_IDENTITY:
6887                 return "DEVICE_IDENTITY";
6888             case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE:
6889                 return "EXIT_EMERGENCY_CALLBACK_MODE";
6890             case RIL_REQUEST_GET_SMSC_ADDRESS:
6891                 return "GET_SMSC_ADDRESS";
6892             case RIL_REQUEST_SET_SMSC_ADDRESS:
6893                 return "SET_SMSC_ADDRESS";
6894             case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS:
6895                 return "REPORT_SMS_MEMORY_STATUS";
6896             case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING:
6897                 return "REPORT_STK_SERVICE_IS_RUNNING";
6898             case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:
6899                 return "CDMA_GET_SUBSCRIPTION_SOURCE";
6900             case RIL_REQUEST_ISIM_AUTHENTICATION:
6901                 return "ISIM_AUTHENTICATION";
6902             case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU:
6903                 return "ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
6904             case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS:
6905                 return "STK_SEND_ENVELOPE_WITH_STATUS";
6906             case RIL_REQUEST_VOICE_RADIO_TECH:
6907                 return "VOICE_RADIO_TECH";
6908             case RIL_REQUEST_GET_CELL_INFO_LIST:
6909                 return "GET_CELL_INFO_LIST";
6910             case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE:
6911                 return "SET_CELL_INFO_LIST_RATE";
6912             case RIL_REQUEST_SET_INITIAL_ATTACH_APN:
6913                 return "SET_INITIAL_ATTACH_APN";
6914             case RIL_REQUEST_IMS_REGISTRATION_STATE:
6915                 return "IMS_REGISTRATION_STATE";
6916             case RIL_REQUEST_IMS_SEND_SMS:
6917                 return "IMS_SEND_SMS";
6918             case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC:
6919                 return "SIM_TRANSMIT_APDU_BASIC";
6920             case RIL_REQUEST_SIM_OPEN_CHANNEL:
6921                 return "SIM_OPEN_CHANNEL";
6922             case RIL_REQUEST_SIM_CLOSE_CHANNEL:
6923                 return "SIM_CLOSE_CHANNEL";
6924             case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL:
6925                 return "SIM_TRANSMIT_APDU_CHANNEL";
6926             case RIL_REQUEST_NV_READ_ITEM:
6927                 return "NV_READ_ITEM";
6928             case RIL_REQUEST_NV_WRITE_ITEM:
6929                 return "NV_WRITE_ITEM";
6930             case RIL_REQUEST_NV_WRITE_CDMA_PRL:
6931                 return "NV_WRITE_CDMA_PRL";
6932             case RIL_REQUEST_NV_RESET_CONFIG:
6933                 return "NV_RESET_CONFIG";
6934             case RIL_REQUEST_SET_UICC_SUBSCRIPTION:
6935                 return "SET_UICC_SUBSCRIPTION";
6936             case RIL_REQUEST_ALLOW_DATA:
6937                 return "ALLOW_DATA";
6938             case RIL_REQUEST_GET_HARDWARE_CONFIG:
6939                 return "GET_HARDWARE_CONFIG";
6940             case RIL_REQUEST_SIM_AUTHENTICATION:
6941                 return "SIM_AUTHENTICATION";
6942             case RIL_REQUEST_GET_DC_RT_INFO:
6943                 return "GET_DC_RT_INFO";
6944             case RIL_REQUEST_SET_DC_RT_INFO_RATE:
6945                 return "SET_DC_RT_INFO_RATE";
6946             case RIL_REQUEST_SET_DATA_PROFILE:
6947                 return "SET_DATA_PROFILE";
6948             case RIL_REQUEST_SHUTDOWN:
6949                 return "SHUTDOWN";
6950             case RIL_REQUEST_GET_RADIO_CAPABILITY:
6951                 return "GET_RADIO_CAPABILITY";
6952             case RIL_REQUEST_SET_RADIO_CAPABILITY:
6953                 return "SET_RADIO_CAPABILITY";
6954             case RIL_REQUEST_START_LCE:
6955                 return "START_LCE";
6956             case RIL_REQUEST_STOP_LCE:
6957                 return "STOP_LCE";
6958             case RIL_REQUEST_PULL_LCEDATA:
6959                 return "PULL_LCEDATA";
6960             case RIL_REQUEST_GET_ACTIVITY_INFO:
6961                 return "GET_ACTIVITY_INFO";
6962             case RIL_REQUEST_SET_ALLOWED_CARRIERS:
6963                 return "SET_ALLOWED_CARRIERS";
6964             case RIL_REQUEST_GET_ALLOWED_CARRIERS:
6965                 return "GET_ALLOWED_CARRIERS";
6966             case RIL_REQUEST_SEND_DEVICE_STATE:
6967                 return "SEND_DEVICE_STATE";
6968             case RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER:
6969                 return "SET_UNSOLICITED_RESPONSE_FILTER";
6970             case RIL_REQUEST_SET_SIM_CARD_POWER:
6971                 return "SET_SIM_CARD_POWER";
6972             case RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION:
6973                 return "SET_CARRIER_INFO_IMSI_ENCRYPTION";
6974             case RIL_REQUEST_START_NETWORK_SCAN:
6975                 return "START_NETWORK_SCAN";
6976             case RIL_REQUEST_STOP_NETWORK_SCAN:
6977                 return "STOP_NETWORK_SCAN";
6978             case RIL_REQUEST_START_KEEPALIVE:
6979                 return "START_KEEPALIVE";
6980             case RIL_REQUEST_STOP_KEEPALIVE:
6981                 return "STOP_KEEPALIVE";
6982             case RIL_REQUEST_ENABLE_MODEM:
6983                 return "ENABLE_MODEM";
6984             case RIL_REQUEST_GET_MODEM_STATUS:
6985                 return "GET_MODEM_STATUS";
6986             case RIL_REQUEST_CDMA_SEND_SMS_EXPECT_MORE:
6987                 return "CDMA_SEND_SMS_EXPECT_MORE";
6988             case RIL_REQUEST_GET_SLOT_STATUS:
6989                 return "GET_SLOT_STATUS";
6990             case RIL_REQUEST_SET_LOGICAL_TO_PHYSICAL_SLOT_MAPPING:
6991                 return "SET_LOGICAL_TO_PHYSICAL_SLOT_MAPPING";
6992             case RIL_REQUEST_SET_SIGNAL_STRENGTH_REPORTING_CRITERIA:
6993                 return "SET_SIGNAL_STRENGTH_REPORTING_CRITERIA";
6994             case RIL_REQUEST_SET_LINK_CAPACITY_REPORTING_CRITERIA:
6995                 return "SET_LINK_CAPACITY_REPORTING_CRITERIA";
6996             case RIL_REQUEST_SET_PREFERRED_DATA_MODEM:
6997                 return "SET_PREFERRED_DATA_MODEM";
6998             case RIL_REQUEST_EMERGENCY_DIAL:
6999                 return "EMERGENCY_DIAL";
7000             case RIL_REQUEST_GET_PHONE_CAPABILITY:
7001                 return "GET_PHONE_CAPABILITY";
7002             case RIL_REQUEST_SWITCH_DUAL_SIM_CONFIG:
7003                 return "SWITCH_DUAL_SIM_CONFIG";
7004             case RIL_REQUEST_ENABLE_UICC_APPLICATIONS:
7005                 return "ENABLE_UICC_APPLICATIONS";
7006             case RIL_REQUEST_GET_UICC_APPLICATIONS_ENABLEMENT:
7007                 return "GET_UICC_APPLICATIONS_ENABLEMENT";
7008             case RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS:
7009                 return "SET_SYSTEM_SELECTION_CHANNELS";
7010             case RIL_REQUEST_GET_BARRING_INFO:
7011                 return "GET_BARRING_INFO";
7012             case RIL_REQUEST_ENTER_SIM_DEPERSONALIZATION:
7013                 return "ENTER_SIM_DEPERSONALIZATION";
7014             case RIL_REQUEST_ENABLE_NR_DUAL_CONNECTIVITY:
7015                 return "ENABLE_NR_DUAL_CONNECTIVITY";
7016             case RIL_REQUEST_IS_NR_DUAL_CONNECTIVITY_ENABLED:
7017                 return "IS_NR_DUAL_CONNECTIVITY_ENABLED";
7018             case RIL_REQUEST_ALLOCATE_PDU_SESSION_ID:
7019                 return "ALLOCATE_PDU_SESSION_ID";
7020             case RIL_REQUEST_RELEASE_PDU_SESSION_ID:
7021                 return "RELEASE_PDU_SESSION_ID";
7022             case RIL_REQUEST_START_HANDOVER:
7023                 return "START_HANDOVER";
7024             case RIL_REQUEST_CANCEL_HANDOVER:
7025                 return "CANCEL_HANDOVER";
7026             case RIL_REQUEST_GET_SYSTEM_SELECTION_CHANNELS:
7027                 return "GET_SYSTEM_SELECTION_CHANNELS";
7028             case RIL_REQUEST_GET_HAL_DEVICE_CAPABILITIES:
7029                 return "GET_HAL_DEVICE_CAPABILITIES";
7030             case RIL_REQUEST_SET_DATA_THROTTLING:
7031                 return "SET_DATA_THROTTLING";
7032             case RIL_REQUEST_SET_ALLOWED_NETWORK_TYPES_BITMAP:
7033                 return "SET_ALLOWED_NETWORK_TYPES_BITMAP";
7034             case RIL_REQUEST_GET_ALLOWED_NETWORK_TYPES_BITMAP:
7035                 return "GET_ALLOWED_NETWORK_TYPES_BITMAP";
7036             case RIL_REQUEST_GET_SLICING_CONFIG:
7037                 return "GET_SLICING_CONFIG";
7038             case RIL_REQUEST_GET_SIM_PHONEBOOK_RECORDS:
7039                 return "GET_SIM_PHONEBOOK_RECORDS";
7040             case RIL_REQUEST_UPDATE_SIM_PHONEBOOK_RECORD:
7041                 return "UPDATE_SIM_PHONEBOOK_RECORD";
7042             case RIL_REQUEST_GET_SIM_PHONEBOOK_CAPACITY:
7043                 return "GET_SIM_PHONEBOOK_CAPACITY";
7044             default: return "<unknown request>";
7045         }
7046     }
7047 
7048     @UnsupportedAppUsage
responseToString(int request)7049     static String responseToString(int request) {
7050         switch(request) {
7051             case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
7052                 return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
7053             case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
7054                 return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
7055             case RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED:
7056                 return "UNSOL_RESPONSE_NETWORK_STATE_CHANGED";
7057             case RIL_UNSOL_RESPONSE_NEW_SMS:
7058                 return "UNSOL_RESPONSE_NEW_SMS";
7059             case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT:
7060                 return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
7061             case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM:
7062                 return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
7063             case RIL_UNSOL_ON_USSD:
7064                 return "UNSOL_ON_USSD";
7065             case RIL_UNSOL_ON_USSD_REQUEST:
7066                 return "UNSOL_ON_USSD_REQUEST";
7067             case RIL_UNSOL_NITZ_TIME_RECEIVED:
7068                 return "UNSOL_NITZ_TIME_RECEIVED";
7069             case RIL_UNSOL_SIGNAL_STRENGTH:
7070                 return "UNSOL_SIGNAL_STRENGTH";
7071             case RIL_UNSOL_DATA_CALL_LIST_CHANGED:
7072                 return "UNSOL_DATA_CALL_LIST_CHANGED";
7073             case RIL_UNSOL_SUPP_SVC_NOTIFICATION:
7074                 return "UNSOL_SUPP_SVC_NOTIFICATION";
7075             case RIL_UNSOL_STK_SESSION_END:
7076                 return "UNSOL_STK_SESSION_END";
7077             case RIL_UNSOL_STK_PROACTIVE_COMMAND:
7078                 return "UNSOL_STK_PROACTIVE_COMMAND";
7079             case RIL_UNSOL_STK_EVENT_NOTIFY:
7080                 return "UNSOL_STK_EVENT_NOTIFY";
7081             case RIL_UNSOL_STK_CALL_SETUP:
7082                 return "UNSOL_STK_CALL_SETUP";
7083             case RIL_UNSOL_SIM_SMS_STORAGE_FULL:
7084                 return "UNSOL_SIM_SMS_STORAGE_FULL";
7085             case RIL_UNSOL_SIM_REFRESH:
7086                 return "UNSOL_SIM_REFRESH";
7087             case RIL_UNSOL_CALL_RING:
7088                 return "UNSOL_CALL_RING";
7089             case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED:
7090                 return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
7091             case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS:
7092                 return "UNSOL_RESPONSE_CDMA_NEW_SMS";
7093             case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS:
7094                 return "UNSOL_RESPONSE_NEW_BROADCAST_SMS";
7095             case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL:
7096                 return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
7097             case RIL_UNSOL_RESTRICTED_STATE_CHANGED:
7098                 return "UNSOL_RESTRICTED_STATE_CHANGED";
7099             case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE:
7100                 return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
7101             case RIL_UNSOL_CDMA_CALL_WAITING:
7102                 return "UNSOL_CDMA_CALL_WAITING";
7103             case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS:
7104                 return "UNSOL_CDMA_OTA_PROVISION_STATUS";
7105             case RIL_UNSOL_CDMA_INFO_REC:
7106                 return "UNSOL_CDMA_INFO_REC";
7107             case RIL_UNSOL_OEM_HOOK_RAW:
7108                 return "UNSOL_OEM_HOOK_RAW";
7109             case RIL_UNSOL_RINGBACK_TONE:
7110                 return "UNSOL_RINGBACK_TONE";
7111             case RIL_UNSOL_RESEND_INCALL_MUTE:
7112                 return "UNSOL_RESEND_INCALL_MUTE";
7113             case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED:
7114                 return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
7115             case RIL_UNSOl_CDMA_PRL_CHANGED:
7116                 return "UNSOL_CDMA_PRL_CHANGED";
7117             case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE:
7118                 return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
7119             case RIL_UNSOL_RIL_CONNECTED:
7120                 return "UNSOL_RIL_CONNECTED";
7121             case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED:
7122                 return "UNSOL_VOICE_RADIO_TECH_CHANGED";
7123             case RIL_UNSOL_CELL_INFO_LIST:
7124                 return "UNSOL_CELL_INFO_LIST";
7125             case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED:
7126                 return "UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED";
7127             case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED:
7128                 return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
7129             case RIL_UNSOL_SRVCC_STATE_NOTIFY:
7130                 return "UNSOL_SRVCC_STATE_NOTIFY";
7131             case RIL_UNSOL_HARDWARE_CONFIG_CHANGED:
7132                 return "UNSOL_HARDWARE_CONFIG_CHANGED";
7133             case RIL_UNSOL_DC_RT_INFO_CHANGED:
7134                 return "UNSOL_DC_RT_INFO_CHANGED";
7135             case RIL_UNSOL_RADIO_CAPABILITY:
7136                 return "UNSOL_RADIO_CAPABILITY";
7137             case RIL_UNSOL_ON_SS:
7138                 return "UNSOL_ON_SS";
7139             case RIL_UNSOL_STK_CC_ALPHA_NOTIFY:
7140                 return "UNSOL_STK_CC_ALPHA_NOTIFY";
7141             case RIL_UNSOL_LCEDATA_RECV:
7142                 return "UNSOL_LCE_INFO_RECV";
7143             case RIL_UNSOL_PCO_DATA:
7144                 return "UNSOL_PCO_DATA";
7145             case RIL_UNSOL_MODEM_RESTART:
7146                 return "UNSOL_MODEM_RESTART";
7147             case RIL_UNSOL_CARRIER_INFO_IMSI_ENCRYPTION:
7148                 return "UNSOL_CARRIER_INFO_IMSI_ENCRYPTION";
7149             case RIL_UNSOL_NETWORK_SCAN_RESULT:
7150                 return "UNSOL_NETWORK_SCAN_RESULT";
7151             case RIL_UNSOL_KEEPALIVE_STATUS:
7152                 return "UNSOL_KEEPALIVE_STATUS";
7153             case RIL_UNSOL_UNTHROTTLE_APN:
7154                 return "UNSOL_UNTHROTTLE_APN";
7155             case RIL_UNSOL_ICC_SLOT_STATUS:
7156                 return "UNSOL_ICC_SLOT_STATUS";
7157             case RIL_UNSOL_PHYSICAL_CHANNEL_CONFIG:
7158                 return "UNSOL_PHYSICAL_CHANNEL_CONFIG";
7159             case RIL_UNSOL_EMERGENCY_NUMBER_LIST:
7160                 return "UNSOL_EMERGENCY_NUMBER_LIST";
7161             case RIL_UNSOL_UICC_APPLICATIONS_ENABLEMENT_CHANGED:
7162                 return "UNSOL_UICC_APPLICATIONS_ENABLEMENT_CHANGED";
7163             case RIL_UNSOL_REGISTRATION_FAILED:
7164                 return "UNSOL_REGISTRATION_FAILED";
7165             case RIL_UNSOL_BARRING_INFO_CHANGED:
7166                 return "UNSOL_BARRING_INFO_CHANGED";
7167             case RIL_UNSOL_RESPONSE_SIM_PHONEBOOK_CHANGED:
7168                 return "UNSOL_RESPONSE_SIM_PHONEBOOK_CHANGED";
7169             case RIL_UNSOL_RESPONSE_SIM_PHONEBOOK_RECORDS_RECEIVED:
7170                 return "UNSOL_RESPONSE_SIM_PHONEBOOK_RECORDS_RECEIVED";
7171             default:
7172                 return "<unknown response>";
7173         }
7174     }
7175 
7176     @UnsupportedAppUsage
riljLog(String msg)7177     void riljLog(String msg) {
7178         Rlog.d(RILJ_LOG_TAG, msg + (" [PHONE" + mPhoneId + "]"));
7179     }
7180 
riljLoge(String msg)7181     void riljLoge(String msg) {
7182         Rlog.e(RILJ_LOG_TAG, msg + (" [PHONE" + mPhoneId + "]"));
7183     }
7184 
riljLoge(String msg, Exception e)7185     void riljLoge(String msg, Exception e) {
7186         Rlog.e(RILJ_LOG_TAG, msg + (" [PHONE" + mPhoneId + "]"), e);
7187     }
7188 
riljLogv(String msg)7189     void riljLogv(String msg) {
7190         Rlog.v(RILJ_LOG_TAG, msg + (" [PHONE" + mPhoneId + "]"));
7191     }
7192 
7193     @UnsupportedAppUsage
unsljLog(int response)7194     void unsljLog(int response) {
7195         riljLog("[UNSL]< " + responseToString(response));
7196     }
7197 
7198     @UnsupportedAppUsage
unsljLogMore(int response, String more)7199     void unsljLogMore(int response, String more) {
7200         riljLog("[UNSL]< " + responseToString(response) + " " + more);
7201     }
7202 
7203     @UnsupportedAppUsage
unsljLogRet(int response, Object ret)7204     void unsljLogRet(int response, Object ret) {
7205         riljLog("[UNSL]< " + responseToString(response) + " " + retToString(response, ret));
7206     }
7207 
7208     @UnsupportedAppUsage
unsljLogvRet(int response, Object ret)7209     void unsljLogvRet(int response, Object ret) {
7210         riljLogv("[UNSL]< " + responseToString(response) + " " + retToString(response, ret));
7211     }
7212 
7213     @Override
setPhoneType(int phoneType)7214     public void setPhoneType(int phoneType) { // Called by GsmCdmaPhone
7215         if (RILJ_LOGD) riljLog("setPhoneType=" + phoneType + " old value=" + mPhoneType);
7216         mPhoneType = phoneType;
7217     }
7218 
7219     /* (non-Javadoc)
7220      * @see com.android.internal.telephony.BaseCommands#testingEmergencyCall()
7221      */
7222     @Override
testingEmergencyCall()7223     public void testingEmergencyCall() {
7224         if (RILJ_LOGD) riljLog("testingEmergencyCall");
7225         mTestingEmergencyCall.set(true);
7226     }
7227 
dump(FileDescriptor fd, PrintWriter pw, String[] args)7228     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
7229         pw.println("RIL: " + this);
7230         pw.println(" mWakeLock=" + mWakeLock);
7231         pw.println(" mWakeLockTimeout=" + mWakeLockTimeout);
7232         synchronized (mRequestList) {
7233             synchronized (mWakeLock) {
7234                 pw.println(" mWakeLockCount=" + mWakeLockCount);
7235             }
7236             int count = mRequestList.size();
7237             pw.println(" mRequestList count=" + count);
7238             for (int i = 0; i < count; i++) {
7239                 RILRequest rr = mRequestList.valueAt(i);
7240                 pw.println("  [" + rr.mSerial + "] " + requestToString(rr.mRequest));
7241             }
7242         }
7243         pw.println(" mLastNITZTimeInfo=" + Arrays.toString(mLastNITZTimeInfo));
7244         pw.println(" mLastRadioPowerResult=" + mLastRadioPowerResult);
7245         pw.println(" mTestingEmergencyCall=" + mTestingEmergencyCall.get());
7246         mClientWakelockTracker.dumpClientRequestTracker(pw);
7247     }
7248 
getClientRequestStats()7249     public List<ClientRequestStats> getClientRequestStats() {
7250         return mClientWakelockTracker.getClientRequestStats();
7251     }
7252 
7253     /** Append the data to the end of an ArrayList */
appendPrimitiveArrayToArrayList(byte[] src, ArrayList<Byte> dst)7254     public static void appendPrimitiveArrayToArrayList(byte[] src, ArrayList<Byte> dst) {
7255         for (byte b : src) {
7256             dst.add(b);
7257         }
7258     }
7259 
primitiveArrayToArrayList(byte[] arr)7260     public static ArrayList<Byte> primitiveArrayToArrayList(byte[] arr) {
7261         ArrayList<Byte> arrayList = new ArrayList<>(arr.length);
7262         for (byte b : arr) {
7263             arrayList.add(b);
7264         }
7265         return arrayList;
7266     }
7267 
7268     /** Convert a primitive int array to an ArrayList<Integer>. */
primitiveArrayToArrayList(int[] arr)7269     public static ArrayList<Integer> primitiveArrayToArrayList(int[] arr) {
7270         ArrayList<Integer> arrayList = new ArrayList<>(arr.length);
7271         for (int i : arr) {
7272             arrayList.add(i);
7273         }
7274         return arrayList;
7275     }
7276 
7277     /** Convert an ArrayList of Bytes to an exactly-sized primitive array */
arrayListToPrimitiveArray(ArrayList<Byte> bytes)7278     public static byte[] arrayListToPrimitiveArray(ArrayList<Byte> bytes) {
7279         byte[] ret = new byte[bytes.size()];
7280         for (int i = 0; i < ret.length; i++) {
7281             ret[i] = bytes.get(i);
7282         }
7283         return ret;
7284     }
7285 
convertHalHwConfigList( ArrayList<android.hardware.radio.V1_0.HardwareConfig> hwListRil, RIL ril)7286     static ArrayList<HardwareConfig> convertHalHwConfigList(
7287             ArrayList<android.hardware.radio.V1_0.HardwareConfig> hwListRil,
7288             RIL ril) {
7289         int num;
7290         ArrayList<HardwareConfig> response;
7291         HardwareConfig hw;
7292 
7293         num = hwListRil.size();
7294         response = new ArrayList<HardwareConfig>(num);
7295 
7296         if (RILJ_LOGV) {
7297             ril.riljLog("convertHalHwConfigList: num=" + num);
7298         }
7299         for (android.hardware.radio.V1_0.HardwareConfig hwRil : hwListRil) {
7300             int type = hwRil.type;
7301             switch(type) {
7302                 case HardwareConfig.DEV_HARDWARE_TYPE_MODEM: {
7303                     hw = new HardwareConfig(type);
7304                     HardwareConfigModem hwModem = hwRil.modem.get(0);
7305                     hw.assignModem(hwRil.uuid, hwRil.state, hwModem.rilModel, hwModem.rat,
7306                             hwModem.maxVoice, hwModem.maxData, hwModem.maxStandby);
7307                     break;
7308                 }
7309                 case HardwareConfig.DEV_HARDWARE_TYPE_SIM: {
7310                     hw = new HardwareConfig(type);
7311                     hw.assignSim(hwRil.uuid, hwRil.state, hwRil.sim.get(0).modemUuid);
7312                     break;
7313                 }
7314                 default: {
7315                     throw new RuntimeException(
7316                             "RIL_REQUEST_GET_HARDWARE_CONFIG invalid hardward type:" + type);
7317                 }
7318             }
7319 
7320             response.add(hw);
7321         }
7322 
7323         return response;
7324     }
7325 
convertHalRadioCapability( android.hardware.radio.V1_0.RadioCapability rcRil, RIL ril)7326     static RadioCapability convertHalRadioCapability(
7327             android.hardware.radio.V1_0.RadioCapability rcRil, RIL ril) {
7328         int session = rcRil.session;
7329         int phase = rcRil.phase;
7330         // convert to public bitmask {@link TelephonyManager.NetworkTypeBitMask}
7331         int rat = convertToNetworkTypeBitMask(rcRil.raf);
7332         String logicModemUuid = rcRil.logicalModemUuid;
7333         int status = rcRil.status;
7334 
7335         ril.riljLog("convertHalRadioCapability: session=" + session +
7336                 ", phase=" + phase +
7337                 ", rat=" + rat +
7338                 ", logicModemUuid=" + logicModemUuid +
7339                 ", status=" + status + ", rcRil.raf=" + rcRil.raf);
7340         RadioCapability rc = new RadioCapability(
7341                 ril.mPhoneId, session, phase, rat, logicModemUuid, status);
7342         return rc;
7343     }
7344 
convertHalLceData(LceDataInfo halData, RIL ril)7345     static List<LinkCapacityEstimate> convertHalLceData(LceDataInfo halData, RIL ril) {
7346         final List<LinkCapacityEstimate> lceList = new ArrayList<>();
7347         lceList.add(new LinkCapacityEstimate(LinkCapacityEstimate.LCE_TYPE_COMBINED,
7348                 halData.lastHopCapacityKbps,
7349                 LinkCapacityEstimate.INVALID));
7350         ril.riljLog("LCE capacity information received:" + lceList);
7351         return lceList;
7352     }
7353 
convertHalLceData( android.hardware.radio.V1_2.LinkCapacityEstimate halData, RIL ril)7354     static List<LinkCapacityEstimate> convertHalLceData(
7355             android.hardware.radio.V1_2.LinkCapacityEstimate halData, RIL ril) {
7356         final List<LinkCapacityEstimate> lceList = new ArrayList<>();
7357         lceList.add(new LinkCapacityEstimate(LinkCapacityEstimate.LCE_TYPE_COMBINED,
7358                 halData.downlinkCapacityKbps,
7359                 halData.uplinkCapacityKbps));
7360         ril.riljLog("LCE capacity information received:" + lceList);
7361         return lceList;
7362     }
7363 
convertHalLceData( android.hardware.radio.V1_6.LinkCapacityEstimate halData, RIL ril)7364     static List<LinkCapacityEstimate> convertHalLceData(
7365             android.hardware.radio.V1_6.LinkCapacityEstimate halData, RIL ril) {
7366         final List<LinkCapacityEstimate> lceList = new ArrayList<>();
7367         int primaryDownlinkCapacityKbps = halData.downlinkCapacityKbps;
7368         int primaryUplinkCapacityKbps = halData.uplinkCapacityKbps;
7369         if (primaryDownlinkCapacityKbps != LinkCapacityEstimate.INVALID
7370                 && halData.secondaryDownlinkCapacityKbps != LinkCapacityEstimate.INVALID) {
7371             primaryDownlinkCapacityKbps =
7372                     halData.downlinkCapacityKbps - halData.secondaryDownlinkCapacityKbps;
7373         }
7374         if (primaryUplinkCapacityKbps != LinkCapacityEstimate.INVALID
7375                 && halData.secondaryUplinkCapacityKbps != LinkCapacityEstimate.INVALID) {
7376             primaryUplinkCapacityKbps =
7377                     halData.uplinkCapacityKbps - halData.secondaryUplinkCapacityKbps;
7378         }
7379 
7380         lceList.add(new LinkCapacityEstimate(LinkCapacityEstimate.LCE_TYPE_PRIMARY,
7381                 primaryDownlinkCapacityKbps,
7382                 primaryUplinkCapacityKbps));
7383         lceList.add(new LinkCapacityEstimate(LinkCapacityEstimate.LCE_TYPE_SECONDARY,
7384                 halData.secondaryDownlinkCapacityKbps,
7385                 halData.secondaryUplinkCapacityKbps));
7386         ril.riljLog("LCE capacity information received:" + lceList);
7387         return lceList;
7388     }
7389 
7390     /**
7391      * Convert CellInfo defined in 1.0/types.hal to CellInfo type.
7392      * @param records List of CellInfo defined in 1.0/types.hal
7393      * @return List of converted CellInfo object
7394      */
7395     @VisibleForTesting
convertHalCellInfoList( ArrayList<android.hardware.radio.V1_0.CellInfo> records)7396     public static ArrayList<CellInfo> convertHalCellInfoList(
7397             ArrayList<android.hardware.radio.V1_0.CellInfo> records) {
7398         ArrayList<CellInfo> response = new ArrayList<CellInfo>(records.size());
7399 
7400         final long nanotime = SystemClock.elapsedRealtimeNanos();
7401         for (android.hardware.radio.V1_0.CellInfo record : records) {
7402             record.timeStamp = nanotime;
7403             response.add(CellInfo.create(record));
7404         }
7405 
7406         return response;
7407     }
7408 
7409     /**
7410      * Convert CellInfo defined in 1.2/types.hal to CellInfo type.
7411      * @param records List of CellInfo defined in 1.2/types.hal
7412      * @return List of converted CellInfo object
7413      */
7414     @VisibleForTesting
convertHalCellInfoList_1_2( ArrayList<android.hardware.radio.V1_2.CellInfo> records)7415     public static ArrayList<CellInfo> convertHalCellInfoList_1_2(
7416             ArrayList<android.hardware.radio.V1_2.CellInfo> records) {
7417         ArrayList<CellInfo> response = new ArrayList<CellInfo>(records.size());
7418 
7419         final long nanotime = SystemClock.elapsedRealtimeNanos();
7420         for (android.hardware.radio.V1_2.CellInfo record : records) {
7421             record.timeStamp = nanotime;
7422             response.add(CellInfo.create(record));
7423         }
7424         return response;
7425     }
7426 
7427     /**
7428      * Fixup for SignalStrength 1.0 to Assume GSM to WCDMA when
7429      * The current RAT type is one of the UMTS RATs.
7430      * @param signalStrength the initial signal strength
7431      * @return a new SignalStrength if RAT is UMTS or existing SignalStrength
7432      */
fixupSignalStrength10(SignalStrength signalStrength)7433     public SignalStrength fixupSignalStrength10(SignalStrength signalStrength) {
7434         List<CellSignalStrengthGsm> gsmList = signalStrength.getCellSignalStrengths(
7435                 CellSignalStrengthGsm.class);
7436         // If GSM is not the primary type, then bail out; no fixup needed.
7437         if (gsmList.isEmpty() || !gsmList.get(0).isValid()) {
7438             return signalStrength;
7439         }
7440 
7441         CellSignalStrengthGsm gsmStrength = gsmList.get(0);
7442 
7443         // Use the voice RAT which is a guarantee in GSM and UMTS
7444         int voiceRat = ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN;
7445         Phone phone = PhoneFactory.getPhone(mPhoneId);
7446         if (phone != null) {
7447             ServiceState ss = phone.getServiceState();
7448             if (ss != null) {
7449                 voiceRat = ss.getRilVoiceRadioTechnology();
7450             }
7451         }
7452         switch (voiceRat) {
7453             case ServiceState.RIL_RADIO_TECHNOLOGY_UMTS: /* fallthrough */
7454             case ServiceState.RIL_RADIO_TECHNOLOGY_HSDPA: /* fallthrough */
7455             case ServiceState.RIL_RADIO_TECHNOLOGY_HSUPA: /* fallthrough */
7456             case ServiceState.RIL_RADIO_TECHNOLOGY_HSPA: /* fallthrough */
7457             case ServiceState.RIL_RADIO_TECHNOLOGY_HSPAP: /* fallthrough */
7458                 break;
7459             default:
7460                 // If we are not currently on WCDMA/HSPA, then we don't need to do a fixup.
7461                 return signalStrength;
7462         }
7463 
7464         // The service state reports WCDMA, and the SignalStrength is reported for GSM, so at this
7465         // point we take an educated guess that the GSM SignalStrength report is actually for
7466         // WCDMA. Also, if we are in WCDMA/GSM we can safely assume that there are no other valid
7467         // signal strength reports (no SRLTE, which is the only supported case in HAL 1.0).
7468         // Thus, we just construct a new SignalStrength and migrate RSSI and BER from the
7469         // GSM report to the WCDMA report, leaving everything else empty.
7470         return new SignalStrength(
7471                 new CellSignalStrengthCdma(), new CellSignalStrengthGsm(),
7472                 new CellSignalStrengthWcdma(gsmStrength.getRssi(),
7473                         gsmStrength.getBitErrorRate(),
7474                         CellInfo.UNAVAILABLE, CellInfo.UNAVAILABLE),
7475                 new CellSignalStrengthTdscdma(), new CellSignalStrengthLte(),
7476                 new CellSignalStrengthNr());
7477     }
7478 
7479     /**
7480      * Convert CellInfo defined in 1.4/types.hal to CellInfo type.
7481      * @param records List of CellInfo defined in 1.4/types.hal.
7482      * @return List of converted CellInfo object.
7483      */
7484     @VisibleForTesting
convertHalCellInfoList_1_4( ArrayList<android.hardware.radio.V1_4.CellInfo> records)7485     public static ArrayList<CellInfo> convertHalCellInfoList_1_4(
7486             ArrayList<android.hardware.radio.V1_4.CellInfo> records) {
7487         ArrayList<CellInfo> response = new ArrayList<CellInfo>(records.size());
7488 
7489         final long nanotime = SystemClock.elapsedRealtimeNanos();
7490         for (android.hardware.radio.V1_4.CellInfo record : records) {
7491             response.add(CellInfo.create(record, nanotime));
7492         }
7493         return response;
7494     }
7495 
7496     /**
7497      * Convert CellInfo defined in 1.5/types.hal to CellInfo type.
7498      * @param records List of CellInfo defined in 1.5/types.hal.
7499      * @return List of converted CellInfo object.
7500      */
7501     @VisibleForTesting
convertHalCellInfoList_1_5( ArrayList<android.hardware.radio.V1_5.CellInfo> records)7502     public static ArrayList<CellInfo> convertHalCellInfoList_1_5(
7503             ArrayList<android.hardware.radio.V1_5.CellInfo> records) {
7504         ArrayList<CellInfo> response = new ArrayList<>(records.size());
7505 
7506         final long nanotime = SystemClock.elapsedRealtimeNanos();
7507         for (android.hardware.radio.V1_5.CellInfo record : records) {
7508             response.add(CellInfo.create(record, nanotime));
7509         }
7510         return response;
7511     }
7512 
7513     /**
7514      * Convert CellInfo defined in 1.6/types.hal to CellInfo type.
7515      * @param records List of CellInfo defined in 1.6/types.hal.
7516      * @return List of converted CellInfo object.
7517      */
7518     @VisibleForTesting
convertHalCellInfoList_1_6( ArrayList<android.hardware.radio.V1_6.CellInfo> records)7519     public static ArrayList<CellInfo> convertHalCellInfoList_1_6(
7520             ArrayList<android.hardware.radio.V1_6.CellInfo> records) {
7521         ArrayList<CellInfo> response = new ArrayList<>(records.size());
7522 
7523         final long nanotime = SystemClock.elapsedRealtimeNanos();
7524         for (android.hardware.radio.V1_6.CellInfo record : records) {
7525             response.add(CellInfo.create(record, nanotime));
7526         }
7527         return response;
7528     }
7529 
createLinkAddressFromString(String addressString)7530     private static LinkAddress createLinkAddressFromString(String addressString) {
7531         return createLinkAddressFromString(addressString, 0, LinkAddress.LIFETIME_UNKNOWN,
7532                 LinkAddress.LIFETIME_UNKNOWN);
7533     }
7534 
createLinkAddressFromString(String addressString, int properties, long deprecationTime, long expirationTime)7535     private static LinkAddress createLinkAddressFromString(String addressString, int properties,
7536             long deprecationTime, long expirationTime) {
7537         addressString = addressString.trim();
7538         InetAddress address = null;
7539         int prefixLength = -1;
7540         try {
7541             String[] pieces = addressString.split("/", 2);
7542             address = InetAddresses.parseNumericAddress(pieces[0]);
7543             if (pieces.length == 1) {
7544                 prefixLength = (address instanceof Inet4Address) ? 32 : 128;
7545             } else if (pieces.length == 2) {
7546                 prefixLength = Integer.parseInt(pieces[1]);
7547             }
7548         } catch (NullPointerException e) {            // Null string.
7549         } catch (ArrayIndexOutOfBoundsException e) {  // No prefix length.
7550         } catch (NumberFormatException e) {           // Non-numeric prefix.
7551         } catch (IllegalArgumentException e) {        // Invalid IP address.
7552         }
7553 
7554         if (address == null || prefixLength == -1) {
7555             throw new IllegalArgumentException("Invalid link address " + addressString);
7556         }
7557 
7558         return new LinkAddress(address, prefixLength, properties, 0,
7559                 deprecationTime, expirationTime);
7560     }
7561 
7562     /**
7563      * Convert SetupDataCallResult defined in 1.0, 1.4, 1.5 or 1.6 types.hal into DataCallResponse
7564      * @param dcResult setup data call result
7565      * @return converted DataCallResponse object
7566      */
7567     @VisibleForTesting
convertDataCallResult(Object dcResult)7568     public static DataCallResponse convertDataCallResult(Object dcResult) {
7569         if (dcResult == null) return null;
7570 
7571         int cause, cid, active, mtu, mtuV4, mtuV6;
7572         long suggestedRetryTime;
7573         String ifname;
7574         int protocolType;
7575         String[] addresses = null;
7576         String[] dnses = null;
7577         String[] gateways = null;
7578         String[] pcscfs = null;
7579         Qos defaultQos = null;
7580 
7581         @HandoverFailureMode
7582         int handoverFailureMode = DataCallResponse.HANDOVER_FAILURE_MODE_LEGACY;
7583 
7584         int pduSessionId = DataCallResponse.PDU_SESSION_ID_NOT_SET;
7585 
7586         List<LinkAddress> laList = new ArrayList<>();
7587         List<QosBearerSession> qosSessions = new ArrayList<>();
7588         NetworkSliceInfo sliceInfo = null;
7589         List<TrafficDescriptor> trafficDescriptors = new ArrayList<>();
7590 
7591         if (dcResult instanceof android.hardware.radio.V1_0.SetupDataCallResult) {
7592             final android.hardware.radio.V1_0.SetupDataCallResult result =
7593                     (android.hardware.radio.V1_0.SetupDataCallResult) dcResult;
7594             cause = result.status;
7595             suggestedRetryTime = result.suggestedRetryTime;
7596             cid = result.cid;
7597             active = result.active;
7598             protocolType = ApnSetting.getProtocolIntFromString(result.type);
7599             ifname = result.ifname;
7600             if (!TextUtils.isEmpty(result.addresses)) {
7601                 addresses = result.addresses.split("\\s+");
7602             }
7603             if (!TextUtils.isEmpty(result.dnses)) {
7604                 dnses = result.dnses.split("\\s+");
7605             }
7606             if (!TextUtils.isEmpty(result.gateways)) {
7607                 gateways = result.gateways.split("\\s+");
7608             }
7609             if (!TextUtils.isEmpty(result.pcscf)) {
7610                 pcscfs = result.pcscf.split("\\s+");
7611             }
7612             mtu = mtuV4 = mtuV6 = result.mtu;
7613             if (addresses != null) {
7614                 for (String address : addresses) {
7615                     laList.add(createLinkAddressFromString(address));
7616                 }
7617             }
7618         } else if (dcResult instanceof android.hardware.radio.V1_4.SetupDataCallResult) {
7619             final android.hardware.radio.V1_4.SetupDataCallResult result =
7620                     (android.hardware.radio.V1_4.SetupDataCallResult) dcResult;
7621             cause = result.cause;
7622             suggestedRetryTime = result.suggestedRetryTime;
7623             cid = result.cid;
7624             active = result.active;
7625             protocolType = result.type;
7626             ifname = result.ifname;
7627             addresses = result.addresses.stream().toArray(String[]::new);
7628             dnses = result.dnses.stream().toArray(String[]::new);
7629             gateways = result.gateways.stream().toArray(String[]::new);
7630             pcscfs = result.pcscf.stream().toArray(String[]::new);
7631             mtu = mtuV4 = mtuV6 = result.mtu;
7632             if (addresses != null) {
7633                 for (String address : addresses) {
7634                     laList.add(createLinkAddressFromString(address));
7635                 }
7636             }
7637         } else if (dcResult instanceof android.hardware.radio.V1_5.SetupDataCallResult) {
7638             final android.hardware.radio.V1_5.SetupDataCallResult result =
7639                     (android.hardware.radio.V1_5.SetupDataCallResult) dcResult;
7640             cause = result.cause;
7641             suggestedRetryTime = result.suggestedRetryTime;
7642             cid = result.cid;
7643             active = result.active;
7644             protocolType = result.type;
7645             ifname = result.ifname;
7646             laList = result.addresses.stream().map(la -> createLinkAddressFromString(
7647                     la.address, la.properties, la.deprecationTime, la.expirationTime))
7648                     .collect(Collectors.toList());
7649 
7650             dnses = result.dnses.stream().toArray(String[]::new);
7651             gateways = result.gateways.stream().toArray(String[]::new);
7652             pcscfs = result.pcscf.stream().toArray(String[]::new);
7653             mtu = Math.max(result.mtuV4, result.mtuV6);
7654             mtuV4 = result.mtuV4;
7655             mtuV6 = result.mtuV6;
7656         } else if (dcResult instanceof android.hardware.radio.V1_6.SetupDataCallResult) {
7657             final android.hardware.radio.V1_6.SetupDataCallResult result =
7658                     (android.hardware.radio.V1_6.SetupDataCallResult) dcResult;
7659             cause = result.cause;
7660             suggestedRetryTime = result.suggestedRetryTime;
7661             cid = result.cid;
7662             active = result.active;
7663             protocolType = result.type;
7664             ifname = result.ifname;
7665             laList = result.addresses.stream().map(la -> createLinkAddressFromString(
7666                     la.address, la.properties, la.deprecationTime, la.expirationTime))
7667                     .collect(Collectors.toList());
7668             dnses = result.dnses.stream().toArray(String[]::new);
7669             gateways = result.gateways.stream().toArray(String[]::new);
7670             pcscfs = result.pcscf.stream().toArray(String[]::new);
7671             mtu = Math.max(result.mtuV4, result.mtuV6);
7672             mtuV4 = result.mtuV4;
7673             mtuV6 = result.mtuV6;
7674             handoverFailureMode = result.handoverFailureMode;
7675             pduSessionId = result.pduSessionId;
7676             defaultQos = Qos.create(result.defaultQos);
7677             qosSessions = result.qosSessions.stream().map(session ->
7678                     QosBearerSession.create(session)).collect(Collectors.toList());
7679             sliceInfo = convertToSliceInfo(result.sliceInfo);
7680             trafficDescriptors = result.trafficDescriptors.stream().map(td ->
7681                     convertToTrafficDescriptor(td)).collect(Collectors.toList());
7682         } else {
7683             Rlog.e(RILJ_LOG_TAG, "Unsupported SetupDataCallResult " + dcResult);
7684             return null;
7685         }
7686 
7687         // Process dns
7688         List<InetAddress> dnsList = new ArrayList<>();
7689         if (dnses != null) {
7690             for (String dns : dnses) {
7691                 dns = dns.trim();
7692                 InetAddress ia;
7693                 try {
7694                     ia = InetAddresses.parseNumericAddress(dns);
7695                     dnsList.add(ia);
7696                 } catch (IllegalArgumentException e) {
7697                     Rlog.e(RILJ_LOG_TAG, "Unknown dns: " + dns, e);
7698                 }
7699             }
7700         }
7701 
7702         // Process gateway
7703         List<InetAddress> gatewayList = new ArrayList<>();
7704         if (gateways != null) {
7705             for (String gateway : gateways) {
7706                 gateway = gateway.trim();
7707                 InetAddress ia;
7708                 try {
7709                     ia = InetAddresses.parseNumericAddress(gateway);
7710                     gatewayList.add(ia);
7711                 } catch (IllegalArgumentException e) {
7712                     Rlog.e(RILJ_LOG_TAG, "Unknown gateway: " + gateway, e);
7713                 }
7714             }
7715         }
7716 
7717         // Process gateway
7718         List<InetAddress> pcscfList = new ArrayList<>();
7719         if (pcscfs != null) {
7720             for (String pcscf : pcscfs) {
7721                 pcscf = pcscf.trim();
7722                 InetAddress ia;
7723                 try {
7724                     ia = InetAddresses.parseNumericAddress(pcscf);
7725                     pcscfList.add(ia);
7726                 } catch (IllegalArgumentException e) {
7727                     Rlog.e(RILJ_LOG_TAG, "Unknown pcscf: " + pcscf, e);
7728                 }
7729             }
7730         }
7731 
7732         return new DataCallResponse.Builder()
7733                 .setCause(cause)
7734                 .setRetryDurationMillis(suggestedRetryTime)
7735                 .setId(cid)
7736                 .setLinkStatus(active)
7737                 .setProtocolType(protocolType)
7738                 .setInterfaceName(ifname)
7739                 .setAddresses(laList)
7740                 .setDnsAddresses(dnsList)
7741                 .setGatewayAddresses(gatewayList)
7742                 .setPcscfAddresses(pcscfList)
7743                 .setMtu(mtu)
7744                 .setMtuV4(mtuV4)
7745                 .setMtuV6(mtuV6)
7746                 .setHandoverFailureMode(handoverFailureMode)
7747                 .setPduSessionId(pduSessionId)
7748                 .setDefaultQos(defaultQos)
7749                 .setQosBearerSessions(qosSessions)
7750                 .setSliceInfo(sliceInfo)
7751                 .setTrafficDescriptors(trafficDescriptors)
7752                 .build();
7753     }
7754 
convertToSliceInfo(OptionalSliceInfo optionalSliceInfo)7755     private static NetworkSliceInfo convertToSliceInfo(OptionalSliceInfo optionalSliceInfo) {
7756         if (optionalSliceInfo.getDiscriminator() == OptionalSliceInfo.hidl_discriminator.noinit) {
7757             return null;
7758         }
7759 
7760         android.hardware.radio.V1_6.SliceInfo si = optionalSliceInfo.value();
7761         NetworkSliceInfo.Builder builder =
7762                 new NetworkSliceInfo.Builder()
7763                 .setSliceServiceType(si.sst)
7764                 .setMappedHplmnSliceServiceType(si.mappedHplmnSst);
7765         if (si.sliceDifferentiator != NetworkSliceInfo.SLICE_DIFFERENTIATOR_NO_SLICE) {
7766             builder
7767                 .setSliceDifferentiator(si.sliceDifferentiator)
7768                 .setMappedHplmnSliceDifferentiator(si.mappedHplmnSD);
7769         }
7770         return builder.build();
7771     }
7772 
convertToTrafficDescriptor( android.hardware.radio.V1_6.TrafficDescriptor td)7773     private static TrafficDescriptor convertToTrafficDescriptor(
7774             android.hardware.radio.V1_6.TrafficDescriptor td) {
7775         String dnn = td.dnn.getDiscriminator() == OptionalDnn.hidl_discriminator.noinit
7776                 ? null : td.dnn.value();
7777         byte[] osAppId = td.osAppId.getDiscriminator() == OptionalOsAppId.hidl_discriminator.noinit
7778                 ? null : arrayListToPrimitiveArray(td.osAppId.value().osAppId);
7779         TrafficDescriptor.Builder builder = new TrafficDescriptor.Builder();
7780         if (dnn != null) {
7781             builder.setDataNetworkName(dnn);
7782         }
7783         if (osAppId != null) {
7784             builder.setOsAppId(osAppId);
7785         }
7786         return builder.build();
7787     }
7788 
7789     /**
7790      * Convert SetupDataCallResult defined in 1.0 or 1.4/types.hal into DataCallResponse
7791      * @param dataCallResultList List of SetupDataCallResult defined in 1.0 or 1.4/types.hal
7792      * @return List of converted DataCallResponse object
7793      */
7794     @VisibleForTesting
convertDataCallResultList( List<? extends Object> dataCallResultList)7795     public static ArrayList<DataCallResponse> convertDataCallResultList(
7796             List<? extends Object> dataCallResultList) {
7797         ArrayList<DataCallResponse> response =
7798                 new ArrayList<DataCallResponse>(dataCallResultList.size());
7799 
7800         for (Object obj : dataCallResultList) {
7801             response.add(convertDataCallResult(obj));
7802         }
7803         return response;
7804     }
7805 
7806     /**
7807      * Get the HAL version.
7808      *
7809      * @return the current HalVersion
7810      */
getHalVersion()7811     public HalVersion getHalVersion() {
7812         return mRadioVersion;
7813     }
7814 }
7815