• 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 android.telephony.TelephonyManager.HAL_SERVICE_DATA;
20 import static android.telephony.TelephonyManager.HAL_SERVICE_IMS;
21 import static android.telephony.TelephonyManager.HAL_SERVICE_MESSAGING;
22 import static android.telephony.TelephonyManager.HAL_SERVICE_MODEM;
23 import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
24 import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
25 import static android.telephony.TelephonyManager.HAL_SERVICE_SIM;
26 import static android.telephony.TelephonyManager.HAL_SERVICE_VOICE;
27 
28 import static com.android.internal.telephony.RILConstants.*;
29 
30 import android.annotation.NonNull;
31 import android.annotation.Nullable;
32 import android.compat.annotation.UnsupportedAppUsage;
33 import android.content.Context;
34 import android.hardware.radio.V1_0.IRadio;
35 import android.hardware.radio.V1_0.RadioError;
36 import android.hardware.radio.V1_0.RadioIndicationType;
37 import android.hardware.radio.V1_0.RadioResponseInfo;
38 import android.hardware.radio.V1_0.RadioResponseType;
39 import android.net.KeepalivePacketData;
40 import android.net.LinkProperties;
41 import android.os.AsyncResult;
42 import android.os.Build;
43 import android.os.Handler;
44 import android.os.HwBinder;
45 import android.os.IBinder;
46 import android.os.Message;
47 import android.os.PowerManager;
48 import android.os.PowerManager.WakeLock;
49 import android.os.RemoteException;
50 import android.os.ServiceManager;
51 import android.os.SystemClock;
52 import android.os.SystemProperties;
53 import android.os.Trace;
54 import android.os.WorkSource;
55 import android.provider.Settings;
56 import android.sysprop.TelephonyProperties;
57 import android.telephony.AccessNetworkConstants;
58 import android.telephony.AccessNetworkConstants.AccessNetworkType;
59 import android.telephony.BarringInfo;
60 import android.telephony.CarrierRestrictionRules;
61 import android.telephony.CellInfo;
62 import android.telephony.CellSignalStrengthCdma;
63 import android.telephony.CellSignalStrengthGsm;
64 import android.telephony.CellSignalStrengthLte;
65 import android.telephony.CellSignalStrengthNr;
66 import android.telephony.CellSignalStrengthTdscdma;
67 import android.telephony.CellSignalStrengthWcdma;
68 import android.telephony.ClientRequestStats;
69 import android.telephony.DomainSelectionService;
70 import android.telephony.ImsiEncryptionInfo;
71 import android.telephony.ModemActivityInfo;
72 import android.telephony.NeighboringCellInfo;
73 import android.telephony.NetworkScanRequest;
74 import android.telephony.RadioAccessFamily;
75 import android.telephony.RadioAccessSpecifier;
76 import android.telephony.ServiceState;
77 import android.telephony.SignalStrength;
78 import android.telephony.SignalThresholdInfo;
79 import android.telephony.SubscriptionManager;
80 import android.telephony.TelephonyHistogram;
81 import android.telephony.TelephonyManager;
82 import android.telephony.TelephonyManager.HalService;
83 import android.telephony.TelephonyManager.PrefNetworkMode;
84 import android.telephony.data.DataProfile;
85 import android.telephony.data.NetworkSliceInfo;
86 import android.telephony.data.TrafficDescriptor;
87 import android.telephony.emergency.EmergencyNumber;
88 import android.telephony.ims.RegistrationManager;
89 import android.telephony.ims.feature.ConnectionFailureInfo;
90 import android.telephony.ims.stub.ImsRegistrationImplBase;
91 import android.text.TextUtils;
92 import android.util.SparseArray;
93 
94 import com.android.internal.annotations.VisibleForTesting;
95 import com.android.internal.telephony.cdma.CdmaInformationRecords;
96 import com.android.internal.telephony.cdma.CdmaSmsBroadcastConfigInfo;
97 import com.android.internal.telephony.emergency.EmergencyConstants;
98 import com.android.internal.telephony.gsm.SmsBroadcastConfigInfo;
99 import com.android.internal.telephony.imsphone.ImsCallInfo;
100 import com.android.internal.telephony.metrics.ModemRestartStats;
101 import com.android.internal.telephony.metrics.TelephonyMetrics;
102 import com.android.internal.telephony.nano.TelephonyProto.SmsSession;
103 import com.android.internal.telephony.uicc.IccCardApplicationStatus.PersoSubState;
104 import com.android.internal.telephony.uicc.IccUtils;
105 import com.android.internal.telephony.uicc.SimPhonebookRecord;
106 import com.android.internal.telephony.util.TelephonyUtils;
107 import com.android.telephony.Rlog;
108 
109 import java.io.FileDescriptor;
110 import java.io.PrintWriter;
111 import java.util.ArrayList;
112 import java.util.Arrays;
113 import java.util.HashMap;
114 import java.util.HashSet;
115 import java.util.List;
116 import java.util.Map;
117 import java.util.NoSuchElementException;
118 import java.util.Objects;
119 import java.util.Set;
120 import java.util.concurrent.ConcurrentHashMap;
121 import java.util.concurrent.atomic.AtomicBoolean;
122 import java.util.concurrent.atomic.AtomicLong;
123 
124 /**
125  * RIL implementation of the CommandsInterface.
126  *
127  * {@hide}
128  */
129 public class RIL extends BaseCommands implements CommandsInterface {
130     static final String RILJ_LOG_TAG = "RILJ";
131     static final String RILJ_WAKELOCK_TAG = "*telephony-radio*";
132     // Have a separate wakelock instance for Ack
133     static final String RILJ_ACK_WAKELOCK_NAME = "RILJ_ACK_WL";
134     static final boolean RILJ_LOGD = true;
135     static final boolean RILJ_LOGV = false; // STOPSHIP if true
136     static final int RIL_HISTOGRAM_BUCKET_COUNT = 5;
137 
138     /**
139      * Wake lock timeout should be longer than the longest timeout in
140      * the vendor ril.
141      */
142     private static final int DEFAULT_WAKE_LOCK_TIMEOUT_MS = 60000;
143 
144     // Wake lock default timeout associated with ack
145     private static final int DEFAULT_ACK_WAKE_LOCK_TIMEOUT_MS = 200;
146 
147     private static final int DEFAULT_BLOCKING_MESSAGE_RESPONSE_TIMEOUT_MS = 2000;
148 
149     // Variables used to differentiate ack messages from request while calling clearWakeLock()
150     public static final int INVALID_WAKELOCK = -1;
151     public static final int FOR_WAKELOCK = 0;
152     public static final int FOR_ACK_WAKELOCK = 1;
153     private final ClientWakelockTracker mClientWakelockTracker = new ClientWakelockTracker();
154 
155     /** @hide */
156     public static final HalVersion RADIO_HAL_VERSION_UNSUPPORTED = HalVersion.UNSUPPORTED;
157 
158     /** @hide */
159     public static final HalVersion RADIO_HAL_VERSION_UNKNOWN = HalVersion.UNKNOWN;
160 
161     /** @hide */
162     public static final HalVersion RADIO_HAL_VERSION_1_0 = new HalVersion(1, 0);
163 
164     /** @hide */
165     public static final HalVersion RADIO_HAL_VERSION_1_1 = new HalVersion(1, 1);
166 
167     /** @hide */
168     public static final HalVersion RADIO_HAL_VERSION_1_2 = new HalVersion(1, 2);
169 
170     /** @hide */
171     public static final HalVersion RADIO_HAL_VERSION_1_3 = new HalVersion(1, 3);
172 
173     /** @hide */
174     public static final HalVersion RADIO_HAL_VERSION_1_4 = new HalVersion(1, 4);
175 
176     /** @hide */
177     public static final HalVersion RADIO_HAL_VERSION_1_5 = new HalVersion(1, 5);
178 
179     /** @hide */
180     public static final HalVersion RADIO_HAL_VERSION_1_6 = new HalVersion(1, 6);
181 
182     /** @hide */
183     public static final HalVersion RADIO_HAL_VERSION_2_0 = new HalVersion(2, 0);
184 
185     /** @hide */
186     public static final HalVersion RADIO_HAL_VERSION_2_1 = new HalVersion(2, 1);
187 
188     // Hal version
189     private Map<Integer, HalVersion> mHalVersion = new HashMap<>();
190 
191     //***** Instance Variables
192 
193     @UnsupportedAppUsage
194     @VisibleForTesting
195     public final WakeLock mWakeLock;           // Wake lock associated with request/response
196     @VisibleForTesting
197     public final WakeLock mAckWakeLock;        // Wake lock associated with ack sent
198     final int mWakeLockTimeout;         // Timeout associated with request/response
199     final int mAckWakeLockTimeout;      // Timeout associated with ack sent
200     // The number of wakelock requests currently active.  Don't release the lock
201     // until dec'd to 0
202     int mWakeLockCount;
203 
204     // Variables used to identify releasing of WL on wakelock timeouts
205     volatile int mWlSequenceNum = 0;
206     volatile int mAckWlSequenceNum = 0;
207 
208     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
209     SparseArray<RILRequest> mRequestList = new SparseArray<>();
210     static SparseArray<TelephonyHistogram> sRilTimeHistograms = new SparseArray<>();
211 
212     Object[] mLastNITZTimeInfo;
213 
214     int mLastRadioPowerResult = RadioError.NONE;
215 
216     boolean mIsRadioProxyInitialized = false;
217 
218     // When we are testing emergency calls using ril.test.emergencynumber, this will trigger test
219     // ECbM when the call is ended.
220     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
221     AtomicBoolean mTestingEmergencyCall = new AtomicBoolean(false);
222 
223     final Integer mPhoneId;
224 
225     private static final String PROPERTY_IS_VONR_ENABLED = "persist.radio.is_vonr_enabled_";
226 
227     public static final int MIN_SERVICE_IDX = HAL_SERVICE_RADIO;
228 
229     public static final int MAX_SERVICE_IDX = HAL_SERVICE_IMS;
230 
231     /**
232      * An array of sets that records if services are disabled in the HAL for a specific phone ID
233      * slot to avoid further getService requests for that service. See XXX_SERVICE for the indices.
234      * RADIO_SERVICE is the HIDL IRadio service, and mDisabledRadioServices.get(RADIO_SERVICE)
235      * will return a set of all phone ID slots that are disabled for IRadio.
236      */
237     private final SparseArray<Set<Integer>> mDisabledRadioServices = new SparseArray<>();
238 
239     /* default work source which will blame phone process */
240     private WorkSource mRILDefaultWorkSource;
241 
242     /* Worksource containing all applications causing wakelock to be held */
243     private WorkSource mActiveWakelockWorkSource;
244 
245     /** Telephony metrics instance for logging metrics event */
246     private TelephonyMetrics mMetrics = TelephonyMetrics.getInstance();
247     /** Radio bug detector instance */
248     private RadioBugDetector mRadioBugDetector = null;
249 
250     private boolean mIsCellularSupported;
251     private RadioResponse mRadioResponse;
252     private RadioIndication mRadioIndication;
253     private volatile IRadio mRadioProxy = null;
254     private DataResponse mDataResponse;
255     private DataIndication mDataIndication;
256     private ImsResponse mImsResponse;
257     private ImsIndication mImsIndication;
258     private MessagingResponse mMessagingResponse;
259     private MessagingIndication mMessagingIndication;
260     private ModemResponse mModemResponse;
261     private ModemIndication mModemIndication;
262     private NetworkResponse mNetworkResponse;
263     private NetworkIndication mNetworkIndication;
264     private SimResponse mSimResponse;
265     private SimIndication mSimIndication;
266     private VoiceResponse mVoiceResponse;
267     private VoiceIndication mVoiceIndication;
268     private SparseArray<RadioServiceProxy> mServiceProxies = new SparseArray<>();
269     private final SparseArray<BinderServiceDeathRecipient> mDeathRecipients = new SparseArray<>();
270     private final SparseArray<AtomicLong> mServiceCookies = new SparseArray<>();
271     private final RadioProxyDeathRecipient mRadioProxyDeathRecipient;
272     final RilHandler mRilHandler;
273     private MockModem mMockModem;
274 
275     // Thread-safe HashMap to map from RIL_REQUEST_XXX constant to HalVersion.
276     // This is for Radio HAL Fallback Compatibility feature. When a RIL request
277     // is received, the HAL method from the mapping HalVersion here (if present),
278     // instead of the latest HalVersion, will be invoked.
279     private final ConcurrentHashMap<Integer, HalVersion> mCompatOverrides =
280             new ConcurrentHashMap<>();
281 
282     //***** Events
283     static final int EVENT_WAKE_LOCK_TIMEOUT = 2;
284     static final int EVENT_ACK_WAKE_LOCK_TIMEOUT = 4;
285     static final int EVENT_BLOCKING_RESPONSE_TIMEOUT = 5;
286     static final int EVENT_RADIO_PROXY_DEAD = 6;
287     static final int EVENT_AIDL_PROXY_DEAD = 7;
288 
289     //***** Constants
290 
291     static final String[] HIDL_SERVICE_NAME = {"slot1", "slot2", "slot3"};
292 
getTelephonyRILTimingHistograms()293     public static List<TelephonyHistogram> getTelephonyRILTimingHistograms() {
294         List<TelephonyHistogram> list;
295         synchronized (sRilTimeHistograms) {
296             list = new ArrayList<>(sRilTimeHistograms.size());
297             for (int i = 0; i < sRilTimeHistograms.size(); i++) {
298                 TelephonyHistogram entry = new TelephonyHistogram(sRilTimeHistograms.valueAt(i));
299                 list.add(entry);
300             }
301         }
302         return list;
303     }
304 
305     /** The handler used to handle the internal event of RIL. */
306     @VisibleForTesting
307     public class RilHandler extends Handler {
308 
309         //***** Handler implementation
310         @Override
handleMessage(Message msg)311         public void handleMessage(Message msg) {
312             RILRequest rr;
313 
314             switch (msg.what) {
315                 case EVENT_WAKE_LOCK_TIMEOUT:
316                     // Haven't heard back from the last request.  Assume we're
317                     // not getting a response and  release the wake lock.
318 
319                     // The timer of WAKE_LOCK_TIMEOUT is reset with each
320                     // new send request. So when WAKE_LOCK_TIMEOUT occurs
321                     // all requests in mRequestList already waited at
322                     // least DEFAULT_WAKE_LOCK_TIMEOUT_MS but no response.
323                     //
324                     // Note: Keep mRequestList so that delayed response
325                     // can still be handled when response finally comes.
326 
327                     synchronized (mRequestList) {
328                         if (msg.arg1 == mWlSequenceNum && clearWakeLock(FOR_WAKELOCK)) {
329                             if (mRadioBugDetector != null) {
330                                 mRadioBugDetector.processWakelockTimeout();
331                             }
332                             if (RILJ_LOGD) {
333                                 int count = mRequestList.size();
334                                 Rlog.d(RILJ_LOG_TAG, "WAKE_LOCK_TIMEOUT " +
335                                         " mRequestList=" + count);
336                                 for (int i = 0; i < count; i++) {
337                                     rr = mRequestList.valueAt(i);
338                                     Rlog.d(RILJ_LOG_TAG, i + ": [" + rr.mSerial + "] "
339                                             + RILUtils.requestToString(rr.mRequest));
340                                 }
341                             }
342                         }
343                     }
344                     break;
345 
346                 case EVENT_ACK_WAKE_LOCK_TIMEOUT:
347                     if (msg.arg1 == mAckWlSequenceNum && clearWakeLock(FOR_ACK_WAKELOCK)) {
348                         if (RILJ_LOGV) {
349                             Rlog.d(RILJ_LOG_TAG, "ACK_WAKE_LOCK_TIMEOUT");
350                         }
351                     }
352                     break;
353 
354                 case EVENT_BLOCKING_RESPONSE_TIMEOUT:
355                     int serial = (int) msg.obj;
356                     rr = findAndRemoveRequestFromList(serial);
357                     // If the request has already been processed, do nothing
358                     if (rr == null) {
359                         break;
360                     }
361 
362                     // Build a response if expected
363                     if (rr.mResult != null) {
364                         Object timeoutResponse = getResponseForTimedOutRILRequest(rr);
365                         AsyncResult.forMessage(rr.mResult, timeoutResponse, null);
366                         rr.mResult.sendToTarget();
367                         mMetrics.writeOnRilTimeoutResponse(mPhoneId, rr.mSerial, rr.mRequest);
368                     }
369 
370                     decrementWakeLock(rr);
371                     rr.release();
372                     break;
373 
374                 case EVENT_RADIO_PROXY_DEAD:
375                     int service = msg.arg1;
376                     riljLog("handleMessage: EVENT_RADIO_PROXY_DEAD cookie = " + msg.obj
377                             + ", service = " + serviceToString(service) + ", service cookie = "
378                             + mServiceCookies.get(service));
379                     if ((long) msg.obj == mServiceCookies.get(service).get()) {
380                         mIsRadioProxyInitialized = false;
381                         resetProxyAndRequestList(service);
382                     }
383                     break;
384 
385                 case EVENT_AIDL_PROXY_DEAD:
386                     int aidlService = msg.arg1;
387                     long msgCookie = (long) msg.obj;
388                     riljLog("handleMessage: EVENT_AIDL_PROXY_DEAD cookie = " + msgCookie
389                             + ", service = " + serviceToString(aidlService) + ", cookie = "
390                             + mServiceCookies.get(aidlService));
391                     if (msgCookie == mServiceCookies.get(aidlService).get()) {
392                         mIsRadioProxyInitialized = false;
393                         resetProxyAndRequestList(aidlService);
394                     }
395                     break;
396             }
397         }
398     }
399 
400     /** Return RadioBugDetector instance for testing. */
401     @VisibleForTesting
getRadioBugDetector()402     public RadioBugDetector getRadioBugDetector() {
403         if (mRadioBugDetector == null) {
404             mRadioBugDetector = new RadioBugDetector(mContext, mPhoneId);
405         }
406         return mRadioBugDetector;
407     }
408 
409     /**
410      * In order to prevent calls to Telephony from waiting indefinitely
411      * low-latency blocking calls will eventually time out. In the event of
412      * a timeout, this function generates a response that is returned to the
413      * higher layers to unblock the call. This is in lieu of a meaningful
414      * response.
415      * @param rr The RIL Request that has timed out.
416      * @return A default object, such as the one generated by a normal response
417      * that is returned to the higher layers.
418      **/
419     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
getResponseForTimedOutRILRequest(RILRequest rr)420     private static Object getResponseForTimedOutRILRequest(RILRequest rr) {
421         if (rr == null ) return null;
422 
423         Object timeoutResponse = null;
424         switch(rr.mRequest) {
425             case RIL_REQUEST_GET_ACTIVITY_INFO:
426                 timeoutResponse = new ModemActivityInfo(
427                         0, 0, 0, new int [ModemActivityInfo.getNumTxPowerLevels()], 0);
428                 break;
429         };
430         return timeoutResponse;
431     }
432 
433     final class RadioProxyDeathRecipient implements HwBinder.DeathRecipient {
434         @Override
serviceDied(long cookie)435         public void serviceDied(long cookie) {
436             // Deal with service going away
437             riljLog("serviceDied");
438             mRilHandler.sendMessage(mRilHandler.obtainMessage(EVENT_RADIO_PROXY_DEAD,
439                     HAL_SERVICE_RADIO, 0 /* ignored arg2 */, cookie));
440         }
441     }
442 
443     private final class BinderServiceDeathRecipient implements IBinder.DeathRecipient {
444         private IBinder mBinder;
445         private final int mService;
446 
BinderServiceDeathRecipient(int service)447         BinderServiceDeathRecipient(int service) {
448             mService = service;
449         }
450 
linkToDeath(IBinder service)451         public void linkToDeath(IBinder service) throws RemoteException {
452             if (service != null) {
453                 riljLog("Linked to death for service " + serviceToString(mService));
454                 mBinder = service;
455                 mBinder.linkToDeath(this, (int) mServiceCookies.get(mService).incrementAndGet());
456             } else {
457                 riljLoge("Unable to link to death for service " + serviceToString(mService));
458             }
459         }
460 
unlinkToDeath()461         public synchronized void unlinkToDeath() {
462             if (mBinder != null) {
463                 mBinder.unlinkToDeath(this, 0);
464                 mBinder = null;
465             }
466         }
467 
468         @Override
binderDied()469         public void binderDied() {
470             riljLog("Service " + serviceToString(mService) + " has died.");
471             mRilHandler.sendMessage(mRilHandler.obtainMessage(EVENT_AIDL_PROXY_DEAD, mService,
472                     0 /* ignored arg2 */, mServiceCookies.get(mService).get()));
473             unlinkToDeath();
474         }
475     }
476 
resetProxyAndRequestList(int service)477     private synchronized void resetProxyAndRequestList(int service) {
478         if (service == HAL_SERVICE_RADIO) {
479             mRadioProxy = null;
480         } else {
481             mServiceProxies.get(service).clear();
482         }
483 
484         // Increment the cookie so that death notification can be ignored
485         mServiceCookies.get(service).incrementAndGet();
486 
487         // TODO: If a service doesn't exist or is unimplemented, it shouldn't cause the radio to
488         //  become unavailable for all other services
489         setRadioState(TelephonyManager.RADIO_POWER_UNAVAILABLE, true /* forceNotifyRegistrants */);
490 
491         RILRequest.resetSerial();
492         // Clear request list on close
493         clearRequestList(RADIO_NOT_AVAILABLE, false);
494 
495         if (service == HAL_SERVICE_RADIO) {
496             getRadioProxy(null);
497         } else {
498             getRadioServiceProxy(service, null);
499         }
500     }
501 
502     /**
503      * Request to enable/disable the mock modem service.
504      * This is invoked from shell commands during CTS testing only.
505      *
506      * @param serviceName the service name we want to bind to
507      */
setModemService(String serviceName)508     public boolean setModemService(String serviceName) {
509         boolean serviceBound = true;
510 
511         if (serviceName != null) {
512             riljLog("Binding to MockModemService");
513             mMockModem = null;
514 
515             mMockModem = new MockModem(mContext, serviceName, mPhoneId);
516             if (mMockModem == null) {
517                 riljLoge("MockModem create fail.");
518                 return false;
519             }
520 
521             // Disable HIDL service
522             if (mRadioProxy != null) {
523                 riljLog("Disable HIDL service");
524                 mDisabledRadioServices.get(HAL_SERVICE_RADIO).add(mPhoneId);
525             }
526 
527             mMockModem.bindAllMockModemService();
528 
529             for (int service = MIN_SERVICE_IDX; service <= MAX_SERVICE_IDX; service++) {
530                 if (service == HAL_SERVICE_RADIO) continue;
531 
532                 int retryCount = 0;
533                 IBinder binder;
534                 do {
535                     binder = mMockModem.getServiceBinder(service);
536 
537                     retryCount++;
538                     if (binder == null) {
539                         riljLog("Retry(" + retryCount + ") Service " + serviceToString(service));
540                         try {
541                             Thread.sleep(MockModem.BINDER_RETRY_MILLIS);
542                         } catch (InterruptedException e) {
543                         }
544                     }
545                 } while ((binder == null) && (retryCount < MockModem.BINDER_MAX_RETRY));
546 
547                 if (binder == null) {
548                     riljLoge("Service " + serviceToString(service) + " bind fail");
549                     serviceBound = false;
550                     break;
551                 }
552             }
553 
554             if (serviceBound) {
555                 mIsRadioProxyInitialized = false;
556                 for (int service = MIN_SERVICE_IDX; service <= MAX_SERVICE_IDX; service++) {
557                     resetProxyAndRequestList(service);
558                 }
559             }
560         }
561 
562         if ((serviceName == null) || (!serviceBound)) {
563             if (serviceBound) riljLog("Unbinding to MockModemService");
564 
565             if (mDisabledRadioServices.get(HAL_SERVICE_RADIO).contains(mPhoneId)) {
566                 mDisabledRadioServices.get(HAL_SERVICE_RADIO).clear();
567             }
568 
569             if (mMockModem != null) {
570                 mMockModem = null;
571                 for (int service = MIN_SERVICE_IDX; service <= MAX_SERVICE_IDX; service++) {
572                     if (service == HAL_SERVICE_RADIO) {
573                         if (isRadioVersion2_0()) {
574                             mHalVersion.put(service, RADIO_HAL_VERSION_2_0);
575                         } else {
576                             mHalVersion.put(service, RADIO_HAL_VERSION_UNKNOWN);
577                         }
578                     } else {
579                         if (isRadioServiceSupported(service)) {
580                             mHalVersion.put(service, RADIO_HAL_VERSION_UNKNOWN);
581                         } else {
582                             mHalVersion.put(service, RADIO_HAL_VERSION_UNSUPPORTED);
583                         }
584                     }
585                     resetProxyAndRequestList(service);
586                 }
587             }
588         }
589 
590         return serviceBound;
591     }
592 
593     /**
594      * Get current bound service in Radio Module
595      */
getModemService()596     public String getModemService() {
597         if (mMockModem != null) {
598             return mMockModem.getServiceName();
599         } else {
600             return "default";
601         }
602     }
603 
604     /** Set a radio HAL fallback compatibility override. */
605     @VisibleForTesting
setCompatVersion(int rilRequest, @NonNull HalVersion halVersion)606     public void setCompatVersion(int rilRequest, @NonNull HalVersion halVersion) {
607         HalVersion oldVersion = getCompatVersion(rilRequest);
608         // Do not allow to set same or greater verions
609         if (oldVersion != null && halVersion.greaterOrEqual(oldVersion)) {
610             riljLoge("setCompatVersion with equal or greater one, ignored, halVerion=" + halVersion
611                     + ", oldVerion=" + oldVersion);
612             return;
613         }
614         mCompatOverrides.put(rilRequest, halVersion);
615     }
616 
617     /** Get a radio HAL fallback compatibility override, or null if not exist. */
618     @VisibleForTesting
getCompatVersion(int rilRequest)619     public @Nullable HalVersion getCompatVersion(int rilRequest) {
620         return mCompatOverrides.getOrDefault(rilRequest, null);
621     }
622 
623     /** Returns a {@link IRadio} instance or null if the service is not available. */
624     @VisibleForTesting
getRadioProxy(Message result)625     public synchronized IRadio getRadioProxy(Message result) {
626         if (mHalVersion.containsKey(HAL_SERVICE_RADIO)
627                 && mHalVersion.get(HAL_SERVICE_RADIO).greaterOrEqual(RADIO_HAL_VERSION_2_0)) {
628             return null;
629         }
630         if (!SubscriptionManager.isValidPhoneId(mPhoneId)) return null;
631         if (!mIsCellularSupported) {
632             if (RILJ_LOGV) riljLog("getRadioProxy: Not calling getService(): wifi-only");
633             if (result != null) {
634                 AsyncResult.forMessage(result, null,
635                         CommandException.fromRilErrno(RADIO_NOT_AVAILABLE));
636                 result.sendToTarget();
637             }
638             return null;
639         }
640 
641         if (mRadioProxy != null) {
642             return mRadioProxy;
643         }
644 
645         try {
646             if (mDisabledRadioServices.get(HAL_SERVICE_RADIO).contains(mPhoneId)) {
647                 riljLoge("getRadioProxy: mRadioProxy for " + HIDL_SERVICE_NAME[mPhoneId]
648                         + " is disabled");
649             } else {
650                 try {
651                     mRadioProxy = android.hardware.radio.V1_6.IRadio.getService(
652                             HIDL_SERVICE_NAME[mPhoneId], true);
653                     mHalVersion.put(HAL_SERVICE_RADIO, RADIO_HAL_VERSION_1_6);
654                 } catch (NoSuchElementException e) {
655                 }
656 
657                 if (mRadioProxy == null) {
658                     try {
659                         mRadioProxy = android.hardware.radio.V1_5.IRadio.getService(
660                                 HIDL_SERVICE_NAME[mPhoneId], true);
661                         mHalVersion.put(HAL_SERVICE_RADIO, RADIO_HAL_VERSION_1_5);
662                     } catch (NoSuchElementException e) {
663                     }
664                 }
665 
666                 if (mRadioProxy == null) {
667                     try {
668                         mRadioProxy = android.hardware.radio.V1_4.IRadio.getService(
669                                 HIDL_SERVICE_NAME[mPhoneId], true);
670                         mHalVersion.put(HAL_SERVICE_RADIO, RADIO_HAL_VERSION_1_4);
671                     } catch (NoSuchElementException e) {
672                     }
673                 }
674 
675                 if (mRadioProxy == null) {
676                     try {
677                         mRadioProxy = android.hardware.radio.V1_3.IRadio.getService(
678                                 HIDL_SERVICE_NAME[mPhoneId], true);
679                         mHalVersion.put(HAL_SERVICE_RADIO, RADIO_HAL_VERSION_1_3);
680                     } catch (NoSuchElementException e) {
681                     }
682                 }
683 
684                 if (mRadioProxy == null) {
685                     try {
686                         mRadioProxy = android.hardware.radio.V1_2.IRadio.getService(
687                                 HIDL_SERVICE_NAME[mPhoneId], true);
688                         mHalVersion.put(HAL_SERVICE_RADIO, RADIO_HAL_VERSION_1_2);
689                     } catch (NoSuchElementException e) {
690                     }
691                 }
692 
693                 if (mRadioProxy == null) {
694                     try {
695                         mRadioProxy = android.hardware.radio.V1_1.IRadio.getService(
696                                 HIDL_SERVICE_NAME[mPhoneId], true);
697                         mHalVersion.put(HAL_SERVICE_RADIO, RADIO_HAL_VERSION_1_1);
698                     } catch (NoSuchElementException e) {
699                     }
700                 }
701 
702                 if (mRadioProxy == null) {
703                     try {
704                         mRadioProxy = android.hardware.radio.V1_0.IRadio.getService(
705                                 HIDL_SERVICE_NAME[mPhoneId], true);
706                         mHalVersion.put(HAL_SERVICE_RADIO, RADIO_HAL_VERSION_1_0);
707                     } catch (NoSuchElementException e) {
708                     }
709                 }
710 
711                 if (mRadioProxy != null) {
712                     if (!mIsRadioProxyInitialized) {
713                         mIsRadioProxyInitialized = true;
714                         mRadioProxy.linkToDeath(mRadioProxyDeathRecipient,
715                                 mServiceCookies.get(HAL_SERVICE_RADIO).incrementAndGet());
716                         mRadioProxy.setResponseFunctions(mRadioResponse, mRadioIndication);
717                     }
718                 } else {
719                     mDisabledRadioServices.get(HAL_SERVICE_RADIO).add(mPhoneId);
720                     riljLoge("getRadioProxy: set mRadioProxy for "
721                             + HIDL_SERVICE_NAME[mPhoneId] + " as disabled");
722                 }
723             }
724         } catch (RemoteException e) {
725             mRadioProxy = null;
726             riljLoge("RadioProxy getService/setResponseFunctions: " + e);
727         }
728 
729         if (mRadioProxy == null) {
730             // getService() is a blocking call, so this should never happen
731             riljLoge("getRadioProxy: mRadioProxy == null");
732             if (result != null) {
733                 AsyncResult.forMessage(result, null,
734                         CommandException.fromRilErrno(RADIO_NOT_AVAILABLE));
735                 result.sendToTarget();
736             }
737         }
738 
739         return mRadioProxy;
740     }
741 
742     /**
743      * Returns a {@link RadioDataProxy}, {@link RadioMessagingProxy}, {@link RadioModemProxy},
744      * {@link RadioNetworkProxy}, {@link RadioSimProxy}, {@link RadioVoiceProxy},
745      * {@link RadioImsProxy}, or null if the service is not available.
746      */
747     @NonNull
getRadioServiceProxy(Class<T> serviceClass, Message result)748     public <T extends RadioServiceProxy> T getRadioServiceProxy(Class<T> serviceClass,
749             Message result) {
750         if (serviceClass == RadioDataProxy.class) {
751             return (T) getRadioServiceProxy(HAL_SERVICE_DATA, result);
752         }
753         if (serviceClass == RadioMessagingProxy.class) {
754             return (T) getRadioServiceProxy(HAL_SERVICE_MESSAGING, result);
755         }
756         if (serviceClass == RadioModemProxy.class) {
757             return (T) getRadioServiceProxy(HAL_SERVICE_MODEM, result);
758         }
759         if (serviceClass == RadioNetworkProxy.class) {
760             return (T) getRadioServiceProxy(HAL_SERVICE_NETWORK, result);
761         }
762         if (serviceClass == RadioSimProxy.class) {
763             return (T) getRadioServiceProxy(HAL_SERVICE_SIM, result);
764         }
765         if (serviceClass == RadioVoiceProxy.class) {
766             return (T) getRadioServiceProxy(HAL_SERVICE_VOICE, result);
767         }
768         if (serviceClass == RadioImsProxy.class) {
769             return (T) getRadioServiceProxy(HAL_SERVICE_IMS, result);
770         }
771         riljLoge("getRadioServiceProxy: unrecognized " + serviceClass);
772         return null;
773     }
774 
775     /**
776      * Returns a {@link RadioServiceProxy}, which is empty if the service is not available.
777      * For HAL_SERVICE_RADIO, use {@link #getRadioProxy} instead, as this will always return null.
778      */
779     @VisibleForTesting
780     @NonNull
getRadioServiceProxy(int service, Message result)781     public synchronized RadioServiceProxy getRadioServiceProxy(int service, Message result) {
782         if (!SubscriptionManager.isValidPhoneId(mPhoneId)) return mServiceProxies.get(service);
783         if ((service >= HAL_SERVICE_IMS) && !isRadioServiceSupported(service)) {
784             return mServiceProxies.get(service);
785         }
786         if (!mIsCellularSupported) {
787             if (RILJ_LOGV) riljLog("getRadioServiceProxy: Not calling getService(): wifi-only");
788             if (result != null) {
789                 AsyncResult.forMessage(result, null,
790                         CommandException.fromRilErrno(RADIO_NOT_AVAILABLE));
791                 result.sendToTarget();
792             }
793             return mServiceProxies.get(service);
794         }
795 
796         RadioServiceProxy serviceProxy = mServiceProxies.get(service);
797         if (!serviceProxy.isEmpty()) {
798             return serviceProxy;
799         }
800 
801         try {
802             if (mMockModem == null && mDisabledRadioServices.get(service).contains(mPhoneId)) {
803                 riljLoge("getRadioServiceProxy: " + serviceToString(service) + " for "
804                         + HIDL_SERVICE_NAME[mPhoneId] + " is disabled");
805             } else {
806                 IBinder binder;
807                 switch (service) {
808                     case HAL_SERVICE_DATA:
809                         if (mMockModem == null) {
810                             binder = ServiceManager.waitForDeclaredService(
811                                     android.hardware.radio.data.IRadioData.DESCRIPTOR + "/"
812                                             + HIDL_SERVICE_NAME[mPhoneId]);
813                         } else {
814                             binder = mMockModem.getServiceBinder(HAL_SERVICE_DATA);
815                         }
816                         if (binder != null) {
817                             mHalVersion.put(service, ((RadioDataProxy) serviceProxy).setAidl(
818                                     mHalVersion.get(service),
819                                     android.hardware.radio.data.IRadioData.Stub.asInterface(
820                                             binder)));
821                         }
822                         break;
823                     case HAL_SERVICE_MESSAGING:
824                         if (mMockModem == null) {
825                             binder = ServiceManager.waitForDeclaredService(
826                                     android.hardware.radio.messaging.IRadioMessaging.DESCRIPTOR
827                                             + "/" + HIDL_SERVICE_NAME[mPhoneId]);
828                         } else {
829                             binder = mMockModem.getServiceBinder(HAL_SERVICE_MESSAGING);
830                         }
831                         if (binder != null) {
832                             mHalVersion.put(service, ((RadioMessagingProxy) serviceProxy).setAidl(
833                                     mHalVersion.get(service),
834                                     android.hardware.radio.messaging.IRadioMessaging.Stub
835                                             .asInterface(binder)));
836                         }
837                         break;
838                     case HAL_SERVICE_MODEM:
839                         if (mMockModem == null) {
840                             binder = ServiceManager.waitForDeclaredService(
841                                     android.hardware.radio.modem.IRadioModem.DESCRIPTOR + "/"
842                                             + HIDL_SERVICE_NAME[mPhoneId]);
843                         } else {
844                             binder = mMockModem.getServiceBinder(HAL_SERVICE_MODEM);
845                         }
846                         if (binder != null) {
847                             mHalVersion.put(service, ((RadioModemProxy) serviceProxy).setAidl(
848                                     mHalVersion.get(service),
849                                     android.hardware.radio.modem.IRadioModem.Stub
850                                             .asInterface(binder)));
851                         }
852                         break;
853                     case HAL_SERVICE_NETWORK:
854                         if (mMockModem == null) {
855                             binder = ServiceManager.waitForDeclaredService(
856                                     android.hardware.radio.network.IRadioNetwork.DESCRIPTOR + "/"
857                                             + HIDL_SERVICE_NAME[mPhoneId]);
858                         } else {
859                             binder = mMockModem.getServiceBinder(HAL_SERVICE_NETWORK);
860                         }
861                         if (binder != null) {
862                             mHalVersion.put(service, ((RadioNetworkProxy) serviceProxy).setAidl(
863                                     mHalVersion.get(service),
864                                     android.hardware.radio.network.IRadioNetwork.Stub
865                                             .asInterface(binder)));
866                         }
867                         break;
868                     case HAL_SERVICE_SIM:
869                         if (mMockModem == null) {
870                             binder = ServiceManager.waitForDeclaredService(
871                                     android.hardware.radio.sim.IRadioSim.DESCRIPTOR + "/"
872                                             + HIDL_SERVICE_NAME[mPhoneId]);
873                         } else {
874                             binder = mMockModem.getServiceBinder(HAL_SERVICE_SIM);
875                         }
876                         if (binder != null) {
877                             mHalVersion.put(service, ((RadioSimProxy) serviceProxy).setAidl(
878                                     mHalVersion.get(service),
879                                     android.hardware.radio.sim.IRadioSim.Stub
880                                             .asInterface(binder)));
881                         }
882                         break;
883                     case HAL_SERVICE_VOICE:
884                         if (mMockModem == null) {
885                             binder = ServiceManager.waitForDeclaredService(
886                                     android.hardware.radio.voice.IRadioVoice.DESCRIPTOR + "/"
887                                             + HIDL_SERVICE_NAME[mPhoneId]);
888                         } else {
889                             binder = mMockModem.getServiceBinder(HAL_SERVICE_VOICE);
890                         }
891                         if (binder != null) {
892                             mHalVersion.put(service, ((RadioVoiceProxy) serviceProxy).setAidl(
893                                     mHalVersion.get(service),
894                                     android.hardware.radio.voice.IRadioVoice.Stub
895                                             .asInterface(binder)));
896                         }
897                         break;
898                     case HAL_SERVICE_IMS:
899                         if (mMockModem == null) {
900                             binder = ServiceManager.waitForDeclaredService(
901                                     android.hardware.radio.ims.IRadioIms.DESCRIPTOR + "/"
902                                             + HIDL_SERVICE_NAME[mPhoneId]);
903                         } else {
904                             binder = mMockModem.getServiceBinder(HAL_SERVICE_IMS);
905                         }
906                         if (binder != null) {
907                             mHalVersion.put(service, ((RadioImsProxy) serviceProxy).setAidl(
908                                     mHalVersion.get(service),
909                                     android.hardware.radio.ims.IRadioIms.Stub
910                                             .asInterface(binder)));
911                         }
912                         break;
913                 }
914 
915                 if (serviceProxy.isEmpty()
916                         && mHalVersion.get(service).less(RADIO_HAL_VERSION_2_0)) {
917                     try {
918                         mHalVersion.put(service, RADIO_HAL_VERSION_1_6);
919                         serviceProxy.setHidl(mHalVersion.get(service),
920                                 android.hardware.radio.V1_6.IRadio.getService(
921                                         HIDL_SERVICE_NAME[mPhoneId], true));
922                     } catch (NoSuchElementException e) {
923                     }
924                 }
925 
926                 if (serviceProxy.isEmpty()
927                         && mHalVersion.get(service).less(RADIO_HAL_VERSION_2_0)) {
928                     try {
929                         mHalVersion.put(service, RADIO_HAL_VERSION_1_5);
930                         serviceProxy.setHidl(mHalVersion.get(service),
931                                 android.hardware.radio.V1_5.IRadio.getService(
932                                         HIDL_SERVICE_NAME[mPhoneId], true));
933                     } catch (NoSuchElementException e) {
934                     }
935                 }
936 
937                 if (serviceProxy.isEmpty()
938                         && mHalVersion.get(service).less(RADIO_HAL_VERSION_2_0)) {
939                     try {
940                         mHalVersion.put(service, RADIO_HAL_VERSION_1_4);
941                         serviceProxy.setHidl(mHalVersion.get(service),
942                                 android.hardware.radio.V1_4.IRadio.getService(
943                                         HIDL_SERVICE_NAME[mPhoneId], true));
944                     } catch (NoSuchElementException e) {
945                     }
946                 }
947 
948                 if (serviceProxy.isEmpty()
949                         && mHalVersion.get(service).less(RADIO_HAL_VERSION_2_0)) {
950                     try {
951                         mHalVersion.put(service, RADIO_HAL_VERSION_1_3);
952                         serviceProxy.setHidl(mHalVersion.get(service),
953                                 android.hardware.radio.V1_3.IRadio.getService(
954                                         HIDL_SERVICE_NAME[mPhoneId], true));
955                     } catch (NoSuchElementException e) {
956                     }
957                 }
958 
959                 if (serviceProxy.isEmpty()
960                         && mHalVersion.get(service).less(RADIO_HAL_VERSION_2_0)) {
961                     try {
962                         mHalVersion.put(service, RADIO_HAL_VERSION_1_2);
963                         serviceProxy.setHidl(mHalVersion.get(service),
964                                 android.hardware.radio.V1_2.IRadio.getService(
965                                         HIDL_SERVICE_NAME[mPhoneId], true));
966                     } catch (NoSuchElementException e) {
967                     }
968                 }
969 
970                 if (serviceProxy.isEmpty()
971                         && mHalVersion.get(service).less(RADIO_HAL_VERSION_2_0)) {
972                     try {
973                         mHalVersion.put(service, RADIO_HAL_VERSION_1_1);
974                         serviceProxy.setHidl(mHalVersion.get(service),
975                                 android.hardware.radio.V1_1.IRadio.getService(
976                                         HIDL_SERVICE_NAME[mPhoneId], true));
977                     } catch (NoSuchElementException e) {
978                     }
979                 }
980 
981                 if (serviceProxy.isEmpty()
982                         && mHalVersion.get(service).less(RADIO_HAL_VERSION_2_0)) {
983                     try {
984                         mHalVersion.put(service, RADIO_HAL_VERSION_1_0);
985                         serviceProxy.setHidl(mHalVersion.get(service),
986                                 android.hardware.radio.V1_0.IRadio.getService(
987                                         HIDL_SERVICE_NAME[mPhoneId], true));
988                     } catch (NoSuchElementException e) {
989                     }
990                 }
991 
992                 if (!serviceProxy.isEmpty()) {
993                     if (serviceProxy.isAidl()) {
994                         switch (service) {
995                             case HAL_SERVICE_DATA:
996                                 mDeathRecipients.get(service).linkToDeath(
997                                         ((RadioDataProxy) serviceProxy).getAidl().asBinder());
998                                 ((RadioDataProxy) serviceProxy).getAidl().setResponseFunctions(
999                                         mDataResponse, mDataIndication);
1000                                 break;
1001                             case HAL_SERVICE_MESSAGING:
1002                                 mDeathRecipients.get(service).linkToDeath(
1003                                         ((RadioMessagingProxy) serviceProxy).getAidl().asBinder());
1004                                 ((RadioMessagingProxy) serviceProxy).getAidl().setResponseFunctions(
1005                                         mMessagingResponse, mMessagingIndication);
1006                                 break;
1007                             case HAL_SERVICE_MODEM:
1008                                 mDeathRecipients.get(service).linkToDeath(
1009                                         ((RadioModemProxy) serviceProxy).getAidl().asBinder());
1010                                 ((RadioModemProxy) serviceProxy).getAidl().setResponseFunctions(
1011                                         mModemResponse, mModemIndication);
1012                                 break;
1013                             case HAL_SERVICE_NETWORK:
1014                                 mDeathRecipients.get(service).linkToDeath(
1015                                         ((RadioNetworkProxy) serviceProxy).getAidl().asBinder());
1016                                 ((RadioNetworkProxy) serviceProxy).getAidl().setResponseFunctions(
1017                                         mNetworkResponse, mNetworkIndication);
1018                                 break;
1019                             case HAL_SERVICE_SIM:
1020                                 mDeathRecipients.get(service).linkToDeath(
1021                                         ((RadioSimProxy) serviceProxy).getAidl().asBinder());
1022                                 ((RadioSimProxy) serviceProxy).getAidl().setResponseFunctions(
1023                                         mSimResponse, mSimIndication);
1024                                 break;
1025                             case HAL_SERVICE_VOICE:
1026                                 mDeathRecipients.get(service).linkToDeath(
1027                                         ((RadioVoiceProxy) serviceProxy).getAidl().asBinder());
1028                                 ((RadioVoiceProxy) serviceProxy).getAidl().setResponseFunctions(
1029                                         mVoiceResponse, mVoiceIndication);
1030                                 break;
1031                             case HAL_SERVICE_IMS:
1032                                 mDeathRecipients.get(service).linkToDeath(
1033                                         ((RadioImsProxy) serviceProxy).getAidl().asBinder());
1034                                 ((RadioImsProxy) serviceProxy).getAidl().setResponseFunctions(
1035                                         mImsResponse, mImsIndication);
1036                                 break;
1037                         }
1038                     } else {
1039                         if (mHalVersion.get(service)
1040                                 .greaterOrEqual(RADIO_HAL_VERSION_2_0)) {
1041                             throw new AssertionError("serviceProxy shouldn't be HIDL with HAL 2.0");
1042                         }
1043                         if (!mIsRadioProxyInitialized) {
1044                             mIsRadioProxyInitialized = true;
1045                             serviceProxy.getHidl().linkToDeath(mRadioProxyDeathRecipient,
1046                                     mServiceCookies.get(HAL_SERVICE_RADIO).incrementAndGet());
1047                             serviceProxy.getHidl().setResponseFunctions(
1048                                     mRadioResponse, mRadioIndication);
1049                         }
1050                     }
1051                 } else {
1052                     mDisabledRadioServices.get(service).add(mPhoneId);
1053                     mHalVersion.put(service, RADIO_HAL_VERSION_UNKNOWN);
1054                     riljLoge("getRadioServiceProxy: set " + serviceToString(service) + " for "
1055                             + HIDL_SERVICE_NAME[mPhoneId] + " as disabled");
1056                 }
1057             }
1058         } catch (RemoteException e) {
1059             serviceProxy.clear();
1060             riljLoge("ServiceProxy getService/setResponseFunctions: " + e);
1061         }
1062 
1063         if (serviceProxy.isEmpty()) {
1064             // getService() is a blocking call, so this should never happen
1065             riljLoge("getRadioServiceProxy: serviceProxy == null");
1066             if (result != null) {
1067                 AsyncResult.forMessage(result, null,
1068                         CommandException.fromRilErrno(RADIO_NOT_AVAILABLE));
1069                 result.sendToTarget();
1070             }
1071         }
1072 
1073         return serviceProxy;
1074     }
1075 
1076     @Override
onSlotActiveStatusChange(boolean active)1077     public synchronized void onSlotActiveStatusChange(boolean active) {
1078         mIsRadioProxyInitialized = false;
1079         for (int service = MIN_SERVICE_IDX; service <= MAX_SERVICE_IDX; service++) {
1080             if (active) {
1081                 // Try to connect to RIL services and set response functions.
1082                 if (service == HAL_SERVICE_RADIO) {
1083                     getRadioProxy(null);
1084                 } else {
1085                     getRadioServiceProxy(service, null);
1086                 }
1087             } else {
1088                 resetProxyAndRequestList(service);
1089             }
1090         }
1091     }
1092 
1093     //***** Constructors
1094 
1095     @UnsupportedAppUsage
RIL(Context context, int allowedNetworkTypes, int cdmaSubscription)1096     public RIL(Context context, int allowedNetworkTypes, int cdmaSubscription) {
1097         this(context, allowedNetworkTypes, cdmaSubscription, null);
1098     }
1099 
1100     @UnsupportedAppUsage
RIL(Context context, int allowedNetworkTypes, int cdmaSubscription, Integer instanceId)1101     public RIL(Context context, int allowedNetworkTypes, int cdmaSubscription, Integer instanceId) {
1102         this(context, allowedNetworkTypes, cdmaSubscription, instanceId, null);
1103     }
1104 
1105     @VisibleForTesting
RIL(Context context, int allowedNetworkTypes, int cdmaSubscription, Integer instanceId, SparseArray<RadioServiceProxy> proxies)1106     public RIL(Context context, int allowedNetworkTypes, int cdmaSubscription, Integer instanceId,
1107             SparseArray<RadioServiceProxy> proxies) {
1108         super(context);
1109         if (RILJ_LOGD) {
1110             riljLog("RIL: init allowedNetworkTypes=" + allowedNetworkTypes
1111                     + " cdmaSubscription=" + cdmaSubscription + ")");
1112         }
1113 
1114         mContext = context;
1115         mCdmaSubscription  = cdmaSubscription;
1116         mAllowedNetworkTypesBitmask = allowedNetworkTypes;
1117         mPhoneType = RILConstants.NO_PHONE;
1118         mPhoneId = instanceId == null ? 0 : instanceId;
1119         if (isRadioBugDetectionEnabled()) {
1120             mRadioBugDetector = new RadioBugDetector(context, mPhoneId);
1121         }
1122         try {
1123             if (isRadioVersion2_0()) {
1124                 mHalVersion.put(HAL_SERVICE_RADIO, RADIO_HAL_VERSION_2_0);
1125             } else {
1126                 mHalVersion.put(HAL_SERVICE_RADIO, RADIO_HAL_VERSION_UNKNOWN);
1127             }
1128         } catch (SecurityException ex) {
1129             /* TODO(b/211920208): instead of the following workaround (guessing if we're in a test
1130              * based on proxies being populated), mock ServiceManager to not throw
1131              * SecurityException and return correct value based on what HAL we're testing. */
1132             if (proxies == null) throw ex;
1133         }
1134 
1135         TelephonyManager tm = (TelephonyManager) context.getSystemService(
1136                 Context.TELEPHONY_SERVICE);
1137         mIsCellularSupported = tm.isVoiceCapable() || tm.isSmsCapable() || tm.isDataCapable();
1138 
1139         mRadioResponse = new RadioResponse(this);
1140         mRadioIndication = new RadioIndication(this);
1141         mDataResponse = new DataResponse(this);
1142         mDataIndication = new DataIndication(this);
1143         mImsResponse = new ImsResponse(this);
1144         mImsIndication = new ImsIndication(this);
1145         mMessagingResponse = new MessagingResponse(this);
1146         mMessagingIndication = new MessagingIndication(this);
1147         mModemResponse = new ModemResponse(this);
1148         mModemIndication = new ModemIndication(this);
1149         mNetworkResponse = new NetworkResponse(this);
1150         mNetworkIndication = new NetworkIndication(this);
1151         mSimResponse = new SimResponse(this);
1152         mSimIndication = new SimIndication(this);
1153         mVoiceResponse = new VoiceResponse(this);
1154         mVoiceIndication = new VoiceIndication(this);
1155         mRilHandler = new RilHandler();
1156         mRadioProxyDeathRecipient = new RadioProxyDeathRecipient();
1157         for (int service = MIN_SERVICE_IDX; service <= MAX_SERVICE_IDX; service++) {
1158             if (service != HAL_SERVICE_RADIO) {
1159                 try {
1160                     if (isRadioServiceSupported(service)) {
1161                         mHalVersion.put(service, RADIO_HAL_VERSION_UNKNOWN);
1162                     } else {
1163                         mHalVersion.put(service, RADIO_HAL_VERSION_UNSUPPORTED);
1164                     }
1165                 } catch (SecurityException ex) {
1166                     /* TODO(b/211920208): instead of the following workaround (guessing if
1167                     * we're in a test based on proxies being populated), mock ServiceManager
1168                     * to not throw SecurityException and return correct value based on what
1169                     * HAL we're testing. */
1170                     if (proxies == null) throw ex;
1171                 }
1172                 mDeathRecipients.put(service, new BinderServiceDeathRecipient(service));
1173             }
1174             mDisabledRadioServices.put(service, new HashSet<>());
1175             mServiceCookies.put(service, new AtomicLong(0));
1176         }
1177         if (proxies == null) {
1178             mServiceProxies.put(HAL_SERVICE_DATA, new RadioDataProxy());
1179             mServiceProxies.put(HAL_SERVICE_MESSAGING, new RadioMessagingProxy());
1180             mServiceProxies.put(HAL_SERVICE_MODEM, new RadioModemProxy());
1181             mServiceProxies.put(HAL_SERVICE_NETWORK, new RadioNetworkProxy());
1182             mServiceProxies.put(HAL_SERVICE_SIM, new RadioSimProxy());
1183             mServiceProxies.put(HAL_SERVICE_VOICE, new RadioVoiceProxy());
1184             mServiceProxies.put(HAL_SERVICE_IMS, new RadioImsProxy());
1185         } else {
1186             mServiceProxies = proxies;
1187         }
1188 
1189         PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1190         mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, RILJ_WAKELOCK_TAG);
1191         mWakeLock.setReferenceCounted(false);
1192         mAckWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, RILJ_ACK_WAKELOCK_NAME);
1193         mAckWakeLock.setReferenceCounted(false);
1194         mWakeLockTimeout = TelephonyProperties.wake_lock_timeout()
1195                 .orElse(DEFAULT_WAKE_LOCK_TIMEOUT_MS);
1196         mAckWakeLockTimeout = TelephonyProperties.wake_lock_timeout()
1197                 .orElse(DEFAULT_ACK_WAKE_LOCK_TIMEOUT_MS);
1198         mWakeLockCount = 0;
1199         mRILDefaultWorkSource = new WorkSource(context.getApplicationInfo().uid,
1200                 context.getPackageName());
1201         mActiveWakelockWorkSource = new WorkSource();
1202 
1203         TelephonyDevController tdc = TelephonyDevController.getInstance();
1204         if (proxies == null) {
1205             // TelephonyDevController#registerRIL will call getHardwareConfig.
1206             // To prevent extra requests when running tests, only registerRIL when proxies is null
1207             tdc.registerRIL(this);
1208         }
1209 
1210         // Set radio callback; needed to set RadioIndication callback (should be done after
1211         // wakelock stuff is initialized above as callbacks are received on separate binder threads)
1212         for (int service = MIN_SERVICE_IDX; service <= MAX_SERVICE_IDX; service++) {
1213             if (service == HAL_SERVICE_RADIO) {
1214                 getRadioProxy(null);
1215             } else {
1216                 if (proxies == null) {
1217                     // Prevent telephony tests from calling the service
1218                     getRadioServiceProxy(service, null);
1219                 }
1220             }
1221 
1222             if (RILJ_LOGD) {
1223                 riljLog("HAL version of " + serviceToString(service)
1224                         + ": " + mHalVersion.get(service));
1225             }
1226         }
1227     }
1228 
isRadioVersion2_0()1229     private boolean isRadioVersion2_0() {
1230         for (int service = HAL_SERVICE_DATA; service <= MAX_SERVICE_IDX; service++) {
1231             if (isRadioServiceSupported(service)) {
1232                 return true;
1233             }
1234         }
1235         return false;
1236     }
1237 
isRadioServiceSupported(int service)1238     private boolean isRadioServiceSupported(int service) {
1239         String serviceName = "";
1240 
1241         if (service == HAL_SERVICE_RADIO) {
1242             return true;
1243         }
1244 
1245         switch (service) {
1246             case HAL_SERVICE_DATA:
1247                 serviceName = android.hardware.radio.data.IRadioData.DESCRIPTOR;
1248                 break;
1249             case HAL_SERVICE_MESSAGING:
1250                 serviceName = android.hardware.radio.messaging.IRadioMessaging.DESCRIPTOR;
1251                 break;
1252             case HAL_SERVICE_MODEM:
1253                 serviceName = android.hardware.radio.modem.IRadioModem.DESCRIPTOR;
1254                 break;
1255             case HAL_SERVICE_NETWORK:
1256                 serviceName = android.hardware.radio.network.IRadioNetwork.DESCRIPTOR;
1257                 break;
1258             case HAL_SERVICE_SIM:
1259                 serviceName = android.hardware.radio.sim.IRadioSim.DESCRIPTOR;
1260                 break;
1261             case HAL_SERVICE_VOICE:
1262                 serviceName = android.hardware.radio.voice.IRadioVoice.DESCRIPTOR;
1263                 break;
1264             case HAL_SERVICE_IMS:
1265                 serviceName = android.hardware.radio.ims.IRadioIms.DESCRIPTOR;
1266                 break;
1267         }
1268 
1269         if (!serviceName.equals("")
1270                 && ServiceManager.isDeclared(serviceName + '/' + HIDL_SERVICE_NAME[mPhoneId])) {
1271             return true;
1272         }
1273 
1274         return false;
1275     }
1276 
isRadioBugDetectionEnabled()1277     private boolean isRadioBugDetectionEnabled() {
1278         return Settings.Global.getInt(mContext.getContentResolver(),
1279                 Settings.Global.ENABLE_RADIO_BUG_DETECTION, 1) != 0;
1280     }
1281 
1282     @Override
setOnNITZTime(Handler h, int what, Object obj)1283     public void setOnNITZTime(Handler h, int what, Object obj) {
1284         super.setOnNITZTime(h, what, obj);
1285 
1286         // Send the last NITZ time if we have it
1287         if (mLastNITZTimeInfo != null) {
1288             mNITZTimeRegistrant.notifyRegistrant(new AsyncResult(null, mLastNITZTimeInfo, null));
1289         }
1290     }
1291 
addRequest(RILRequest rr)1292     private void addRequest(RILRequest rr) {
1293         acquireWakeLock(rr, FOR_WAKELOCK);
1294         Trace.asyncTraceForTrackBegin(
1295                 Trace.TRACE_TAG_NETWORK, "RIL", RILUtils.requestToString(rr.mRequest), rr.mSerial);
1296         synchronized (mRequestList) {
1297             rr.mStartTimeMs = SystemClock.elapsedRealtime();
1298             mRequestList.append(rr.mSerial, rr);
1299         }
1300     }
1301 
obtainRequest(int request, Message result, WorkSource workSource)1302     private RILRequest obtainRequest(int request, Message result, WorkSource workSource) {
1303         RILRequest rr = RILRequest.obtain(request, result, workSource);
1304         addRequest(rr);
1305         return rr;
1306     }
1307 
obtainRequest(int request, Message result, WorkSource workSource, Object... args)1308     private RILRequest obtainRequest(int request, Message result, WorkSource workSource,
1309             Object... args) {
1310         RILRequest rr = RILRequest.obtain(request, result, workSource, args);
1311         addRequest(rr);
1312         return rr;
1313     }
1314 
handleRadioProxyExceptionForRR(int service, String caller, Exception e)1315     private void handleRadioProxyExceptionForRR(int service, String caller, Exception e) {
1316         riljLoge(caller + ": " + e);
1317         e.printStackTrace();
1318         mIsRadioProxyInitialized = false;
1319         resetProxyAndRequestList(service);
1320     }
1321 
1322     @Override
getIccCardStatus(Message result)1323     public void getIccCardStatus(Message result) {
1324         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
1325         if (!simProxy.isEmpty()) {
1326             RILRequest rr = obtainRequest(RIL_REQUEST_GET_SIM_STATUS, result,
1327                     mRILDefaultWorkSource);
1328 
1329             if (RILJ_LOGD) {
1330                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1331             }
1332 
1333             try {
1334                 simProxy.getIccCardStatus(rr.mSerial);
1335             } catch (RemoteException | RuntimeException e) {
1336                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "getIccCardStatus", e);
1337             }
1338         }
1339     }
1340 
1341     @Override
getIccSlotsStatus(Message result)1342     public void getIccSlotsStatus(Message result) {
1343         if (RILJ_LOGD) Rlog.d(RILJ_LOG_TAG, "getIccSlotsStatus: REQUEST_NOT_SUPPORTED");
1344         if (result != null) {
1345             AsyncResult.forMessage(result, null,
1346                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
1347             result.sendToTarget();
1348         }
1349     }
1350 
1351     @Override
setLogicalToPhysicalSlotMapping(int[] physicalSlots, Message result)1352     public void setLogicalToPhysicalSlotMapping(int[] physicalSlots, Message result) {
1353         if (RILJ_LOGD) {
1354             Rlog.d(RILJ_LOG_TAG, "setLogicalToPhysicalSlotMapping: REQUEST_NOT_SUPPORTED");
1355         }
1356         if (result != null) {
1357             AsyncResult.forMessage(result, null,
1358                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
1359             result.sendToTarget();
1360         }
1361     }
1362 
1363     @Override
supplyIccPin(String pin, Message result)1364     public void supplyIccPin(String pin, Message result) {
1365         supplyIccPinForApp(pin, null, result);
1366     }
1367 
1368     @Override
supplyIccPinForApp(String pin, String aid, Message result)1369     public void supplyIccPinForApp(String pin, String aid, Message result) {
1370         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
1371         if (!simProxy.isEmpty()) {
1372             RILRequest rr = obtainRequest(RIL_REQUEST_ENTER_SIM_PIN, result, mRILDefaultWorkSource);
1373 
1374             if (RILJ_LOGD) {
1375                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1376                         + " aid = " + aid);
1377             }
1378 
1379             try {
1380                 simProxy.supplyIccPinForApp(rr.mSerial, RILUtils.convertNullToEmptyString(pin),
1381                         RILUtils.convertNullToEmptyString(aid));
1382             } catch (RemoteException | RuntimeException e) {
1383                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "supplyIccPinForApp", e);
1384             }
1385         }
1386     }
1387 
1388     @Override
supplyIccPuk(String puk, String newPin, Message result)1389     public void supplyIccPuk(String puk, String newPin, Message result) {
1390         supplyIccPukForApp(puk, newPin, null, result);
1391     }
1392 
1393     @Override
supplyIccPukForApp(String puk, String newPin, String aid, Message result)1394     public void supplyIccPukForApp(String puk, String newPin, String aid, Message result) {
1395         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
1396         if (!simProxy.isEmpty()) {
1397             RILRequest rr = obtainRequest(RIL_REQUEST_ENTER_SIM_PUK, result, mRILDefaultWorkSource);
1398 
1399             String pukStr = RILUtils.convertNullToEmptyString(puk);
1400             if (RILJ_LOGD) {
1401                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1402                         + " isPukEmpty = " + pukStr.isEmpty() + " aid = " + aid);
1403             }
1404 
1405             try {
1406                 simProxy.supplyIccPukForApp(rr.mSerial, pukStr,
1407                         RILUtils.convertNullToEmptyString(newPin),
1408                         RILUtils.convertNullToEmptyString(aid));
1409             } catch (RemoteException | RuntimeException e) {
1410                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "supplyIccPukForApp", e);
1411             }
1412         }
1413     }
1414 
1415     @Override
supplyIccPin2(String pin, Message result)1416     public void supplyIccPin2(String pin, Message result) {
1417         supplyIccPin2ForApp(pin, null, result);
1418     }
1419 
1420     @Override
supplyIccPin2ForApp(String pin, String aid, Message result)1421     public void supplyIccPin2ForApp(String pin, String aid, Message result) {
1422         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
1423         if (!simProxy.isEmpty()) {
1424             RILRequest rr = obtainRequest(RIL_REQUEST_ENTER_SIM_PIN2, result,
1425                     mRILDefaultWorkSource);
1426 
1427             if (RILJ_LOGD) {
1428                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1429                         + " aid = " + aid);
1430             }
1431 
1432             try {
1433                 simProxy.supplyIccPin2ForApp(rr.mSerial, RILUtils.convertNullToEmptyString(pin),
1434                         RILUtils.convertNullToEmptyString(aid));
1435             } catch (RemoteException | RuntimeException e) {
1436                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "supplyIccPin2ForApp", e);
1437             }
1438         }
1439     }
1440 
1441     @Override
supplyIccPuk2(String puk2, String newPin2, Message result)1442     public void supplyIccPuk2(String puk2, String newPin2, Message result) {
1443         supplyIccPuk2ForApp(puk2, newPin2, null, result);
1444     }
1445 
1446     @Override
supplyIccPuk2ForApp(String puk, String newPin2, String aid, Message result)1447     public void supplyIccPuk2ForApp(String puk, String newPin2, String aid, Message result) {
1448         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
1449         if (!simProxy.isEmpty()) {
1450             RILRequest rr = obtainRequest(RIL_REQUEST_ENTER_SIM_PUK2, result,
1451                     mRILDefaultWorkSource);
1452 
1453             if (RILJ_LOGD) {
1454                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1455                         + " aid = " + aid);
1456             }
1457 
1458             try {
1459                 simProxy.supplyIccPuk2ForApp(rr.mSerial, RILUtils.convertNullToEmptyString(puk),
1460                         RILUtils.convertNullToEmptyString(newPin2),
1461                         RILUtils.convertNullToEmptyString(aid));
1462             } catch (RemoteException | RuntimeException e) {
1463                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "supplyIccPuk2ForApp", e);
1464             }
1465         }
1466     }
1467 
1468     @Override
changeIccPin(String oldPin, String newPin, Message result)1469     public void changeIccPin(String oldPin, String newPin, Message result) {
1470         changeIccPinForApp(oldPin, newPin, null, result);
1471     }
1472 
1473     @Override
changeIccPinForApp(String oldPin, String newPin, String aid, Message result)1474     public void changeIccPinForApp(String oldPin, String newPin, String aid, Message result) {
1475         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
1476         if (!simProxy.isEmpty()) {
1477             RILRequest rr = obtainRequest(RIL_REQUEST_CHANGE_SIM_PIN, result,
1478                     mRILDefaultWorkSource);
1479 
1480             if (RILJ_LOGD) {
1481                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1482                         + " oldPin = " + oldPin + " newPin = " + newPin + " aid = " + aid);
1483             }
1484 
1485             try {
1486                 simProxy.changeIccPinForApp(rr.mSerial,
1487                         RILUtils.convertNullToEmptyString(oldPin),
1488                         RILUtils.convertNullToEmptyString(newPin),
1489                         RILUtils.convertNullToEmptyString(aid));
1490             } catch (RemoteException | RuntimeException e) {
1491                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "changeIccPinForApp", e);
1492             }
1493         }
1494     }
1495 
1496     @Override
changeIccPin2(String oldPin2, String newPin2, Message result)1497     public void changeIccPin2(String oldPin2, String newPin2, Message result) {
1498         changeIccPin2ForApp(oldPin2, newPin2, null, result);
1499     }
1500 
1501     @Override
changeIccPin2ForApp(String oldPin2, String newPin2, String aid, Message result)1502     public void changeIccPin2ForApp(String oldPin2, String newPin2, String aid, Message result) {
1503         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
1504         if (!simProxy.isEmpty()) {
1505             RILRequest rr = obtainRequest(RIL_REQUEST_CHANGE_SIM_PIN2, result,
1506                     mRILDefaultWorkSource);
1507 
1508             if (RILJ_LOGD) {
1509                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1510                         + " oldPin = " + oldPin2 + " newPin = " + newPin2 + " aid = " + aid);
1511             }
1512 
1513             try {
1514                 simProxy.changeIccPin2ForApp(rr.mSerial,
1515                         RILUtils.convertNullToEmptyString(oldPin2),
1516                         RILUtils.convertNullToEmptyString(newPin2),
1517                         RILUtils.convertNullToEmptyString(aid));
1518             } catch (RemoteException | RuntimeException e) {
1519                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "changeIccPin2ForApp", e);
1520             }
1521         }
1522     }
1523 
1524     @Override
supplyNetworkDepersonalization(String netpin, Message result)1525     public void supplyNetworkDepersonalization(String netpin, Message result) {
1526         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
1527         if (!networkProxy.isEmpty()) {
1528             RILRequest rr = obtainRequest(RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION, result,
1529                     mRILDefaultWorkSource);
1530 
1531             if (RILJ_LOGD) {
1532                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1533                         + " netpin = " + netpin);
1534             }
1535 
1536             try {
1537                 networkProxy.supplyNetworkDepersonalization(rr.mSerial,
1538                         RILUtils.convertNullToEmptyString(netpin));
1539             } catch (RemoteException | RuntimeException e) {
1540                 handleRadioProxyExceptionForRR(
1541                         HAL_SERVICE_NETWORK, "supplyNetworkDepersonalization", e);
1542             }
1543         }
1544     }
1545 
1546     @Override
supplySimDepersonalization(PersoSubState persoType, String controlKey, Message result)1547     public void supplySimDepersonalization(PersoSubState persoType, String controlKey,
1548             Message result) {
1549         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
1550         if (simProxy.isEmpty()) return;
1551         if (mHalVersion.get(HAL_SERVICE_SIM).greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
1552             RILRequest rr = obtainRequest(RIL_REQUEST_ENTER_SIM_DEPERSONALIZATION, result,
1553                     mRILDefaultWorkSource);
1554 
1555             if (RILJ_LOGD) {
1556                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1557                         + " controlKey = " + controlKey + " persoType" + persoType);
1558             }
1559 
1560             try {
1561                 simProxy.supplySimDepersonalization(rr.mSerial, persoType,
1562                         RILUtils.convertNullToEmptyString(controlKey));
1563             } catch (RemoteException | RuntimeException e) {
1564                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "supplySimDepersonalization", e);
1565             }
1566         } else {
1567             if (PersoSubState.PERSOSUBSTATE_SIM_NETWORK == persoType) {
1568                 supplyNetworkDepersonalization(controlKey, result);
1569                 return;
1570             }
1571             if (RILJ_LOGD) {
1572                 Rlog.d(RILJ_LOG_TAG, "supplySimDepersonalization: REQUEST_NOT_SUPPORTED");
1573             }
1574             if (result != null) {
1575                 AsyncResult.forMessage(result, null,
1576                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
1577                 result.sendToTarget();
1578             }
1579         }
1580     }
1581 
1582     @Override
getCurrentCalls(Message result)1583     public void getCurrentCalls(Message result) {
1584         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
1585         if (!voiceProxy.isEmpty()) {
1586             RILRequest rr = obtainRequest(RIL_REQUEST_GET_CURRENT_CALLS, result,
1587                     mRILDefaultWorkSource);
1588 
1589             if (RILJ_LOGD) {
1590                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1591             }
1592 
1593             try {
1594                 voiceProxy.getCurrentCalls(rr.mSerial);
1595             } catch (RemoteException | RuntimeException e) {
1596                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "getCurrentCalls", e);
1597             }
1598         }
1599     }
1600 
1601     @Override
dial(String address, boolean isEmergencyCall, EmergencyNumber emergencyNumberInfo, boolean hasKnownUserIntentEmergency, int clirMode, Message result)1602     public void dial(String address, boolean isEmergencyCall, EmergencyNumber emergencyNumberInfo,
1603             boolean hasKnownUserIntentEmergency, int clirMode, Message result) {
1604         dial(address, isEmergencyCall, emergencyNumberInfo, hasKnownUserIntentEmergency,
1605                 clirMode, null, result);
1606     }
1607 
1608     @Override
enableModem(boolean enable, Message result)1609     public void enableModem(boolean enable, Message result) {
1610         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class, result);
1611         if (modemProxy.isEmpty()) return;
1612         if (mHalVersion.get(HAL_SERVICE_MODEM).greaterOrEqual(RADIO_HAL_VERSION_1_3)) {
1613             RILRequest rr = obtainRequest(RIL_REQUEST_ENABLE_MODEM, result, mRILDefaultWorkSource);
1614 
1615             if (RILJ_LOGD) {
1616                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1617                         + " enable = " + enable);
1618             }
1619 
1620             try {
1621                 modemProxy.enableModem(rr.mSerial, enable);
1622             } catch (RemoteException | RuntimeException e) {
1623                 handleRadioProxyExceptionForRR(HAL_SERVICE_MODEM,
1624                         "enableModem", e);
1625             }
1626         } else {
1627             if (RILJ_LOGV) riljLog("enableModem: not supported.");
1628             if (result != null) {
1629                 AsyncResult.forMessage(result, null,
1630                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
1631                 result.sendToTarget();
1632             }
1633         }
1634     }
1635 
1636     @Override
setSystemSelectionChannels(@onNull List<RadioAccessSpecifier> specifiers, Message result)1637     public void setSystemSelectionChannels(@NonNull List<RadioAccessSpecifier> specifiers,
1638             Message result) {
1639         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
1640         if (networkProxy.isEmpty()) return;
1641         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_1_3)) {
1642             RILRequest rr = obtainRequest(RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS, result,
1643                     mRILDefaultWorkSource);
1644 
1645             if (RILJ_LOGD) {
1646                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1647                         + " setSystemSelectionChannels_1.3= " + specifiers);
1648             }
1649 
1650             try {
1651                 networkProxy.setSystemSelectionChannels(rr.mSerial, specifiers);
1652             } catch (RemoteException | RuntimeException e) {
1653                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK,
1654                         "setSystemSelectionChannels", e);
1655             }
1656         } else {
1657             if (RILJ_LOGV) riljLog("setSystemSelectionChannels: not supported.");
1658             if (result != null) {
1659                 AsyncResult.forMessage(result, null,
1660                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
1661                 result.sendToTarget();
1662             }
1663         }
1664     }
1665 
1666     @Override
getSystemSelectionChannels(Message result)1667     public void getSystemSelectionChannels(Message result) {
1668         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
1669         if (networkProxy.isEmpty()) return;
1670         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
1671             RILRequest rr = obtainRequest(RIL_REQUEST_GET_SYSTEM_SELECTION_CHANNELS, result,
1672                     mRILDefaultWorkSource);
1673 
1674             if (RILJ_LOGD) {
1675                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1676                         + " getSystemSelectionChannels");
1677             }
1678 
1679             try {
1680                 networkProxy.getSystemSelectionChannels(rr.mSerial);
1681             } catch (RemoteException | RuntimeException e) {
1682                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK,
1683                         "getSystemSelectionChannels", e);
1684             }
1685         } else {
1686             if (RILJ_LOGV) riljLog("getSystemSelectionChannels: not supported.");
1687             if (result != null) {
1688                 AsyncResult.forMessage(result, null,
1689                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
1690                 result.sendToTarget();
1691             }
1692         }
1693     }
1694 
1695     @Override
getModemStatus(Message result)1696     public void getModemStatus(Message result) {
1697         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class, result);
1698         if (modemProxy.isEmpty()) return;
1699         if (mHalVersion.get(HAL_SERVICE_MODEM).greaterOrEqual(RADIO_HAL_VERSION_1_3)) {
1700             RILRequest rr = obtainRequest(RIL_REQUEST_GET_MODEM_STATUS, result,
1701                     mRILDefaultWorkSource);
1702 
1703             if (RILJ_LOGD) {
1704                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1705             }
1706 
1707             try {
1708                 modemProxy.getModemStackStatus(rr.mSerial);
1709             } catch (RemoteException | RuntimeException e) {
1710                 handleRadioProxyExceptionForRR(HAL_SERVICE_MODEM, "getModemStatus", e);
1711             }
1712         } else {
1713             if (RILJ_LOGV) riljLog("getModemStatus: not supported.");
1714             if (result != null) {
1715                 AsyncResult.forMessage(result, null,
1716                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
1717                 result.sendToTarget();
1718             }
1719         }
1720     }
1721 
1722     @Override
dial(String address, boolean isEmergencyCall, EmergencyNumber emergencyNumberInfo, boolean hasKnownUserIntentEmergency, int clirMode, UUSInfo uusInfo, Message result)1723     public void dial(String address, boolean isEmergencyCall, EmergencyNumber emergencyNumberInfo,
1724             boolean hasKnownUserIntentEmergency, int clirMode, UUSInfo uusInfo, Message result) {
1725         if (isEmergencyCall
1726                 && mHalVersion.get(HAL_SERVICE_VOICE).greaterOrEqual(RADIO_HAL_VERSION_1_4)
1727                 && emergencyNumberInfo != null) {
1728             emergencyDial(address, emergencyNumberInfo, hasKnownUserIntentEmergency, clirMode,
1729                     uusInfo, result);
1730             return;
1731         }
1732         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
1733         if (!voiceProxy.isEmpty()) {
1734             RILRequest rr = obtainRequest(RIL_REQUEST_DIAL, result, mRILDefaultWorkSource);
1735 
1736             if (RILJ_LOGD) {
1737                 // Do not log function arg for privacy
1738                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1739             }
1740 
1741             try {
1742                 voiceProxy.dial(rr.mSerial, address, clirMode, uusInfo);
1743             } catch (RemoteException | RuntimeException e) {
1744                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "dial", e);
1745             }
1746         }
1747     }
1748 
emergencyDial(String address, EmergencyNumber emergencyNumberInfo, boolean hasKnownUserIntentEmergency, int clirMode, UUSInfo uusInfo, Message result)1749     private void emergencyDial(String address, EmergencyNumber emergencyNumberInfo,
1750             boolean hasKnownUserIntentEmergency, int clirMode, UUSInfo uusInfo, Message result) {
1751         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
1752         if (voiceProxy.isEmpty()) return;
1753         if (mHalVersion.get(HAL_SERVICE_VOICE).greaterOrEqual(RADIO_HAL_VERSION_1_4)) {
1754             RILRequest rr = obtainRequest(RIL_REQUEST_EMERGENCY_DIAL, result,
1755                     mRILDefaultWorkSource);
1756 
1757             if (RILJ_LOGD) {
1758                 // Do not log function arg for privacy
1759                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1760             }
1761 
1762             try {
1763                 voiceProxy.emergencyDial(rr.mSerial, RILUtils.convertNullToEmptyString(address),
1764                         emergencyNumberInfo, hasKnownUserIntentEmergency, clirMode, uusInfo);
1765             } catch (RemoteException | RuntimeException e) {
1766                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "emergencyDial", e);
1767             }
1768         } else {
1769             riljLoge("emergencyDial is not supported with 1.4 below IRadio");
1770         }
1771     }
1772 
1773     @Override
getIMSI(Message result)1774     public void getIMSI(Message result) {
1775         getIMSIForApp(null, result);
1776     }
1777 
1778     @Override
getIMSIForApp(String aid, Message result)1779     public void getIMSIForApp(String aid, Message result) {
1780         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
1781         if (!simProxy.isEmpty()) {
1782             RILRequest rr = obtainRequest(RIL_REQUEST_GET_IMSI, result, mRILDefaultWorkSource);
1783 
1784             if (RILJ_LOGD) {
1785                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1786                         + " aid = " + aid);
1787             }
1788             try {
1789                 simProxy.getImsiForApp(rr.mSerial, RILUtils.convertNullToEmptyString(aid));
1790             } catch (RemoteException | RuntimeException e) {
1791                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "getImsiForApp", e);
1792             }
1793         }
1794     }
1795 
1796     @Override
hangupConnection(int gsmIndex, Message result)1797     public void hangupConnection(int gsmIndex, Message result) {
1798         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
1799         if (!voiceProxy.isEmpty()) {
1800             RILRequest rr = obtainRequest(RIL_REQUEST_HANGUP, result, mRILDefaultWorkSource);
1801 
1802             if (RILJ_LOGD) {
1803                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1804                         + " gsmIndex = " + gsmIndex);
1805             }
1806 
1807             try {
1808                 voiceProxy.hangup(rr.mSerial, gsmIndex);
1809             } catch (RemoteException | RuntimeException e) {
1810                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "hangup", e);
1811             }
1812         }
1813     }
1814 
1815     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
1816     @Override
hangupWaitingOrBackground(Message result)1817     public void hangupWaitingOrBackground(Message result) {
1818         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
1819         if (!voiceProxy.isEmpty()) {
1820             RILRequest rr = obtainRequest(RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND, result,
1821                     mRILDefaultWorkSource);
1822 
1823             if (RILJ_LOGD) {
1824                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1825             }
1826 
1827             try {
1828                 voiceProxy.hangupWaitingOrBackground(rr.mSerial);
1829             } catch (RemoteException | RuntimeException e) {
1830                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "hangupWaitingOrBackground", e);
1831             }
1832         }
1833     }
1834 
1835     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
1836     @Override
hangupForegroundResumeBackground(Message result)1837     public void hangupForegroundResumeBackground(Message result) {
1838         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
1839         if (!voiceProxy.isEmpty()) {
1840             RILRequest rr = obtainRequest(RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND, result,
1841                     mRILDefaultWorkSource);
1842 
1843             if (RILJ_LOGD) {
1844                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1845             }
1846 
1847             try {
1848                 voiceProxy.hangupForegroundResumeBackground(rr.mSerial);
1849             } catch (RemoteException | RuntimeException e) {
1850                 handleRadioProxyExceptionForRR(
1851                         HAL_SERVICE_VOICE, "hangupForegroundResumeBackground", e);
1852             }
1853         }
1854     }
1855 
1856     @Override
switchWaitingOrHoldingAndActive(Message result)1857     public void switchWaitingOrHoldingAndActive(Message result) {
1858         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
1859         if (!voiceProxy.isEmpty()) {
1860             RILRequest rr = obtainRequest(RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE, result,
1861                     mRILDefaultWorkSource);
1862 
1863             if (RILJ_LOGD) {
1864                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1865             }
1866 
1867             try {
1868                 voiceProxy.switchWaitingOrHoldingAndActive(rr.mSerial);
1869             } catch (RemoteException | RuntimeException e) {
1870                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE,
1871                         "switchWaitingOrHoldingAndActive", e);
1872             }
1873         }
1874     }
1875 
1876     @Override
conference(Message result)1877     public void conference(Message result) {
1878         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
1879         if (!voiceProxy.isEmpty()) {
1880             RILRequest rr = obtainRequest(RIL_REQUEST_CONFERENCE, result, mRILDefaultWorkSource);
1881 
1882             if (RILJ_LOGD) {
1883                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1884             }
1885 
1886             try {
1887                 voiceProxy.conference(rr.mSerial);
1888             } catch (RemoteException | RuntimeException e) {
1889                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "conference", e);
1890             }
1891         }
1892     }
1893 
1894     @Override
rejectCall(Message result)1895     public void rejectCall(Message result) {
1896         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
1897         if (!voiceProxy.isEmpty()) {
1898             RILRequest rr = obtainRequest(RIL_REQUEST_UDUB, result, mRILDefaultWorkSource);
1899 
1900             if (RILJ_LOGD) {
1901                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1902             }
1903 
1904             try {
1905                 voiceProxy.rejectCall(rr.mSerial);
1906             } catch (RemoteException | RuntimeException e) {
1907                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "rejectCall", e);
1908             }
1909         }
1910     }
1911 
1912     @Override
getLastCallFailCause(Message result)1913     public void getLastCallFailCause(Message result) {
1914         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
1915         if (!voiceProxy.isEmpty()) {
1916             RILRequest rr = obtainRequest(RIL_REQUEST_LAST_CALL_FAIL_CAUSE, result,
1917                     mRILDefaultWorkSource);
1918 
1919             if (RILJ_LOGD) {
1920                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1921             }
1922 
1923             try {
1924                 voiceProxy.getLastCallFailCause(rr.mSerial);
1925             } catch (RemoteException | RuntimeException e) {
1926                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "getLastCallFailCause", e);
1927             }
1928         }
1929     }
1930 
1931     @Override
getSignalStrength(Message result)1932     public void getSignalStrength(Message result) {
1933         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
1934         if (!networkProxy.isEmpty()) {
1935             RILRequest rr = obtainRequest(RIL_REQUEST_SIGNAL_STRENGTH, result,
1936                     mRILDefaultWorkSource);
1937 
1938             if (RILJ_LOGD) {
1939                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1940             }
1941 
1942             try {
1943                 networkProxy.getSignalStrength(rr.mSerial);
1944             } catch (RemoteException | RuntimeException e) {
1945                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "getSignalStrength", e);
1946             }
1947         }
1948     }
1949 
1950     @Override
getVoiceRegistrationState(Message result)1951     public void getVoiceRegistrationState(Message result) {
1952         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
1953         if (!networkProxy.isEmpty()) {
1954             RILRequest rr = obtainRequest(RIL_REQUEST_VOICE_REGISTRATION_STATE, result,
1955                     mRILDefaultWorkSource);
1956 
1957             if (RILJ_LOGD) {
1958                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1959             }
1960 
1961             HalVersion overrideHalVersion = getCompatVersion(RIL_REQUEST_VOICE_REGISTRATION_STATE);
1962             if (RILJ_LOGD) {
1963                 riljLog("getVoiceRegistrationState: overrideHalVersion=" + overrideHalVersion);
1964             }
1965 
1966             try {
1967                 networkProxy.getVoiceRegistrationState(rr.mSerial, overrideHalVersion);
1968             } catch (RemoteException | RuntimeException e) {
1969                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "getVoiceRegistrationState", e);
1970             }
1971         }
1972     }
1973 
1974     @Override
getDataRegistrationState(Message result)1975     public void getDataRegistrationState(Message result) {
1976         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
1977         if (!networkProxy.isEmpty()) {
1978             RILRequest rr = obtainRequest(RIL_REQUEST_DATA_REGISTRATION_STATE, result,
1979                     mRILDefaultWorkSource);
1980 
1981             if (RILJ_LOGD) {
1982                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1983             }
1984 
1985             HalVersion overrideHalVersion = getCompatVersion(RIL_REQUEST_DATA_REGISTRATION_STATE);
1986             if (RILJ_LOGD) {
1987                 riljLog("getDataRegistrationState: overrideHalVersion=" + overrideHalVersion);
1988             }
1989 
1990             try {
1991                 networkProxy.getDataRegistrationState(rr.mSerial, overrideHalVersion);
1992             } catch (RemoteException | RuntimeException e) {
1993                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "getDataRegistrationState", e);
1994             }
1995         }
1996     }
1997 
1998     @Override
getOperator(Message result)1999     public void getOperator(Message result) {
2000         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
2001         if (!networkProxy.isEmpty()) {
2002             RILRequest rr = obtainRequest(RIL_REQUEST_OPERATOR, result, mRILDefaultWorkSource);
2003 
2004             if (RILJ_LOGD) {
2005                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2006             }
2007 
2008             try {
2009                 networkProxy.getOperator(rr.mSerial);
2010             } catch (RemoteException | RuntimeException e) {
2011                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "getOperator", e);
2012             }
2013         }
2014     }
2015 
2016     @UnsupportedAppUsage
2017     @Override
setRadioPower(boolean on, boolean forEmergencyCall, boolean preferredForEmergencyCall, Message result)2018     public void setRadioPower(boolean on, boolean forEmergencyCall,
2019             boolean preferredForEmergencyCall, Message result) {
2020         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class, result);
2021         if (!modemProxy.isEmpty()) {
2022             RILRequest rr = obtainRequest(RIL_REQUEST_RADIO_POWER, result, mRILDefaultWorkSource);
2023 
2024             if (RILJ_LOGD) {
2025                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2026                         + " on = " + on + " forEmergencyCall= " + forEmergencyCall
2027                         + " preferredForEmergencyCall="  + preferredForEmergencyCall);
2028             }
2029 
2030             try {
2031                 modemProxy.setRadioPower(rr.mSerial, on, forEmergencyCall,
2032                         preferredForEmergencyCall);
2033             } catch (RemoteException | RuntimeException e) {
2034                 handleRadioProxyExceptionForRR(HAL_SERVICE_MODEM, "setRadioPower", e);
2035             }
2036         }
2037     }
2038 
2039     @Override
sendDtmf(char c, Message result)2040     public void sendDtmf(char c, Message result) {
2041         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
2042         if (!voiceProxy.isEmpty()) {
2043             RILRequest rr = obtainRequest(RIL_REQUEST_DTMF, result, mRILDefaultWorkSource);
2044 
2045             if (RILJ_LOGD) {
2046                 // Do not log function arg for privacy
2047                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2048             }
2049 
2050             try {
2051                 voiceProxy.sendDtmf(rr.mSerial, c + "");
2052             } catch (RemoteException | RuntimeException e) {
2053                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "sendDtmf", e);
2054             }
2055         }
2056     }
2057 
2058     @Override
sendSMS(String smscPdu, String pdu, Message result)2059     public void sendSMS(String smscPdu, String pdu, Message result) {
2060         RadioMessagingProxy messagingProxy =
2061                 getRadioServiceProxy(RadioMessagingProxy.class, result);
2062         if (!messagingProxy.isEmpty()) {
2063             RILRequest rr = obtainRequest(RIL_REQUEST_SEND_SMS, result, mRILDefaultWorkSource);
2064 
2065             // Do not log function args for privacy
2066             if (RILJ_LOGD) {
2067                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2068             }
2069 
2070             try {
2071                 messagingProxy.sendSms(rr.mSerial, smscPdu, pdu);
2072                 mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_GSM,
2073                         SmsSession.Event.Format.SMS_FORMAT_3GPP, getOutgoingSmsMessageId(result));
2074             } catch (RemoteException | RuntimeException e) {
2075                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING, "sendSMS", e);
2076             }
2077         }
2078     }
2079 
2080     /**
2081      * Extract the outgoing sms messageId from the tracker, if there is one. This is specifically
2082      * for SMS related APIs.
2083      * @param result the result Message
2084      * @return messageId unique identifier or 0 if there is no message id
2085      */
getOutgoingSmsMessageId(Message result)2086     public static long getOutgoingSmsMessageId(Message result) {
2087         if (result == null || !(result.obj instanceof SMSDispatcher.SmsTracker)) {
2088             return 0L;
2089         }
2090         long messageId = ((SMSDispatcher.SmsTracker) result.obj).mMessageId;
2091         if (RILJ_LOGV) {
2092             Rlog.d(RILJ_LOG_TAG, "getOutgoingSmsMessageId "
2093                     + SmsController.formatCrossStackMessageId(messageId));
2094         }
2095         return messageId;
2096     }
2097 
2098     @Override
sendSMSExpectMore(String smscPdu, String pdu, Message result)2099     public void sendSMSExpectMore(String smscPdu, String pdu, Message result) {
2100         RadioMessagingProxy messagingProxy =
2101                 getRadioServiceProxy(RadioMessagingProxy.class, result);
2102         if (!messagingProxy.isEmpty()) {
2103             RILRequest rr = obtainRequest(RIL_REQUEST_SEND_SMS_EXPECT_MORE, result,
2104                     mRILDefaultWorkSource);
2105 
2106             // Do not log function arg for privacy
2107             if (RILJ_LOGD) {
2108                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2109             }
2110 
2111             try {
2112                 messagingProxy.sendSmsExpectMore(rr.mSerial, smscPdu, pdu);
2113                 mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_GSM,
2114                         SmsSession.Event.Format.SMS_FORMAT_3GPP, getOutgoingSmsMessageId(result));
2115             } catch (RemoteException | RuntimeException e) {
2116                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING, "sendSMSExpectMore", e);
2117             }
2118         }
2119     }
2120 
2121     @Override
setupDataCall(int accessNetworkType, DataProfile dataProfile, boolean isRoaming, boolean allowRoaming, int reason, LinkProperties linkProperties, int pduSessionId, NetworkSliceInfo sliceInfo, TrafficDescriptor trafficDescriptor, boolean matchAllRuleAllowed, Message result)2122     public void setupDataCall(int accessNetworkType, DataProfile dataProfile, boolean isRoaming,
2123             boolean allowRoaming, int reason, LinkProperties linkProperties, int pduSessionId,
2124             NetworkSliceInfo sliceInfo, TrafficDescriptor trafficDescriptor,
2125             boolean matchAllRuleAllowed, Message result) {
2126         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class, result);
2127         if (!dataProxy.isEmpty()) {
2128             RILRequest rr = obtainRequest(RIL_REQUEST_SETUP_DATA_CALL, result,
2129                     mRILDefaultWorkSource);
2130 
2131             if (RILJ_LOGD) {
2132                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2133                         + ",reason=" + RILUtils.setupDataReasonToString(reason)
2134                         + ",accessNetworkType=" + AccessNetworkType.toString(accessNetworkType)
2135                         + ",dataProfile=" + dataProfile + ",isRoaming=" + isRoaming
2136                         + ",allowRoaming=" + allowRoaming
2137                         + ",linkProperties=" + linkProperties + ",pduSessionId=" + pduSessionId
2138                         + ",sliceInfo=" + sliceInfo + ",trafficDescriptor=" + trafficDescriptor
2139                         + ",matchAllRuleAllowed=" + matchAllRuleAllowed);
2140             }
2141 
2142             try {
2143                 dataProxy.setupDataCall(rr.mSerial, mPhoneId, accessNetworkType, dataProfile,
2144                         isRoaming, allowRoaming, reason, linkProperties, pduSessionId, sliceInfo,
2145                         trafficDescriptor, matchAllRuleAllowed);
2146             } catch (RemoteException e) {
2147                 handleRadioProxyExceptionForRR(HAL_SERVICE_DATA, "setupDataCall", e);
2148             } catch (RuntimeException e) {
2149                 riljLoge("setupDataCall RuntimeException: " + e);
2150                 int error = RadioError.SYSTEM_ERR;
2151                 int responseType = RadioResponseType.SOLICITED;
2152                 processResponseInternal(HAL_SERVICE_DATA, rr.mSerial, error, responseType);
2153                 processResponseDoneInternal(rr, error, responseType, null);
2154             }
2155         } else {
2156             riljLoge("setupDataCall: DataProxy is empty");
2157             if (result != null) {
2158                 AsyncResult.forMessage(result, null,
2159                         CommandException.fromRilErrno(RADIO_NOT_AVAILABLE));
2160                 result.sendToTarget();
2161             }
2162         }
2163     }
2164 
2165     @Override
iccIO(int command, int fileId, String path, int p1, int p2, int p3, String data, String pin2, Message result)2166     public void iccIO(int command, int fileId, String path, int p1, int p2, int p3, String data,
2167             String pin2, Message result) {
2168         iccIOForApp(command, fileId, path, p1, p2, p3, data, pin2, null, result);
2169     }
2170 
2171     @Override
iccIOForApp(int command, int fileId, String path, int p1, int p2, int p3, String data, String pin2, String aid, Message result)2172     public void iccIOForApp(int command, int fileId, String path, int p1, int p2, int p3,
2173             String data, String pin2, String aid, Message result) {
2174         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
2175         if (!simProxy.isEmpty()) {
2176             RILRequest rr = obtainRequest(RIL_REQUEST_SIM_IO, result, mRILDefaultWorkSource);
2177 
2178             if (RILJ_LOGD) {
2179                 if (TelephonyUtils.IS_DEBUGGABLE) {
2180                     riljLog(rr.serialString() + "> iccIO: " + RILUtils.requestToString(rr.mRequest)
2181                             + " command = 0x" + Integer.toHexString(command) + " fileId = 0x"
2182                             + Integer.toHexString(fileId) + " path = " + path + " p1 = " + p1
2183                             + " p2 = " + p2 + " p3 = " + " data = " + data + " aid = " + aid);
2184                 } else {
2185                     riljLog(rr.serialString() + "> iccIO: "
2186                             + RILUtils.requestToString(rr.mRequest));
2187                 }
2188             }
2189 
2190             try {
2191                 simProxy.iccIoForApp(rr.mSerial, command, fileId,
2192                         RILUtils.convertNullToEmptyString(path), p1, p2, p3,
2193                         RILUtils.convertNullToEmptyString(data),
2194                         RILUtils.convertNullToEmptyString(pin2),
2195                         RILUtils.convertNullToEmptyString(aid));
2196             } catch (RemoteException | RuntimeException e) {
2197                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "iccIoForApp", e);
2198             }
2199         }
2200     }
2201 
2202     @Override
sendUSSD(String ussd, Message result)2203     public void sendUSSD(String ussd, Message result) {
2204         RadioVoiceProxy voiceProxy =
2205                 getRadioServiceProxy(RadioVoiceProxy.class, result);
2206         if (!voiceProxy.isEmpty()) {
2207             RILRequest rr = obtainRequest(RIL_REQUEST_SEND_USSD, result, mRILDefaultWorkSource);
2208 
2209             if (RILJ_LOGD) {
2210                 String logUssd = "*******";
2211                 if (RILJ_LOGV) logUssd = ussd;
2212                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2213                         + " ussd = " + logUssd);
2214             }
2215 
2216             try {
2217                 voiceProxy.sendUssd(rr.mSerial, RILUtils.convertNullToEmptyString(ussd));
2218             } catch (RemoteException | RuntimeException e) {
2219                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "sendUssd", e);
2220             }
2221         }
2222     }
2223 
2224     @Override
cancelPendingUssd(Message result)2225     public void cancelPendingUssd(Message result) {
2226         RadioVoiceProxy voiceProxy =
2227                 getRadioServiceProxy(RadioVoiceProxy.class, result);
2228         if (!voiceProxy.isEmpty()) {
2229             RILRequest rr = obtainRequest(RIL_REQUEST_CANCEL_USSD, result, mRILDefaultWorkSource);
2230 
2231             if (RILJ_LOGD) {
2232                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2233             }
2234 
2235             try {
2236                 voiceProxy.cancelPendingUssd(rr.mSerial);
2237             } catch (RemoteException | RuntimeException e) {
2238                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "cancelPendingUssd", e);
2239             }
2240         }
2241     }
2242 
2243     @Override
getCLIR(Message result)2244     public void getCLIR(Message result) {
2245         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
2246         if (!voiceProxy.isEmpty()) {
2247             RILRequest rr = obtainRequest(RIL_REQUEST_GET_CLIR, result, mRILDefaultWorkSource);
2248 
2249             if (RILJ_LOGD) {
2250                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2251             }
2252 
2253             try {
2254                 voiceProxy.getClir(rr.mSerial);
2255             } catch (RemoteException | RuntimeException e) {
2256                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "getClir", e);
2257             }
2258         }
2259     }
2260 
2261     @Override
setCLIR(int clirMode, Message result)2262     public void setCLIR(int clirMode, Message result) {
2263         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
2264         if (!voiceProxy.isEmpty()) {
2265             RILRequest rr = obtainRequest(RIL_REQUEST_SET_CLIR, result, mRILDefaultWorkSource);
2266 
2267             if (RILJ_LOGD) {
2268                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2269                         + " clirMode = " + clirMode);
2270             }
2271 
2272             try {
2273                 voiceProxy.setClir(rr.mSerial, clirMode);
2274             } catch (RemoteException | RuntimeException e) {
2275                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "setClir", e);
2276             }
2277         }
2278     }
2279 
2280     @Override
queryCallForwardStatus(int cfReason, int serviceClass, String number, Message result)2281     public void queryCallForwardStatus(int cfReason, int serviceClass, String number,
2282             Message result) {
2283         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
2284         if (!voiceProxy.isEmpty()) {
2285             RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_CALL_FORWARD_STATUS, result,
2286                     mRILDefaultWorkSource);
2287 
2288             if (RILJ_LOGD) {
2289                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2290                         + " cfreason = " + cfReason + " serviceClass = " + serviceClass);
2291             }
2292 
2293             try {
2294                 voiceProxy.getCallForwardStatus(rr.mSerial, cfReason, serviceClass, number);
2295             } catch (RemoteException | RuntimeException e) {
2296                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "getCallForwardStatus", e);
2297             }
2298         }
2299     }
2300 
2301     @Override
setCallForward(int action, int cfReason, int serviceClass, String number, int timeSeconds, Message result)2302     public void setCallForward(int action, int cfReason, int serviceClass, String number,
2303             int timeSeconds, Message result) {
2304         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
2305         if (!voiceProxy.isEmpty()) {
2306             RILRequest rr = obtainRequest(RIL_REQUEST_SET_CALL_FORWARD, result,
2307                     mRILDefaultWorkSource);
2308 
2309             if (RILJ_LOGD) {
2310                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2311                         + " action = " + action + " cfReason = " + cfReason + " serviceClass = "
2312                         + serviceClass + " timeSeconds = " + timeSeconds);
2313             }
2314 
2315             try {
2316                 voiceProxy.setCallForward(
2317                         rr.mSerial, action, cfReason, serviceClass, number, timeSeconds);
2318             } catch (RemoteException | RuntimeException e) {
2319                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "setCallForward", e);
2320             }
2321         }
2322     }
2323 
2324     @Override
queryCallWaiting(int serviceClass, Message result)2325     public void queryCallWaiting(int serviceClass, Message result) {
2326         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
2327         if (!voiceProxy.isEmpty()) {
2328             RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_CALL_WAITING, result,
2329                     mRILDefaultWorkSource);
2330 
2331             if (RILJ_LOGD) {
2332                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2333                         + " serviceClass = " + serviceClass);
2334             }
2335 
2336             try {
2337                 voiceProxy.getCallWaiting(rr.mSerial, serviceClass);
2338             } catch (RemoteException | RuntimeException e) {
2339                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "getCallWaiting", e);
2340             }
2341         }
2342     }
2343 
2344     @Override
setCallWaiting(boolean enable, int serviceClass, Message result)2345     public void setCallWaiting(boolean enable, int serviceClass, Message result) {
2346         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
2347         if (!voiceProxy.isEmpty()) {
2348             RILRequest rr = obtainRequest(RIL_REQUEST_SET_CALL_WAITING, result,
2349                     mRILDefaultWorkSource);
2350 
2351             if (RILJ_LOGD) {
2352                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2353                         + " enable = " + enable + " serviceClass = " + serviceClass);
2354             }
2355 
2356             try {
2357                 voiceProxy.setCallWaiting(rr.mSerial, enable, serviceClass);
2358             } catch (RemoteException | RuntimeException e) {
2359                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "setCallWaiting", e);
2360             }
2361         }
2362     }
2363 
2364     @Override
acknowledgeLastIncomingGsmSms(boolean success, int cause, Message result)2365     public void acknowledgeLastIncomingGsmSms(boolean success, int cause, Message result) {
2366         RadioMessagingProxy messagingProxy =
2367                 getRadioServiceProxy(RadioMessagingProxy.class, result);
2368         if (!messagingProxy.isEmpty()) {
2369             RILRequest rr = obtainRequest(RIL_REQUEST_SMS_ACKNOWLEDGE, result,
2370                     mRILDefaultWorkSource);
2371 
2372             if (RILJ_LOGD) {
2373                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2374                         + " success = " + success + " cause = " + cause);
2375             }
2376 
2377             try {
2378                 messagingProxy.acknowledgeLastIncomingGsmSms(rr.mSerial, success, cause);
2379             } catch (RemoteException | RuntimeException e) {
2380                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING,
2381                         "acknowledgeLastIncomingGsmSms", e);
2382             }
2383         }
2384     }
2385 
2386     @Override
acceptCall(Message result)2387     public void acceptCall(Message result) {
2388         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
2389         if (!voiceProxy.isEmpty()) {
2390             RILRequest rr = obtainRequest(RIL_REQUEST_ANSWER, result, mRILDefaultWorkSource);
2391 
2392             if (RILJ_LOGD) {
2393                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2394             }
2395 
2396             try {
2397                 voiceProxy.acceptCall(rr.mSerial);
2398                 mMetrics.writeRilAnswer(mPhoneId, rr.mSerial);
2399             } catch (RemoteException | RuntimeException e) {
2400                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "acceptCall", e);
2401             }
2402         }
2403     }
2404 
2405     @Override
deactivateDataCall(int cid, int reason, Message result)2406     public void deactivateDataCall(int cid, int reason, Message result) {
2407         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class, result);
2408         if (!dataProxy.isEmpty()) {
2409             RILRequest rr = obtainRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, result,
2410                     mRILDefaultWorkSource);
2411 
2412             if (RILJ_LOGD) {
2413                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2414                         + " cid = " + cid + " reason = "
2415                         + RILUtils.deactivateDataReasonToString(reason));
2416             }
2417 
2418             try {
2419                 dataProxy.deactivateDataCall(rr.mSerial, cid, reason);
2420                 mMetrics.writeRilDeactivateDataCall(mPhoneId, rr.mSerial, cid, reason);
2421             } catch (RemoteException | RuntimeException e) {
2422                 handleRadioProxyExceptionForRR(HAL_SERVICE_DATA, "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         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
2437         if (!simProxy.isEmpty()) {
2438             RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_FACILITY_LOCK, result,
2439                     mRILDefaultWorkSource);
2440 
2441             if (RILJ_LOGD) {
2442                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2443                         + " facility = " + facility + " serviceClass = " + serviceClass
2444                         + " appId = " + appId);
2445             }
2446 
2447             try {
2448                 simProxy.getFacilityLockForApp(rr.mSerial,
2449                         RILUtils.convertNullToEmptyString(facility),
2450                         RILUtils.convertNullToEmptyString(password),
2451                         serviceClass, RILUtils.convertNullToEmptyString(appId));
2452             } catch (RemoteException | RuntimeException e) {
2453                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "getFacilityLockForApp", e);
2454             }
2455         }
2456     }
2457 
2458     @Override
setFacilityLock(String facility, boolean lockState, String password, int serviceClass, Message result)2459     public void setFacilityLock(String facility, boolean lockState, String password,
2460             int serviceClass, Message result) {
2461         setFacilityLockForApp(facility, lockState, password, serviceClass, null, result);
2462     }
2463 
2464     @Override
setFacilityLockForApp(String facility, boolean lockState, String password, int serviceClass, String appId, Message result)2465     public void setFacilityLockForApp(String facility, boolean lockState, String password,
2466             int serviceClass, String appId, Message result) {
2467         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
2468         if (!simProxy.isEmpty()) {
2469             RILRequest rr = obtainRequest(RIL_REQUEST_SET_FACILITY_LOCK, result,
2470                     mRILDefaultWorkSource);
2471 
2472             if (RILJ_LOGD) {
2473                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2474                         + " facility = " + facility + " lockstate = " + lockState
2475                         + " serviceClass = " + serviceClass + " appId = " + appId);
2476             }
2477 
2478             try {
2479                 simProxy.setFacilityLockForApp(rr.mSerial,
2480                         RILUtils.convertNullToEmptyString(facility), lockState,
2481                         RILUtils.convertNullToEmptyString(password), serviceClass,
2482                         RILUtils.convertNullToEmptyString(appId));
2483             } catch (RemoteException | RuntimeException e) {
2484                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "setFacilityLockForApp", e);
2485             }
2486         }
2487     }
2488 
2489     @Override
changeBarringPassword(String facility, String oldPwd, String newPwd, Message result)2490     public void changeBarringPassword(String facility, String oldPwd, String newPwd,
2491             Message result) {
2492         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
2493         if (!networkProxy.isEmpty()) {
2494             RILRequest rr = obtainRequest(RIL_REQUEST_CHANGE_BARRING_PASSWORD, result,
2495                     mRILDefaultWorkSource);
2496 
2497             // Do not log all function args for privacy
2498             if (RILJ_LOGD) {
2499                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2500                         + "facility = " + facility);
2501             }
2502 
2503             try {
2504                 networkProxy.setBarringPassword(rr.mSerial,
2505                         RILUtils.convertNullToEmptyString(facility),
2506                         RILUtils.convertNullToEmptyString(oldPwd),
2507                         RILUtils.convertNullToEmptyString(newPwd));
2508             } catch (RemoteException | RuntimeException e) {
2509                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "changeBarringPassword", e);
2510             }
2511         }
2512     }
2513 
2514     @Override
getNetworkSelectionMode(Message result)2515     public void getNetworkSelectionMode(Message result) {
2516         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
2517         if (!networkProxy.isEmpty()) {
2518             RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE, result,
2519                     mRILDefaultWorkSource);
2520 
2521             if (RILJ_LOGD) {
2522                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2523             }
2524 
2525             try {
2526                 networkProxy.getNetworkSelectionMode(rr.mSerial);
2527             } catch (RemoteException | RuntimeException e) {
2528                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "getNetworkSelectionMode", e);
2529             }
2530         }
2531     }
2532 
2533     @Override
setNetworkSelectionModeAutomatic(Message result)2534     public void setNetworkSelectionModeAutomatic(Message result) {
2535         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
2536         if (!networkProxy.isEmpty()) {
2537             RILRequest rr = obtainRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, result,
2538                     mRILDefaultWorkSource);
2539 
2540             if (RILJ_LOGD) {
2541                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2542             }
2543 
2544             try {
2545                 networkProxy.setNetworkSelectionModeAutomatic(rr.mSerial);
2546             } catch (RemoteException | RuntimeException e) {
2547                 handleRadioProxyExceptionForRR(
2548                         HAL_SERVICE_NETWORK, "setNetworkSelectionModeAutomatic", e);
2549             }
2550         }
2551     }
2552 
2553     @Override
setNetworkSelectionModeManual(String operatorNumeric, int ran, Message result)2554     public void setNetworkSelectionModeManual(String operatorNumeric, int ran, Message result) {
2555         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
2556         if (!networkProxy.isEmpty()) {
2557             RILRequest rr = obtainRequest(RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL, result,
2558                     mRILDefaultWorkSource);
2559 
2560             if (RILJ_LOGD) {
2561                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2562                         + " operatorNumeric = " + operatorNumeric + ", ran = " + ran);
2563             }
2564 
2565             try {
2566                 networkProxy.setNetworkSelectionModeManual(rr.mSerial,
2567                         RILUtils.convertNullToEmptyString(operatorNumeric), ran);
2568             } catch (RemoteException | RuntimeException e) {
2569                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK,
2570                         "setNetworkSelectionModeManual", e);
2571             }
2572         }
2573     }
2574 
2575     @Override
getAvailableNetworks(Message result)2576     public void getAvailableNetworks(Message result) {
2577         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
2578         if (!networkProxy.isEmpty()) {
2579             RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_AVAILABLE_NETWORKS, result,
2580                     mRILDefaultWorkSource);
2581 
2582             if (RILJ_LOGD) {
2583                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2584             }
2585 
2586             try {
2587                 networkProxy.getAvailableNetworks(rr.mSerial);
2588             } catch (RemoteException | RuntimeException e) {
2589                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "getAvailableNetworks", e);
2590             }
2591         }
2592     }
2593 
2594     /**
2595      * Radio HAL fallback compatibility feature (b/151106728) assumes that the input parameter
2596      * networkScanRequest is immutable (read-only) here. Once the caller invokes the method, the
2597      * parameter networkScanRequest should not be modified. This helps us keep a consistent and
2598      * simple data model that avoid copying it in the scan result.
2599      */
2600     @Override
startNetworkScan(NetworkScanRequest networkScanRequest, Message result)2601     public void startNetworkScan(NetworkScanRequest networkScanRequest, Message result) {
2602         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
2603         if (networkProxy.isEmpty()) return;
2604         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_1_1)) {
2605             HalVersion overrideHalVersion = getCompatVersion(RIL_REQUEST_START_NETWORK_SCAN);
2606             if (RILJ_LOGD) {
2607                 riljLog("startNetworkScan: overrideHalVersion=" + overrideHalVersion);
2608             }
2609 
2610             RILRequest rr = obtainRequest(RIL_REQUEST_START_NETWORK_SCAN, result,
2611                     mRILDefaultWorkSource, networkScanRequest);
2612 
2613             if (RILJ_LOGD) {
2614                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2615             }
2616 
2617             try {
2618                 networkProxy.startNetworkScan(rr.mSerial, networkScanRequest, overrideHalVersion,
2619                         result);
2620             } catch (RemoteException | RuntimeException e) {
2621                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "startNetworkScan", e);
2622             }
2623         } else {
2624             if (RILJ_LOGD) Rlog.d(RILJ_LOG_TAG, "startNetworkScan: REQUEST_NOT_SUPPORTED");
2625             if (result != null) {
2626                 AsyncResult.forMessage(result, null,
2627                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
2628                 result.sendToTarget();
2629             }
2630         }
2631     }
2632 
2633     @Override
stopNetworkScan(Message result)2634     public void stopNetworkScan(Message result) {
2635         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
2636         if (networkProxy.isEmpty()) return;
2637         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_1_1)) {
2638             RILRequest rr = obtainRequest(RIL_REQUEST_STOP_NETWORK_SCAN, result,
2639                     mRILDefaultWorkSource);
2640 
2641             if (RILJ_LOGD) {
2642                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2643             }
2644 
2645             try {
2646                 networkProxy.stopNetworkScan(rr.mSerial);
2647             } catch (RemoteException | RuntimeException e) {
2648                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "stopNetworkScan", e);
2649             }
2650         } else {
2651             if (RILJ_LOGD) Rlog.d(RILJ_LOG_TAG, "stopNetworkScan: REQUEST_NOT_SUPPORTED");
2652             if (result != null) {
2653                 AsyncResult.forMessage(result, null,
2654                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
2655                 result.sendToTarget();
2656             }
2657         }
2658     }
2659 
2660     @Override
startDtmf(char c, Message result)2661     public void startDtmf(char c, Message result) {
2662         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
2663         if (!voiceProxy.isEmpty()) {
2664             RILRequest rr = obtainRequest(RIL_REQUEST_DTMF_START, result, mRILDefaultWorkSource);
2665 
2666             // Do not log function arg for privacy
2667             if (RILJ_LOGD) {
2668                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2669             }
2670 
2671             try {
2672                 voiceProxy.startDtmf(rr.mSerial, c + "");
2673             } catch (RemoteException | RuntimeException e) {
2674                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "startDtmf", e);
2675             }
2676         }
2677     }
2678 
2679     @Override
stopDtmf(Message result)2680     public void stopDtmf(Message result) {
2681         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
2682         if (!voiceProxy.isEmpty()) {
2683             RILRequest rr = obtainRequest(RIL_REQUEST_DTMF_STOP, result, mRILDefaultWorkSource);
2684 
2685             if (RILJ_LOGD) {
2686                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2687             }
2688 
2689             try {
2690                 voiceProxy.stopDtmf(rr.mSerial);
2691             } catch (RemoteException | RuntimeException e) {
2692                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "stopDtmf", e);
2693             }
2694         }
2695     }
2696 
2697     @Override
separateConnection(int gsmIndex, Message result)2698     public void separateConnection(int gsmIndex, Message result) {
2699         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
2700         if (!voiceProxy.isEmpty()) {
2701             RILRequest rr = obtainRequest(RIL_REQUEST_SEPARATE_CONNECTION, result,
2702                     mRILDefaultWorkSource);
2703 
2704             if (RILJ_LOGD) {
2705                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2706                         + " gsmIndex = " + gsmIndex);
2707             }
2708 
2709             try {
2710                 voiceProxy.separateConnection(rr.mSerial, gsmIndex);
2711             } catch (RemoteException | RuntimeException e) {
2712                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "separateConnection", e);
2713             }
2714         }
2715     }
2716 
2717     @Override
getBasebandVersion(Message result)2718     public void getBasebandVersion(Message result) {
2719         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class, result);
2720         if (!modemProxy.isEmpty()) {
2721             RILRequest rr = obtainRequest(RIL_REQUEST_BASEBAND_VERSION, result,
2722                     mRILDefaultWorkSource);
2723 
2724             if (RILJ_LOGD) {
2725                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2726             }
2727 
2728             try {
2729                 modemProxy.getBasebandVersion(rr.mSerial);
2730             } catch (RemoteException | RuntimeException e) {
2731                 handleRadioProxyExceptionForRR(HAL_SERVICE_MODEM, "getBasebandVersion", e);
2732             }
2733         }
2734     }
2735 
2736     @Override
setMute(boolean enableMute, Message result)2737     public void setMute(boolean enableMute, Message result) {
2738         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
2739         if (!voiceProxy.isEmpty()) {
2740             RILRequest rr = obtainRequest(RIL_REQUEST_SET_MUTE, result, mRILDefaultWorkSource);
2741 
2742             if (RILJ_LOGD) {
2743                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2744                         + " enableMute = " + enableMute);
2745             }
2746 
2747             try {
2748                 voiceProxy.setMute(rr.mSerial, enableMute);
2749             } catch (RemoteException | RuntimeException e) {
2750                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "setMute", e);
2751             }
2752         }
2753     }
2754 
2755     @Override
getMute(Message result)2756     public void getMute(Message result) {
2757         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
2758         if (!voiceProxy.isEmpty()) {
2759             RILRequest rr = obtainRequest(RIL_REQUEST_GET_MUTE, result, mRILDefaultWorkSource);
2760 
2761             if (RILJ_LOGD) {
2762                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2763             }
2764 
2765             try {
2766                 voiceProxy.getMute(rr.mSerial);
2767             } catch (RemoteException | RuntimeException e) {
2768                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "getMute", e);
2769             }
2770         }
2771     }
2772 
2773     @Override
queryCLIP(Message result)2774     public void queryCLIP(Message result) {
2775         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
2776         if (!voiceProxy.isEmpty()) {
2777             RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_CLIP, result, mRILDefaultWorkSource);
2778 
2779             if (RILJ_LOGD) {
2780                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2781             }
2782 
2783             try {
2784                 voiceProxy.getClip(rr.mSerial);
2785             } catch (RemoteException | RuntimeException e) {
2786                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "getClip", e);
2787             }
2788         }
2789     }
2790 
2791     /**
2792      * @deprecated
2793      */
2794     @Override
2795     @Deprecated
getPDPContextList(Message result)2796     public void getPDPContextList(Message result) {
2797         getDataCallList(result);
2798     }
2799 
2800     @Override
getDataCallList(Message result)2801     public void getDataCallList(Message result) {
2802         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class, result);
2803         if (!dataProxy.isEmpty()) {
2804             RILRequest rr = obtainRequest(RIL_REQUEST_DATA_CALL_LIST, result,
2805                     mRILDefaultWorkSource);
2806 
2807             if (RILJ_LOGD) {
2808                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2809             }
2810 
2811             try {
2812                 dataProxy.getDataCallList(rr.mSerial);
2813             } catch (RemoteException | RuntimeException e) {
2814                 handleRadioProxyExceptionForRR(HAL_SERVICE_DATA, "getDataCallList", e);
2815             }
2816         }
2817     }
2818 
2819     // TODO(b/171260715) Remove when HAL definition is removed
2820     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
2821     @Override
invokeOemRilRequestRaw(byte[] data, Message response)2822     public void invokeOemRilRequestRaw(byte[] data, Message response) {
2823     }
2824 
2825     // TODO(b/171260715) Remove when HAL definition is removed
2826     @Override
invokeOemRilRequestStrings(String[] strings, Message result)2827     public void invokeOemRilRequestStrings(String[] strings, Message result) {
2828     }
2829 
2830     @Override
setSuppServiceNotifications(boolean enable, Message result)2831     public void setSuppServiceNotifications(boolean enable, Message result) {
2832         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
2833         if (!networkProxy.isEmpty()) {
2834             RILRequest rr = obtainRequest(RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION, result,
2835                     mRILDefaultWorkSource);
2836 
2837             if (RILJ_LOGD) {
2838                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2839                         + " enable = " + enable);
2840             }
2841 
2842             try {
2843                 networkProxy.setSuppServiceNotifications(rr.mSerial, enable);
2844             } catch (RemoteException | RuntimeException e) {
2845                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK,
2846                         "setSuppServiceNotifications", e);
2847             }
2848         }
2849     }
2850 
2851     @Override
writeSmsToSim(int status, String smsc, String pdu, Message result)2852     public void writeSmsToSim(int status, String smsc, String pdu, Message result) {
2853         RadioMessagingProxy messagingProxy =
2854                 getRadioServiceProxy(RadioMessagingProxy.class, result);
2855         if (!messagingProxy.isEmpty()) {
2856             RILRequest rr = obtainRequest(RIL_REQUEST_WRITE_SMS_TO_SIM, result,
2857                     mRILDefaultWorkSource);
2858 
2859             if (RILJ_LOGV) {
2860                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2861                         + " " + status);
2862             }
2863 
2864             try {
2865                 messagingProxy.writeSmsToSim(rr.mSerial, status,
2866                         RILUtils.convertNullToEmptyString(smsc),
2867                         RILUtils.convertNullToEmptyString(pdu));
2868             } catch (RemoteException | RuntimeException e) {
2869                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING, "writeSmsToSim", e);
2870             }
2871         }
2872     }
2873 
2874     @Override
deleteSmsOnSim(int index, Message result)2875     public void deleteSmsOnSim(int index, Message result) {
2876         RadioMessagingProxy messagingProxy =
2877                 getRadioServiceProxy(RadioMessagingProxy.class, result);
2878         if (!messagingProxy.isEmpty()) {
2879             RILRequest rr = obtainRequest(RIL_REQUEST_DELETE_SMS_ON_SIM, result,
2880                     mRILDefaultWorkSource);
2881 
2882             if (RILJ_LOGV) {
2883                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2884                         + " index = " + index);
2885             }
2886 
2887             try {
2888                 messagingProxy.deleteSmsOnSim(rr.mSerial, index);
2889             } catch (RemoteException | RuntimeException e) {
2890                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING, "deleteSmsOnSim", e);
2891             }
2892         }
2893     }
2894 
2895     @Override
setBandMode(int bandMode, Message result)2896     public void setBandMode(int bandMode, Message result) {
2897         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
2898         if (!networkProxy.isEmpty()) {
2899             RILRequest rr = obtainRequest(RIL_REQUEST_SET_BAND_MODE, result, mRILDefaultWorkSource);
2900 
2901             if (RILJ_LOGD) {
2902                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2903                         + " bandMode = " + bandMode);
2904             }
2905 
2906             try {
2907                 networkProxy.setBandMode(rr.mSerial, bandMode);
2908             } catch (RemoteException | RuntimeException e) {
2909                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "setBandMode", e);
2910             }
2911         }
2912     }
2913 
2914     @Override
queryAvailableBandMode(Message result)2915     public void queryAvailableBandMode(Message result) {
2916         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
2917         if (!networkProxy.isEmpty()) {
2918             RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE, result,
2919                     mRILDefaultWorkSource);
2920 
2921             if (RILJ_LOGD) {
2922                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2923             }
2924 
2925             try {
2926                 networkProxy.getAvailableBandModes(rr.mSerial);
2927             } catch (RemoteException | RuntimeException e) {
2928                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "queryAvailableBandMode", e);
2929             }
2930         }
2931     }
2932 
2933     @Override
sendEnvelope(String contents, Message result)2934     public void sendEnvelope(String contents, Message result) {
2935         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
2936         if (!simProxy.isEmpty()) {
2937             RILRequest rr = obtainRequest(RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND, result,
2938                     mRILDefaultWorkSource);
2939 
2940             if (RILJ_LOGD) {
2941                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2942                         + " contents = " + contents);
2943             }
2944 
2945             try {
2946                 simProxy.sendEnvelope(rr.mSerial, RILUtils.convertNullToEmptyString(contents));
2947             } catch (RemoteException | RuntimeException e) {
2948                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "sendEnvelope", e);
2949             }
2950         }
2951     }
2952 
2953     @Override
sendTerminalResponse(String contents, Message result)2954     public void sendTerminalResponse(String contents, Message result) {
2955         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
2956         if (!simProxy.isEmpty()) {
2957             RILRequest rr = obtainRequest(RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE, result,
2958                     mRILDefaultWorkSource);
2959 
2960             if (RILJ_LOGD) {
2961                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2962                         + " contents = " + (TelephonyUtils.IS_DEBUGGABLE
2963                         ? contents : RILUtils.convertToCensoredTerminalResponse(contents)));
2964             }
2965 
2966             try {
2967                 simProxy.sendTerminalResponseToSim(rr.mSerial,
2968                         RILUtils.convertNullToEmptyString(contents));
2969             } catch (RemoteException | RuntimeException e) {
2970                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "sendTerminalResponse", e);
2971             }
2972         }
2973     }
2974 
2975     @Override
sendEnvelopeWithStatus(String contents, Message result)2976     public void sendEnvelopeWithStatus(String contents, Message result) {
2977         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
2978         if (!simProxy.isEmpty()) {
2979             RILRequest rr = obtainRequest(RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS, result,
2980                     mRILDefaultWorkSource);
2981 
2982             if (RILJ_LOGD) {
2983                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2984                         + " contents = " + contents);
2985             }
2986 
2987             try {
2988                 simProxy.sendEnvelopeWithStatus(rr.mSerial,
2989                         RILUtils.convertNullToEmptyString(contents));
2990             } catch (RemoteException | RuntimeException e) {
2991                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "sendEnvelopeWithStatus", e);
2992             }
2993         }
2994     }
2995 
2996     @Override
explicitCallTransfer(Message result)2997     public void explicitCallTransfer(Message result) {
2998         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
2999         if (!voiceProxy.isEmpty()) {
3000             RILRequest rr = obtainRequest(RIL_REQUEST_EXPLICIT_CALL_TRANSFER, result,
3001                     mRILDefaultWorkSource);
3002 
3003             if (RILJ_LOGD) {
3004                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3005             }
3006 
3007             try {
3008                 voiceProxy.explicitCallTransfer(rr.mSerial);
3009             } catch (RemoteException | RuntimeException e) {
3010                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "explicitCallTransfer", e);
3011             }
3012         }
3013     }
3014 
3015     @Override
setPreferredNetworkType(@refNetworkMode int networkType , Message result)3016     public void setPreferredNetworkType(@PrefNetworkMode int networkType , Message result) {
3017         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
3018         if (!networkProxy.isEmpty()) {
3019             RILRequest rr = obtainRequest(RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE, result,
3020                     mRILDefaultWorkSource);
3021 
3022             if (RILJ_LOGD) {
3023                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3024                         + " networkType = " + networkType);
3025             }
3026             mAllowedNetworkTypesBitmask = RadioAccessFamily.getRafFromNetworkType(networkType);
3027             mMetrics.writeSetPreferredNetworkType(mPhoneId, networkType);
3028 
3029             try {
3030                 networkProxy.setPreferredNetworkTypeBitmap(rr.mSerial, mAllowedNetworkTypesBitmask);
3031             } catch (RemoteException | RuntimeException e) {
3032                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "setPreferredNetworkType", e);
3033             }
3034         }
3035     }
3036 
3037     @Override
getPreferredNetworkType(Message result)3038     public void getPreferredNetworkType(Message result) {
3039         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
3040         if (!networkProxy.isEmpty()) {
3041             RILRequest rr = obtainRequest(RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE, result,
3042                     mRILDefaultWorkSource);
3043 
3044             if (RILJ_LOGD) {
3045                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3046             }
3047 
3048             try {
3049                 networkProxy.getAllowedNetworkTypesBitmap(rr.mSerial);
3050             } catch (RemoteException | RuntimeException e) {
3051                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "getPreferredNetworkType", e);
3052             }
3053         }
3054     }
3055 
3056     @Override
setAllowedNetworkTypesBitmap( @elephonyManager.NetworkTypeBitMask int networkTypeBitmask, Message result)3057     public void setAllowedNetworkTypesBitmap(
3058             @TelephonyManager.NetworkTypeBitMask int networkTypeBitmask, Message result) {
3059         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
3060         if (!networkProxy.isEmpty()) {
3061             if (mHalVersion.get(HAL_SERVICE_NETWORK).less(RADIO_HAL_VERSION_1_6)) {
3062                 // For older HAL, redirects the call to setPreferredNetworkType.
3063                 setPreferredNetworkType(
3064                         RadioAccessFamily.getNetworkTypeFromRaf(networkTypeBitmask), result);
3065                 return;
3066             }
3067             RILRequest rr = obtainRequest(RIL_REQUEST_SET_ALLOWED_NETWORK_TYPES_BITMAP, result,
3068                     mRILDefaultWorkSource);
3069 
3070             if (RILJ_LOGD) {
3071                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3072             }
3073             mAllowedNetworkTypesBitmask = networkTypeBitmask;
3074 
3075             try {
3076                 networkProxy.setAllowedNetworkTypesBitmap(rr.mSerial, mAllowedNetworkTypesBitmask);
3077             } catch (RemoteException | RuntimeException e) {
3078                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK,
3079                         "setAllowedNetworkTypeBitmask", e);
3080             }
3081         }
3082     }
3083 
3084     @Override
getAllowedNetworkTypesBitmap(Message result)3085     public void getAllowedNetworkTypesBitmap(Message result) {
3086         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
3087         if (!networkProxy.isEmpty()) {
3088             RILRequest rr = obtainRequest(RIL_REQUEST_GET_ALLOWED_NETWORK_TYPES_BITMAP, result,
3089                     mRILDefaultWorkSource);
3090 
3091             if (RILJ_LOGD) {
3092                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3093             }
3094 
3095             try {
3096                 networkProxy.getAllowedNetworkTypesBitmap(rr.mSerial);
3097             } catch (RemoteException | RuntimeException e) {
3098                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK,
3099                         "getAllowedNetworkTypeBitmask", e);
3100             }
3101         }
3102     }
3103 
3104     @Override
setLocationUpdates(boolean enable, WorkSource workSource, Message result)3105     public void setLocationUpdates(boolean enable, WorkSource workSource, Message result) {
3106         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
3107         if (!networkProxy.isEmpty()) {
3108             RILRequest rr = obtainRequest(RIL_REQUEST_SET_LOCATION_UPDATES, result,
3109                     getDefaultWorkSourceIfInvalid(workSource));
3110 
3111             if (RILJ_LOGD) {
3112                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3113                         + " enable = " + enable);
3114             }
3115 
3116             try {
3117                 networkProxy.setLocationUpdates(rr.mSerial, enable);
3118             } catch (RemoteException | RuntimeException e) {
3119                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "setLocationUpdates", e);
3120             }
3121         }
3122     }
3123 
3124     /**
3125      * Is E-UTRA-NR Dual Connectivity enabled
3126      */
3127     @Override
isNrDualConnectivityEnabled(Message result, WorkSource workSource)3128     public void isNrDualConnectivityEnabled(Message result, WorkSource workSource) {
3129         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
3130         if (networkProxy.isEmpty()) return;
3131         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
3132             RILRequest rr = obtainRequest(RIL_REQUEST_IS_NR_DUAL_CONNECTIVITY_ENABLED, result,
3133                     getDefaultWorkSourceIfInvalid(workSource));
3134 
3135             if (RILJ_LOGD) {
3136                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3137             }
3138 
3139             try {
3140                 networkProxy.isNrDualConnectivityEnabled(rr.mSerial);
3141             } catch (RemoteException | RuntimeException e) {
3142                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK,
3143                         "isNrDualConnectivityEnabled", e);
3144             }
3145         } else {
3146             if (RILJ_LOGD) {
3147                 Rlog.d(RILJ_LOG_TAG, "isNrDualConnectivityEnabled: REQUEST_NOT_SUPPORTED");
3148             }
3149             if (result != null) {
3150                 AsyncResult.forMessage(result, null,
3151                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
3152                 result.sendToTarget();
3153             }
3154         }
3155     }
3156 
3157     /**
3158      * Enable/Disable E-UTRA-NR Dual Connectivity
3159      * @param nrDualConnectivityState expected NR dual connectivity state
3160      * This can be passed following states
3161      * <ol>
3162      * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
3163      * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
3164      * <li>Disable NR dual connectivity and force secondary cell to be released
3165      * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
3166      * </ol>
3167      */
3168     @Override
setNrDualConnectivityState(int nrDualConnectivityState, Message result, WorkSource workSource)3169     public void setNrDualConnectivityState(int nrDualConnectivityState, Message result,
3170             WorkSource workSource) {
3171         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
3172         if (networkProxy.isEmpty()) return;
3173         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
3174             RILRequest rr = obtainRequest(RIL_REQUEST_ENABLE_NR_DUAL_CONNECTIVITY, result,
3175                     getDefaultWorkSourceIfInvalid(workSource));
3176 
3177             if (RILJ_LOGD) {
3178                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3179                         + " enable = " + nrDualConnectivityState);
3180             }
3181 
3182             try {
3183                 networkProxy.setNrDualConnectivityState(rr.mSerial, (byte) nrDualConnectivityState);
3184             } catch (RemoteException | RuntimeException e) {
3185                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "enableNrDualConnectivity", e);
3186             }
3187         } else {
3188             if (RILJ_LOGD) Rlog.d(RILJ_LOG_TAG, "enableNrDualConnectivity: REQUEST_NOT_SUPPORTED");
3189             if (result != null) {
3190                 AsyncResult.forMessage(result, null,
3191                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
3192                 result.sendToTarget();
3193             }
3194         }
3195     }
3196 
setVoNrEnabled(boolean enabled)3197     private void setVoNrEnabled(boolean enabled) {
3198         SystemProperties.set(PROPERTY_IS_VONR_ENABLED + mPhoneId, String.valueOf(enabled));
3199     }
3200 
isVoNrEnabled()3201     private boolean isVoNrEnabled() {
3202         return SystemProperties.getBoolean(PROPERTY_IS_VONR_ENABLED + mPhoneId, true);
3203     }
3204 
3205     /**
3206      * Is voice over NR enabled
3207      */
3208     @Override
isVoNrEnabled(Message result, WorkSource workSource)3209     public void isVoNrEnabled(Message result, WorkSource workSource) {
3210 
3211         if (mHalVersion.get(HAL_SERVICE_VOICE).greaterOrEqual(RADIO_HAL_VERSION_2_0)) {
3212             RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
3213             if (!voiceProxy.isEmpty()) {
3214                 RILRequest rr = obtainRequest(RIL_REQUEST_IS_VONR_ENABLED , result,
3215                         getDefaultWorkSourceIfInvalid(workSource));
3216 
3217                 if (RILJ_LOGD) {
3218                     riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3219                 }
3220 
3221                 try {
3222                     voiceProxy.isVoNrEnabled(rr.mSerial);
3223                 } catch (RemoteException | RuntimeException e) {
3224                     handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "isVoNrEnabled", e);
3225                 }
3226             }
3227         } else {
3228             boolean isEnabled = isVoNrEnabled();
3229             if (result != null) {
3230                 AsyncResult.forMessage(result, isEnabled, null);
3231                 result.sendToTarget();
3232             }
3233         }
3234     }
3235 
3236     /**
3237      * Enable or disable Voice over NR (VoNR)
3238      * @param enabled enable or disable VoNR.
3239      */
3240     @Override
setVoNrEnabled(boolean enabled, Message result, WorkSource workSource)3241     public void setVoNrEnabled(boolean enabled, Message result, WorkSource workSource) {
3242         setVoNrEnabled(enabled);
3243 
3244         if (mHalVersion.get(HAL_SERVICE_VOICE).greaterOrEqual(RADIO_HAL_VERSION_2_0)) {
3245             RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
3246             if (!voiceProxy.isEmpty()) {
3247                 RILRequest rr = obtainRequest(RIL_REQUEST_ENABLE_VONR, result,
3248                         getDefaultWorkSourceIfInvalid(workSource));
3249 
3250                 if (RILJ_LOGD) {
3251                     riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3252                 }
3253 
3254                 try {
3255                     voiceProxy.setVoNrEnabled(rr.mSerial, enabled);
3256                 } catch (RemoteException | RuntimeException e) {
3257                     handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "setVoNrEnabled", e);
3258                 }
3259             }
3260         } else {
3261             /* calling a query api to let HAL know that VoNREnabled state is updated.
3262                This is a work around as new AIDL API is not allowed for older HAL version devices.
3263                HAL can check the value of PROPERTY_IS_VONR_ENABLED property to determine
3264                if there is any change whenever it receives isNrDualConnectivityEnabled request.
3265             */
3266             isNrDualConnectivityEnabled(null, workSource);
3267             if (result != null) {
3268                 AsyncResult.forMessage(result, null, null);
3269                 result.sendToTarget();
3270             }
3271         }
3272     }
3273 
3274     @Override
setCdmaSubscriptionSource(int cdmaSubscription, Message result)3275     public void setCdmaSubscriptionSource(int cdmaSubscription, Message result) {
3276         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
3277         if (!simProxy.isEmpty()) {
3278             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE, result,
3279                     mRILDefaultWorkSource);
3280 
3281             if (RILJ_LOGD) {
3282                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3283                         + " cdmaSubscription = " + cdmaSubscription);
3284             }
3285 
3286             try {
3287                 simProxy.setCdmaSubscriptionSource(rr.mSerial, cdmaSubscription);
3288             } catch (RemoteException | RuntimeException e) {
3289                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "setCdmaSubscriptionSource", e);
3290             }
3291         }
3292     }
3293 
3294     @Override
queryCdmaRoamingPreference(Message result)3295     public void queryCdmaRoamingPreference(Message result) {
3296         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
3297         if (!networkProxy.isEmpty()) {
3298             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE, result,
3299                     mRILDefaultWorkSource);
3300 
3301             if (RILJ_LOGD) {
3302                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3303             }
3304 
3305             try {
3306                 networkProxy.getCdmaRoamingPreference(rr.mSerial);
3307             } catch (RemoteException | RuntimeException e) {
3308                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK,
3309                         "queryCdmaRoamingPreference", e);
3310             }
3311         }
3312     }
3313 
3314     @Override
setCdmaRoamingPreference(int cdmaRoamingType, Message result)3315     public void setCdmaRoamingPreference(int cdmaRoamingType, Message result) {
3316         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
3317         if (!networkProxy.isEmpty()) {
3318             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE, result,
3319                     mRILDefaultWorkSource);
3320 
3321             if (RILJ_LOGD) {
3322                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3323                         + " cdmaRoamingType = " + cdmaRoamingType);
3324             }
3325 
3326             try {
3327                 networkProxy.setCdmaRoamingPreference(rr.mSerial, cdmaRoamingType);
3328             } catch (RemoteException | RuntimeException e) {
3329                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "setCdmaRoamingPreference", e);
3330             }
3331         }
3332     }
3333 
3334     @Override
queryTTYMode(Message result)3335     public void queryTTYMode(Message result) {
3336         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
3337         if (!voiceProxy.isEmpty()) {
3338             RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_TTY_MODE, result,
3339                     mRILDefaultWorkSource);
3340 
3341             if (RILJ_LOGD) {
3342                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3343             }
3344 
3345             try {
3346                 voiceProxy.getTtyMode(rr.mSerial);
3347             } catch (RemoteException | RuntimeException e) {
3348                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "getTtyMode", e);
3349             }
3350         }
3351     }
3352 
3353     @Override
setTTYMode(int ttyMode, Message result)3354     public void setTTYMode(int ttyMode, Message result) {
3355         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
3356         if (!voiceProxy.isEmpty()) {
3357             RILRequest rr = obtainRequest(RIL_REQUEST_SET_TTY_MODE, result, mRILDefaultWorkSource);
3358 
3359             if (RILJ_LOGD) {
3360                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3361                         + " ttyMode = " + ttyMode);
3362             }
3363 
3364             try {
3365                 voiceProxy.setTtyMode(rr.mSerial, ttyMode);
3366             } catch (RemoteException | RuntimeException e) {
3367                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "setTtyMode", e);
3368             }
3369         }
3370     }
3371 
3372     @Override
setPreferredVoicePrivacy(boolean enable, Message result)3373     public void setPreferredVoicePrivacy(boolean enable, Message result) {
3374         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
3375         if (!voiceProxy.isEmpty()) {
3376             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE, result,
3377                     mRILDefaultWorkSource);
3378 
3379             if (RILJ_LOGD) {
3380                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3381                         + " enable = " + enable);
3382             }
3383 
3384             try {
3385                 voiceProxy.setPreferredVoicePrivacy(rr.mSerial, enable);
3386             } catch (RemoteException | RuntimeException e) {
3387                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "setPreferredVoicePrivacy", e);
3388             }
3389         }
3390     }
3391 
3392     @Override
getPreferredVoicePrivacy(Message result)3393     public void getPreferredVoicePrivacy(Message result) {
3394         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
3395         if (!voiceProxy.isEmpty()) {
3396             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE,
3397                     result, mRILDefaultWorkSource);
3398 
3399             if (RILJ_LOGD) {
3400                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3401             }
3402 
3403             try {
3404                 voiceProxy.getPreferredVoicePrivacy(rr.mSerial);
3405             } catch (RemoteException | RuntimeException e) {
3406                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "getPreferredVoicePrivacy", e);
3407             }
3408         }
3409     }
3410 
3411     @Override
sendCDMAFeatureCode(String featureCode, Message result)3412     public void sendCDMAFeatureCode(String featureCode, Message result) {
3413         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
3414         if (!voiceProxy.isEmpty()) {
3415             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_FLASH, result, mRILDefaultWorkSource);
3416 
3417             if (RILJ_LOGD) {
3418                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3419                         + " featureCode = " + Rlog.pii(RILJ_LOG_TAG, featureCode));
3420             }
3421 
3422             try {
3423                 voiceProxy.sendCdmaFeatureCode(rr.mSerial,
3424                         RILUtils.convertNullToEmptyString(featureCode));
3425             } catch (RemoteException | RuntimeException e) {
3426                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "sendCdmaFeatureCode", e);
3427             }
3428         }
3429     }
3430 
3431     @Override
sendBurstDtmf(String dtmfString, int on, int off, Message result)3432     public void sendBurstDtmf(String dtmfString, int on, int off, Message result) {
3433         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
3434         if (!voiceProxy.isEmpty()) {
3435             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_BURST_DTMF, result,
3436                     mRILDefaultWorkSource);
3437 
3438             if (RILJ_LOGD) {
3439                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3440                         + " dtmfString = " + dtmfString + " on = " + on + " off = " + off);
3441             }
3442 
3443             try {
3444                 voiceProxy.sendBurstDtmf(rr.mSerial, RILUtils.convertNullToEmptyString(dtmfString),
3445                         on, off);
3446             } catch (RemoteException | RuntimeException e) {
3447                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "sendBurstDtmf", e);
3448             }
3449         }
3450     }
3451 
3452     @Override
sendCdmaSMSExpectMore(byte[] pdu, Message result)3453     public void sendCdmaSMSExpectMore(byte[] pdu, Message result) {
3454         RadioMessagingProxy messagingProxy =
3455                 getRadioServiceProxy(RadioMessagingProxy.class, result);
3456         if (!messagingProxy.isEmpty()) {
3457             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SEND_SMS_EXPECT_MORE, result,
3458                     mRILDefaultWorkSource);
3459 
3460             // Do not log function arg for privacy
3461             if (RILJ_LOGD) {
3462                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3463             }
3464 
3465             try {
3466                 messagingProxy.sendCdmaSmsExpectMore(rr.mSerial, pdu);
3467                 if (mHalVersion.get(HAL_SERVICE_MESSAGING).greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
3468                     mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_CDMA,
3469                             SmsSession.Event.Format.SMS_FORMAT_3GPP2,
3470                             getOutgoingSmsMessageId(result));
3471                 }
3472             } catch (RemoteException | RuntimeException e) {
3473                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING, "sendCdmaSMSExpectMore", e);
3474             }
3475         }
3476     }
3477 
3478     @Override
sendCdmaSms(byte[] pdu, Message result)3479     public void sendCdmaSms(byte[] pdu, Message result) {
3480         RadioMessagingProxy messagingProxy =
3481                 getRadioServiceProxy(RadioMessagingProxy.class, result);
3482         if (!messagingProxy.isEmpty()) {
3483             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SEND_SMS, result, mRILDefaultWorkSource);
3484 
3485             // Do not log function arg for privacy
3486             if (RILJ_LOGD) {
3487                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3488             }
3489 
3490             try {
3491                 messagingProxy.sendCdmaSms(rr.mSerial, pdu);
3492                 mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_CDMA,
3493                         SmsSession.Event.Format.SMS_FORMAT_3GPP2, getOutgoingSmsMessageId(result));
3494             } catch (RemoteException | RuntimeException e) {
3495                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING, "sendCdmaSms", e);
3496             }
3497         }
3498     }
3499 
3500     @Override
acknowledgeLastIncomingCdmaSms(boolean success, int cause, Message result)3501     public void acknowledgeLastIncomingCdmaSms(boolean success, int cause, Message result) {
3502         RadioMessagingProxy messagingProxy =
3503                 getRadioServiceProxy(RadioMessagingProxy.class, result);
3504         if (!messagingProxy.isEmpty()) {
3505             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE, result,
3506                     mRILDefaultWorkSource);
3507 
3508             if (RILJ_LOGD) {
3509                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3510                         + " success = " + success + " cause = " + cause);
3511             }
3512 
3513             try {
3514                 messagingProxy.acknowledgeLastIncomingCdmaSms(rr.mSerial, success, cause);
3515             } catch (RemoteException | RuntimeException e) {
3516                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING,
3517                         "acknowledgeLastIncomingCdmaSms", e);
3518             }
3519         }
3520     }
3521 
3522     @Override
getGsmBroadcastConfig(Message result)3523     public void getGsmBroadcastConfig(Message result) {
3524         RadioMessagingProxy messagingProxy =
3525                 getRadioServiceProxy(RadioMessagingProxy.class, result);
3526         if (!messagingProxy.isEmpty()) {
3527             RILRequest rr = obtainRequest(RIL_REQUEST_GSM_GET_BROADCAST_CONFIG, result,
3528                     mRILDefaultWorkSource);
3529 
3530             if (RILJ_LOGD) {
3531                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3532             }
3533 
3534             try {
3535                 messagingProxy.getGsmBroadcastConfig(rr.mSerial);
3536             } catch (RemoteException | RuntimeException e) {
3537                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING, "getGsmBroadcastConfig", e);
3538             }
3539         }
3540     }
3541 
3542     @Override
setGsmBroadcastConfig(SmsBroadcastConfigInfo[] config, Message result)3543     public void setGsmBroadcastConfig(SmsBroadcastConfigInfo[] config, Message result) {
3544         RadioMessagingProxy messagingProxy =
3545                 getRadioServiceProxy(RadioMessagingProxy.class, result);
3546         if (!messagingProxy.isEmpty()) {
3547             RILRequest rr = obtainRequest(RIL_REQUEST_GSM_SET_BROADCAST_CONFIG, result,
3548                     mRILDefaultWorkSource);
3549 
3550             if (RILJ_LOGD) {
3551                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3552                         + " with " + config.length + " configs : ");
3553                 for (int i = 0; i < config.length; i++) {
3554                     riljLog(config[i].toString());
3555                 }
3556             }
3557 
3558             try {
3559                 messagingProxy.setGsmBroadcastConfig(rr.mSerial, config);
3560             } catch (RemoteException | RuntimeException e) {
3561                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING, "setGsmBroadcastConfig", e);
3562             }
3563         }
3564     }
3565 
3566     @Override
setGsmBroadcastActivation(boolean activate, Message result)3567     public void setGsmBroadcastActivation(boolean activate, Message result) {
3568         RadioMessagingProxy messagingProxy =
3569                 getRadioServiceProxy(RadioMessagingProxy.class, result);
3570         if (!messagingProxy.isEmpty()) {
3571             RILRequest rr = obtainRequest(RIL_REQUEST_GSM_BROADCAST_ACTIVATION, result,
3572                     mRILDefaultWorkSource);
3573 
3574             if (RILJ_LOGD) {
3575                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3576                         + " activate = " + activate);
3577             }
3578 
3579             try {
3580                 messagingProxy.setGsmBroadcastActivation(rr.mSerial, activate);
3581             } catch (RemoteException | RuntimeException e) {
3582                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING,
3583                         "setGsmBroadcastActivation", e);
3584             }
3585         }
3586     }
3587 
3588     @Override
getCdmaBroadcastConfig(Message result)3589     public void getCdmaBroadcastConfig(Message result) {
3590         RadioMessagingProxy messagingProxy =
3591                 getRadioServiceProxy(RadioMessagingProxy.class, result);
3592         if (!messagingProxy.isEmpty()) {
3593             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG, result,
3594                     mRILDefaultWorkSource);
3595 
3596             if (RILJ_LOGD) {
3597                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3598             }
3599 
3600             try {
3601                 messagingProxy.getCdmaBroadcastConfig(rr.mSerial);
3602             } catch (RemoteException | RuntimeException e) {
3603                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING, "getCdmaBroadcastConfig", e);
3604             }
3605         }
3606     }
3607 
3608     @Override
setCdmaBroadcastConfig(CdmaSmsBroadcastConfigInfo[] configs, Message result)3609     public void setCdmaBroadcastConfig(CdmaSmsBroadcastConfigInfo[] configs, Message result) {
3610         RadioMessagingProxy messagingProxy =
3611                 getRadioServiceProxy(RadioMessagingProxy.class, result);
3612         if (!messagingProxy.isEmpty()) {
3613             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG, result,
3614                     mRILDefaultWorkSource);
3615 
3616             if (RILJ_LOGD) {
3617                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3618                         + " with " + configs.length + " configs : ");
3619                 for (CdmaSmsBroadcastConfigInfo config : configs) {
3620                     riljLog(config.toString());
3621                 }
3622             }
3623 
3624             try {
3625                 messagingProxy.setCdmaBroadcastConfig(rr.mSerial, configs);
3626             } catch (RemoteException | RuntimeException e) {
3627                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING, "setCdmaBroadcastConfig", e);
3628             }
3629         }
3630     }
3631 
3632     @Override
setCdmaBroadcastActivation(boolean activate, Message result)3633     public void setCdmaBroadcastActivation(boolean activate, Message result) {
3634         RadioMessagingProxy messagingProxy =
3635                 getRadioServiceProxy(RadioMessagingProxy.class, result);
3636         if (!messagingProxy.isEmpty()) {
3637             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_BROADCAST_ACTIVATION, result,
3638                     mRILDefaultWorkSource);
3639 
3640             if (RILJ_LOGD) {
3641                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3642                         + " activate = " + activate);
3643             }
3644 
3645             try {
3646                 messagingProxy.setCdmaBroadcastActivation(rr.mSerial, activate);
3647             } catch (RemoteException | RuntimeException e) {
3648                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING,
3649                         "setCdmaBroadcastActivation", e);
3650             }
3651         }
3652     }
3653 
3654     @Override
getCDMASubscription(Message result)3655     public void getCDMASubscription(Message result) {
3656         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
3657         if (!simProxy.isEmpty()) {
3658             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SUBSCRIPTION, result,
3659                     mRILDefaultWorkSource);
3660 
3661             if (RILJ_LOGD) {
3662                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3663             }
3664 
3665             try {
3666                 simProxy.getCdmaSubscription(rr.mSerial);
3667             } catch (RemoteException | RuntimeException e) {
3668                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "getCdmaSubscription", e);
3669             }
3670         }
3671     }
3672 
3673     @Override
writeSmsToRuim(int status, byte[] pdu, Message result)3674     public void writeSmsToRuim(int status, byte[] pdu, Message result) {
3675         RadioMessagingProxy messagingProxy =
3676                 getRadioServiceProxy(RadioMessagingProxy.class, result);
3677         if (!messagingProxy.isEmpty()) {
3678             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM, result,
3679                     mRILDefaultWorkSource);
3680 
3681             if (RILJ_LOGV) {
3682                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3683                         + " status = " + status);
3684             }
3685 
3686             try {
3687                 messagingProxy.writeSmsToRuim(rr.mSerial, status, pdu);
3688             } catch (RemoteException | RuntimeException e) {
3689                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING, "writeSmsToRuim", e);
3690             }
3691         }
3692     }
3693 
3694     @Override
deleteSmsOnRuim(int index, Message result)3695     public void deleteSmsOnRuim(int index, Message result) {
3696         RadioMessagingProxy messagingProxy =
3697                 getRadioServiceProxy(RadioMessagingProxy.class, result);
3698         if (!messagingProxy.isEmpty()) {
3699             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM, result,
3700                     mRILDefaultWorkSource);
3701 
3702             if (RILJ_LOGV) {
3703                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3704                         + " index = " + index);
3705             }
3706 
3707             try {
3708                 messagingProxy.deleteSmsOnRuim(rr.mSerial, index);
3709             } catch (RemoteException | RuntimeException e) {
3710                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING, "deleteSmsOnRuim", e);
3711             }
3712         }
3713     }
3714 
3715     @Override
getDeviceIdentity(Message result)3716     public void getDeviceIdentity(Message result) {
3717         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class, result);
3718         if (!modemProxy.isEmpty()) {
3719             RILRequest rr = obtainRequest(RIL_REQUEST_DEVICE_IDENTITY, result,
3720                     mRILDefaultWorkSource);
3721 
3722             if (RILJ_LOGD) {
3723                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3724             }
3725 
3726             try {
3727                 modemProxy.getDeviceIdentity(rr.mSerial);
3728             } catch (RemoteException | RuntimeException e) {
3729                 handleRadioProxyExceptionForRR(HAL_SERVICE_MODEM, "getDeviceIdentity", e);
3730             }
3731         }
3732     }
3733 
3734     @Override
getImei(Message result)3735     public void getImei(Message result) {
3736         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class, result);
3737         if (modemProxy.isEmpty()) {
3738             if (RILJ_LOGD) {
3739                 Rlog.e(RILJ_LOG_TAG, "getImei: modemProxy is Empty");
3740             }
3741             return;
3742         }
3743         if (mHalVersion.get(HAL_SERVICE_MODEM).greaterOrEqual(RADIO_HAL_VERSION_2_1)) {
3744             RILRequest rr = obtainRequest(RIL_REQUEST_DEVICE_IMEI, result,
3745                     mRILDefaultWorkSource);
3746 
3747             if (RILJ_LOGD) {
3748                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3749             }
3750 
3751             try {
3752                 modemProxy.getImei(rr.mSerial);
3753             } catch (RemoteException | RuntimeException e) {
3754                 handleRadioProxyExceptionForRR(HAL_SERVICE_MODEM, "getImei", e);
3755             }
3756         }  else {
3757             if (RILJ_LOGD) {
3758                 Rlog.e(RILJ_LOG_TAG, "getImei: REQUEST_NOT_SUPPORTED");
3759             }
3760             if (result != null) {
3761                 AsyncResult.forMessage(result, null,
3762                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
3763                 result.sendToTarget();
3764             }
3765         }
3766     }
3767 
3768     @Override
exitEmergencyCallbackMode(Message result)3769     public void exitEmergencyCallbackMode(Message result) {
3770         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
3771         if (!voiceProxy.isEmpty()) {
3772             RILRequest rr = obtainRequest(RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE, result,
3773                     mRILDefaultWorkSource);
3774 
3775             if (RILJ_LOGD) {
3776                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3777             }
3778 
3779             try {
3780                 voiceProxy.exitEmergencyCallbackMode(rr.mSerial);
3781             } catch (RemoteException | RuntimeException e) {
3782                 handleRadioProxyExceptionForRR(HAL_SERVICE_VOICE, "exitEmergencyCallbackMode", e);
3783             }
3784         }
3785     }
3786 
3787     @Override
getSmscAddress(Message result)3788     public void getSmscAddress(Message result) {
3789         RadioMessagingProxy messagingProxy =
3790                 getRadioServiceProxy(RadioMessagingProxy.class, result);
3791         if (!messagingProxy.isEmpty()) {
3792             RILRequest rr = obtainRequest(RIL_REQUEST_GET_SMSC_ADDRESS, result,
3793                     mRILDefaultWorkSource);
3794 
3795             if (RILJ_LOGD) {
3796                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3797             }
3798 
3799             try {
3800                 messagingProxy.getSmscAddress(rr.mSerial);
3801             } catch (RemoteException | RuntimeException e) {
3802                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING, "getSmscAddress", e);
3803             }
3804         }
3805     }
3806 
3807     @Override
setSmscAddress(String address, Message result)3808     public void setSmscAddress(String address, Message result) {
3809         RadioMessagingProxy messagingProxy =
3810                 getRadioServiceProxy(RadioMessagingProxy.class, result);
3811         if (!messagingProxy.isEmpty()) {
3812             RILRequest rr = obtainRequest(RIL_REQUEST_SET_SMSC_ADDRESS, result,
3813                     mRILDefaultWorkSource);
3814 
3815             if (RILJ_LOGD) {
3816                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3817                         + " address = " + address);
3818             }
3819 
3820             try {
3821                 messagingProxy.setSmscAddress(rr.mSerial,
3822                         RILUtils.convertNullToEmptyString(address));
3823             } catch (RemoteException | RuntimeException e) {
3824                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING, "setSmscAddress", e);
3825             }
3826         }
3827     }
3828 
3829     @Override
reportSmsMemoryStatus(boolean available, Message result)3830     public void reportSmsMemoryStatus(boolean available, Message result) {
3831         RadioMessagingProxy messagingProxy =
3832                 getRadioServiceProxy(RadioMessagingProxy.class, result);
3833         if (!messagingProxy.isEmpty()) {
3834             RILRequest rr = obtainRequest(RIL_REQUEST_REPORT_SMS_MEMORY_STATUS, result,
3835                     mRILDefaultWorkSource);
3836 
3837             if (RILJ_LOGD) {
3838                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3839                         + " available = " + available);
3840             }
3841 
3842             try {
3843                 messagingProxy.reportSmsMemoryStatus(rr.mSerial, available);
3844             } catch (RemoteException | RuntimeException e) {
3845                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING, "reportSmsMemoryStatus", e);
3846             }
3847         }
3848     }
3849 
3850     @Override
reportStkServiceIsRunning(Message result)3851     public void reportStkServiceIsRunning(Message result) {
3852         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
3853         if (!simProxy.isEmpty()) {
3854             RILRequest rr = obtainRequest(RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING, result,
3855                     mRILDefaultWorkSource);
3856 
3857             if (RILJ_LOGD) {
3858                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3859             }
3860 
3861             try {
3862                 simProxy.reportStkServiceIsRunning(rr.mSerial);
3863             } catch (RemoteException | RuntimeException e) {
3864                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "reportStkServiceIsRunning", e);
3865             }
3866         }
3867     }
3868 
3869     @Override
getCdmaSubscriptionSource(Message result)3870     public void getCdmaSubscriptionSource(Message result) {
3871         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
3872         if (!simProxy.isEmpty()) {
3873             RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE, result,
3874                     mRILDefaultWorkSource);
3875 
3876             if (RILJ_LOGD) {
3877                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3878             }
3879 
3880             try {
3881                 simProxy.getCdmaSubscriptionSource(rr.mSerial);
3882             } catch (RemoteException | RuntimeException e) {
3883                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "getCdmaSubscriptionSource", e);
3884             }
3885         }
3886     }
3887 
3888     @Override
acknowledgeIncomingGsmSmsWithPdu(boolean success, String ackPdu, Message result)3889     public void acknowledgeIncomingGsmSmsWithPdu(boolean success, String ackPdu, Message result) {
3890         RadioMessagingProxy messagingProxy =
3891                 getRadioServiceProxy(RadioMessagingProxy.class, result);
3892         if (!messagingProxy.isEmpty()) {
3893             RILRequest rr = obtainRequest(RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU, result,
3894                     mRILDefaultWorkSource);
3895 
3896             if (RILJ_LOGD) {
3897                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3898                         + " success = " + success);
3899             }
3900 
3901             try {
3902                 messagingProxy.acknowledgeIncomingGsmSmsWithPdu(rr.mSerial, success,
3903                         RILUtils.convertNullToEmptyString(ackPdu));
3904             } catch (RemoteException | RuntimeException e) {
3905                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING,
3906                         "acknowledgeIncomingGsmSmsWithPdu", e);
3907             }
3908         }
3909     }
3910 
3911     @Override
getVoiceRadioTechnology(Message result)3912     public void getVoiceRadioTechnology(Message result) {
3913         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
3914         if (!networkProxy.isEmpty()) {
3915             RILRequest rr = obtainRequest(RIL_REQUEST_VOICE_RADIO_TECH, result,
3916                     mRILDefaultWorkSource);
3917 
3918             if (RILJ_LOGD) {
3919                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3920             }
3921 
3922             try {
3923                 networkProxy.getVoiceRadioTechnology(rr.mSerial);
3924             } catch (RemoteException | RuntimeException e) {
3925                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "getVoiceRadioTechnology", e);
3926             }
3927         }
3928     }
3929 
3930     @Override
getCellInfoList(Message result, WorkSource workSource)3931     public void getCellInfoList(Message result, WorkSource workSource) {
3932         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
3933         if (!networkProxy.isEmpty()) {
3934             RILRequest rr = obtainRequest(RIL_REQUEST_GET_CELL_INFO_LIST, result,
3935                     getDefaultWorkSourceIfInvalid(workSource));
3936 
3937             if (RILJ_LOGD) {
3938                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3939             }
3940 
3941             try {
3942                 networkProxy.getCellInfoList(rr.mSerial);
3943             } catch (RemoteException | RuntimeException e) {
3944                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "getCellInfoList", e);
3945             }
3946         }
3947     }
3948 
3949     @Override
setCellInfoListRate(int rateInMillis, Message result, WorkSource workSource)3950     public void setCellInfoListRate(int rateInMillis, Message result, WorkSource workSource) {
3951         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
3952         if (!networkProxy.isEmpty()) {
3953             RILRequest rr = obtainRequest(RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE, result,
3954                     getDefaultWorkSourceIfInvalid(workSource));
3955 
3956             if (RILJ_LOGD) {
3957                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3958                         + " rateInMillis = " + rateInMillis);
3959             }
3960 
3961             try {
3962                 networkProxy.setCellInfoListRate(rr.mSerial, rateInMillis);
3963             } catch (RemoteException | RuntimeException e) {
3964                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "setCellInfoListRate", e);
3965             }
3966         }
3967     }
3968 
3969     @Override
setInitialAttachApn(DataProfile dataProfile, boolean isRoaming, Message result)3970     public void setInitialAttachApn(DataProfile dataProfile, boolean isRoaming, Message result) {
3971         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class, result);
3972         if (!dataProxy.isEmpty()) {
3973             RILRequest rr = obtainRequest(RIL_REQUEST_SET_INITIAL_ATTACH_APN, result,
3974                     mRILDefaultWorkSource);
3975 
3976             if (RILJ_LOGD) {
3977                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3978                         + dataProfile);
3979             }
3980 
3981             try {
3982                 dataProxy.setInitialAttachApn(rr.mSerial, dataProfile, isRoaming);
3983             } catch (RemoteException | RuntimeException e) {
3984                 handleRadioProxyExceptionForRR(HAL_SERVICE_DATA, "setInitialAttachApn", e);
3985             }
3986         }
3987     }
3988 
3989     @Override
getImsRegistrationState(Message result)3990     public void getImsRegistrationState(Message result) {
3991         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
3992         if (!networkProxy.isEmpty()) {
3993             RILRequest rr = obtainRequest(RIL_REQUEST_IMS_REGISTRATION_STATE, result,
3994                     mRILDefaultWorkSource);
3995 
3996             if (RILJ_LOGD) {
3997                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3998             }
3999 
4000             try {
4001                 networkProxy.getImsRegistrationState(rr.mSerial);
4002             } catch (RemoteException | RuntimeException e) {
4003                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "getImsRegistrationState", e);
4004             }
4005         }
4006     }
4007 
4008     @Override
sendImsGsmSms(String smscPdu, String pdu, int retry, int messageRef, Message result)4009     public void sendImsGsmSms(String smscPdu, String pdu, int retry, int messageRef,
4010             Message result) {
4011         RadioMessagingProxy messagingProxy =
4012                 getRadioServiceProxy(RadioMessagingProxy.class, result);
4013         if (!messagingProxy.isEmpty()) {
4014             RILRequest rr = obtainRequest(RIL_REQUEST_IMS_SEND_SMS, result, mRILDefaultWorkSource);
4015 
4016             // Do not log function args for privacy
4017             if (RILJ_LOGD) {
4018                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4019             }
4020 
4021             try {
4022                 messagingProxy.sendImsSms(rr.mSerial, smscPdu, pdu, null, retry, messageRef);
4023                 mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_IMS,
4024                         SmsSession.Event.Format.SMS_FORMAT_3GPP, getOutgoingSmsMessageId(result));
4025             } catch (RemoteException | RuntimeException e) {
4026                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING, "sendImsGsmSms", e);
4027             }
4028         }
4029     }
4030 
4031     @Override
sendImsCdmaSms(byte[] pdu, int retry, int messageRef, Message result)4032     public void sendImsCdmaSms(byte[] pdu, int retry, int messageRef, Message result) {
4033         RadioMessagingProxy messagingProxy =
4034                 getRadioServiceProxy(RadioMessagingProxy.class, result);
4035         if (!messagingProxy.isEmpty()) {
4036             RILRequest rr = obtainRequest(RIL_REQUEST_IMS_SEND_SMS, result, mRILDefaultWorkSource);
4037 
4038             // Do not log function args for privacy
4039             if (RILJ_LOGD) {
4040                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4041             }
4042 
4043             try {
4044                 messagingProxy.sendImsSms(rr.mSerial, null, null, pdu, retry, messageRef);
4045                 mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_IMS,
4046                         SmsSession.Event.Format.SMS_FORMAT_3GPP2, getOutgoingSmsMessageId(result));
4047             } catch (RemoteException | RuntimeException e) {
4048                 handleRadioProxyExceptionForRR(HAL_SERVICE_MESSAGING, "sendImsCdmaSms", e);
4049             }
4050         }
4051     }
4052 
4053     @Override
iccTransmitApduBasicChannel(int cla, int instruction, int p1, int p2, int p3, String data, Message result)4054     public void iccTransmitApduBasicChannel(int cla, int instruction, int p1, int p2, int p3,
4055             String data, Message result) {
4056         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
4057         if (!simProxy.isEmpty()) {
4058             RILRequest rr = obtainRequest(RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC, result,
4059                     mRILDefaultWorkSource);
4060 
4061             if (RILJ_LOGD) {
4062                 if (TelephonyUtils.IS_DEBUGGABLE) {
4063                     riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4064                             + String.format(" cla = 0x%02X ins = 0x%02X", cla, instruction)
4065                             + String.format(" p1 = 0x%02X p2 = 0x%02X p3 = 0x%02X", p1, p2, p3)
4066                             + " data = " + data);
4067                 } else {
4068                     riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4069                 }
4070             }
4071 
4072             try {
4073                 simProxy.iccTransmitApduBasicChannel(
4074                         rr.mSerial, cla, instruction, p1, p2, p3, data);
4075             } catch (RemoteException | RuntimeException e) {
4076                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "iccTransmitApduBasicChannel", e);
4077             }
4078         }
4079     }
4080 
4081     @Override
iccOpenLogicalChannel(String aid, int p2, Message result)4082     public void iccOpenLogicalChannel(String aid, int p2, Message result) {
4083         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
4084         if (!simProxy.isEmpty()) {
4085             RILRequest rr = obtainRequest(RIL_REQUEST_SIM_OPEN_CHANNEL, result,
4086                     mRILDefaultWorkSource);
4087 
4088             if (RILJ_LOGD) {
4089                 if (TelephonyUtils.IS_DEBUGGABLE) {
4090                     riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4091                             + " aid = " + aid + " p2 = " + p2);
4092                 } else {
4093                     riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4094                 }
4095             }
4096 
4097             try {
4098                 simProxy.iccOpenLogicalChannel(rr.mSerial, RILUtils.convertNullToEmptyString(aid),
4099                         p2);
4100             } catch (RemoteException | RuntimeException e) {
4101                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "iccOpenLogicalChannel", e);
4102             }
4103         }
4104     }
4105 
4106     @Override
iccCloseLogicalChannel(int channel, boolean isEs10, Message result)4107     public void iccCloseLogicalChannel(int channel, boolean isEs10, Message result) {
4108         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
4109         if (!simProxy.isEmpty()) {
4110             RILRequest rr = obtainRequest(RIL_REQUEST_SIM_CLOSE_CHANNEL, result,
4111                     mRILDefaultWorkSource);
4112 
4113             if (RILJ_LOGD) {
4114                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4115                         + " channel = " + channel + " isEs10 = " + isEs10);
4116             }
4117             try {
4118                 simProxy.iccCloseLogicalChannel(rr.mSerial, channel, isEs10);
4119             } catch (RemoteException | RuntimeException e) {
4120                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "iccCloseLogicalChannel", e);
4121             }
4122         }
4123     }
4124 
4125     @Override
iccTransmitApduLogicalChannel(int channel, int cla, int instruction, int p1, int p2, int p3, String data, boolean isEs10Command, Message result)4126     public void iccTransmitApduLogicalChannel(int channel, int cla, int instruction, int p1, int p2,
4127             int p3, String data, boolean isEs10Command, Message result) {
4128         if (channel <= 0) {
4129             throw new RuntimeException(
4130                     "Invalid channel in iccTransmitApduLogicalChannel: " + channel);
4131         }
4132 
4133         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
4134         if (!simProxy.isEmpty()) {
4135             RILRequest rr = obtainRequest(RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL, result,
4136                     mRILDefaultWorkSource);
4137 
4138             if (RILJ_LOGD) {
4139                 if (TelephonyUtils.IS_DEBUGGABLE) {
4140                     riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4141                             + String.format(" channel = %d", channel)
4142                             + String.format(" cla = 0x%02X ins = 0x%02X", cla, instruction)
4143                             + String.format(" p1 = 0x%02X p2 = 0x%02X p3 = 0x%02X", p1, p2, p3)
4144                             + " isEs10Command = " + isEs10Command
4145                             + " data = " + data);
4146                 } else {
4147                     riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4148                 }
4149             }
4150 
4151             try {
4152                 simProxy.iccTransmitApduLogicalChannel(
4153                         rr.mSerial, channel, cla, instruction, p1, p2, p3, data, isEs10Command);
4154             } catch (RemoteException | RuntimeException e) {
4155                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "iccTransmitApduLogicalChannel", e);
4156             }
4157         }
4158     }
4159 
4160     @Override
nvReadItem(int itemID, Message result, WorkSource workSource)4161     public void nvReadItem(int itemID, Message result, WorkSource workSource) {
4162         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class, result);
4163         if (!modemProxy.isEmpty()) {
4164             RILRequest rr = obtainRequest(RIL_REQUEST_NV_READ_ITEM, result,
4165                     getDefaultWorkSourceIfInvalid(workSource));
4166 
4167             if (RILJ_LOGD) {
4168                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4169                         + " itemId = " + itemID);
4170             }
4171 
4172             try {
4173                 modemProxy.nvReadItem(rr.mSerial, itemID);
4174             } catch (RemoteException | RuntimeException e) {
4175                 handleRadioProxyExceptionForRR(HAL_SERVICE_MODEM, "nvReadItem", e);
4176             }
4177         }
4178     }
4179 
4180     @Override
nvWriteItem(int itemId, String itemValue, Message result, WorkSource workSource)4181     public void nvWriteItem(int itemId, String itemValue, Message result, WorkSource workSource) {
4182         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class, result);
4183         if (!modemProxy.isEmpty()) {
4184             RILRequest rr = obtainRequest(RIL_REQUEST_NV_WRITE_ITEM, result,
4185                     getDefaultWorkSourceIfInvalid(workSource));
4186 
4187             if (RILJ_LOGD) {
4188                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4189                         + " itemId = " + itemId + " itemValue = " + itemValue);
4190             }
4191 
4192             try {
4193                 modemProxy.nvWriteItem(rr.mSerial, itemId,
4194                         RILUtils.convertNullToEmptyString(itemValue));
4195             } catch (RemoteException | RuntimeException e) {
4196                 handleRadioProxyExceptionForRR(HAL_SERVICE_MODEM, "nvWriteItem", e);
4197             }
4198         }
4199     }
4200 
4201     @Override
nvWriteCdmaPrl(byte[] preferredRoamingList, Message result)4202     public void nvWriteCdmaPrl(byte[] preferredRoamingList, Message result) {
4203         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class, result);
4204         if (!modemProxy.isEmpty()) {
4205             RILRequest rr = obtainRequest(RIL_REQUEST_NV_WRITE_CDMA_PRL, result,
4206                     mRILDefaultWorkSource);
4207 
4208             if (RILJ_LOGD) {
4209                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4210                         + " PreferredRoamingList = 0x"
4211                         + IccUtils.bytesToHexString(preferredRoamingList));
4212             }
4213 
4214             try {
4215                 modemProxy.nvWriteCdmaPrl(rr.mSerial, preferredRoamingList);
4216             } catch (RemoteException | RuntimeException e) {
4217                 handleRadioProxyExceptionForRR(HAL_SERVICE_MODEM, "nvWriteCdmaPrl", e);
4218             }
4219         }
4220     }
4221 
4222     @Override
nvResetConfig(int resetType, Message result)4223     public void nvResetConfig(int resetType, Message result) {
4224         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class, result);
4225         if (!modemProxy.isEmpty()) {
4226             RILRequest rr = obtainRequest(RIL_REQUEST_NV_RESET_CONFIG, result,
4227                     mRILDefaultWorkSource);
4228 
4229             if (RILJ_LOGD) {
4230                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4231                         + " resetType = " + resetType);
4232             }
4233 
4234             try {
4235                 modemProxy.nvResetConfig(rr.mSerial, resetType);
4236             } catch (RemoteException | RuntimeException e) {
4237                 handleRadioProxyExceptionForRR(HAL_SERVICE_MODEM, "nvResetConfig", e);
4238             }
4239         }
4240     }
4241 
4242     @Override
setUiccSubscription(int slotId, int appIndex, int subId, int subStatus, Message result)4243     public void setUiccSubscription(int slotId, int appIndex, int subId, int subStatus,
4244             Message result) {
4245         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
4246         if (!simProxy.isEmpty()) {
4247             RILRequest rr = obtainRequest(RIL_REQUEST_SET_UICC_SUBSCRIPTION, result,
4248                     mRILDefaultWorkSource);
4249 
4250             if (RILJ_LOGD) {
4251                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4252                         + " slot = " + slotId + " appIndex = " + appIndex
4253                         + " subId = " + subId + " subStatus = " + subStatus);
4254             }
4255 
4256             try {
4257                 simProxy.setUiccSubscription(rr.mSerial, slotId, appIndex, subId, subStatus);
4258             } catch (RemoteException | RuntimeException e) {
4259                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "setUiccSubscription", e);
4260             }
4261         }
4262     }
4263 
4264     /**
4265      * Whether the device modem supports reporting the EID in either the slot or card status or
4266      * through ATR.
4267      * @return true if the modem supports EID.
4268      */
4269     @Override
supportsEid()4270     public boolean supportsEid() {
4271         // EID should be supported as long as HAL >= 1.2.
4272         //  - in HAL 1.2 we have EID through ATR
4273         //  - in later HAL versions we also have EID through slot / card status.
4274         return mHalVersion.get(HAL_SERVICE_RADIO).greaterOrEqual(RADIO_HAL_VERSION_1_2);
4275     }
4276 
4277     @Override
setDataAllowed(boolean allowed, Message result)4278     public void setDataAllowed(boolean allowed, Message result) {
4279         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class, result);
4280         if (!dataProxy.isEmpty()) {
4281             RILRequest rr = obtainRequest(RIL_REQUEST_ALLOW_DATA, result, mRILDefaultWorkSource);
4282 
4283             if (RILJ_LOGD) {
4284                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4285                         + " allowed = " + allowed);
4286             }
4287 
4288             try {
4289                 dataProxy.setDataAllowed(rr.mSerial, allowed);
4290             } catch (RemoteException | RuntimeException e) {
4291                 handleRadioProxyExceptionForRR(HAL_SERVICE_DATA, "setDataAllowed", e);
4292             }
4293         }
4294     }
4295 
4296     @Override
getHardwareConfig(Message result)4297     public void getHardwareConfig(Message result) {
4298         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class, result);
4299         if (!modemProxy.isEmpty()) {
4300             RILRequest rr = obtainRequest(RIL_REQUEST_GET_HARDWARE_CONFIG, result,
4301                     mRILDefaultWorkSource);
4302 
4303             // Do not log function args for privacy
4304             if (RILJ_LOGD) {
4305                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4306             }
4307 
4308             try {
4309                 modemProxy.getHardwareConfig(rr.mSerial);
4310             } catch (RemoteException | RuntimeException e) {
4311                 handleRadioProxyExceptionForRR(HAL_SERVICE_MODEM, "getHardwareConfig", e);
4312             }
4313         }
4314     }
4315 
4316     @Override
requestIccSimAuthentication(int authContext, String data, String aid, Message result)4317     public void requestIccSimAuthentication(int authContext, String data, String aid,
4318             Message result) {
4319         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
4320         if (!simProxy.isEmpty()) {
4321             RILRequest rr = obtainRequest(RIL_REQUEST_SIM_AUTHENTICATION, result,
4322                     mRILDefaultWorkSource);
4323 
4324             // Do not log function args for privacy
4325             if (RILJ_LOGD) {
4326                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4327             }
4328 
4329             try {
4330                 simProxy.requestIccSimAuthentication(rr.mSerial, authContext,
4331                         RILUtils.convertNullToEmptyString(data),
4332                         RILUtils.convertNullToEmptyString(aid));
4333             } catch (RemoteException | RuntimeException e) {
4334                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "requestIccSimAuthentication", e);
4335             }
4336         }
4337     }
4338 
4339     @Override
setDataProfile(DataProfile[] dps, boolean isRoaming, Message result)4340     public void setDataProfile(DataProfile[] dps, boolean isRoaming, Message result) {
4341         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class, result);
4342         if (!dataProxy.isEmpty()) {
4343             RILRequest rr = obtainRequest(RIL_REQUEST_SET_DATA_PROFILE, result,
4344                     mRILDefaultWorkSource);
4345 
4346             if (RILJ_LOGD) {
4347                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4348                         + " with data profiles : ");
4349                 for (DataProfile profile : dps) {
4350                     riljLog(profile.toString());
4351                 }
4352             }
4353 
4354             try {
4355                 dataProxy.setDataProfile(rr.mSerial, dps, isRoaming);
4356             } catch (RemoteException | RuntimeException e) {
4357                 handleRadioProxyExceptionForRR(HAL_SERVICE_DATA, "setDataProfile", e);
4358             }
4359         }
4360     }
4361 
4362     @Override
requestShutdown(Message result)4363     public void requestShutdown(Message result) {
4364         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class, result);
4365         if (!modemProxy.isEmpty()) {
4366             RILRequest rr = obtainRequest(RIL_REQUEST_SHUTDOWN, result, mRILDefaultWorkSource);
4367 
4368             if (RILJ_LOGD) {
4369                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4370             }
4371 
4372             try {
4373                 modemProxy.requestShutdown(rr.mSerial);
4374             } catch (RemoteException | RuntimeException e) {
4375                 handleRadioProxyExceptionForRR(HAL_SERVICE_MODEM, "requestShutdown", e);
4376             }
4377         }
4378     }
4379 
4380     @Override
getRadioCapability(Message result)4381     public void getRadioCapability(Message result) {
4382         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class, result);
4383         if (!modemProxy.isEmpty()) {
4384             RILRequest rr = obtainRequest(RIL_REQUEST_GET_RADIO_CAPABILITY, result,
4385                     mRILDefaultWorkSource);
4386 
4387             if (RILJ_LOGD) {
4388                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4389             }
4390 
4391             try {
4392                 modemProxy.getRadioCapability(rr.mSerial);
4393             } catch (RemoteException | RuntimeException e) {
4394                 handleRadioProxyExceptionForRR(HAL_SERVICE_MODEM, "getRadioCapability", e);
4395             }
4396         }
4397     }
4398 
4399     @Override
setRadioCapability(RadioCapability rc, Message result)4400     public void setRadioCapability(RadioCapability rc, Message result) {
4401         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class, result);
4402         if (!modemProxy.isEmpty()) {
4403             RILRequest rr = obtainRequest(RIL_REQUEST_SET_RADIO_CAPABILITY, result,
4404                     mRILDefaultWorkSource);
4405 
4406             if (RILJ_LOGD) {
4407                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4408                         + " RadioCapability = " + rc.toString());
4409             }
4410 
4411             try {
4412                 modemProxy.setRadioCapability(rr.mSerial, rc);
4413             } catch (Exception e) {
4414                 handleRadioProxyExceptionForRR(HAL_SERVICE_MODEM, "setRadioCapability", e);
4415             }
4416         }
4417     }
4418 
4419     @Override
startLceService(int reportIntervalMs, boolean pullMode, Message result)4420     public void startLceService(int reportIntervalMs, boolean pullMode, Message result) {
4421         if (mHalVersion.get(HAL_SERVICE_RADIO).greaterOrEqual(RADIO_HAL_VERSION_1_2)) {
4422             // We have a 1.2 or later radio, so the LCE 1.0 LCE service control path is unused.
4423             // Instead the LCE functionality is always-on and provides unsolicited indications.
4424             if (RILJ_LOGD) Rlog.d(RILJ_LOG_TAG, "startLceService: REQUEST_NOT_SUPPORTED");
4425             if (result != null) {
4426                 AsyncResult.forMessage(result, null,
4427                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
4428                 result.sendToTarget();
4429             }
4430             return;
4431         }
4432 
4433         IRadio radioProxy = getRadioProxy(result);
4434         if (radioProxy != null) {
4435             RILRequest rr = obtainRequest(RIL_REQUEST_START_LCE, result, mRILDefaultWorkSource);
4436 
4437             if (RILJ_LOGD) {
4438                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4439                         + " reportIntervalMs = " + reportIntervalMs + " pullMode = " + pullMode);
4440             }
4441 
4442             try {
4443                 radioProxy.startLceService(rr.mSerial, reportIntervalMs, pullMode);
4444             } catch (RemoteException | RuntimeException e) {
4445                 handleRadioProxyExceptionForRR(HAL_SERVICE_RADIO, "startLceService", e);
4446             }
4447         }
4448     }
4449 
4450     @Override
stopLceService(Message result)4451     public void stopLceService(Message result) {
4452         if (mHalVersion.get(HAL_SERVICE_RADIO).greaterOrEqual(RADIO_HAL_VERSION_1_2)) {
4453             // We have a 1.2 or later radio, so the LCE 1.0 LCE service control is unused.
4454             // Instead the LCE functionality is always-on and provides unsolicited indications.
4455             if (RILJ_LOGD) Rlog.d(RILJ_LOG_TAG, "stopLceService: REQUEST_NOT_SUPPORTED");
4456             if (result != null) {
4457                 AsyncResult.forMessage(result, null,
4458                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
4459                 result.sendToTarget();
4460             }
4461             return;
4462         }
4463 
4464         IRadio radioProxy = getRadioProxy(result);
4465         if (radioProxy != null) {
4466             RILRequest rr = obtainRequest(RIL_REQUEST_STOP_LCE, result, mRILDefaultWorkSource);
4467 
4468             if (RILJ_LOGD) {
4469                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4470             }
4471 
4472             try {
4473                 radioProxy.stopLceService(rr.mSerial);
4474             } catch (RemoteException | RuntimeException e) {
4475                 handleRadioProxyExceptionForRR(HAL_SERVICE_RADIO, "stopLceService", e);
4476             }
4477         }
4478     }
4479 
4480     /**
4481      * Control the data throttling at modem.
4482      *
4483      * @param result Message that will be sent back to the requester
4484      * @param workSource calling Worksource
4485      * @param dataThrottlingAction the DataThrottlingAction that is being requested. Defined in
4486      *      android.hardware.radio@1.6.types.
4487      * @param completionWindowMillis milliseconds in which full throttling has to be achieved.
4488      */
4489     @Override
setDataThrottling(Message result, WorkSource workSource, int dataThrottlingAction, long completionWindowMillis)4490     public void setDataThrottling(Message result, WorkSource workSource, int dataThrottlingAction,
4491             long completionWindowMillis) {
4492         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class, result);
4493         if (dataProxy.isEmpty()) return;
4494         if (mHalVersion.get(HAL_SERVICE_DATA).greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
4495             RILRequest rr = obtainRequest(RIL_REQUEST_SET_DATA_THROTTLING, result,
4496                     getDefaultWorkSourceIfInvalid(workSource));
4497 
4498             if (RILJ_LOGD) {
4499                 riljLog(rr.serialString() + "> "
4500                         + RILUtils.requestToString(rr.mRequest)
4501                         + " dataThrottlingAction = " + dataThrottlingAction
4502                         + " completionWindowMillis " + completionWindowMillis);
4503             }
4504 
4505             try {
4506                 dataProxy.setDataThrottling(rr.mSerial, (byte) dataThrottlingAction,
4507                         completionWindowMillis);
4508             } catch (RemoteException | RuntimeException e) {
4509                 handleRadioProxyExceptionForRR(HAL_SERVICE_DATA, "setDataThrottling", e);
4510             }
4511         } else {
4512             if (RILJ_LOGD) Rlog.d(RILJ_LOG_TAG, "setDataThrottling: REQUEST_NOT_SUPPORTED");
4513             if (result != null) {
4514                 AsyncResult.forMessage(result, null,
4515                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
4516                 result.sendToTarget();
4517             }
4518         }
4519     }
4520 
4521     /**
4522      * This will only be called if the LCE service is started in PULL mode, which is
4523      * only enabled when using Radio HAL versions 1.1 and earlier.
4524      *
4525      * It is still possible for vendors to override this behavior and use the 1.1 version
4526      * of LCE; however, this is strongly discouraged and this functionality will be removed
4527      * when HAL 1.x support is dropped.
4528      *
4529      * @deprecated HAL 1.2 and later use an always-on LCE that relies on indications.
4530      */
4531     @Deprecated
4532     @Override
pullLceData(Message result)4533     public void pullLceData(Message result) {
4534         if (mHalVersion.get(HAL_SERVICE_RADIO).greaterOrEqual(RADIO_HAL_VERSION_1_2)) {
4535             // We have a 1.2 or later radio, so the LCE 1.0 LCE service control path is unused.
4536             // Instead the LCE functionality is always-on and provides unsolicited indications.
4537             if (RILJ_LOGD) Rlog.d(RILJ_LOG_TAG, "pullLceData: REQUEST_NOT_SUPPORTED");
4538             if (result != null) {
4539                 AsyncResult.forMessage(result, null,
4540                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
4541                 result.sendToTarget();
4542             }
4543             return;
4544         }
4545 
4546         IRadio radioProxy = getRadioProxy(result);
4547         if (radioProxy != null) {
4548             RILRequest rr = obtainRequest(RIL_REQUEST_PULL_LCEDATA, result, mRILDefaultWorkSource);
4549 
4550             if (RILJ_LOGD) {
4551                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4552             }
4553 
4554             try {
4555                 radioProxy.pullLceData(rr.mSerial);
4556             } catch (RemoteException | RuntimeException e) {
4557                 handleRadioProxyExceptionForRR(HAL_SERVICE_RADIO, "pullLceData", e);
4558             }
4559         }
4560     }
4561 
4562     @Override
getModemActivityInfo(Message result, WorkSource workSource)4563     public void getModemActivityInfo(Message result, WorkSource workSource) {
4564         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class, result);
4565         if (!modemProxy.isEmpty()) {
4566             RILRequest rr = obtainRequest(RIL_REQUEST_GET_ACTIVITY_INFO, result,
4567                     getDefaultWorkSourceIfInvalid(workSource));
4568 
4569             if (RILJ_LOGD) {
4570                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4571             }
4572 
4573             try {
4574                 modemProxy.getModemActivityInfo(rr.mSerial);
4575                 Message msg =
4576                         mRilHandler.obtainMessage(EVENT_BLOCKING_RESPONSE_TIMEOUT, rr.mSerial);
4577                 mRilHandler.sendMessageDelayed(msg, DEFAULT_BLOCKING_MESSAGE_RESPONSE_TIMEOUT_MS);
4578             } catch (RemoteException | RuntimeException e) {
4579                 handleRadioProxyExceptionForRR(HAL_SERVICE_MODEM, "getModemActivityInfo", e);
4580             }
4581         }
4582     }
4583 
4584     @Override
setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules, Message result, WorkSource workSource)4585     public void setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules,
4586             Message result, WorkSource workSource) {
4587         Objects.requireNonNull(carrierRestrictionRules, "Carrier restriction cannot be null.");
4588 
4589         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
4590         if (!simProxy.isEmpty()) {
4591             RILRequest rr = obtainRequest(RIL_REQUEST_SET_ALLOWED_CARRIERS, result,
4592                     getDefaultWorkSourceIfInvalid(workSource));
4593 
4594             if (RILJ_LOGD) {
4595                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4596                         + " params: " + carrierRestrictionRules);
4597             }
4598 
4599             try {
4600                 simProxy.setAllowedCarriers(rr.mSerial, carrierRestrictionRules, result);
4601             } catch (RemoteException | RuntimeException e) {
4602                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "setAllowedCarriers", e);
4603             }
4604         }
4605     }
4606 
4607     @Override
getAllowedCarriers(Message result, WorkSource workSource)4608     public void getAllowedCarriers(Message result, WorkSource workSource) {
4609         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
4610         if (!simProxy.isEmpty()) {
4611             RILRequest rr = obtainRequest(RIL_REQUEST_GET_ALLOWED_CARRIERS, result,
4612                     getDefaultWorkSourceIfInvalid(workSource));
4613 
4614             if (RILJ_LOGD) {
4615                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4616             }
4617 
4618             try {
4619                 simProxy.getAllowedCarriers(rr.mSerial);
4620             } catch (RemoteException | RuntimeException e) {
4621                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "getAllowedCarriers", e);
4622             }
4623         }
4624     }
4625 
4626     @Override
sendDeviceState(int stateType, boolean state, Message result)4627     public void sendDeviceState(int stateType, boolean state, Message result) {
4628         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class, result);
4629         if (!modemProxy.isEmpty()) {
4630             RILRequest rr = obtainRequest(RIL_REQUEST_SEND_DEVICE_STATE, result,
4631                     mRILDefaultWorkSource);
4632 
4633             if (RILJ_LOGD) {
4634                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest) + " "
4635                         + stateType + ":" + state);
4636             }
4637 
4638             try {
4639                 modemProxy.sendDeviceState(rr.mSerial, stateType, state);
4640             } catch (RemoteException | RuntimeException e) {
4641                 handleRadioProxyExceptionForRR(HAL_SERVICE_MODEM, "sendDeviceState", e);
4642             }
4643         }
4644     }
4645 
4646     @Override
setUnsolResponseFilter(int filter, Message result)4647     public void setUnsolResponseFilter(int filter, Message result) {
4648         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
4649         if (!networkProxy.isEmpty()) {
4650             RILRequest rr = obtainRequest(RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER, result,
4651                     mRILDefaultWorkSource);
4652 
4653             if (RILJ_LOGD) {
4654                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4655                         + " " + filter);
4656             }
4657 
4658             try {
4659                 networkProxy.setIndicationFilter(rr.mSerial, filter);
4660             } catch (RemoteException | RuntimeException e) {
4661                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "setIndicationFilter", e);
4662             }
4663         }
4664     }
4665 
4666     @Override
setSignalStrengthReportingCriteria( @onNull List<SignalThresholdInfo> signalThresholdInfos, @Nullable Message result)4667     public void setSignalStrengthReportingCriteria(
4668             @NonNull List<SignalThresholdInfo> signalThresholdInfos, @Nullable Message result) {
4669         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
4670         if (networkProxy.isEmpty()) return;
4671         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_1_2)) {
4672             RILRequest rr = obtainRequest(RIL_REQUEST_SET_SIGNAL_STRENGTH_REPORTING_CRITERIA,
4673                     result, mRILDefaultWorkSource);
4674 
4675             if (RILJ_LOGD) {
4676                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4677             }
4678 
4679             try {
4680                 networkProxy.setSignalStrengthReportingCriteria(rr.mSerial, signalThresholdInfos);
4681             } catch (RemoteException | RuntimeException e) {
4682                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK,
4683                         "setSignalStrengthReportingCriteria", e);
4684             }
4685         } else {
4686             riljLoge("setSignalStrengthReportingCriteria ignored on IRadio version less than 1.2");
4687         }
4688     }
4689 
4690     @Override
setLinkCapacityReportingCriteria(int hysteresisMs, int hysteresisDlKbps, int hysteresisUlKbps, int[] thresholdsDlKbps, int[] thresholdsUlKbps, int ran, Message result)4691     public void setLinkCapacityReportingCriteria(int hysteresisMs, int hysteresisDlKbps,
4692             int hysteresisUlKbps, int[] thresholdsDlKbps, int[] thresholdsUlKbps, int ran,
4693             Message result) {
4694         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
4695         if (networkProxy.isEmpty()) return;
4696         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_1_2)) {
4697             RILRequest rr = obtainRequest(RIL_REQUEST_SET_LINK_CAPACITY_REPORTING_CRITERIA, result,
4698                     mRILDefaultWorkSource);
4699 
4700             if (RILJ_LOGD) {
4701                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4702             }
4703 
4704             try {
4705                 networkProxy.setLinkCapacityReportingCriteria(rr.mSerial, hysteresisMs,
4706                         hysteresisDlKbps, hysteresisUlKbps, thresholdsDlKbps, thresholdsUlKbps,
4707                         ran);
4708             } catch (RemoteException | RuntimeException e) {
4709                 handleRadioProxyExceptionForRR(
4710                         HAL_SERVICE_NETWORK, "setLinkCapacityReportingCriteria", e);
4711             }
4712         } else {
4713             riljLoge("setLinkCapacityReportingCriteria ignored on IRadio version less than 1.2");
4714         }
4715     }
4716 
4717     @Override
setSimCardPower(int state, Message result, WorkSource workSource)4718     public void setSimCardPower(int state, Message result, WorkSource workSource) {
4719         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
4720         if (!simProxy.isEmpty()) {
4721             RILRequest rr = obtainRequest(RIL_REQUEST_SET_SIM_CARD_POWER, result,
4722                     getDefaultWorkSourceIfInvalid(workSource));
4723 
4724             if (RILJ_LOGD) {
4725                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4726                         + " " + state);
4727             }
4728 
4729             try {
4730                 simProxy.setSimCardPower(rr.mSerial, state, result);
4731             } catch (RemoteException | RuntimeException e) {
4732                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "setSimCardPower", e);
4733             }
4734         }
4735     }
4736 
4737     @Override
setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo, Message result)4738     public void setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo,
4739             Message result) {
4740         Objects.requireNonNull(imsiEncryptionInfo, "ImsiEncryptionInfo cannot be null.");
4741         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
4742         if (simProxy.isEmpty()) return;
4743         if (mHalVersion.get(HAL_SERVICE_SIM).greaterOrEqual(RADIO_HAL_VERSION_1_1)) {
4744             RILRequest rr = obtainRequest(RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION, result,
4745                     mRILDefaultWorkSource);
4746             if (RILJ_LOGD) {
4747                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4748             }
4749 
4750             try {
4751                 simProxy.setCarrierInfoForImsiEncryption(rr.mSerial, imsiEncryptionInfo);
4752             } catch (RemoteException | RuntimeException e) {
4753                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM,
4754                         "setCarrierInfoForImsiEncryption", e);
4755             }
4756         } else {
4757             if (RILJ_LOGD) {
4758                 Rlog.d(RILJ_LOG_TAG, "setCarrierInfoForImsiEncryption: REQUEST_NOT_SUPPORTED");
4759             }
4760             if (result != null) {
4761                 AsyncResult.forMessage(result, null,
4762                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
4763                 result.sendToTarget();
4764             }
4765         }
4766     }
4767 
4768     @Override
startNattKeepalive(int contextId, KeepalivePacketData packetData, int intervalMillis, Message result)4769     public void startNattKeepalive(int contextId, KeepalivePacketData packetData,
4770             int intervalMillis, Message result) {
4771         Objects.requireNonNull(packetData, "KeepaliveRequest cannot be null.");
4772         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class, result);
4773         if (dataProxy.isEmpty()) return;
4774         if (mHalVersion.get(HAL_SERVICE_DATA).greaterOrEqual(RADIO_HAL_VERSION_1_1)) {
4775             RILRequest rr = obtainRequest(RIL_REQUEST_START_KEEPALIVE, result,
4776                     mRILDefaultWorkSource);
4777 
4778             if (RILJ_LOGD) {
4779                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4780             }
4781 
4782             try {
4783                 dataProxy.startKeepalive(rr.mSerial, contextId, packetData, intervalMillis, result);
4784             } catch (RemoteException | RuntimeException e) {
4785                 handleRadioProxyExceptionForRR(HAL_SERVICE_DATA, "startNattKeepalive", e);
4786             }
4787         } else {
4788             if (RILJ_LOGD) Rlog.d(RILJ_LOG_TAG, "startNattKeepalive: REQUEST_NOT_SUPPORTED");
4789             if (result != null) {
4790                 AsyncResult.forMessage(result, null,
4791                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
4792                 result.sendToTarget();
4793             }
4794         }
4795     }
4796 
4797     @Override
stopNattKeepalive(int sessionHandle, Message result)4798     public void stopNattKeepalive(int sessionHandle, Message result) {
4799         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class, result);
4800         if (dataProxy.isEmpty()) return;
4801         if (mHalVersion.get(HAL_SERVICE_DATA).greaterOrEqual(RADIO_HAL_VERSION_1_1)) {
4802             RILRequest rr = obtainRequest(RIL_REQUEST_STOP_KEEPALIVE, result,
4803                     mRILDefaultWorkSource);
4804 
4805             if (RILJ_LOGD) {
4806                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4807             }
4808 
4809             try {
4810                 dataProxy.stopKeepalive(rr.mSerial, sessionHandle);
4811             } catch (RemoteException | RuntimeException e) {
4812                 handleRadioProxyExceptionForRR(HAL_SERVICE_DATA, "stopNattKeepalive", e);
4813             }
4814         } else {
4815             if (RILJ_LOGD) Rlog.d(RILJ_LOG_TAG, "stopNattKeepalive: REQUEST_NOT_SUPPORTED");
4816             if (result != null) {
4817                 AsyncResult.forMessage(result, null,
4818                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
4819                 result.sendToTarget();
4820             }
4821         }
4822     }
4823 
4824     @Override
getIMEI(Message result)4825     public void getIMEI(Message result) {
4826         throw new RuntimeException("getIMEI not expected to be called");
4827     }
4828 
4829     @Override
getIMEISV(Message result)4830     public void getIMEISV(Message result) {
4831         throw new RuntimeException("getIMEISV not expected to be called");
4832     }
4833 
4834     /**
4835      * @deprecated
4836      */
4837     @Deprecated
4838     @Override
getLastPdpFailCause(Message result)4839     public void getLastPdpFailCause(Message result) {
4840         throw new RuntimeException("getLastPdpFailCause not expected to be called");
4841     }
4842 
4843     /**
4844      * The preferred new alternative to getLastPdpFailCause
4845      */
4846     @Override
getLastDataCallFailCause(Message result)4847     public void getLastDataCallFailCause(Message result) {
4848         throw new RuntimeException("getLastDataCallFailCause not expected to be called");
4849     }
4850 
4851     /**
4852      * Enable or disable uicc applications on the SIM.
4853      *
4854      * @param enable whether to enable or disable uicc applications.
4855      * @param result a Message to return to the requester
4856      */
4857     @Override
enableUiccApplications(boolean enable, Message result)4858     public void enableUiccApplications(boolean enable, Message result) {
4859         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
4860         if (simProxy.isEmpty()) return;
4861         if (mHalVersion.get(HAL_SERVICE_SIM).greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
4862             RILRequest rr = obtainRequest(RIL_REQUEST_ENABLE_UICC_APPLICATIONS, result,
4863                     mRILDefaultWorkSource);
4864 
4865             if (RILJ_LOGD) {
4866                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4867                         + " " + enable);
4868             }
4869 
4870             try {
4871                 simProxy.enableUiccApplications(rr.mSerial, enable);
4872             } catch (RemoteException | RuntimeException e) {
4873                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "enableUiccApplications", e);
4874             }
4875         } else {
4876             if (RILJ_LOGD) Rlog.d(RILJ_LOG_TAG, "enableUiccApplications: REQUEST_NOT_SUPPORTED");
4877             if (result != null) {
4878                 AsyncResult.forMessage(result, null,
4879                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
4880                 result.sendToTarget();
4881             }
4882         }
4883     }
4884 
4885     /**
4886      * Whether uicc applications are enabled or not.
4887      *
4888      * @param result a Message to return to the requester
4889      */
4890     @Override
areUiccApplicationsEnabled(Message result)4891     public void areUiccApplicationsEnabled(Message result) {
4892         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
4893         if (simProxy.isEmpty()) return;
4894         if (mHalVersion.get(HAL_SERVICE_SIM).greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
4895             RILRequest rr = obtainRequest(RIL_REQUEST_GET_UICC_APPLICATIONS_ENABLEMENT, result,
4896                     mRILDefaultWorkSource);
4897 
4898             if (RILJ_LOGD) {
4899                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4900             }
4901 
4902             try {
4903                 simProxy.areUiccApplicationsEnabled(rr.mSerial);
4904             } catch (RemoteException | RuntimeException e) {
4905                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "areUiccApplicationsEnabled", e);
4906             }
4907         } else {
4908             if (RILJ_LOGD) {
4909                 Rlog.d(RILJ_LOG_TAG, "areUiccApplicationsEnabled: REQUEST_NOT_SUPPORTED");
4910             }
4911             if (result != null) {
4912                 AsyncResult.forMessage(result, null,
4913                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
4914                 result.sendToTarget();
4915             }
4916         }
4917     }
4918 
4919     /**
4920      * Whether {@link #enableUiccApplications} is supported, which is supported in 1.5 version.
4921      */
4922     @Override
canToggleUiccApplicationsEnablement()4923     public boolean canToggleUiccApplicationsEnablement() {
4924         return !getRadioServiceProxy(RadioSimProxy.class, null).isEmpty()
4925                 && mHalVersion.get(HAL_SERVICE_SIM).greaterOrEqual(RADIO_HAL_VERSION_1_5);
4926     }
4927 
4928     @Override
resetRadio(Message result)4929     public void resetRadio(Message result) {
4930         throw new RuntimeException("resetRadio not expected to be called");
4931     }
4932 
4933     /**
4934      * {@inheritDoc}
4935      */
4936     @Override
handleCallSetupRequestFromSim(boolean accept, Message result)4937     public void handleCallSetupRequestFromSim(boolean accept, Message result) {
4938         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class, result);
4939         if (!voiceProxy.isEmpty()) {
4940             RILRequest rr = obtainRequest(RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM,
4941                     result, mRILDefaultWorkSource);
4942 
4943             if (RILJ_LOGD) {
4944                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4945             }
4946 
4947             try {
4948                 voiceProxy.handleStkCallSetupRequestFromSim(rr.mSerial, accept);
4949             } catch (RemoteException | RuntimeException e) {
4950                 handleRadioProxyExceptionForRR(
4951                         HAL_SERVICE_VOICE, "handleStkCallSetupRequestFromSim", e);
4952             }
4953         }
4954     }
4955 
4956     /**
4957      * {@inheritDoc}
4958      */
4959     @Override
getBarringInfo(Message result)4960     public void getBarringInfo(Message result) {
4961         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
4962         if (networkProxy.isEmpty()) return;
4963         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
4964             RILRequest rr = obtainRequest(RIL_REQUEST_GET_BARRING_INFO, result,
4965                     mRILDefaultWorkSource);
4966 
4967             if (RILJ_LOGD) {
4968                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4969             }
4970 
4971             try {
4972                 networkProxy.getBarringInfo(rr.mSerial);
4973             } catch (RemoteException | RuntimeException e) {
4974                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "getBarringInfo", e);
4975             }
4976         } else {
4977             if (RILJ_LOGD) Rlog.d(RILJ_LOG_TAG, "getBarringInfo: REQUEST_NOT_SUPPORTED");
4978             if (result != null) {
4979                 AsyncResult.forMessage(result, null,
4980                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
4981                 result.sendToTarget();
4982             }
4983         }
4984     }
4985 
4986     /**
4987      * {@inheritDoc}
4988      */
4989     @Override
allocatePduSessionId(Message result)4990     public void allocatePduSessionId(Message result) {
4991         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class, result);
4992         if (dataProxy.isEmpty()) return;
4993         if (mHalVersion.get(HAL_SERVICE_DATA).greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
4994             RILRequest rr = obtainRequest(RIL_REQUEST_ALLOCATE_PDU_SESSION_ID, result,
4995                     mRILDefaultWorkSource);
4996             if (RILJ_LOGD) {
4997                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4998             }
4999 
5000             try {
5001                 dataProxy.allocatePduSessionId(rr.mSerial);
5002             } catch (RemoteException e) {
5003                 handleRadioProxyExceptionForRR(HAL_SERVICE_DATA, "allocatePduSessionId", e);
5004             }
5005         } else {
5006             AsyncResult.forMessage(result, null,
5007                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5008             result.sendToTarget();
5009         }
5010     }
5011 
5012     /**
5013      * {@inheritDoc}
5014      */
5015     @Override
releasePduSessionId(Message result, int pduSessionId)5016     public void releasePduSessionId(Message result, int pduSessionId) {
5017         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class, result);
5018         if (dataProxy.isEmpty()) return;
5019         if (mHalVersion.get(HAL_SERVICE_DATA).greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
5020             RILRequest rr = obtainRequest(RIL_REQUEST_RELEASE_PDU_SESSION_ID, result,
5021                     mRILDefaultWorkSource);
5022             if (RILJ_LOGD) {
5023                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5024             }
5025 
5026             try {
5027                 dataProxy.releasePduSessionId(rr.mSerial, pduSessionId);
5028             } catch (RemoteException e) {
5029                 handleRadioProxyExceptionForRR(HAL_SERVICE_DATA, "releasePduSessionId", e);
5030             }
5031         } else {
5032             AsyncResult.forMessage(result, null,
5033                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5034             result.sendToTarget();
5035         }
5036     }
5037 
5038     /**
5039      * {@inheritDoc}
5040      */
5041     @Override
startHandover(Message result, int callId)5042     public void startHandover(Message result, int callId) {
5043         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class, result);
5044         if (dataProxy.isEmpty()) return;
5045         if (mHalVersion.get(HAL_SERVICE_DATA).greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
5046             RILRequest rr = obtainRequest(RIL_REQUEST_START_HANDOVER, result,
5047                     mRILDefaultWorkSource);
5048             if (RILJ_LOGD) {
5049                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5050             }
5051 
5052             try {
5053                 dataProxy.startHandover(rr.mSerial, callId);
5054             } catch (RemoteException e) {
5055                 handleRadioProxyExceptionForRR(HAL_SERVICE_DATA, "startHandover", e);
5056             }
5057         } else {
5058             if (RILJ_LOGD) Rlog.d(RILJ_LOG_TAG, "startHandover: REQUEST_NOT_SUPPORTED");
5059             if (result != null) {
5060                 AsyncResult.forMessage(result, null,
5061                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5062                 result.sendToTarget();
5063             }
5064         }
5065     }
5066 
5067     /**
5068      * {@inheritDoc}
5069      */
5070     @Override
cancelHandover(Message result, int callId)5071     public void cancelHandover(Message result, int callId) {
5072         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class, result);
5073         if (dataProxy.isEmpty()) return;
5074         if (mHalVersion.get(HAL_SERVICE_DATA).greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
5075             RILRequest rr = obtainRequest(RIL_REQUEST_CANCEL_HANDOVER, result,
5076                     mRILDefaultWorkSource);
5077             if (RILJ_LOGD) {
5078                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5079             }
5080 
5081             try {
5082                 dataProxy.cancelHandover(rr.mSerial, callId);
5083             } catch (RemoteException e) {
5084                 handleRadioProxyExceptionForRR(HAL_SERVICE_DATA, "cancelHandover", e);
5085             }
5086         } else {
5087             if (RILJ_LOGD) Rlog.d(RILJ_LOG_TAG, "cancelHandover: REQUEST_NOT_SUPPORTED");
5088             AsyncResult.forMessage(result, null,
5089                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5090             result.sendToTarget();
5091         }
5092     }
5093 
5094     /**
5095      * {@inheritDoc}
5096      */
5097     @Override
getSlicingConfig(Message result)5098     public void getSlicingConfig(Message result) {
5099         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class, result);
5100         if (dataProxy.isEmpty()) return;
5101         if (mHalVersion.get(HAL_SERVICE_DATA).greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
5102             RILRequest rr = obtainRequest(RIL_REQUEST_GET_SLICING_CONFIG, result,
5103                     mRILDefaultWorkSource);
5104 
5105             if (RILJ_LOGD) {
5106                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5107             }
5108 
5109             try {
5110                 dataProxy.getSlicingConfig(rr.mSerial);
5111             } catch (RemoteException | RuntimeException e) {
5112                 handleRadioProxyExceptionForRR(HAL_SERVICE_DATA, "getSlicingConfig", e);
5113             }
5114         } else {
5115             if (RILJ_LOGD) Rlog.d(RILJ_LOG_TAG, "getSlicingConfig: REQUEST_NOT_SUPPORTED");
5116             AsyncResult.forMessage(result, null,
5117                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5118             result.sendToTarget();
5119         }
5120     }
5121 
5122     @Override
getSimPhonebookRecords(Message result)5123     public void getSimPhonebookRecords(Message result) {
5124         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
5125         if (simProxy.isEmpty()) return;
5126         if (mHalVersion.get(HAL_SERVICE_SIM).greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
5127             RILRequest rr = obtainRequest(RIL_REQUEST_GET_SIM_PHONEBOOK_RECORDS, result,
5128                     mRILDefaultWorkSource);
5129 
5130             if (RILJ_LOGD) {
5131                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5132             }
5133 
5134             try {
5135                 simProxy.getSimPhonebookRecords(rr.mSerial);
5136             } catch (RemoteException | RuntimeException e) {
5137                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "getSimPhonebookRecords", e);
5138             }
5139         } else {
5140             if (RILJ_LOGD) {
5141                 Rlog.d(RILJ_LOG_TAG, "getSimPhonebookRecords: REQUEST_NOT_SUPPORTED");
5142             }
5143             if (result != null) {
5144                 AsyncResult.forMessage(result, null,
5145                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5146                 result.sendToTarget();
5147             }
5148         }
5149     }
5150 
5151     @Override
getSimPhonebookCapacity(Message result)5152     public void getSimPhonebookCapacity(Message result) {
5153         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
5154         if (simProxy.isEmpty()) return;
5155         if (mHalVersion.get(HAL_SERVICE_SIM).greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
5156             RILRequest rr = obtainRequest(RIL_REQUEST_GET_SIM_PHONEBOOK_CAPACITY, result,
5157                     mRILDefaultWorkSource);
5158 
5159             if (RILJ_LOGD) {
5160                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5161             }
5162 
5163             try {
5164                 simProxy.getSimPhonebookCapacity(rr.mSerial);
5165             } catch (RemoteException | RuntimeException e) {
5166                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "getSimPhonebookCapacity", e);
5167             }
5168         } else {
5169             if (RILJ_LOGD) {
5170                 Rlog.d(RILJ_LOG_TAG, "getSimPhonebookCapacity: REQUEST_NOT_SUPPORTED");
5171             }
5172             if (result != null) {
5173                 AsyncResult.forMessage(result, null,
5174                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5175                 result.sendToTarget();
5176             }
5177         }
5178     }
5179 
5180     @Override
updateSimPhonebookRecord(SimPhonebookRecord phonebookRecord, Message result)5181     public void updateSimPhonebookRecord(SimPhonebookRecord phonebookRecord, Message result) {
5182         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class, result);
5183         if (simProxy.isEmpty()) return;
5184         if (mHalVersion.get(HAL_SERVICE_SIM).greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
5185             RILRequest rr = obtainRequest(RIL_REQUEST_UPDATE_SIM_PHONEBOOK_RECORD, result,
5186                     mRILDefaultWorkSource);
5187 
5188             if (RILJ_LOGD) {
5189                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
5190                         + " with " + phonebookRecord.toString());
5191             }
5192 
5193             try {
5194                 simProxy.updateSimPhonebookRecords(rr.mSerial, phonebookRecord);
5195             } catch (RemoteException | RuntimeException e) {
5196                 handleRadioProxyExceptionForRR(HAL_SERVICE_SIM, "updateSimPhonebookRecords", e);
5197             }
5198         } else {
5199             if (RILJ_LOGD) {
5200                 Rlog.d(RILJ_LOG_TAG, "updateSimPhonebookRecords: REQUEST_NOT_SUPPORTED");
5201             }
5202             if (result != null) {
5203                 AsyncResult.forMessage(result, null,
5204                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5205                 result.sendToTarget();
5206             }
5207         }
5208     }
5209 
5210     /**
5211      * Set the UE's usage setting.
5212      *
5213      * @param result Callback message containing the success or failure status.
5214      * @param usageSetting the UE's usage setting, either VOICE_CENTRIC or DATA_CENTRIC.
5215      */
5216     @Override
setUsageSetting(Message result, int usageSetting)5217     public void setUsageSetting(Message result,
5218             /* @TelephonyManager.UsageSetting */ int usageSetting) {
5219         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
5220         if (networkProxy.isEmpty()) return;
5221         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_2_0)) {
5222             RILRequest rr = obtainRequest(RIL_REQUEST_SET_USAGE_SETTING, result,
5223                     mRILDefaultWorkSource);
5224 
5225             if (RILJ_LOGD) {
5226                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5227             }
5228 
5229             try {
5230                 networkProxy.setUsageSetting(rr.mSerial, usageSetting);
5231             } catch (RemoteException | RuntimeException e) {
5232                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "setUsageSetting", e);
5233             }
5234         } else {
5235             if (RILJ_LOGD) {
5236                 Rlog.d(RILJ_LOG_TAG, "setUsageSetting: REQUEST_NOT_SUPPORTED");
5237             }
5238             if (result != null) {
5239                 AsyncResult.forMessage(result, null,
5240                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5241                 result.sendToTarget();
5242             }
5243         }
5244     }
5245 
5246     /**
5247      * Get the UE's usage setting.
5248      *
5249      * @param result Callback message containing the usage setting (or a failure status).
5250      */
5251     @Override
getUsageSetting(Message result)5252     public void getUsageSetting(Message result) {
5253         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
5254         if (networkProxy.isEmpty()) return;
5255         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_2_0)) {
5256             RILRequest rr = obtainRequest(RIL_REQUEST_GET_USAGE_SETTING, result,
5257                     mRILDefaultWorkSource);
5258 
5259             if (RILJ_LOGD) {
5260                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5261             }
5262 
5263             try {
5264                 networkProxy.getUsageSetting(rr.mSerial);
5265             } catch (RemoteException | RuntimeException e) {
5266                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "getUsageSetting", e);
5267             }
5268         } else {
5269             if (RILJ_LOGD) {
5270                 Rlog.d(RILJ_LOG_TAG, "getUsageSetting: REQUEST_NOT_SUPPORTED");
5271             }
5272             if (result != null) {
5273                 AsyncResult.forMessage(result, null,
5274                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5275                 result.sendToTarget();
5276             }
5277         }
5278     }
5279 
5280     @Override
setSrvccCallInfo(SrvccConnection[] srvccConnections, Message result)5281     public void setSrvccCallInfo(SrvccConnection[] srvccConnections, Message result) {
5282         RadioImsProxy imsProxy = getRadioServiceProxy(RadioImsProxy.class, result);
5283         if (imsProxy.isEmpty()) return;
5284         if (mHalVersion.get(HAL_SERVICE_IMS).greaterOrEqual(RADIO_HAL_VERSION_2_0)) {
5285             RILRequest rr = obtainRequest(RIL_REQUEST_SET_SRVCC_CALL_INFO, result,
5286                     mRILDefaultWorkSource);
5287 
5288             if (RILJ_LOGD) {
5289                 // Do not log function arg for privacy
5290                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5291             }
5292 
5293             try {
5294                 imsProxy.setSrvccCallInfo(rr.mSerial,
5295                         RILUtils.convertToHalSrvccCall(srvccConnections));
5296             } catch (RemoteException | RuntimeException e) {
5297                 handleRadioProxyExceptionForRR(HAL_SERVICE_IMS, "setSrvccCallInfo", e);
5298             }
5299         } else {
5300             if (RILJ_LOGD) {
5301                 Rlog.d(RILJ_LOG_TAG, "setSrvccCallInfo: REQUEST_NOT_SUPPORTED");
5302             }
5303             if (result != null) {
5304                 AsyncResult.forMessage(result, null,
5305                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5306                 result.sendToTarget();
5307             }
5308         }
5309     }
5310 
5311     @Override
updateImsRegistrationInfo( @egistrationManager.ImsRegistrationState int state, @ImsRegistrationImplBase.ImsRegistrationTech int imsRadioTech, @RegistrationManager.SuggestedAction int suggestedAction, int capabilities, Message result)5312     public void updateImsRegistrationInfo(
5313             @RegistrationManager.ImsRegistrationState int state,
5314             @ImsRegistrationImplBase.ImsRegistrationTech int imsRadioTech,
5315             @RegistrationManager.SuggestedAction int suggestedAction,
5316             int capabilities, Message result) {
5317         RadioImsProxy imsProxy = getRadioServiceProxy(RadioImsProxy.class, result);
5318         if (imsProxy.isEmpty()) return;
5319         if (mHalVersion.get(HAL_SERVICE_IMS).greaterOrEqual(RADIO_HAL_VERSION_2_0)) {
5320             RILRequest rr = obtainRequest(RIL_REQUEST_UPDATE_IMS_REGISTRATION_INFO, result,
5321                     mRILDefaultWorkSource);
5322 
5323             if (RILJ_LOGD) {
5324                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
5325                         + " state=" + state + ", radioTech=" + imsRadioTech
5326                         + ", suggested=" + suggestedAction + ", cap=" + capabilities);
5327             }
5328 
5329             android.hardware.radio.ims.ImsRegistration registrationInfo =
5330                     new android.hardware.radio.ims.ImsRegistration();
5331             registrationInfo.regState = RILUtils.convertImsRegistrationState(state);
5332             registrationInfo.accessNetworkType = RILUtils.convertImsRegistrationTech(imsRadioTech);
5333             registrationInfo.suggestedAction = suggestedAction;
5334             registrationInfo.capabilities = RILUtils.convertImsCapability(capabilities);
5335 
5336             try {
5337                 imsProxy.updateImsRegistrationInfo(rr.mSerial, registrationInfo);
5338             } catch (RemoteException | RuntimeException e) {
5339                 handleRadioProxyExceptionForRR(HAL_SERVICE_IMS, "updateImsRegistrationInfo", e);
5340             }
5341         } else {
5342             if (RILJ_LOGD) {
5343                 Rlog.d(RILJ_LOG_TAG, "updateImsRegistrationInfo: REQUEST_NOT_SUPPORTED");
5344             }
5345             if (result != null) {
5346                 AsyncResult.forMessage(result, null,
5347                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5348                 result.sendToTarget();
5349             }
5350         }
5351     }
5352 
5353     @Override
startImsTraffic(int token, int trafficType, int accessNetworkType, int trafficDirection, Message result)5354     public void startImsTraffic(int token,
5355             int trafficType, int accessNetworkType, int trafficDirection, Message result) {
5356         RadioImsProxy imsProxy = getRadioServiceProxy(RadioImsProxy.class, result);
5357         if (imsProxy.isEmpty()) return;
5358         if (mHalVersion.get(HAL_SERVICE_IMS).greaterOrEqual(RADIO_HAL_VERSION_2_0)) {
5359             RILRequest rr = obtainRequest(RIL_REQUEST_START_IMS_TRAFFIC, result,
5360                     mRILDefaultWorkSource);
5361 
5362             if (RILJ_LOGD) {
5363                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
5364                         + "{" + token + ", " + trafficType + ", "
5365                         + accessNetworkType + ", " + trafficDirection + "}");
5366             }
5367 
5368             try {
5369                 imsProxy.startImsTraffic(rr.mSerial, token,
5370                         RILUtils.convertImsTrafficType(trafficType), accessNetworkType,
5371                         RILUtils.convertImsTrafficDirection(trafficDirection));
5372             } catch (RemoteException | RuntimeException e) {
5373                 handleRadioProxyExceptionForRR(HAL_SERVICE_IMS, "startImsTraffic", e);
5374             }
5375         } else {
5376             if (RILJ_LOGD) {
5377                 Rlog.d(RILJ_LOG_TAG, "startImsTraffic: REQUEST_NOT_SUPPORTED");
5378             }
5379             if (result != null) {
5380                 AsyncResult.forMessage(result, null,
5381                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5382                 result.sendToTarget();
5383             }
5384         }
5385     }
5386 
5387     @Override
stopImsTraffic(int token, Message result)5388     public void stopImsTraffic(int token, Message result) {
5389         RadioImsProxy imsProxy = getRadioServiceProxy(RadioImsProxy.class, result);
5390         if (imsProxy.isEmpty()) return;
5391         if (mHalVersion.get(HAL_SERVICE_IMS).greaterOrEqual(RADIO_HAL_VERSION_2_0)) {
5392             RILRequest rr = obtainRequest(RIL_REQUEST_STOP_IMS_TRAFFIC, result,
5393                     mRILDefaultWorkSource);
5394 
5395             if (RILJ_LOGD) {
5396                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
5397                         + "{" + token + "}");
5398             }
5399 
5400             try {
5401                 imsProxy.stopImsTraffic(rr.mSerial, token);
5402             } catch (RemoteException | RuntimeException e) {
5403                 handleRadioProxyExceptionForRR(HAL_SERVICE_IMS, "stopImsTraffic", e);
5404             }
5405         } else {
5406             if (RILJ_LOGD) {
5407                 Rlog.d(RILJ_LOG_TAG, "stopImsTraffic: REQUEST_NOT_SUPPORTED");
5408             }
5409             if (result != null) {
5410                 AsyncResult.forMessage(result, null,
5411                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5412                 result.sendToTarget();
5413             }
5414         }
5415     }
5416 
5417     @Override
triggerEpsFallback(int reason, Message result)5418     public void triggerEpsFallback(int reason, Message result) {
5419         RadioImsProxy imsProxy = getRadioServiceProxy(RadioImsProxy.class, result);
5420         if (imsProxy.isEmpty()) return;
5421         if (mHalVersion.get(HAL_SERVICE_IMS).greaterOrEqual(RADIO_HAL_VERSION_2_0)) {
5422             RILRequest rr = obtainRequest(RIL_REQUEST_TRIGGER_EPS_FALLBACK, result,
5423                     mRILDefaultWorkSource);
5424 
5425             if (RILJ_LOGD) {
5426                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
5427                         + " reason=" + reason);
5428             }
5429 
5430             try {
5431                 imsProxy.triggerEpsFallback(rr.mSerial, reason);
5432             } catch (RemoteException | RuntimeException e) {
5433                 handleRadioProxyExceptionForRR(HAL_SERVICE_IMS, "triggerEpsFallback", e);
5434             }
5435         } else {
5436             if (RILJ_LOGD) {
5437                 Rlog.d(RILJ_LOG_TAG, "triggerEpsFallback: REQUEST_NOT_SUPPORTED");
5438             }
5439             if (result != null) {
5440                 AsyncResult.forMessage(result, null,
5441                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5442                 result.sendToTarget();
5443             }
5444         }
5445     }
5446 
5447     @Override
sendAnbrQuery(int mediaType, int direction, int bitsPerSecond, Message result)5448     public void sendAnbrQuery(int mediaType, int direction, int bitsPerSecond,
5449             Message result) {
5450         RadioImsProxy imsProxy = getRadioServiceProxy(RadioImsProxy.class, result);
5451         if (imsProxy.isEmpty()) return;
5452         if (mHalVersion.get(HAL_SERVICE_IMS).greaterOrEqual(RADIO_HAL_VERSION_2_0)) {
5453             RILRequest rr = obtainRequest(RIL_REQUEST_SEND_ANBR_QUERY, result,
5454                     mRILDefaultWorkSource);
5455 
5456             if (RILJ_LOGD) {
5457                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5458             }
5459 
5460             try {
5461                 imsProxy.sendAnbrQuery(rr.mSerial, mediaType, direction, bitsPerSecond);
5462             } catch (RemoteException | RuntimeException e) {
5463                 handleRadioProxyExceptionForRR(HAL_SERVICE_IMS, "sendAnbrQuery", e);
5464             }
5465         } else {
5466             if (RILJ_LOGD) {
5467                 Rlog.d(RILJ_LOG_TAG, "sendAnbrQuery: REQUEST_NOT_SUPPORTED");
5468             }
5469             if (result != null) {
5470                 AsyncResult.forMessage(result, null,
5471                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5472                 result.sendToTarget();
5473             }
5474         }
5475     }
5476 
5477     /**
5478      * {@inheritDoc}
5479      */
5480     @Override
setEmergencyMode(int emcMode, Message result)5481     public void setEmergencyMode(int emcMode, Message result) {
5482         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
5483         if (networkProxy.isEmpty()) return;
5484         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_2_1)) {
5485             RILRequest rr = obtainRequest(RIL_REQUEST_SET_EMERGENCY_MODE, result,
5486                     mRILDefaultWorkSource);
5487 
5488             if (RILJ_LOGD) {
5489                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
5490                         + " mode=" + EmergencyConstants.emergencyModeToString(emcMode));
5491             }
5492 
5493             try {
5494                 networkProxy.setEmergencyMode(rr.mSerial, emcMode);
5495             } catch (RemoteException | RuntimeException e) {
5496                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "setEmergencyMode", e);
5497             }
5498         } else {
5499             if (RILJ_LOGD) {
5500                 Rlog.d(RILJ_LOG_TAG, "setEmergencyMode: REQUEST_NOT_SUPPORTED");
5501             }
5502             if (result != null) {
5503                 AsyncResult.forMessage(result, null,
5504                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5505                 result.sendToTarget();
5506             }
5507         }
5508     }
5509 
5510     /**
5511      * {@inheritDoc}
5512      */
5513     @Override
triggerEmergencyNetworkScan( @onNull @ccessNetworkConstants.RadioAccessNetworkType int[] accessNetwork, @DomainSelectionService.EmergencyScanType int scanType, Message result)5514     public void triggerEmergencyNetworkScan(
5515             @NonNull @AccessNetworkConstants.RadioAccessNetworkType int[] accessNetwork,
5516             @DomainSelectionService.EmergencyScanType int scanType, Message result) {
5517         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
5518         if (networkProxy.isEmpty()) return;
5519         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_2_1)) {
5520             RILRequest rr = obtainRequest(RIL_REQUEST_TRIGGER_EMERGENCY_NETWORK_SCAN, result,
5521                     mRILDefaultWorkSource);
5522 
5523             if (RILJ_LOGD) {
5524                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
5525                         + " networkType=" + RILUtils.accessNetworkTypesToString(accessNetwork)
5526                         + ", scanType=" + RILUtils.scanTypeToString(scanType));
5527             }
5528 
5529             try {
5530                 networkProxy.triggerEmergencyNetworkScan(rr.mSerial,
5531                         RILUtils.convertEmergencyNetworkScanTrigger(accessNetwork, scanType));
5532             } catch (RemoteException | RuntimeException e) {
5533                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK,
5534                         "triggerEmergencyNetworkScan", e);
5535             }
5536         } else {
5537             if (RILJ_LOGD) {
5538                 Rlog.d(RILJ_LOG_TAG, "triggerEmergencyNetworkScan: REQUEST_NOT_SUPPORTED");
5539             }
5540             if (result != null) {
5541                 AsyncResult.forMessage(result, null,
5542                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5543                 result.sendToTarget();
5544             }
5545         }
5546     }
5547 
5548     /**
5549      * {@inheritDoc}
5550      */
5551     @Override
cancelEmergencyNetworkScan(boolean resetScan, Message result)5552     public void cancelEmergencyNetworkScan(boolean resetScan, Message result) {
5553         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
5554         if (networkProxy.isEmpty()) return;
5555         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_2_1)) {
5556             RILRequest rr = obtainRequest(RIL_REQUEST_CANCEL_EMERGENCY_NETWORK_SCAN, result,
5557                     mRILDefaultWorkSource);
5558 
5559             if (RILJ_LOGD) {
5560                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
5561                         + " resetScan=" + resetScan);
5562             }
5563 
5564             try {
5565                 networkProxy.cancelEmergencyNetworkScan(rr.mSerial, resetScan);
5566             } catch (RemoteException | RuntimeException e) {
5567                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK,
5568                         "cancelEmergencyNetworkScan", e);
5569             }
5570         } else {
5571             if (RILJ_LOGD) {
5572                 Rlog.d(RILJ_LOG_TAG, "cancelEmergencyNetworkScan: REQUEST_NOT_SUPPORTED");
5573             }
5574             if (result != null) {
5575                 AsyncResult.forMessage(result, null,
5576                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5577                 result.sendToTarget();
5578             }
5579         }
5580     }
5581 
5582     /**
5583      * {@inheritDoc}
5584      */
5585     @Override
exitEmergencyMode(Message result)5586     public void exitEmergencyMode(Message result) {
5587         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
5588         if (networkProxy.isEmpty()) return;
5589         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_2_1)) {
5590             RILRequest rr = obtainRequest(RIL_REQUEST_EXIT_EMERGENCY_MODE, result,
5591                     mRILDefaultWorkSource);
5592 
5593             if (RILJ_LOGD) {
5594                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5595             }
5596 
5597             try {
5598                 networkProxy.exitEmergencyMode(rr.mSerial);
5599             } catch (RemoteException | RuntimeException e) {
5600                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "exitEmergencyMode", e);
5601             }
5602         } else {
5603             if (RILJ_LOGD) {
5604                 Rlog.d(RILJ_LOG_TAG, "exitEmergencyMode: REQUEST_NOT_SUPPORTED");
5605             }
5606             if (result != null) {
5607                 AsyncResult.forMessage(result, null,
5608                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5609                 result.sendToTarget();
5610             }
5611         }
5612     }
5613 
5614     /**
5615      * Set if null ciphering / null integrity modes are permitted.
5616      *
5617      * @param result Callback message containing the success or failure status.
5618      * @param enabled true if null ciphering / null integrity modes are permitted, false otherwise
5619      */
5620     @Override
setNullCipherAndIntegrityEnabled(boolean enabled, Message result)5621     public void setNullCipherAndIntegrityEnabled(boolean enabled, Message result) {
5622         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
5623         if (networkProxy.isEmpty()) return;
5624         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_2_1)) {
5625             RILRequest rr = obtainRequest(RIL_REQUEST_SET_NULL_CIPHER_AND_INTEGRITY_ENABLED, result,
5626                     mRILDefaultWorkSource);
5627 
5628             if (RILJ_LOGD) {
5629                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5630             }
5631 
5632             try {
5633                 networkProxy.setNullCipherAndIntegrityEnabled(rr.mSerial, enabled);
5634             } catch (RemoteException | RuntimeException e) {
5635                 handleRadioProxyExceptionForRR(
5636                         HAL_SERVICE_NETWORK, "setNullCipherAndIntegrityEnabled", e);
5637             }
5638         } else {
5639             if (RILJ_LOGD) {
5640                 Rlog.d(RILJ_LOG_TAG, "setNullCipherAndIntegrityEnabled: REQUEST_NOT_SUPPORTED");
5641             }
5642             if (result != null) {
5643                 AsyncResult.forMessage(result, null,
5644                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5645                 result.sendToTarget();
5646             }
5647         }
5648     }
5649 
5650     /**
5651      * Get if null ciphering / null integrity are enabled / disabled.
5652      *
5653      * @param result Callback message containing the success or failure status.
5654      */
5655     @Override
isNullCipherAndIntegrityEnabled(Message result)5656     public void isNullCipherAndIntegrityEnabled(Message result) {
5657         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
5658         if (networkProxy.isEmpty()) return;
5659         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_2_1)) {
5660             RILRequest rr = obtainRequest(RIL_REQUEST_IS_NULL_CIPHER_AND_INTEGRITY_ENABLED, result,
5661                     mRILDefaultWorkSource);
5662 
5663             if (RILJ_LOGD) {
5664                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5665             }
5666 
5667             try {
5668                 networkProxy.isNullCipherAndIntegrityEnabled(rr.mSerial);
5669             } catch (RemoteException | RuntimeException e) {
5670                 handleRadioProxyExceptionForRR(
5671                         HAL_SERVICE_NETWORK, "isNullCipherAndIntegrityEnabled", e);
5672             }
5673         } else {
5674             if (RILJ_LOGD) {
5675                 Rlog.d(RILJ_LOG_TAG, "isNullCipherAndIntegrityEnabled: REQUEST_NOT_SUPPORTED");
5676             }
5677             if (result != null) {
5678                 AsyncResult.forMessage(result, null,
5679                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5680                 result.sendToTarget();
5681             }
5682         }
5683     }
5684 
5685     /**
5686      * {@inheritDoc}
5687      */
5688     @Override
updateImsCallStatus(@onNull List<ImsCallInfo> imsCallInfo, Message result)5689     public void updateImsCallStatus(@NonNull List<ImsCallInfo> imsCallInfo, Message result) {
5690         RadioImsProxy imsProxy = getRadioServiceProxy(RadioImsProxy.class, result);
5691         if (imsProxy.isEmpty()) return;
5692         if (mHalVersion.get(HAL_SERVICE_IMS).greaterOrEqual(RADIO_HAL_VERSION_2_0)) {
5693             RILRequest rr = obtainRequest(RIL_REQUEST_UPDATE_IMS_CALL_STATUS, result,
5694                     mRILDefaultWorkSource);
5695 
5696             if (RILJ_LOGD) {
5697                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
5698                         + " " + imsCallInfo);
5699             }
5700             try {
5701                 imsProxy.updateImsCallStatus(rr.mSerial, RILUtils.convertImsCallInfo(imsCallInfo));
5702             } catch (RemoteException | RuntimeException e) {
5703                 handleRadioProxyExceptionForRR(HAL_SERVICE_IMS, "updateImsCallStatus", e);
5704             }
5705         } else {
5706             if (RILJ_LOGD) {
5707                 Rlog.d(RILJ_LOG_TAG, "updateImsCallStatus: REQUEST_NOT_SUPPORTED");
5708             }
5709             if (result != null) {
5710                 AsyncResult.forMessage(result, null,
5711                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5712                 result.sendToTarget();
5713             }
5714         }
5715     }
5716 
5717     /**
5718      * {@inheritDoc}
5719      */
5720     @Override
setN1ModeEnabled(boolean enable, Message result)5721     public void setN1ModeEnabled(boolean enable, Message result) {
5722         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
5723         if (networkProxy.isEmpty()) return;
5724         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_2_1)) {
5725             RILRequest rr = obtainRequest(RIL_REQUEST_SET_N1_MODE_ENABLED, result,
5726                     mRILDefaultWorkSource);
5727 
5728             if (RILJ_LOGD) {
5729                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
5730                         + " enable=" + enable);
5731             }
5732 
5733             try {
5734                 networkProxy.setN1ModeEnabled(rr.mSerial, enable);
5735             } catch (RemoteException | RuntimeException e) {
5736                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "setN1ModeEnabled", e);
5737             }
5738         } else {
5739             if (RILJ_LOGD) {
5740                 Rlog.d(RILJ_LOG_TAG, "setN1ModeEnabled: REQUEST_NOT_SUPPORTED");
5741             }
5742             if (result != null) {
5743                 AsyncResult.forMessage(result, null,
5744                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5745                 result.sendToTarget();
5746             }
5747         }
5748     }
5749 
5750     /**
5751      * {@inheritDoc}
5752      */
5753     @Override
isN1ModeEnabled(Message result)5754     public void isN1ModeEnabled(Message result) {
5755         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
5756         if (networkProxy.isEmpty()) return;
5757         if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_2_1)) {
5758             RILRequest rr = obtainRequest(RIL_REQUEST_IS_N1_MODE_ENABLED, result,
5759                     mRILDefaultWorkSource);
5760 
5761             if (RILJ_LOGD) {
5762                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5763             }
5764 
5765             try {
5766                 networkProxy.isN1ModeEnabled(rr.mSerial);
5767             } catch (RemoteException | RuntimeException e) {
5768                 handleRadioProxyExceptionForRR(HAL_SERVICE_NETWORK, "isN1ModeEnabled", e);
5769             }
5770         } else {
5771             if (RILJ_LOGD) {
5772                 Rlog.d(RILJ_LOG_TAG, "isN1ModeEnabled: REQUEST_NOT_SUPPORTED");
5773             }
5774             if (result != null) {
5775                 AsyncResult.forMessage(result, null,
5776                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5777                 result.sendToTarget();
5778             }
5779         }
5780     }
5781 
5782     /**
5783      * Get feature capabilities supported by satellite.
5784      *
5785      * @param result Message that will be sent back to the requester
5786      */
5787     @Override
getSatelliteCapabilities(Message result)5788     public void getSatelliteCapabilities(Message result) {
5789         // Satellite HAL APIs are not supported before Android V.
5790         if (result != null) {
5791             AsyncResult.forMessage(result, null,
5792                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5793             result.sendToTarget();
5794         }
5795     }
5796 
5797     /**
5798      * Turn satellite modem on/off.
5799      *
5800      * @param result Message that will be sent back to the requester
5801      * @param on True for turning on.
5802      *           False for turning off.
5803      */
5804     @Override
setSatellitePower(Message result, boolean on)5805     public void setSatellitePower(Message result, boolean on) {
5806         // Satellite HAL APIs are not supported before Android V.
5807         if (result != null) {
5808             AsyncResult.forMessage(result, null,
5809                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5810             result.sendToTarget();
5811         }
5812     }
5813 
5814     /**
5815      * Get satellite modem state.
5816      *
5817      * @param result Message that will be sent back to the requester
5818      */
5819     @Override
getSatellitePowerState(Message result)5820     public void getSatellitePowerState(Message result) {
5821         // Satellite HAL APIs are not supported before Android V.
5822         if (result != null) {
5823             AsyncResult.forMessage(result, null,
5824                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5825             result.sendToTarget();
5826         }
5827     }
5828 
5829     /**
5830      * Get satellite provision state.
5831      *
5832      * @param result Message that will be sent back to the requester
5833      */
5834     @Override
getSatelliteProvisionState(Message result)5835     public void getSatelliteProvisionState(Message result) {
5836         // Satellite HAL APIs are not supported before Android V.
5837         if (result != null) {
5838             AsyncResult.forMessage(result, null,
5839                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5840             result.sendToTarget();
5841         }
5842     }
5843 
5844     /**
5845      * Provision the subscription with a satellite provider. This is needed to register the
5846      * subscription if the provider allows dynamic registration.
5847      *
5848      * @param result Message that will be sent back to the requester.
5849      * @param imei IMEI of the SIM associated with the satellite modem.
5850      * @param msisdn MSISDN of the SIM associated with the satellite modem.
5851      * @param imsi IMSI of the SIM associated with the satellite modem.
5852      * @param features List of features to be provisioned.
5853      */
5854     @Override
provisionSatelliteService( Message result, String imei, String msisdn, String imsi, int[] features)5855     public void provisionSatelliteService(
5856             Message result, String imei, String msisdn, String imsi, int[] features) {
5857         // Satellite HAL APIs are not supported before Android V.
5858         if (result != null) {
5859             AsyncResult.forMessage(result, null,
5860                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5861             result.sendToTarget();
5862         }
5863     }
5864 
5865     /**
5866      * Add contacts that are allowed to be used for satellite communication. This is applicable for
5867      * incoming messages as well.
5868      *
5869      * @param result Message that will be sent back to the requester.
5870      * @param contacts List of allowed contacts to be added.
5871      */
5872     @Override
addAllowedSatelliteContacts(Message result, String[] contacts)5873     public void addAllowedSatelliteContacts(Message result, String[] contacts) {
5874         // Satellite HAL APIs are not supported before Android V.
5875         if (result != null) {
5876             AsyncResult.forMessage(result, null,
5877                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5878             result.sendToTarget();
5879         }
5880     }
5881 
5882     /**
5883      * Remove contacts that are allowed to be used for satellite communication. This is applicable
5884      * for incoming messages as well.
5885      *
5886      * @param result Message that will be sent back to the requester.
5887      * @param contacts List of allowed contacts to be removed.
5888      */
5889     @Override
removeAllowedSatelliteContacts(Message result, String[] contacts)5890     public void removeAllowedSatelliteContacts(Message result, String[] contacts) {
5891         // Satellite HAL APIs are not supported before Android V.
5892         if (result != null) {
5893             AsyncResult.forMessage(result, null,
5894                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5895             result.sendToTarget();
5896         }
5897     }
5898 
5899     /**
5900      * Send text messages.
5901      *
5902      * @param result Message that will be sent back to the requester.
5903      * @param messages List of messages in text format to be sent.
5904      * @param destination The recipient of the message.
5905      * @param latitude The current latitude of the device.
5906      * @param longitude The current longitude of the device.
5907      */
5908     @Override
sendSatelliteMessages(Message result, String[] messages, String destination, double latitude, double longitude)5909     public void sendSatelliteMessages(Message result, String[] messages, String destination,
5910             double latitude, double longitude) {
5911         // Satellite HAL APIs are not supported before Android V.
5912         if (result != null) {
5913             AsyncResult.forMessage(result, null,
5914                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5915             result.sendToTarget();
5916         }
5917     }
5918 
5919     /**
5920      * Get pending messages.
5921      *
5922      * @param result Message that will be sent back to the requester.
5923      */
5924     @Override
getPendingSatelliteMessages(Message result)5925     public void getPendingSatelliteMessages(Message result) {
5926         // Satellite HAL APIs are not supported before Android V.
5927         if (result != null) {
5928             AsyncResult.forMessage(result, null,
5929                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5930             result.sendToTarget();
5931         }
5932     }
5933 
5934     /**
5935      * Get current satellite registration mode.
5936      *
5937      * @param result Message that will be sent back to the requester.
5938      */
5939     @Override
getSatelliteMode(Message result)5940     public void getSatelliteMode(Message result) {
5941         // Satellite HAL APIs are not supported before Android V.
5942         if (result != null) {
5943             AsyncResult.forMessage(result, null,
5944                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5945             result.sendToTarget();
5946         }
5947     }
5948 
5949     /**
5950      * Set the filter for what type of indication framework want to receive from modem.
5951      *
5952      * @param result Message that will be sent back to the requester.
5953      * @param filterBitmask The filter bitmask identifying what type of indication framework want to
5954      *                         receive from modem.
5955      */
5956     @Override
setSatelliteIndicationFilter(Message result, int filterBitmask)5957     public void setSatelliteIndicationFilter(Message result, int filterBitmask) {
5958         // Satellite HAL APIs are not supported before Android V.
5959         if (result != null) {
5960             AsyncResult.forMessage(result, null,
5961                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5962             result.sendToTarget();
5963         }
5964     }
5965 
5966     /**
5967      * Check whether satellite modem is supported by the device.
5968      *
5969      * @param result Message that will be sent back to the requester.
5970      */
5971     @Override
isSatelliteSupported(Message result)5972     public void isSatelliteSupported(Message result) {
5973         // Satellite HAL APIs are not supported before Android V.
5974         if (result != null) {
5975             AsyncResult.forMessage(result, null,
5976                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5977             result.sendToTarget();
5978         }
5979     }
5980 
5981     /**
5982      * User started pointing to the satellite. Modem should continue to update the ponting input
5983      * as user moves device.
5984      *
5985      * @param result Message that will be sent back to the requester.
5986      */
5987     @Override
startSendingSatellitePointingInfo(Message result)5988     public void startSendingSatellitePointingInfo(Message result) {
5989         // Satellite HAL APIs are not supported before Android V.
5990         if (result != null) {
5991             AsyncResult.forMessage(result, null,
5992                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
5993             result.sendToTarget();
5994         }
5995     }
5996 
5997     /**
5998      * Stop pointing to satellite indications.
5999      *
6000      * @param result Message that will be sent back to the requester.
6001      */
6002     @Override
stopSendingSatellitePointingInfo(Message result)6003     public void stopSendingSatellitePointingInfo(Message result) {
6004         // Satellite HAL APIs are not supported before Android V.
6005         if (result != null) {
6006             AsyncResult.forMessage(result, null,
6007                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
6008             result.sendToTarget();
6009         }
6010     }
6011 
6012     /**
6013      * Get max text limit for messaging per message.
6014      *
6015      * @param result Message that will be sent back to the requester.
6016      */
6017     @Override
getMaxCharactersPerSatelliteTextMessage(Message result)6018     public void getMaxCharactersPerSatelliteTextMessage(Message result) {
6019         // Satellite HAL APIs are not supported before Android V.
6020         if (result != null) {
6021             AsyncResult.forMessage(result, null,
6022                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
6023             result.sendToTarget();
6024         }
6025     }
6026 
6027     /**
6028      * Get whether satellite communication is allowed for the current location
6029      *
6030      * @param result Message that will be sent back to the requester.
6031      */
6032     @Override
isSatelliteCommunicationAllowedForCurrentLocation(Message result)6033     public void isSatelliteCommunicationAllowedForCurrentLocation(Message result) {
6034         // Satellite HAL APIs are not supported before Android V.
6035         if (result != null) {
6036             AsyncResult.forMessage(result, null,
6037                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
6038             result.sendToTarget();
6039         }
6040     }
6041 
6042     /**
6043      * Get time for next visibility of satellite.
6044      *
6045      * @param result Message that will be sent back to the requester.
6046      */
6047     @Override
getTimeForNextSatelliteVisibility(Message result)6048     public void getTimeForNextSatelliteVisibility(Message result) {
6049         // Satellite HAL APIs are not supported before Android V.
6050         if (result != null) {
6051             AsyncResult.forMessage(result, null,
6052                     CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
6053             result.sendToTarget();
6054         }
6055     }
6056 
6057     //***** Private Methods
6058     /**
6059      * This is a helper function to be called when an indication callback is called for any radio
6060      * service. It takes care of acquiring wakelock and sending ack if needed.
6061      * @param service radio service the indication is for
6062      * @param indicationType indication type received
6063      */
processIndication(int service, int indicationType)6064     void processIndication(int service, int indicationType) {
6065         if (indicationType == RadioIndicationType.UNSOLICITED_ACK_EXP) {
6066             sendAck(service);
6067             if (RILJ_LOGD) riljLog("Unsol response received; Sending ack to ril.cpp");
6068         } else {
6069             // ack is not expected to be sent back. Nothing is required to be done here.
6070         }
6071     }
6072 
processRequestAck(int serial)6073     void processRequestAck(int serial) {
6074         RILRequest rr;
6075         synchronized (mRequestList) {
6076             rr = mRequestList.get(serial);
6077         }
6078         if (rr == null) {
6079             Rlog.w(RILJ_LOG_TAG, "processRequestAck: Unexpected solicited ack response! "
6080                     + "serial: " + serial);
6081         } else {
6082             decrementWakeLock(rr);
6083             if (RILJ_LOGD) {
6084                 riljLog(rr.serialString() + " Ack < " + RILUtils.requestToString(rr.mRequest));
6085             }
6086         }
6087     }
6088 
6089     /**
6090      * This is a helper function to be called when a RadioResponse callback is called.
6091      * It takes care of acks, wakelocks, and finds and returns RILRequest corresponding to the
6092      * response if one is found.
6093      * @param responseInfo RadioResponseInfo received in response callback
6094      * @return RILRequest corresponding to the response
6095      */
6096     @VisibleForTesting
processResponse(RadioResponseInfo responseInfo)6097     public RILRequest processResponse(RadioResponseInfo responseInfo) {
6098         return processResponseInternal(HAL_SERVICE_RADIO, responseInfo.serial, responseInfo.error,
6099                 responseInfo.type);
6100     }
6101 
6102     /**
6103      * This is a helper function for V1_6.RadioResponseInfo to be called when a RadioResponse
6104      * callback is called. It takes care of acks, wakelocks, and finds and returns RILRequest
6105      * corresponding to the response if one is found.
6106      * @param responseInfo RadioResponseInfo received in response callback
6107      * @return RILRequest corresponding to the response
6108      */
6109     @VisibleForTesting
processResponse_1_6( android.hardware.radio.V1_6.RadioResponseInfo responseInfo)6110     public RILRequest processResponse_1_6(
6111             android.hardware.radio.V1_6.RadioResponseInfo responseInfo) {
6112         return processResponseInternal(HAL_SERVICE_RADIO, responseInfo.serial, responseInfo.error,
6113                 responseInfo.type);
6114     }
6115 
6116     /**
6117      * This is a helper function for an AIDL RadioResponseInfo to be called when a RadioResponse
6118      * callback is called. It takes care of acks, wakelocks, and finds and returns RILRequest
6119      * corresponding to the response if one is found.
6120      * @param service Radio service that received the response
6121      * @param responseInfo RadioResponseInfo received in response callback
6122      * @return RILRequest corresponding to the response
6123      */
processResponse(int service, android.hardware.radio.RadioResponseInfo responseInfo)6124     public RILRequest processResponse(int service,
6125             android.hardware.radio.RadioResponseInfo responseInfo) {
6126         return processResponseInternal(service, responseInfo.serial, responseInfo.error,
6127                 responseInfo.type);
6128     }
6129 
processResponseInternal(int service, int serial, int error, int type)6130     private RILRequest processResponseInternal(int service, int serial, int error, int type) {
6131         RILRequest rr;
6132 
6133         if (type == RadioResponseType.SOLICITED_ACK) {
6134             synchronized (mRequestList) {
6135                 rr = mRequestList.get(serial);
6136             }
6137             if (rr == null) {
6138                 Rlog.w(RILJ_LOG_TAG, "Unexpected solicited ack response! sn: " + serial);
6139             } else {
6140                 decrementWakeLock(rr);
6141                 if (mRadioBugDetector != null) {
6142                     mRadioBugDetector.detectRadioBug(rr.mRequest, error);
6143                 }
6144                 if (RILJ_LOGD) {
6145                     riljLog(rr.serialString() + " Ack from " + serviceToString(service)
6146                             + " < " + RILUtils.requestToString(rr.mRequest));
6147                 }
6148             }
6149             return rr;
6150         }
6151 
6152         rr = findAndRemoveRequestFromList(serial);
6153         if (rr == null) {
6154             Rlog.e(RILJ_LOG_TAG, "processResponse: Unexpected response! serial: " + serial
6155                     + " ,error: " + error);
6156             return null;
6157         }
6158         Trace.asyncTraceForTrackEnd(Trace.TRACE_TAG_NETWORK, "RIL", rr.mSerial);
6159 
6160         // Time logging for RIL command and storing it in TelephonyHistogram.
6161         addToRilHistogram(rr);
6162         if (mRadioBugDetector != null) {
6163             mRadioBugDetector.detectRadioBug(rr.mRequest, error);
6164         }
6165         if (type == RadioResponseType.SOLICITED_ACK_EXP) {
6166             sendAck(service);
6167             if (RILJ_LOGD) {
6168                 riljLog("Response received from " + serviceToString(service) + " for "
6169                         + rr.serialString() + " " + RILUtils.requestToString(rr.mRequest)
6170                         + " Sending ack to ril.cpp");
6171             }
6172         } else {
6173             // ack sent for SOLICITED_ACK_EXP above; nothing to do for SOLICITED response
6174         }
6175 
6176         // Here and below fake RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, see b/7255789.
6177         // This is needed otherwise we don't automatically transition to the main lock
6178         // screen when the pin or puk is entered incorrectly.
6179         switch (rr.mRequest) {
6180             case RIL_REQUEST_ENTER_SIM_PUK:
6181             case RIL_REQUEST_ENTER_SIM_PUK2:
6182                 if (mIccStatusChangedRegistrants != null) {
6183                     if (RILJ_LOGD) {
6184                         riljLog("ON enter sim puk fakeSimStatusChanged: reg count="
6185                                 + mIccStatusChangedRegistrants.size());
6186                     }
6187                     mIccStatusChangedRegistrants.notifyRegistrants();
6188                 }
6189                 break;
6190             case RIL_REQUEST_SHUTDOWN:
6191                 setRadioState(TelephonyManager.RADIO_POWER_UNAVAILABLE,
6192                         false /* forceNotifyRegistrants */);
6193                 break;
6194         }
6195 
6196         if (error != RadioError.NONE) {
6197             switch (rr.mRequest) {
6198                 case RIL_REQUEST_ENTER_SIM_PIN:
6199                 case RIL_REQUEST_ENTER_SIM_PIN2:
6200                 case RIL_REQUEST_CHANGE_SIM_PIN:
6201                 case RIL_REQUEST_CHANGE_SIM_PIN2:
6202                 case RIL_REQUEST_SET_FACILITY_LOCK:
6203                     if (mIccStatusChangedRegistrants != null) {
6204                         if (RILJ_LOGD) {
6205                             riljLog("ON some errors fakeSimStatusChanged: reg count="
6206                                     + mIccStatusChangedRegistrants.size());
6207                         }
6208                         mIccStatusChangedRegistrants.notifyRegistrants();
6209                     }
6210                     break;
6211 
6212             }
6213         } else {
6214             switch (rr.mRequest) {
6215                 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND:
6216                 if (mTestingEmergencyCall.getAndSet(false)) {
6217                     if (mEmergencyCallbackModeRegistrant != null) {
6218                         riljLog("testing emergency call, notify ECM Registrants");
6219                         mEmergencyCallbackModeRegistrant.notifyRegistrant();
6220                     }
6221                 }
6222             }
6223         }
6224         return rr;
6225     }
6226 
6227     /**
6228      * This is a helper function to be called at the end of all RadioResponse callbacks.
6229      * It takes care of sending error response, logging, decrementing wakelock if needed, and
6230      * releases the request from memory pool.
6231      * @param rr RILRequest for which response callback was called
6232      * @param responseInfo RadioResponseInfo received in the callback
6233      * @param ret object to be returned to request sender
6234      */
6235     @VisibleForTesting
processResponseDone(RILRequest rr, RadioResponseInfo responseInfo, Object ret)6236     public void processResponseDone(RILRequest rr, RadioResponseInfo responseInfo, Object ret) {
6237         processResponseDoneInternal(rr, responseInfo.error, responseInfo.type, ret);
6238     }
6239 
6240     /**
6241      * This is a helper function to be called at the end of the RadioResponse callbacks using for
6242      * V1_6.RadioResponseInfo.
6243      * It takes care of sending error response, logging, decrementing wakelock if needed, and
6244      * releases the request from memory pool.
6245      * @param rr RILRequest for which response callback was called
6246      * @param responseInfo RadioResponseInfo received in the callback
6247      * @param ret object to be returned to request sender
6248      */
6249     @VisibleForTesting
processResponseDone_1_6(RILRequest rr, android.hardware.radio.V1_6.RadioResponseInfo responseInfo, Object ret)6250     public void processResponseDone_1_6(RILRequest rr,
6251             android.hardware.radio.V1_6.RadioResponseInfo responseInfo, Object ret) {
6252         processResponseDoneInternal(rr, responseInfo.error, responseInfo.type, ret);
6253     }
6254 
6255     /**
6256      * This is a helper function to be called at the end of the RadioResponse callbacks using for
6257      * RadioResponseInfo AIDL.
6258      * It takes care of sending error response, logging, decrementing wakelock if needed, and
6259      * releases the request from memory pool.
6260      * @param rr RILRequest for which response callback was called
6261      * @param responseInfo RadioResponseInfo received in the callback
6262      * @param ret object to be returned to request sender
6263      */
6264     @VisibleForTesting
processResponseDone(RILRequest rr, android.hardware.radio.RadioResponseInfo responseInfo, Object ret)6265     public void processResponseDone(RILRequest rr,
6266             android.hardware.radio.RadioResponseInfo responseInfo, Object ret) {
6267         processResponseDoneInternal(rr, responseInfo.error, responseInfo.type, ret);
6268     }
6269 
processResponseDoneInternal(RILRequest rr, int rilError, int responseType, Object ret)6270     private void processResponseDoneInternal(RILRequest rr, int rilError, int responseType,
6271             Object ret) {
6272         if (rilError == 0) {
6273             if (RILJ_LOGD) {
6274                 riljLog(rr.serialString() + "< " + RILUtils.requestToString(rr.mRequest)
6275                         + " " + retToString(rr.mRequest, ret));
6276             }
6277         } else {
6278             if (RILJ_LOGD) {
6279                 riljLog(rr.serialString() + "< " + RILUtils.requestToString(rr.mRequest)
6280                         + " error " + rilError);
6281             }
6282             rr.onError(rilError, ret);
6283         }
6284         processResponseCleanUp(rr, rilError, responseType, ret);
6285     }
6286 
6287     /**
6288      * This is a helper function to be called at the end of all RadioResponse callbacks for
6289      * radio HAL fallback cases. It takes care of logging, decrementing wakelock if needed, and
6290      * releases the request from memory pool. Unlike processResponseDone, it will not send
6291      * error response to caller.
6292      * @param rr RILRequest for which response callback was called
6293      * @param responseInfo RadioResponseInfo received in the callback
6294      * @param ret object to be returned to request sender
6295      */
6296     @VisibleForTesting
processResponseFallback(RILRequest rr, RadioResponseInfo responseInfo, Object ret)6297     public void processResponseFallback(RILRequest rr, RadioResponseInfo responseInfo, Object ret) {
6298         if (responseInfo.error == REQUEST_NOT_SUPPORTED && RILJ_LOGD) {
6299             riljLog(rr.serialString() + "< " + RILUtils.requestToString(rr.mRequest)
6300                     + " request not supported, falling back");
6301         }
6302         processResponseCleanUp(rr, responseInfo.error, responseInfo.type, ret);
6303     }
6304 
processResponseCleanUp(RILRequest rr, int rilError, int responseType, Object ret)6305     private void processResponseCleanUp(RILRequest rr, int rilError, int responseType, Object ret) {
6306         if (rr != null) {
6307             mMetrics.writeOnRilSolicitedResponse(mPhoneId, rr.mSerial, rilError, rr.mRequest, ret);
6308             if (responseType == RadioResponseType.SOLICITED) {
6309                 decrementWakeLock(rr);
6310             }
6311             rr.release();
6312         }
6313     }
6314 
6315     /**
6316      * Function to send ack and acquire related wakelock
6317      */
sendAck(int service)6318     private void sendAck(int service) {
6319         // TODO: Remove rr and clean up acquireWakelock for response and ack
6320         RILRequest rr = RILRequest.obtain(RIL_RESPONSE_ACKNOWLEDGEMENT, null,
6321                 mRILDefaultWorkSource);
6322         acquireWakeLock(rr, FOR_ACK_WAKELOCK);
6323         if (service == HAL_SERVICE_RADIO) {
6324             IRadio radioProxy = getRadioProxy(null);
6325             if (radioProxy != null) {
6326                 try {
6327                     radioProxy.responseAcknowledgement();
6328                 } catch (RemoteException | RuntimeException e) {
6329                     handleRadioProxyExceptionForRR(HAL_SERVICE_RADIO, "sendAck", e);
6330                     riljLoge("sendAck: " + e);
6331                 }
6332             } else {
6333                 Rlog.e(RILJ_LOG_TAG, "Error trying to send ack, radioProxy = null");
6334             }
6335         } else {
6336             RadioServiceProxy serviceProxy = getRadioServiceProxy(service, null);
6337             if (!serviceProxy.isEmpty()) {
6338                 try {
6339                     serviceProxy.responseAcknowledgement();
6340                 } catch (RemoteException | RuntimeException e) {
6341                     handleRadioProxyExceptionForRR(service, "sendAck", e);
6342                     riljLoge("sendAck: " + e);
6343                 }
6344             } else {
6345                 Rlog.e(RILJ_LOG_TAG, "Error trying to send ack, serviceProxy is empty");
6346             }
6347         }
6348         rr.release();
6349     }
6350 
getDefaultWorkSourceIfInvalid(WorkSource workSource)6351     private WorkSource getDefaultWorkSourceIfInvalid(WorkSource workSource) {
6352         if (workSource == null) {
6353             workSource = mRILDefaultWorkSource;
6354         }
6355 
6356         return workSource;
6357     }
6358 
6359 
6360     /**
6361      * Holds a PARTIAL_WAKE_LOCK whenever
6362      * a) There is outstanding RIL request sent to RIL deamon and no replied
6363      * b) There is a request pending to be sent out.
6364      *
6365      * There is a WAKE_LOCK_TIMEOUT to release the lock, though it shouldn't
6366      * happen often.
6367      */
6368     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
acquireWakeLock(RILRequest rr, int wakeLockType)6369     private void acquireWakeLock(RILRequest rr, int wakeLockType) {
6370         synchronized (rr) {
6371             if (rr.mWakeLockType != INVALID_WAKELOCK) {
6372                 Rlog.d(RILJ_LOG_TAG, "Failed to aquire wakelock for " + rr.serialString());
6373                 return;
6374             }
6375 
6376             switch(wakeLockType) {
6377                 case FOR_WAKELOCK:
6378                     synchronized (mWakeLock) {
6379                         mWakeLock.acquire();
6380                         mWakeLockCount++;
6381                         mWlSequenceNum++;
6382 
6383                         String clientId = rr.getWorkSourceClientId();
6384                         if (!mClientWakelockTracker.isClientActive(clientId)) {
6385                             mActiveWakelockWorkSource.add(rr.mWorkSource);
6386                             mWakeLock.setWorkSource(mActiveWakelockWorkSource);
6387                         }
6388 
6389                         mClientWakelockTracker.startTracking(rr.mClientId,
6390                                 rr.mRequest, rr.mSerial, mWakeLockCount);
6391 
6392                         Message msg = mRilHandler.obtainMessage(EVENT_WAKE_LOCK_TIMEOUT);
6393                         msg.arg1 = mWlSequenceNum;
6394                         mRilHandler.sendMessageDelayed(msg, mWakeLockTimeout);
6395                     }
6396                     break;
6397                 case FOR_ACK_WAKELOCK:
6398                     synchronized (mAckWakeLock) {
6399                         mAckWakeLock.acquire();
6400                         mAckWlSequenceNum++;
6401 
6402                         Message msg = mRilHandler.obtainMessage(EVENT_ACK_WAKE_LOCK_TIMEOUT);
6403                         msg.arg1 = mAckWlSequenceNum;
6404                         mRilHandler.sendMessageDelayed(msg, mAckWakeLockTimeout);
6405                     }
6406                     break;
6407                 default: //WTF
6408                     Rlog.w(RILJ_LOG_TAG, "Acquiring Invalid Wakelock type " + wakeLockType);
6409                     return;
6410             }
6411             rr.mWakeLockType = wakeLockType;
6412         }
6413     }
6414 
6415     /** Returns the wake lock of the given type. */
6416     @VisibleForTesting
getWakeLock(int wakeLockType)6417     public WakeLock getWakeLock(int wakeLockType) {
6418         return wakeLockType == FOR_WAKELOCK ? mWakeLock : mAckWakeLock;
6419     }
6420 
6421     /** Returns the {@link RilHandler} instance. */
6422     @VisibleForTesting
getRilHandler()6423     public RilHandler getRilHandler() {
6424         return mRilHandler;
6425     }
6426 
6427     /** Returns the Ril request list. */
6428     @VisibleForTesting
getRilRequestList()6429     public SparseArray<RILRequest> getRilRequestList() {
6430         return mRequestList;
6431     }
6432 
6433     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
decrementWakeLock(RILRequest rr)6434     private void decrementWakeLock(RILRequest rr) {
6435         synchronized (rr) {
6436             switch(rr.mWakeLockType) {
6437                 case FOR_WAKELOCK:
6438                     synchronized (mWakeLock) {
6439                         mClientWakelockTracker.stopTracking(rr.mClientId,
6440                                 rr.mRequest, rr.mSerial,
6441                                 (mWakeLockCount > 1) ? mWakeLockCount - 1 : 0);
6442                         String clientId = rr.getWorkSourceClientId();
6443                         if (!mClientWakelockTracker.isClientActive(clientId)) {
6444                             mActiveWakelockWorkSource.remove(rr.mWorkSource);
6445                             mWakeLock.setWorkSource(mActiveWakelockWorkSource);
6446                         }
6447 
6448                         if (mWakeLockCount > 1) {
6449                             mWakeLockCount--;
6450                         } else {
6451                             mWakeLockCount = 0;
6452                             mWakeLock.release();
6453                         }
6454                     }
6455                     break;
6456                 case FOR_ACK_WAKELOCK:
6457                     //We do not decrement the ACK wakelock
6458                     break;
6459                 case INVALID_WAKELOCK:
6460                     break;
6461                 default:
6462                     Rlog.w(RILJ_LOG_TAG, "Decrementing Invalid Wakelock type " + rr.mWakeLockType);
6463             }
6464             rr.mWakeLockType = INVALID_WAKELOCK;
6465         }
6466     }
6467 
6468     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
clearWakeLock(int wakeLockType)6469     private boolean clearWakeLock(int wakeLockType) {
6470         if (wakeLockType == FOR_WAKELOCK) {
6471             synchronized (mWakeLock) {
6472                 if (mWakeLockCount == 0 && !mWakeLock.isHeld()) return false;
6473                 Rlog.d(RILJ_LOG_TAG, "NOTE: mWakeLockCount is " + mWakeLockCount
6474                         + " at time of clearing");
6475                 mWakeLockCount = 0;
6476                 mWakeLock.release();
6477                 mClientWakelockTracker.stopTrackingAll();
6478                 mActiveWakelockWorkSource = new WorkSource();
6479                 return true;
6480             }
6481         } else {
6482             synchronized (mAckWakeLock) {
6483                 if (!mAckWakeLock.isHeld()) return false;
6484                 mAckWakeLock.release();
6485                 return true;
6486             }
6487         }
6488     }
6489 
6490     /**
6491      * Release each request in mRequestList then clear the list
6492      * @param error is the RIL_Errno sent back
6493      * @param loggable true means to print all requests in mRequestList
6494      */
6495     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
clearRequestList(int error, boolean loggable)6496     private void clearRequestList(int error, boolean loggable) {
6497         RILRequest rr;
6498         synchronized (mRequestList) {
6499             int count = mRequestList.size();
6500             if (RILJ_LOGD && loggable) {
6501                 Rlog.d(RILJ_LOG_TAG, "clearRequestList " + " mWakeLockCount="
6502                         + mWakeLockCount + " mRequestList=" + count);
6503             }
6504 
6505             for (int i = 0; i < count; i++) {
6506                 rr = mRequestList.valueAt(i);
6507                 if (RILJ_LOGD && loggable) {
6508                     Rlog.d(RILJ_LOG_TAG, i + ": [" + rr.mSerial + "] "
6509                             + RILUtils.requestToString(rr.mRequest));
6510                 }
6511                 rr.onError(error, null);
6512                 decrementWakeLock(rr);
6513                 rr.release();
6514             }
6515             mRequestList.clear();
6516         }
6517     }
6518 
6519     @UnsupportedAppUsage
findAndRemoveRequestFromList(int serial)6520     private RILRequest findAndRemoveRequestFromList(int serial) {
6521         RILRequest rr;
6522         synchronized (mRequestList) {
6523             rr = mRequestList.get(serial);
6524             if (rr != null) {
6525                 mRequestList.remove(serial);
6526             }
6527         }
6528 
6529         return rr;
6530     }
6531 
addToRilHistogram(RILRequest rr)6532     private void addToRilHistogram(RILRequest rr) {
6533         long endTime = SystemClock.elapsedRealtime();
6534         int totalTime = (int) (endTime - rr.mStartTimeMs);
6535 
6536         synchronized (sRilTimeHistograms) {
6537             TelephonyHistogram entry = sRilTimeHistograms.get(rr.mRequest);
6538             if (entry == null) {
6539                 // We would have total #RIL_HISTOGRAM_BUCKET_COUNT range buckets for RIL commands
6540                 entry = new TelephonyHistogram(TelephonyHistogram.TELEPHONY_CATEGORY_RIL,
6541                         rr.mRequest, RIL_HISTOGRAM_BUCKET_COUNT);
6542                 sRilTimeHistograms.put(rr.mRequest, entry);
6543             }
6544             entry.addTimeTaken(totalTime);
6545         }
6546     }
6547 
6548     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
makeStaticRadioCapability()6549     RadioCapability makeStaticRadioCapability() {
6550         // default to UNKNOWN so we fail fast.
6551         int raf = RadioAccessFamily.RAF_UNKNOWN;
6552 
6553         String rafString = mContext.getResources().getString(
6554                 com.android.internal.R.string.config_radio_access_family);
6555         if (!TextUtils.isEmpty(rafString)) {
6556             raf = RadioAccessFamily.rafTypeFromString(rafString);
6557         }
6558         RadioCapability rc = new RadioCapability(mPhoneId.intValue(), 0, 0, raf,
6559                 "", RadioCapability.RC_STATUS_SUCCESS);
6560         if (RILJ_LOGD) riljLog("Faking RIL_REQUEST_GET_RADIO_CAPABILITY response using " + raf);
6561         return rc;
6562     }
6563 
6564     @UnsupportedAppUsage
retToString(int req, Object ret)6565     static String retToString(int req, Object ret) {
6566         if (ret == null) return "";
6567         switch (req) {
6568             // Don't log these return values, for privacy's sake.
6569             case RIL_REQUEST_GET_IMSI:
6570             case RIL_REQUEST_GET_IMEI:
6571             case RIL_REQUEST_GET_IMEISV:
6572             case RIL_REQUEST_SIM_OPEN_CHANNEL:
6573             case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL:
6574 
6575                 if (!RILJ_LOGV) {
6576                     // If not versbose logging just return and don't display IMSI and IMEI, IMEISV
6577                     return "";
6578                 }
6579         }
6580 
6581         StringBuilder sb;
6582         String s;
6583         int length;
6584         if (ret instanceof int[]) {
6585             int[] intArray = (int[]) ret;
6586             length = intArray.length;
6587             sb = new StringBuilder("{");
6588             if (length > 0) {
6589                 int i = 0;
6590                 sb.append(intArray[i++]);
6591                 while (i < length) {
6592                     sb.append(", ").append(intArray[i++]);
6593                 }
6594             }
6595             sb.append("}");
6596             s = sb.toString();
6597         } else if (ret instanceof String[]) {
6598             String[] strings = (String[]) ret;
6599             length = strings.length;
6600             sb = new StringBuilder("{");
6601             if (length > 0) {
6602                 int i = 0;
6603                 // position 0 is IMEI in RIL_REQUEST_DEVICE_IDENTITY
6604                 if (req == RIL_REQUEST_DEVICE_IDENTITY) {
6605                     sb.append(Rlog.pii(RILJ_LOG_TAG, strings[i++]));
6606                 } else {
6607                     sb.append(strings[i++]);
6608                 }
6609                 while (i < length) {
6610                     sb.append(", ").append(strings[i++]);
6611                 }
6612             }
6613             sb.append("}");
6614             s = sb.toString();
6615         } else if (req == RIL_REQUEST_GET_CURRENT_CALLS) {
6616             ArrayList<DriverCall> calls = (ArrayList<DriverCall>) ret;
6617             sb = new StringBuilder("{");
6618             for (DriverCall dc : calls) {
6619                 sb.append("[").append(dc).append("] ");
6620             }
6621             sb.append("}");
6622             s = sb.toString();
6623         } else if (req == RIL_REQUEST_GET_NEIGHBORING_CELL_IDS) {
6624             ArrayList<NeighboringCellInfo> cells = (ArrayList<NeighboringCellInfo>) ret;
6625             sb = new StringBuilder("{");
6626             for (NeighboringCellInfo cell : cells) {
6627                 sb.append("[").append(cell).append("] ");
6628             }
6629             sb.append("}");
6630             s = sb.toString();
6631         } else if (req == RIL_REQUEST_QUERY_CALL_FORWARD_STATUS) {
6632             CallForwardInfo[] cinfo = (CallForwardInfo[]) ret;
6633             length = cinfo.length;
6634             sb = new StringBuilder("{");
6635             for (int i = 0; i < length; i++) {
6636                 sb.append("[").append(cinfo[i]).append("] ");
6637             }
6638             sb.append("}");
6639             s = sb.toString();
6640         } else if (req == RIL_REQUEST_GET_HARDWARE_CONFIG) {
6641             ArrayList<HardwareConfig> hwcfgs = (ArrayList<HardwareConfig>) ret;
6642             sb = new StringBuilder(" ");
6643             for (HardwareConfig hwcfg : hwcfgs) {
6644                 sb.append("[").append(hwcfg).append("] ");
6645             }
6646             s = sb.toString();
6647         } else if (req == RIL_REQUEST_START_IMS_TRAFFIC
6648                 || req == RIL_UNSOL_CONNECTION_SETUP_FAILURE) {
6649             sb = new StringBuilder("{");
6650             Object[] info = (Object[]) ret;
6651             int token = (Integer) info[0];
6652             sb.append(token).append(", ");
6653             if (info[1] != null) {
6654                 ConnectionFailureInfo failureInfo = (ConnectionFailureInfo) info[1];
6655                 sb.append(failureInfo.getReason()).append(", ");
6656                 sb.append(failureInfo.getCauseCode()).append(", ");
6657                 sb.append(failureInfo.getWaitTimeMillis());
6658             } else {
6659                 sb.append("null");
6660             }
6661             sb.append("}");
6662             s = sb.toString();
6663         } else {
6664             // Check if toString() was overridden. Java classes created from HIDL have a built-in
6665             // toString() method, but AIDL classes only have it if the parcelable contains a
6666             // @JavaDerive annotation. Manually convert to String as a backup for AIDL parcelables
6667             // missing the annotation.
6668             boolean toStringExists = false;
6669             try {
6670                 toStringExists = ret.getClass().getMethod("toString").getDeclaringClass()
6671                         != Object.class;
6672             } catch (NoSuchMethodException e) {
6673                 Rlog.e(RILJ_LOG_TAG, e.getMessage());
6674             }
6675             if (toStringExists) {
6676                 s = ret.toString();
6677             } else {
6678                 s = RILUtils.convertToString(ret) + " [convertToString]";
6679             }
6680         }
6681         return s;
6682     }
6683 
writeMetricsCallRing(char[] response)6684     void writeMetricsCallRing(char[] response) {
6685         mMetrics.writeRilCallRing(mPhoneId, response);
6686     }
6687 
writeMetricsSrvcc(int state)6688     void writeMetricsSrvcc(int state) {
6689         mMetrics.writeRilSrvcc(mPhoneId, state);
6690         PhoneFactory.getPhone(mPhoneId).getVoiceCallSessionStats().onRilSrvccStateChanged(state);
6691     }
6692 
writeMetricsModemRestartEvent(String reason)6693     void writeMetricsModemRestartEvent(String reason) {
6694         mMetrics.writeModemRestartEvent(mPhoneId, reason);
6695         // Write metrics to statsd. Generate metric only when modem reset is detected by the
6696         // first instance of RIL to avoid duplicated events.
6697         if (mPhoneId == 0) {
6698             ModemRestartStats.onModemRestart(reason);
6699         }
6700     }
6701 
6702     /**
6703      * Notify all registrants that the ril has connected or disconnected.
6704      *
6705      * @param rilVer is the version of the ril or -1 if disconnected.
6706      */
6707     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
notifyRegistrantsRilConnectionChanged(int rilVer)6708     void notifyRegistrantsRilConnectionChanged(int rilVer) {
6709         mRilVersion = rilVer;
6710         if (mRilConnectedRegistrants != null) {
6711             mRilConnectedRegistrants.notifyRegistrants(
6712                     new AsyncResult(null, new Integer(rilVer), null));
6713         }
6714     }
6715 
6716     @UnsupportedAppUsage
notifyRegistrantsCdmaInfoRec(CdmaInformationRecords infoRec)6717     void notifyRegistrantsCdmaInfoRec(CdmaInformationRecords infoRec) {
6718         int response = RIL_UNSOL_CDMA_INFO_REC;
6719         if (infoRec.record instanceof CdmaInformationRecords.CdmaDisplayInfoRec) {
6720             if (mDisplayInfoRegistrants != null) {
6721                 if (isLogOrTrace()) unsljLogRet(response, infoRec.record);
6722                 mDisplayInfoRegistrants.notifyRegistrants(
6723                         new AsyncResult(null, infoRec.record, null));
6724             }
6725         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaSignalInfoRec) {
6726             if (mSignalInfoRegistrants != null) {
6727                 if (isLogOrTrace()) unsljLogRet(response, infoRec.record);
6728                 mSignalInfoRegistrants.notifyRegistrants(
6729                         new AsyncResult(null, infoRec.record, null));
6730             }
6731         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaNumberInfoRec) {
6732             if (mNumberInfoRegistrants != null) {
6733                 if (isLogOrTrace()) unsljLogRet(response, infoRec.record);
6734                 mNumberInfoRegistrants.notifyRegistrants(
6735                         new AsyncResult(null, infoRec.record, null));
6736             }
6737         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaRedirectingNumberInfoRec) {
6738             if (mRedirNumInfoRegistrants != null) {
6739                 if (isLogOrTrace()) unsljLogRet(response, infoRec.record);
6740                 mRedirNumInfoRegistrants.notifyRegistrants(
6741                         new AsyncResult(null, infoRec.record, null));
6742             }
6743         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaLineControlInfoRec) {
6744             if (mLineControlInfoRegistrants != null) {
6745                 if (isLogOrTrace()) unsljLogRet(response, infoRec.record);
6746                 mLineControlInfoRegistrants.notifyRegistrants(
6747                         new AsyncResult(null, infoRec.record, null));
6748             }
6749         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaT53ClirInfoRec) {
6750             if (mT53ClirInfoRegistrants != null) {
6751                 if (isLogOrTrace()) unsljLogRet(response, infoRec.record);
6752                 mT53ClirInfoRegistrants.notifyRegistrants(
6753                         new AsyncResult(null, infoRec.record, null));
6754             }
6755         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaT53AudioControlInfoRec) {
6756             if (mT53AudCntrlInfoRegistrants != null) {
6757                 if (isLogOrTrace()) {
6758                     unsljLogRet(response, infoRec.record);
6759                 }
6760                 mT53AudCntrlInfoRegistrants.notifyRegistrants(
6761                         new AsyncResult(null, infoRec.record, null));
6762             }
6763         }
6764     }
6765 
6766     @UnsupportedAppUsage
riljLog(String msg)6767     void riljLog(String msg) {
6768         Rlog.d(RILJ_LOG_TAG, msg + (" [PHONE" + mPhoneId + "]"));
6769     }
6770 
riljLoge(String msg)6771     void riljLoge(String msg) {
6772         Rlog.e(RILJ_LOG_TAG, msg + (" [PHONE" + mPhoneId + "]"));
6773     }
6774 
riljLogv(String msg)6775     void riljLogv(String msg) {
6776         Rlog.v(RILJ_LOG_TAG, msg + (" [PHONE" + mPhoneId + "]"));
6777     }
6778 
isLogOrTrace()6779     boolean isLogOrTrace() {
6780         return RIL.RILJ_LOGD || Trace.isTagEnabled(Trace.TRACE_TAG_NETWORK);
6781     }
6782 
isLogvOrTrace()6783     boolean isLogvOrTrace() {
6784         return RIL.RILJ_LOGV || Trace.isTagEnabled(Trace.TRACE_TAG_NETWORK);
6785     }
6786 
6787     @UnsupportedAppUsage
unsljLog(int response)6788     void unsljLog(int response) {
6789         String logStr = RILUtils.responseToString(response);
6790         if (RIL.RILJ_LOGD) {
6791             riljLog("[UNSL]< " + logStr);
6792         }
6793         Trace.instantForTrack(Trace.TRACE_TAG_NETWORK, "RIL", logStr);
6794     }
6795 
6796     @UnsupportedAppUsage
unsljLogMore(int response, String more)6797     void unsljLogMore(int response, String more) {
6798         String logStr = RILUtils.responseToString(response) + " " + more;
6799         if (RIL.RILJ_LOGD) {
6800             riljLog("[UNSL]< " + logStr);
6801         }
6802         Trace.instantForTrack(Trace.TRACE_TAG_NETWORK, "RIL", logStr);
6803     }
6804 
6805     @UnsupportedAppUsage
unsljLogRet(int response, Object ret)6806     void unsljLogRet(int response, Object ret) {
6807         String logStr = RILUtils.responseToString(response) + " " + retToString(response, ret);
6808         if (RIL.RILJ_LOGD) {
6809             riljLog("[UNSL]< " + logStr);
6810         }
6811         Trace.instantForTrack(Trace.TRACE_TAG_NETWORK, "RIL", logStr);
6812     }
6813 
6814     @UnsupportedAppUsage
unsljLogvRet(int response, Object ret)6815     void unsljLogvRet(int response, Object ret) {
6816         String logStr = RILUtils.responseToString(response) + " " + retToString(response, ret);
6817         if (RIL.RILJ_LOGV) {
6818             riljLogv("[UNSL]< " + logStr);
6819         }
6820         Trace.instantForTrack(Trace.TRACE_TAG_NETWORK, "RIL", logStr);
6821     }
6822 
6823     @Override
setPhoneType(int phoneType)6824     public void setPhoneType(int phoneType) { // Called by GsmCdmaPhone
6825         if (RILJ_LOGD) riljLog("setPhoneType=" + phoneType + " old value=" + mPhoneType);
6826         mPhoneType = phoneType;
6827     }
6828 
6829     /* (non-Javadoc)
6830      * @see com.android.internal.telephony.BaseCommands#testingEmergencyCall()
6831      */
6832     @Override
testingEmergencyCall()6833     public void testingEmergencyCall() {
6834         if (RILJ_LOGD) riljLog("testingEmergencyCall");
6835         mTestingEmergencyCall.set(true);
6836     }
6837 
dump(FileDescriptor fd, PrintWriter pw, String[] args)6838     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
6839         pw.println("RIL: " + this);
6840         pw.println(" " + mServiceProxies.get(HAL_SERVICE_DATA));
6841         pw.println(" " + mServiceProxies.get(HAL_SERVICE_MESSAGING));
6842         pw.println(" " + mServiceProxies.get(HAL_SERVICE_MODEM));
6843         pw.println(" " + mServiceProxies.get(HAL_SERVICE_NETWORK));
6844         pw.println(" " + mServiceProxies.get(HAL_SERVICE_SIM));
6845         pw.println(" " + mServiceProxies.get(HAL_SERVICE_VOICE));
6846         pw.println(" " + mServiceProxies.get(HAL_SERVICE_IMS));
6847         pw.println(" mWakeLock=" + mWakeLock);
6848         pw.println(" mWakeLockTimeout=" + mWakeLockTimeout);
6849         synchronized (mRequestList) {
6850             synchronized (mWakeLock) {
6851                 pw.println(" mWakeLockCount=" + mWakeLockCount);
6852             }
6853             int count = mRequestList.size();
6854             pw.println(" mRequestList count=" + count);
6855             for (int i = 0; i < count; i++) {
6856                 RILRequest rr = mRequestList.valueAt(i);
6857                 pw.println("  [" + rr.mSerial + "] " + RILUtils.requestToString(rr.mRequest));
6858             }
6859         }
6860         pw.println(" mLastNITZTimeInfo=" + Arrays.toString(mLastNITZTimeInfo));
6861         pw.println(" mLastRadioPowerResult=" + mLastRadioPowerResult);
6862         pw.println(" mTestingEmergencyCall=" + mTestingEmergencyCall.get());
6863         mClientWakelockTracker.dumpClientRequestTracker(pw);
6864     }
6865 
getClientRequestStats()6866     public List<ClientRequestStats> getClientRequestStats() {
6867         return mClientWakelockTracker.getClientRequestStats();
6868     }
6869 
6870     /**
6871      * Fixup for SignalStrength 1.0 to Assume GSM to WCDMA when
6872      * The current RAT type is one of the UMTS RATs.
6873      * @param signalStrength the initial signal strength
6874      * @return a new SignalStrength if RAT is UMTS or existing SignalStrength
6875      */
fixupSignalStrength10(SignalStrength signalStrength)6876     public SignalStrength fixupSignalStrength10(SignalStrength signalStrength) {
6877         List<CellSignalStrengthGsm> gsmList = signalStrength.getCellSignalStrengths(
6878                 CellSignalStrengthGsm.class);
6879         // If GSM is not the primary type, then bail out; no fixup needed.
6880         if (gsmList.isEmpty() || !gsmList.get(0).isValid()) {
6881             return signalStrength;
6882         }
6883 
6884         CellSignalStrengthGsm gsmStrength = gsmList.get(0);
6885 
6886         // Use the voice RAT which is a guarantee in GSM and UMTS
6887         int voiceRat = ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN;
6888         Phone phone = PhoneFactory.getPhone(mPhoneId);
6889         if (phone != null) {
6890             ServiceState ss = phone.getServiceState();
6891             if (ss != null) {
6892                 voiceRat = ss.getRilVoiceRadioTechnology();
6893             }
6894         }
6895         switch (voiceRat) {
6896             case ServiceState.RIL_RADIO_TECHNOLOGY_UMTS: /* fallthrough */
6897             case ServiceState.RIL_RADIO_TECHNOLOGY_HSDPA: /* fallthrough */
6898             case ServiceState.RIL_RADIO_TECHNOLOGY_HSUPA: /* fallthrough */
6899             case ServiceState.RIL_RADIO_TECHNOLOGY_HSPA: /* fallthrough */
6900             case ServiceState.RIL_RADIO_TECHNOLOGY_HSPAP: /* fallthrough */
6901                 break;
6902             default:
6903                 // If we are not currently on WCDMA/HSPA, then we don't need to do a fixup.
6904                 return signalStrength;
6905         }
6906 
6907         // The service state reports WCDMA, and the SignalStrength is reported for GSM, so at this
6908         // point we take an educated guess that the GSM SignalStrength report is actually for
6909         // WCDMA. Also, if we are in WCDMA/GSM we can safely assume that there are no other valid
6910         // signal strength reports (no SRLTE, which is the only supported case in HAL 1.0).
6911         // Thus, we just construct a new SignalStrength and migrate RSSI and BER from the
6912         // GSM report to the WCDMA report, leaving everything else empty.
6913         return new SignalStrength(
6914                 new CellSignalStrengthCdma(), new CellSignalStrengthGsm(),
6915                 new CellSignalStrengthWcdma(gsmStrength.getRssi(),
6916                         gsmStrength.getBitErrorRate(),
6917                         CellInfo.UNAVAILABLE, CellInfo.UNAVAILABLE),
6918                 new CellSignalStrengthTdscdma(), new CellSignalStrengthLte(),
6919                 new CellSignalStrengthNr());
6920     }
6921 
notifyBarringInfoChanged(@onNull BarringInfo barringInfo)6922     void notifyBarringInfoChanged(@NonNull BarringInfo barringInfo) {
6923         mLastBarringInfo = barringInfo;
6924         mBarringInfoChangedRegistrants.notifyRegistrants(new AsyncResult(null, barringInfo, null));
6925     }
6926 
6927     /**
6928      * Get the HAL version with a specific service.
6929      *
6930      * @param service the hal service id
6931      * @return the current HalVersion
6932      */
getHalVersion(int service)6933     public HalVersion getHalVersion(int service) {
6934         HalVersion halVersion = mHalVersion.get(service);
6935         if (halVersion == null) {
6936             if (isRadioServiceSupported(service)) {
6937                 halVersion = RADIO_HAL_VERSION_UNKNOWN;
6938             } else {
6939                 halVersion = RADIO_HAL_VERSION_UNSUPPORTED;
6940             }
6941         }
6942         return halVersion;
6943     }
6944 
6945     /**
6946      * Get the HAL version corresponding to the interface version of a IRadioService module.
6947      * @param interfaceVersion The interface version, from IRadioService#getInterfaceVersion().
6948      * @return The corresponding HalVersion.
6949      */
getServiceHalVersion(int interfaceVersion)6950     public static HalVersion getServiceHalVersion(int interfaceVersion) {
6951         switch (interfaceVersion) {
6952             case 1: return RADIO_HAL_VERSION_2_0;
6953             case 2: return RADIO_HAL_VERSION_2_1;
6954             default: return RADIO_HAL_VERSION_UNKNOWN;
6955         }
6956     }
6957 
serviceToString(@alService int service)6958     private static String serviceToString(@HalService int service) {
6959         switch (service) {
6960             case HAL_SERVICE_RADIO:
6961                 return "RADIO";
6962             case HAL_SERVICE_DATA:
6963                 return "DATA";
6964             case HAL_SERVICE_MESSAGING:
6965                 return "MESSAGING";
6966             case HAL_SERVICE_MODEM:
6967                 return "MODEM";
6968             case HAL_SERVICE_NETWORK:
6969                 return "NETWORK";
6970             case HAL_SERVICE_SIM:
6971                 return "SIM";
6972             case HAL_SERVICE_VOICE:
6973                 return "VOICE";
6974             case HAL_SERVICE_IMS:
6975                 return "IMS";
6976             default:
6977                 return "UNKNOWN:" + service;
6978         }
6979     }
6980 }
6981