aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/android/internal/telephony/TelephonyCountryDetector.java
blob: 56e8b464a809054389b3f3c01d9a2a50a9ec65c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony;


import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.telephony.Rlog;
import android.util.Pair;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * This class is used to detect the country where the device is.
 *
 * {@link LocaleTracker} also tracks country of a device based on the information provided by
 * network operators. However, it won't work when a device is out of service. In such cases and if
 * Wi-Fi is available, {@link Geocoder} can be used to query the country for the current location of
 * the device. {@link TelephonyCountryDetector} uses both {@link LocaleTracker} and {@link Geocoder}
 * to track country of a device.
 */
public class TelephonyCountryDetector extends Handler {
    private static final String TAG = "TelephonyCountryDetector";
    private static final String ALLOW_MOCK_MODEM_PROPERTY = "persist.radio.allow_mock_modem";
    private static final String BOOT_ALLOW_MOCK_MODEM_PROPERTY = "ro.boot.radio.allow_mock_modem";
    private static final boolean DEBUG = !"user".equals(Build.TYPE);
    private static final int EVENT_LOCATION_CHANGED = 1;
    private static final int EVENT_LOCATION_COUNTRY_CODE_CHANGED = 2;
    private static final int EVENT_NETWORK_COUNTRY_CODE_CHANGED = 3;
    private static final int EVENT_WIFI_CONNECTIVITY_STATE_CHANGED = 4;
    private static final int EVENT_LOCATION_UPDATE_REQUEST_QUOTA_RESET = 5;

    // Wait 12 hours between location updates
    private static final long TIME_BETWEEN_LOCATION_UPDATES_MILLIS = TimeUnit.HOURS.toMillis(12);
    // Minimum distance before a location update is triggered, in meters. We don't need this to be
    // too exact because all we care about is in what country the device is.
    private static final float DISTANCE_BETWEEN_LOCATION_UPDATES_METERS = 2000;
    protected static final long WAIT_FOR_LOCATION_UPDATE_REQUEST_QUOTA_RESET_TIMEOUT_MILLIS =
            TimeUnit.MINUTES.toMillis(30);

    private static TelephonyCountryDetector sInstance;

    @NonNull private final Geocoder mGeocoder;
    @NonNull private final LocationManager mLocationManager;
    @NonNull private final ConnectivityManager mConnectivityManager;
    @NonNull private final Object mLock = new Object();
    @NonNull
    @GuardedBy("mLock")
    private final Map<Integer, NetworkCountryCodeInfo> mNetworkCountryCodeInfoPerPhone =
            new HashMap<>();
    @GuardedBy("mLock")
    private String mLocationCountryCode = null;
    /** This should be used by CTS only */
    @GuardedBy("mLock")
    private String mOverriddenLocationCountryCode = null;
    @GuardedBy("mLock")
    private boolean mIsLocationUpdateRequested = false;
    @GuardedBy("mLock")
    private long mLocationCountryCodeUpdatedTimestampNanos = 0;
    /** This should be used by CTS only */
    @GuardedBy("mLock")
    private long mOverriddenLocationCountryCodeUpdatedTimestampNanos = 0;
    @GuardedBy("mLock")
    private List<String> mOverriddenCurrentNetworkCountryCodes = null;
    @GuardedBy("mLock")
    private Map<String, Long> mOverriddenCachedNetworkCountryCodes = new HashMap<>();
    @GuardedBy("mLock")
    private boolean mIsCountryCodesOverridden = false;
    @NonNull private final LocationListener mLocationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            logd("onLocationChanged: " + (location != null));
            if (location != null) {
                sendRequestAsync(EVENT_LOCATION_CHANGED, location);
            }
        }

        @Override
        public void onProviderDisabled(String provider) {
            logd("onProviderDisabled: provider=" + provider);
        }

        @Override
        public void onProviderEnabled(String provider) {
            logd("onProviderEnabled: provider=" + provider);
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            logd("onStatusChanged: provider=" + provider + ", status=" + status
                    + ", extras=" + extras);
        }
    };

    private class TelephonyGeocodeListener implements Geocoder.GeocodeListener {
        private long mLocationUpdatedTime;
        TelephonyGeocodeListener(long locationUpdatedTime) {
            mLocationUpdatedTime = locationUpdatedTime;
        }

        @Override
        public void onGeocode(List<Address> addresses) {
            if (addresses != null && !addresses.isEmpty()) {
                logd("onGeocode: addresses is available");
                String countryCode = addresses.get(0).getCountryCode();
                sendRequestAsync(EVENT_LOCATION_COUNTRY_CODE_CHANGED,
                        new Pair<>(countryCode, mLocationUpdatedTime));
            } else {
                logd("onGeocode: addresses is not available");
            }
        }

        @Override
        public void onError(String errorMessage) {
            loge("GeocodeListener.onError=" + errorMessage);
        }
    }

    /**
     * Container class to store country code per Phone.
     */
    private static class NetworkCountryCodeInfo {
        public int phoneId;
        public String countryCode;
        public long timestamp;

        @Override
        public String toString() {
            return "NetworkCountryCodeInfo[phoneId: " + phoneId
                    + ", countryCode: " + countryCode
                    + ", timestamp: " + timestamp + "]";
        }
    }

    /**
     * Create the singleton instance of {@link TelephonyCountryDetector}.
     *
     * @param looper The looper to run the {@link TelephonyCountryDetector} instance.
     * @param context The context used by the instance.
     * @param locationManager The LocationManager instance.
     * @param connectivityManager The ConnectivityManager instance.
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected TelephonyCountryDetector(@NonNull Looper looper, @NonNull Context context,
            @NonNull LocationManager locationManager,
            @NonNull ConnectivityManager connectivityManager) {
        super(looper);
        mLocationManager = locationManager;
        mGeocoder = new Geocoder(context);
        mConnectivityManager = connectivityManager;
        initialize();
    }

    /** @return the singleton instance of the {@link TelephonyCountryDetector} */
    public static synchronized TelephonyCountryDetector getInstance(@NonNull Context context) {
        if (sInstance == null) {
            HandlerThread handlerThread = new HandlerThread("TelephonyCountryDetector");
            handlerThread.start();
            sInstance = new TelephonyCountryDetector(handlerThread.getLooper(), context,
                    context.getSystemService(LocationManager.class),
                    context.getSystemService(ConnectivityManager.class));
        }
        return sInstance;
    }

    /**
     * @return The list of current network country ISOs if available, an empty list otherwise.
     */
    @NonNull public List<String> getCurrentNetworkCountryIso() {
        synchronized (mLock) {
            if (mIsCountryCodesOverridden) {
                logd("mOverriddenCurrentNetworkCountryCodes="
                        + String.join(", ", mOverriddenCurrentNetworkCountryCodes));
                return mOverriddenCurrentNetworkCountryCodes;
            }
        }

        List<String> result = new ArrayList<>();
        for (Phone phone : PhoneFactory.getPhones()) {
            String countryIso = getNetworkCountryIsoForPhone(phone);
            if (isValid(countryIso)) {
                String countryIsoInUpperCase = countryIso.toUpperCase(Locale.US);
                if (!result.contains(countryIsoInUpperCase)) {
                    result.add(countryIsoInUpperCase);
                }
            } else {
                logd("getCurrentNetworkCountryIso: invalid countryIso=" + countryIso
                        + " for phoneId=" + phone.getPhoneId() + ", subId=" + phone.getSubId());
            }
        }
        return result;
    }

    /**
     * @return The cached location country code and its updated timestamp.
     */
    @NonNull public Pair<String, Long> getCachedLocationCountryIsoInfo() {
        synchronized (mLock) {
            if (mIsCountryCodesOverridden) {
                logd("mOverriddenLocationCountryCode=" + mOverriddenLocationCountryCode
                        + " will be used");
                return new Pair<>(mOverriddenLocationCountryCode,
                        mOverriddenLocationCountryCodeUpdatedTimestampNanos);
            }
            return new Pair<>(mLocationCountryCode, mLocationCountryCodeUpdatedTimestampNanos);
        }
    }

    /**
     * This API should be used only when {@link #getCurrentNetworkCountryIso()} returns an empty
     * list.
     *
     * @return The list of cached network country codes and their updated timestamps.
     */
    @NonNull public Map<String, Long> getCachedNetworkCountryIsoInfo() {
        synchronized (mLock) {
            if (mIsCountryCodesOverridden) {
                logd("mOverriddenCachedNetworkCountryCodes = "
                        + String.join(", ", mOverriddenCachedNetworkCountryCodes.keySet())
                        + " will be used");
                return mOverriddenCachedNetworkCountryCodes;
            }
            Map<String, Long> result = new HashMap<>();
            for (NetworkCountryCodeInfo countryCodeInfo :
                    mNetworkCountryCodeInfoPerPhone.values()) {
                boolean alreadyAdded = result.containsKey(countryCodeInfo.countryCode);
                if (!alreadyAdded || (alreadyAdded
                        && result.get(countryCodeInfo.countryCode) < countryCodeInfo.timestamp)) {
                    result.put(countryCodeInfo.countryCode, countryCodeInfo.timestamp);
                }
            }
            return result;
        }
    }

    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case EVENT_LOCATION_CHANGED:
                queryCountryCodeForLocation((Location) msg.obj);
                break;
            case EVENT_LOCATION_COUNTRY_CODE_CHANGED:
                setLocationCountryCode((Pair) msg.obj);
                break;
            case EVENT_NETWORK_COUNTRY_CODE_CHANGED:
                handleNetworkCountryCodeChangedEvent((NetworkCountryCodeInfo) msg.obj);
                break;
            case EVENT_WIFI_CONNECTIVITY_STATE_CHANGED:
            case EVENT_LOCATION_UPDATE_REQUEST_QUOTA_RESET:
                evaluateRequestingLocationUpdates();
                break;
            default:
                logw("CountryDetectorHandler: unexpected message code: " + msg.what);
                break;
        }
    }

    /**
     * This API is called by {@link LocaleTracker} whenever there is a change in network country
     * code of a phone.
     */
    public void onNetworkCountryCodeChanged(
            @NonNull Phone phone, @Nullable String currentCountryCode) {
        NetworkCountryCodeInfo networkCountryCodeInfo = new NetworkCountryCodeInfo();
        networkCountryCodeInfo.phoneId = phone.getPhoneId();
        networkCountryCodeInfo.countryCode = currentCountryCode;
        sendRequestAsync(EVENT_NETWORK_COUNTRY_CODE_CHANGED, networkCountryCodeInfo);
    }

    /**
     * This API should be used by only CTS tests to forcefully set the telephony country codes.
     */
    public boolean setCountryCodes(boolean reset, @NonNull List<String> currentNetworkCountryCodes,
            @NonNull Map<String, Long> cachedNetworkCountryCodes, String locationCountryCode,
            long locationCountryCodeTimestampNanos) {
        if (!isMockModemAllowed()) {
            logd("setCountryCodes: mock modem is not allowed");
            return false;
        }
        logd("setCountryCodes: currentNetworkCountryCodes="
                + String.join(", ", currentNetworkCountryCodes)
                + ", locationCountryCode=" + locationCountryCode
                + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
                + ", reset=" + reset + ", cachedNetworkCountryCodes="
                + String.join(", ", cachedNetworkCountryCodes.keySet()));

        synchronized (mLock) {
            if (reset) {
                mIsCountryCodesOverridden = false;
            } else {
                mIsCountryCodesOverridden = true;
                mOverriddenCachedNetworkCountryCodes = cachedNetworkCountryCodes;
                mOverriddenCurrentNetworkCountryCodes = currentNetworkCountryCodes;
                mOverriddenLocationCountryCode = locationCountryCode;
                mOverriddenLocationCountryCodeUpdatedTimestampNanos =
                        locationCountryCodeTimestampNanos;
            }
        }
        return true;
    }

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected void queryCountryCodeForLocation(@NonNull Location location) {
        mGeocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1,
                new TelephonyGeocodeListener(location.getElapsedRealtimeNanos()));
    }

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected long getElapsedRealtimeNanos() {
        return SystemClock.elapsedRealtimeNanos();
    }

    private void initialize() {
        evaluateRequestingLocationUpdates();
        registerForWifiConnectivityStateChanged();
    }

    private boolean isGeoCoderImplemented() {
        return Geocoder.isPresent();
    }

    private void registerForLocationUpdates() {
        // If the device does not implement Geocoder, there is no point trying to get location
        // updates because we cannot retrieve the country based on the location anyway.
        if (!isGeoCoderImplemented()) {
            logd("Geocoder is not implemented on the device");
            return;
        }

        synchronized (mLock) {
            if (mIsLocationUpdateRequested) {
                logd("Already registered for location updates");
                return;
            }

            logd("Registering for location updates");
            /*
             * PASSIVE_PROVIDER can be used to passively receive location updates when other
             * applications or services request them without actually requesting the locations
             * ourselves. This provider will only return locations generated by other providers.
             * This provider is used to make sure there is no impact on the thermal and battery of
             * a device.
             */
            mLocationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER,
                    TIME_BETWEEN_LOCATION_UPDATES_MILLIS, DISTANCE_BETWEEN_LOCATION_UPDATES_METERS,
                    mLocationListener);
            mIsLocationUpdateRequested = true;
            mLocationListener.onLocationChanged(getLastKnownLocation());
        }
    }

    @Nullable
    private Location getLastKnownLocation() {
        Location result = null;
        for (String provider : mLocationManager.getProviders(true)) {
            Location location = mLocationManager.getLastKnownLocation(provider);
            if (location != null && (result == null
                    || result.getElapsedRealtimeNanos() < location.getElapsedRealtimeNanos())) {
                result = location;
            }
        }
        return result;
    }

    private void unregisterForLocationUpdates() {
        synchronized (mLock) {
            if (!mIsLocationUpdateRequested) {
                logd("Location update was not requested yet");
                return;
            }
            if (isLocationUpdateRequestQuotaExceeded()) {
                logd("Removing location updates will be re-evaluated after the quota is refilled");
                return;
            }
            mLocationManager.removeUpdates(mLocationListener);
            mIsLocationUpdateRequested = false;
            sendMessageDelayed(obtainMessage(EVENT_LOCATION_UPDATE_REQUEST_QUOTA_RESET),
                    WAIT_FOR_LOCATION_UPDATE_REQUEST_QUOTA_RESET_TIMEOUT_MILLIS);
        }
    }

    private boolean isLocationUpdateRequestQuotaExceeded() {
        return hasMessages(EVENT_LOCATION_UPDATE_REQUEST_QUOTA_RESET);
    }

    private boolean shouldRequestLocationUpdate() {
        return getCurrentNetworkCountryIso().isEmpty() && isWifiNetworkConnected();
    }

    /**
     * Posts the specified command to be executed on the main thread and returns immediately.
     *
     * @param command command to be executed on the main thread
     * @param argument additional parameters required to perform of the operation
     */
    private void sendRequestAsync(int command, @NonNull Object argument) {
        Message msg = this.obtainMessage(command, argument);
        msg.sendToTarget();
    }

    private void handleNetworkCountryCodeChangedEvent(
            @NonNull NetworkCountryCodeInfo currentNetworkCountryCodeInfo) {
        logd("currentNetworkCountryCodeInfo=" + currentNetworkCountryCodeInfo);
        if (isValid(currentNetworkCountryCodeInfo.countryCode)) {
            synchronized (mLock) {
                NetworkCountryCodeInfo cachedNetworkCountryCodeInfo =
                        mNetworkCountryCodeInfoPerPhone.computeIfAbsent(
                                currentNetworkCountryCodeInfo.phoneId,
                                k -> new NetworkCountryCodeInfo());
                cachedNetworkCountryCodeInfo.phoneId = currentNetworkCountryCodeInfo.phoneId;
                cachedNetworkCountryCodeInfo.timestamp = getElapsedRealtimeNanos();
                cachedNetworkCountryCodeInfo.countryCode =
                        currentNetworkCountryCodeInfo.countryCode.toUpperCase(Locale.US);
            }
        } else {
            logd("handleNetworkCountryCodeChangedEvent: Got invalid or empty country code for "
                    + "phoneId=" + currentNetworkCountryCodeInfo.phoneId);
            synchronized (mLock) {
                if (mNetworkCountryCodeInfoPerPhone.containsKey(
                        currentNetworkCountryCodeInfo.phoneId)) {
                    // The country code has changed from valid to invalid. Thus, we need to update
                    // the last valid timestamp.
                    NetworkCountryCodeInfo cachedNetworkCountryCodeInfo =
                            mNetworkCountryCodeInfoPerPhone.get(
                                    currentNetworkCountryCodeInfo.phoneId);
                    cachedNetworkCountryCodeInfo.timestamp = getElapsedRealtimeNanos();
                }
            }
        }
        evaluateRequestingLocationUpdates();
    }

    private void setLocationCountryCode(@NonNull Pair<String, Long> countryCodeInfo) {
        logd("Set location country code to: " + countryCodeInfo.first);
        if (!isValid(countryCodeInfo.first)) {
            logd("Received invalid location country code");
        } else {
            synchronized (mLock) {
                mLocationCountryCode = countryCodeInfo.first.toUpperCase(Locale.US);
                mLocationCountryCodeUpdatedTimestampNanos = countryCodeInfo.second;
            }
        }
    }

    private String getNetworkCountryIsoForPhone(@NonNull Phone phone) {
        ServiceStateTracker serviceStateTracker = phone.getServiceStateTracker();
        if (serviceStateTracker == null) {
            logw("getNetworkCountryIsoForPhone: serviceStateTracker is null");
            return null;
        }

        LocaleTracker localeTracker = serviceStateTracker.getLocaleTracker();
        if (localeTracker == null) {
            logw("getNetworkCountryIsoForPhone: localeTracker is null");
            return null;
        }

        return localeTracker.getCurrentCountry();
    }

    private void registerForWifiConnectivityStateChanged() {
        logd("registerForWifiConnectivityStateChanged");
        NetworkRequest.Builder builder = new NetworkRequest.Builder();
        builder.addTransportType(NetworkCapabilities.TRANSPORT_WIFI);
        ConnectivityManager.NetworkCallback networkCallback =
                new ConnectivityManager.NetworkCallback() {
                    @Override
                    public void onAvailable(Network network) {
                        logd("Wifi network available: " + network);
                        sendRequestAsync(EVENT_WIFI_CONNECTIVITY_STATE_CHANGED, null);
                    }

                    @Override
                    public void onLost(Network network) {
                        logd("Wifi network lost: " + network);
                        sendRequestAsync(EVENT_WIFI_CONNECTIVITY_STATE_CHANGED, null);
                    }

                    @Override
                    public void onUnavailable() {
                        logd("Wifi network unavailable");
                        sendRequestAsync(EVENT_WIFI_CONNECTIVITY_STATE_CHANGED, null);
                    }
                };
        mConnectivityManager.registerNetworkCallback(builder.build(), networkCallback);
    }

    private void evaluateRequestingLocationUpdates() {
        if (shouldRequestLocationUpdate()) {
            registerForLocationUpdates();
        } else {
            unregisterForLocationUpdates();
        }
    }

    private boolean isWifiNetworkConnected() {
        Network activeNetwork = mConnectivityManager.getActiveNetwork();
        NetworkCapabilities networkCapabilities =
                mConnectivityManager.getNetworkCapabilities(activeNetwork);
        return networkCapabilities != null
                && networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
                && networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
    }

    /**
     * Check whether this is a valid country code.
     *
     * @param countryCode A 2-Character alphanumeric country code.
     * @return {@code true} if the countryCode is valid, {@code false} otherwise.
     */
    private static boolean isValid(String countryCode) {
        return countryCode != null && countryCode.length() == 2
                && countryCode.chars().allMatch(Character::isLetterOrDigit);
    }

    private static boolean isMockModemAllowed() {
        return (DEBUG || SystemProperties.getBoolean(ALLOW_MOCK_MODEM_PROPERTY, false)
                || SystemProperties.getBoolean(BOOT_ALLOW_MOCK_MODEM_PROPERTY, false));
    }

    private static void logd(@NonNull String log) {
        Rlog.d(TAG, log);
    }

    private static void logw(@NonNull String log) {
        Rlog.w(TAG, log);
    }

    private static void loge(@NonNull String log) {
        Rlog.e(TAG, log);
    }
}