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