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