| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 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.phone; | 
|  | 18 |  | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; | 
|  | 20 |  | 
| Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; | 
|  | 22 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; | 
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 23 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 24 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; | 
|  | 25 |  | 
| Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 26 | import android.Manifest; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 27 | import android.Manifest.permission; | 
| Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 28 | import android.annotation.NonNull; | 
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 29 | import android.annotation.Nullable; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 30 | import android.app.AppOpsManager; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 31 | import android.app.PendingIntent; | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 32 | import android.app.role.RoleManager; | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 33 | import android.content.ComponentName; | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 34 | import android.content.ContentResolver; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.content.Context; | 
|  | 36 | import android.content.Intent; | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 37 | import android.content.SharedPreferences; | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 38 | import android.content.pm.ComponentInfo; | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 39 | import android.content.pm.PackageInfo; | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 40 | import android.content.pm.PackageManager; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.net.Uri; | 
|  | 42 | import android.os.AsyncResult; | 
|  | 43 | import android.os.Binder; | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 44 | import android.os.Build; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Bundle; | 
|  | 46 | import android.os.Handler; | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.IBinder; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 48 | import android.os.Looper; | 
|  | 49 | import android.os.Message; | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 50 | import android.os.Messenger; | 
| Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 51 | import android.os.ParcelFileDescriptor; | 
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 52 | import android.os.ParcelUuid; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 53 | import android.os.PersistableBundle; | 
| Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 54 | import android.os.Process; | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 55 | import android.os.RemoteException; | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 56 | import android.os.ResultReceiver; | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 57 | import android.os.ServiceSpecificException; | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 58 | import android.os.SystemClock; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 59 | import android.os.UserHandle; | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 60 | import android.os.UserManager; | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 61 | import android.os.WorkSource; | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 62 | import android.preference.PreferenceManager; | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 63 | import android.provider.DeviceConfig; | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 64 | import android.provider.Settings; | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 65 | import android.provider.Telephony; | 
| Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 66 | import android.sysprop.TelephonyProperties; | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 67 | import android.telecom.PhoneAccount; | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 68 | import android.telecom.PhoneAccountHandle; | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 69 | import android.telecom.TelecomManager; | 
| Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 70 | import android.telephony.Annotation.ApnType; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 71 | import android.telephony.Annotation.ThermalMitigationResult; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 72 | import android.telephony.CallForwardingInfo; | 
| Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 73 | import android.telephony.CarrierConfigManager; | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 74 | import android.telephony.CarrierRestrictionRules; | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 75 | import android.telephony.CellIdentity; | 
| Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 76 | import android.telephony.CellIdentityCdma; | 
|  | 77 | import android.telephony.CellIdentityGsm; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 78 | import android.telephony.CellInfo; | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 79 | import android.telephony.CellInfoGsm; | 
|  | 80 | import android.telephony.CellInfoWcdma; | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 81 | import android.telephony.ClientRequestStats; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 82 | import android.telephony.DataThrottlingRequest; | 
| Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 83 | import android.telephony.IBootstrapAuthenticationCallback; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 84 | import android.telephony.ICellInfoCallback; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 85 | import android.telephony.IccOpenLogicalChannelResponse; | 
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 86 | import android.telephony.LocationAccessPolicy; | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 87 | import android.telephony.ModemActivityInfo; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 88 | import android.telephony.NeighboringCellInfo; | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 89 | import android.telephony.NetworkScanRequest; | 
| Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 90 | import android.telephony.PhoneCapability; | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 91 | import android.telephony.PhoneNumberRange; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 92 | import android.telephony.RadioAccessFamily; | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 93 | import android.telephony.RadioAccessSpecifier; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 94 | import android.telephony.ServiceState; | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 95 | import android.telephony.SignalStrength; | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 96 | import android.telephony.SignalStrengthUpdateRequest; | 
|  | 97 | import android.telephony.SignalThresholdInfo; | 
| Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 98 | import android.telephony.SubscriptionInfo; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 99 | import android.telephony.SubscriptionManager; | 
| Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 100 | import android.telephony.TelephonyFrameworkInitializer; | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 101 | import android.telephony.TelephonyHistogram; | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 102 | import android.telephony.TelephonyManager; | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 103 | import android.telephony.TelephonyScanManager; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 104 | import android.telephony.ThermalMitigationRequest; | 
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 105 | import android.telephony.UiccCardInfo; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 106 | import android.telephony.UiccSlotInfo; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 107 | import android.telephony.UssdResponse; | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 108 | import android.telephony.VisualVoicemailSmsFilterSettings; | 
| Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 109 | import android.telephony.data.ApnSetting; | 
|  | 110 | import android.telephony.emergency.EmergencyNumber; | 
| Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 111 | import android.telephony.gba.GbaAuthRequest; | 
|  | 112 | import android.telephony.gba.UaSecurityProtocolIdentifier; | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 113 | import android.telephony.ims.ImsException; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 114 | import android.telephony.ims.ProvisioningManager; | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 115 | import android.telephony.ims.RcsClientConfiguration; | 
| Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 116 | import android.telephony.ims.RcsContactUceCapability; | 
| Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 117 | import android.telephony.ims.RegistrationManager; | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 118 | import android.telephony.ims.aidl.IImsCapabilityCallback; | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 119 | import android.telephony.ims.aidl.IImsConfig; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 120 | import android.telephony.ims.aidl.IImsConfigCallback; | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 121 | import android.telephony.ims.aidl.IImsRegistration; | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 122 | import android.telephony.ims.aidl.IImsRegistrationCallback; | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 123 | import android.telephony.ims.aidl.IRcsConfigCallback; | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 124 | import android.telephony.ims.feature.ImsFeature; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 125 | import android.telephony.ims.feature.MmTelFeature; | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 126 | import android.telephony.ims.feature.RcsFeature; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 127 | import android.telephony.ims.stub.ImsConfigImplBase; | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 128 | import android.telephony.ims.stub.ImsRegistrationImplBase; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | import android.text.TextUtils; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 130 | import android.util.ArraySet; | 
| Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 131 | import android.util.EventLog; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 132 | import android.util.Log; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 133 | import android.util.Pair; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 134 |  | 
| Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 135 | import com.android.ims.ImsManager; | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 136 | import com.android.ims.internal.IImsServiceFeatureCallback; | 
| James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 137 | import com.android.ims.rcs.uce.eab.EabUtil; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.CallForwardInfo; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.CallManager; | 
| Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.CallStateException; | 
| pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.CarrierInfoManager; | 
| chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.CarrierResolver; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.CellNetworkScanResult; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.CommandException; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.CommandsInterface; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.DefaultPhoneNotifier; | 
| Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.GbaManager; | 
| Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.GsmCdmaPhone; | 
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.HalVersion; | 
| Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.IBooleanConsumer; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.ICallForwardingInfoCallback; | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.IIntegerConsumer; | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.INumberVerificationCallback; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.ITelephony; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.IccCard; | 
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.LocaleTracker; | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.NetworkScanRequestTracker; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.OperatorInfo; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.Phone; | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.PhoneConfigurationManager; | 
| Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.PhoneConstantConversions; | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.PhoneConstants; | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.PhoneFactory; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.ProxyController; | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.RIL; | 
| SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 166 | import com.android.internal.telephony.RILConstants; | 
| Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.RadioInterfaceCapabilityController; | 
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.ServiceStateTracker; | 
| Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.SmsController; | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.SmsPermissions; | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.SubscriptionController; | 
| Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 172 | import com.android.internal.telephony.TelephonyIntents; | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.TelephonyPermissions; | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; | 
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.euicc.EuiccConnector; | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 177 | import com.android.internal.telephony.ims.ImsResolver; | 
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.imsphone.ImsPhone; | 
|  | 179 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; | 
| Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.metrics.TelephonyMetrics; | 
| Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.IccIoResult; | 
| changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.IccRecords; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.uicc.IccUtils; | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.uicc.SIMRecords; | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.uicc.UiccCard; | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.uicc.UiccCardApplication; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.uicc.UiccController; | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.uicc.UiccProfile; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 190 | import com.android.internal.telephony.uicc.UiccSlot; | 
| zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 191 | import com.android.internal.telephony.util.LocaleUtils; | 
| fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 193 | import com.android.internal.util.FunctionalUtils; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 194 | import com.android.internal.util.HexDump; | 
| Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 195 | import com.android.phone.callcomposer.CallComposerPictureManager; | 
|  | 196 | import com.android.phone.callcomposer.CallComposerPictureTransfer; | 
|  | 197 | import com.android.phone.callcomposer.ImageData; | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 198 | import com.android.phone.settings.PickSmsSubscriptionActivity; | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 199 | import com.android.phone.vvm.PhoneAccountHandleConverter; | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 200 | import com.android.phone.vvm.RemoteVvmTaskManager; | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 201 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; | 
| Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 202 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 203 | import com.android.services.telephony.TelecomAccountRegistry; | 
|  | 204 | import com.android.services.telephony.TelephonyConnectionService; | 
| Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 205 | import com.android.telephony.Rlog; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 206 |  | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 207 | import java.io.ByteArrayOutputStream; | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 208 | import java.io.FileDescriptor; | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 209 | import java.io.IOException; | 
|  | 210 | import java.io.InputStream; | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 211 | import java.io.PrintWriter; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 212 | import java.util.ArrayList; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 213 | import java.util.Arrays; | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 214 | import java.util.HashMap; | 
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 215 | import java.util.HashSet; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 216 | import java.util.List; | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 217 | import java.util.Locale; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 218 | import java.util.Map; | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 219 | import java.util.NoSuchElementException; | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 220 | import java.util.Objects; | 
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 221 | import java.util.Set; | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 222 | import java.util.concurrent.Executors; | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 223 | import java.util.concurrent.atomic.AtomicBoolean; | 
| Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 224 | import java.util.function.Consumer; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 225 |  | 
|  | 226 | /** | 
|  | 227 | * Implementation of the ITelephony interface. | 
|  | 228 | */ | 
| Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 229 | public class PhoneInterfaceManager extends ITelephony.Stub { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 230 | private static final String LOG_TAG = "PhoneInterfaceManager"; | 
|  | 231 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); | 
|  | 232 | private static final boolean DBG_LOC = false; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 233 | private static final boolean DBG_MERGE = false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 234 |  | 
|  | 235 | // Message codes used with mMainThreadHandler | 
|  | 236 | private static final int CMD_HANDLE_PIN_MMI = 1; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 237 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; | 
|  | 238 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 239 | private static final int CMD_OPEN_CHANNEL = 9; | 
|  | 240 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; | 
|  | 241 | private static final int CMD_CLOSE_CHANNEL = 11; | 
|  | 242 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 243 | private static final int CMD_NV_READ_ITEM = 13; | 
|  | 244 | private static final int EVENT_NV_READ_ITEM_DONE = 14; | 
|  | 245 | private static final int CMD_NV_WRITE_ITEM = 15; | 
|  | 246 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; | 
|  | 247 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; | 
|  | 248 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 249 | private static final int CMD_RESET_MODEM_CONFIG = 19; | 
|  | 250 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 251 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; | 
|  | 252 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; | 
| Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 253 | private static final int CMD_SEND_ENVELOPE = 25; | 
|  | 254 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 255 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; | 
|  | 256 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; | 
| Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 257 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; | 
|  | 258 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; | 
|  | 259 | private static final int CMD_EXCHANGE_SIM_IO = 31; | 
|  | 260 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 261 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; | 
|  | 262 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 263 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; | 
|  | 264 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 265 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; | 
|  | 266 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 267 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; | 
|  | 268 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; | 
|  | 269 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; | 
|  | 270 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 271 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; | 
|  | 272 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; | 
|  | 273 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; | 
|  | 274 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 275 | private static final int CMD_HANDLE_USSD_REQUEST = 47; | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 276 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; | 
|  | 277 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 278 | private static final int CMD_SWITCH_SLOTS = 50; | 
|  | 279 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 280 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; | 
|  | 281 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; | 
|  | 282 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; | 
|  | 283 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; | 
|  | 284 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; | 
|  | 285 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; | 
|  | 286 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; | 
|  | 287 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 288 | private static final int CMD_GET_ALL_CELL_INFO = 60; | 
|  | 289 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; | 
|  | 290 | private static final int CMD_GET_CELL_LOCATION = 62; | 
|  | 291 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 292 | private static final int CMD_MODEM_REBOOT = 64; | 
|  | 293 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 294 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; | 
|  | 295 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 296 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; | 
|  | 297 | private static final int EVENT_ENABLE_MODEM_DONE = 69; | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 298 | private static final int CMD_GET_MODEM_STATUS = 70; | 
|  | 299 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 300 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; | 
|  | 301 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 302 | private static final int CMD_ERASE_MODEM_CONFIG = 74; | 
|  | 303 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 304 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; | 
|  | 305 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; | 
|  | 306 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; | 
|  | 307 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; | 
| Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 308 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; | 
|  | 309 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 310 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 311 | private static final int CMD_GET_CALL_FORWARDING = 83; | 
|  | 312 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; | 
|  | 313 | private static final int CMD_SET_CALL_FORWARDING = 85; | 
|  | 314 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; | 
|  | 315 | private static final int CMD_GET_CALL_WAITING = 87; | 
|  | 316 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; | 
|  | 317 | private static final int CMD_SET_CALL_WAITING = 89; | 
|  | 318 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; | 
| Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 319 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; | 
|  | 320 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; | 
|  | 321 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; | 
|  | 322 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; | 
| Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 323 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; | 
|  | 324 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; | 
| Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 325 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; | 
|  | 326 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 327 | private static final int CMD_SET_DATA_THROTTLING = 99; | 
|  | 328 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; | 
| Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 329 | private static final int CMD_SET_SIM_POWER = 101; | 
|  | 330 | private static final int EVENT_SET_SIM_POWER_DONE = 102; | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 331 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; | 
|  | 332 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; | 
|  | 333 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; | 
|  | 334 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 335 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; | 
|  | 336 | private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108; | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 337 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 338 |  | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 339 | // Parameters of select command. | 
|  | 340 | private static final int SELECT_COMMAND = 0xA4; | 
|  | 341 | private static final int SELECT_P1 = 0x04; | 
|  | 342 | private static final int SELECT_P2 = 0; | 
|  | 343 | private static final int SELECT_P3 = 0x10; | 
|  | 344 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 345 | /** The singleton instance. */ | 
|  | 346 | private static PhoneInterfaceManager sInstance; | 
|  | 347 |  | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 348 | private PhoneGlobals mApp; | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 349 | private CallManager mCM; | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 350 | private ImsResolver mImsResolver; | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 351 | private UserManager mUserManager; | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 352 | private AppOpsManager mAppOps; | 
|  | 353 | private MainThreadHandler mMainThreadHandler; | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 354 | private SubscriptionController mSubscriptionController; | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 355 | private SharedPreferences mTelephonySharedPreferences; | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 356 | private PhoneConfigurationManager mPhoneConfigurationManager; | 
| Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 357 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 358 |  | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 359 | /** User Activity */ | 
|  | 360 | private AtomicBoolean mNotifyUserActivity; | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 361 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; | 
|  | 362 |  | 
| Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 363 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); | 
|  | 364 |  | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 365 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; | 
|  | 366 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 367 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 368 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 369 |  | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 370 | // String to store multi SIM allowed | 
|  | 371 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; | 
|  | 372 |  | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 373 | // The AID of ISD-R. | 
|  | 374 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; | 
|  | 375 |  | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 376 | private NetworkScanRequestTracker mNetworkScanRequestTracker; | 
|  | 377 |  | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 378 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; | 
|  | 379 | private static final int MANUFACTURER_CODE_LENGTH = 8; | 
|  | 380 |  | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 381 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; | 
|  | 382 |  | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 383 | /** | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 384 | * Experiment flag to enable erase modem config on reset network, default value is false | 
|  | 385 | */ | 
|  | 386 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = | 
|  | 387 | "reset_network_erase_modem_config_enabled"; | 
|  | 388 |  | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 389 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds | 
|  | 390 |  | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 391 | /** | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 392 | * A request object to use for transmitting data to an ICC. | 
|  | 393 | */ | 
|  | 394 | private static final class IccAPDUArgument { | 
|  | 395 | public int channel, cla, command, p1, p2, p3; | 
|  | 396 | public String data; | 
|  | 397 |  | 
|  | 398 | public IccAPDUArgument(int channel, int cla, int command, | 
|  | 399 | int p1, int p2, int p3, String data) { | 
|  | 400 | this.channel = channel; | 
|  | 401 | this.cla = cla; | 
|  | 402 | this.command = command; | 
|  | 403 | this.p1 = p1; | 
|  | 404 | this.p2 = p2; | 
|  | 405 | this.p3 = p3; | 
|  | 406 | this.data = data; | 
|  | 407 | } | 
|  | 408 | } | 
|  | 409 |  | 
|  | 410 | /** | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 411 | * A request object to use for transmitting data to an ICC. | 
|  | 412 | */ | 
|  | 413 | private static final class ManualNetworkSelectionArgument { | 
|  | 414 | public OperatorInfo operatorInfo; | 
|  | 415 | public boolean persistSelection; | 
|  | 416 |  | 
|  | 417 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { | 
|  | 418 | this.operatorInfo = operatorInfo; | 
|  | 419 | this.persistSelection = persistSelection; | 
|  | 420 | } | 
|  | 421 | } | 
|  | 422 |  | 
|  | 423 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 424 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the | 
|  | 425 | * request after sending. The main thread will notify the request when it is complete. | 
|  | 426 | */ | 
|  | 427 | private static final class MainThreadRequest { | 
|  | 428 | /** The argument to use for the request */ | 
|  | 429 | public Object argument; | 
|  | 430 | /** The result of the request that is run on the main thread */ | 
|  | 431 | public Object result; | 
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 432 | // The subscriber id that this request applies to. Defaults to | 
|  | 433 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID | 
|  | 434 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 435 |  | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 436 | // In cases where subId is unavailable, the caller needs to specify the phone. | 
|  | 437 | public Phone phone; | 
|  | 438 |  | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 439 | public WorkSource workSource; | 
|  | 440 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 441 | public MainThreadRequest(Object argument) { | 
|  | 442 | this.argument = argument; | 
|  | 443 | } | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 444 |  | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 445 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { | 
|  | 446 | this.argument = argument; | 
|  | 447 | if (phone != null) { | 
|  | 448 | this.phone = phone; | 
|  | 449 | } | 
|  | 450 | this.workSource = workSource; | 
|  | 451 | } | 
|  | 452 |  | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 453 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 454 | this.argument = argument; | 
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 455 | if (subId != null) { | 
|  | 456 | this.subId = subId; | 
|  | 457 | } | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 458 | this.workSource = workSource; | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 459 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 460 | } | 
|  | 461 |  | 
| Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 462 | private static final class IncomingThirdPartyCallArgs { | 
|  | 463 | public final ComponentName component; | 
|  | 464 | public final String callId; | 
|  | 465 | public final String callerDisplayName; | 
|  | 466 |  | 
|  | 467 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, | 
|  | 468 | String callerDisplayName) { | 
|  | 469 | this.component = component; | 
|  | 470 | this.callId = callId; | 
|  | 471 | this.callerDisplayName = callerDisplayName; | 
|  | 472 | } | 
|  | 473 | } | 
|  | 474 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 475 | /** | 
|  | 476 | * A handler that processes messages on the main thread in the phone process. Since many | 
|  | 477 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the | 
|  | 478 | * inbound binder threads to the main thread in the phone process.  The Binder thread | 
|  | 479 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting | 
|  | 480 | * on, which will be notified when the operation completes and will contain the result of the | 
|  | 481 | * request. | 
|  | 482 | * | 
|  | 483 | * <p>If a MainThreadRequest object is provided in the msg.obj field, | 
|  | 484 | * note that request.result must be set to something non-null for the calling thread to | 
|  | 485 | * unblock. | 
|  | 486 | */ | 
|  | 487 | private final class MainThreadHandler extends Handler { | 
|  | 488 | @Override | 
|  | 489 | public void handleMessage(Message msg) { | 
|  | 490 | MainThreadRequest request; | 
|  | 491 | Message onCompleted; | 
|  | 492 | AsyncResult ar; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 493 | UiccCard uiccCard; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 494 | IccAPDUArgument iccArgument; | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 495 | final Phone defaultPhone = getDefaultPhone(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 496 |  | 
|  | 497 | switch (msg.what) { | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 498 | case CMD_HANDLE_USSD_REQUEST: { | 
|  | 499 | request = (MainThreadRequest) msg.obj; | 
|  | 500 | final Phone phone = getPhoneFromRequest(request); | 
|  | 501 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; | 
|  | 502 | String ussdRequest =  ussdObject.first; | 
|  | 503 | ResultReceiver wrappedCallback = ussdObject.second; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 504 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 505 | if (!isUssdApiAllowed(request.subId)) { | 
|  | 506 | // Carrier does not support use of this API, return failure. | 
|  | 507 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); | 
|  | 508 | UssdResponse response = new UssdResponse(ussdRequest, null); | 
|  | 509 | Bundle returnData = new Bundle(); | 
|  | 510 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); | 
|  | 511 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 512 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 513 | request.result = true; | 
|  | 514 | notifyRequester(request); | 
|  | 515 | return; | 
|  | 516 | } | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 517 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 518 | try { | 
|  | 519 | request.result = phone != null | 
|  | 520 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; | 
|  | 521 | } catch (CallStateException cse) { | 
|  | 522 | request.result = false; | 
|  | 523 | } | 
|  | 524 | // Wake up the requesting thread | 
|  | 525 | notifyRequester(request); | 
|  | 526 | break; | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 527 | } | 
|  | 528 |  | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 529 | case CMD_HANDLE_PIN_MMI: { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 530 | request = (MainThreadRequest) msg.obj; | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 531 | final Phone phone = getPhoneFromRequest(request); | 
|  | 532 | request.result = phone != null ? | 
|  | 533 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) | 
|  | 534 | : false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 535 | // Wake up the requesting thread | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 536 | notifyRequester(request); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 537 | break; | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 538 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 539 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 540 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 541 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 542 | iccArgument = (IccAPDUArgument) request.argument; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 543 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 544 | if (uiccCard == null) { | 
|  | 545 | loge("iccTransmitApduLogicalChannel: No UICC"); | 
|  | 546 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 547 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 548 | } else { | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 549 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, | 
|  | 550 | request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 551 | uiccCard.iccTransmitApduLogicalChannel( | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 552 | iccArgument.channel, iccArgument.cla, iccArgument.command, | 
|  | 553 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 554 | onCompleted); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 555 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 556 | break; | 
|  | 557 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 558 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 559 | ar = (AsyncResult) msg.obj; | 
|  | 560 | request = (MainThreadRequest) ar.userObj; | 
|  | 561 | if (ar.exception == null && ar.result != null) { | 
|  | 562 | request.result = ar.result; | 
|  | 563 | } else { | 
|  | 564 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
|  | 565 | if (ar.result == null) { | 
|  | 566 | loge("iccTransmitApduLogicalChannel: Empty response"); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 567 | } else if (ar.exception instanceof CommandException) { | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 568 | loge("iccTransmitApduLogicalChannel: CommandException: " + | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 569 | ar.exception); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 570 | } else { | 
|  | 571 | loge("iccTransmitApduLogicalChannel: Unknown exception"); | 
|  | 572 | } | 
|  | 573 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 574 | notifyRequester(request); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 575 | break; | 
|  | 576 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 577 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: | 
|  | 578 | request = (MainThreadRequest) msg.obj; | 
|  | 579 | iccArgument = (IccAPDUArgument) request.argument; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 580 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 581 | if (uiccCard == null) { | 
|  | 582 | loge("iccTransmitApduBasicChannel: No UICC"); | 
|  | 583 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 584 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 585 | } else { | 
|  | 586 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, | 
|  | 587 | request); | 
|  | 588 | uiccCard.iccTransmitApduBasicChannel( | 
|  | 589 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, | 
|  | 590 | iccArgument.p3, iccArgument.data, onCompleted); | 
|  | 591 | } | 
|  | 592 | break; | 
|  | 593 |  | 
|  | 594 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: | 
|  | 595 | ar = (AsyncResult) msg.obj; | 
|  | 596 | request = (MainThreadRequest) ar.userObj; | 
|  | 597 | if (ar.exception == null && ar.result != null) { | 
|  | 598 | request.result = ar.result; | 
|  | 599 | } else { | 
|  | 600 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
|  | 601 | if (ar.result == null) { | 
|  | 602 | loge("iccTransmitApduBasicChannel: Empty response"); | 
|  | 603 | } else if (ar.exception instanceof CommandException) { | 
|  | 604 | loge("iccTransmitApduBasicChannel: CommandException: " + | 
|  | 605 | ar.exception); | 
|  | 606 | } else { | 
|  | 607 | loge("iccTransmitApduBasicChannel: Unknown exception"); | 
|  | 608 | } | 
|  | 609 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 610 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 611 | break; | 
|  | 612 |  | 
|  | 613 | case CMD_EXCHANGE_SIM_IO: | 
|  | 614 | request = (MainThreadRequest) msg.obj; | 
|  | 615 | iccArgument = (IccAPDUArgument) request.argument; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 616 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 617 | if (uiccCard == null) { | 
|  | 618 | loge("iccExchangeSimIO: No UICC"); | 
|  | 619 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 620 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 621 | } else { | 
|  | 622 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, | 
|  | 623 | request); | 
|  | 624 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ | 
|  | 625 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, | 
|  | 626 | iccArgument.data, onCompleted); | 
|  | 627 | } | 
|  | 628 | break; | 
|  | 629 |  | 
|  | 630 | case EVENT_EXCHANGE_SIM_IO_DONE: | 
|  | 631 | ar = (AsyncResult) msg.obj; | 
|  | 632 | request = (MainThreadRequest) ar.userObj; | 
|  | 633 | if (ar.exception == null && ar.result != null) { | 
|  | 634 | request.result = ar.result; | 
|  | 635 | } else { | 
|  | 636 | request.result = new IccIoResult(0x6f, 0, (byte[])null); | 
|  | 637 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 638 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 639 | break; | 
|  | 640 |  | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 641 | case CMD_SEND_ENVELOPE: | 
|  | 642 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 643 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 644 | if (uiccCard == null) { | 
|  | 645 | loge("sendEnvelopeWithStatus: No UICC"); | 
|  | 646 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 647 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 648 | } else { | 
|  | 649 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); | 
|  | 650 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); | 
|  | 651 | } | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 652 | break; | 
|  | 653 |  | 
|  | 654 | case EVENT_SEND_ENVELOPE_DONE: | 
|  | 655 | ar = (AsyncResult) msg.obj; | 
|  | 656 | request = (MainThreadRequest) ar.userObj; | 
| Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 657 | if (ar.exception == null && ar.result != null) { | 
|  | 658 | request.result = ar.result; | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 659 | } else { | 
| Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 660 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
|  | 661 | if (ar.result == null) { | 
|  | 662 | loge("sendEnvelopeWithStatus: Empty response"); | 
|  | 663 | } else if (ar.exception instanceof CommandException) { | 
|  | 664 | loge("sendEnvelopeWithStatus: CommandException: " + | 
|  | 665 | ar.exception); | 
|  | 666 | } else { | 
|  | 667 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); | 
|  | 668 | } | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 669 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 670 | notifyRequester(request); | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 671 | break; | 
|  | 672 |  | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 673 | case CMD_OPEN_CHANNEL: | 
|  | 674 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 675 | uiccCard = getUiccCardFromRequest(request); | 
| Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 676 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 677 | if (uiccCard == null) { | 
|  | 678 | loge("iccOpenLogicalChannel: No UICC"); | 
| Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 679 | request.result = new IccOpenLogicalChannelResponse(-1, | 
|  | 680 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 681 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 682 | } else { | 
|  | 683 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); | 
| Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 684 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, | 
|  | 685 | openChannelArgs.second, onCompleted); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 686 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 687 | break; | 
|  | 688 |  | 
|  | 689 | case EVENT_OPEN_CHANNEL_DONE: | 
|  | 690 | ar = (AsyncResult) msg.obj; | 
|  | 691 | request = (MainThreadRequest) ar.userObj; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 692 | IccOpenLogicalChannelResponse openChannelResp; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 693 | if (ar.exception == null && ar.result != null) { | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 694 | int[] result = (int[]) ar.result; | 
|  | 695 | int channelId = result[0]; | 
|  | 696 | byte[] selectResponse = null; | 
|  | 697 | if (result.length > 1) { | 
|  | 698 | selectResponse = new byte[result.length - 1]; | 
|  | 699 | for (int i = 1; i < result.length; ++i) { | 
|  | 700 | selectResponse[i - 1] = (byte) result[i]; | 
|  | 701 | } | 
|  | 702 | } | 
|  | 703 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 704 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 705 | } else { | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 706 | if (ar.result == null) { | 
|  | 707 | loge("iccOpenLogicalChannel: Empty response"); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 708 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 709 | if (ar.exception != null) { | 
|  | 710 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); | 
|  | 711 | } | 
|  | 712 |  | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 713 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; | 
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 714 | if (ar.exception instanceof CommandException) { | 
|  | 715 | CommandException.Error error = | 
|  | 716 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 717 | if (error == CommandException.Error.MISSING_RESOURCE) { | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 718 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; | 
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 719 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 720 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 721 | } | 
|  | 722 | } | 
|  | 723 | openChannelResp = new IccOpenLogicalChannelResponse( | 
|  | 724 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 725 | } | 
| Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 726 | request.result = openChannelResp; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 727 | notifyRequester(request); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 728 | break; | 
|  | 729 |  | 
|  | 730 | case CMD_CLOSE_CHANNEL: | 
|  | 731 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 732 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 733 | if (uiccCard == null) { | 
|  | 734 | loge("iccCloseLogicalChannel: No UICC"); | 
| Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 735 | request.result = false; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 736 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 737 | } else { | 
|  | 738 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); | 
|  | 739 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); | 
|  | 740 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 741 | break; | 
|  | 742 |  | 
|  | 743 | case EVENT_CLOSE_CHANNEL_DONE: | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 744 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); | 
|  | 745 | break; | 
|  | 746 |  | 
|  | 747 | case CMD_NV_READ_ITEM: | 
|  | 748 | request = (MainThreadRequest) msg.obj; | 
|  | 749 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 750 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, | 
|  | 751 | request.workSource); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 752 | break; | 
|  | 753 |  | 
|  | 754 | case EVENT_NV_READ_ITEM_DONE: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 755 | ar = (AsyncResult) msg.obj; | 
|  | 756 | request = (MainThreadRequest) ar.userObj; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 757 | if (ar.exception == null && ar.result != null) { | 
|  | 758 | request.result = ar.result;     // String | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 759 | } else { | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 760 | request.result = ""; | 
|  | 761 | if (ar.result == null) { | 
|  | 762 | loge("nvReadItem: Empty response"); | 
|  | 763 | } else if (ar.exception instanceof CommandException) { | 
|  | 764 | loge("nvReadItem: CommandException: " + | 
|  | 765 | ar.exception); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 766 | } else { | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 767 | loge("nvReadItem: Unknown exception"); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 768 | } | 
|  | 769 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 770 | notifyRequester(request); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 771 | break; | 
|  | 772 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 773 | case CMD_NV_WRITE_ITEM: | 
|  | 774 | request = (MainThreadRequest) msg.obj; | 
|  | 775 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); | 
|  | 776 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 777 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 778 | request.workSource); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 779 | break; | 
|  | 780 |  | 
|  | 781 | case EVENT_NV_WRITE_ITEM_DONE: | 
|  | 782 | handleNullReturnEvent(msg, "nvWriteItem"); | 
|  | 783 | break; | 
|  | 784 |  | 
|  | 785 | case CMD_NV_WRITE_CDMA_PRL: | 
|  | 786 | request = (MainThreadRequest) msg.obj; | 
|  | 787 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 788 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 789 | break; | 
|  | 790 |  | 
|  | 791 | case EVENT_NV_WRITE_CDMA_PRL_DONE: | 
|  | 792 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); | 
|  | 793 | break; | 
|  | 794 |  | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 795 | case CMD_RESET_MODEM_CONFIG: | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 796 | request = (MainThreadRequest) msg.obj; | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 797 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 798 | defaultPhone.resetModemConfig(onCompleted); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 799 | break; | 
|  | 800 |  | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 801 | case EVENT_RESET_MODEM_CONFIG_DONE: | 
|  | 802 | handleNullReturnEvent(msg, "resetModemConfig"); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 803 | break; | 
|  | 804 |  | 
| Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 805 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { | 
|  | 806 | request = (MainThreadRequest) msg.obj; | 
|  | 807 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, | 
|  | 808 | request); | 
|  | 809 | Phone phone = getPhoneFromRequest(request); | 
|  | 810 | if (phone != null) { | 
|  | 811 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); | 
|  | 812 | } else { | 
|  | 813 | loge("isNRDualConnectivityEnabled: No phone object"); | 
|  | 814 | request.result = false; | 
|  | 815 | notifyRequester(request); | 
|  | 816 | } | 
|  | 817 | break; | 
|  | 818 | } | 
|  | 819 |  | 
|  | 820 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: | 
|  | 821 | ar = (AsyncResult) msg.obj; | 
|  | 822 | request = (MainThreadRequest) ar.userObj; | 
|  | 823 | if (ar.exception == null && ar.result != null) { | 
|  | 824 | request.result = ar.result; | 
|  | 825 | } else { | 
|  | 826 | // request.result must be set to something non-null | 
|  | 827 | // for the calling thread to unblock | 
|  | 828 | if (request.result != null) { | 
|  | 829 | request.result = ar.result; | 
|  | 830 | } else { | 
|  | 831 | request.result = false; | 
|  | 832 | } | 
|  | 833 | if (ar.result == null) { | 
|  | 834 | loge("isNRDualConnectivityEnabled: Empty response"); | 
|  | 835 | } else if (ar.exception instanceof CommandException) { | 
|  | 836 | loge("isNRDualConnectivityEnabled: CommandException: " | 
|  | 837 | + ar.exception); | 
|  | 838 | } else { | 
|  | 839 | loge("isNRDualConnectivityEnabled: Unknown exception"); | 
|  | 840 | } | 
|  | 841 | } | 
|  | 842 | notifyRequester(request); | 
|  | 843 | break; | 
|  | 844 |  | 
|  | 845 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { | 
|  | 846 | request = (MainThreadRequest) msg.obj; | 
|  | 847 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); | 
|  | 848 | Phone phone = getPhoneFromRequest(request); | 
|  | 849 | if (phone != null) { | 
|  | 850 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, | 
|  | 851 | request.workSource); | 
|  | 852 | } else { | 
|  | 853 | loge("enableNrDualConnectivity: No phone object"); | 
|  | 854 | request.result = | 
|  | 855 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; | 
|  | 856 | notifyRequester(request); | 
|  | 857 | } | 
|  | 858 | break; | 
|  | 859 | } | 
|  | 860 |  | 
|  | 861 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { | 
|  | 862 | ar = (AsyncResult) msg.obj; | 
|  | 863 | request = (MainThreadRequest) ar.userObj; | 
|  | 864 | if (ar.exception == null) { | 
|  | 865 | request.result = | 
|  | 866 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; | 
|  | 867 | } else { | 
|  | 868 | request.result = | 
|  | 869 | TelephonyManager | 
|  | 870 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; | 
|  | 871 | if (ar.exception instanceof CommandException) { | 
|  | 872 | CommandException.Error error = | 
|  | 873 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 874 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { | 
|  | 875 | request.result = | 
|  | 876 | TelephonyManager | 
|  | 877 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; | 
| Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 878 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
|  | 879 | request.result = | 
|  | 880 | TelephonyManager | 
|  | 881 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; | 
| Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 882 | } | 
|  | 883 | loge("enableNrDualConnectivity" + ": CommandException: " | 
|  | 884 | + ar.exception); | 
|  | 885 | } else { | 
|  | 886 | loge("enableNrDualConnectivity" + ": Unknown exception"); | 
|  | 887 | } | 
|  | 888 | } | 
|  | 889 | notifyRequester(request); | 
|  | 890 | break; | 
|  | 891 | } | 
|  | 892 |  | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 893 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 894 | request = (MainThreadRequest) msg.obj; | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 895 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, | 
|  | 896 | request); | 
|  | 897 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 898 | break; | 
|  | 899 |  | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 900 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 901 | ar = (AsyncResult) msg.obj; | 
|  | 902 | request = (MainThreadRequest) ar.userObj; | 
|  | 903 | if (ar.exception == null && ar.result != null) { | 
|  | 904 | request.result = ar.result;     // Integer | 
|  | 905 | } else { | 
| Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 906 | // request.result must be set to something non-null | 
|  | 907 | // for the calling thread to unblock | 
|  | 908 | request.result = new int[]{-1}; | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 909 | if (ar.result == null) { | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 910 | loge("getAllowedNetworkTypesBitmask: Empty response"); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 911 | } else if (ar.exception instanceof CommandException) { | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 912 | loge("getAllowedNetworkTypesBitmask: CommandException: " | 
|  | 913 | + ar.exception); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 914 | } else { | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 915 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 916 | } | 
|  | 917 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 918 | notifyRequester(request); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 919 | break; | 
|  | 920 |  | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 921 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 922 | request = (MainThreadRequest) msg.obj; | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 923 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, | 
|  | 924 | request); | 
|  | 925 | Pair<Integer, Long> reasonWithNetworkTypes = | 
|  | 926 | (Pair<Integer, Long>) request.argument; | 
|  | 927 | getPhoneFromRequest(request).setAllowedNetworkTypes( | 
|  | 928 | reasonWithNetworkTypes.first, | 
|  | 929 | reasonWithNetworkTypes.second, | 
|  | 930 | onCompleted); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 931 | break; | 
|  | 932 |  | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 933 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: | 
|  | 934 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 935 | break; | 
|  | 936 |  | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 937 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: | 
|  | 938 | request = (MainThreadRequest)msg.obj; | 
|  | 939 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 940 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 941 | break; | 
|  | 942 |  | 
|  | 943 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: | 
|  | 944 | ar = (AsyncResult)msg.obj; | 
|  | 945 | request = (MainThreadRequest)ar.userObj; | 
|  | 946 | request.result = ar; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 947 | notifyRequester(request); | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 948 | break; | 
|  | 949 |  | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 950 | case CMD_SET_VOICEMAIL_NUMBER: | 
|  | 951 | request = (MainThreadRequest) msg.obj; | 
|  | 952 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); | 
|  | 953 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 954 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, | 
|  | 955 | onCompleted); | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 956 | break; | 
|  | 957 |  | 
|  | 958 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: | 
|  | 959 | handleNullReturnEvent(msg, "setVoicemailNumber"); | 
|  | 960 | break; | 
|  | 961 |  | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 962 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: | 
|  | 963 | request = (MainThreadRequest) msg.obj; | 
|  | 964 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, | 
|  | 965 | request); | 
|  | 966 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); | 
|  | 967 | break; | 
|  | 968 |  | 
|  | 969 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: | 
|  | 970 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); | 
|  | 971 | break; | 
|  | 972 |  | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 973 | case CMD_PERFORM_NETWORK_SCAN: | 
|  | 974 | request = (MainThreadRequest) msg.obj; | 
|  | 975 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); | 
|  | 976 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); | 
|  | 977 | break; | 
|  | 978 |  | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 979 | case CMD_GET_CALL_FORWARDING: { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 980 | request = (MainThreadRequest) msg.obj; | 
|  | 981 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 982 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = | 
|  | 983 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) | 
|  | 984 | request.argument; | 
|  | 985 | int callForwardingReason = args.first; | 
|  | 986 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 987 | break; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 988 | } | 
|  | 989 | case EVENT_GET_CALL_FORWARDING_DONE: { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 990 | ar = (AsyncResult) msg.obj; | 
|  | 991 | request = (MainThreadRequest) ar.userObj; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 992 | TelephonyManager.CallForwardingInfoCallback callback = | 
|  | 993 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) | 
|  | 994 | request.argument).second; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 995 | if (ar.exception == null && ar.result != null) { | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 996 | CallForwardingInfo callForwardingInfo = null; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 997 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; | 
|  | 998 | for (CallForwardInfo callForwardInfo : callForwardInfos) { | 
|  | 999 | // Service Class is a bit mask per 3gpp 27.007. Search for | 
|  | 1000 | // any service for voice call. | 
|  | 1001 | if ((callForwardInfo.serviceClass | 
|  | 1002 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1003 | callForwardingInfo = new CallForwardingInfo(true, | 
|  | 1004 | callForwardInfo.reason, | 
|  | 1005 | callForwardInfo.number, | 
|  | 1006 | callForwardInfo.timeSeconds); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1007 | break; | 
|  | 1008 | } | 
|  | 1009 | } | 
|  | 1010 | // Didn't find a call forward info for voice call. | 
|  | 1011 | if (callForwardingInfo == null) { | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1012 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, | 
|  | 1013 | 0 /* reason */, null /* number */, 0 /* timeout */); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1014 | } | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1015 | callback.onCallForwardingInfoAvailable(callForwardingInfo); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1016 | } else { | 
|  | 1017 | if (ar.result == null) { | 
|  | 1018 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); | 
|  | 1019 | } | 
|  | 1020 | if (ar.exception != null) { | 
|  | 1021 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); | 
|  | 1022 | } | 
| Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1023 | int errorCode = TelephonyManager | 
|  | 1024 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1025 | if (ar.exception instanceof CommandException) { | 
|  | 1026 | CommandException.Error error = | 
|  | 1027 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1028 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { | 
| Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1029 | errorCode = TelephonyManager | 
|  | 1030 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1031 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
| Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1032 | errorCode = TelephonyManager | 
|  | 1033 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1034 | } | 
|  | 1035 | } | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1036 | callback.onError(errorCode); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1037 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1038 | break; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1039 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1040 |  | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1041 | case CMD_SET_CALL_FORWARDING: { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1042 | request = (MainThreadRequest) msg.obj; | 
|  | 1043 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1044 | request = (MainThreadRequest) msg.obj; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1045 | CallForwardingInfo callForwardingInfoToSet = | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1046 | ((Pair<CallForwardingInfo, Consumer<Integer>>) | 
|  | 1047 | request.argument).first; | 
|  | 1048 | request.phone.setCallForwardingOption( | 
|  | 1049 | callForwardingInfoToSet.isEnabled() | 
|  | 1050 | ? CommandsInterface.CF_ACTION_ENABLE | 
|  | 1051 | : CommandsInterface.CF_ACTION_DISABLE, | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1052 | callForwardingInfoToSet.getReason(), | 
|  | 1053 | callForwardingInfoToSet.getNumber(), | 
|  | 1054 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); | 
|  | 1055 | break; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1056 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1057 |  | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1058 | case EVENT_SET_CALL_FORWARDING_DONE: { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1059 | ar = (AsyncResult) msg.obj; | 
|  | 1060 | request = (MainThreadRequest) ar.userObj; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1061 | Consumer<Integer> callback = | 
|  | 1062 | ((Pair<CallForwardingInfo, Consumer<Integer>>) | 
|  | 1063 | request.argument).second; | 
|  | 1064 | if (ar.exception != null) { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1065 | loge("setCallForwarding exception: " + ar.exception); | 
| Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1066 | int errorCode = TelephonyManager.CallForwardingInfoCallback | 
|  | 1067 | .RESULT_ERROR_UNKNOWN; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1068 | if (ar.exception instanceof CommandException) { | 
|  | 1069 | CommandException.Error error = | 
|  | 1070 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1071 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { | 
| Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1072 | errorCode = TelephonyManager.CallForwardingInfoCallback | 
|  | 1073 | .RESULT_ERROR_FDN_CHECK_FAILURE; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1074 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
| Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1075 | errorCode = TelephonyManager.CallForwardingInfoCallback | 
|  | 1076 | .RESULT_ERROR_NOT_SUPPORTED; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1077 | } | 
|  | 1078 | } | 
|  | 1079 | callback.accept(errorCode); | 
|  | 1080 | } else { | 
| Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1081 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1082 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1083 | break; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1084 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1085 |  | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1086 | case CMD_GET_CALL_WAITING: { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1087 | request = (MainThreadRequest) msg.obj; | 
|  | 1088 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); | 
|  | 1089 | getPhoneFromRequest(request).getCallWaiting(onCompleted); | 
|  | 1090 | break; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1091 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1092 |  | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1093 | case EVENT_GET_CALL_WAITING_DONE: { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1094 | ar = (AsyncResult) msg.obj; | 
|  | 1095 | request = (MainThreadRequest) ar.userObj; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1096 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1097 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; | 
|  | 1098 | if (ar.exception == null && ar.result != null) { | 
| Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1099 | int[] callForwardResults = (int[]) ar.result; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1100 | // Service Class is a bit mask per 3gpp 27.007. | 
|  | 1101 | // Search for any service for voice call. | 
| Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1102 | if (callForwardResults.length > 1 | 
|  | 1103 | && ((callForwardResults[1] | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1104 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { | 
| Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1105 | callForwardingStatus = callForwardResults[0] == 0 | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1106 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED | 
|  | 1107 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1108 | } else { | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1109 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1110 | } | 
|  | 1111 | } else { | 
|  | 1112 | if (ar.result == null) { | 
|  | 1113 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); | 
|  | 1114 | } | 
|  | 1115 | if (ar.exception != null) { | 
|  | 1116 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); | 
|  | 1117 | } | 
|  | 1118 | if (ar.exception instanceof CommandException) { | 
|  | 1119 | CommandException.Error error = | 
|  | 1120 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1121 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
|  | 1122 | callForwardingStatus = | 
|  | 1123 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; | 
|  | 1124 | } | 
|  | 1125 | } | 
|  | 1126 | } | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1127 | callback.accept(callForwardingStatus); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1128 | break; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1129 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1130 |  | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1131 | case CMD_SET_CALL_WAITING: { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1132 | request = (MainThreadRequest) msg.obj; | 
|  | 1133 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1134 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; | 
|  | 1135 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1136 | break; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1137 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1138 |  | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1139 | case EVENT_SET_CALL_WAITING_DONE: { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1140 | ar = (AsyncResult) msg.obj; | 
|  | 1141 | request = (MainThreadRequest) ar.userObj; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1142 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; | 
|  | 1143 | Consumer<Integer> callback = | 
|  | 1144 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; | 
|  | 1145 | if (ar.exception != null) { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1146 | loge("setCallWaiting exception: " + ar.exception); | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1147 | if (ar.exception instanceof CommandException) { | 
|  | 1148 | CommandException.Error error = | 
|  | 1149 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1150 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
|  | 1151 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); | 
|  | 1152 | } else { | 
|  | 1153 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); | 
|  | 1154 | } | 
|  | 1155 | } else { | 
|  | 1156 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); | 
|  | 1157 | } | 
|  | 1158 | } else { | 
|  | 1159 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED | 
|  | 1160 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1161 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1162 | break; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1163 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1164 |  | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1165 | case EVENT_PERFORM_NETWORK_SCAN_DONE: | 
|  | 1166 | ar = (AsyncResult) msg.obj; | 
|  | 1167 | request = (MainThreadRequest) ar.userObj; | 
|  | 1168 | CellNetworkScanResult cellScanResult; | 
|  | 1169 | if (ar.exception == null && ar.result != null) { | 
|  | 1170 | cellScanResult = new CellNetworkScanResult( | 
|  | 1171 | CellNetworkScanResult.STATUS_SUCCESS, | 
|  | 1172 | (List<OperatorInfo>) ar.result); | 
|  | 1173 | } else { | 
|  | 1174 | if (ar.result == null) { | 
|  | 1175 | loge("getCellNetworkScanResults: Empty response"); | 
|  | 1176 | } | 
|  | 1177 | if (ar.exception != null) { | 
|  | 1178 | loge("getCellNetworkScanResults: Exception: " + ar.exception); | 
|  | 1179 | } | 
|  | 1180 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; | 
|  | 1181 | if (ar.exception instanceof CommandException) { | 
|  | 1182 | CommandException.Error error = | 
|  | 1183 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1184 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { | 
|  | 1185 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; | 
|  | 1186 | } else if (error == CommandException.Error.GENERIC_FAILURE) { | 
|  | 1187 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; | 
|  | 1188 | } | 
|  | 1189 | } | 
|  | 1190 | cellScanResult = new CellNetworkScanResult(errorCode, null); | 
|  | 1191 | } | 
|  | 1192 | request.result = cellScanResult; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1193 | notifyRequester(request); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1194 | break; | 
|  | 1195 |  | 
|  | 1196 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: | 
|  | 1197 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1198 | ManualNetworkSelectionArgument selArg = | 
|  | 1199 | (ManualNetworkSelectionArgument) request.argument; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1200 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, | 
|  | 1201 | request); | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1202 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, | 
|  | 1203 | selArg.persistSelection, onCompleted); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1204 | break; | 
|  | 1205 |  | 
|  | 1206 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: | 
| Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1207 | ar = (AsyncResult) msg.obj; | 
|  | 1208 | request = (MainThreadRequest) ar.userObj; | 
|  | 1209 | if (ar.exception == null) { | 
|  | 1210 | request.result = true; | 
|  | 1211 | } else { | 
|  | 1212 | request.result = false; | 
|  | 1213 | loge("setNetworkSelectionModeManual " + ar.exception); | 
|  | 1214 | } | 
|  | 1215 | notifyRequester(request); | 
|  | 1216 | mApp.onNetworkSelectionChanged(request.subId); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1217 | break; | 
|  | 1218 |  | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1219 | case CMD_GET_MODEM_ACTIVITY_INFO: | 
|  | 1220 | request = (MainThreadRequest) msg.obj; | 
|  | 1221 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); | 
| James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1222 | if (defaultPhone != null) { | 
|  | 1223 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); | 
| Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1224 | } else { | 
|  | 1225 | ResultReceiver result = (ResultReceiver) request.argument; | 
|  | 1226 | Bundle bundle = new Bundle(); | 
|  | 1227 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, | 
| Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1228 | new ModemActivityInfo(0, 0, 0, | 
|  | 1229 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); | 
| Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1230 | result.send(0, bundle); | 
| James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1231 | } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1232 | break; | 
|  | 1233 |  | 
| Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1234 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1235 | ar = (AsyncResult) msg.obj; | 
|  | 1236 | request = (MainThreadRequest) ar.userObj; | 
| Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1237 | ResultReceiver result = (ResultReceiver) request.argument; | 
|  | 1238 |  | 
| Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1239 | ModemActivityInfo ret = null; | 
|  | 1240 | int error = 0; | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1241 | if (ar.exception == null && ar.result != null) { | 
| Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1242 | // Update the last modem activity info and the result of the request. | 
|  | 1243 | ModemActivityInfo info = (ModemActivityInfo) ar.result; | 
|  | 1244 | if (isModemActivityInfoValid(info)) { | 
| Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1245 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; | 
| Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1246 | int[] txTimeMs = info.getTransmitTimeMillis(); | 
|  | 1247 | int[] lastModemTxTimeMs = mLastModemActivityInfo | 
|  | 1248 | .getTransmitTimeMillis(); | 
|  | 1249 | for (int i = 0; i < mergedTxTimeMs.length; i++) { | 
|  | 1250 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; | 
|  | 1251 | } | 
| Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1252 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); | 
| Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1253 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() | 
|  | 1254 | + mLastModemActivityInfo.getSleepTimeMillis()); | 
|  | 1255 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() | 
|  | 1256 | + mLastModemActivityInfo.getIdleTimeMillis()); | 
|  | 1257 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); | 
|  | 1258 | mLastModemActivityInfo.setReceiveTimeMillis( | 
|  | 1259 | info.getReceiveTimeMillis() | 
|  | 1260 | + mLastModemActivityInfo.getReceiveTimeMillis()); | 
|  | 1261 | } | 
| Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1262 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), | 
| Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1263 | mLastModemActivityInfo.getSleepTimeMillis(), | 
|  | 1264 | mLastModemActivityInfo.getIdleTimeMillis(), | 
|  | 1265 | mLastModemActivityInfo.getTransmitTimeMillis(), | 
|  | 1266 | mLastModemActivityInfo.getReceiveTimeMillis()); | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1267 | } else { | 
|  | 1268 | if (ar.result == null) { | 
|  | 1269 | loge("queryModemActivityInfo: Empty response"); | 
| Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1270 | error = TelephonyManager.ModemActivityInfoException | 
|  | 1271 | .ERROR_INVALID_INFO_RECEIVED; | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1272 | } else if (ar.exception instanceof CommandException) { | 
|  | 1273 | loge("queryModemActivityInfo: CommandException: " + | 
|  | 1274 | ar.exception); | 
| Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1275 | error = TelephonyManager.ModemActivityInfoException | 
|  | 1276 | .ERROR_MODEM_RESPONSE_ERROR; | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1277 | } else { | 
|  | 1278 | loge("queryModemActivityInfo: Unknown exception"); | 
| Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1279 | error = TelephonyManager.ModemActivityInfoException | 
|  | 1280 | .ERROR_UNKNOWN; | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1281 | } | 
|  | 1282 | } | 
| Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1283 | Bundle bundle = new Bundle(); | 
| Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1284 | if (ret != null) { | 
|  | 1285 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); | 
|  | 1286 | } else { | 
|  | 1287 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); | 
|  | 1288 | } | 
| Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1289 | result.send(0, bundle); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1290 | notifyRequester(request); | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1291 | break; | 
| Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1292 | } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1293 |  | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1294 | case CMD_SET_ALLOWED_CARRIERS: | 
|  | 1295 | request = (MainThreadRequest) msg.obj; | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1296 | CarrierRestrictionRules argument = | 
|  | 1297 | (CarrierRestrictionRules) request.argument; | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1298 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1299 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1300 | break; | 
|  | 1301 |  | 
|  | 1302 | case EVENT_SET_ALLOWED_CARRIERS_DONE: | 
|  | 1303 | ar = (AsyncResult) msg.obj; | 
|  | 1304 | request = (MainThreadRequest) ar.userObj; | 
|  | 1305 | if (ar.exception == null && ar.result != null) { | 
|  | 1306 | request.result = ar.result; | 
|  | 1307 | } else { | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1308 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; | 
|  | 1309 | if (ar.exception instanceof CommandException) { | 
|  | 1310 | loge("setAllowedCarriers: CommandException: " + ar.exception); | 
|  | 1311 | CommandException.Error error = | 
|  | 1312 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1313 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
|  | 1314 | request.result = | 
|  | 1315 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; | 
|  | 1316 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1317 | } else { | 
|  | 1318 | loge("setAllowedCarriers: Unknown exception"); | 
|  | 1319 | } | 
|  | 1320 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1321 | notifyRequester(request); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1322 | break; | 
|  | 1323 |  | 
|  | 1324 | case CMD_GET_ALLOWED_CARRIERS: | 
|  | 1325 | request = (MainThreadRequest) msg.obj; | 
|  | 1326 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1327 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1328 | break; | 
|  | 1329 |  | 
|  | 1330 | case EVENT_GET_ALLOWED_CARRIERS_DONE: | 
|  | 1331 | ar = (AsyncResult) msg.obj; | 
|  | 1332 | request = (MainThreadRequest) ar.userObj; | 
|  | 1333 | if (ar.exception == null && ar.result != null) { | 
|  | 1334 | request.result = ar.result; | 
|  | 1335 | } else { | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1336 | request.result = new IllegalStateException( | 
|  | 1337 | "Failed to get carrier restrictions"); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1338 | if (ar.result == null) { | 
|  | 1339 | loge("getAllowedCarriers: Empty response"); | 
|  | 1340 | } else if (ar.exception instanceof CommandException) { | 
|  | 1341 | loge("getAllowedCarriers: CommandException: " + | 
|  | 1342 | ar.exception); | 
|  | 1343 | } else { | 
|  | 1344 | loge("getAllowedCarriers: Unknown exception"); | 
|  | 1345 | } | 
|  | 1346 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1347 | notifyRequester(request); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1348 | break; | 
|  | 1349 |  | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1350 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: | 
|  | 1351 | ar = (AsyncResult) msg.obj; | 
|  | 1352 | request = (MainThreadRequest) ar.userObj; | 
|  | 1353 | if (ar.exception == null && ar.result != null) { | 
|  | 1354 | request.result = ar.result; | 
|  | 1355 | } else { | 
|  | 1356 | request.result = new IllegalArgumentException( | 
|  | 1357 | "Failed to retrieve Forbidden Plmns"); | 
|  | 1358 | if (ar.result == null) { | 
|  | 1359 | loge("getForbiddenPlmns: Empty response"); | 
|  | 1360 | } else { | 
|  | 1361 | loge("getForbiddenPlmns: Unknown exception"); | 
|  | 1362 | } | 
|  | 1363 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1364 | notifyRequester(request); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1365 | break; | 
|  | 1366 |  | 
|  | 1367 | case CMD_GET_FORBIDDEN_PLMNS: | 
|  | 1368 | request = (MainThreadRequest) msg.obj; | 
|  | 1369 | uiccCard = getUiccCardFromRequest(request); | 
|  | 1370 | if (uiccCard == null) { | 
|  | 1371 | loge("getForbiddenPlmns() UiccCard is null"); | 
|  | 1372 | request.result = new IllegalArgumentException( | 
|  | 1373 | "getForbiddenPlmns() UiccCard is null"); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1374 | notifyRequester(request); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1375 | break; | 
|  | 1376 | } | 
|  | 1377 | Integer appType = (Integer) request.argument; | 
|  | 1378 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); | 
|  | 1379 | if (uiccApp == null) { | 
|  | 1380 | loge("getForbiddenPlmns() no app with specified type -- " | 
|  | 1381 | + appType); | 
|  | 1382 | request.result = new IllegalArgumentException("Failed to get UICC App"); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1383 | notifyRequester(request); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1384 | break; | 
|  | 1385 | } else { | 
|  | 1386 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() | 
|  | 1387 | + " specified type -- " + appType); | 
|  | 1388 | } | 
|  | 1389 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); | 
|  | 1390 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( | 
|  | 1391 | onCompleted); | 
|  | 1392 | break; | 
|  | 1393 |  | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1394 | case CMD_SWITCH_SLOTS: | 
|  | 1395 | request = (MainThreadRequest) msg.obj; | 
|  | 1396 | int[] physicalSlots = (int[]) request.argument; | 
|  | 1397 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); | 
|  | 1398 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); | 
|  | 1399 | break; | 
|  | 1400 |  | 
|  | 1401 | case EVENT_SWITCH_SLOTS_DONE: | 
|  | 1402 | ar = (AsyncResult) msg.obj; | 
|  | 1403 | request = (MainThreadRequest) ar.userObj; | 
|  | 1404 | request.result = (ar.exception == null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1405 | notifyRequester(request); | 
|  | 1406 | break; | 
|  | 1407 | case CMD_GET_NETWORK_SELECTION_MODE: | 
|  | 1408 | request = (MainThreadRequest) msg.obj; | 
|  | 1409 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); | 
|  | 1410 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); | 
|  | 1411 | break; | 
|  | 1412 |  | 
|  | 1413 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: | 
|  | 1414 | ar = (AsyncResult) msg.obj; | 
|  | 1415 | request = (MainThreadRequest) ar.userObj; | 
|  | 1416 | if (ar.exception != null) { | 
|  | 1417 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; | 
|  | 1418 | } else { | 
|  | 1419 | int mode = ((int[]) ar.result)[0]; | 
|  | 1420 | if (mode == 0) { | 
|  | 1421 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; | 
|  | 1422 | } else { | 
|  | 1423 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; | 
|  | 1424 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1425 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1426 | notifyRequester(request); | 
|  | 1427 | break; | 
|  | 1428 | case CMD_GET_CDMA_ROAMING_MODE: | 
|  | 1429 | request = (MainThreadRequest) msg.obj; | 
|  | 1430 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); | 
|  | 1431 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); | 
|  | 1432 | break; | 
|  | 1433 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: | 
|  | 1434 | ar = (AsyncResult) msg.obj; | 
|  | 1435 | request = (MainThreadRequest) ar.userObj; | 
|  | 1436 | if (ar.exception != null) { | 
|  | 1437 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; | 
|  | 1438 | } else { | 
|  | 1439 | request.result = ((int[]) ar.result)[0]; | 
|  | 1440 | } | 
|  | 1441 | notifyRequester(request); | 
|  | 1442 | break; | 
|  | 1443 | case CMD_SET_CDMA_ROAMING_MODE: | 
|  | 1444 | request = (MainThreadRequest) msg.obj; | 
|  | 1445 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); | 
|  | 1446 | int mode = (int) request.argument; | 
|  | 1447 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); | 
|  | 1448 | break; | 
|  | 1449 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: | 
|  | 1450 | ar = (AsyncResult) msg.obj; | 
|  | 1451 | request = (MainThreadRequest) ar.userObj; | 
|  | 1452 | request.result = ar.exception == null; | 
|  | 1453 | notifyRequester(request); | 
|  | 1454 | break; | 
| Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1455 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: | 
|  | 1456 | request = (MainThreadRequest) msg.obj; | 
|  | 1457 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); | 
|  | 1458 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); | 
|  | 1459 | break; | 
|  | 1460 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: | 
|  | 1461 | ar = (AsyncResult) msg.obj; | 
|  | 1462 | request = (MainThreadRequest) ar.userObj; | 
|  | 1463 | if (ar.exception != null) { | 
|  | 1464 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; | 
|  | 1465 | } else { | 
|  | 1466 | request.result = ((int[]) ar.result)[0]; | 
|  | 1467 | } | 
|  | 1468 | notifyRequester(request); | 
|  | 1469 | break; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1470 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: | 
|  | 1471 | request = (MainThreadRequest) msg.obj; | 
|  | 1472 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); | 
|  | 1473 | int subscriptionMode = (int) request.argument; | 
| Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1474 | getPhoneFromRequest(request).setCdmaSubscriptionMode( | 
|  | 1475 | subscriptionMode, onCompleted); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1476 | break; | 
|  | 1477 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: | 
|  | 1478 | ar = (AsyncResult) msg.obj; | 
|  | 1479 | request = (MainThreadRequest) ar.userObj; | 
|  | 1480 | request.result = ar.exception == null; | 
|  | 1481 | notifyRequester(request); | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1482 | break; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1483 | case CMD_GET_ALL_CELL_INFO: | 
|  | 1484 | request = (MainThreadRequest) msg.obj; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1485 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1486 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1487 | break; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1488 | case EVENT_GET_ALL_CELL_INFO_DONE: | 
|  | 1489 | ar = (AsyncResult) msg.obj; | 
|  | 1490 | request = (MainThreadRequest) ar.userObj; | 
| Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1491 | // If a timeout occurs, the response will be null | 
|  | 1492 | request.result = (ar.exception == null && ar.result != null) | 
|  | 1493 | ? ar.result : new ArrayList<CellInfo>(); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1494 | synchronized (request) { | 
|  | 1495 | request.notifyAll(); | 
|  | 1496 | } | 
|  | 1497 | break; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1498 | case CMD_REQUEST_CELL_INFO_UPDATE: | 
|  | 1499 | request = (MainThreadRequest) msg.obj; | 
|  | 1500 | request.phone.requestCellInfoUpdate(request.workSource, | 
|  | 1501 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); | 
|  | 1502 | break; | 
|  | 1503 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: | 
|  | 1504 | ar = (AsyncResult) msg.obj; | 
|  | 1505 | request = (MainThreadRequest) ar.userObj; | 
|  | 1506 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; | 
|  | 1507 | try { | 
|  | 1508 | if (ar.exception != null) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1509 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); | 
| Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1510 | cb.onError( | 
|  | 1511 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, | 
|  | 1512 | ar.exception.getClass().getName(), | 
|  | 1513 | ar.exception.toString()); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1514 | } else if (ar.result == null) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1515 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); | 
| Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1516 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1517 | } else { | 
|  | 1518 | // use the result as returned | 
|  | 1519 | cb.onCellInfo((List<CellInfo>) ar.result); | 
|  | 1520 | } | 
|  | 1521 | } catch (RemoteException re) { | 
|  | 1522 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); | 
|  | 1523 | } | 
|  | 1524 | break; | 
| Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1525 | case CMD_GET_CELL_LOCATION: { | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1526 | request = (MainThreadRequest) msg.obj; | 
|  | 1527 | WorkSource ws = (WorkSource) request.argument; | 
|  | 1528 | Phone phone = getPhoneFromRequest(request); | 
| Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1529 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1530 | break; | 
| Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1531 | } | 
|  | 1532 | case EVENT_GET_CELL_LOCATION_DONE: { | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1533 | ar = (AsyncResult) msg.obj; | 
|  | 1534 | request = (MainThreadRequest) ar.userObj; | 
|  | 1535 | if (ar.exception == null) { | 
|  | 1536 | request.result = ar.result; | 
|  | 1537 | } else { | 
| Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1538 | Phone phone = getPhoneFromRequest(request); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1539 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) | 
| Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1540 | ? new CellIdentityCdma() : new CellIdentityGsm(); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1541 | } | 
|  | 1542 |  | 
|  | 1543 | synchronized (request) { | 
|  | 1544 | request.notifyAll(); | 
|  | 1545 | } | 
|  | 1546 | break; | 
| Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1547 | } | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1548 | case CMD_MODEM_REBOOT: | 
|  | 1549 | request = (MainThreadRequest) msg.obj; | 
|  | 1550 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1551 | defaultPhone.rebootModem(onCompleted); | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1552 | break; | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1553 | case EVENT_CMD_MODEM_REBOOT_DONE: | 
|  | 1554 | handleNullReturnEvent(msg, "rebootModem"); | 
|  | 1555 | break; | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1556 | case CMD_REQUEST_ENABLE_MODEM: | 
|  | 1557 | request = (MainThreadRequest) msg.obj; | 
|  | 1558 | boolean enable = (boolean) request.argument; | 
|  | 1559 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); | 
| Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1560 | onCompleted.arg1 = enable ? 1 : 0; | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1561 | PhoneConfigurationManager.getInstance() | 
|  | 1562 | .enablePhone(request.phone, enable, onCompleted); | 
|  | 1563 | break; | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1564 | case EVENT_ENABLE_MODEM_DONE: { | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1565 | ar = (AsyncResult) msg.obj; | 
|  | 1566 | request = (MainThreadRequest) ar.userObj; | 
|  | 1567 | request.result = (ar.exception == null); | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1568 | int phoneId = request.phone.getPhoneId(); | 
| Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1569 | //update the cache as modem status has changed | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1570 | if ((boolean) request.result) { | 
|  | 1571 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); | 
|  | 1572 | updateModemStateMetrics(); | 
|  | 1573 | } else { | 
|  | 1574 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." | 
|  | 1575 | + ar.exception); | 
|  | 1576 | } | 
|  | 1577 | notifyRequester(request); | 
|  | 1578 | break; | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1579 | } | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1580 | case CMD_GET_MODEM_STATUS: | 
|  | 1581 | request = (MainThreadRequest) msg.obj; | 
|  | 1582 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); | 
|  | 1583 | PhoneConfigurationManager.getInstance() | 
|  | 1584 | .getPhoneStatusFromModem(request.phone, onCompleted); | 
|  | 1585 | break; | 
|  | 1586 | case EVENT_GET_MODEM_STATUS_DONE: | 
|  | 1587 | ar = (AsyncResult) msg.obj; | 
|  | 1588 | request = (MainThreadRequest) ar.userObj; | 
|  | 1589 | int id = request.phone.getPhoneId(); | 
|  | 1590 | if (ar.exception == null && ar.result != null) { | 
|  | 1591 | request.result = ar.result; | 
|  | 1592 | //update the cache as modem status has changed | 
|  | 1593 | mPhoneConfigurationManager.addToPhoneStatusCache(id, | 
|  | 1594 | (boolean) request.result); | 
|  | 1595 | } else { | 
|  | 1596 | // Return true if modem status cannot be retrieved. For most cases, | 
|  | 1597 | // modem status is on. And for older version modems, GET_MODEM_STATUS | 
|  | 1598 | // and disable modem are not supported. Modem is always on. | 
|  | 1599 | // TODO: this should be fixed in R to support a third | 
|  | 1600 | // status UNKNOWN b/131631629 | 
|  | 1601 | request.result = true; | 
|  | 1602 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." | 
|  | 1603 | + ar.exception); | 
|  | 1604 | } | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1605 | notifyRequester(request); | 
|  | 1606 | break; | 
| Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1607 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { | 
|  | 1608 | request = (MainThreadRequest) msg.obj; | 
|  | 1609 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); | 
|  | 1610 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = | 
|  | 1611 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; | 
|  | 1612 | request.phone.setSystemSelectionChannels(args.first, onCompleted); | 
|  | 1613 | break; | 
|  | 1614 | } | 
|  | 1615 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { | 
|  | 1616 | ar = (AsyncResult) msg.obj; | 
|  | 1617 | request = (MainThreadRequest) ar.userObj; | 
|  | 1618 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = | 
|  | 1619 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; | 
|  | 1620 | args.second.accept(ar.exception == null); | 
|  | 1621 | notifyRequester(request); | 
|  | 1622 | break; | 
|  | 1623 | } | 
| Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1624 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { | 
|  | 1625 | request = (MainThreadRequest) msg.obj; | 
|  | 1626 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); | 
|  | 1627 | Phone phone = getPhoneFromRequest(request); | 
|  | 1628 | if (phone != null) { | 
|  | 1629 | phone.getSystemSelectionChannels(onCompleted); | 
|  | 1630 | } else { | 
|  | 1631 | loge("getSystemSelectionChannels: No phone object"); | 
|  | 1632 | request.result = new ArrayList<RadioAccessSpecifier>(); | 
|  | 1633 | notifyRequester(request); | 
|  | 1634 | } | 
|  | 1635 | break; | 
|  | 1636 | } | 
|  | 1637 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: | 
|  | 1638 | ar = (AsyncResult) msg.obj; | 
|  | 1639 | request = (MainThreadRequest) ar.userObj; | 
|  | 1640 | if (ar.exception == null && ar.result != null) { | 
|  | 1641 | request.result = ar.result; | 
|  | 1642 | } else { | 
|  | 1643 | request.result = new IllegalArgumentException( | 
|  | 1644 | "Failed to retrieve system selection channels"); | 
|  | 1645 | if (ar.result == null) { | 
|  | 1646 | loge("getSystemSelectionChannels: Empty response"); | 
|  | 1647 | } else { | 
|  | 1648 | loge("getSystemSelectionChannels: Unknown exception"); | 
|  | 1649 | } | 
|  | 1650 | } | 
|  | 1651 | notifyRequester(request); | 
|  | 1652 | break; | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1653 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: | 
|  | 1654 | ar = (AsyncResult) msg.obj; | 
|  | 1655 | request = (MainThreadRequest) ar.userObj; | 
|  | 1656 | if (ar.exception == null && ar.result != null) { | 
|  | 1657 | request.result = ar.result; | 
|  | 1658 | } else { | 
|  | 1659 | request.result = -1; | 
|  | 1660 | loge("Failed to set Forbidden Plmns"); | 
|  | 1661 | if (ar.result == null) { | 
|  | 1662 | loge("setForbidenPlmns: Empty response"); | 
|  | 1663 | } else if (ar.exception != null) { | 
|  | 1664 | loge("setForbiddenPlmns: Exception: " + ar.exception); | 
|  | 1665 | request.result = -1; | 
|  | 1666 | } else { | 
|  | 1667 | loge("setForbiddenPlmns: Unknown exception"); | 
|  | 1668 | } | 
|  | 1669 | } | 
|  | 1670 | notifyRequester(request); | 
|  | 1671 | break; | 
|  | 1672 | case CMD_SET_FORBIDDEN_PLMNS: | 
|  | 1673 | request = (MainThreadRequest) msg.obj; | 
|  | 1674 | uiccCard = getUiccCardFromRequest(request); | 
|  | 1675 | if (uiccCard == null) { | 
|  | 1676 | loge("setForbiddenPlmns: UiccCard is null"); | 
|  | 1677 | request.result = -1; | 
|  | 1678 | notifyRequester(request); | 
|  | 1679 | break; | 
|  | 1680 | } | 
|  | 1681 | Pair<Integer, List<String>> setFplmnsArgs = | 
|  | 1682 | (Pair<Integer, List<String>>) request.argument; | 
|  | 1683 | appType = setFplmnsArgs.first; | 
|  | 1684 | List<String> fplmns = setFplmnsArgs.second; | 
|  | 1685 | uiccApp = uiccCard.getApplicationByType(appType); | 
|  | 1686 | if (uiccApp == null) { | 
|  | 1687 | loge("setForbiddenPlmns: no app with specified type -- " + appType); | 
|  | 1688 | request.result = -1; | 
|  | 1689 | loge("Failed to get UICC App"); | 
|  | 1690 | notifyRequester(request); | 
|  | 1691 | } else { | 
|  | 1692 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); | 
|  | 1693 | ((SIMRecords) uiccApp.getIccRecords()) | 
|  | 1694 | .setForbiddenPlmns(onCompleted, fplmns); | 
|  | 1695 | } | 
| yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1696 | break; | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1697 | case CMD_ERASE_MODEM_CONFIG: | 
|  | 1698 | request = (MainThreadRequest) msg.obj; | 
|  | 1699 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); | 
|  | 1700 | defaultPhone.eraseModemConfig(onCompleted); | 
|  | 1701 | break; | 
|  | 1702 | case EVENT_ERASE_MODEM_CONFIG_DONE: | 
|  | 1703 | handleNullReturnEvent(msg, "eraseModemConfig"); | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1704 | break; | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1705 |  | 
|  | 1706 | case CMD_CHANGE_ICC_LOCK_PASSWORD: | 
|  | 1707 | request = (MainThreadRequest) msg.obj; | 
|  | 1708 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); | 
|  | 1709 | Pair<String, String> changed = (Pair<String, String>) request.argument; | 
|  | 1710 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( | 
|  | 1711 | changed.first, changed.second, onCompleted); | 
|  | 1712 | break; | 
|  | 1713 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: | 
|  | 1714 | ar = (AsyncResult) msg.obj; | 
|  | 1715 | request = (MainThreadRequest) ar.userObj; | 
|  | 1716 | if (ar.exception == null) { | 
|  | 1717 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1718 | // If the operation is successful, update the PIN storage | 
|  | 1719 | Pair<String, String> passwords = (Pair<String, String>) request.argument; | 
|  | 1720 | int phoneId = getPhoneFromRequest(request).getPhoneId(); | 
|  | 1721 | UiccController.getInstance().getPinStorage() | 
|  | 1722 | .storePin(passwords.second, phoneId); | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1723 | } else { | 
|  | 1724 | request.result = msg.arg1; | 
|  | 1725 | } | 
|  | 1726 | notifyRequester(request); | 
|  | 1727 | break; | 
|  | 1728 |  | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1729 | case CMD_SET_ICC_LOCK_ENABLED: { | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1730 | request = (MainThreadRequest) msg.obj; | 
|  | 1731 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); | 
|  | 1732 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; | 
|  | 1733 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( | 
|  | 1734 | enabled.first, enabled.second, onCompleted); | 
|  | 1735 | break; | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1736 | } | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1737 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: | 
|  | 1738 | ar = (AsyncResult) msg.obj; | 
|  | 1739 | request = (MainThreadRequest) ar.userObj; | 
|  | 1740 | if (ar.exception == null) { | 
|  | 1741 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1742 | // If the operation is successful, update the PIN storage | 
|  | 1743 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; | 
|  | 1744 | int phoneId = getPhoneFromRequest(request).getPhoneId(); | 
|  | 1745 | if (enabled.first) { | 
|  | 1746 | UiccController.getInstance().getPinStorage() | 
|  | 1747 | .storePin(enabled.second, phoneId); | 
|  | 1748 | } else { | 
|  | 1749 | UiccController.getInstance().getPinStorage().clearPin(phoneId); | 
|  | 1750 | } | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1751 | } else { | 
|  | 1752 | request.result = msg.arg1; | 
|  | 1753 | } | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1754 |  | 
|  | 1755 |  | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1756 | notifyRequester(request); | 
|  | 1757 | break; | 
|  | 1758 |  | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1759 | case MSG_NOTIFY_USER_ACTIVITY: | 
|  | 1760 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); | 
| Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1761 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1762 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); | 
|  | 1763 | getDefaultPhone().getContext().sendBroadcastAsUser( | 
|  | 1764 | intent, UserHandle.ALL, permission.USER_ACTIVITY); | 
|  | 1765 | break; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1766 |  | 
|  | 1767 | case CMD_SET_DATA_THROTTLING: { | 
|  | 1768 | request = (MainThreadRequest) msg.obj; | 
|  | 1769 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); | 
|  | 1770 | DataThrottlingRequest dataThrottlingRequest = | 
|  | 1771 | (DataThrottlingRequest) request.argument; | 
|  | 1772 | Phone phone = getPhoneFromRequest(request); | 
|  | 1773 | if (phone != null) { | 
|  | 1774 | phone.setDataThrottling(onCompleted, | 
|  | 1775 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), | 
|  | 1776 | dataThrottlingRequest.getCompletionDurationMillis()); | 
|  | 1777 | } else { | 
|  | 1778 | loge("setDataThrottling: No phone object"); | 
|  | 1779 | request.result = | 
|  | 1780 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 1781 | notifyRequester(request); | 
|  | 1782 | } | 
|  | 1783 |  | 
|  | 1784 | break; | 
|  | 1785 | } | 
|  | 1786 | case EVENT_SET_DATA_THROTTLING_DONE: | 
|  | 1787 | ar = (AsyncResult) msg.obj; | 
|  | 1788 | request = (MainThreadRequest) ar.userObj; | 
|  | 1789 |  | 
|  | 1790 | if (ar.exception == null) { | 
|  | 1791 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; | 
|  | 1792 | } else if (ar.exception instanceof CommandException) { | 
|  | 1793 | loge("setDataThrottling: CommandException: " + ar.exception); | 
|  | 1794 | CommandException.Error error = | 
|  | 1795 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1796 |  | 
|  | 1797 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { | 
|  | 1798 | request.result = TelephonyManager | 
|  | 1799 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 1800 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { | 
|  | 1801 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; | 
|  | 1802 | } else { | 
|  | 1803 | request.result = | 
|  | 1804 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; | 
|  | 1805 | } | 
|  | 1806 | } else { | 
|  | 1807 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; | 
|  | 1808 | } | 
|  | 1809 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); | 
|  | 1810 | notifyRequester(request); | 
|  | 1811 | break; | 
| Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1812 |  | 
|  | 1813 | case CMD_SET_SIM_POWER: { | 
|  | 1814 | request = (MainThreadRequest) msg.obj; | 
|  | 1815 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); | 
|  | 1816 | request = (MainThreadRequest) msg.obj; | 
|  | 1817 | int stateToSet = | 
|  | 1818 | ((Pair<Integer, IIntegerConsumer>) | 
|  | 1819 | request.argument).first; | 
|  | 1820 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); | 
|  | 1821 | break; | 
|  | 1822 | } | 
|  | 1823 | case EVENT_SET_SIM_POWER_DONE: { | 
|  | 1824 | ar = (AsyncResult) msg.obj; | 
|  | 1825 | request = (MainThreadRequest) ar.userObj; | 
|  | 1826 | IIntegerConsumer callback = | 
|  | 1827 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; | 
|  | 1828 | if (ar.exception != null) { | 
|  | 1829 | loge("setSimPower exception: " + ar.exception); | 
|  | 1830 | int errorCode = TelephonyManager.CallForwardingInfoCallback | 
|  | 1831 | .RESULT_ERROR_UNKNOWN; | 
|  | 1832 | if (ar.exception instanceof CommandException) { | 
|  | 1833 | CommandException.Error error = | 
|  | 1834 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1835 | if (error == CommandException.Error.SIM_ERR) { | 
|  | 1836 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; | 
|  | 1837 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { | 
|  | 1838 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; | 
|  | 1839 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
|  | 1840 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; | 
|  | 1841 | } else { | 
|  | 1842 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; | 
|  | 1843 | } | 
|  | 1844 | } | 
|  | 1845 | try { | 
|  | 1846 | callback.accept(errorCode); | 
|  | 1847 | } catch (RemoteException e) { | 
|  | 1848 | // Ignore if the remote process is no longer available to call back. | 
|  | 1849 | Log.w(LOG_TAG, "setSimPower: callback not available."); | 
|  | 1850 | } | 
|  | 1851 | } else { | 
|  | 1852 | try { | 
|  | 1853 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); | 
|  | 1854 | } catch (RemoteException e) { | 
|  | 1855 | // Ignore if the remote process is no longer available to call back. | 
|  | 1856 | Log.w(LOG_TAG, "setSimPower: callback not available."); | 
|  | 1857 | } | 
|  | 1858 | } | 
|  | 1859 | break; | 
|  | 1860 | } | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1861 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { | 
|  | 1862 | request = (MainThreadRequest) msg.obj; | 
|  | 1863 |  | 
|  | 1864 | final Phone phone = getPhoneFromRequest(request); | 
|  | 1865 | if (phone == null || phone.getServiceStateTracker() == null) { | 
|  | 1866 | request.result = new IllegalStateException("Phone or SST is null"); | 
|  | 1867 | notifyRequester(request); | 
|  | 1868 | break; | 
|  | 1869 | } | 
|  | 1870 |  | 
|  | 1871 | Pair<Integer, SignalStrengthUpdateRequest> pair = | 
|  | 1872 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; | 
|  | 1873 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, | 
|  | 1874 | request); | 
|  | 1875 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( | 
|  | 1876 | request.subId, pair.first /*callingUid*/, | 
|  | 1877 | pair.second /*request*/, onCompleted); | 
|  | 1878 | break; | 
|  | 1879 | } | 
|  | 1880 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { | 
|  | 1881 | ar = (AsyncResult) msg.obj; | 
|  | 1882 | request = (MainThreadRequest) ar.userObj; | 
|  | 1883 | // request.result will be the exception of ar if present, true otherwise. | 
|  | 1884 | // Be cautious not to leave result null which will wait() forever | 
|  | 1885 | request.result = ar.exception != null ? ar.exception : true; | 
|  | 1886 | notifyRequester(request); | 
|  | 1887 | break; | 
|  | 1888 | } | 
|  | 1889 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { | 
|  | 1890 | request = (MainThreadRequest) msg.obj; | 
|  | 1891 |  | 
|  | 1892 | Phone phone = getPhoneFromRequest(request); | 
|  | 1893 | if (phone == null || phone.getServiceStateTracker() == null) { | 
|  | 1894 | request.result = new IllegalStateException("Phone or SST is null"); | 
|  | 1895 | notifyRequester(request); | 
|  | 1896 | break; | 
|  | 1897 | } | 
|  | 1898 |  | 
|  | 1899 | Pair<Integer, SignalStrengthUpdateRequest> pair = | 
|  | 1900 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; | 
|  | 1901 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, | 
|  | 1902 | request); | 
|  | 1903 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( | 
|  | 1904 | request.subId, pair.first /*callingUid*/, | 
|  | 1905 | pair.second /*request*/, onCompleted); | 
|  | 1906 | break; | 
|  | 1907 | } | 
|  | 1908 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { | 
|  | 1909 | ar = (AsyncResult) msg.obj; | 
|  | 1910 | request = (MainThreadRequest) ar.userObj; | 
|  | 1911 | request.result = ar.exception != null ? ar.exception : true; | 
|  | 1912 | notifyRequester(request); | 
|  | 1913 | break; | 
|  | 1914 | } | 
| Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1915 |  | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1916 | case CMD_PREPARE_UNATTENDED_REBOOT: | 
|  | 1917 | request = (MainThreadRequest) msg.obj; | 
|  | 1918 | request.result = | 
|  | 1919 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); | 
|  | 1920 | notifyRequester(request); | 
|  | 1921 | break; | 
|  | 1922 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1923 | default: | 
|  | 1924 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); | 
|  | 1925 | break; | 
|  | 1926 | } | 
|  | 1927 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1928 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1929 | private void notifyRequester(MainThreadRequest request) { | 
|  | 1930 | synchronized (request) { | 
|  | 1931 | request.notifyAll(); | 
|  | 1932 | } | 
|  | 1933 | } | 
|  | 1934 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1935 | private void handleNullReturnEvent(Message msg, String command) { | 
|  | 1936 | AsyncResult ar = (AsyncResult) msg.obj; | 
|  | 1937 | MainThreadRequest request = (MainThreadRequest) ar.userObj; | 
|  | 1938 | if (ar.exception == null) { | 
|  | 1939 | request.result = true; | 
|  | 1940 | } else { | 
|  | 1941 | request.result = false; | 
|  | 1942 | if (ar.exception instanceof CommandException) { | 
|  | 1943 | loge(command + ": CommandException: " + ar.exception); | 
|  | 1944 | } else { | 
|  | 1945 | loge(command + ": Unknown exception"); | 
|  | 1946 | } | 
|  | 1947 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1948 | notifyRequester(request); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1949 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1950 | } | 
|  | 1951 |  | 
|  | 1952 | /** | 
|  | 1953 | * Posts the specified command to be executed on the main thread, | 
|  | 1954 | * waits for the request to complete, and returns the result. | 
|  | 1955 | * @see #sendRequestAsync | 
|  | 1956 | */ | 
|  | 1957 | private Object sendRequest(int command, Object argument) { | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1958 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, | 
|  | 1959 | null, -1 /*timeoutInMs*/); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1960 | } | 
|  | 1961 |  | 
|  | 1962 | /** | 
|  | 1963 | * Posts the specified command to be executed on the main thread, | 
|  | 1964 | * waits for the request to complete, and returns the result. | 
|  | 1965 | * @see #sendRequestAsync | 
|  | 1966 | */ | 
|  | 1967 | private Object sendRequest(int command, Object argument, WorkSource workSource) { | 
|  | 1968 | return sendRequest(command, argument,  SubscriptionManager.INVALID_SUBSCRIPTION_ID, | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1969 | null, workSource, -1 /*timeoutInMs*/); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1970 | } | 
|  | 1971 |  | 
|  | 1972 | /** | 
|  | 1973 | * Posts the specified command to be executed on the main thread, | 
|  | 1974 | * waits for the request to complete, and returns the result. | 
|  | 1975 | * @see #sendRequestAsync | 
|  | 1976 | */ | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1977 | private Object sendRequest(int command, Object argument, Integer subId) { | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1978 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); | 
|  | 1979 | } | 
|  | 1980 |  | 
|  | 1981 | /** | 
|  | 1982 | * Posts the specified command to be executed on the main thread, | 
|  | 1983 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result | 
|  | 1984 | * if not timeout or null otherwise. | 
|  | 1985 | * @see #sendRequestAsync | 
|  | 1986 | */ | 
|  | 1987 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, | 
|  | 1988 | long timeoutInMs) { | 
|  | 1989 | return sendRequest(command, argument, subId, null, null, timeoutInMs); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1990 | } | 
|  | 1991 |  | 
|  | 1992 | /** | 
|  | 1993 | * Posts the specified command to be executed on the main thread, | 
|  | 1994 | * waits for the request to complete, and returns the result. | 
|  | 1995 | * @see #sendRequestAsync | 
|  | 1996 | */ | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1997 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1998 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1999 | } | 
|  | 2000 |  | 
|  | 2001 | /** | 
|  | 2002 | * Posts the specified command to be executed on the main thread, | 
|  | 2003 | * waits for the request to complete, and returns the result. | 
|  | 2004 | * @see #sendRequestAsync | 
|  | 2005 | */ | 
|  | 2006 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2007 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, | 
|  | 2008 | workSource, -1 /*timeoutInMs*/); | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2009 | } | 
|  | 2010 |  | 
|  | 2011 | /** | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2012 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is | 
|  | 2013 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for | 
|  | 2014 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2015 | * @see #sendRequestAsync | 
|  | 2016 | */ | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2017 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, | 
|  | 2018 | WorkSource workSource, long timeoutInMs) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2019 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { | 
|  | 2020 | throw new RuntimeException("This method will deadlock if called from the main thread."); | 
|  | 2021 | } | 
|  | 2022 |  | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2023 | MainThreadRequest request = null; | 
|  | 2024 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { | 
|  | 2025 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); | 
|  | 2026 | } else if (phone != null) { | 
|  | 2027 | request = new MainThreadRequest(argument, phone, workSource); | 
|  | 2028 | } else { | 
|  | 2029 | request = new MainThreadRequest(argument, subId, workSource); | 
|  | 2030 | } | 
|  | 2031 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2032 | Message msg = mMainThreadHandler.obtainMessage(command, request); | 
|  | 2033 | msg.sendToTarget(); | 
|  | 2034 |  | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2035 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2036 | synchronized (request) { | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2037 | if (timeoutInMs >= 0) { | 
|  | 2038 | // Wait for at least timeoutInMs before returning null request result | 
|  | 2039 | long now = SystemClock.elapsedRealtime(); | 
|  | 2040 | long deadline = now + timeoutInMs; | 
|  | 2041 | while (request == null && now < deadline) { | 
|  | 2042 | try { | 
|  | 2043 | request.wait(deadline - now); | 
|  | 2044 | } catch (InterruptedException e) { | 
|  | 2045 | // Do nothing, go back and check if request is completed or timeout | 
|  | 2046 | } finally { | 
|  | 2047 | now = SystemClock.elapsedRealtime(); | 
|  | 2048 | } | 
|  | 2049 | } | 
|  | 2050 | } else { | 
|  | 2051 | // Wait for the request to complete | 
|  | 2052 | while (request.result == null) { | 
|  | 2053 | try { | 
|  | 2054 | request.wait(); | 
|  | 2055 | } catch (InterruptedException e) { | 
|  | 2056 | // Do nothing, go back and wait until the request is complete | 
|  | 2057 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2058 | } | 
|  | 2059 | } | 
|  | 2060 | } | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2061 | if (request.result == null) { | 
|  | 2062 | Log.wtf(LOG_TAG, | 
|  | 2063 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); | 
|  | 2064 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2065 | return request.result; | 
|  | 2066 | } | 
|  | 2067 |  | 
|  | 2068 | /** | 
|  | 2069 | * Asynchronous ("fire and forget") version of sendRequest(): | 
|  | 2070 | * Posts the specified command to be executed on the main thread, and | 
|  | 2071 | * returns immediately. | 
|  | 2072 | * @see #sendRequest | 
|  | 2073 | */ | 
|  | 2074 | private void sendRequestAsync(int command) { | 
|  | 2075 | mMainThreadHandler.sendEmptyMessage(command); | 
|  | 2076 | } | 
|  | 2077 |  | 
|  | 2078 | /** | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2079 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2080 | * @see {@link #sendRequest(int)} | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2081 | */ | 
|  | 2082 | private void sendRequestAsync(int command, Object argument) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2083 | sendRequestAsync(command, argument, null, null); | 
|  | 2084 | } | 
|  | 2085 |  | 
|  | 2086 | /** | 
|  | 2087 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. | 
|  | 2088 | * @see {@link #sendRequest(int,Object)} | 
|  | 2089 | */ | 
|  | 2090 | private void sendRequestAsync( | 
|  | 2091 | int command, Object argument, Phone phone, WorkSource workSource) { | 
|  | 2092 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2093 | Message msg = mMainThreadHandler.obtainMessage(command, request); | 
|  | 2094 | msg.sendToTarget(); | 
|  | 2095 | } | 
|  | 2096 |  | 
|  | 2097 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2098 | * Initialize the singleton PhoneInterfaceManager instance. | 
|  | 2099 | * This is only done once, at startup, from PhoneApp.onCreate(). | 
|  | 2100 | */ | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2101 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2102 | synchronized (PhoneInterfaceManager.class) { | 
|  | 2103 | if (sInstance == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2104 | sInstance = new PhoneInterfaceManager(app); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2105 | } else { | 
|  | 2106 | Log.wtf(LOG_TAG, "init() called multiple times!  sInstance = " + sInstance); | 
|  | 2107 | } | 
|  | 2108 | return sInstance; | 
|  | 2109 | } | 
|  | 2110 | } | 
|  | 2111 |  | 
|  | 2112 | /** Private constructor; @see init() */ | 
| Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2113 | private PhoneInterfaceManager(PhoneGlobals app) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2114 | mApp = app; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2115 | mCM = PhoneGlobals.getInstance().mCM; | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2116 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2117 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2118 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); | 
|  | 2119 | mMainThreadHandler = new MainThreadHandler(); | 
| Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2120 | mSubscriptionController = SubscriptionController.getInstance(); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2121 | mTelephonySharedPreferences = | 
|  | 2122 | PreferenceManager.getDefaultSharedPreferences(mApp); | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2123 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2124 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); | 
| Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2125 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); | 
| Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2126 | mNotifyUserActivity = new AtomicBoolean(false); | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2127 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2128 | publish(); | 
|  | 2129 | } | 
|  | 2130 |  | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2131 | private Phone getDefaultPhone() { | 
|  | 2132 | Phone thePhone = getPhone(getDefaultSubscription()); | 
|  | 2133 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); | 
|  | 2134 | } | 
|  | 2135 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2136 | private void publish() { | 
|  | 2137 | if (DBG) log("publish: " + this); | 
|  | 2138 |  | 
| Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2139 | TelephonyFrameworkInitializer | 
|  | 2140 | .getTelephonyServiceManager() | 
|  | 2141 | .getTelephonyServiceRegisterer() | 
|  | 2142 | .register(this); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2143 | } | 
|  | 2144 |  | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2145 | private Phone getPhoneFromRequest(MainThreadRequest request) { | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2146 | if (request.phone != null) { | 
|  | 2147 | return request.phone; | 
|  | 2148 | } else { | 
|  | 2149 | return getPhoneFromSubId(request.subId); | 
|  | 2150 | } | 
|  | 2151 | } | 
|  | 2152 |  | 
|  | 2153 | private Phone getPhoneFromSubId(int subId) { | 
|  | 2154 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) | 
|  | 2155 | ? getDefaultPhone() : getPhone(subId); | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2156 | } | 
|  | 2157 |  | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2158 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { | 
|  | 2159 | Phone phone = getPhoneFromRequest(request); | 
|  | 2160 | return phone == null ? null : | 
|  | 2161 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); | 
|  | 2162 | } | 
|  | 2163 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2164 | // returns phone associated with the subId. | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2165 | private Phone getPhone(int subId) { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2166 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2167 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2168 |  | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2169 | private void sendEraseModemConfig(Phone phone) { | 
|  | 2170 | if (phone != null) { | 
|  | 2171 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 2172 | mApp, phone.getSubId(), "eraseModemConfig"); | 
|  | 2173 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2174 | try { | 
|  | 2175 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); | 
|  | 2176 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); | 
|  | 2177 | } finally { | 
|  | 2178 | Binder.restoreCallingIdentity(identity); | 
|  | 2179 | } | 
|  | 2180 | } | 
|  | 2181 | } | 
|  | 2182 |  | 
| Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2183 | private boolean isImsAvailableOnDevice() { | 
|  | 2184 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); | 
|  | 2185 | if (pm == null) { | 
|  | 2186 | // For some reason package manger is not available.. This will fail internally anyway, | 
|  | 2187 | // so do not throw error and allow. | 
|  | 2188 | return true; | 
|  | 2189 | } | 
|  | 2190 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); | 
|  | 2191 | } | 
|  | 2192 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2193 | public void dial(String number) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2194 | dialForSubscriber(getPreferredVoiceSubscription(), number); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2195 | } | 
|  | 2196 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2197 | public void dialForSubscriber(int subId, String number) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2198 | if (DBG) log("dial: " + number); | 
|  | 2199 | // No permission check needed here: This is just a wrapper around the | 
|  | 2200 | // ACTION_DIAL intent, which is available to any app since it puts up | 
|  | 2201 | // the UI before it does anything. | 
|  | 2202 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2203 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2204 | try { | 
|  | 2205 | String url = createTelUrl(number); | 
|  | 2206 | if (url == null) { | 
|  | 2207 | return; | 
|  | 2208 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2209 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2210 | // PENDING: should we just silently fail if phone is offhook or ringing? | 
|  | 2211 | PhoneConstants.State state = mCM.getState(subId); | 
|  | 2212 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { | 
|  | 2213 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); | 
|  | 2214 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
|  | 2215 | mApp.startActivity(intent); | 
|  | 2216 | } | 
|  | 2217 | } finally { | 
|  | 2218 | Binder.restoreCallingIdentity(identity); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2219 | } | 
|  | 2220 | } | 
|  | 2221 |  | 
|  | 2222 | public void call(String callingPackage, String number) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2223 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2224 | } | 
|  | 2225 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2226 | public void callForSubscriber(int subId, String callingPackage, String number) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2227 | if (DBG) log("call: " + number); | 
|  | 2228 |  | 
|  | 2229 | // This is just a wrapper around the ACTION_CALL intent, but we still | 
|  | 2230 | // need to do a permission check since we're calling startActivity() | 
|  | 2231 | // from the context of the phone app. | 
|  | 2232 | enforceCallPermission(); | 
|  | 2233 |  | 
| Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2234 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2235 | != AppOpsManager.MODE_ALLOWED) { | 
|  | 2236 | return; | 
|  | 2237 | } | 
|  | 2238 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2239 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2240 | try { | 
|  | 2241 | String url = createTelUrl(number); | 
|  | 2242 | if (url == null) { | 
|  | 2243 | return; | 
|  | 2244 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2245 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2246 | boolean isValid = false; | 
|  | 2247 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); | 
|  | 2248 | if (slist != null) { | 
|  | 2249 | for (SubscriptionInfo subInfoRecord : slist) { | 
|  | 2250 | if (subInfoRecord.getSubscriptionId() == subId) { | 
|  | 2251 | isValid = true; | 
|  | 2252 | break; | 
|  | 2253 | } | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2254 | } | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2255 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2256 | if (!isValid) { | 
|  | 2257 | return; | 
|  | 2258 | } | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2259 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2260 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); | 
|  | 2261 | intent.putExtra(SUBSCRIPTION_KEY, subId); | 
|  | 2262 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
|  | 2263 | mApp.startActivity(intent); | 
|  | 2264 | } finally { | 
|  | 2265 | Binder.restoreCallingIdentity(identity); | 
|  | 2266 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2267 | } | 
|  | 2268 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2269 | public boolean supplyPinForSubscriber(int subId, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2270 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2271 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; | 
|  | 2272 | } | 
|  | 2273 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2274 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2275 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2276 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; | 
|  | 2277 | } | 
|  | 2278 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2279 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2280 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2281 |  | 
|  | 2282 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2283 | try { | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2284 | Phone phone = getPhone(subId); | 
|  | 2285 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2286 | checkSimPin.start(); | 
|  | 2287 | return checkSimPin.unlockSim(null, pin); | 
|  | 2288 | } finally { | 
|  | 2289 | Binder.restoreCallingIdentity(identity); | 
|  | 2290 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2291 | } | 
|  | 2292 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2293 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2294 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2295 |  | 
|  | 2296 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2297 | try { | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2298 | Phone phone = getPhone(subId); | 
|  | 2299 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2300 | checkSimPuk.start(); | 
|  | 2301 | return checkSimPuk.unlockSim(puk, pin); | 
|  | 2302 | } finally { | 
|  | 2303 | Binder.restoreCallingIdentity(identity); | 
|  | 2304 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2305 | } | 
|  | 2306 |  | 
|  | 2307 | /** | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2308 | * Helper thread to turn async call to SimCard#supplyPin into | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2309 | * a synchronous one. | 
|  | 2310 | */ | 
|  | 2311 | private static class UnlockSim extends Thread { | 
|  | 2312 |  | 
|  | 2313 | private final IccCard mSimCard; | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2314 | private final int mPhoneId; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2315 |  | 
|  | 2316 | private boolean mDone = false; | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2317 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; | 
|  | 2318 | private int mRetryCount = -1; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2319 |  | 
|  | 2320 | // For replies from SimCard interface | 
|  | 2321 | private Handler mHandler; | 
|  | 2322 |  | 
|  | 2323 | // For async handler to identify request type | 
|  | 2324 | private static final int SUPPLY_PIN_COMPLETE = 100; | 
|  | 2325 |  | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2326 | UnlockSim(int phoneId, IccCard simCard) { | 
|  | 2327 | mPhoneId = phoneId; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2328 | mSimCard = simCard; | 
|  | 2329 | } | 
|  | 2330 |  | 
|  | 2331 | @Override | 
|  | 2332 | public void run() { | 
|  | 2333 | Looper.prepare(); | 
|  | 2334 | synchronized (UnlockSim.this) { | 
|  | 2335 | mHandler = new Handler() { | 
|  | 2336 | @Override | 
|  | 2337 | public void handleMessage(Message msg) { | 
|  | 2338 | AsyncResult ar = (AsyncResult) msg.obj; | 
|  | 2339 | switch (msg.what) { | 
|  | 2340 | case SUPPLY_PIN_COMPLETE: | 
|  | 2341 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); | 
|  | 2342 | synchronized (UnlockSim.this) { | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2343 | mRetryCount = msg.arg1; | 
|  | 2344 | if (ar.exception != null) { | 
|  | 2345 | if (ar.exception instanceof CommandException && | 
|  | 2346 | ((CommandException)(ar.exception)).getCommandError() | 
|  | 2347 | == CommandException.Error.PASSWORD_INCORRECT) { | 
|  | 2348 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; | 
| vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2349 | } //When UiccCardApp dispose,handle message and return exception | 
|  | 2350 | else if (ar.exception instanceof CommandException && | 
|  | 2351 | ((CommandException) (ar.exception)).getCommandError() | 
|  | 2352 | == CommandException.Error.ABORTED) { | 
|  | 2353 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2354 | } else { | 
|  | 2355 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; | 
|  | 2356 | } | 
|  | 2357 | } else { | 
|  | 2358 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; | 
|  | 2359 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2360 | mDone = true; | 
|  | 2361 | UnlockSim.this.notifyAll(); | 
|  | 2362 | } | 
|  | 2363 | break; | 
|  | 2364 | } | 
|  | 2365 | } | 
|  | 2366 | }; | 
|  | 2367 | UnlockSim.this.notifyAll(); | 
|  | 2368 | } | 
|  | 2369 | Looper.loop(); | 
|  | 2370 | } | 
|  | 2371 |  | 
|  | 2372 | /* | 
|  | 2373 | * Use PIN or PUK to unlock SIM card | 
|  | 2374 | * | 
|  | 2375 | * If PUK is null, unlock SIM card with PIN | 
|  | 2376 | * | 
|  | 2377 | * If PUK is not null, unlock SIM card with PUK and set PIN code | 
|  | 2378 | */ | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2379 | synchronized int[] unlockSim(String puk, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2380 |  | 
|  | 2381 | while (mHandler == null) { | 
|  | 2382 | try { | 
|  | 2383 | wait(); | 
|  | 2384 | } catch (InterruptedException e) { | 
|  | 2385 | Thread.currentThread().interrupt(); | 
|  | 2386 | } | 
|  | 2387 | } | 
|  | 2388 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); | 
|  | 2389 |  | 
|  | 2390 | if (puk == null) { | 
|  | 2391 | mSimCard.supplyPin(pin, callback); | 
|  | 2392 | } else { | 
|  | 2393 | mSimCard.supplyPuk(puk, pin, callback); | 
|  | 2394 | } | 
|  | 2395 |  | 
|  | 2396 | while (!mDone) { | 
|  | 2397 | try { | 
|  | 2398 | Log.d(LOG_TAG, "wait for done"); | 
|  | 2399 | wait(); | 
|  | 2400 | } catch (InterruptedException e) { | 
|  | 2401 | // Restore the interrupted status | 
|  | 2402 | Thread.currentThread().interrupt(); | 
|  | 2403 | } | 
|  | 2404 | } | 
|  | 2405 | Log.d(LOG_TAG, "done"); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2406 | int[] resultArray = new int[2]; | 
|  | 2407 | resultArray[0] = mResult; | 
|  | 2408 | resultArray[1] = mRetryCount; | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2409 |  | 
|  | 2410 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { | 
|  | 2411 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); | 
|  | 2412 | } | 
|  | 2413 |  | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2414 | return resultArray; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2415 | } | 
|  | 2416 | } | 
|  | 2417 |  | 
| Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2418 | /** | 
|  | 2419 | * This method has been removed due to privacy and stability concerns. | 
|  | 2420 | */ | 
|  | 2421 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2422 | public void updateServiceLocation() { | 
| Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2423 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); | 
|  | 2424 | return; | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2425 | } | 
|  | 2426 |  | 
| Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2427 | @Override | 
|  | 2428 | public void updateServiceLocationWithPackageName(String callingPackage) { | 
|  | 2429 | mApp.getSystemService(AppOpsManager.class) | 
|  | 2430 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 2431 |  | 
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2432 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); | 
| Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2433 | if (targetSdk > android.os.Build.VERSION_CODES.R) { | 
|  | 2434 | // Callers targeting S have no business invoking this method. | 
|  | 2435 | return; | 
|  | 2436 | } | 
|  | 2437 |  | 
|  | 2438 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 2439 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 2440 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 2441 | .setCallingPackage(callingPackage) | 
|  | 2442 | .setCallingFeatureId(null) | 
|  | 2443 | .setCallingPid(Binder.getCallingPid()) | 
|  | 2444 | .setCallingUid(Binder.getCallingUid()) | 
|  | 2445 | .setMethod("updateServiceLocation") | 
|  | 2446 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) | 
|  | 2447 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 2448 | .build()); | 
|  | 2449 | // Apps that lack location permission have no business calling this method; | 
|  | 2450 | // however, because no permission was declared in the public API, denials must | 
|  | 2451 | // all be "soft". | 
|  | 2452 | switch (locationResult) { | 
|  | 2453 | case DENIED_HARD: /* fall through */ | 
|  | 2454 | case DENIED_SOFT: | 
|  | 2455 | return; | 
|  | 2456 | } | 
|  | 2457 |  | 
|  | 2458 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2459 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2460 | try { | 
| Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2461 | final Phone phone = getPhone(getDefaultSubscription()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2462 | if (phone != null) { | 
| Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2463 | phone.updateServiceLocation(workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2464 | } | 
|  | 2465 | } finally { | 
|  | 2466 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2467 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2468 | } | 
|  | 2469 |  | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2470 | @Deprecated | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2471 | @Override | 
|  | 2472 | public boolean isRadioOn(String callingPackage) { | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2473 | return isRadioOnWithFeature(callingPackage, null); | 
|  | 2474 | } | 
|  | 2475 |  | 
|  | 2476 |  | 
|  | 2477 | @Override | 
|  | 2478 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { | 
|  | 2479 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, | 
|  | 2480 | callingFeatureId); | 
|  | 2481 | } | 
|  | 2482 |  | 
|  | 2483 | @Deprecated | 
|  | 2484 | @Override | 
|  | 2485 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { | 
|  | 2486 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2487 | } | 
|  | 2488 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2489 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2490 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, | 
|  | 2491 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2492 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2493 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2494 | return false; | 
|  | 2495 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2496 |  | 
|  | 2497 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2498 | try { | 
|  | 2499 | return isRadioOnForSubscriber(subId); | 
|  | 2500 | } finally { | 
|  | 2501 | Binder.restoreCallingIdentity(identity); | 
|  | 2502 | } | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2503 | } | 
|  | 2504 |  | 
|  | 2505 | private boolean isRadioOnForSubscriber(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2506 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2507 | try { | 
|  | 2508 | final Phone phone = getPhone(subId); | 
|  | 2509 | if (phone != null) { | 
|  | 2510 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; | 
|  | 2511 | } else { | 
|  | 2512 | return false; | 
|  | 2513 | } | 
|  | 2514 | } finally { | 
|  | 2515 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2516 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2517 | } | 
|  | 2518 |  | 
|  | 2519 | public void toggleRadioOnOff() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2520 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2521 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2522 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2523 | public void toggleRadioOnOffForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2524 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2525 |  | 
|  | 2526 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2527 | try { | 
|  | 2528 | final Phone phone = getPhone(subId); | 
|  | 2529 | if (phone != null) { | 
|  | 2530 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); | 
|  | 2531 | } | 
|  | 2532 | } finally { | 
|  | 2533 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2534 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2535 | } | 
|  | 2536 |  | 
|  | 2537 | public boolean setRadio(boolean turnOn) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2538 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2539 | } | 
|  | 2540 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2541 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2542 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2543 |  | 
|  | 2544 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2545 | try { | 
|  | 2546 | final Phone phone = getPhone(subId); | 
|  | 2547 | if (phone == null) { | 
|  | 2548 | return false; | 
|  | 2549 | } | 
|  | 2550 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { | 
|  | 2551 | toggleRadioOnOffForSubscriber(subId); | 
|  | 2552 | } | 
|  | 2553 | return true; | 
|  | 2554 | } finally { | 
|  | 2555 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2556 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2557 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2558 |  | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2559 | public boolean needMobileRadioShutdown() { | 
| Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2560 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2561 | /* | 
|  | 2562 | * If any of the Radios are available, it will need to be | 
|  | 2563 | * shutdown. So return true if any Radio is available. | 
|  | 2564 | */ | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2565 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2566 | try { | 
|  | 2567 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 2568 | Phone phone = PhoneFactory.getPhone(i); | 
|  | 2569 | if (phone != null && phone.isRadioAvailable()) return true; | 
|  | 2570 | } | 
|  | 2571 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); | 
|  | 2572 | return false; | 
|  | 2573 | } finally { | 
|  | 2574 | Binder.restoreCallingIdentity(identity); | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2575 | } | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2576 | } | 
|  | 2577 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2578 | @Override | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2579 | public void shutdownMobileRadios() { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2580 | enforceModifyPermission(); | 
|  | 2581 |  | 
|  | 2582 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2583 | try { | 
|  | 2584 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 2585 | logv("Shutting down Phone " + i); | 
|  | 2586 | shutdownRadioUsingPhoneId(i); | 
|  | 2587 | } | 
|  | 2588 | } finally { | 
|  | 2589 | Binder.restoreCallingIdentity(identity); | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2590 | } | 
|  | 2591 | } | 
|  | 2592 |  | 
|  | 2593 | private void shutdownRadioUsingPhoneId(int phoneId) { | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2594 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 2595 | if (phone != null && phone.isRadioAvailable()) { | 
|  | 2596 | phone.shutdownRadio(); | 
|  | 2597 | } | 
|  | 2598 | } | 
|  | 2599 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2600 | public boolean setRadioPower(boolean turnOn) { | 
| Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2601 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2602 |  | 
|  | 2603 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2604 | try { | 
|  | 2605 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); | 
|  | 2606 | if (defaultPhone != null) { | 
|  | 2607 | defaultPhone.setRadioPower(turnOn); | 
|  | 2608 | return true; | 
|  | 2609 | } else { | 
|  | 2610 | loge("There's no default phone."); | 
|  | 2611 | return false; | 
|  | 2612 | } | 
|  | 2613 | } finally { | 
|  | 2614 | Binder.restoreCallingIdentity(identity); | 
| Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2615 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2616 | } | 
|  | 2617 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2618 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2619 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2620 |  | 
|  | 2621 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2622 | try { | 
|  | 2623 | final Phone phone = getPhone(subId); | 
|  | 2624 | if (phone != null) { | 
|  | 2625 | phone.setRadioPower(turnOn); | 
|  | 2626 | return true; | 
|  | 2627 | } else { | 
|  | 2628 | return false; | 
|  | 2629 | } | 
|  | 2630 | } finally { | 
|  | 2631 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2632 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2633 | } | 
|  | 2634 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2635 | // FIXME: subId version needed | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2636 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2637 | public boolean enableDataConnectivity() { | 
|  | 2638 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2639 |  | 
|  | 2640 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2641 | try { | 
|  | 2642 | int subId = mSubscriptionController.getDefaultDataSubId(); | 
|  | 2643 | final Phone phone = getPhone(subId); | 
|  | 2644 | if (phone != null) { | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2645 | phone.getDataEnabledSettings().setDataEnabled( | 
|  | 2646 | TelephonyManager.DATA_ENABLED_REASON_USER, true); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2647 | return true; | 
|  | 2648 | } else { | 
|  | 2649 | return false; | 
|  | 2650 | } | 
|  | 2651 | } finally { | 
|  | 2652 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2653 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2654 | } | 
|  | 2655 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2656 | // FIXME: subId version needed | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2657 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2658 | public boolean disableDataConnectivity() { | 
|  | 2659 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2660 |  | 
|  | 2661 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2662 | try { | 
|  | 2663 | int subId = mSubscriptionController.getDefaultDataSubId(); | 
|  | 2664 | final Phone phone = getPhone(subId); | 
|  | 2665 | if (phone != null) { | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2666 | phone.getDataEnabledSettings().setDataEnabled( | 
|  | 2667 | TelephonyManager.DATA_ENABLED_REASON_USER, false); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2668 | return true; | 
|  | 2669 | } else { | 
|  | 2670 | return false; | 
|  | 2671 | } | 
|  | 2672 | } finally { | 
|  | 2673 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2674 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2675 | } | 
|  | 2676 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2677 | @Override | 
| Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2678 | public boolean isDataConnectivityPossible(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2679 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2680 | try { | 
|  | 2681 | final Phone phone = getPhone(subId); | 
|  | 2682 | if (phone != null) { | 
| Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2683 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2684 | } else { | 
|  | 2685 | return false; | 
|  | 2686 | } | 
|  | 2687 | } finally { | 
|  | 2688 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2689 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2690 | } | 
|  | 2691 |  | 
|  | 2692 | public boolean handlePinMmi(String dialString) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2693 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2694 | } | 
|  | 2695 |  | 
| pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2696 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2697 | enforceCallPermission(); | 
|  | 2698 |  | 
|  | 2699 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2700 | try { | 
|  | 2701 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 2702 | return; | 
|  | 2703 | } | 
|  | 2704 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); | 
|  | 2705 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); | 
|  | 2706 | } finally { | 
|  | 2707 | Binder.restoreCallingIdentity(identity); | 
|  | 2708 | } | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2709 | }; | 
|  | 2710 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2711 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2712 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2713 |  | 
|  | 2714 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2715 | try { | 
|  | 2716 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 2717 | return false; | 
|  | 2718 | } | 
|  | 2719 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); | 
|  | 2720 | } finally { | 
|  | 2721 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2722 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2723 | } | 
|  | 2724 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2725 | public int getCallState() { | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2726 | return getCallStateForSlot(getSlotForDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2727 | } | 
|  | 2728 |  | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2729 | public int getCallStateForSlot(int slotIndex) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2730 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2731 | try { | 
|  | 2732 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2733 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : | 
|  | 2734 | PhoneConstantConversions.convertCallState(phone.getState()); | 
|  | 2735 | } finally { | 
|  | 2736 | Binder.restoreCallingIdentity(identity); | 
|  | 2737 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2738 | } | 
|  | 2739 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2740 | @Override | 
| Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2741 | public int getDataState() { | 
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2742 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); | 
|  | 2743 | } | 
|  | 2744 |  | 
|  | 2745 | @Override | 
|  | 2746 | public int getDataStateForSubId(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2747 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2748 | try { | 
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2749 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2750 | if (phone != null) { | 
|  | 2751 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); | 
|  | 2752 | } else { | 
|  | 2753 | return PhoneConstantConversions.convertDataState( | 
|  | 2754 | PhoneConstants.DataState.DISCONNECTED); | 
|  | 2755 | } | 
|  | 2756 | } finally { | 
|  | 2757 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2758 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2759 | } | 
|  | 2760 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2761 | @Override | 
| Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2762 | public int getDataActivity() { | 
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2763 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); | 
|  | 2764 | } | 
|  | 2765 |  | 
|  | 2766 | @Override | 
|  | 2767 | public int getDataActivityForSubId(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2768 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2769 | try { | 
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2770 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2771 | if (phone != null) { | 
|  | 2772 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); | 
|  | 2773 | } else { | 
|  | 2774 | return TelephonyManager.DATA_ACTIVITY_NONE; | 
|  | 2775 | } | 
|  | 2776 | } finally { | 
|  | 2777 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2778 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2779 | } | 
|  | 2780 |  | 
|  | 2781 | @Override | 
| Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2782 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2783 | mApp.getSystemService(AppOpsManager.class) | 
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2784 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2785 |  | 
|  | 2786 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 2787 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 2788 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 2789 | .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2790 | .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2791 | .setCallingPid(Binder.getCallingPid()) | 
|  | 2792 | .setCallingUid(Binder.getCallingUid()) | 
|  | 2793 | .setMethod("getCellLocation") | 
| Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2794 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2795 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 2796 | .build()); | 
|  | 2797 | switch (locationResult) { | 
|  | 2798 | case DENIED_HARD: | 
|  | 2799 | throw new SecurityException("Not allowed to access cell location"); | 
|  | 2800 | case DENIED_SOFT: | 
| Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2801 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) | 
|  | 2802 | ? new CellIdentityCdma() : new CellIdentityGsm(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2803 | } | 
|  | 2804 |  | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2805 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2806 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2807 | try { | 
|  | 2808 | if (DBG_LOC) log("getCellLocation: is active user"); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2809 | int subId = mSubscriptionController.getDefaultDataSubId(); | 
| Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2810 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2811 | } finally { | 
|  | 2812 | Binder.restoreCallingIdentity(identity); | 
|  | 2813 | } | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2814 | } | 
|  | 2815 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2816 | @Override | 
| Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2817 | public String getNetworkCountryIsoForPhone(int phoneId) { | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2818 | // Reporting the correct network country is ambiguous when IWLAN could conflict with | 
|  | 2819 | // registered cell info, so return a NULL country instead. | 
|  | 2820 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2821 | try { | 
| Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2822 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { | 
|  | 2823 | // Get default phone in this case. | 
|  | 2824 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; | 
|  | 2825 | } | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2826 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2827 | Phone phone = PhoneFactory.getPhone(phoneId); | 
| Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2828 | if (phone == null) return ""; | 
|  | 2829 | ServiceStateTracker sst = phone.getServiceStateTracker(); | 
|  | 2830 | if (sst == null) return ""; | 
|  | 2831 | LocaleTracker lt = sst.getLocaleTracker(); | 
|  | 2832 | if (lt == null) return ""; | 
| Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 2833 | return lt.getCurrentCountry(); | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2834 | } finally { | 
|  | 2835 | Binder.restoreCallingIdentity(identity); | 
|  | 2836 | } | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2837 | } | 
|  | 2838 |  | 
| Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2839 | /** | 
|  | 2840 | * This method was removed due to potential issues caused by performing partial | 
|  | 2841 | * updates of service state, and lack of a credible use case. | 
|  | 2842 | * | 
|  | 2843 | * This has the ability to break the telephony implementation by disabling notification of | 
|  | 2844 | * changes in device connectivity. DO NOT USE THIS! | 
|  | 2845 | */ | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2846 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2847 | public void enableLocationUpdates() { | 
|  | 2848 | mApp.enforceCallingOrSelfPermission( | 
|  | 2849 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2850 | } | 
|  | 2851 |  | 
| Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2852 | /** | 
|  | 2853 | * This method was removed due to potential issues caused by performing partial | 
|  | 2854 | * updates of service state, and lack of a credible use case. | 
|  | 2855 | * | 
|  | 2856 | * This has the ability to break the telephony implementation by disabling notification of | 
|  | 2857 | * changes in device connectivity. DO NOT USE THIS! | 
|  | 2858 | */ | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2859 | @Override | 
|  | 2860 | public void disableLocationUpdates() { | 
|  | 2861 | mApp.enforceCallingOrSelfPermission( | 
|  | 2862 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2863 | } | 
|  | 2864 |  | 
|  | 2865 | @Override | 
|  | 2866 | @SuppressWarnings("unchecked") | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2867 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, | 
|  | 2868 | String callingFeatureId) { | 
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2869 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); | 
| Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2870 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { | 
|  | 2871 | throw new SecurityException( | 
|  | 2872 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); | 
|  | 2873 | } | 
| Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2874 |  | 
| Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2875 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2876 | callingPackage) != AppOpsManager.MODE_ALLOWED) { | 
|  | 2877 | return null; | 
|  | 2878 | } | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2879 |  | 
| Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2880 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2881 |  | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2882 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2883 | if (info == null) return null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2884 |  | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2885 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); | 
|  | 2886 | for (CellInfo ci : info) { | 
|  | 2887 | if (ci instanceof CellInfoGsm) { | 
|  | 2888 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); | 
|  | 2889 | } else if (ci instanceof CellInfoWcdma) { | 
|  | 2890 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); | 
|  | 2891 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2892 | } | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2893 | return (neighbors.size()) > 0 ? neighbors : null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2894 | } | 
|  | 2895 |  | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2896 | private List<CellInfo> getCachedCellInfo() { | 
|  | 2897 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); | 
|  | 2898 | for (Phone phone : PhoneFactory.getPhones()) { | 
|  | 2899 | List<CellInfo> info = phone.getAllCellInfo(); | 
|  | 2900 | if (info != null) cellInfos.addAll(info); | 
|  | 2901 | } | 
|  | 2902 | return cellInfos; | 
|  | 2903 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2904 |  | 
|  | 2905 | @Override | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2906 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2907 | mApp.getSystemService(AppOpsManager.class) | 
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2908 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2909 |  | 
|  | 2910 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 2911 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 2912 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 2913 | .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2914 | .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2915 | .setCallingPid(Binder.getCallingPid()) | 
|  | 2916 | .setCallingUid(Binder.getCallingUid()) | 
|  | 2917 | .setMethod("getAllCellInfo") | 
| Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2918 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2919 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 2920 | .build()); | 
|  | 2921 | switch (locationResult) { | 
|  | 2922 | case DENIED_HARD: | 
|  | 2923 | throw new SecurityException("Not allowed to access cell info"); | 
|  | 2924 | case DENIED_SOFT: | 
|  | 2925 | return new ArrayList<>(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2926 | } | 
|  | 2927 |  | 
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2928 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2929 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { | 
|  | 2930 | return getCachedCellInfo(); | 
|  | 2931 | } | 
|  | 2932 |  | 
| Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2933 | if (DBG_LOC) log("getAllCellInfo: is active user"); | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2934 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2935 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2936 | try { | 
|  | 2937 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); | 
|  | 2938 | for (Phone phone : PhoneFactory.getPhones()) { | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2939 | final List<CellInfo> info = (List<CellInfo>) sendRequest( | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2940 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2941 | if (info != null) cellInfos.addAll(info); | 
|  | 2942 | } | 
|  | 2943 | return cellInfos; | 
|  | 2944 | } finally { | 
|  | 2945 | Binder.restoreCallingIdentity(identity); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2946 | } | 
|  | 2947 | } | 
|  | 2948 |  | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2949 | @Override | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2950 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, | 
|  | 2951 | String callingFeatureId) { | 
|  | 2952 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, | 
|  | 2953 | getWorkSource(Binder.getCallingUid())); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2954 | } | 
|  | 2955 |  | 
|  | 2956 | @Override | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2957 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, | 
|  | 2958 | String callingPackage, String callingFeatureId, WorkSource workSource) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2959 | enforceModifyPermission(); | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2960 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2961 | } | 
|  | 2962 |  | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2963 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, | 
|  | 2964 | String callingPackage, String callingFeatureId, WorkSource workSource) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2965 | mApp.getSystemService(AppOpsManager.class) | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2966 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2967 |  | 
|  | 2968 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 2969 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 2970 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 2971 | .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2972 | .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2973 | .setCallingPid(Binder.getCallingPid()) | 
|  | 2974 | .setCallingUid(Binder.getCallingUid()) | 
|  | 2975 | .setMethod("requestCellInfoUpdate") | 
| Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2976 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) | 
|  | 2977 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2978 | .build()); | 
|  | 2979 | switch (locationResult) { | 
|  | 2980 | case DENIED_HARD: | 
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2981 | if (TelephonyPermissions | 
|  | 2982 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { | 
| Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2983 | // Safetynet logging for b/154934934 | 
|  | 2984 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); | 
|  | 2985 | } | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2986 | throw new SecurityException("Not allowed to access cell info"); | 
|  | 2987 | case DENIED_SOFT: | 
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2988 | if (TelephonyPermissions | 
|  | 2989 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { | 
| Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2990 | // Safetynet logging for b/154934934 | 
|  | 2991 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); | 
|  | 2992 | } | 
| Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2993 | try { | 
|  | 2994 | cb.onCellInfo(new ArrayList<CellInfo>()); | 
|  | 2995 | } catch (RemoteException re) { | 
|  | 2996 | // Drop without consequences | 
|  | 2997 | } | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2998 | return; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2999 | } | 
|  | 3000 |  | 
| Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3001 |  | 
|  | 3002 | final Phone phone = getPhoneFromSubId(subId); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3003 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); | 
|  | 3004 |  | 
|  | 3005 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); | 
|  | 3006 | } | 
|  | 3007 |  | 
|  | 3008 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3009 | public void setCellInfoListRate(int rateInMillis) { | 
| Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3010 | enforceModifyPermission(); | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3011 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3012 |  | 
|  | 3013 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3014 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3015 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3016 | } finally { | 
|  | 3017 | Binder.restoreCallingIdentity(identity); | 
|  | 3018 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3019 | } | 
|  | 3020 |  | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3021 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3022 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3023 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3024 | if (phone == null) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3025 | return null; | 
|  | 3026 | } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3027 | int subId = phone.getSubId(); | 
| Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3028 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3029 | callingPackage, callingFeatureId, "getImeiForSlot")) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3030 | return null; | 
|  | 3031 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3032 |  | 
|  | 3033 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3034 | try { | 
|  | 3035 | return phone.getImei(); | 
|  | 3036 | } finally { | 
|  | 3037 | Binder.restoreCallingIdentity(identity); | 
|  | 3038 | } | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3039 | } | 
|  | 3040 |  | 
|  | 3041 | @Override | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3042 | public String getTypeAllocationCodeForSlot(int slotIndex) { | 
|  | 3043 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3044 | String tac = null; | 
|  | 3045 | if (phone != null) { | 
|  | 3046 | String imei = phone.getImei(); | 
|  | 3047 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); | 
|  | 3048 | } | 
|  | 3049 | return tac; | 
|  | 3050 | } | 
|  | 3051 |  | 
|  | 3052 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3053 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3054 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3055 | if (phone == null) { | 
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3056 | return null; | 
|  | 3057 | } | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3058 |  | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3059 | int subId = phone.getSubId(); | 
| Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3060 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3061 | callingPackage, callingFeatureId, "getMeidForSlot")) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3062 | return null; | 
|  | 3063 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3064 |  | 
|  | 3065 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3066 | try { | 
|  | 3067 | return phone.getMeid(); | 
|  | 3068 | } finally { | 
|  | 3069 | Binder.restoreCallingIdentity(identity); | 
|  | 3070 | } | 
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3071 | } | 
|  | 3072 |  | 
|  | 3073 | @Override | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3074 | public String getManufacturerCodeForSlot(int slotIndex) { | 
|  | 3075 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3076 | String manufacturerCode = null; | 
|  | 3077 | if (phone != null) { | 
|  | 3078 | String meid = phone.getMeid(); | 
|  | 3079 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); | 
|  | 3080 | } | 
|  | 3081 | return manufacturerCode; | 
|  | 3082 | } | 
|  | 3083 |  | 
|  | 3084 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3085 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, | 
|  | 3086 | String callingFeatureId) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3087 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3088 | if (phone == null) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3089 | return null; | 
|  | 3090 | } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3091 | int subId = phone.getSubId(); | 
|  | 3092 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3093 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 3094 | "getDeviceSoftwareVersionForSlot")) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3095 | return null; | 
|  | 3096 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3097 |  | 
|  | 3098 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3099 | try { | 
|  | 3100 | return phone.getDeviceSvn(); | 
|  | 3101 | } finally { | 
|  | 3102 | Binder.restoreCallingIdentity(identity); | 
|  | 3103 | } | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3104 | } | 
|  | 3105 |  | 
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3106 | @Override | 
|  | 3107 | public int getSubscriptionCarrierId(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3108 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3109 | try { | 
|  | 3110 | final Phone phone = getPhone(subId); | 
|  | 3111 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); | 
|  | 3112 | } finally { | 
|  | 3113 | Binder.restoreCallingIdentity(identity); | 
|  | 3114 | } | 
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3115 | } | 
|  | 3116 |  | 
|  | 3117 | @Override | 
|  | 3118 | public String getSubscriptionCarrierName(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3119 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3120 | try { | 
|  | 3121 | final Phone phone = getPhone(subId); | 
|  | 3122 | return phone == null ? null : phone.getCarrierName(); | 
|  | 3123 | } finally { | 
|  | 3124 | Binder.restoreCallingIdentity(identity); | 
|  | 3125 | } | 
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3126 | } | 
|  | 3127 |  | 
| calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3128 | @Override | 
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3129 | public int getSubscriptionSpecificCarrierId(int subId) { | 
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3130 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3131 | try { | 
|  | 3132 | final Phone phone = getPhone(subId); | 
|  | 3133 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID | 
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3134 | : phone.getSpecificCarrierId(); | 
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3135 | } finally { | 
|  | 3136 | Binder.restoreCallingIdentity(identity); | 
|  | 3137 | } | 
|  | 3138 | } | 
|  | 3139 |  | 
|  | 3140 | @Override | 
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3141 | public String getSubscriptionSpecificCarrierName(int subId) { | 
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3142 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3143 | try { | 
|  | 3144 | final Phone phone = getPhone(subId); | 
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3145 | return phone == null ? null : phone.getSpecificCarrierName(); | 
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3146 | } finally { | 
|  | 3147 | Binder.restoreCallingIdentity(identity); | 
|  | 3148 | } | 
|  | 3149 | } | 
|  | 3150 |  | 
| chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3151 | @Override | 
| chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3152 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { | 
|  | 3153 | if (!isSubscriptionMccMnc) { | 
|  | 3154 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); | 
|  | 3155 | } | 
| chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3156 | final Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3157 | if (phone == null) { | 
|  | 3158 | return TelephonyManager.UNKNOWN_CARRIER_ID; | 
|  | 3159 | } | 
|  | 3160 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3161 | try { | 
|  | 3162 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); | 
|  | 3163 | } finally { | 
|  | 3164 | Binder.restoreCallingIdentity(identity); | 
|  | 3165 | } | 
|  | 3166 | } | 
|  | 3167 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3168 | // | 
|  | 3169 | // Internal helper methods. | 
|  | 3170 | // | 
|  | 3171 |  | 
| Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3172 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3173 | * Make sure the caller has the MODIFY_PHONE_STATE permission. | 
|  | 3174 | * | 
|  | 3175 | * @throws SecurityException if the caller does not have the required permission | 
|  | 3176 | */ | 
|  | 3177 | private void enforceModifyPermission() { | 
|  | 3178 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); | 
|  | 3179 | } | 
|  | 3180 |  | 
| Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3181 | /** | 
|  | 3182 | * Make sure the caller is system. | 
|  | 3183 | * | 
|  | 3184 | * @throws SecurityException if the caller is not system. | 
|  | 3185 | */ | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3186 | private static void enforceSystemCaller() { | 
| Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3187 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { | 
|  | 3188 | throw new SecurityException("Caller must be system"); | 
|  | 3189 | } | 
|  | 3190 | } | 
|  | 3191 |  | 
| Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3192 | private void enforceActiveEmergencySessionPermission() { | 
|  | 3193 | mApp.enforceCallingOrSelfPermission( | 
|  | 3194 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); | 
|  | 3195 | } | 
|  | 3196 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3197 | /** | 
|  | 3198 | * Make sure the caller has the CALL_PHONE permission. | 
|  | 3199 | * | 
|  | 3200 | * @throws SecurityException if the caller does not have the required permission | 
|  | 3201 | */ | 
|  | 3202 | private void enforceCallPermission() { | 
|  | 3203 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); | 
|  | 3204 | } | 
|  | 3205 |  | 
| paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3206 | private void enforceSettingsPermission() { | 
|  | 3207 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3208 | } | 
|  | 3209 |  | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3210 | private void enforceRebootPermission() { | 
|  | 3211 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); | 
|  | 3212 | } | 
|  | 3213 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3214 | private String createTelUrl(String number) { | 
|  | 3215 | if (TextUtils.isEmpty(number)) { | 
|  | 3216 | return null; | 
|  | 3217 | } | 
|  | 3218 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3219 | return "tel:" + number; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3220 | } | 
|  | 3221 |  | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3222 | private static void log(String msg) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3223 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); | 
|  | 3224 | } | 
|  | 3225 |  | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3226 | private static void logv(String msg) { | 
|  | 3227 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); | 
|  | 3228 | } | 
|  | 3229 |  | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3230 | private static void loge(String msg) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3231 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); | 
|  | 3232 | } | 
|  | 3233 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3234 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3235 | public int getActivePhoneType() { | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3236 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3237 | } | 
|  | 3238 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3239 | @Override | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3240 | public int getActivePhoneTypeForSlot(int slotIndex) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3241 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3242 | try { | 
|  | 3243 | final Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3244 | if (phone == null) { | 
|  | 3245 | return PhoneConstants.PHONE_TYPE_NONE; | 
|  | 3246 | } else { | 
|  | 3247 | return phone.getPhoneType(); | 
|  | 3248 | } | 
|  | 3249 | } finally { | 
|  | 3250 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3251 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3252 | } | 
|  | 3253 |  | 
|  | 3254 | /** | 
|  | 3255 | * Returns the CDMA ERI icon index to display | 
|  | 3256 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3257 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3258 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { | 
|  | 3259 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, | 
|  | 3260 | callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3261 | } | 
|  | 3262 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3263 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3264 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, | 
|  | 3265 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3266 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3267 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 3268 | "getCdmaEriIconIndexForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3269 | return -1; | 
|  | 3270 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3271 |  | 
|  | 3272 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3273 | try { | 
|  | 3274 | final Phone phone = getPhone(subId); | 
|  | 3275 | if (phone != null) { | 
|  | 3276 | return phone.getCdmaEriIconIndex(); | 
|  | 3277 | } else { | 
|  | 3278 | return -1; | 
|  | 3279 | } | 
|  | 3280 | } finally { | 
|  | 3281 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3282 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3283 | } | 
|  | 3284 |  | 
|  | 3285 | /** | 
|  | 3286 | * Returns the CDMA ERI icon mode, | 
|  | 3287 | * 0 - ON | 
|  | 3288 | * 1 - FLASHING | 
|  | 3289 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3290 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3291 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { | 
|  | 3292 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, | 
|  | 3293 | callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3294 | } | 
|  | 3295 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3296 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3297 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, | 
|  | 3298 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3299 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3300 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 3301 | "getCdmaEriIconModeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3302 | return -1; | 
|  | 3303 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3304 |  | 
|  | 3305 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3306 | try { | 
|  | 3307 | final Phone phone = getPhone(subId); | 
|  | 3308 | if (phone != null) { | 
|  | 3309 | return phone.getCdmaEriIconMode(); | 
|  | 3310 | } else { | 
|  | 3311 | return -1; | 
|  | 3312 | } | 
|  | 3313 | } finally { | 
|  | 3314 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3315 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3316 | } | 
|  | 3317 |  | 
|  | 3318 | /** | 
|  | 3319 | * Returns the CDMA ERI text, | 
|  | 3320 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3321 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3322 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { | 
|  | 3323 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, | 
|  | 3324 | callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3325 | } | 
|  | 3326 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3327 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3328 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, | 
|  | 3329 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3330 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3331 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 3332 | "getCdmaEriIconTextForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3333 | return null; | 
|  | 3334 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3335 |  | 
|  | 3336 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3337 | try { | 
|  | 3338 | final Phone phone = getPhone(subId); | 
|  | 3339 | if (phone != null) { | 
|  | 3340 | return phone.getCdmaEriText(); | 
|  | 3341 | } else { | 
|  | 3342 | return null; | 
|  | 3343 | } | 
|  | 3344 | } finally { | 
|  | 3345 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3346 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3347 | } | 
|  | 3348 |  | 
|  | 3349 | /** | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3350 | * Returns the CDMA MDN. | 
|  | 3351 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3352 | @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3353 | public String getCdmaMdn(int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3354 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3355 | mApp, subId, "getCdmaMdn"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3356 |  | 
|  | 3357 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3358 | try { | 
|  | 3359 | final Phone phone = getPhone(subId); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3360 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3361 | return phone.getLine1Number(); | 
|  | 3362 | } else { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3363 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3364 | return null; | 
|  | 3365 | } | 
|  | 3366 | } finally { | 
|  | 3367 | Binder.restoreCallingIdentity(identity); | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3368 | } | 
|  | 3369 | } | 
|  | 3370 |  | 
|  | 3371 | /** | 
|  | 3372 | * Returns the CDMA MIN. | 
|  | 3373 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3374 | @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3375 | public String getCdmaMin(int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3376 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3377 | mApp, subId, "getCdmaMin"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3378 |  | 
|  | 3379 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3380 | try { | 
|  | 3381 | final Phone phone = getPhone(subId); | 
|  | 3382 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { | 
|  | 3383 | return phone.getCdmaMin(); | 
|  | 3384 | } else { | 
|  | 3385 | return null; | 
|  | 3386 | } | 
|  | 3387 | } finally { | 
|  | 3388 | Binder.restoreCallingIdentity(identity); | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3389 | } | 
|  | 3390 | } | 
|  | 3391 |  | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3392 | @Override | 
|  | 3393 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, | 
|  | 3394 | INumberVerificationCallback callback, String callingPackage) { | 
|  | 3395 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) | 
|  | 3396 | != PERMISSION_GRANTED) { | 
|  | 3397 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); | 
|  | 3398 | } | 
|  | 3399 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 3400 |  | 
|  | 3401 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); | 
|  | 3402 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { | 
| Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3403 | throw new SecurityException("Calling package must be configured in the device config: " | 
|  | 3404 | + "calling package: " + callingPackage | 
|  | 3405 | + ", configured package: " + authorizedPackage); | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3406 | } | 
|  | 3407 |  | 
|  | 3408 | if (range == null) { | 
|  | 3409 | throw new NullPointerException("Range must be non-null"); | 
|  | 3410 | } | 
|  | 3411 |  | 
|  | 3412 | timeoutMillis = Math.min(timeoutMillis, | 
| Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3413 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3414 |  | 
|  | 3415 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); | 
|  | 3416 | } | 
|  | 3417 |  | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3418 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3419 | * Returns true if CDMA provisioning needs to run. | 
|  | 3420 | */ | 
|  | 3421 | public boolean needsOtaServiceProvisioning() { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3422 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3423 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3424 | return getDefaultPhone().needsOtaServiceProvisioning(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3425 | } finally { | 
|  | 3426 | Binder.restoreCallingIdentity(identity); | 
|  | 3427 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3428 | } | 
|  | 3429 |  | 
|  | 3430 | /** | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3431 | * Sets the voice mail number of a given subId. | 
|  | 3432 | */ | 
|  | 3433 | @Override | 
|  | 3434 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3435 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( | 
|  | 3436 | mApp, subId, "setVoiceMailNumber"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3437 |  | 
|  | 3438 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3439 | try { | 
|  | 3440 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, | 
|  | 3441 | new Pair<String, String>(alphaTag, number), new Integer(subId)); | 
|  | 3442 | return success; | 
|  | 3443 | } finally { | 
|  | 3444 | Binder.restoreCallingIdentity(identity); | 
|  | 3445 | } | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3446 | } | 
|  | 3447 |  | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3448 | @Override | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3449 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { | 
|  | 3450 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3451 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); | 
|  | 3452 | String systemDialer = tm.getSystemDialerPackage(); | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3453 | if (!TextUtils.equals(callingPackage, systemDialer)) { | 
|  | 3454 | throw new SecurityException("caller must be system dialer"); | 
|  | 3455 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3456 |  | 
|  | 3457 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3458 | try { | 
|  | 3459 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); | 
|  | 3460 | if (phoneAccountHandle == null) { | 
|  | 3461 | return null; | 
|  | 3462 | } | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3463 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3464 | } finally { | 
|  | 3465 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3466 | } | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3467 | } | 
|  | 3468 |  | 
|  | 3469 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3470 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, | 
|  | 3471 | int subId) { | 
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3472 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3473 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3474 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 3475 | "getVisualVoicemailPackageName")) { | 
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3476 | return null; | 
|  | 3477 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3478 |  | 
| Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3479 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3480 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3481 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); | 
| Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3482 | } finally { | 
|  | 3483 | Binder.restoreCallingIdentity(identity); | 
|  | 3484 | } | 
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3485 | } | 
|  | 3486 |  | 
|  | 3487 | @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3488 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, | 
|  | 3489 | VisualVoicemailSmsFilterSettings settings) { | 
|  | 3490 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3491 |  | 
|  | 3492 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3493 | try { | 
|  | 3494 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3495 | mApp, callingPackage, subId, settings); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3496 | } finally { | 
|  | 3497 | Binder.restoreCallingIdentity(identity); | 
|  | 3498 | } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3499 | } | 
|  | 3500 |  | 
|  | 3501 | @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3502 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { | 
|  | 3503 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3504 |  | 
|  | 3505 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3506 | try { | 
|  | 3507 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3508 | mApp, callingPackage, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3509 | } finally { | 
|  | 3510 | Binder.restoreCallingIdentity(identity); | 
|  | 3511 | } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3512 | } | 
|  | 3513 |  | 
|  | 3514 | @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3515 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( | 
|  | 3516 | String callingPackage, int subId) { | 
|  | 3517 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3518 |  | 
|  | 3519 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3520 | try { | 
|  | 3521 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3522 | mApp, callingPackage, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3523 | } finally { | 
|  | 3524 | Binder.restoreCallingIdentity(identity); | 
|  | 3525 | } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3526 | } | 
|  | 3527 |  | 
|  | 3528 | @Override | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3529 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3530 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3531 |  | 
|  | 3532 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3533 | try { | 
|  | 3534 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3535 | mApp, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3536 | } finally { | 
|  | 3537 | Binder.restoreCallingIdentity(identity); | 
|  | 3538 | } | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3539 | } | 
|  | 3540 |  | 
|  | 3541 | @Override | 
| Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3542 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, | 
|  | 3543 | String callingAttributionTag, int subId, String number, int port, String text, | 
|  | 3544 | PendingIntent sentIntent) { | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3545 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3546 | enforceVisualVoicemailPackage(callingPackage, subId); | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3547 | enforceSendSmsPermission(); | 
| Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3548 | SmsController smsController = PhoneFactory.getSmsController(); | 
| Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3549 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, | 
|  | 3550 | subId, number, port, text, sentIntent); | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3551 | } | 
| Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3552 |  | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3553 | /** | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3554 | * Sets the voice activation state of a given subId. | 
|  | 3555 | */ | 
|  | 3556 | @Override | 
|  | 3557 | public void setVoiceActivationState(int subId, int activationState) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3558 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3559 | mApp, subId, "setVoiceActivationState"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3560 |  | 
|  | 3561 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3562 | try { | 
|  | 3563 | final Phone phone = getPhone(subId); | 
|  | 3564 | if (phone != null) { | 
|  | 3565 | phone.setVoiceActivationState(activationState); | 
|  | 3566 | } else { | 
|  | 3567 | loge("setVoiceActivationState fails with invalid subId: " + subId); | 
|  | 3568 | } | 
|  | 3569 | } finally { | 
|  | 3570 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3571 | } | 
|  | 3572 | } | 
|  | 3573 |  | 
|  | 3574 | /** | 
|  | 3575 | * Sets the data activation state of a given subId. | 
|  | 3576 | */ | 
|  | 3577 | @Override | 
|  | 3578 | public void setDataActivationState(int subId, int activationState) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3579 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3580 | mApp, subId, "setDataActivationState"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3581 |  | 
|  | 3582 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3583 | try { | 
|  | 3584 | final Phone phone = getPhone(subId); | 
|  | 3585 | if (phone != null) { | 
|  | 3586 | phone.setDataActivationState(activationState); | 
|  | 3587 | } else { | 
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3588 | loge("setDataActivationState fails with invalid subId: " + subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3589 | } | 
|  | 3590 | } finally { | 
|  | 3591 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3592 | } | 
|  | 3593 | } | 
|  | 3594 |  | 
|  | 3595 | /** | 
|  | 3596 | * Returns the voice activation state of a given subId. | 
|  | 3597 | */ | 
|  | 3598 | @Override | 
|  | 3599 | public int getVoiceActivationState(int subId, String callingPackage) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3600 | enforceReadPrivilegedPermission("getVoiceActivationState"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3601 |  | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3602 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3603 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3604 | try { | 
|  | 3605 | if (phone != null) { | 
|  | 3606 | return phone.getVoiceActivationState(); | 
|  | 3607 | } else { | 
|  | 3608 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; | 
|  | 3609 | } | 
|  | 3610 | } finally { | 
|  | 3611 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3612 | } | 
|  | 3613 | } | 
|  | 3614 |  | 
|  | 3615 | /** | 
|  | 3616 | * Returns the data activation state of a given subId. | 
|  | 3617 | */ | 
|  | 3618 | @Override | 
|  | 3619 | public int getDataActivationState(int subId, String callingPackage) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3620 | enforceReadPrivilegedPermission("getDataActivationState"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3621 |  | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3622 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3623 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3624 | try { | 
|  | 3625 | if (phone != null) { | 
|  | 3626 | return phone.getDataActivationState(); | 
|  | 3627 | } else { | 
|  | 3628 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; | 
|  | 3629 | } | 
|  | 3630 | } finally { | 
|  | 3631 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3632 | } | 
|  | 3633 | } | 
|  | 3634 |  | 
|  | 3635 | /** | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3636 | * Returns the unread count of voicemails for a subId | 
|  | 3637 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3638 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3639 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, | 
|  | 3640 | String callingFeatureId) { | 
| Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3641 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3642 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 3643 | "getVoiceMessageCountForSubscriber")) { | 
| Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3644 | return 0; | 
|  | 3645 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3646 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3647 | try { | 
|  | 3648 | final Phone phone = getPhone(subId); | 
|  | 3649 | if (phone != null) { | 
|  | 3650 | return phone.getVoiceMessageCount(); | 
|  | 3651 | } else { | 
|  | 3652 | return 0; | 
|  | 3653 | } | 
|  | 3654 | } finally { | 
|  | 3655 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3656 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3657 | } | 
|  | 3658 |  | 
|  | 3659 | /** | 
| pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3660 | * returns true, if the device is in a state where both voice and data | 
|  | 3661 | * are supported simultaneously. This can change based on location or network condition. | 
|  | 3662 | */ | 
|  | 3663 | @Override | 
|  | 3664 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3665 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3666 | try { | 
|  | 3667 | final Phone phone = getPhone(subId); | 
|  | 3668 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); | 
|  | 3669 | } finally { | 
|  | 3670 | Binder.restoreCallingIdentity(identity); | 
|  | 3671 | } | 
| pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3672 | } | 
|  | 3673 |  | 
|  | 3674 | /** | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3675 | * Send the dialer code if called from the current default dialer or the caller has | 
|  | 3676 | * carrier privilege. | 
|  | 3677 | * @param inputCode The dialer code to send | 
|  | 3678 | */ | 
|  | 3679 | @Override | 
|  | 3680 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3681 | final Phone defaultPhone = getDefaultPhone(); | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3682 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3683 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); | 
|  | 3684 | String defaultDialer = tm.getDefaultDialerPackage(); | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3685 | if (!TextUtils.equals(callingPackage, defaultDialer)) { | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3686 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3687 | getDefaultSubscription(), "sendDialerSpecialCode"); | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3688 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3689 |  | 
|  | 3690 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3691 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3692 | defaultPhone.sendDialerSpecialCode(inputCode); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3693 | } finally { | 
|  | 3694 | Binder.restoreCallingIdentity(identity); | 
|  | 3695 | } | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3696 | } | 
|  | 3697 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3698 | @Override | 
|  | 3699 | public int getNetworkSelectionMode(int subId) { | 
| shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3700 | TelephonyPermissions | 
|  | 3701 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 3702 | mApp, subId, "getNetworkSelectionMode"); | 
|  | 3703 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3704 | try { | 
|  | 3705 | if (!isActiveSubscription(subId)) { | 
|  | 3706 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; | 
|  | 3707 | } | 
|  | 3708 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); | 
|  | 3709 | } finally { | 
|  | 3710 | Binder.restoreCallingIdentity(identity); | 
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3711 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3712 | } | 
|  | 3713 |  | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3714 | @Override | 
| Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3715 | public boolean isInEmergencySmsMode() { | 
|  | 3716 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); | 
|  | 3717 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3718 | try { | 
|  | 3719 | for (Phone phone : PhoneFactory.getPhones()) { | 
|  | 3720 | if (phone.isInEmergencySmsMode()) { | 
|  | 3721 | return true; | 
|  | 3722 | } | 
|  | 3723 | } | 
|  | 3724 | } finally { | 
|  | 3725 | Binder.restoreCallingIdentity(identity); | 
|  | 3726 | } | 
|  | 3727 | return false; | 
|  | 3728 | } | 
|  | 3729 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3730 | /** | 
|  | 3731 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 3732 | * @param subId The subscription to use to check the configuration. | 
|  | 3733 | * @param c The callback that will be used to send the result. | 
|  | 3734 | */ | 
| Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3735 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3736 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) | 
|  | 3737 | throws RemoteException { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3738 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 3739 | mApp, subId, "registerImsRegistrationCallback"); | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3740 |  | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3741 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 3742 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 3743 | "IMS not available on device."); | 
|  | 3744 | } | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3745 | final long token = Binder.clearCallingIdentity(); | 
|  | 3746 | try { | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3747 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3748 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3749 | .addRegistrationCallbackForSubscription(c, subId); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3750 | } catch (ImsException e) { | 
|  | 3751 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3752 | } finally { | 
|  | 3753 | Binder.restoreCallingIdentity(token); | 
|  | 3754 | } | 
|  | 3755 | } | 
|  | 3756 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3757 | /** | 
|  | 3758 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 3759 | * @param subId The subscription to use to check the configuration. | 
|  | 3760 | * @param c The callback that will be used to send the result. | 
|  | 3761 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3762 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3763 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3764 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 3765 | mApp, subId, "unregisterImsRegistrationCallback"); | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3766 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 3767 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 3768 | } | 
| Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3769 | final long token = Binder.clearCallingIdentity(); | 
|  | 3770 | try { | 
| Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3771 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. | 
| Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3772 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
|  | 3773 | .removeRegistrationCallbackForSubscription(c, subId); | 
|  | 3774 | } catch (ImsException e) { | 
|  | 3775 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId | 
|  | 3776 | + "is inactive, ignoring unregister."); | 
|  | 3777 | // If the subscription is no longer active, just return, since the callback | 
|  | 3778 | // will already have been removed internally. | 
|  | 3779 | } finally { | 
|  | 3780 | Binder.restoreCallingIdentity(token); | 
|  | 3781 | } | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3782 | } | 
|  | 3783 |  | 
| Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3784 | /** | 
|  | 3785 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. | 
|  | 3786 | */ | 
|  | 3787 | @Override | 
|  | 3788 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { | 
|  | 3789 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); | 
|  | 3790 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 3791 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 3792 | "IMS not available on device."); | 
|  | 3793 | } | 
|  | 3794 | final long token = Binder.clearCallingIdentity(); | 
|  | 3795 | try { | 
|  | 3796 | Phone phone = getPhone(subId); | 
|  | 3797 | if (phone == null) { | 
|  | 3798 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" | 
|  | 3799 | + subId + "'"); | 
|  | 3800 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
|  | 3801 | } | 
|  | 3802 | phone.getImsRegistrationState(regState -> { | 
|  | 3803 | try { | 
|  | 3804 | consumer.accept((regState == null) | 
|  | 3805 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); | 
|  | 3806 | } catch (RemoteException e) { | 
|  | 3807 | // Ignore if the remote process is no longer available to call back. | 
|  | 3808 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); | 
|  | 3809 | } | 
|  | 3810 | }); | 
|  | 3811 | } finally { | 
|  | 3812 | Binder.restoreCallingIdentity(token); | 
|  | 3813 | } | 
|  | 3814 | } | 
|  | 3815 |  | 
|  | 3816 | /** | 
|  | 3817 | * Get the transport type for the IMS service registration state. | 
|  | 3818 | */ | 
|  | 3819 | @Override | 
|  | 3820 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3821 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 3822 | mApp, subId, "getImsMmTelRegistrationTransportType"); | 
| Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3823 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 3824 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 3825 | "IMS not available on device."); | 
|  | 3826 | } | 
|  | 3827 | final long token = Binder.clearCallingIdentity(); | 
|  | 3828 | try { | 
|  | 3829 | Phone phone = getPhone(subId); | 
|  | 3830 | if (phone == null) { | 
|  | 3831 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" | 
|  | 3832 | + subId + "'"); | 
|  | 3833 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
|  | 3834 | } | 
|  | 3835 | phone.getImsRegistrationTech(regTech -> { | 
|  | 3836 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager | 
|  | 3837 | int regTechConverted = (regTech == null) | 
|  | 3838 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; | 
|  | 3839 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( | 
|  | 3840 | regTechConverted); | 
|  | 3841 | try { | 
|  | 3842 | consumer.accept(regTechConverted); | 
|  | 3843 | } catch (RemoteException e) { | 
|  | 3844 | // Ignore if the remote process is no longer available to call back. | 
|  | 3845 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); | 
|  | 3846 | } | 
|  | 3847 | }); | 
|  | 3848 | } finally { | 
|  | 3849 | Binder.restoreCallingIdentity(token); | 
|  | 3850 | } | 
|  | 3851 | } | 
|  | 3852 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3853 | /** | 
|  | 3854 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 3855 | * @param subId The subscription to use to check the configuration. | 
|  | 3856 | * @param c The callback that will be used to send the result. | 
|  | 3857 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3858 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3859 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) | 
|  | 3860 | throws RemoteException { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3861 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 3862 | mApp, subId, "registerMmTelCapabilityCallback"); | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3863 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 3864 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 3865 | "IMS not available on device."); | 
|  | 3866 | } | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3867 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 3868 | final long token = Binder.clearCallingIdentity(); | 
|  | 3869 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3870 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3871 | .addCapabilitiesCallbackForSubscription(c, subId); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3872 | } catch (ImsException e) { | 
|  | 3873 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3874 | } finally { | 
|  | 3875 | Binder.restoreCallingIdentity(token); | 
|  | 3876 | } | 
|  | 3877 | } | 
|  | 3878 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3879 | /** | 
|  | 3880 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 3881 | * @param subId The subscription to use to check the configuration. | 
|  | 3882 | * @param c The callback that will be used to send the result. | 
|  | 3883 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3884 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3885 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3886 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 3887 | mApp, subId, "unregisterMmTelCapabilityCallback"); | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3888 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 3889 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 3890 | } | 
| Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3891 |  | 
|  | 3892 | final long token = Binder.clearCallingIdentity(); | 
|  | 3893 | try { | 
| Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3894 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. | 
| Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3895 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3896 | .removeCapabilitiesCallbackForSubscription(c, subId); | 
| Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3897 | } catch (ImsException e) { | 
|  | 3898 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId | 
|  | 3899 | + "is inactive, ignoring unregister."); | 
|  | 3900 | // If the subscription is no longer active, just return, since the callback | 
|  | 3901 | // will already have been removed internally. | 
|  | 3902 | } finally { | 
|  | 3903 | Binder.restoreCallingIdentity(token); | 
|  | 3904 | } | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3905 | } | 
|  | 3906 |  | 
|  | 3907 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3908 | public boolean isCapable(int subId, int capability, int regTech) { | 
|  | 3909 | enforceReadPrivilegedPermission("isCapable"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3910 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 3911 | final long token = Binder.clearCallingIdentity(); | 
|  | 3912 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3913 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3914 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3915 | } catch (com.android.ims.ImsException e) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3916 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); | 
|  | 3917 | return false; | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3918 | } catch (ImsException e) { | 
| Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3919 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); | 
|  | 3920 | return false; | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3921 | } finally { | 
|  | 3922 | Binder.restoreCallingIdentity(token); | 
|  | 3923 | } | 
|  | 3924 | } | 
|  | 3925 |  | 
|  | 3926 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3927 | public boolean isAvailable(int subId, int capability, int regTech) { | 
|  | 3928 | enforceReadPrivilegedPermission("isAvailable"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3929 | final long token = Binder.clearCallingIdentity(); | 
|  | 3930 | try { | 
|  | 3931 | Phone phone = getPhone(subId); | 
|  | 3932 | if (phone == null) return false; | 
|  | 3933 | return phone.isImsCapabilityAvailable(capability, regTech); | 
| Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3934 | } catch (com.android.ims.ImsException e) { | 
|  | 3935 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); | 
|  | 3936 | return false; | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3937 | } finally { | 
|  | 3938 | Binder.restoreCallingIdentity(token); | 
|  | 3939 | } | 
|  | 3940 | } | 
|  | 3941 |  | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3942 | /** | 
|  | 3943 | * Determines if the MmTel feature capability is supported by the carrier configuration for this | 
|  | 3944 | * subscription. | 
|  | 3945 | * @param subId The subscription to use to check the configuration. | 
|  | 3946 | * @param callback The callback that will be used to send the result. | 
|  | 3947 | * @param capability The MmTelFeature capability that will be used to send the result. | 
|  | 3948 | * @param transportType The transport type of the MmTelFeature capability. | 
|  | 3949 | */ | 
|  | 3950 | @Override | 
|  | 3951 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, | 
|  | 3952 | int transportType) { | 
|  | 3953 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); | 
|  | 3954 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 3955 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 3956 | "IMS not available on device."); | 
|  | 3957 | } | 
|  | 3958 | final long token = Binder.clearCallingIdentity(); | 
|  | 3959 | try { | 
|  | 3960 | int slotId = getSlotIndex(subId); | 
|  | 3961 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 3962 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" | 
|  | 3963 | + subId + "'"); | 
|  | 3964 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
|  | 3965 | } | 
|  | 3966 | ImsManager.getInstance(mApp, slotId).isSupported(capability, | 
|  | 3967 | transportType, aBoolean -> { | 
|  | 3968 | try { | 
|  | 3969 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); | 
|  | 3970 | } catch (RemoteException e) { | 
|  | 3971 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " | 
|  | 3972 | + "running. Ignore"); | 
|  | 3973 | } | 
|  | 3974 | }); | 
|  | 3975 | } finally { | 
|  | 3976 | Binder.restoreCallingIdentity(token); | 
|  | 3977 | } | 
|  | 3978 | } | 
|  | 3979 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3980 | /** | 
|  | 3981 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 3982 | * @param subId The subscription to use to check the configuration. | 
|  | 3983 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3984 | @Override | 
|  | 3985 | public boolean isAdvancedCallingSettingEnabled(int subId) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3986 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 3987 | mApp, subId, "isAdvancedCallingSettingEnabled"); | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3988 |  | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3989 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 3990 | final long token = Binder.clearCallingIdentity(); | 
|  | 3991 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3992 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3993 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3994 | } catch (ImsException e) { | 
|  | 3995 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3996 | } finally { | 
|  | 3997 | Binder.restoreCallingIdentity(token); | 
|  | 3998 | } | 
|  | 3999 | } | 
|  | 4000 |  | 
|  | 4001 | @Override | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4002 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4004 | "setAdvancedCallingSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4005 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4006 | try { | 
|  | 4007 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4008 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4009 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4010 | } catch (ImsException e) { | 
|  | 4011 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4012 | } finally { | 
|  | 4013 | Binder.restoreCallingIdentity(identity); | 
|  | 4014 | } | 
|  | 4015 | } | 
|  | 4016 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4017 | /** | 
|  | 4018 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 4019 | * @param subId The subscription to use to check the configuration. | 
|  | 4020 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4021 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4022 | public boolean isVtSettingEnabled(int subId) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4023 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 4024 | mApp, subId, "isVtSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4025 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4026 | try { | 
|  | 4027 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4028 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); | 
|  | 4029 | } catch (ImsException e) { | 
|  | 4030 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4031 | } finally { | 
|  | 4032 | Binder.restoreCallingIdentity(identity); | 
|  | 4033 | } | 
|  | 4034 | } | 
|  | 4035 |  | 
|  | 4036 | @Override | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4037 | public void setVtSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4038 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4039 | "setVtSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4040 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4041 | try { | 
|  | 4042 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4043 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4044 | } catch (ImsException e) { | 
|  | 4045 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4046 | } finally { | 
|  | 4047 | Binder.restoreCallingIdentity(identity); | 
|  | 4048 | } | 
|  | 4049 | } | 
|  | 4050 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4051 | /** | 
|  | 4052 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 4053 | * @param subId The subscription to use to check the configuration. | 
|  | 4054 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4055 | @Override | 
|  | 4056 | public boolean isVoWiFiSettingEnabled(int subId) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4057 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 4058 | mApp, subId, "isVoWiFiSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4059 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4060 | try { | 
|  | 4061 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4062 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4063 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4064 | } catch (ImsException e) { | 
|  | 4065 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4066 | } finally { | 
|  | 4067 | Binder.restoreCallingIdentity(identity); | 
|  | 4068 | } | 
|  | 4069 | } | 
|  | 4070 |  | 
|  | 4071 | @Override | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4072 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4073 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4074 | "setVoWiFiSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4075 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4076 | try { | 
|  | 4077 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4078 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4079 | } catch (ImsException e) { | 
|  | 4080 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4081 | } finally { | 
|  | 4082 | Binder.restoreCallingIdentity(identity); | 
|  | 4083 | } | 
|  | 4084 | } | 
|  | 4085 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4086 | /** | 
| Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4087 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not | 
|  | 4088 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 4089 | * @param subId The subscription to use to check the configuration. | 
|  | 4090 | */ | 
|  | 4091 | @Override | 
|  | 4092 | public boolean isCrossSimCallingEnabledByUser(int subId) { | 
|  | 4093 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 4094 | mApp, subId, "isCrossSimCallingEnabledByUser"); | 
|  | 4095 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4096 | try { | 
|  | 4097 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 4098 | return ImsManager.getInstance(mApp, | 
|  | 4099 | getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser(); | 
|  | 4100 | } catch (ImsException e) { | 
|  | 4101 | throw new ServiceSpecificException(e.getCode()); | 
|  | 4102 | } finally { | 
|  | 4103 | Binder.restoreCallingIdentity(identity); | 
|  | 4104 | } | 
|  | 4105 | } | 
|  | 4106 |  | 
|  | 4107 | /** | 
|  | 4108 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. | 
|  | 4109 | * Requires MODIFY_PHONE_STATE permission. | 
|  | 4110 | * @param subId The subscription to use to check the configuration. | 
|  | 4111 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, | 
|  | 4112 | *                 false otherwise | 
|  | 4113 | */ | 
|  | 4114 | @Override | 
|  | 4115 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { | 
|  | 4116 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4117 | "setCrossSimCallingEnabled"); | 
|  | 4118 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4119 | try { | 
|  | 4120 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 4121 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
|  | 4122 | .setCrossSimCallingEnabled(isEnabled); | 
|  | 4123 | } catch (ImsException e) { | 
|  | 4124 | throw new ServiceSpecificException(e.getCode()); | 
|  | 4125 | } finally { | 
|  | 4126 | Binder.restoreCallingIdentity(identity); | 
|  | 4127 | } | 
|  | 4128 | } | 
|  | 4129 |  | 
|  | 4130 | /** | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4131 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 4132 | * @param subId The subscription to use to check the configuration. | 
|  | 4133 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4134 | @Override | 
|  | 4135 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4136 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 4137 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4138 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4139 | try { | 
|  | 4140 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4141 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4142 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4143 | } catch (ImsException e) { | 
|  | 4144 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4145 | } finally { | 
|  | 4146 | Binder.restoreCallingIdentity(identity); | 
|  | 4147 | } | 
|  | 4148 | } | 
|  | 4149 |  | 
|  | 4150 | @Override | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4151 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4152 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4153 | "setVoWiFiRoamingSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4154 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4155 | try { | 
|  | 4156 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4157 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4158 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4159 | } catch (ImsException e) { | 
|  | 4160 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4161 | } finally { | 
|  | 4162 | Binder.restoreCallingIdentity(identity); | 
|  | 4163 | } | 
|  | 4164 | } | 
|  | 4165 |  | 
|  | 4166 | @Override | 
|  | 4167 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { | 
|  | 4168 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4169 | "setVoWiFiNonPersistent"); | 
|  | 4170 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4171 | try { | 
|  | 4172 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4173 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4174 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4175 | } catch (ImsException e) { | 
|  | 4176 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4177 | } finally { | 
|  | 4178 | Binder.restoreCallingIdentity(identity); | 
|  | 4179 | } | 
|  | 4180 | } | 
|  | 4181 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4182 | /** | 
|  | 4183 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 4184 | * @param subId The subscription to use to check the configuration. | 
|  | 4185 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4186 | @Override | 
|  | 4187 | public int getVoWiFiModeSetting(int subId) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4188 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 4189 | mApp, subId, "getVoWiFiModeSetting"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4190 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4191 | try { | 
|  | 4192 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4193 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4194 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4195 | } catch (ImsException e) { | 
|  | 4196 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4197 | } finally { | 
|  | 4198 | Binder.restoreCallingIdentity(identity); | 
|  | 4199 | } | 
|  | 4200 | } | 
|  | 4201 |  | 
|  | 4202 | @Override | 
|  | 4203 | public void setVoWiFiModeSetting(int subId, int mode) { | 
|  | 4204 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4205 | "setVoWiFiModeSetting"); | 
|  | 4206 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4207 | try { | 
|  | 4208 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4209 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4210 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4211 | } catch (ImsException e) { | 
|  | 4212 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4213 | } finally { | 
|  | 4214 | Binder.restoreCallingIdentity(identity); | 
|  | 4215 | } | 
|  | 4216 | } | 
|  | 4217 |  | 
|  | 4218 | @Override | 
|  | 4219 | public int getVoWiFiRoamingModeSetting(int subId) { | 
|  | 4220 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); | 
|  | 4221 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4222 | try { | 
|  | 4223 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4224 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4225 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4226 | } catch (ImsException e) { | 
|  | 4227 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4228 | } finally { | 
|  | 4229 | Binder.restoreCallingIdentity(identity); | 
|  | 4230 | } | 
|  | 4231 | } | 
|  | 4232 |  | 
|  | 4233 | @Override | 
|  | 4234 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { | 
|  | 4235 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4236 | "setVoWiFiRoamingModeSetting"); | 
|  | 4237 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4238 | try { | 
|  | 4239 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4240 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4241 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4242 | } catch (ImsException e) { | 
|  | 4243 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4244 | } finally { | 
|  | 4245 | Binder.restoreCallingIdentity(identity); | 
|  | 4246 | } | 
|  | 4247 | } | 
|  | 4248 |  | 
|  | 4249 | @Override | 
|  | 4250 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { | 
|  | 4251 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4252 | "setRttCapabilityEnabled"); | 
|  | 4253 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4254 | try { | 
|  | 4255 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4256 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); | 
|  | 4257 | } catch (ImsException e) { | 
|  | 4258 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4259 | } finally { | 
|  | 4260 | Binder.restoreCallingIdentity(identity); | 
|  | 4261 | } | 
|  | 4262 | } | 
|  | 4263 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4264 | /** | 
|  | 4265 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 4266 | * @param subId The subscription to use to check the configuration. | 
|  | 4267 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4268 | @Override | 
|  | 4269 | public boolean isTtyOverVolteEnabled(int subId) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4270 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 4271 | mApp, subId, "isTtyOverVolteEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4272 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4273 | try { | 
|  | 4274 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4275 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4276 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4277 | } catch (ImsException e) { | 
|  | 4278 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4279 | } finally { | 
|  | 4280 | Binder.restoreCallingIdentity(identity); | 
|  | 4281 | } | 
|  | 4282 | } | 
|  | 4283 |  | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4284 | @Override | 
|  | 4285 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { | 
|  | 4286 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); | 
|  | 4287 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4288 | try { | 
| Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4289 | if (!isImsAvailableOnDevice()) { | 
|  | 4290 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 4291 | "IMS not available on device."); | 
| Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4292 | } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4293 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4294 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4295 | .addProvisioningCallbackForSubscription(callback, subId); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4296 | } catch (ImsException e) { | 
|  | 4297 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4298 | } finally { | 
|  | 4299 | Binder.restoreCallingIdentity(identity); | 
|  | 4300 | } | 
|  | 4301 | } | 
|  | 4302 |  | 
|  | 4303 | @Override | 
|  | 4304 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { | 
|  | 4305 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); | 
|  | 4306 | final long identity = Binder.clearCallingIdentity(); | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4307 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 4308 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 4309 | } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4310 | try { | 
|  | 4311 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4312 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4313 | .removeProvisioningCallbackForSubscription(callback, subId); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4314 | } catch (ImsException e) { | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4315 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId | 
|  | 4316 | + "is inactive, ignoring unregister."); | 
|  | 4317 | // If the subscription is no longer active, just return, since the callback will already | 
|  | 4318 | // have been removed internally. | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4319 | } finally { | 
|  | 4320 | Binder.restoreCallingIdentity(identity); | 
|  | 4321 | } | 
|  | 4322 | } | 
|  | 4323 |  | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4324 |  | 
|  | 4325 | private void checkModifyPhoneStatePermission(int subId, String message) { | 
|  | 4326 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4327 | message); | 
|  | 4328 | } | 
|  | 4329 |  | 
|  | 4330 | private boolean isImsProvisioningRequired(int subId, int capability, | 
|  | 4331 | boolean isMmtelCapability) { | 
|  | 4332 | Phone phone = getPhone(subId); | 
|  | 4333 | if (phone == null) { | 
|  | 4334 | loge("phone instance null for subid " + subId); | 
|  | 4335 | return false; | 
|  | 4336 | } | 
|  | 4337 | if (isMmtelCapability) { | 
|  | 4338 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { | 
|  | 4339 | return false; | 
|  | 4340 | } | 
|  | 4341 | } else { | 
|  | 4342 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { | 
|  | 4343 | return false; | 
|  | 4344 | } | 
|  | 4345 | } | 
|  | 4346 | return true; | 
|  | 4347 | } | 
|  | 4348 |  | 
|  | 4349 | @Override | 
|  | 4350 | public void setRcsProvisioningStatusForCapability(int subId, int capability, | 
|  | 4351 | boolean isProvisioned) { | 
|  | 4352 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); | 
|  | 4353 |  | 
|  | 4354 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4355 | try { | 
|  | 4356 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 4357 | if (!isImsProvisioningRequired(subId, capability, false)) { | 
|  | 4358 | return; | 
|  | 4359 | } | 
|  | 4360 |  | 
|  | 4361 | // this capability requires provisioning, route to the correct API. | 
|  | 4362 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); | 
|  | 4363 | switch (capability) { | 
|  | 4364 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: | 
|  | 4365 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: | 
|  | 4366 | ims.setEabProvisioned(isProvisioned); | 
|  | 4367 | break; | 
|  | 4368 | default: { | 
|  | 4369 | throw new IllegalArgumentException("Tried to set provisioning for " | 
|  | 4370 | + "rcs capability '" + capability + "', which does not require " | 
|  | 4371 | + "provisioning."); | 
|  | 4372 | } | 
|  | 4373 | } | 
|  | 4374 | } finally { | 
|  | 4375 | Binder.restoreCallingIdentity(identity); | 
|  | 4376 | } | 
|  | 4377 |  | 
|  | 4378 | } | 
|  | 4379 |  | 
|  | 4380 |  | 
|  | 4381 | @Override | 
|  | 4382 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { | 
|  | 4383 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); | 
|  | 4384 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4385 | try { | 
|  | 4386 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 4387 | if (!isImsProvisioningRequired(subId, capability, false)) { | 
|  | 4388 | return true; | 
|  | 4389 | } | 
|  | 4390 |  | 
|  | 4391 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); | 
|  | 4392 | switch (capability) { | 
|  | 4393 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: | 
|  | 4394 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: | 
|  | 4395 | return ims.isEabProvisionedOnDevice(); | 
|  | 4396 |  | 
|  | 4397 | default: { | 
|  | 4398 | throw new IllegalArgumentException("Tried to get rcs provisioning for " | 
|  | 4399 | + "capability '" + capability + "', which does not require " | 
|  | 4400 | + "provisioning."); | 
|  | 4401 | } | 
|  | 4402 | } | 
|  | 4403 |  | 
|  | 4404 | } finally { | 
|  | 4405 | Binder.restoreCallingIdentity(identity); | 
|  | 4406 | } | 
|  | 4407 | } | 
|  | 4408 |  | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4409 | @Override | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4410 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, | 
|  | 4411 | boolean isProvisioned) { | 
|  | 4412 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
|  | 4413 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 4414 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
|  | 4415 | } | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4416 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4417 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4418 | try { | 
|  | 4419 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4420 | if (!isImsProvisioningRequired(subId, capability, true)) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4421 | return; | 
|  | 4422 | } | 
|  | 4423 |  | 
|  | 4424 | // this capability requires provisioning, route to the correct API. | 
|  | 4425 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); | 
|  | 4426 | switch (capability) { | 
|  | 4427 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { | 
|  | 4428 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 4429 | ims.setVolteProvisioned(isProvisioned); | 
|  | 4430 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { | 
|  | 4431 | ims.setWfcProvisioned(isProvisioned); | 
|  | 4432 | } | 
|  | 4433 | break; | 
|  | 4434 | } | 
|  | 4435 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { | 
|  | 4436 | // There is currently no difference in VT provisioning type. | 
|  | 4437 | ims.setVtProvisioned(isProvisioned); | 
|  | 4438 | break; | 
|  | 4439 | } | 
|  | 4440 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { | 
|  | 4441 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so | 
|  | 4442 | // change the capability of the feature instead if needed. | 
|  | 4443 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) | 
|  | 4444 | == isProvisioned) { | 
|  | 4445 | // No change in provisioning. | 
|  | 4446 | return; | 
|  | 4447 | } | 
|  | 4448 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); | 
|  | 4449 | try { | 
|  | 4450 | ims.changeMmTelCapability(capability, tech, isProvisioned); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4451 | } catch (com.android.ims.ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4452 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" | 
|  | 4453 | + ", Exception" + e.getMessage()); | 
|  | 4454 | } | 
|  | 4455 | break; | 
|  | 4456 | } | 
|  | 4457 | default: { | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4458 | throw new IllegalArgumentException("Tried to set provisioning for " | 
|  | 4459 | + "MmTel capability '" + capability + "', which does not require " | 
|  | 4460 | + "provisioning. "); | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4461 | } | 
|  | 4462 | } | 
|  | 4463 |  | 
|  | 4464 | } finally { | 
|  | 4465 | Binder.restoreCallingIdentity(identity); | 
|  | 4466 | } | 
|  | 4467 | } | 
|  | 4468 |  | 
|  | 4469 | @Override | 
|  | 4470 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { | 
|  | 4471 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
|  | 4472 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 4473 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
|  | 4474 | } | 
|  | 4475 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); | 
|  | 4476 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4477 | try { | 
|  | 4478 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4479 | if (!isImsProvisioningRequired(subId, capability, true)) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4480 | return true; | 
|  | 4481 | } | 
|  | 4482 |  | 
|  | 4483 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); | 
|  | 4484 | switch (capability) { | 
|  | 4485 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { | 
|  | 4486 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 4487 | return ims.isVolteProvisionedOnDevice(); | 
|  | 4488 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { | 
|  | 4489 | return ims.isWfcProvisionedOnDevice(); | 
|  | 4490 | } | 
|  | 4491 | // This should never happen, since we are checking tech above to make sure it | 
|  | 4492 | // is either LTE or IWLAN. | 
|  | 4493 | throw new IllegalArgumentException("Invalid radio technology for voice " | 
|  | 4494 | + "capability."); | 
|  | 4495 | } | 
|  | 4496 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { | 
|  | 4497 | // There is currently no difference in VT provisioning type. | 
|  | 4498 | return ims.isVtProvisionedOnDevice(); | 
|  | 4499 | } | 
|  | 4500 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { | 
|  | 4501 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. | 
|  | 4502 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); | 
|  | 4503 | } | 
|  | 4504 | default: { | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4505 | throw new IllegalArgumentException( | 
|  | 4506 | "Tried to get provisioning for MmTel capability '" + capability | 
|  | 4507 | + "', which does not require provisioning."); | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4508 | } | 
|  | 4509 | } | 
|  | 4510 |  | 
|  | 4511 | } finally { | 
|  | 4512 | Binder.restoreCallingIdentity(identity); | 
|  | 4513 | } | 
|  | 4514 | } | 
|  | 4515 |  | 
|  | 4516 | @Override | 
|  | 4517 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { | 
|  | 4518 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
|  | 4519 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 4520 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
|  | 4521 | } | 
|  | 4522 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); | 
|  | 4523 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); | 
|  | 4524 | return (provisionedBits & capability) > 0; | 
|  | 4525 | } | 
|  | 4526 |  | 
|  | 4527 | @Override | 
|  | 4528 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, | 
|  | 4529 | boolean isProvisioned) { | 
|  | 4530 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
|  | 4531 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 4532 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
|  | 4533 | } | 
|  | 4534 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4535 | "setProvisioningStatusForCapability"); | 
|  | 4536 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); | 
|  | 4537 | // If the current provisioning status for capability already matches isProvisioned, | 
|  | 4538 | // do nothing. | 
|  | 4539 | if (((provisionedBits & capability) > 0) == isProvisioned) { | 
|  | 4540 | return; | 
|  | 4541 | } | 
|  | 4542 | if (isProvisioned) { | 
|  | 4543 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); | 
|  | 4544 | } else { | 
|  | 4545 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); | 
|  | 4546 | } | 
|  | 4547 | } | 
|  | 4548 |  | 
|  | 4549 | /** | 
|  | 4550 | * @return the bitfield containing the MmTel provisioning for the provided subscription and | 
|  | 4551 | * technology. The bitfield should mirror the bitfield defined by | 
|  | 4552 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. | 
|  | 4553 | */ | 
|  | 4554 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { | 
|  | 4555 | String key = getMmTelProvisioningKey(subId, tech); | 
|  | 4556 | // Default is no capabilities are provisioned. | 
|  | 4557 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); | 
|  | 4558 | } | 
|  | 4559 |  | 
|  | 4560 | /** | 
|  | 4561 | * Sets the MmTel capability provisioning bitfield (defined by | 
|  | 4562 | *     {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and | 
|  | 4563 | *     technology specified. | 
|  | 4564 | * | 
|  | 4565 | * Note: This is a synchronous command and should not be called on UI thread. | 
|  | 4566 | */ | 
|  | 4567 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { | 
|  | 4568 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); | 
|  | 4569 | String key = getMmTelProvisioningKey(subId, tech); | 
|  | 4570 | editor.putInt(key, newField); | 
|  | 4571 | editor.commit(); | 
|  | 4572 | } | 
|  | 4573 |  | 
|  | 4574 | private static String getMmTelProvisioningKey(int subId, int tech) { | 
|  | 4575 | // resulting key is provision_ims_mmtel_{subId}_{tech} | 
|  | 4576 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; | 
|  | 4577 | } | 
|  | 4578 |  | 
|  | 4579 | /** | 
|  | 4580 | * Query CarrierConfig to see if the specified capability requires provisioning for the | 
|  | 4581 | * carrier associated with the subscription id. | 
|  | 4582 | */ | 
|  | 4583 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, | 
|  | 4584 | int capability) { | 
|  | 4585 | CarrierConfigManager configManager = new CarrierConfigManager(context); | 
|  | 4586 | PersistableBundle c = configManager.getConfigForSubId(subId); | 
|  | 4587 | boolean requireUtProvisioning = c.getBoolean( | 
| Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4588 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4589 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, | 
|  | 4590 | false); | 
|  | 4591 | boolean requireVoiceVtProvisioning = c.getBoolean( | 
|  | 4592 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); | 
|  | 4593 |  | 
|  | 4594 | // First check to make sure that the capability requires provisioning. | 
|  | 4595 | switch (capability) { | 
|  | 4596 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: | 
|  | 4597 | // intentional fallthrough | 
|  | 4598 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { | 
|  | 4599 | if (requireVoiceVtProvisioning) { | 
|  | 4600 | // Voice and Video requires provisioning | 
|  | 4601 | return true; | 
|  | 4602 | } | 
|  | 4603 | break; | 
|  | 4604 | } | 
|  | 4605 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { | 
|  | 4606 | if (requireUtProvisioning) { | 
|  | 4607 | // UT requires provisioning | 
|  | 4608 | return true; | 
|  | 4609 | } | 
|  | 4610 | break; | 
|  | 4611 | } | 
|  | 4612 | } | 
|  | 4613 | return false; | 
|  | 4614 | } | 
|  | 4615 |  | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4616 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, | 
|  | 4617 | int capability) { | 
|  | 4618 | CarrierConfigManager configManager = new CarrierConfigManager(context); | 
|  | 4619 | PersistableBundle c = configManager.getConfigForSubId(subId); | 
|  | 4620 |  | 
|  | 4621 | boolean requireRcsProvisioning = c.getBoolean( | 
|  | 4622 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); | 
|  | 4623 |  | 
|  | 4624 | // First check to make sure that the capability requires provisioning. | 
|  | 4625 | switch (capability) { | 
|  | 4626 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: | 
|  | 4627 | // intentional fallthrough | 
|  | 4628 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { | 
|  | 4629 | if (requireRcsProvisioning) { | 
|  | 4630 | // OPTION or PRESENCE requires provisioning | 
|  | 4631 | return true; | 
|  | 4632 | } | 
|  | 4633 | break; | 
|  | 4634 | } | 
|  | 4635 | } | 
|  | 4636 | return false; | 
|  | 4637 | } | 
|  | 4638 |  | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4639 | @Override | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4640 | public int getImsProvisioningInt(int subId, int key) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4641 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 4642 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 4643 | } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4644 | enforceReadPrivilegedPermission("getImsProvisioningInt"); | 
|  | 4645 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4646 | try { | 
|  | 4647 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4648 | int slotId = getSlotIndex(subId); | 
|  | 4649 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 4650 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" | 
|  | 4651 | + subId + "' for key:" + key); | 
|  | 4652 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; | 
|  | 4653 | } | 
| calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4654 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4655 | } catch (com.android.ims.ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4656 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" | 
|  | 4657 | + subId + "' for key:" + key); | 
|  | 4658 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4659 | } finally { | 
|  | 4660 | Binder.restoreCallingIdentity(identity); | 
|  | 4661 | } | 
|  | 4662 | } | 
|  | 4663 |  | 
|  | 4664 | @Override | 
|  | 4665 | public String getImsProvisioningString(int subId, int key) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4666 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 4667 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 4668 | } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4669 | enforceReadPrivilegedPermission("getImsProvisioningString"); | 
|  | 4670 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4671 | try { | 
|  | 4672 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4673 | int slotId = getSlotIndex(subId); | 
|  | 4674 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 4675 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" | 
|  | 4676 | + subId + "' for key:" + key); | 
|  | 4677 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; | 
|  | 4678 | } | 
| calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4679 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4680 | } catch (com.android.ims.ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4681 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" | 
|  | 4682 | + subId + "' for key:" + key); | 
|  | 4683 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4684 | } finally { | 
|  | 4685 | Binder.restoreCallingIdentity(identity); | 
|  | 4686 | } | 
|  | 4687 | } | 
|  | 4688 |  | 
|  | 4689 | @Override | 
|  | 4690 | public int setImsProvisioningInt(int subId, int key, int value) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4691 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 4692 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 4693 | } | 
| Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4694 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4695 | "setImsProvisioningInt"); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4696 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4697 | try { | 
|  | 4698 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4699 | int slotId = getSlotIndex(subId); | 
|  | 4700 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 4701 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" | 
|  | 4702 | + subId + "' for key:" + key); | 
|  | 4703 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
|  | 4704 | } | 
| calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4705 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); | 
|  | 4706 | } catch (com.android.ims.ImsException | RemoteException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4707 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId | 
| calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4708 | + "' for key:" + key, e); | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4709 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4710 | } finally { | 
|  | 4711 | Binder.restoreCallingIdentity(identity); | 
|  | 4712 | } | 
|  | 4713 | } | 
|  | 4714 |  | 
|  | 4715 | @Override | 
|  | 4716 | public int setImsProvisioningString(int subId, int key, String value) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4717 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 4718 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 4719 | } | 
| Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4720 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4721 | "setImsProvisioningString"); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4722 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4723 | try { | 
|  | 4724 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4725 | int slotId = getSlotIndex(subId); | 
|  | 4726 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 4727 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" | 
|  | 4728 | + subId + "' for key:" + key); | 
|  | 4729 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
|  | 4730 | } | 
| calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4731 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); | 
|  | 4732 | } catch (com.android.ims.ImsException | RemoteException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4733 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId | 
| calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4734 | + "' for key:" + key, e); | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4735 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4736 | } finally { | 
|  | 4737 | Binder.restoreCallingIdentity(identity); | 
|  | 4738 | } | 
|  | 4739 | } | 
|  | 4740 |  | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4741 | private int getSlotIndexOrException(int subId) throws ImsException { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4742 | int slotId = SubscriptionManager.getSlotIndex(subId); | 
|  | 4743 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4744 | throw new ImsException("Invalid Subscription Id, subId=" + subId, | 
|  | 4745 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4746 | } | 
|  | 4747 | return slotId; | 
|  | 4748 | } | 
|  | 4749 |  | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4750 | private int getSlotIndex(int subId) { | 
|  | 4751 | int slotId = SubscriptionManager.getSlotIndex(subId); | 
|  | 4752 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { | 
|  | 4753 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; | 
|  | 4754 | } | 
|  | 4755 | return slotId; | 
|  | 4756 | } | 
|  | 4757 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4758 | /** | 
| Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4759 | * Returns the data network type for a subId; does not throw SecurityException. | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4760 | */ | 
|  | 4761 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4762 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, | 
|  | 4763 | String callingFeatureId) { | 
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4764 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); | 
| Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4765 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4766 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); | 
| Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4767 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q | 
| Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4768 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4769 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 4770 | "getNetworkTypeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4771 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 4772 | } | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4773 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4774 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4775 | try { | 
|  | 4776 | final Phone phone = getPhone(subId); | 
|  | 4777 | if (phone != null) { | 
|  | 4778 | return phone.getServiceState().getDataNetworkType(); | 
|  | 4779 | } else { | 
|  | 4780 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 4781 | } | 
|  | 4782 | } finally { | 
|  | 4783 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4784 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4785 | } | 
|  | 4786 |  | 
|  | 4787 | /** | 
|  | 4788 | * Returns the data network type | 
|  | 4789 | */ | 
|  | 4790 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4791 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { | 
|  | 4792 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, | 
|  | 4793 | callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4794 | } | 
|  | 4795 |  | 
|  | 4796 | /** | 
|  | 4797 | * Returns the data network type for a subId | 
|  | 4798 | */ | 
|  | 4799 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4800 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, | 
|  | 4801 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4802 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4803 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 4804 | "getDataNetworkTypeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4805 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 4806 | } | 
|  | 4807 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4808 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4809 | try { | 
|  | 4810 | final Phone phone = getPhone(subId); | 
|  | 4811 | if (phone != null) { | 
|  | 4812 | return phone.getServiceState().getDataNetworkType(); | 
|  | 4813 | } else { | 
|  | 4814 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 4815 | } | 
|  | 4816 | } finally { | 
|  | 4817 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4818 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4819 | } | 
|  | 4820 |  | 
|  | 4821 | /** | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4822 | * Returns the Voice network type for a subId | 
|  | 4823 | */ | 
|  | 4824 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4825 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, | 
|  | 4826 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4827 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4828 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 4829 | "getDataNetworkTypeForSubscriber")) { | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4830 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 4831 | } | 
|  | 4832 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4833 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4834 | try { | 
|  | 4835 | final Phone phone = getPhone(subId); | 
|  | 4836 | if (phone != null) { | 
|  | 4837 | return phone.getServiceState().getVoiceNetworkType(); | 
|  | 4838 | } else { | 
|  | 4839 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 4840 | } | 
|  | 4841 | } finally { | 
|  | 4842 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4843 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4844 | } | 
|  | 4845 |  | 
|  | 4846 | /** | 
|  | 4847 | * @return true if a ICC card is present | 
|  | 4848 | */ | 
|  | 4849 | public boolean hasIccCard() { | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4850 | // FIXME Make changes to pass defaultSimId of type int | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4851 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( | 
|  | 4852 | getDefaultSubscription())); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4853 | } | 
|  | 4854 |  | 
|  | 4855 | /** | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4856 | * @return true if a ICC card is present for a slotIndex | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4857 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4858 | @Override | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4859 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4860 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4861 | try { | 
|  | 4862 | final Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 4863 | if (phone != null) { | 
|  | 4864 | return phone.getIccCard().hasIccCard(); | 
|  | 4865 | } else { | 
|  | 4866 | return false; | 
|  | 4867 | } | 
|  | 4868 | } finally { | 
|  | 4869 | Binder.restoreCallingIdentity(identity); | 
| Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4870 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4871 | } | 
|  | 4872 |  | 
|  | 4873 | /** | 
|  | 4874 | * Return if the current radio is LTE on CDMA. This | 
|  | 4875 | * is a tri-state return value as for a period of time | 
|  | 4876 | * the mode may be unknown. | 
|  | 4877 | * | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4878 | * @param callingPackage the name of the package making the call. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4879 | * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE} | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4880 | * or {@link Phone#LTE_ON_CDMA_TRUE} | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4881 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4882 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4883 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { | 
|  | 4884 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, | 
|  | 4885 | callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4886 | } | 
|  | 4887 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4888 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4889 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, | 
|  | 4890 | String callingFeatureId) { | 
| Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4891 | try { | 
|  | 4892 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); | 
|  | 4893 | } catch (SecurityException e) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4894 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; | 
|  | 4895 | } | 
|  | 4896 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4897 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4898 | try { | 
|  | 4899 | final Phone phone = getPhone(subId); | 
|  | 4900 | if (phone == null) { | 
|  | 4901 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; | 
|  | 4902 | } else { | 
| Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4903 | return TelephonyProperties.lte_on_cdma_device() | 
|  | 4904 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4905 | } | 
|  | 4906 | } finally { | 
|  | 4907 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4908 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4909 | } | 
|  | 4910 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4911 | /** | 
|  | 4912 | * {@hide} | 
|  | 4913 | * Returns Default subId, 0 in the case of single standby. | 
|  | 4914 | */ | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4915 | private int getDefaultSubscription() { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4916 | return mSubscriptionController.getDefaultSubId(); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4917 | } | 
|  | 4918 |  | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4919 | private int getSlotForDefaultSubscription() { | 
|  | 4920 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); | 
|  | 4921 | } | 
|  | 4922 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4923 | private int getPreferredVoiceSubscription() { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4924 | return mSubscriptionController.getDefaultVoiceSubId(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4925 | } | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4926 |  | 
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4927 | private boolean isActiveSubscription(int subId) { | 
|  | 4928 | return mSubscriptionController.isActiveSubId(subId); | 
|  | 4929 | } | 
|  | 4930 |  | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4931 | /** | 
|  | 4932 | * @see android.telephony.TelephonyManager.WifiCallingChoices | 
|  | 4933 | */ | 
|  | 4934 | public int getWhenToMakeWifiCalls() { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4935 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4936 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4937 | return Settings.System.getInt(mApp.getContentResolver(), | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4938 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, | 
|  | 4939 | getWhenToMakeWifiCallsDefaultPreference()); | 
|  | 4940 | } finally { | 
|  | 4941 | Binder.restoreCallingIdentity(identity); | 
|  | 4942 | } | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4943 | } | 
|  | 4944 |  | 
|  | 4945 | /** | 
|  | 4946 | * @see android.telephony.TelephonyManager.WifiCallingChoices | 
|  | 4947 | */ | 
|  | 4948 | public void setWhenToMakeWifiCalls(int preference) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4949 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4950 | try { | 
|  | 4951 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4952 | Settings.System.putInt(mApp.getContentResolver(), | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4953 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); | 
|  | 4954 | } finally { | 
|  | 4955 | Binder.restoreCallingIdentity(identity); | 
|  | 4956 | } | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4957 | } | 
|  | 4958 |  | 
| Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4959 | private static int getWhenToMakeWifiCallsDefaultPreference() { | 
| Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4960 | // TODO: Use a build property to choose this value. | 
| Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4961 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4962 | } | 
| Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4963 |  | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4964 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { | 
|  | 4965 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); | 
|  | 4966 | if (phoneId == -1) { | 
|  | 4967 | throw new IllegalArgumentException("Given slot index: " + slotIndex | 
|  | 4968 | + " does not correspond to an active phone"); | 
|  | 4969 | } | 
|  | 4970 | return PhoneFactory.getPhone(phoneId); | 
|  | 4971 | } | 
|  | 4972 |  | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4973 | @Override | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4974 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( | 
|  | 4975 | int subId, String callingPackage, String aid, int p2) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4976 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4977 | mApp, subId, "iccOpenLogicalChannel"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4978 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4979 | if (DBG) { | 
|  | 4980 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); | 
|  | 4981 | } | 
|  | 4982 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, | 
|  | 4983 | p2); | 
|  | 4984 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4985 |  | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4986 |  | 
|  | 4987 | @Override | 
|  | 4988 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( | 
|  | 4989 | int slotIndex, String callingPackage, String aid, int p2) { | 
|  | 4990 | enforceModifyPermission(); | 
|  | 4991 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 4992 | if (DBG) { | 
|  | 4993 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); | 
|  | 4994 | } | 
|  | 4995 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), | 
|  | 4996 | callingPackage, aid, p2); | 
|  | 4997 | } | 
|  | 4998 |  | 
|  | 4999 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, | 
|  | 5000 | String callingPackage, String aid, int p2) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5001 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5002 | try { | 
|  | 5003 | if (TextUtils.equals(ISDR_AID, aid)) { | 
|  | 5004 | // Only allows LPA to open logical channel to ISD-R. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5005 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() | 
|  | 5006 | .getContext().getPackageManager()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5007 | if (bestComponent == null | 
|  | 5008 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { | 
|  | 5009 | loge("The calling package is not allowed to access ISD-R."); | 
|  | 5010 | throw new SecurityException( | 
|  | 5011 | "The calling package is not allowed to access ISD-R."); | 
|  | 5012 | } | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5013 | } | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5014 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5015 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5016 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, | 
|  | 5017 | null /* workSource */); | 
|  | 5018 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5019 | return response; | 
|  | 5020 | } finally { | 
|  | 5021 | Binder.restoreCallingIdentity(identity); | 
|  | 5022 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5023 | } | 
|  | 5024 |  | 
|  | 5025 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5026 | public boolean iccCloseLogicalChannel(int subId, int channel) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5027 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5028 | mApp, subId, "iccCloseLogicalChannel"); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5029 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); | 
|  | 5030 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); | 
|  | 5031 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5032 |  | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5033 | @Override | 
|  | 5034 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { | 
|  | 5035 | enforceModifyPermission(); | 
|  | 5036 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); | 
|  | 5037 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), | 
|  | 5038 | channel); | 
|  | 5039 | } | 
|  | 5040 |  | 
|  | 5041 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5042 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5043 | try { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5044 | if (channel < 0) { | 
|  | 5045 | return false; | 
|  | 5046 | } | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5047 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, | 
|  | 5048 | null /* workSource */); | 
|  | 5049 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5050 | return success; | 
|  | 5051 | } finally { | 
|  | 5052 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5053 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5054 | } | 
|  | 5055 |  | 
|  | 5056 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5057 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5058 | int command, int p1, int p2, int p3, String data) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5059 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5060 | mApp, subId, "iccTransmitApduLogicalChannel"); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5061 | if (DBG) { | 
|  | 5062 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel | 
|  | 5063 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" | 
|  | 5064 | + p3 + " data=" + data); | 
|  | 5065 | } | 
|  | 5066 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, | 
|  | 5067 | command, p1, p2, p3, data); | 
|  | 5068 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5069 |  | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5070 | @Override | 
|  | 5071 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, | 
|  | 5072 | int command, int p1, int p2, int p3, String data) { | 
|  | 5073 | enforceModifyPermission(); | 
|  | 5074 | if (DBG) { | 
|  | 5075 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel | 
|  | 5076 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" | 
|  | 5077 | + p3 + " data=" + data); | 
|  | 5078 | } | 
|  | 5079 | return iccTransmitApduLogicalChannelWithPermission( | 
|  | 5080 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, | 
|  | 5081 | data); | 
|  | 5082 | } | 
|  | 5083 |  | 
|  | 5084 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, | 
|  | 5085 | int command, int p1, int p2, int p3, String data) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5086 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5087 | try { | 
| Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5088 | if (channel <= 0) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5089 | return ""; | 
|  | 5090 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5091 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5092 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5093 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, | 
|  | 5094 | null /* workSource */); | 
|  | 5095 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5096 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5097 | // Append the returned status code to the end of the response payload. | 
|  | 5098 | String s = Integer.toHexString( | 
|  | 5099 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
|  | 5100 | if (response.payload != null) { | 
|  | 5101 | s = IccUtils.bytesToHexString(response.payload) + s; | 
|  | 5102 | } | 
|  | 5103 | return s; | 
|  | 5104 | } finally { | 
|  | 5105 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5106 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5107 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5108 |  | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5109 | @Override | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5110 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, | 
|  | 5111 | int command, int p1, int p2, int p3, String data) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5112 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5113 | mApp, subId, "iccTransmitApduBasicChannel"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5114 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5115 | if (DBG) { | 
|  | 5116 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" | 
|  | 5117 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); | 
|  | 5118 | } | 
|  | 5119 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, | 
|  | 5120 | cla, command, p1, p2, p3, data); | 
|  | 5121 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5122 |  | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5123 | @Override | 
|  | 5124 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, | 
|  | 5125 | int command, int p1, int p2, int p3, String data) { | 
|  | 5126 | enforceModifyPermission(); | 
|  | 5127 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 5128 | if (DBG) { | 
|  | 5129 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla | 
|  | 5130 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 | 
|  | 5131 | + " data=" + data); | 
|  | 5132 | } | 
|  | 5133 |  | 
|  | 5134 | return iccTransmitApduBasicChannelWithPermission( | 
|  | 5135 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, | 
|  | 5136 | p2, p3, data); | 
|  | 5137 | } | 
|  | 5138 |  | 
|  | 5139 | // open APDU basic channel assuming the caller has sufficient permissions | 
|  | 5140 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, | 
|  | 5141 | int cla, int command, int p1, int p2, int p3, String data) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5142 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5143 | try { | 
|  | 5144 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 | 
|  | 5145 | && TextUtils.equals(ISDR_AID, data)) { | 
|  | 5146 | // Only allows LPA to select ISD-R. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5147 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() | 
|  | 5148 | .getContext().getPackageManager()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5149 | if (bestComponent == null | 
|  | 5150 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { | 
|  | 5151 | loge("The calling package is not allowed to select ISD-R."); | 
|  | 5152 | throw new SecurityException( | 
|  | 5153 | "The calling package is not allowed to select ISD-R."); | 
|  | 5154 | } | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5155 | } | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5156 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5157 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5158 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, | 
|  | 5159 | null /* workSource */); | 
|  | 5160 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5161 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5162 | // Append the returned status code to the end of the response payload. | 
|  | 5163 | String s = Integer.toHexString( | 
|  | 5164 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
|  | 5165 | if (response.payload != null) { | 
|  | 5166 | s = IccUtils.bytesToHexString(response.payload) + s; | 
|  | 5167 | } | 
|  | 5168 | return s; | 
|  | 5169 | } finally { | 
|  | 5170 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5171 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5172 | } | 
|  | 5173 |  | 
|  | 5174 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5175 | public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3, | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5176 | String filePath) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5177 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5178 | mApp, subId, "iccExchangeSimIO"); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5179 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5180 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5181 | try { | 
|  | 5182 | if (DBG) { | 
|  | 5183 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " | 
|  | 5184 | + p1 + " " + p2 + " " + p3 + ":" + filePath); | 
|  | 5185 | } | 
|  | 5186 |  | 
|  | 5187 | IccIoResult response = | 
|  | 5188 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, | 
|  | 5189 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), | 
|  | 5190 | subId); | 
|  | 5191 |  | 
|  | 5192 | if (DBG) { | 
|  | 5193 | log("Exchange SIM_IO [R]" + response); | 
|  | 5194 | } | 
|  | 5195 |  | 
|  | 5196 | byte[] result = null; | 
|  | 5197 | int length = 2; | 
|  | 5198 | if (response.payload != null) { | 
|  | 5199 | length = 2 + response.payload.length; | 
|  | 5200 | result = new byte[length]; | 
|  | 5201 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); | 
|  | 5202 | } else { | 
|  | 5203 | result = new byte[length]; | 
|  | 5204 | } | 
|  | 5205 |  | 
|  | 5206 | result[length - 1] = (byte) response.sw2; | 
|  | 5207 | result[length - 2] = (byte) response.sw1; | 
|  | 5208 | return result; | 
|  | 5209 | } finally { | 
|  | 5210 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5211 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5212 | } | 
|  | 5213 |  | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5214 | /** | 
|  | 5215 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) | 
|  | 5216 | * on a particular subscription | 
|  | 5217 | */ | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5218 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, | 
|  | 5219 | String callingFeatureId) { | 
| sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5220 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5221 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { | 
| sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5222 | return null; | 
|  | 5223 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5224 |  | 
|  | 5225 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5226 | try { | 
|  | 5227 | if (appType != TelephonyManager.APPTYPE_USIM | 
|  | 5228 | && appType != TelephonyManager.APPTYPE_SIM) { | 
|  | 5229 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); | 
|  | 5230 | return null; | 
|  | 5231 | } | 
|  | 5232 | Object response = sendRequest( | 
|  | 5233 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); | 
|  | 5234 | if (response instanceof String[]) { | 
|  | 5235 | return (String[]) response; | 
|  | 5236 | } | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5237 | // Response is an Exception of some kind | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5238 | // which is signalled to the user as a NULL retval | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5239 | return null; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5240 | } finally { | 
|  | 5241 | Binder.restoreCallingIdentity(identity); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5242 | } | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5243 | } | 
|  | 5244 |  | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5245 | /** | 
|  | 5246 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular | 
|  | 5247 | * subscription. | 
|  | 5248 | * | 
|  | 5249 | * @param subId the id of the subscription. | 
|  | 5250 | * @param appType the uicc app type, must be USIM or SIM. | 
|  | 5251 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. | 
|  | 5252 | * @param callingPackage the op Package name. | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5253 | * @param callingFeatureId the feature in the package. | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5254 | * @return number of fplmns that is successfully written to the SIM. | 
|  | 5255 | */ | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5256 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, | 
|  | 5257 | String callingFeatureId) { | 
|  | 5258 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, | 
|  | 5259 | callingFeatureId, "setForbiddenPlmns")) { | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5260 | if (DBG) logv("no permissions for setForbiddenplmns"); | 
|  | 5261 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); | 
|  | 5262 | } | 
|  | 5263 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { | 
|  | 5264 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); | 
|  | 5265 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); | 
|  | 5266 | } | 
|  | 5267 | if (fplmns == null) { | 
|  | 5268 | throw new IllegalArgumentException("Fplmn List provided is null"); | 
|  | 5269 | } | 
|  | 5270 | for (String fplmn : fplmns) { | 
|  | 5271 | if (!CellIdentity.isValidPlmn(fplmn)) { | 
|  | 5272 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); | 
|  | 5273 | } | 
|  | 5274 | } | 
|  | 5275 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5276 | try { | 
|  | 5277 | Object response = sendRequest( | 
|  | 5278 | CMD_SET_FORBIDDEN_PLMNS, | 
|  | 5279 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), | 
|  | 5280 | subId); | 
|  | 5281 | return (int) response; | 
|  | 5282 | } finally { | 
|  | 5283 | Binder.restoreCallingIdentity(identity); | 
|  | 5284 | } | 
|  | 5285 | } | 
|  | 5286 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5287 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5288 | public String sendEnvelopeWithStatus(int subId, String content) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5289 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5290 | mApp, subId, "sendEnvelopeWithStatus"); | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5291 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5292 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5293 | try { | 
|  | 5294 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); | 
|  | 5295 | if (response.payload == null) { | 
|  | 5296 | return ""; | 
|  | 5297 | } | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5298 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5299 | // Append the returned status code to the end of the response payload. | 
|  | 5300 | String s = Integer.toHexString( | 
|  | 5301 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
|  | 5302 | s = IccUtils.bytesToHexString(response.payload) + s; | 
|  | 5303 | return s; | 
|  | 5304 | } finally { | 
|  | 5305 | Binder.restoreCallingIdentity(identity); | 
|  | 5306 | } | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5307 | } | 
|  | 5308 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5309 | /** | 
|  | 5310 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} | 
|  | 5311 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. | 
|  | 5312 | * | 
|  | 5313 | * @param itemID the ID of the item to read | 
|  | 5314 | * @return the NV item as a String, or null on error. | 
|  | 5315 | */ | 
|  | 5316 | @Override | 
|  | 5317 | public String nvReadItem(int itemID) { | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5318 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5319 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5320 | mApp, getDefaultSubscription(), "nvReadItem"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5321 |  | 
|  | 5322 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5323 | try { | 
|  | 5324 | if (DBG) log("nvReadItem: item " + itemID); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5325 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5326 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); | 
|  | 5327 | return value; | 
|  | 5328 | } finally { | 
|  | 5329 | Binder.restoreCallingIdentity(identity); | 
|  | 5330 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5331 | } | 
|  | 5332 |  | 
|  | 5333 | /** | 
|  | 5334 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} | 
|  | 5335 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. | 
|  | 5336 | * | 
|  | 5337 | * @param itemID the ID of the item to read | 
|  | 5338 | * @param itemValue the value to write, as a String | 
|  | 5339 | * @return true on success; false on any failure | 
|  | 5340 | */ | 
|  | 5341 | @Override | 
|  | 5342 | public boolean nvWriteItem(int itemID, String itemValue) { | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5343 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5344 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5345 | mApp, getDefaultSubscription(), "nvWriteItem"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5346 |  | 
|  | 5347 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5348 | try { | 
|  | 5349 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); | 
|  | 5350 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5351 | new Pair<Integer, String>(itemID, itemValue), workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5352 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); | 
|  | 5353 | return success; | 
|  | 5354 | } finally { | 
|  | 5355 | Binder.restoreCallingIdentity(identity); | 
|  | 5356 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5357 | } | 
|  | 5358 |  | 
|  | 5359 | /** | 
|  | 5360 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. | 
|  | 5361 | * Used for device configuration by some CDMA operators. | 
|  | 5362 | * | 
|  | 5363 | * @param preferredRoamingList byte array containing the new PRL | 
|  | 5364 | * @return true on success; false on any failure | 
|  | 5365 | */ | 
|  | 5366 | @Override | 
|  | 5367 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5368 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5369 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5370 |  | 
|  | 5371 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5372 | try { | 
|  | 5373 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); | 
|  | 5374 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); | 
|  | 5375 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); | 
|  | 5376 | return success; | 
|  | 5377 | } finally { | 
|  | 5378 | Binder.restoreCallingIdentity(identity); | 
|  | 5379 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5380 | } | 
|  | 5381 |  | 
|  | 5382 | /** | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5383 | * Rollback modem configurations to factory default except some config which are in whitelist. | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5384 | * Used for device configuration by some CDMA operators. | 
|  | 5385 | * | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5386 | * @param slotIndex - device slot. | 
|  | 5387 | * | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5388 | * @return true on success; false on any failure | 
|  | 5389 | */ | 
|  | 5390 | @Override | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5391 | public boolean resetModemConfig(int slotIndex) { | 
|  | 5392 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 5393 | if (phone != null) { | 
|  | 5394 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5395 | mApp, phone.getSubId(), "resetModemConfig"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5396 |  | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5397 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5398 | try { | 
|  | 5399 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); | 
|  | 5400 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); | 
|  | 5401 | return success; | 
|  | 5402 | } finally { | 
|  | 5403 | Binder.restoreCallingIdentity(identity); | 
|  | 5404 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5405 | } | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5406 | return false; | 
|  | 5407 | } | 
|  | 5408 |  | 
|  | 5409 | /** | 
|  | 5410 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. | 
|  | 5411 | * | 
|  | 5412 | * @param slotIndex - device slot. | 
|  | 5413 | * | 
|  | 5414 | * @return true on success; false on any failure | 
|  | 5415 | */ | 
|  | 5416 | @Override | 
|  | 5417 | public boolean rebootModem(int slotIndex) { | 
|  | 5418 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 5419 | if (phone != null) { | 
|  | 5420 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5421 | mApp, phone.getSubId(), "rebootModem"); | 
|  | 5422 |  | 
|  | 5423 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5424 | try { | 
|  | 5425 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); | 
|  | 5426 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); | 
|  | 5427 | return success; | 
|  | 5428 | } finally { | 
|  | 5429 | Binder.restoreCallingIdentity(identity); | 
|  | 5430 | } | 
|  | 5431 | } | 
|  | 5432 | return false; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5433 | } | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5434 |  | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5435 | public String[] getPcscfAddress(String apnType, String callingPackage, | 
|  | 5436 | String callingFeatureId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5437 | final Phone defaultPhone = getDefaultPhone(); | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5438 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), | 
|  | 5439 | callingPackage, callingFeatureId, "getPcscfAddress")) { | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5440 | return new String[0]; | 
|  | 5441 | } | 
|  | 5442 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5443 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5444 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5445 | return defaultPhone.getPcscfAddress(apnType); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5446 | } finally { | 
|  | 5447 | Binder.restoreCallingIdentity(identity); | 
|  | 5448 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5449 | } | 
|  | 5450 |  | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5451 | /** | 
| Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5452 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and | 
|  | 5453 | * {@link #disableIms(int)}. | 
|  | 5454 | * @param slotIndex device slot. | 
|  | 5455 | */ | 
|  | 5456 | public void resetIms(int slotIndex) { | 
|  | 5457 | enforceModifyPermission(); | 
|  | 5458 |  | 
|  | 5459 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5460 | try { | 
|  | 5461 | if (mImsResolver == null) { | 
|  | 5462 | // may happen if the does not support IMS. | 
|  | 5463 | return; | 
|  | 5464 | } | 
|  | 5465 | mImsResolver.disableIms(slotIndex); | 
|  | 5466 | mImsResolver.enableIms(slotIndex); | 
|  | 5467 | } finally { | 
|  | 5468 | Binder.restoreCallingIdentity(identity); | 
|  | 5469 | } | 
|  | 5470 | } | 
|  | 5471 |  | 
|  | 5472 | /** | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5473 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability | 
|  | 5474 | * status updates, if not already enabled. | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5475 | */ | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5476 | public void enableIms(int slotId) { | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5477 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5478 |  | 
|  | 5479 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5480 | try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5481 | if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5482 | // may happen if the device does not support IMS. | 
|  | 5483 | return; | 
|  | 5484 | } | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5485 | mImsResolver.enableIms(slotId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5486 | } finally { | 
|  | 5487 | Binder.restoreCallingIdentity(identity); | 
|  | 5488 | } | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5489 | } | 
|  | 5490 |  | 
|  | 5491 | /** | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5492 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature | 
|  | 5493 | * status updates to disabled. | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5494 | */ | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5495 | public void disableIms(int slotId) { | 
|  | 5496 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5497 |  | 
|  | 5498 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5499 | try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5500 | if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5501 | // may happen if the device does not support IMS. | 
|  | 5502 | return; | 
|  | 5503 | } | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5504 | mImsResolver.disableIms(slotId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5505 | } finally { | 
|  | 5506 | Binder.restoreCallingIdentity(identity); | 
|  | 5507 | } | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5508 | } | 
|  | 5509 |  | 
|  | 5510 | /** | 
| Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5511 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback | 
|  | 5512 | * callback. | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5513 | */ | 
| Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5514 | @Override | 
| Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5515 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5516 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5517 |  | 
|  | 5518 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5519 | try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5520 | if (mImsResolver == null) { | 
| Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5521 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 5522 | "Device does not support IMS"); | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5523 | } | 
| Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5524 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5525 | } finally { | 
|  | 5526 | Binder.restoreCallingIdentity(identity); | 
|  | 5527 | } | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5528 | } | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5529 | /** | 
| Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5530 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. | 
|  | 5531 | */ | 
| Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5532 | @Override | 
|  | 5533 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { | 
| Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5534 | enforceModifyPermission(); | 
|  | 5535 |  | 
|  | 5536 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5537 | try { | 
|  | 5538 | if (mImsResolver == null) return; | 
| Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5539 | mImsResolver.unregisterImsFeatureCallback(callback); | 
| Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5540 | } finally { | 
|  | 5541 | Binder.restoreCallingIdentity(identity); | 
|  | 5542 | } | 
|  | 5543 | } | 
|  | 5544 |  | 
|  | 5545 | /** | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5546 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5547 | * specified or null if IMS is not supported on the slot specified. | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5548 | */ | 
|  | 5549 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { | 
|  | 5550 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5551 |  | 
|  | 5552 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5553 | try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5554 | if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5555 | // may happen if the device does not support IMS. | 
|  | 5556 | return null; | 
|  | 5557 | } | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5558 | return mImsResolver.getImsRegistration(slotId, feature); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5559 | } finally { | 
|  | 5560 | Binder.restoreCallingIdentity(identity); | 
|  | 5561 | } | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5562 | } | 
|  | 5563 |  | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5564 | /** | 
|  | 5565 | * Returns the {@link IImsConfig} structure associated with the slotId and feature | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5566 | * specified or null if IMS is not supported on the slot specified. | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5567 | */ | 
|  | 5568 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { | 
|  | 5569 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5570 |  | 
|  | 5571 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5572 | try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5573 | if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5574 | // may happen if the device does not support IMS. | 
|  | 5575 | return null; | 
|  | 5576 | } | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5577 | return mImsResolver.getImsConfig(slotId, feature); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5578 | } finally { | 
|  | 5579 | Binder.restoreCallingIdentity(identity); | 
|  | 5580 | } | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5581 | } | 
|  | 5582 |  | 
| Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5583 | /** | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5584 | * Sets the ImsService Package Name that Telephony will bind to. | 
|  | 5585 | * | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5586 | * @param slotIndex the slot ID that the ImsService should bind for. | 
|  | 5587 | * @param isCarrierService true if the ImsService is the carrier override, false if the | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5588 | *         ImsService is the device default ImsService. | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5589 | * @param featureTypes An integer array of feature types associated with a packageName. | 
|  | 5590 | * @param packageName The name of the package that the current configuration will be replaced | 
|  | 5591 | *                    with. | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5592 | * @return true if setting the ImsService to bind to succeeded, false if it did not. | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5593 | */ | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5594 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, | 
|  | 5595 | int[] featureTypes, String packageName) { | 
|  | 5596 | int[] subIds = SubscriptionManager.getSubId(slotIndex); | 
|  | 5597 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5598 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, | 
|  | 5599 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5600 | "setBoundImsServiceOverride"); | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5601 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5602 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5603 | try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5604 | if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5605 | // may happen if the device does not support IMS. | 
|  | 5606 | return false; | 
|  | 5607 | } | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5608 | Map<Integer, String> featureConfig = new HashMap<>(); | 
|  | 5609 | for (int featureType : featureTypes) { | 
|  | 5610 | featureConfig.put(featureType, packageName); | 
|  | 5611 | } | 
|  | 5612 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, | 
|  | 5613 | featureConfig); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5614 | } finally { | 
|  | 5615 | Binder.restoreCallingIdentity(identity); | 
|  | 5616 | } | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5617 | } | 
|  | 5618 |  | 
|  | 5619 | /** | 
| Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5620 | * Clears any carrier ImsService overrides for the slot index specified that were previously | 
|  | 5621 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. | 
|  | 5622 | * | 
|  | 5623 | * This should only be used for testing. | 
|  | 5624 | * | 
|  | 5625 | * @param slotIndex the slot ID that the ImsService should bind for. | 
|  | 5626 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. | 
|  | 5627 | */ | 
|  | 5628 | @Override | 
|  | 5629 | public boolean clearCarrierImsServiceOverride(int slotIndex) { | 
|  | 5630 | int[] subIds = SubscriptionManager.getSubId(slotIndex); | 
|  | 5631 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 5632 | "clearCarrierImsServiceOverride"); | 
|  | 5633 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, | 
|  | 5634 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), | 
|  | 5635 | "clearCarrierImsServiceOverride"); | 
|  | 5636 |  | 
|  | 5637 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5638 | try { | 
|  | 5639 | if (mImsResolver == null) { | 
|  | 5640 | // may happen if the device does not support IMS. | 
|  | 5641 | return false; | 
|  | 5642 | } | 
|  | 5643 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); | 
|  | 5644 | } finally { | 
|  | 5645 | Binder.restoreCallingIdentity(identity); | 
|  | 5646 | } | 
|  | 5647 | } | 
|  | 5648 |  | 
|  | 5649 | /** | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5650 | * Return the package name of the currently bound ImsService. | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5651 | * | 
|  | 5652 | * @param slotId The slot that the ImsService is associated with. | 
|  | 5653 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is | 
|  | 5654 | *         the device default. | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5655 | * @param featureType The feature associated with the queried configuration. | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5656 | * @return the package name of the ImsService configuration. | 
|  | 5657 | */ | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5658 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, | 
|  | 5659 | @ImsFeature.FeatureType int featureType) { | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5660 | int[] subIds = SubscriptionManager.getSubId(slotId); | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5661 | TelephonyPermissions | 
|  | 5662 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 5663 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), | 
|  | 5664 | "getBoundImsServicePackage"); | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5665 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5666 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5667 | try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5668 | if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5669 | // may happen if the device does not support IMS. | 
|  | 5670 | return ""; | 
|  | 5671 | } | 
| Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5672 | // TODO: change API to query RCS separately. | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5673 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, | 
|  | 5674 | featureType); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5675 | } finally { | 
|  | 5676 | Binder.restoreCallingIdentity(identity); | 
|  | 5677 | } | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5678 | } | 
|  | 5679 |  | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5680 | /** | 
|  | 5681 | * Get the MmTelFeature state associated with the requested subscription id. | 
|  | 5682 | * @param subId The subscription that the MmTelFeature is associated with. | 
|  | 5683 | * @param callback A callback with an integer containing the | 
|  | 5684 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. | 
|  | 5685 | */ | 
|  | 5686 | @Override | 
|  | 5687 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { | 
|  | 5688 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); | 
|  | 5689 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 5690 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 5691 | "IMS not available on device."); | 
|  | 5692 | } | 
|  | 5693 | final long token = Binder.clearCallingIdentity(); | 
|  | 5694 | try { | 
|  | 5695 | int slotId = getSlotIndex(subId); | 
|  | 5696 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 5697 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" | 
|  | 5698 | + subId + "'"); | 
|  | 5699 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
|  | 5700 | } | 
|  | 5701 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { | 
|  | 5702 | try { | 
|  | 5703 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); | 
|  | 5704 | } catch (RemoteException e) { | 
|  | 5705 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " | 
|  | 5706 | + "Ignore"); | 
|  | 5707 | } | 
|  | 5708 | }); | 
|  | 5709 | } finally { | 
|  | 5710 | Binder.restoreCallingIdentity(token); | 
|  | 5711 | } | 
|  | 5712 | } | 
|  | 5713 |  | 
| Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5714 | /** | 
|  | 5715 | * Sets the ims registration state on all valid {@link Phone}s. | 
|  | 5716 | */ | 
|  | 5717 | public void setImsRegistrationState(final boolean registered) { | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5718 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5719 |  | 
|  | 5720 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5721 | try { | 
| Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5722 | // NOTE: Before S, this method only set the default phone. | 
|  | 5723 | for (final Phone phone : PhoneFactory.getPhones()) { | 
|  | 5724 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { | 
|  | 5725 | phone.setImsRegistrationState(registered); | 
|  | 5726 | } | 
|  | 5727 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5728 | } finally { | 
|  | 5729 | Binder.restoreCallingIdentity(identity); | 
|  | 5730 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5731 | } | 
|  | 5732 |  | 
|  | 5733 | /** | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5734 | * Set the network selection mode to automatic. | 
|  | 5735 | * | 
|  | 5736 | */ | 
|  | 5737 | @Override | 
|  | 5738 | public void setNetworkSelectionModeAutomatic(int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5739 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5740 | mApp, subId, "setNetworkSelectionModeAutomatic"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5741 |  | 
|  | 5742 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5743 | try { | 
| shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5744 | if (!isActiveSubscription(subId)) { | 
|  | 5745 | return; | 
|  | 5746 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5747 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5748 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, | 
|  | 5749 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5750 | } finally { | 
|  | 5751 | Binder.restoreCallingIdentity(identity); | 
|  | 5752 | } | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5753 | } | 
|  | 5754 |  | 
| Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5755 | /** | 
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5756 | * Ask the radio to connect to the input network and change selection mode to manual. | 
|  | 5757 | * | 
|  | 5758 | * @param subId the id of the subscription. | 
|  | 5759 | * @param operatorInfo the operator information, included the PLMN, long name and short name of | 
|  | 5760 | * the operator to attach to. | 
|  | 5761 | * @param persistSelection whether the selection will persist until reboot. If true, only allows | 
|  | 5762 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume | 
|  | 5763 | * normal network selection next time. | 
|  | 5764 | * @return {@code true} on success; {@code true} on any failure. | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5765 | */ | 
|  | 5766 | @Override | 
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5767 | public boolean setNetworkSelectionModeManual( | 
|  | 5768 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5769 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5770 | mApp, subId, "setNetworkSelectionModeManual"); | 
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5771 |  | 
|  | 5772 | if (!isActiveSubscription(subId)) { | 
|  | 5773 | return false; | 
|  | 5774 | } | 
|  | 5775 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5776 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5777 | try { | 
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5778 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5779 | persistSelection); | 
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5780 | if (DBG) { | 
|  | 5781 | log("setNetworkSelectionModeManual: subId: " + subId | 
|  | 5782 | + " operator: " + operatorInfo); | 
|  | 5783 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5784 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); | 
|  | 5785 | } finally { | 
|  | 5786 | Binder.restoreCallingIdentity(identity); | 
|  | 5787 | } | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5788 | } | 
| shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5789 | /** | 
|  | 5790 | * Get the manual network selection | 
|  | 5791 | * | 
|  | 5792 | * @param subId the id of the subscription. | 
|  | 5793 | * | 
|  | 5794 | * @return the previously saved user selected PLMN | 
|  | 5795 | */ | 
|  | 5796 | @Override | 
|  | 5797 | public String getManualNetworkSelectionPlmn(int subId) { | 
|  | 5798 | TelephonyPermissions | 
|  | 5799 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 5800 | mApp, subId, "getManualNetworkSelectionPlmn"); | 
|  | 5801 |  | 
|  | 5802 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5803 | try { | 
|  | 5804 | if (!isActiveSubscription(subId)) { | 
| shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5805 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); | 
| shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5806 | } | 
|  | 5807 |  | 
|  | 5808 | final Phone phone = getPhone(subId); | 
|  | 5809 | if (phone == null) { | 
| shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5810 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); | 
| shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5811 | } | 
|  | 5812 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); | 
|  | 5813 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) | 
|  | 5814 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); | 
|  | 5815 | } finally { | 
|  | 5816 | Binder.restoreCallingIdentity(identity); | 
|  | 5817 | } | 
|  | 5818 | } | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5819 |  | 
|  | 5820 | /** | 
|  | 5821 | * Scans for available networks. | 
|  | 5822 | */ | 
|  | 5823 | @Override | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5824 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, | 
|  | 5825 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5826 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5827 | mApp, subId, "getCellNetworkScanResults"); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5828 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 5829 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 5830 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 5831 | .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5832 | .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5833 | .setCallingPid(Binder.getCallingPid()) | 
|  | 5834 | .setCallingUid(Binder.getCallingUid()) | 
|  | 5835 | .setMethod("getCellNetworkScanResults") | 
|  | 5836 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
| Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5837 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) | 
|  | 5838 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5839 | .build()); | 
|  | 5840 | switch (locationResult) { | 
|  | 5841 | case DENIED_HARD: | 
|  | 5842 | throw new SecurityException("Not allowed to access scan results -- location"); | 
|  | 5843 | case DENIED_SOFT: | 
|  | 5844 | return null; | 
|  | 5845 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5846 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5847 | long identity = Binder.clearCallingIdentity(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5848 | try { | 
|  | 5849 | if (DBG) log("getCellNetworkScanResults: subId " + subId); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5850 | return (CellNetworkScanResult) sendRequest( | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5851 | CMD_PERFORM_NETWORK_SCAN, null, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5852 | } finally { | 
|  | 5853 | Binder.restoreCallingIdentity(identity); | 
|  | 5854 | } | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5855 | } | 
|  | 5856 |  | 
|  | 5857 | /** | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5858 | * Get the call forwarding info, given the call forwarding reason. | 
|  | 5859 | */ | 
|  | 5860 | @Override | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5861 | public void getCallForwarding(int subId, int callForwardingReason, | 
|  | 5862 | ICallForwardingInfoCallback callback) { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5863 | enforceReadPrivilegedPermission("getCallForwarding"); | 
|  | 5864 | long identity = Binder.clearCallingIdentity(); | 
|  | 5865 | try { | 
|  | 5866 | if (DBG) { | 
|  | 5867 | log("getCallForwarding: subId " + subId | 
|  | 5868 | + " callForwardingReason" + callForwardingReason); | 
|  | 5869 | } | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5870 |  | 
|  | 5871 | Phone phone = getPhone(subId); | 
|  | 5872 | if (phone == null) { | 
|  | 5873 | try { | 
| Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5874 | callback.onError( | 
|  | 5875 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5876 | } catch (RemoteException e) { | 
|  | 5877 | // ignore | 
|  | 5878 | } | 
|  | 5879 | return; | 
|  | 5880 | } | 
|  | 5881 |  | 
|  | 5882 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( | 
|  | 5883 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { | 
|  | 5884 | @Override | 
|  | 5885 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { | 
|  | 5886 | try { | 
|  | 5887 | callback.onCallForwardingInfoAvailable(info); | 
|  | 5888 | } catch (RemoteException e) { | 
|  | 5889 | // ignore | 
|  | 5890 | } | 
|  | 5891 | } | 
|  | 5892 |  | 
|  | 5893 | @Override | 
|  | 5894 | public void onError(int error) { | 
|  | 5895 | try { | 
|  | 5896 | callback.onError(error); | 
|  | 5897 | } catch (RemoteException e) { | 
|  | 5898 | // ignore | 
|  | 5899 | } | 
|  | 5900 | } | 
|  | 5901 | }); | 
|  | 5902 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5903 | } finally { | 
|  | 5904 | Binder.restoreCallingIdentity(identity); | 
|  | 5905 | } | 
|  | 5906 | } | 
|  | 5907 |  | 
|  | 5908 | /** | 
|  | 5909 | * Sets the voice call forwarding info including status (enable/disable), call forwarding | 
|  | 5910 | * reason, the number to forward, and the timeout before the forwarding is attempted. | 
|  | 5911 | */ | 
|  | 5912 | @Override | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5913 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, | 
|  | 5914 | IIntegerConsumer callback) { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5915 | enforceModifyPermission(); | 
|  | 5916 | long identity = Binder.clearCallingIdentity(); | 
|  | 5917 | try { | 
|  | 5918 | if (DBG) { | 
|  | 5919 | log("setCallForwarding: subId " + subId | 
|  | 5920 | + " callForwardingInfo" + callForwardingInfo); | 
|  | 5921 | } | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5922 |  | 
|  | 5923 | Phone phone = getPhone(subId); | 
|  | 5924 | if (phone == null) { | 
|  | 5925 | try { | 
| Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5926 | callback.accept( | 
|  | 5927 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5928 | } catch (RemoteException e) { | 
|  | 5929 | // ignore | 
|  | 5930 | } | 
|  | 5931 | return; | 
|  | 5932 | } | 
|  | 5933 |  | 
|  | 5934 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, | 
|  | 5935 | FunctionalUtils.ignoreRemoteException(callback::accept)); | 
|  | 5936 |  | 
|  | 5937 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5938 | } finally { | 
|  | 5939 | Binder.restoreCallingIdentity(identity); | 
|  | 5940 | } | 
|  | 5941 | } | 
|  | 5942 |  | 
|  | 5943 | /** | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5944 | * Get the call waiting status for a subId. | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5945 | */ | 
|  | 5946 | @Override | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5947 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5948 | enforceReadPrivilegedPermission("getCallForwarding"); | 
|  | 5949 | long identity = Binder.clearCallingIdentity(); | 
|  | 5950 | try { | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5951 |  | 
|  | 5952 | Phone phone = getPhone(subId); | 
|  | 5953 | if (phone == null) { | 
|  | 5954 | try { | 
|  | 5955 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); | 
|  | 5956 | } catch (RemoteException e) { | 
|  | 5957 | // ignore | 
|  | 5958 | } | 
|  | 5959 | return; | 
|  | 5960 | } | 
|  | 5961 |  | 
|  | 5962 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); | 
|  | 5963 |  | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5964 | if (DBG) log("getCallWaitingStatus: subId " + subId); | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5965 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5966 | } finally { | 
|  | 5967 | Binder.restoreCallingIdentity(identity); | 
|  | 5968 | } | 
|  | 5969 | } | 
|  | 5970 |  | 
|  | 5971 | /** | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5972 | * Sets whether call waiting is enabled for a given subId. | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5973 | */ | 
|  | 5974 | @Override | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5975 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5976 | enforceModifyPermission(); | 
|  | 5977 | long identity = Binder.clearCallingIdentity(); | 
|  | 5978 | try { | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5979 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); | 
|  | 5980 |  | 
|  | 5981 | Phone phone = getPhone(subId); | 
|  | 5982 | if (phone == null) { | 
|  | 5983 | try { | 
|  | 5984 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); | 
|  | 5985 | } catch (RemoteException e) { | 
|  | 5986 | // ignore | 
|  | 5987 | } | 
|  | 5988 | return; | 
|  | 5989 | } | 
|  | 5990 |  | 
|  | 5991 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, | 
|  | 5992 | FunctionalUtils.ignoreRemoteException(callback::accept)); | 
|  | 5993 |  | 
|  | 5994 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5995 | } finally { | 
|  | 5996 | Binder.restoreCallingIdentity(identity); | 
|  | 5997 | } | 
|  | 5998 | } | 
|  | 5999 |  | 
|  | 6000 | /** | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6001 | * Starts a new network scan and returns the id of this scan. | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6002 | * | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6003 | * @param subId id of the subscription | 
|  | 6004 | * @param request contains the radio access networks with bands/channels to scan | 
|  | 6005 | * @param messenger callback messenger for scan results or errors | 
|  | 6006 | * @param binder for the purpose of auto clean when the user thread crashes | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6007 | * @return the id of the requested scan which can be used to stop the scan. | 
|  | 6008 | */ | 
|  | 6009 | @Override | 
|  | 6010 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6011 | IBinder binder, String callingPackage, String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6012 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6013 | mApp, subId, "requestNetworkScan"); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6014 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 6015 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 6016 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 6017 | .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6018 | .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6019 | .setCallingPid(Binder.getCallingPid()) | 
|  | 6020 | .setCallingUid(Binder.getCallingUid()) | 
|  | 6021 | .setMethod("requestNetworkScan") | 
|  | 6022 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
| James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 6023 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) | 
|  | 6024 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6025 | .build()); | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6026 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { | 
| Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6027 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( | 
|  | 6028 | request, subId, callingPackage); | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6029 | if (e != null) { | 
|  | 6030 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { | 
|  | 6031 | throw e; | 
|  | 6032 | } else { | 
| Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6033 | loge(e.getMessage()); | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6034 | return TelephonyScanManager.INVALID_SCAN_ID; | 
|  | 6035 | } | 
|  | 6036 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6037 | } | 
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6038 | int callingUid = Binder.getCallingUid(); | 
|  | 6039 | int callingPid = Binder.getCallingPid(); | 
| Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6040 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6041 | try { | 
|  | 6042 | return mNetworkScanRequestTracker.startNetworkScan( | 
|  | 6043 | request, messenger, binder, getPhone(subId), | 
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6044 | callingUid, callingPid, callingPackage); | 
| Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6045 | } finally { | 
|  | 6046 | Binder.restoreCallingIdentity(identity); | 
|  | 6047 | } | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6048 | } | 
|  | 6049 |  | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6050 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( | 
| Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6051 | NetworkScanRequest request, int subId, String callingPackage) { | 
|  | 6052 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) | 
| Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6053 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; | 
|  | 6054 | boolean hasNetworkScanPermission = | 
|  | 6055 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) | 
|  | 6056 | == PERMISSION_GRANTED; | 
|  | 6057 |  | 
|  | 6058 | if (!hasCarrierPriv && !hasNetworkScanPermission) { | 
|  | 6059 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" | 
|  | 6060 | + " for network scans without location access."); | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6061 | } | 
|  | 6062 |  | 
|  | 6063 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { | 
|  | 6064 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6065 | if (ras.getChannels() != null && ras.getChannels().length > 0) { | 
|  | 6066 | return new SecurityException("Specific channels must not be" | 
|  | 6067 | + " scanned without location access."); | 
|  | 6068 | } | 
|  | 6069 | } | 
|  | 6070 | } | 
|  | 6071 |  | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6072 | return null; | 
|  | 6073 | } | 
|  | 6074 |  | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6075 | /** | 
|  | 6076 | * Stops an existing network scan with the given scanId. | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6077 | * | 
|  | 6078 | * @param subId id of the subscription | 
|  | 6079 | * @param scanId id of the scan that needs to be stopped | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6080 | */ | 
|  | 6081 | @Override | 
|  | 6082 | public void stopNetworkScan(int subId, int scanId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6083 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6084 | mApp, subId, "stopNetworkScan"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6085 |  | 
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6086 | int callingUid = Binder.getCallingUid(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6087 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6088 | try { | 
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6089 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6090 | } finally { | 
|  | 6091 | Binder.restoreCallingIdentity(identity); | 
|  | 6092 | } | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6093 | } | 
|  | 6094 |  | 
|  | 6095 | /** | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6096 | * Get the allowed network types bitmask. | 
| Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6097 | * | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6098 | * @return the allowed network types bitmask, defined in RILConstants.java. | 
| Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6099 | */ | 
|  | 6100 | @Override | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6101 | public int getAllowedNetworkTypesBitmask(int subId) { | 
| Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6102 | TelephonyPermissions | 
|  | 6103 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6104 | mApp, subId, "getAllowedNetworkTypesBitmask"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6105 |  | 
|  | 6106 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6107 | try { | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6108 | if (DBG) log("getAllowedNetworkTypesBitmask"); | 
|  | 6109 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); | 
|  | 6110 | int networkTypesBitmask = (result != null ? result[0] : -1); | 
|  | 6111 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); | 
|  | 6112 | return networkTypesBitmask; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6113 | } finally { | 
|  | 6114 | Binder.restoreCallingIdentity(identity); | 
|  | 6115 | } | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6116 | } | 
|  | 6117 |  | 
|  | 6118 | /** | 
| Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6119 | * Get the allowed network types for certain reason. | 
|  | 6120 | * | 
|  | 6121 | * @param subId the id of the subscription. | 
|  | 6122 | * @param reason the reason the allowed network type change is taking place | 
|  | 6123 | * @return the allowed network types. | 
|  | 6124 | */ | 
|  | 6125 | @Override | 
|  | 6126 | public long getAllowedNetworkTypesForReason(int subId, | 
|  | 6127 | @TelephonyManager.AllowedNetworkTypesReason int reason) { | 
| SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6128 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 6129 | mApp, subId, "getAllowedNetworkTypesForReason"); | 
| Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6130 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6131 | try { | 
|  | 6132 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); | 
|  | 6133 | } finally { | 
|  | 6134 | Binder.restoreCallingIdentity(identity); | 
|  | 6135 | } | 
|  | 6136 | } | 
|  | 6137 |  | 
|  | 6138 | /** | 
| Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6139 | * Enable/Disable E-UTRA-NR Dual Connectivity | 
|  | 6140 | * @param subId subscription id of the sim card | 
|  | 6141 | * @param nrDualConnectivityState expected NR dual connectivity state | 
|  | 6142 | * This can be passed following states | 
|  | 6143 | * <ol> | 
|  | 6144 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} | 
|  | 6145 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} | 
|  | 6146 | * <li>Disable NR dual connectivity and force secondary cell to be released | 
|  | 6147 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} | 
|  | 6148 | * </ol> | 
|  | 6149 | * @return operation result. | 
|  | 6150 | */ | 
|  | 6151 | @Override | 
|  | 6152 | public int setNrDualConnectivityState(int subId, | 
|  | 6153 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { | 
|  | 6154 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6155 | mApp, subId, "enableNRDualConnectivity"); | 
| Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6156 | if (!isRadioInterfaceCapabilitySupported( | 
| Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6157 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { | 
|  | 6158 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; | 
|  | 6159 | } | 
|  | 6160 |  | 
| Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6161 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 6162 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6163 | try { | 
|  | 6164 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, | 
|  | 6165 | nrDualConnectivityState, subId, | 
|  | 6166 | workSource); | 
|  | 6167 | if (DBG) log("enableNRDualConnectivity result: " + result); | 
|  | 6168 | return result; | 
|  | 6169 | } finally { | 
|  | 6170 | Binder.restoreCallingIdentity(identity); | 
|  | 6171 | } | 
|  | 6172 | } | 
|  | 6173 |  | 
|  | 6174 | /** | 
|  | 6175 | * Is E-UTRA-NR Dual Connectivity enabled | 
|  | 6176 | * @return true if dual connectivity is enabled else false | 
|  | 6177 | */ | 
|  | 6178 | @Override | 
|  | 6179 | public boolean isNrDualConnectivityEnabled(int subId) { | 
|  | 6180 | TelephonyPermissions | 
|  | 6181 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 6182 | mApp, subId, "isNRDualConnectivityEnabled"); | 
| Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6183 | if (!isRadioInterfaceCapabilitySupported( | 
| Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6184 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { | 
|  | 6185 | return false; | 
|  | 6186 | } | 
| Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6187 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 6188 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6189 | try { | 
|  | 6190 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, | 
|  | 6191 | null, subId, workSource); | 
|  | 6192 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); | 
|  | 6193 | return isEnabled; | 
|  | 6194 | } finally { | 
|  | 6195 | Binder.restoreCallingIdentity(identity); | 
|  | 6196 | } | 
|  | 6197 | } | 
|  | 6198 |  | 
|  | 6199 | /** | 
| Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6200 | * Set the allowed network types of the device and | 
|  | 6201 | * provide the reason triggering the allowed network change. | 
|  | 6202 | * | 
|  | 6203 | * @param subId the id of the subscription. | 
|  | 6204 | * @param reason the reason the allowed network type change is taking place | 
|  | 6205 | * @param allowedNetworkTypes the allowed network types. | 
|  | 6206 | * @return true on success; false on any failure. | 
|  | 6207 | */ | 
|  | 6208 | @Override | 
|  | 6209 | public boolean setAllowedNetworkTypesForReason(int subId, | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6210 | @TelephonyManager.AllowedNetworkTypesReason int reason, | 
|  | 6211 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { | 
| Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6212 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6213 | mApp, subId, "setAllowedNetworkTypesForReason"); | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6214 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { | 
|  | 6215 | Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason); | 
|  | 6216 | return false; | 
|  | 6217 | } | 
|  | 6218 |  | 
| SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6219 | log("setAllowedNetworkTypesForReason: " + reason + " value: " | 
|  | 6220 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); | 
|  | 6221 |  | 
|  | 6222 |  | 
|  | 6223 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { | 
|  | 6224 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); | 
|  | 6225 | return true; | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6226 | } | 
| SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6227 |  | 
| Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6228 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6229 | try { | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6230 | Boolean success = (Boolean) sendRequest( | 
|  | 6231 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, | 
|  | 6232 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); | 
|  | 6233 |  | 
|  | 6234 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); | 
|  | 6235 | return success; | 
| Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6236 | } finally { | 
|  | 6237 | Binder.restoreCallingIdentity(identity); | 
|  | 6238 | } | 
|  | 6239 | } | 
|  | 6240 |  | 
|  | 6241 | /** | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6242 | * Check whether DUN APN is required for tethering with subId. | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6243 | * | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6244 | * @param subId the id of the subscription to require tethering. | 
| Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6245 | * @return {@code true} if DUN APN is required for tethering. | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6246 | * @hide | 
|  | 6247 | */ | 
|  | 6248 | @Override | 
| SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6249 | public boolean isTetheringApnRequiredForSubscriber(int subId) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6250 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6251 | final long identity = Binder.clearCallingIdentity(); | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6252 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6253 | try { | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6254 | if (phone != null) { | 
|  | 6255 | return phone.hasMatchedTetherApnSetting(); | 
|  | 6256 | } else { | 
|  | 6257 | return false; | 
|  | 6258 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6259 | } finally { | 
|  | 6260 | Binder.restoreCallingIdentity(identity); | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6261 | } | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6262 | } | 
|  | 6263 |  | 
|  | 6264 | /** | 
| Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6265 | * Enable or disable always reporting signal strength changes from radio. | 
|  | 6266 | * | 
|  | 6267 | * @param isEnable {@code true} for enabling; {@code false} for disabling. | 
|  | 6268 | */ | 
|  | 6269 | @Override | 
|  | 6270 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { | 
|  | 6271 | enforceModifyPermission(); | 
|  | 6272 | enforceSystemCaller(); | 
|  | 6273 |  | 
|  | 6274 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6275 | final Phone phone = getPhone(subId); | 
|  | 6276 | try { | 
|  | 6277 | if (phone != null) { | 
|  | 6278 | if (DBG) { | 
|  | 6279 | log("setAlwaysReportSignalStrength: subId=" + subId | 
|  | 6280 | + " isEnable=" + isEnable); | 
|  | 6281 | } | 
|  | 6282 | phone.setAlwaysReportSignalStrength(isEnable); | 
|  | 6283 | } else { | 
|  | 6284 | loge("setAlwaysReportSignalStrength: no phone found for subId=" | 
|  | 6285 | + subId); | 
|  | 6286 | } | 
|  | 6287 | } finally { | 
|  | 6288 | Binder.restoreCallingIdentity(identity); | 
|  | 6289 | } | 
|  | 6290 | } | 
|  | 6291 |  | 
|  | 6292 | /** | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6293 | * Get the user enabled state of Mobile Data. | 
|  | 6294 | * | 
|  | 6295 | * TODO: remove and use isUserDataEnabled. | 
|  | 6296 | * This can't be removed now because some vendor codes | 
|  | 6297 | * calls through ITelephony directly while they should | 
|  | 6298 | * use TelephonyManager. | 
|  | 6299 | * | 
|  | 6300 | * @return true on enabled | 
|  | 6301 | */ | 
|  | 6302 | @Override | 
|  | 6303 | public boolean getDataEnabled(int subId) { | 
|  | 6304 | return isUserDataEnabled(subId); | 
|  | 6305 | } | 
|  | 6306 |  | 
|  | 6307 | /** | 
|  | 6308 | * Get whether mobile data is enabled per user setting. | 
|  | 6309 | * | 
|  | 6310 | * There are other factors deciding whether mobile data is actually enabled, but they are | 
|  | 6311 | * not considered here. See {@link #isDataEnabled(int)} for more details. | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6312 | * | 
| Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6313 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6314 | * | 
|  | 6315 | * @return {@code true} if data is enabled else {@code false} | 
|  | 6316 | */ | 
|  | 6317 | @Override | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6318 | public boolean isUserDataEnabled(int subId) { | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6319 | try { | 
|  | 6320 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, | 
|  | 6321 | null); | 
|  | 6322 | } catch (Exception e) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6323 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6324 | mApp, subId, "isUserDataEnabled"); | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6325 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6326 |  | 
|  | 6327 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6328 | try { | 
|  | 6329 | int phoneId = mSubscriptionController.getPhoneId(subId); | 
|  | 6330 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); | 
|  | 6331 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 6332 | if (phone != null) { | 
|  | 6333 | boolean retVal = phone.isUserDataEnabled(); | 
|  | 6334 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); | 
|  | 6335 | return retVal; | 
|  | 6336 | } else { | 
|  | 6337 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); | 
|  | 6338 | return false; | 
|  | 6339 | } | 
|  | 6340 | } finally { | 
|  | 6341 | Binder.restoreCallingIdentity(identity); | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6342 | } | 
|  | 6343 | } | 
|  | 6344 |  | 
|  | 6345 | /** | 
| Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6346 | * Checks if the device is capable of mobile data by considering whether whether the | 
|  | 6347 | * user has enabled mobile data, whether the carrier has enabled mobile data, and | 
|  | 6348 | * whether the network policy allows data connections. | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6349 | * | 
| Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6350 | * @return {@code true} if the overall data connection is capable; {@code false} if not. | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6351 | */ | 
|  | 6352 | @Override | 
|  | 6353 | public boolean isDataEnabled(int subId) { | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6354 | try { | 
|  | 6355 | try { | 
|  | 6356 | mApp.enforceCallingOrSelfPermission( | 
|  | 6357 | android.Manifest.permission.ACCESS_NETWORK_STATE, | 
|  | 6358 | null); | 
|  | 6359 | } catch (Exception e) { | 
|  | 6360 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, | 
|  | 6361 | "isDataEnabled"); | 
|  | 6362 | } | 
|  | 6363 | } catch (Exception e) { | 
|  | 6364 | enforceReadPrivilegedPermission("isDataEnabled"); | 
|  | 6365 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6366 |  | 
|  | 6367 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6368 | try { | 
|  | 6369 | int phoneId = mSubscriptionController.getPhoneId(subId); | 
|  | 6370 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); | 
|  | 6371 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 6372 | if (phone != null) { | 
| Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6373 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6374 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); | 
|  | 6375 | return retVal; | 
|  | 6376 | } else { | 
|  | 6377 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); | 
|  | 6378 | return false; | 
|  | 6379 | } | 
|  | 6380 | } finally { | 
|  | 6381 | Binder.restoreCallingIdentity(identity); | 
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6382 | } | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6383 | } | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6384 |  | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6385 | /** | 
|  | 6386 | * Check if data is enabled for a specific reason | 
|  | 6387 | * @param subId Subscription index | 
|  | 6388 | * @param reason the reason the data enable change is taking place | 
|  | 6389 | * @return {@code true} if the overall data is enabled; {@code false} if not. | 
|  | 6390 | */ | 
|  | 6391 | @Override | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6392 | public boolean isDataEnabledForReason(int subId, | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6393 | @TelephonyManager.DataEnabledReason int reason) { | 
|  | 6394 | try { | 
|  | 6395 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, | 
|  | 6396 | null); | 
|  | 6397 | } catch (Exception e) { | 
|  | 6398 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6399 | "isDataEnabledForReason"); | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6400 | } | 
|  | 6401 |  | 
|  | 6402 |  | 
|  | 6403 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6404 | try { | 
|  | 6405 | int phoneId = mSubscriptionController.getPhoneId(subId); | 
|  | 6406 | if (DBG) { | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6407 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6408 | + " reason=" + reason); | 
|  | 6409 | } | 
|  | 6410 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 6411 | if (phone != null) { | 
|  | 6412 | boolean retVal; | 
|  | 6413 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { | 
|  | 6414 | retVal = phone.isUserDataEnabled(); | 
|  | 6415 | } else { | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6416 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6417 | } | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6418 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6419 | return retVal; | 
|  | 6420 | } else { | 
|  | 6421 | if (DBG) { | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6422 | loge("isDataEnabledForReason: no phone subId=" | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6423 | + subId + " retVal=false"); | 
|  | 6424 | } | 
|  | 6425 | return false; | 
|  | 6426 | } | 
|  | 6427 | } finally { | 
|  | 6428 | Binder.restoreCallingIdentity(identity); | 
|  | 6429 | } | 
|  | 6430 | } | 
|  | 6431 |  | 
| Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6432 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6433 | Phone phone) { | 
| Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6434 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { | 
|  | 6435 | // Skip the check if it's one of these special uids | 
|  | 6436 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; | 
|  | 6437 | } | 
|  | 6438 |  | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6439 | //load access rules from carrier configs, and check those as well: b/139133814 | 
|  | 6440 | SubscriptionController subController = SubscriptionController.getInstance(); | 
|  | 6441 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS | 
|  | 6442 | || subController == null) return privilegeFromSim; | 
|  | 6443 |  | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6444 | PackageManager pkgMgr = phone.getContext().getPackageManager(); | 
|  | 6445 | String[] packages = pkgMgr.getPackagesForUid(uid); | 
|  | 6446 |  | 
|  | 6447 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6448 | try { | 
| Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6449 | int subId = phone.getSubId(); | 
|  | 6450 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { | 
|  | 6451 | // A test override is in place for the privileges for this subId, so don't try to | 
|  | 6452 | // read the subscription privileges. | 
|  | 6453 | return privilegeFromSim; | 
|  | 6454 | } | 
|  | 6455 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6456 | SubscriptionManager subManager = (SubscriptionManager) | 
|  | 6457 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); | 
|  | 6458 | for (String pkg : packages) { | 
|  | 6459 | if (subManager.canManageSubscription(subInfo, pkg)) { | 
|  | 6460 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; | 
|  | 6461 | } | 
|  | 6462 | } | 
|  | 6463 | return privilegeFromSim; | 
|  | 6464 | } finally { | 
|  | 6465 | Binder.restoreCallingIdentity(identity); | 
|  | 6466 | } | 
|  | 6467 | } | 
|  | 6468 |  | 
|  | 6469 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, | 
|  | 6470 | String pkgName) { | 
|  | 6471 | //load access rules from carrier configs, and check those as well: b/139133814 | 
|  | 6472 | SubscriptionController subController = SubscriptionController.getInstance(); | 
|  | 6473 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS | 
|  | 6474 | || subController == null) return privilegeFromSim; | 
|  | 6475 |  | 
|  | 6476 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6477 | try { | 
| Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6478 | int subId = phone.getSubId(); | 
|  | 6479 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { | 
|  | 6480 | // A test override is in place for the privileges for this subId, so don't try to | 
|  | 6481 | // read the subscription privileges. | 
|  | 6482 | return privilegeFromSim; | 
|  | 6483 | } | 
|  | 6484 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6485 | SubscriptionManager subManager = (SubscriptionManager) | 
|  | 6486 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); | 
|  | 6487 | return subManager.canManageSubscription(subInfo, pkgName) | 
|  | 6488 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; | 
|  | 6489 | } finally { | 
|  | 6490 | Binder.restoreCallingIdentity(identity); | 
|  | 6491 | } | 
|  | 6492 | } | 
|  | 6493 |  | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6494 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6495 | public int getCarrierPrivilegeStatus(int subId) { | 
|  | 6496 | final Phone phone = getPhone(subId); | 
|  | 6497 | if (phone == null) { | 
|  | 6498 | loge("getCarrierPrivilegeStatus: Invalid subId"); | 
|  | 6499 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
|  | 6500 | } | 
|  | 6501 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6502 | if (card == null) { | 
| Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6503 | loge("getCarrierPrivilegeStatus: No UICC"); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6504 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
|  | 6505 | } | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6506 |  | 
|  | 6507 | return getCarrierPrivilegeStatusFromCarrierConfigRules( | 
|  | 6508 | card.getCarrierPrivilegeStatusForCurrentTransaction( | 
| Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6509 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6510 | } | 
| Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6511 |  | 
|  | 6512 | @Override | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6513 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6514 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6515 | final Phone phone = getPhone(subId); | 
|  | 6516 | if (phone == null) { | 
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6517 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6518 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
|  | 6519 | } | 
|  | 6520 | UiccProfile profile = | 
|  | 6521 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); | 
|  | 6522 | if (profile == null) { | 
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6523 | loge("getCarrierPrivilegeStatusForUid: No UICC"); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6524 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
|  | 6525 | } | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6526 | return getCarrierPrivilegeStatusFromCarrierConfigRules( | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6527 | profile.getCarrierPrivilegeStatusForUid( | 
| Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6528 | phone.getContext().getPackageManager(), uid), uid, phone); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6529 | } | 
|  | 6530 |  | 
|  | 6531 | @Override | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6532 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { | 
|  | 6533 | if (TextUtils.isEmpty(pkgName)) { | 
| Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6534 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6535 | } | 
|  | 6536 |  | 
|  | 6537 | int phoneId = SubscriptionManager.getPhoneId(subId); | 
|  | 6538 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6539 | if (card == null) { | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6540 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6541 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
|  | 6542 | } | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6543 | return getCarrierPrivilegeStatusFromCarrierConfigRules( | 
|  | 6544 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), | 
|  | 6545 | getPhone(phoneId), pkgName); | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6546 | } | 
|  | 6547 |  | 
|  | 6548 | @Override | 
|  | 6549 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { | 
| Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6550 | if (TextUtils.isEmpty(pkgName)) | 
|  | 6551 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6552 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
|  | 6553 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 6554 | UiccCard card = UiccController.getInstance().getUiccCard(i); | 
|  | 6555 | if (card == null) { | 
| Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6556 | // No UICC in that slot. | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6557 | continue; | 
|  | 6558 | } | 
|  | 6559 |  | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6560 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( | 
|  | 6561 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), | 
|  | 6562 | getPhone(i), pkgName); | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6563 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
|  | 6564 | break; | 
|  | 6565 | } | 
|  | 6566 | } | 
|  | 6567 |  | 
|  | 6568 | return result; | 
| Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6569 | } | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6570 |  | 
|  | 6571 | @Override | 
| Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6572 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { | 
|  | 6573 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { | 
|  | 6574 | loge("phoneId " + phoneId + " is not valid."); | 
|  | 6575 | return null; | 
|  | 6576 | } | 
|  | 6577 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6578 | if (card == null) { | 
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6579 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6580 | return null ; | 
|  | 6581 | } | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6582 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6583 | } | 
|  | 6584 |  | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6585 | @Override | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6586 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6587 | PackageManager pm = mApp.getPackageManager(); | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6588 | List<String> privilegedPackages = new ArrayList<>(); | 
|  | 6589 | List<PackageInfo> packages = null; | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6590 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); | 
|  | 6591 | // has UICC in that slot. | 
|  | 6592 | if (card != null) { | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6593 | if (card.hasCarrierPrivilegeRules()) { | 
|  | 6594 | if (packages == null) { | 
|  | 6595 | // Only check packages in user 0 for now | 
|  | 6596 | packages = pm.getInstalledPackagesAsUser( | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6597 | PackageManager.MATCH_DISABLED_COMPONENTS | 
|  | 6598 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS | 
| Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6599 | | PackageManager.GET_SIGNING_CERTIFICATES, | 
| Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6600 | UserHandle.SYSTEM.getIdentifier()); | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6601 | } | 
|  | 6602 | for (int p = packages.size() - 1; p >= 0; p--) { | 
|  | 6603 | PackageInfo pkgInfo = packages.get(p); | 
|  | 6604 | if (pkgInfo != null && pkgInfo.packageName != null | 
|  | 6605 | && card.getCarrierPrivilegeStatus(pkgInfo) | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6606 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6607 | privilegedPackages.add(pkgInfo.packageName); | 
|  | 6608 | } | 
|  | 6609 | } | 
|  | 6610 | } | 
|  | 6611 | } | 
|  | 6612 | return privilegedPackages; | 
|  | 6613 | } | 
|  | 6614 |  | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6615 | @Override | 
|  | 6616 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { | 
| Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6617 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); | 
|  | 6618 |  | 
|  | 6619 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6620 |  | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6621 | List<String> privilegedPackages = new ArrayList<>(); | 
| Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6622 | try { | 
|  | 6623 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 6624 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); | 
|  | 6625 | } | 
|  | 6626 | } finally { | 
|  | 6627 | Binder.restoreCallingIdentity(identity); | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6628 | } | 
|  | 6629 | return privilegedPackages; | 
|  | 6630 | } | 
|  | 6631 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6632 | private String getIccId(int subId) { | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6633 | final Phone phone = getPhone(subId); | 
|  | 6634 | UiccCard card = phone == null ? null : phone.getUiccCard(); | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6635 | if (card == null) { | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6636 | return null; | 
|  | 6637 | } | 
|  | 6638 | String iccId = card.getIccId(); | 
|  | 6639 | if (TextUtils.isEmpty(iccId)) { | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6640 | return null; | 
|  | 6641 | } | 
|  | 6642 | return iccId; | 
|  | 6643 | } | 
|  | 6644 |  | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6645 | @Override | 
| Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6646 | public void setCallComposerStatus(int subId, int status) { | 
|  | 6647 | enforceModifyPermission(); | 
|  | 6648 |  | 
|  | 6649 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6650 | try { | 
|  | 6651 | Phone phone = getPhone(subId); | 
|  | 6652 | if (phone != null) { | 
|  | 6653 | Phone defaultPhone = phone.getImsPhone(); | 
|  | 6654 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { | 
|  | 6655 | ImsPhone imsPhone = (ImsPhone) defaultPhone; | 
|  | 6656 | imsPhone.setCallComposerStatus(status); | 
| Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6657 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
|  | 6658 | .updateImsServiceConfig(); | 
| Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6659 | } | 
|  | 6660 | } | 
| Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6661 | } catch (ImsException e) { | 
|  | 6662 | throw new ServiceSpecificException(e.getCode()); | 
|  | 6663 | }  finally { | 
| Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6664 | Binder.restoreCallingIdentity(identity); | 
|  | 6665 | } | 
|  | 6666 | } | 
|  | 6667 |  | 
|  | 6668 | @Override | 
|  | 6669 | public int getCallComposerStatus(int subId) { | 
|  | 6670 | enforceReadPrivilegedPermission("getCallComposerStatus"); | 
|  | 6671 |  | 
|  | 6672 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6673 | try { | 
|  | 6674 | Phone phone = getPhone(subId); | 
|  | 6675 | if (phone != null) { | 
|  | 6676 | Phone defaultPhone = phone.getImsPhone(); | 
|  | 6677 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { | 
|  | 6678 | ImsPhone imsPhone = (ImsPhone) defaultPhone; | 
|  | 6679 | return imsPhone.getCallComposerStatus(); | 
|  | 6680 | } | 
|  | 6681 | } | 
|  | 6682 | } finally { | 
|  | 6683 | Binder.restoreCallingIdentity(identity); | 
|  | 6684 | } | 
|  | 6685 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; | 
|  | 6686 | } | 
|  | 6687 |  | 
|  | 6688 | @Override | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6689 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, | 
|  | 6690 | String number) { | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6691 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6692 | subId, "setLine1NumberForDisplayForSubscriber"); | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6693 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6694 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6695 | try { | 
|  | 6696 | final String iccId = getIccId(subId); | 
|  | 6697 | final Phone phone = getPhone(subId); | 
|  | 6698 | if (phone == null) { | 
|  | 6699 | return false; | 
|  | 6700 | } | 
|  | 6701 | final String subscriberId = phone.getSubscriberId(); | 
|  | 6702 |  | 
|  | 6703 | if (DBG_MERGE) { | 
| Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6704 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6705 | + subscriberId + " to " + number); | 
|  | 6706 | } | 
|  | 6707 |  | 
|  | 6708 | if (TextUtils.isEmpty(iccId)) { | 
|  | 6709 | return false; | 
|  | 6710 | } | 
|  | 6711 |  | 
|  | 6712 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); | 
|  | 6713 |  | 
|  | 6714 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; | 
|  | 6715 | if (alphaTag == null) { | 
|  | 6716 | editor.remove(alphaTagPrefKey); | 
|  | 6717 | } else { | 
|  | 6718 | editor.putString(alphaTagPrefKey, alphaTag); | 
|  | 6719 | } | 
|  | 6720 |  | 
|  | 6721 | // Record both the line number and IMSI for this ICCID, since we need to | 
|  | 6722 | // track all merged IMSIs based on line number | 
|  | 6723 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
|  | 6724 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; | 
|  | 6725 | if (number == null) { | 
|  | 6726 | editor.remove(numberPrefKey); | 
|  | 6727 | editor.remove(subscriberPrefKey); | 
|  | 6728 | } else { | 
|  | 6729 | editor.putString(numberPrefKey, number); | 
|  | 6730 | editor.putString(subscriberPrefKey, subscriberId); | 
|  | 6731 | } | 
|  | 6732 |  | 
|  | 6733 | editor.commit(); | 
|  | 6734 | return true; | 
|  | 6735 | } finally { | 
|  | 6736 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6737 | } | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6738 | } | 
|  | 6739 |  | 
|  | 6740 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6741 | public String getLine1NumberForDisplay(int subId, String callingPackage, | 
|  | 6742 | String callingFeatureId) { | 
| Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6743 | // This is open to apps with WRITE_SMS. | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6744 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6745 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { | 
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6746 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6747 | return null; | 
|  | 6748 | } | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6749 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6750 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6751 | try { | 
|  | 6752 | String iccId = getIccId(subId); | 
|  | 6753 | if (iccId != null) { | 
|  | 6754 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
|  | 6755 | if (DBG_MERGE) { | 
|  | 6756 | log("getLine1NumberForDisplay returning " | 
|  | 6757 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); | 
|  | 6758 | } | 
|  | 6759 | return mTelephonySharedPreferences.getString(numberPrefKey, null); | 
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6760 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6761 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); | 
|  | 6762 | return null; | 
|  | 6763 | } finally { | 
|  | 6764 | Binder.restoreCallingIdentity(identity); | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6765 | } | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6766 | } | 
|  | 6767 |  | 
|  | 6768 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6769 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, | 
|  | 6770 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6771 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6772 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6773 | return null; | 
|  | 6774 | } | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6775 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6776 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6777 | try { | 
|  | 6778 | String iccId = getIccId(subId); | 
|  | 6779 | if (iccId != null) { | 
|  | 6780 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; | 
|  | 6781 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); | 
|  | 6782 | } | 
|  | 6783 | return null; | 
|  | 6784 | } finally { | 
|  | 6785 | Binder.restoreCallingIdentity(identity); | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6786 | } | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6787 | } | 
| Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6788 |  | 
|  | 6789 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6790 | public String[] getMergedSubscriberIds(int subId, String callingPackage, | 
|  | 6791 | String callingFeatureId) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6792 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried | 
|  | 6793 | // about carrier-privileged callers not having access. | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6794 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6795 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6796 | callingFeatureId, "getMergedSubscriberIds")) { | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6797 | return null; | 
|  | 6798 | } | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6799 |  | 
| Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6800 | // Clear calling identity, when calling TelephonyManager, because callerUid must be | 
|  | 6801 | // the process, where TelephonyManager was instantiated. | 
|  | 6802 | // Otherwise AppOps check will fail. | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6803 | final long identity  = Binder.clearCallingIdentity(); | 
|  | 6804 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6805 | final Context context = mApp; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6806 | final TelephonyManager tele = TelephonyManager.from(context); | 
|  | 6807 | final SubscriptionManager sub = SubscriptionManager.from(context); | 
|  | 6808 |  | 
|  | 6809 | // Figure out what subscribers are currently active | 
|  | 6810 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6811 |  | 
| Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6812 | // Only consider subs which match the current subId | 
|  | 6813 | // This logic can be simplified. See b/131189269 for progress. | 
|  | 6814 | if (isActiveSubscription(subId)) { | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6815 | activeSubscriberIds.add(tele.getSubscriberId(subId)); | 
|  | 6816 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6817 |  | 
|  | 6818 | // First pass, find a number override for an active subscriber | 
|  | 6819 | String mergeNumber = null; | 
|  | 6820 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); | 
|  | 6821 | for (String key : prefs.keySet()) { | 
|  | 6822 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { | 
|  | 6823 | final String subscriberId = (String) prefs.get(key); | 
|  | 6824 | if (activeSubscriberIds.contains(subscriberId)) { | 
|  | 6825 | final String iccId = key.substring( | 
|  | 6826 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); | 
|  | 6827 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
|  | 6828 | mergeNumber = (String) prefs.get(numberKey); | 
|  | 6829 | if (DBG_MERGE) { | 
| Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6830 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6831 | + " for active subscriber " + subscriberId); | 
|  | 6832 | } | 
|  | 6833 | if (!TextUtils.isEmpty(mergeNumber)) { | 
|  | 6834 | break; | 
|  | 6835 | } | 
|  | 6836 | } | 
|  | 6837 | } | 
|  | 6838 | } | 
|  | 6839 |  | 
|  | 6840 | // Shortcut when no active merged subscribers | 
|  | 6841 | if (TextUtils.isEmpty(mergeNumber)) { | 
|  | 6842 | return null; | 
|  | 6843 | } | 
|  | 6844 |  | 
|  | 6845 | // Second pass, find all subscribers under that line override | 
|  | 6846 | final ArraySet<String> result = new ArraySet<>(); | 
|  | 6847 | for (String key : prefs.keySet()) { | 
|  | 6848 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { | 
|  | 6849 | final String number = (String) prefs.get(key); | 
|  | 6850 | if (mergeNumber.equals(number)) { | 
|  | 6851 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); | 
|  | 6852 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; | 
|  | 6853 | final String subscriberId = (String) prefs.get(subscriberKey); | 
|  | 6854 | if (!TextUtils.isEmpty(subscriberId)) { | 
|  | 6855 | result.add(subscriberId); | 
|  | 6856 | } | 
|  | 6857 | } | 
|  | 6858 | } | 
|  | 6859 | } | 
|  | 6860 |  | 
|  | 6861 | final String[] resultArray = result.toArray(new String[result.size()]); | 
|  | 6862 | Arrays.sort(resultArray); | 
|  | 6863 | if (DBG_MERGE) { | 
| Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6864 | Rlog.d(LOG_TAG, | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6865 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); | 
|  | 6866 | } | 
|  | 6867 | return resultArray; | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6868 | } finally { | 
|  | 6869 | Binder.restoreCallingIdentity(identity); | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6870 | } | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6871 | } | 
|  | 6872 |  | 
|  | 6873 | @Override | 
| zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6874 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { | 
|  | 6875 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); | 
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6876 |  | 
|  | 6877 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6878 | try { | 
|  | 6879 | final TelephonyManager telephonyManager = mApp.getSystemService( | 
|  | 6880 | TelephonyManager.class); | 
|  | 6881 | String subscriberId = telephonyManager.getSubscriberId(subId); | 
|  | 6882 | if (subscriberId == null) { | 
|  | 6883 | if (DBG) { | 
| zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6884 | log("getMergedImsisFromGroup can't find subscriberId for subId " | 
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6885 | + subId); | 
|  | 6886 | } | 
|  | 6887 | return null; | 
|  | 6888 | } | 
|  | 6889 |  | 
|  | 6890 | final SubscriptionInfo info = SubscriptionController.getInstance() | 
|  | 6891 | .getSubscriptionInfo(subId); | 
|  | 6892 | final ParcelUuid groupUuid = info.getGroupUuid(); | 
|  | 6893 | // If it doesn't belong to any group, return just subscriberId of itself. | 
|  | 6894 | if (groupUuid == null) { | 
|  | 6895 | return new String[]{subscriberId}; | 
|  | 6896 | } | 
|  | 6897 |  | 
|  | 6898 | // Get all subscriberIds from the group. | 
|  | 6899 | final List<String> mergedSubscriberIds = new ArrayList<>(); | 
|  | 6900 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6901 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), | 
| Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6902 | mApp.getAttributionTag()); | 
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6903 | for (SubscriptionInfo subInfo : groupInfos) { | 
|  | 6904 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); | 
|  | 6905 | if (subscriberId != null) { | 
|  | 6906 | mergedSubscriberIds.add(subscriberId); | 
|  | 6907 | } | 
|  | 6908 | } | 
|  | 6909 |  | 
|  | 6910 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); | 
|  | 6911 | } finally { | 
|  | 6912 | Binder.restoreCallingIdentity(identity); | 
|  | 6913 |  | 
|  | 6914 | } | 
|  | 6915 | } | 
|  | 6916 |  | 
|  | 6917 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6918 | public boolean setOperatorBrandOverride(int subId, String brand) { | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6919 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6920 | subId, "setOperatorBrandOverride"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6921 |  | 
|  | 6922 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6923 | try { | 
|  | 6924 | final Phone phone = getPhone(subId); | 
|  | 6925 | return phone == null ? false : phone.setOperatorBrandOverride(brand); | 
|  | 6926 | } finally { | 
|  | 6927 | Binder.restoreCallingIdentity(identity); | 
|  | 6928 | } | 
| Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6929 | } | 
| Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6930 |  | 
|  | 6931 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6932 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, | 
| Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6933 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, | 
|  | 6934 | List<String> cdmaNonRoamingList) { | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6935 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( | 
|  | 6936 | mApp, subId, "setRoamingOverride"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6937 |  | 
|  | 6938 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6939 | try { | 
|  | 6940 | final Phone phone = getPhone(subId); | 
|  | 6941 | if (phone == null) { | 
|  | 6942 | return false; | 
|  | 6943 | } | 
|  | 6944 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, | 
|  | 6945 | cdmaNonRoamingList); | 
|  | 6946 | } finally { | 
|  | 6947 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6948 | } | 
| Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6949 | } | 
|  | 6950 |  | 
|  | 6951 | @Override | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6952 | @Deprecated | 
|  | 6953 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { | 
|  | 6954 | enforceModifyPermission(); | 
|  | 6955 |  | 
|  | 6956 | int returnValue = 0; | 
|  | 6957 | try { | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6958 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6959 | if(result.exception == null) { | 
|  | 6960 | if (result.result != null) { | 
|  | 6961 | byte[] responseData = (byte[])(result.result); | 
|  | 6962 | if(responseData.length > oemResp.length) { | 
|  | 6963 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + | 
|  | 6964 | responseData.length +  "bytes. Buffer Size is " + | 
|  | 6965 | oemResp.length + "bytes."); | 
|  | 6966 | } | 
|  | 6967 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); | 
|  | 6968 | returnValue = responseData.length; | 
|  | 6969 | } | 
|  | 6970 | } else { | 
|  | 6971 | CommandException ex = (CommandException) result.exception; | 
|  | 6972 | returnValue = ex.getCommandError().ordinal(); | 
|  | 6973 | if(returnValue > 0) returnValue *= -1; | 
|  | 6974 | } | 
|  | 6975 | } catch (RuntimeException e) { | 
|  | 6976 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); | 
|  | 6977 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); | 
|  | 6978 | if(returnValue > 0) returnValue *= -1; | 
|  | 6979 | } | 
|  | 6980 |  | 
|  | 6981 | return returnValue; | 
|  | 6982 | } | 
|  | 6983 |  | 
|  | 6984 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6985 | public int getRadioAccessFamily(int phoneId, String callingPackage) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6986 | Phone phone = PhoneFactory.getPhone(phoneId); | 
| Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6987 | try { | 
|  | 6988 | TelephonyPermissions | 
|  | 6989 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 6990 | mApp, phone.getSubId(), "getRadioAccessFamily"); | 
|  | 6991 | } catch (SecurityException e) { | 
|  | 6992 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); | 
|  | 6993 | throw e; | 
|  | 6994 | } | 
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6995 | int raf = RadioAccessFamily.RAF_UNKNOWN; | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6996 | if (phone == null) { | 
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6997 | return raf; | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6998 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6999 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7000 | try { | 
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7001 | TelephonyPermissions | 
|  | 7002 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 7003 | mApp, phone.getSubId(), "getRadioAccessFamily"); | 
|  | 7004 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7005 | } finally { | 
|  | 7006 | Binder.restoreCallingIdentity(identity); | 
|  | 7007 | } | 
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7008 | return raf; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7009 | } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7010 |  | 
|  | 7011 | @Override | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7012 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, | 
| Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7013 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7014 | try { | 
|  | 7015 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), | 
|  | 7016 | Binder.getCallingUid())) { | 
|  | 7017 | throw new SecurityException("Package uid and package name do not match: " | 
|  | 7018 | + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage); | 
|  | 7019 | } | 
|  | 7020 | } catch (PackageManager.NameNotFoundException e) { | 
|  | 7021 | throw new SecurityException("Package name invalid:" + callingPackage); | 
|  | 7022 | } | 
|  | 7023 | RoleManager rm = mApp.getSystemService(RoleManager.class); | 
|  | 7024 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); | 
|  | 7025 | if (!dialerRoleHolders.contains(callingPackage)) { | 
|  | 7026 | throw new SecurityException("App must be the dialer role holder to" | 
|  | 7027 | + " upload a call composer pic"); | 
|  | 7028 | } | 
|  | 7029 |  | 
|  | 7030 | Executors.newSingleThreadExecutor().execute(() -> { | 
|  | 7031 | ByteArrayOutputStream output = new ByteArrayOutputStream( | 
|  | 7032 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); | 
|  | 7033 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); | 
|  | 7034 | boolean readUntilEnd = false; | 
|  | 7035 | int totalBytesRead = 0; | 
|  | 7036 | byte[] buffer = new byte[16 * 1024]; | 
|  | 7037 | while (true) { | 
|  | 7038 | int numRead; | 
|  | 7039 | try { | 
|  | 7040 | numRead = input.read(buffer); | 
|  | 7041 | } catch (IOException e) { | 
|  | 7042 | try { | 
|  | 7043 | fd.checkError(); | 
|  | 7044 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, | 
|  | 7045 | null); | 
|  | 7046 | } catch (IOException e1) { | 
|  | 7047 | // This means that the other side closed explicitly with an error. If this | 
|  | 7048 | // happens, log and ignore. | 
|  | 7049 | loge("Remote end of call composer picture pipe closed: " + e1); | 
|  | 7050 | } | 
|  | 7051 | break; | 
|  | 7052 | } | 
|  | 7053 | if (numRead == -1) { | 
|  | 7054 | readUntilEnd = true; | 
|  | 7055 | break; | 
|  | 7056 | } | 
|  | 7057 | totalBytesRead += numRead; | 
|  | 7058 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { | 
|  | 7059 | loge("Too many bytes read for call composer picture: " + totalBytesRead); | 
|  | 7060 | try { | 
|  | 7061 | input.close(); | 
|  | 7062 | } catch (IOException e) { | 
|  | 7063 | // ignore | 
|  | 7064 | } | 
|  | 7065 | break; | 
|  | 7066 | } | 
|  | 7067 | output.write(buffer, 0, numRead); | 
|  | 7068 | } | 
|  | 7069 | // Generally, the remote end will close the file descriptors. The only case where we | 
|  | 7070 | // close is above, where the picture size is too big. | 
|  | 7071 |  | 
|  | 7072 | try { | 
|  | 7073 | fd.checkError(); | 
|  | 7074 | } catch (IOException e) { | 
|  | 7075 | loge("Remote end for call composer closed with an error: " + e); | 
|  | 7076 | return; | 
|  | 7077 | } | 
|  | 7078 |  | 
| Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7079 | if (!readUntilEnd) { | 
|  | 7080 | loge("Did not finish reading entire image; aborting"); | 
|  | 7081 | return; | 
|  | 7082 | } | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7083 |  | 
| Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7084 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); | 
|  | 7085 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( | 
|  | 7086 | new CallComposerPictureTransfer.Factory() {}, | 
|  | 7087 | imageData, | 
|  | 7088 | (result) -> { | 
|  | 7089 | if (result.first != null) { | 
|  | 7090 | ParcelUuid parcelUuid = new ParcelUuid(result.first); | 
|  | 7091 | Bundle outputResult = new Bundle(); | 
|  | 7092 | outputResult.putParcelable( | 
|  | 7093 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); | 
|  | 7094 | callback.send(TelephonyManager.CallComposerException.SUCCESS, | 
|  | 7095 | outputResult); | 
|  | 7096 | } else { | 
|  | 7097 | callback.send(result.second, null); | 
|  | 7098 | } | 
|  | 7099 | } | 
|  | 7100 | ); | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7101 | }); | 
|  | 7102 | } | 
|  | 7103 |  | 
|  | 7104 | @Override | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7105 | public void enableVideoCalling(boolean enable) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7106 | final Phone defaultPhone = getDefaultPhone(); | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7107 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7108 |  | 
|  | 7109 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7110 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7111 | ImsManager.getInstance(defaultPhone.getContext(), | 
|  | 7112 | defaultPhone.getPhoneId()).setVtSetting(enable); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7113 | } finally { | 
|  | 7114 | Binder.restoreCallingIdentity(identity); | 
|  | 7115 | } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7116 | } | 
|  | 7117 |  | 
|  | 7118 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7119 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7120 | final Phone defaultPhone = getDefaultPhone(); | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7121 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), | 
|  | 7122 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { | 
| Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7123 | return false; | 
|  | 7124 | } | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7125 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7126 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7127 | try { | 
|  | 7128 | // Check the user preference and the  system-level IMS setting. Even if the user has | 
|  | 7129 | // enabled video calling, if IMS is disabled we aren't able to support video calling. | 
|  | 7130 | // In the long run, we may instead need to check if there exists a connection service | 
|  | 7131 | // which can support video calling. | 
|  | 7132 | ImsManager imsManager = | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7133 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7134 | return imsManager.isVtEnabledByPlatform() | 
|  | 7135 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() | 
|  | 7136 | && imsManager.isVtEnabledByUser(); | 
|  | 7137 | } finally { | 
|  | 7138 | Binder.restoreCallingIdentity(identity); | 
|  | 7139 | } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7140 | } | 
| Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7141 |  | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7142 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7143 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, | 
|  | 7144 | String callingFeatureId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7145 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7146 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 7147 | "isVideoCallingEnabled")) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7148 | return false; | 
|  | 7149 | } | 
|  | 7150 |  | 
|  | 7151 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7152 | try { | 
|  | 7153 | CarrierConfigManager configManager = | 
|  | 7154 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7155 | return configManager.getConfigForSubId(subId) | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7156 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); | 
|  | 7157 | } finally { | 
|  | 7158 | Binder.restoreCallingIdentity(identity); | 
|  | 7159 | } | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7160 | } | 
|  | 7161 |  | 
|  | 7162 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7163 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7164 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7165 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7166 | return false; | 
|  | 7167 | } | 
|  | 7168 |  | 
|  | 7169 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7170 | try { | 
|  | 7171 | CarrierConfigManager configManager = | 
|  | 7172 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7173 | return configManager.getConfigForSubId(subId) | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7174 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); | 
|  | 7175 | } finally { | 
|  | 7176 | Binder.restoreCallingIdentity(identity); | 
|  | 7177 | } | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7178 | } | 
|  | 7179 |  | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7180 | @Override | 
|  | 7181 | public boolean isTtyModeSupported() { | 
| Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7182 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); | 
| Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7183 | return telecomManager.isTtySupported(); | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7184 | } | 
|  | 7185 |  | 
|  | 7186 | @Override | 
|  | 7187 | public boolean isHearingAidCompatibilitySupported() { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7188 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7189 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7190 | return mApp.getResources().getBoolean(R.bool.hac_enabled); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7191 | } finally { | 
|  | 7192 | Binder.restoreCallingIdentity(identity); | 
|  | 7193 | } | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7194 | } | 
|  | 7195 |  | 
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7196 | /** | 
|  | 7197 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier | 
|  | 7198 | * support for the feature and device firmware support. | 
|  | 7199 | * | 
|  | 7200 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. | 
|  | 7201 | */ | 
|  | 7202 | @Override | 
|  | 7203 | public boolean isRttSupported(int subscriptionId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7204 | final long identity = Binder.clearCallingIdentity(); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7205 | final Phone phone = getPhone(subscriptionId); | 
|  | 7206 | if (phone == null) { | 
|  | 7207 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); | 
|  | 7208 | return false; | 
|  | 7209 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7210 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7211 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7212 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); | 
|  | 7213 | boolean isDeviceSupported = | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7214 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7215 | return isCarrierSupported && isDeviceSupported; | 
|  | 7216 | } finally { | 
|  | 7217 | Binder.restoreCallingIdentity(identity); | 
|  | 7218 | } | 
| Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7219 | } | 
|  | 7220 |  | 
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7221 | /** | 
| Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7222 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set | 
|  | 7223 | * RTT setting, will return true if the device and carrier both support RTT. | 
|  | 7224 | * Otherwise. only returns true if the device and carrier both also support RTT. | 
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7225 | */ | 
|  | 7226 | public boolean isRttEnabled(int subscriptionId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7227 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7228 | try { | 
| Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7229 | boolean isRttSupported = isRttSupported(subscriptionId); | 
|  | 7230 | boolean isUserRttSettingOn = Settings.Secure.getInt( | 
|  | 7231 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; | 
|  | 7232 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) | 
|  | 7233 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); | 
|  | 7234 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7235 | } finally { | 
|  | 7236 | Binder.restoreCallingIdentity(identity); | 
|  | 7237 | } | 
| Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7238 | } | 
|  | 7239 |  | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7240 | @Deprecated | 
|  | 7241 | @Override | 
|  | 7242 | public String getDeviceId(String callingPackage) { | 
|  | 7243 | return getDeviceIdWithFeature(callingPackage, null); | 
|  | 7244 | } | 
|  | 7245 |  | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7246 | /** | 
|  | 7247 | * Returns the unique device ID of phone, for example, the IMEI for | 
|  | 7248 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. | 
|  | 7249 | * | 
|  | 7250 | * <p>Requires Permission: | 
|  | 7251 | *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} | 
|  | 7252 | */ | 
|  | 7253 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7254 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7255 | final Phone phone = PhoneFactory.getPhone(0); | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7256 | if (phone == null) { | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7257 | return null; | 
|  | 7258 | } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7259 | int subId = phone.getSubId(); | 
| Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7260 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7261 | callingPackage, callingFeatureId, "getDeviceId")) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7262 | return null; | 
|  | 7263 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7264 |  | 
|  | 7265 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7266 | try { | 
|  | 7267 | return phone.getDeviceId(); | 
|  | 7268 | } finally { | 
|  | 7269 | Binder.restoreCallingIdentity(identity); | 
|  | 7270 | } | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7271 | } | 
|  | 7272 |  | 
| Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7273 | /** | 
|  | 7274 | * {@hide} | 
|  | 7275 | * Returns the IMS Registration Status on a particular subid | 
|  | 7276 | * | 
|  | 7277 | * @param subId | 
|  | 7278 | */ | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7279 | public boolean isImsRegistered(int subId) { | 
| Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7280 | Phone phone = getPhone(subId); | 
|  | 7281 | if (phone != null) { | 
|  | 7282 | return phone.isImsRegistered(); | 
|  | 7283 | } else { | 
|  | 7284 | return false; | 
|  | 7285 | } | 
|  | 7286 | } | 
|  | 7287 |  | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7288 | @Override | 
|  | 7289 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7290 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7291 | try { | 
|  | 7292 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); | 
|  | 7293 | } finally { | 
|  | 7294 | Binder.restoreCallingIdentity(identity); | 
|  | 7295 | } | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7296 | } | 
| Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7297 |  | 
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7298 | @Override | 
| Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7299 | public int getSubIdForPhoneAccountHandle( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7300 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { | 
| Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7301 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7302 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { | 
| Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7303 | throw new SecurityException("Requires READ_PHONE_STATE permission."); | 
|  | 7304 | } | 
|  | 7305 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7306 | try { | 
|  | 7307 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); | 
|  | 7308 | } finally { | 
|  | 7309 | Binder.restoreCallingIdentity(identity); | 
|  | 7310 | } | 
|  | 7311 | } | 
|  | 7312 |  | 
|  | 7313 | @Override | 
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7314 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { | 
| duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7315 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " | 
|  | 7316 | + "subscriptionId: " + subscriptionId); | 
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7317 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7318 | try { | 
|  | 7319 | Phone phone = getPhone(subscriptionId); | 
|  | 7320 | if (phone == null) { | 
|  | 7321 | return null; | 
|  | 7322 | } | 
|  | 7323 | return PhoneUtils.makePstnPhoneAccountHandle(phone); | 
|  | 7324 | } finally { | 
|  | 7325 | Binder.restoreCallingIdentity(identity); | 
|  | 7326 | } | 
|  | 7327 | } | 
|  | 7328 |  | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7329 | /** | 
|  | 7330 | * @return the VoWiFi calling availability. | 
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7331 | */ | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7332 | public boolean isWifiCallingAvailable(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7333 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7334 | try { | 
|  | 7335 | Phone phone = getPhone(subId); | 
|  | 7336 | if (phone != null) { | 
|  | 7337 | return phone.isWifiCallingEnabled(); | 
|  | 7338 | } else { | 
|  | 7339 | return false; | 
|  | 7340 | } | 
|  | 7341 | } finally { | 
|  | 7342 | Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7343 | } | 
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7344 | } | 
|  | 7345 |  | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7346 | /** | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7347 | * @return the VT calling availability. | 
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7348 | */ | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7349 | public boolean isVideoTelephonyAvailable(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7350 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7351 | try { | 
|  | 7352 | Phone phone = getPhone(subId); | 
|  | 7353 | if (phone != null) { | 
|  | 7354 | return phone.isVideoEnabled(); | 
|  | 7355 | } else { | 
|  | 7356 | return false; | 
|  | 7357 | } | 
|  | 7358 | } finally { | 
|  | 7359 | Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7360 | } | 
|  | 7361 | } | 
|  | 7362 |  | 
|  | 7363 | /** | 
|  | 7364 | * @return the IMS registration technology for the MMTEL feature. Valid return values are | 
|  | 7365 | * defined in {@link ImsRegistrationImplBase}. | 
|  | 7366 | */ | 
|  | 7367 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7368 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7369 | try { | 
|  | 7370 | Phone phone = getPhone(subId); | 
|  | 7371 | if (phone != null) { | 
|  | 7372 | return phone.getImsRegistrationTech(); | 
|  | 7373 | } else { | 
|  | 7374 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; | 
|  | 7375 | } | 
|  | 7376 | } finally { | 
|  | 7377 | Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7378 | } | 
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7379 | } | 
|  | 7380 |  | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7381 | @Override | 
|  | 7382 | public void factoryReset(int subId) { | 
| paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7383 | enforceSettingsPermission(); | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7384 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { | 
|  | 7385 | return; | 
|  | 7386 | } | 
|  | 7387 |  | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7388 | final long identity = Binder.clearCallingIdentity(); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7389 |  | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7390 | try { | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7391 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( | 
|  | 7392 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7393 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7394 | getDefaultDataEnabled()); | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7395 | setNetworkSelectionModeAutomatic(subId); | 
| SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7396 | Phone phone = getPhone(subId); | 
|  | 7397 | if (phone != null) { | 
|  | 7398 | SubscriptionManager.setSubscriptionProperty(subId, | 
|  | 7399 | SubscriptionManager.ALLOWED_NETWORK_TYPES, | 
|  | 7400 | "user=" + RadioAccessFamily.getRafFromNetworkType( | 
|  | 7401 | RILConstants.PREFERRED_NETWORK_MODE)); | 
|  | 7402 | phone.loadAllowedNetworksFromSubscriptionDatabase(); | 
|  | 7403 | } | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7404 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); | 
|  | 7405 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7406 | } | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7407 | // There has been issues when Sms raw table somehow stores orphan | 
|  | 7408 | // fragments. They lead to garbled message when new fragments come | 
|  | 7409 | // in and combined with those stale ones. In case this happens again, | 
|  | 7410 | // user can reset all network settings which will clean up this table. | 
|  | 7411 | cleanUpSmsRawTable(getDefaultPhone().getContext()); | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7412 | // Clean up IMS settings as well here. | 
|  | 7413 | int slotId = getSlotIndex(subId); | 
|  | 7414 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 7415 | ImsManager.getInstance(mApp, slotId).factoryReset(); | 
|  | 7416 | } | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7417 |  | 
|  | 7418 | // Erase modem config if erase modem on network setting is enabled. | 
|  | 7419 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, | 
|  | 7420 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); | 
|  | 7421 | if (configValue != null && Boolean.parseBoolean(configValue)) { | 
|  | 7422 | sendEraseModemConfig(getDefaultPhone()); | 
|  | 7423 | } | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7424 | } finally { | 
|  | 7425 | Binder.restoreCallingIdentity(identity); | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7426 | } | 
|  | 7427 | } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7428 |  | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7429 | private void cleanUpSmsRawTable(Context context) { | 
|  | 7430 | ContentResolver resolver = context.getContentResolver(); | 
|  | 7431 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); | 
|  | 7432 | resolver.delete(uri, null, null); | 
|  | 7433 | } | 
|  | 7434 |  | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7435 | @Override | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7436 | public String getSimLocaleForSubscriber(int subId) { | 
|  | 7437 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); | 
|  | 7438 | final Phone phone = getPhone(subId); | 
|  | 7439 | if (phone == null) { | 
|  | 7440 | log("getSimLocaleForSubscriber, invalid subId"); | 
| chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7441 | return null; | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7442 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7443 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7444 | try { | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7445 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, | 
| Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7446 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); | 
| chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7447 | if (info == null) { | 
|  | 7448 | log("getSimLocaleForSubscriber, inactive subId: " + subId); | 
|  | 7449 | return null; | 
|  | 7450 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7451 | // Try and fetch the locale from the carrier properties or from the SIM language | 
|  | 7452 | // preferences (EF-PL and EF-LI)... | 
|  | 7453 | final int mcc = info.getMcc(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7454 | String simLanguage = null; | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7455 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); | 
|  | 7456 | if (localeFromDefaultSim != null) { | 
|  | 7457 | if (!localeFromDefaultSim.getCountry().isEmpty()) { | 
|  | 7458 | if (DBG) log("Using locale from subId: " + subId + " locale: " | 
|  | 7459 | + localeFromDefaultSim); | 
|  | 7460 | return localeFromDefaultSim.toLanguageTag(); | 
|  | 7461 | } else { | 
|  | 7462 | simLanguage = localeFromDefaultSim.getLanguage(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7463 | } | 
|  | 7464 | } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7465 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7466 | // The SIM language preferences only store a language (e.g. fr = French), not an | 
|  | 7467 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from | 
|  | 7468 | // the SIM and carrier preferences does not include a country we add the country | 
|  | 7469 | // determined from the SIM MCC to provide an exact locale. | 
| zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7470 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7471 | if (mccLocale != null) { | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7472 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7473 | return mccLocale.toLanguageTag(); | 
|  | 7474 | } | 
|  | 7475 |  | 
|  | 7476 | if (DBG) log("No locale found - returning null"); | 
|  | 7477 | return null; | 
|  | 7478 | } finally { | 
|  | 7479 | Binder.restoreCallingIdentity(identity); | 
|  | 7480 | } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7481 | } | 
|  | 7482 |  | 
|  | 7483 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7484 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), | 
| Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7485 | mApp.getAttributionTag()); | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7486 | } | 
|  | 7487 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7488 | /** | 
|  | 7489 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. | 
|  | 7490 | */ | 
|  | 7491 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7492 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), | 
| Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7493 | mApp.getAttributionTag()); | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7494 | } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7495 |  | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7496 | private final ModemActivityInfo mLastModemActivityInfo = | 
| Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7497 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7498 |  | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7499 | /** | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7500 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object | 
|  | 7501 | * representing the state of the modem. | 
|  | 7502 | * | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7503 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one | 
|  | 7504 | * caller to it. Everyone should call this class to get cumulative data. | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7505 | * @hide | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7506 | */ | 
|  | 7507 | @Override | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7508 | public void requestModemActivityInfo(ResultReceiver result) { | 
|  | 7509 | enforceModifyPermission(); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7510 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7511 |  | 
|  | 7512 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7513 | try { | 
| Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7514 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7515 | } finally { | 
|  | 7516 | Binder.restoreCallingIdentity(identity); | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7517 | } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7518 | } | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7519 |  | 
| Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7520 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be | 
|  | 7521 | // less than total activity duration. | 
|  | 7522 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { | 
|  | 7523 | if (info == null) { | 
|  | 7524 | return false; | 
|  | 7525 | } | 
|  | 7526 | int activityDurationMs = | 
| Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7527 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); | 
|  | 7528 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); | 
|  | 7529 |  | 
| Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7530 | return (info.isValid() | 
|  | 7531 | && (info.getSleepTimeMillis() <= activityDurationMs) | 
|  | 7532 | && (info.getIdleTimeMillis() <= activityDurationMs) | 
| Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7533 | && (info.getReceiveTimeMillis() <= activityDurationMs) | 
| Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7534 | && (totalTxTimeMs <= activityDurationMs)); | 
|  | 7535 | } | 
|  | 7536 |  | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7537 | /** | 
|  | 7538 | * {@hide} | 
|  | 7539 | * Returns the service state information on specified subscription. | 
|  | 7540 | */ | 
|  | 7541 | @Override | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7542 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, | 
|  | 7543 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7544 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7545 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7546 | return null; | 
|  | 7547 | } | 
|  | 7548 |  | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7549 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = | 
|  | 7550 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 7551 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 7552 | .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7553 | .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7554 | .setCallingPid(Binder.getCallingPid()) | 
|  | 7555 | .setCallingUid(Binder.getCallingUid()) | 
|  | 7556 | .setMethod("getServiceStateForSubscriber") | 
| Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7557 | .setLogAsInfo(true) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7558 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
| Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7559 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) | 
|  | 7560 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7561 | .build()); | 
|  | 7562 |  | 
|  | 7563 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = | 
|  | 7564 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 7565 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 7566 | .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7567 | .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7568 | .setCallingPid(Binder.getCallingPid()) | 
|  | 7569 | .setCallingUid(Binder.getCallingUid()) | 
|  | 7570 | .setMethod("getServiceStateForSubscriber") | 
| Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7571 | .setLogAsInfo(true) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7572 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) | 
| Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7573 | .setMinSdkVersionForFine(Integer.MAX_VALUE) | 
|  | 7574 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7575 | .build()); | 
|  | 7576 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. | 
|  | 7577 | boolean hasFinePermission = | 
|  | 7578 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; | 
|  | 7579 | boolean hasCoarsePermission = | 
|  | 7580 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; | 
|  | 7581 |  | 
| Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7582 | final Phone phone = getPhone(subId); | 
|  | 7583 | if (phone == null) { | 
|  | 7584 | return null; | 
|  | 7585 | } | 
|  | 7586 |  | 
| Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7587 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7588 |  | 
| Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7589 | boolean isCallingPackageDataService = phone.getDataServicePackages() | 
|  | 7590 | .contains(callingPackage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7591 | try { | 
| Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7592 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above | 
|  | 7593 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { | 
|  | 7594 | Rlog.d(LOG_TAG, | 
|  | 7595 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); | 
|  | 7596 | return null; | 
|  | 7597 | } | 
|  | 7598 |  | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7599 | ServiceState ss = phone.getServiceState(); | 
|  | 7600 |  | 
|  | 7601 | // Scrub out the location info in ServiceState depending on what level of access | 
|  | 7602 | // the caller has. | 
| Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7603 | if (hasFinePermission || isCallingPackageDataService) return ss; | 
| Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7604 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); | 
|  | 7605 | return ss.createLocationInfoSanitizedCopy(true); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7606 | } finally { | 
|  | 7607 | Binder.restoreCallingIdentity(identity); | 
|  | 7608 | } | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7609 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7610 |  | 
|  | 7611 | /** | 
|  | 7612 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. | 
|  | 7613 | * | 
|  | 7614 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the | 
|  | 7615 | * voicemail ringtone. | 
|  | 7616 | * @return The URI for the ringtone to play when receiving a voicemail from a specific | 
|  | 7617 | * PhoneAccount. | 
|  | 7618 | */ | 
|  | 7619 | @Override | 
|  | 7620 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7621 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7622 | try { | 
|  | 7623 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); | 
|  | 7624 | if (phone == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7625 | phone = getDefaultPhone(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7626 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7627 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7628 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); | 
|  | 7629 | } finally { | 
|  | 7630 | Binder.restoreCallingIdentity(identity); | 
|  | 7631 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7632 | } | 
|  | 7633 |  | 
|  | 7634 | /** | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7635 | * Sets the per-account voicemail ringtone. | 
|  | 7636 | * | 
|  | 7637 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or | 
|  | 7638 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. | 
|  | 7639 | * | 
|  | 7640 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the | 
|  | 7641 | * voicemail ringtone. | 
|  | 7642 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific | 
|  | 7643 | * PhoneAccount. | 
|  | 7644 | */ | 
|  | 7645 | @Override | 
|  | 7646 | public void setVoicemailRingtoneUri(String callingPackage, | 
|  | 7647 | PhoneAccountHandle phoneAccountHandle, Uri uri) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7648 | final Phone defaultPhone = getDefaultPhone(); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7649 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7650 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); | 
|  | 7651 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7652 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 7653 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), | 
|  | 7654 | "setVoicemailRingtoneUri"); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7655 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7656 |  | 
|  | 7657 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7658 | try { | 
|  | 7659 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); | 
|  | 7660 | if (phone == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7661 | phone = defaultPhone; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7662 | } | 
|  | 7663 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); | 
|  | 7664 | } finally { | 
|  | 7665 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7666 | } | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7667 | } | 
|  | 7668 |  | 
|  | 7669 | /** | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7670 | * Returns whether vibration is set for voicemail notification in Phone settings. | 
|  | 7671 | * | 
|  | 7672 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the | 
|  | 7673 | * voicemail vibration setting. | 
|  | 7674 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. | 
|  | 7675 | */ | 
|  | 7676 | @Override | 
|  | 7677 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7678 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7679 | try { | 
|  | 7680 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); | 
|  | 7681 | if (phone == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7682 | phone = getDefaultPhone(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7683 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7684 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7685 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); | 
|  | 7686 | } finally { | 
|  | 7687 | Binder.restoreCallingIdentity(identity); | 
|  | 7688 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7689 | } | 
|  | 7690 |  | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7691 | /** | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7692 | * Sets the per-account voicemail vibration. | 
|  | 7693 | * | 
|  | 7694 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or | 
|  | 7695 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. | 
|  | 7696 | * | 
|  | 7697 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the | 
|  | 7698 | * voicemail vibration setting. | 
|  | 7699 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a | 
|  | 7700 | * specific PhoneAccount. | 
|  | 7701 | */ | 
|  | 7702 | @Override | 
|  | 7703 | public void setVoicemailVibrationEnabled(String callingPackage, | 
|  | 7704 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7705 | final Phone defaultPhone = getDefaultPhone(); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7706 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7707 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); | 
|  | 7708 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7709 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 7710 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), | 
|  | 7711 | "setVoicemailVibrationEnabled"); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7712 | } | 
|  | 7713 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7714 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7715 | try { | 
|  | 7716 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); | 
|  | 7717 | if (phone == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7718 | phone = defaultPhone; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7719 | } | 
|  | 7720 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); | 
|  | 7721 | } finally { | 
|  | 7722 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7723 | } | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7724 | } | 
|  | 7725 |  | 
|  | 7726 | /** | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7727 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. | 
|  | 7728 | * | 
|  | 7729 | * @throws SecurityException if the caller does not have the required permission | 
|  | 7730 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7731 | private void enforceReadPrivilegedPermission(String message) { | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7732 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7733 | message); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7734 | } | 
|  | 7735 |  | 
|  | 7736 | /** | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7737 | * Make sure either called from same process as self (phone) or IPC caller has send SMS | 
|  | 7738 | * permission. | 
|  | 7739 | * | 
|  | 7740 | * @throws SecurityException if the caller does not have the required permission | 
|  | 7741 | */ | 
|  | 7742 | private void enforceSendSmsPermission() { | 
|  | 7743 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); | 
|  | 7744 | } | 
|  | 7745 |  | 
|  | 7746 | /** | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7747 | * Make sure called from the package in charge of visual voicemail. | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7748 | * | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7749 | * @throws SecurityException if the caller is not the visual voicemail package. | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7750 | */ | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7751 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7752 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7753 | try { | 
|  | 7754 | ComponentName componentName = | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7755 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7756 | if (componentName == null) { | 
|  | 7757 | throw new SecurityException( | 
|  | 7758 | "Caller not current active visual voicemail package[null]"); | 
|  | 7759 | } | 
|  | 7760 | String vvmPackage = componentName.getPackageName(); | 
|  | 7761 | if (!callingPackage.equals(vvmPackage)) { | 
|  | 7762 | throw new SecurityException("Caller not current active visual voicemail package[" | 
|  | 7763 | + vvmPackage + "]"); | 
|  | 7764 | } | 
|  | 7765 | } finally { | 
|  | 7766 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7767 | } | 
|  | 7768 | } | 
|  | 7769 |  | 
|  | 7770 | /** | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7771 | * Return the application ID for the app type. | 
|  | 7772 | * | 
|  | 7773 | * @param subId the subscription ID that this request applies to. | 
|  | 7774 | * @param appType the uicc app type. | 
|  | 7775 | * @return Application ID for specificied app type, or null if no uicc. | 
|  | 7776 | */ | 
|  | 7777 | @Override | 
|  | 7778 | public String getAidForAppType(int subId, int appType) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7779 | enforceReadPrivilegedPermission("getAidForAppType"); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7780 | Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7781 |  | 
|  | 7782 | final long identity = Binder.clearCallingIdentity(); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7783 | try { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7784 | if (phone == null) { | 
|  | 7785 | return null; | 
|  | 7786 | } | 
|  | 7787 | String aid = null; | 
|  | 7788 | try { | 
|  | 7789 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) | 
|  | 7790 | .getApplicationByType(appType).getAid(); | 
|  | 7791 | } catch (Exception e) { | 
|  | 7792 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); | 
|  | 7793 | } | 
|  | 7794 | return aid; | 
|  | 7795 | } finally { | 
|  | 7796 | Binder.restoreCallingIdentity(identity); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7797 | } | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7798 | } | 
|  | 7799 |  | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7800 | /** | 
|  | 7801 | * Return the Electronic Serial Number. | 
|  | 7802 | * | 
|  | 7803 | * @param subId the subscription ID that this request applies to. | 
|  | 7804 | * @return ESN or null if error. | 
|  | 7805 | */ | 
|  | 7806 | @Override | 
|  | 7807 | public String getEsn(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7808 | enforceReadPrivilegedPermission("getEsn"); | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7809 | Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7810 |  | 
|  | 7811 | final long identity = Binder.clearCallingIdentity(); | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7812 | try { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7813 | if (phone == null) { | 
|  | 7814 | return null; | 
|  | 7815 | } | 
|  | 7816 | String esn = null; | 
|  | 7817 | try { | 
|  | 7818 | esn = phone.getEsn(); | 
|  | 7819 | } catch (Exception e) { | 
|  | 7820 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); | 
|  | 7821 | } | 
|  | 7822 | return esn; | 
|  | 7823 | } finally { | 
|  | 7824 | Binder.restoreCallingIdentity(identity); | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7825 | } | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7826 | } | 
|  | 7827 |  | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7828 | /** | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7829 | * Return the Preferred Roaming List Version. | 
|  | 7830 | * | 
|  | 7831 | * @param subId the subscription ID that this request applies to. | 
|  | 7832 | * @return PRLVersion or null if error. | 
|  | 7833 | */ | 
|  | 7834 | @Override | 
|  | 7835 | public String getCdmaPrlVersion(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7836 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7837 | Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7838 |  | 
|  | 7839 | final long identity = Binder.clearCallingIdentity(); | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7840 | try { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7841 | if (phone == null) { | 
|  | 7842 | return null; | 
|  | 7843 | } | 
|  | 7844 | String cdmaPrlVersion = null; | 
|  | 7845 | try { | 
|  | 7846 | cdmaPrlVersion = phone.getCdmaPrlVersion(); | 
|  | 7847 | } catch (Exception e) { | 
|  | 7848 | Log.e(LOG_TAG, "Not getting PRLVersion", e); | 
|  | 7849 | } | 
|  | 7850 | return cdmaPrlVersion; | 
|  | 7851 | } finally { | 
|  | 7852 | Binder.restoreCallingIdentity(identity); | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7853 | } | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7854 | } | 
|  | 7855 |  | 
|  | 7856 | /** | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7857 | * Get snapshot of Telephony histograms | 
|  | 7858 | * @return List of Telephony histograms | 
|  | 7859 | * @hide | 
|  | 7860 | */ | 
|  | 7861 | @Override | 
|  | 7862 | public List<TelephonyHistogram> getTelephonyHistograms() { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7863 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 7864 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7865 |  | 
|  | 7866 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7867 | try { | 
|  | 7868 | return RIL.getTelephonyRILTimingHistograms(); | 
|  | 7869 | } finally { | 
|  | 7870 | Binder.restoreCallingIdentity(identity); | 
|  | 7871 | } | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7872 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7873 |  | 
|  | 7874 | /** | 
|  | 7875 | * {@hide} | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7876 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between | 
|  | 7877 | * the two lists. | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7878 | * Require system privileges. In the future we may add this to carrier APIs. | 
|  | 7879 | * | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7880 | * @return Integer with the result of the operation, as defined in {@link TelephonyManager}. | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7881 | */ | 
|  | 7882 | @Override | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7883 | @TelephonyManager.SetCarrierRestrictionResult | 
|  | 7884 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7885 | enforceModifyPermission(); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7886 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7887 |  | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7888 | if (carrierRestrictionRules == null) { | 
|  | 7889 | throw new NullPointerException("carrier restriction cannot be null"); | 
| Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7890 | } | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7891 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7892 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7893 | try { | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7894 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7895 | workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7896 | } finally { | 
|  | 7897 | Binder.restoreCallingIdentity(identity); | 
|  | 7898 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7899 | } | 
|  | 7900 |  | 
|  | 7901 | /** | 
|  | 7902 | * {@hide} | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7903 | * Get the allowed carrier list and the excluded carrier list, including the priority between | 
|  | 7904 | * the two lists. | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7905 | * Require system privileges. In the future we may add this to carrier APIs. | 
|  | 7906 | * | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7907 | * @return {@link android.telephony.CarrierRestrictionRules} | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7908 | */ | 
|  | 7909 | @Override | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7910 | public CarrierRestrictionRules getAllowedCarriers() { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7911 | enforceReadPrivilegedPermission("getAllowedCarriers"); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7912 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7913 |  | 
|  | 7914 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7915 | try { | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7916 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); | 
|  | 7917 | if (response instanceof CarrierRestrictionRules) { | 
|  | 7918 | return (CarrierRestrictionRules) response; | 
|  | 7919 | } | 
|  | 7920 | // Response is an Exception of some kind, | 
|  | 7921 | // which is signalled to the user as a NULL retval | 
|  | 7922 | return null; | 
|  | 7923 | } catch (Exception e) { | 
|  | 7924 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); | 
|  | 7925 | return null; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7926 | } finally { | 
|  | 7927 | Binder.restoreCallingIdentity(identity); | 
|  | 7928 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7929 | } | 
|  | 7930 |  | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7931 | /** | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7932 | * Action set from carrier signalling broadcast receivers to enable/disable radio | 
|  | 7933 | * @param subId the subscription ID that this action applies to. | 
|  | 7934 | * @param enabled control enable or disable radio. | 
|  | 7935 | * {@hide} | 
|  | 7936 | */ | 
|  | 7937 | @Override | 
|  | 7938 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { | 
|  | 7939 | enforceModifyPermission(); | 
|  | 7940 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7941 |  | 
|  | 7942 | final long identity = Binder.clearCallingIdentity(); | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7943 | if (phone == null) { | 
|  | 7944 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); | 
|  | 7945 | return; | 
|  | 7946 | } | 
|  | 7947 | try { | 
|  | 7948 | phone.carrierActionSetRadioEnabled(enabled); | 
|  | 7949 | } catch (Exception e) { | 
|  | 7950 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7951 | } finally { | 
|  | 7952 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7953 | } | 
|  | 7954 | } | 
|  | 7955 |  | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7956 | /** | 
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7957 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default | 
|  | 7958 | * network status based on which carrier apps could apply actions accordingly, | 
|  | 7959 | * enable/disable default url handler for example. | 
|  | 7960 | * | 
|  | 7961 | * @param subId the subscription ID that this action applies to. | 
|  | 7962 | * @param report control start/stop reporting the default network status. | 
|  | 7963 | * {@hide} | 
|  | 7964 | */ | 
|  | 7965 | @Override | 
|  | 7966 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { | 
|  | 7967 | enforceModifyPermission(); | 
|  | 7968 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7969 |  | 
|  | 7970 | final long identity = Binder.clearCallingIdentity(); | 
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7971 | if (phone == null) { | 
|  | 7972 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); | 
|  | 7973 | return; | 
|  | 7974 | } | 
|  | 7975 | try { | 
|  | 7976 | phone.carrierActionReportDefaultNetworkStatus(report); | 
|  | 7977 | } catch (Exception e) { | 
|  | 7978 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7979 | } finally { | 
|  | 7980 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7981 | } | 
|  | 7982 | } | 
|  | 7983 |  | 
|  | 7984 | /** | 
| fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7985 | * Action set from carrier signalling broadcast receivers to reset all carrier actions | 
|  | 7986 | * @param subId the subscription ID that this action applies to. | 
|  | 7987 | * {@hide} | 
|  | 7988 | */ | 
|  | 7989 | @Override | 
|  | 7990 | public void carrierActionResetAll(int subId) { | 
|  | 7991 | enforceModifyPermission(); | 
|  | 7992 | final Phone phone = getPhone(subId); | 
|  | 7993 | if (phone == null) { | 
|  | 7994 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); | 
|  | 7995 | return; | 
|  | 7996 | } | 
|  | 7997 | try { | 
|  | 7998 | phone.carrierActionResetAll(); | 
|  | 7999 | } catch (Exception e) { | 
|  | 8000 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); | 
|  | 8001 | } | 
|  | 8002 | } | 
|  | 8003 |  | 
|  | 8004 | /** | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8005 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a | 
|  | 8006 | * bug report is being generated. | 
|  | 8007 | */ | 
|  | 8008 | @Override | 
| Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8009 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8010 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) | 
|  | 8011 | != PackageManager.PERMISSION_GRANTED) { | 
| dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8012 | writer.println("Permission Denial: can't dump Phone from pid=" | 
|  | 8013 | + Binder.getCallingPid() | 
|  | 8014 | + ", uid=" + Binder.getCallingUid() | 
|  | 8015 | + "without permission " | 
|  | 8016 | + android.Manifest.permission.DUMP); | 
|  | 8017 | return; | 
|  | 8018 | } | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8019 | DumpsysHandler.dump(mApp, fd, writer, args); | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8020 | } | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8021 |  | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8022 | @Override | 
| Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8023 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, | 
|  | 8024 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, | 
|  | 8025 | @NonNull String[] args) { | 
|  | 8026 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( | 
|  | 8027 | this, in.getFileDescriptor(), out.getFileDescriptor(), | 
|  | 8028 | err.getFileDescriptor(), args); | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8029 | } | 
|  | 8030 |  | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8031 | /** | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8032 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} | 
| Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8033 | * @param subId Subscription index | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8034 | * @param reason the reason the data enable change is taking place | 
|  | 8035 | * @param enabled True if enabling the data, otherwise disabling. | 
|  | 8036 | * @hide | 
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8037 | */ | 
|  | 8038 | @Override | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8039 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8040 | boolean enabled) { | 
|  | 8041 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER | 
|  | 8042 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { | 
|  | 8043 | try { | 
|  | 8044 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8045 | mApp, subId, "setDataEnabledForReason"); | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8046 | } catch (SecurityException se) { | 
|  | 8047 | enforceModifyPermission(); | 
|  | 8048 | } | 
|  | 8049 | } else { | 
|  | 8050 | enforceModifyPermission(); | 
|  | 8051 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8052 |  | 
|  | 8053 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8054 | try { | 
|  | 8055 | Phone phone = getPhone(subId); | 
|  | 8056 | if (phone != null) { | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8057 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { | 
|  | 8058 | phone.carrierActionSetMeteredApnsEnabled(enabled); | 
|  | 8059 | } else { | 
|  | 8060 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); | 
|  | 8061 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8062 | } | 
|  | 8063 | } finally { | 
|  | 8064 | Binder.restoreCallingIdentity(identity); | 
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8065 | } | 
|  | 8066 | } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8067 |  | 
|  | 8068 | /** | 
|  | 8069 | * Get Client request stats | 
|  | 8070 | * @return List of Client Request Stats | 
|  | 8071 | * @hide | 
|  | 8072 | */ | 
|  | 8073 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8074 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, | 
|  | 8075 | String callingFeatureId, int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8076 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8077 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8078 | return null; | 
|  | 8079 | } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8080 | Phone phone = getPhone(subId); | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8081 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8082 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8083 | try { | 
|  | 8084 | if (phone != null) { | 
|  | 8085 | return phone.getClientRequestStats(); | 
|  | 8086 | } | 
|  | 8087 |  | 
|  | 8088 | return null; | 
|  | 8089 | } finally { | 
|  | 8090 | Binder.restoreCallingIdentity(identity); | 
|  | 8091 | } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8092 | } | 
|  | 8093 |  | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8094 | private WorkSource getWorkSource(int uid) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8095 | String packageName = mApp.getPackageManager().getNameForUid(uid); | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8096 | return new WorkSource(uid, packageName); | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8097 | } | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8098 |  | 
|  | 8099 | /** | 
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8100 | * Set SIM card power state. | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8101 | * | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8102 | * @param slotIndex SIM slot id. | 
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8103 | * @param state  State of SIM (power down, power up, pass through) | 
|  | 8104 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} | 
|  | 8105 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} | 
|  | 8106 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8107 | * | 
|  | 8108 | **/ | 
|  | 8109 | @Override | 
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8110 | public void setSimPowerStateForSlot(int slotIndex, int state) { | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8111 | enforceModifyPermission(); | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8112 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 8113 |  | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8114 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 8115 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8116 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8117 | try { | 
|  | 8118 | if (phone != null) { | 
| Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8119 | phone.setSimPowerState(state, null, workSource); | 
|  | 8120 | } | 
|  | 8121 | } finally { | 
|  | 8122 | Binder.restoreCallingIdentity(identity); | 
|  | 8123 | } | 
|  | 8124 | } | 
|  | 8125 |  | 
|  | 8126 | /** | 
|  | 8127 | * Set SIM card power state. | 
|  | 8128 | * | 
|  | 8129 | * @param slotIndex SIM slot id. | 
|  | 8130 | * @param state  State of SIM (power down, power up, pass through) | 
|  | 8131 | * @param callback  callback to trigger after success or failure | 
|  | 8132 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} | 
|  | 8133 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} | 
|  | 8134 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} | 
|  | 8135 | * | 
|  | 8136 | **/ | 
|  | 8137 | @Override | 
|  | 8138 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, | 
|  | 8139 | IIntegerConsumer callback) { | 
|  | 8140 | enforceModifyPermission(); | 
|  | 8141 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 8142 |  | 
|  | 8143 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 8144 |  | 
|  | 8145 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8146 | try { | 
|  | 8147 | if (phone != null) { | 
|  | 8148 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); | 
|  | 8149 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8150 | } | 
|  | 8151 | } finally { | 
|  | 8152 | Binder.restoreCallingIdentity(identity); | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8153 | } | 
|  | 8154 | } | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8155 |  | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8156 | private boolean isUssdApiAllowed(int subId) { | 
|  | 8157 | CarrierConfigManager configManager = | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8158 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8159 | if (configManager == null) { | 
|  | 8160 | return false; | 
|  | 8161 | } | 
|  | 8162 | PersistableBundle pb = configManager.getConfigForSubId(subId); | 
|  | 8163 | if (pb == null) { | 
|  | 8164 | return false; | 
|  | 8165 | } | 
|  | 8166 | return pb.getBoolean( | 
|  | 8167 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); | 
|  | 8168 | } | 
|  | 8169 |  | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8170 | /** | 
|  | 8171 | * Check if phone is in emergency callback mode | 
|  | 8172 | * @return true if phone is in emergency callback mode | 
|  | 8173 | * @param subId sub id | 
|  | 8174 | */ | 
| goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8175 | @Override | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8176 | public boolean getEmergencyCallbackMode(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8177 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8178 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8179 |  | 
|  | 8180 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8181 | try { | 
|  | 8182 | if (phone != null) { | 
|  | 8183 | return phone.isInEcm(); | 
|  | 8184 | } else { | 
|  | 8185 | return false; | 
|  | 8186 | } | 
|  | 8187 | } finally { | 
|  | 8188 | Binder.restoreCallingIdentity(identity); | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8189 | } | 
|  | 8190 | } | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8191 |  | 
|  | 8192 | /** | 
|  | 8193 | * Get the current signal strength information for the given subscription. | 
|  | 8194 | * Because this information is not updated when the device is in a low power state | 
|  | 8195 | * it should not be relied-upon to be current. | 
|  | 8196 | * @param subId Subscription index | 
|  | 8197 | * @return the most recent cached signal strength info from the modem | 
|  | 8198 | */ | 
|  | 8199 | @Override | 
|  | 8200 | public SignalStrength getSignalStrength(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8201 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8202 | try { | 
|  | 8203 | Phone p = getPhone(subId); | 
|  | 8204 | if (p == null) { | 
|  | 8205 | return null; | 
|  | 8206 | } | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8207 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8208 | return p.getSignalStrength(); | 
|  | 8209 | } finally { | 
|  | 8210 | Binder.restoreCallingIdentity(identity); | 
|  | 8211 | } | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8212 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8213 |  | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8214 | /** | 
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8215 | * Get the current modem radio state for the given slot. | 
|  | 8216 | * @param slotIndex slot index. | 
|  | 8217 | * @param callingPackage the name of the package making the call. | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8218 | * @param callingFeatureId The feature in the package. | 
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8219 | * @return the current radio power state from the modem | 
|  | 8220 | */ | 
|  | 8221 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8222 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { | 
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8223 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 8224 | if (phone != null) { | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8225 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), | 
|  | 8226 | callingPackage, callingFeatureId, "getRadioPowerState")) { | 
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8227 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; | 
|  | 8228 | } | 
|  | 8229 |  | 
|  | 8230 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8231 | try { | 
|  | 8232 | return phone.getRadioPowerState(); | 
|  | 8233 | } finally { | 
|  | 8234 | Binder.restoreCallingIdentity(identity); | 
|  | 8235 | } | 
|  | 8236 | } | 
|  | 8237 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; | 
|  | 8238 | } | 
|  | 8239 |  | 
|  | 8240 | /** | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8241 | * Checks if data roaming is enabled on the subscription with id {@code subId}. | 
|  | 8242 | * | 
|  | 8243 | * <p>Requires one of the following permissions: | 
|  | 8244 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, | 
|  | 8245 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier | 
|  | 8246 | * privileges. | 
|  | 8247 | * | 
|  | 8248 | * @param subId subscription id | 
|  | 8249 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return | 
|  | 8250 | * {@code false}. | 
|  | 8251 | */ | 
|  | 8252 | @Override | 
|  | 8253 | public boolean isDataRoamingEnabled(int subId) { | 
| Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8254 | try { | 
|  | 8255 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, | 
|  | 8256 | null); | 
|  | 8257 | } catch (Exception e) { | 
|  | 8258 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( | 
|  | 8259 | mApp, subId, "isDataRoamingEnabled"); | 
|  | 8260 | } | 
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8261 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8262 | boolean isEnabled = false; | 
|  | 8263 | final long identity = Binder.clearCallingIdentity(); | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8264 | try { | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8265 | Phone phone = getPhone(subId); | 
|  | 8266 | isEnabled =  phone != null ? phone.getDataRoamingEnabled() : false; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8267 | } finally { | 
|  | 8268 | Binder.restoreCallingIdentity(identity); | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8269 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8270 | return isEnabled; | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8271 | } | 
|  | 8272 |  | 
|  | 8273 |  | 
|  | 8274 | /** | 
|  | 8275 | * Enables/Disables the data roaming on the subscription with id {@code subId}. | 
|  | 8276 | * | 
|  | 8277 | * <p> Requires permission: | 
|  | 8278 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier | 
|  | 8279 | * privileges. | 
|  | 8280 | * | 
|  | 8281 | * @param subId subscription id | 
|  | 8282 | * @param isEnabled {@code true} means enable, {@code false} means disable. | 
|  | 8283 | */ | 
|  | 8284 | @Override | 
|  | 8285 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { | 
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8286 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 8287 | mApp, subId, "setDataRoamingEnabled"); | 
|  | 8288 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8289 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8290 | try { | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8291 | Phone phone = getPhone(subId); | 
|  | 8292 | if (phone != null) { | 
|  | 8293 | phone.setDataRoamingEnabled(isEnabled); | 
|  | 8294 | } | 
|  | 8295 | } finally { | 
|  | 8296 | Binder.restoreCallingIdentity(identity); | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8297 | } | 
|  | 8298 | } | 
|  | 8299 |  | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8300 | @Override | 
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8301 | public boolean isManualNetworkSelectionAllowed(int subId) { | 
| tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8302 | TelephonyPermissions | 
|  | 8303 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8304 | mApp, subId, "isManualNetworkSelectionAllowed"); | 
|  | 8305 |  | 
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8306 | boolean isAllowed = true; | 
|  | 8307 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8308 | try { | 
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8309 | Phone phone = getPhone(subId); | 
|  | 8310 | if (phone != null) { | 
|  | 8311 | isAllowed = phone.isCspPlmnEnabled(); | 
|  | 8312 | } | 
|  | 8313 | } finally { | 
|  | 8314 | Binder.restoreCallingIdentity(identity); | 
|  | 8315 | } | 
|  | 8316 | return isAllowed; | 
|  | 8317 | } | 
|  | 8318 |  | 
|  | 8319 | @Override | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8320 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { | 
| Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8321 | // Verify that tha callingPackage belongs to the calling UID | 
|  | 8322 | mApp.getSystemService(AppOpsManager.class) | 
|  | 8323 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 8324 |  | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8325 | boolean hasReadPermission = false; | 
| Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8326 | try { | 
|  | 8327 | enforceReadPrivilegedPermission("getUiccCardsInfo"); | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8328 | hasReadPermission = true; | 
| Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8329 | } catch (SecurityException e) { | 
|  | 8330 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller | 
|  | 8331 | // has carrier privileges on an active UICC | 
|  | 8332 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) | 
|  | 8333 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8334 | throw new SecurityException("Caller does not have permission."); | 
| Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8335 | } | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8336 | } | 
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8337 |  | 
|  | 8338 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8339 | try { | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8340 | UiccController uiccController = UiccController.getInstance(); | 
|  | 8341 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8342 | if (hasReadPermission) { | 
|  | 8343 | return cardInfos; | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8344 | } | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8345 |  | 
|  | 8346 | // Remove private info if the caller doesn't have access | 
|  | 8347 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); | 
|  | 8348 | for (UiccCardInfo cardInfo : cardInfos) { | 
|  | 8349 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo | 
|  | 8350 | // is available | 
|  | 8351 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); | 
|  | 8352 | if (card == null || card.getUiccProfile() == null) { | 
|  | 8353 | // assume no access if the card or profile is unavailable | 
|  | 8354 | filteredInfos.add(cardInfo.getUnprivileged()); | 
|  | 8355 | continue; | 
|  | 8356 | } | 
|  | 8357 | UiccProfile profile = card.getUiccProfile(); | 
|  | 8358 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) | 
|  | 8359 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
|  | 8360 | filteredInfos.add(cardInfo); | 
|  | 8361 | } else { | 
|  | 8362 | filteredInfos.add(cardInfo.getUnprivileged()); | 
|  | 8363 | } | 
|  | 8364 | } | 
|  | 8365 | return filteredInfos; | 
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8366 | } finally { | 
|  | 8367 | Binder.restoreCallingIdentity(identity); | 
|  | 8368 | } | 
|  | 8369 | } | 
|  | 8370 |  | 
|  | 8371 | @Override | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8372 | public UiccSlotInfo[] getUiccSlotsInfo() { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8373 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8374 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8375 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8376 | try { | 
|  | 8377 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); | 
|  | 8378 | if (slots == null) { | 
|  | 8379 | Rlog.i(LOG_TAG, "slots is null."); | 
|  | 8380 | return null; | 
|  | 8381 | } | 
|  | 8382 |  | 
|  | 8383 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; | 
|  | 8384 | for (int i = 0; i < slots.length; i++) { | 
|  | 8385 | UiccSlot slot = slots[i]; | 
|  | 8386 | if (slot == null) { | 
|  | 8387 | continue; | 
|  | 8388 | } | 
|  | 8389 |  | 
| Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8390 | String cardId; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8391 | UiccCard card = slot.getUiccCard(); | 
|  | 8392 | if (card != null) { | 
|  | 8393 | cardId = card.getCardId(); | 
| Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8394 | } else { | 
| Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8395 | cardId = slot.getEid(); | 
|  | 8396 | if (TextUtils.isEmpty(cardId)) { | 
|  | 8397 | cardId = slot.getIccId(); | 
|  | 8398 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8399 | } | 
|  | 8400 |  | 
| Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8401 | if (cardId != null) { | 
|  | 8402 | // if cardId is an ICCID, strip off trailing Fs before exposing to user | 
|  | 8403 | // if cardId is an EID, it's all digits so this is fine | 
|  | 8404 | cardId = IccUtils.stripTrailingFs(cardId); | 
|  | 8405 | } | 
|  | 8406 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8407 | int cardState = 0; | 
|  | 8408 | switch (slot.getCardState()) { | 
|  | 8409 | case CARDSTATE_ABSENT: | 
|  | 8410 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; | 
|  | 8411 | break; | 
|  | 8412 | case CARDSTATE_PRESENT: | 
|  | 8413 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; | 
|  | 8414 | break; | 
|  | 8415 | case CARDSTATE_ERROR: | 
|  | 8416 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; | 
|  | 8417 | break; | 
|  | 8418 | case CARDSTATE_RESTRICTED: | 
|  | 8419 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; | 
|  | 8420 | break; | 
|  | 8421 | default: | 
|  | 8422 | break; | 
|  | 8423 |  | 
|  | 8424 | } | 
|  | 8425 |  | 
|  | 8426 | infos[i] = new UiccSlotInfo( | 
|  | 8427 | slot.isActive(), | 
|  | 8428 | slot.isEuicc(), | 
|  | 8429 | cardId, | 
|  | 8430 | cardState, | 
|  | 8431 | slot.getPhoneId(), | 
| Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8432 | slot.isExtendedApduSupported(), | 
|  | 8433 | slot.isRemovable()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8434 | } | 
|  | 8435 | return infos; | 
|  | 8436 | } finally { | 
|  | 8437 | Binder.restoreCallingIdentity(identity); | 
| Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8438 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8439 | } | 
|  | 8440 |  | 
|  | 8441 | @Override | 
|  | 8442 | public boolean switchSlots(int[] physicalSlots) { | 
|  | 8443 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8444 |  | 
|  | 8445 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8446 | try { | 
|  | 8447 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); | 
|  | 8448 | } finally { | 
|  | 8449 | Binder.restoreCallingIdentity(identity); | 
|  | 8450 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8451 | } | 
| Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8452 |  | 
|  | 8453 | @Override | 
| Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8454 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { | 
| Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8455 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8456 | try { | 
|  | 8457 | return UiccController.getInstance().getCardIdForDefaultEuicc(); | 
|  | 8458 | } finally { | 
|  | 8459 | Binder.restoreCallingIdentity(identity); | 
|  | 8460 | } | 
|  | 8461 | } | 
|  | 8462 |  | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8463 | /** | 
| goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8464 | * A test API to reload the UICC profile. | 
|  | 8465 | * | 
|  | 8466 | * <p>Requires that the calling app has permission | 
|  | 8467 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. | 
|  | 8468 | * @hide | 
|  | 8469 | */ | 
|  | 8470 | @Override | 
|  | 8471 | public void refreshUiccProfile(int subId) { | 
|  | 8472 | enforceModifyPermission(); | 
|  | 8473 |  | 
|  | 8474 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8475 | try { | 
|  | 8476 | Phone phone = getPhone(subId); | 
|  | 8477 | if (phone == null) { | 
|  | 8478 | return; | 
|  | 8479 | } | 
|  | 8480 | UiccCard uiccCard = phone.getUiccCard(); | 
|  | 8481 | if (uiccCard == null) { | 
|  | 8482 | return; | 
|  | 8483 | } | 
|  | 8484 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); | 
|  | 8485 | if (uiccProfile == null) { | 
|  | 8486 | return; | 
|  | 8487 | } | 
|  | 8488 | uiccProfile.refresh(); | 
|  | 8489 | } finally { | 
|  | 8490 | Binder.restoreCallingIdentity(identity); | 
|  | 8491 | } | 
|  | 8492 | } | 
|  | 8493 |  | 
|  | 8494 | /** | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8495 | * Returns false if the mobile data is disabled by default, otherwise return true. | 
|  | 8496 | */ | 
|  | 8497 | private boolean getDefaultDataEnabled() { | 
| Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8498 | return TelephonyProperties.mobile_data().orElse(true); | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8499 | } | 
|  | 8500 |  | 
|  | 8501 | /** | 
|  | 8502 | * Returns true if the data roaming is enabled by default, i.e the system property | 
|  | 8503 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of | 
|  | 8504 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. | 
|  | 8505 | */ | 
|  | 8506 | private boolean getDefaultDataRoamingEnabled(int subId) { | 
|  | 8507 | final CarrierConfigManager configMgr = (CarrierConfigManager) | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8508 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8509 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8510 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( | 
|  | 8511 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); | 
|  | 8512 | return isDataRoamingEnabled; | 
|  | 8513 | } | 
|  | 8514 |  | 
|  | 8515 | /** | 
|  | 8516 | * Returns the default network type for the given {@code subId}, if the default network type is | 
|  | 8517 | * not set, return {@link Phone#PREFERRED_NT_MODE}. | 
|  | 8518 | */ | 
|  | 8519 | private int getDefaultNetworkType(int subId) { | 
| Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8520 | List<Integer> list = TelephonyProperties.default_network(); | 
|  | 8521 | int phoneId = mSubscriptionController.getPhoneId(subId); | 
|  | 8522 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { | 
|  | 8523 | return list.get(phoneId); | 
|  | 8524 | } | 
|  | 8525 | return Phone.PREFERRED_NT_MODE; | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8526 | } | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8527 |  | 
|  | 8528 | @Override | 
|  | 8529 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String | 
| chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8530 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8531 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8532 |  | 
|  | 8533 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8534 | try { | 
|  | 8535 | final Phone phone = getPhone(subId); | 
|  | 8536 | if (phone == null) { | 
|  | 8537 | loge("setCarrierTestOverride fails with invalid subId: " + subId); | 
|  | 8538 | return; | 
|  | 8539 | } | 
| chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8540 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, | 
|  | 8541 | carrierPrivilegeRules, apn); | 
| Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8542 | if (carrierPrivilegeRules == null) { | 
|  | 8543 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); | 
|  | 8544 | } else { | 
|  | 8545 | mCarrierPrivilegeTestOverrideSubIds.add(subId); | 
|  | 8546 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8547 | } finally { | 
|  | 8548 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8549 | } | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8550 | } | 
|  | 8551 |  | 
|  | 8552 | @Override | 
|  | 8553 | public int getCarrierIdListVersion(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8554 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8555 |  | 
|  | 8556 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8557 | try { | 
|  | 8558 | final Phone phone = getPhone(subId); | 
|  | 8559 | if (phone == null) { | 
|  | 8560 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); | 
|  | 8561 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; | 
|  | 8562 | } | 
|  | 8563 | return phone.getCarrierIdListVersion(); | 
|  | 8564 | } finally { | 
|  | 8565 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8566 | } | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8567 | } | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8568 |  | 
|  | 8569 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8570 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, | 
|  | 8571 | String callingFeatureId) { | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8572 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8573 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 8574 | "getNumberOfModemsWithSimultaneousDataConnections")) { | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8575 | return -1; | 
|  | 8576 | } | 
|  | 8577 |  | 
|  | 8578 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8579 | try { | 
|  | 8580 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); | 
|  | 8581 | } finally { | 
|  | 8582 | Binder.restoreCallingIdentity(identity); | 
|  | 8583 | } | 
|  | 8584 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8585 |  | 
|  | 8586 | @Override | 
|  | 8587 | public int getCdmaRoamingMode(int subId) { | 
| zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8588 | TelephonyPermissions | 
|  | 8589 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8590 | mApp, subId, "getCdmaRoamingMode"); | 
|  | 8591 |  | 
|  | 8592 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8593 | try { | 
|  | 8594 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); | 
|  | 8595 | } finally { | 
|  | 8596 | Binder.restoreCallingIdentity(identity); | 
|  | 8597 | } | 
|  | 8598 | } | 
|  | 8599 |  | 
|  | 8600 | @Override | 
|  | 8601 | public boolean setCdmaRoamingMode(int subId, int mode) { | 
|  | 8602 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 8603 | mApp, subId, "setCdmaRoamingMode"); | 
|  | 8604 |  | 
|  | 8605 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8606 | try { | 
|  | 8607 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); | 
|  | 8608 | } finally { | 
|  | 8609 | Binder.restoreCallingIdentity(identity); | 
|  | 8610 | } | 
|  | 8611 | } | 
|  | 8612 |  | 
|  | 8613 | @Override | 
| Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8614 | public int getCdmaSubscriptionMode(int subId) { | 
|  | 8615 | TelephonyPermissions | 
|  | 8616 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 8617 | mApp, subId, "getCdmaSubscriptionMode"); | 
|  | 8618 |  | 
|  | 8619 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8620 | try { | 
|  | 8621 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); | 
|  | 8622 | } finally { | 
|  | 8623 | Binder.restoreCallingIdentity(identity); | 
|  | 8624 | } | 
|  | 8625 | } | 
|  | 8626 |  | 
|  | 8627 | @Override | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8628 | public boolean setCdmaSubscriptionMode(int subId, int mode) { | 
|  | 8629 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 8630 | mApp, subId, "setCdmaSubscriptionMode"); | 
|  | 8631 |  | 
|  | 8632 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8633 | try { | 
|  | 8634 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); | 
|  | 8635 | } finally { | 
|  | 8636 | Binder.restoreCallingIdentity(identity); | 
|  | 8637 | } | 
|  | 8638 | } | 
| Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8639 |  | 
| sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8640 | @Override | 
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8641 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8642 | String callingPackage, String callingFeatureId) { | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8643 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8644 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, | 
|  | 8645 | "getEmergencyNumberList")) { | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8646 | throw new SecurityException("Requires READ_PHONE_STATE permission."); | 
|  | 8647 | } | 
|  | 8648 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8649 | try { | 
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8650 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); | 
|  | 8651 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 8652 | if (phone.getEmergencyNumberTracker() != null | 
|  | 8653 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { | 
|  | 8654 | emergencyNumberListInternal.put( | 
|  | 8655 | phone.getSubId(), | 
|  | 8656 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); | 
|  | 8657 | } | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8658 | } | 
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8659 | return emergencyNumberListInternal; | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8660 | } finally { | 
|  | 8661 | Binder.restoreCallingIdentity(identity); | 
|  | 8662 | } | 
| sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8663 | } | 
|  | 8664 |  | 
|  | 8665 | @Override | 
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8666 | public boolean isEmergencyNumber(String number, boolean exactMatch) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8667 | final Phone defaultPhone = getDefaultPhone(); | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8668 | if (!exactMatch) { | 
|  | 8669 | TelephonyPermissions | 
|  | 8670 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8671 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8672 | } | 
|  | 8673 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8674 | try { | 
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8675 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 8676 | if (phone.getEmergencyNumberTracker() != null | 
| Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8677 | && phone.getEmergencyNumberTracker() | 
|  | 8678 | .isEmergencyNumber(number, exactMatch)) { | 
|  | 8679 | return true; | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8680 | } | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8681 | } | 
|  | 8682 | return false; | 
|  | 8683 | } finally { | 
|  | 8684 | Binder.restoreCallingIdentity(identity); | 
|  | 8685 | } | 
|  | 8686 | } | 
|  | 8687 |  | 
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8688 | /** | 
| Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 8689 | * Start emergency callback mode for GsmCdmaPhone for testing. | 
|  | 8690 | */ | 
|  | 8691 | @Override | 
|  | 8692 | public void startEmergencyCallbackMode() { | 
|  | 8693 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 8694 | "startEmergencyCallbackMode"); | 
|  | 8695 | enforceModifyPermission(); | 
|  | 8696 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8697 | try { | 
|  | 8698 | for (Phone phone : PhoneFactory.getPhones()) { | 
|  | 8699 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); | 
|  | 8700 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) | 
|  | 8701 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { | 
|  | 8702 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; | 
|  | 8703 | gsmCdmaPhone.obtainMessage( | 
|  | 8704 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); | 
|  | 8705 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); | 
|  | 8706 | } | 
|  | 8707 | } | 
|  | 8708 | } finally { | 
|  | 8709 | Binder.restoreCallingIdentity(identity); | 
|  | 8710 | } | 
|  | 8711 | } | 
|  | 8712 |  | 
|  | 8713 | /** | 
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8714 | * Update emergency number list for test mode. | 
|  | 8715 | */ | 
|  | 8716 | @Override | 
|  | 8717 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { | 
|  | 8718 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 8719 | "updateEmergencyNumberListTestMode"); | 
|  | 8720 |  | 
|  | 8721 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8722 | try { | 
|  | 8723 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 8724 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 8725 | if (tracker != null) { | 
|  | 8726 | tracker.executeEmergencyNumberTestModeCommand(action, num); | 
|  | 8727 | } | 
|  | 8728 | } | 
|  | 8729 | } finally { | 
|  | 8730 | Binder.restoreCallingIdentity(identity); | 
|  | 8731 | } | 
|  | 8732 | } | 
|  | 8733 |  | 
|  | 8734 | /** | 
|  | 8735 | * Get the full emergency number list for test mode. | 
|  | 8736 | */ | 
|  | 8737 | @Override | 
|  | 8738 | public List<String> getEmergencyNumberListTestMode() { | 
|  | 8739 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 8740 | "getEmergencyNumberListTestMode"); | 
|  | 8741 |  | 
|  | 8742 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8743 | try { | 
|  | 8744 | Set<String> emergencyNumbers = new HashSet<>(); | 
|  | 8745 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 8746 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 8747 | if (tracker != null) { | 
|  | 8748 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { | 
|  | 8749 | emergencyNumbers.add(num.getNumber()); | 
|  | 8750 | } | 
|  | 8751 | } | 
|  | 8752 | } | 
|  | 8753 | return new ArrayList<>(emergencyNumbers); | 
|  | 8754 | } finally { | 
|  | 8755 | Binder.restoreCallingIdentity(identity); | 
|  | 8756 | } | 
|  | 8757 | } | 
|  | 8758 |  | 
| chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8759 | @Override | 
| Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8760 | public int getEmergencyNumberDbVersion(int subId) { | 
|  | 8761 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); | 
|  | 8762 |  | 
|  | 8763 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8764 | try { | 
|  | 8765 | final Phone phone = getPhone(subId); | 
|  | 8766 | if (phone == null) { | 
|  | 8767 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); | 
|  | 8768 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; | 
|  | 8769 | } | 
|  | 8770 | return phone.getEmergencyNumberDbVersion(); | 
|  | 8771 | } finally { | 
|  | 8772 | Binder.restoreCallingIdentity(identity); | 
|  | 8773 | } | 
|  | 8774 | } | 
|  | 8775 |  | 
|  | 8776 | @Override | 
|  | 8777 | public void notifyOtaEmergencyNumberDbInstalled() { | 
|  | 8778 | enforceModifyPermission(); | 
|  | 8779 |  | 
|  | 8780 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8781 | try { | 
|  | 8782 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 8783 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 8784 | if (tracker != null) { | 
|  | 8785 | tracker.updateOtaEmergencyNumberDatabase(); | 
|  | 8786 | } | 
|  | 8787 | } | 
|  | 8788 | } finally { | 
|  | 8789 | Binder.restoreCallingIdentity(identity); | 
|  | 8790 | } | 
|  | 8791 | } | 
|  | 8792 |  | 
|  | 8793 | @Override | 
| Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8794 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { | 
| Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8795 | enforceActiveEmergencySessionPermission(); | 
|  | 8796 |  | 
|  | 8797 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8798 | try { | 
|  | 8799 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 8800 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 8801 | if (tracker != null) { | 
| Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8802 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); | 
|  | 8803 | } | 
|  | 8804 | } | 
|  | 8805 | } finally { | 
|  | 8806 | Binder.restoreCallingIdentity(identity); | 
|  | 8807 | } | 
|  | 8808 | } | 
|  | 8809 |  | 
|  | 8810 | @Override | 
|  | 8811 | public void resetOtaEmergencyNumberDbFilePath() { | 
|  | 8812 | enforceActiveEmergencySessionPermission(); | 
|  | 8813 |  | 
|  | 8814 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8815 | try { | 
|  | 8816 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 8817 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 8818 | if (tracker != null) { | 
|  | 8819 | tracker.resetOtaEmergencyNumberDbFilePath(); | 
| Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8820 | } | 
|  | 8821 | } | 
|  | 8822 | } finally { | 
|  | 8823 | Binder.restoreCallingIdentity(identity); | 
|  | 8824 | } | 
|  | 8825 | } | 
|  | 8826 |  | 
|  | 8827 | @Override | 
| chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8828 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { | 
|  | 8829 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); | 
|  | 8830 | Phone phone = getPhone(subId); | 
|  | 8831 | if (phone == null) { | 
|  | 8832 | return null; | 
|  | 8833 | } | 
|  | 8834 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8835 | try { | 
|  | 8836 | UiccProfile profile = UiccController.getInstance() | 
|  | 8837 | .getUiccProfileForPhone(phone.getPhoneId()); | 
|  | 8838 | if (profile != null) { | 
|  | 8839 | return profile.getCertsFromCarrierPrivilegeAccessRules(); | 
|  | 8840 | } | 
|  | 8841 | } finally { | 
|  | 8842 | Binder.restoreCallingIdentity(identity); | 
|  | 8843 | } | 
|  | 8844 | return null; | 
|  | 8845 | } | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8846 |  | 
|  | 8847 | /** | 
|  | 8848 | * Enable or disable a modem stack. | 
|  | 8849 | */ | 
|  | 8850 | @Override | 
|  | 8851 | public boolean enableModemForSlot(int slotIndex, boolean enable) { | 
|  | 8852 | enforceModifyPermission(); | 
|  | 8853 |  | 
|  | 8854 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8855 | try { | 
|  | 8856 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 8857 | if (phone == null) { | 
|  | 8858 | return false; | 
|  | 8859 | } else { | 
|  | 8860 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); | 
|  | 8861 | } | 
|  | 8862 | } finally { | 
|  | 8863 | Binder.restoreCallingIdentity(identity); | 
|  | 8864 | } | 
|  | 8865 | } | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8866 |  | 
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8867 | /** | 
|  | 8868 | * Whether a modem stack is enabled or not. | 
|  | 8869 | */ | 
|  | 8870 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8871 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, | 
|  | 8872 | String callingFeatureId) { | 
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8873 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 8874 | if (phone == null) return false; | 
|  | 8875 |  | 
|  | 8876 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8877 | mApp, phone.getSubId(), callingPackage, callingFeatureId, | 
|  | 8878 | "isModemEnabledForSlot")) { | 
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8879 | throw new SecurityException("Requires READ_PHONE_STATE permission."); | 
|  | 8880 | } | 
|  | 8881 |  | 
|  | 8882 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8883 | try { | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8884 | try { | 
|  | 8885 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); | 
|  | 8886 | } catch (NoSuchElementException ex) { | 
|  | 8887 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); | 
|  | 8888 | } | 
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8889 | } finally { | 
|  | 8890 | Binder.restoreCallingIdentity(identity); | 
|  | 8891 | } | 
|  | 8892 | } | 
|  | 8893 |  | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8894 | @Override | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8895 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8896 | enforceModifyPermission(); | 
|  | 8897 |  | 
|  | 8898 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8899 | try { | 
|  | 8900 | mTelephonySharedPreferences.edit() | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8901 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8902 | .commit(); | 
|  | 8903 | } finally { | 
|  | 8904 | Binder.restoreCallingIdentity(identity); | 
|  | 8905 | } | 
|  | 8906 | } | 
|  | 8907 |  | 
|  | 8908 | @Override | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8909 | @TelephonyManager.IsMultiSimSupportedResult | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8910 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { | 
| Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8911 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8912 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, | 
|  | 8913 | "isMultiSimSupported")) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8914 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8915 | } | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8916 |  | 
|  | 8917 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8918 | try { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8919 | return isMultiSimSupportedInternal(); | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8920 | } finally { | 
|  | 8921 | Binder.restoreCallingIdentity(identity); | 
|  | 8922 | } | 
|  | 8923 | } | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8924 |  | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8925 | @TelephonyManager.IsMultiSimSupportedResult | 
|  | 8926 | private int isMultiSimSupportedInternal() { | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8927 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. | 
|  | 8928 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; | 
|  | 8929 | if (numPhysicalSlots < 2) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8930 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); | 
|  | 8931 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8932 | } | 
|  | 8933 | // Check if the hardware supports multisim functionality. If usage of multisim is not | 
|  | 8934 | // supported by the modem, indicate that it is restricted. | 
|  | 8935 | PhoneCapability staticCapability = | 
|  | 8936 | mPhoneConfigurationManager.getStaticPhoneCapability(); | 
|  | 8937 | if (staticCapability == null) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8938 | loge("isMultiSimSupportedInternal: no static configuration available"); | 
|  | 8939 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8940 | } | 
| SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 8941 | if (staticCapability.getLogicalModemList().size() < 2) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8942 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); | 
|  | 8943 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8944 | } | 
|  | 8945 | // Check if support of multiple SIMs is restricted by carrier | 
|  | 8946 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8947 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8948 | } | 
|  | 8949 |  | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8950 | return TelephonyManager.MULTISIM_ALLOWED; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8951 | } | 
|  | 8952 |  | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8953 | /** | 
|  | 8954 | * Switch configs to enable multi-sim or switch back to single-sim | 
| Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8955 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE | 
|  | 8956 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE | 
|  | 8957 | * or carrier privileges | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8958 | * @param numOfSims number of active sims we want to switch to | 
|  | 8959 | */ | 
|  | 8960 | @Override | 
|  | 8961 | public void switchMultiSimConfig(int numOfSims) { | 
| Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8962 | if (numOfSims == 1) { | 
|  | 8963 | enforceModifyPermission(); | 
|  | 8964 | } else { | 
|  | 8965 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 8966 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); | 
|  | 8967 | } | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8968 | final long identity = Binder.clearCallingIdentity(); | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8969 |  | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8970 | try { | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8971 | //only proceed if multi-sim is not restricted | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8972 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8973 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); | 
|  | 8974 | return; | 
|  | 8975 | } | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8976 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); | 
|  | 8977 | } finally { | 
|  | 8978 | Binder.restoreCallingIdentity(identity); | 
|  | 8979 | } | 
|  | 8980 | } | 
|  | 8981 |  | 
| Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8982 | @Override | 
|  | 8983 | public boolean isApplicationOnUicc(int subId, int appType) { | 
|  | 8984 | enforceReadPrivilegedPermission("isApplicationOnUicc"); | 
|  | 8985 | Phone phone = getPhone(subId); | 
|  | 8986 | if (phone == null) { | 
|  | 8987 | return false; | 
|  | 8988 | } | 
|  | 8989 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8990 | try { | 
|  | 8991 | UiccCard uiccCard = phone.getUiccCard(); | 
|  | 8992 | if (uiccCard == null) { | 
|  | 8993 | return false; | 
|  | 8994 | } | 
|  | 8995 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); | 
|  | 8996 | if (uiccProfile == null) { | 
|  | 8997 | return false; | 
|  | 8998 | } | 
|  | 8999 | if (TelephonyManager.APPTYPE_SIM <= appType | 
|  | 9000 | && appType <= TelephonyManager.APPTYPE_ISIM) { | 
|  | 9001 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); | 
|  | 9002 | } | 
|  | 9003 | return false; | 
|  | 9004 | } finally { | 
|  | 9005 | Binder.restoreCallingIdentity(identity); | 
|  | 9006 | } | 
|  | 9007 | } | 
|  | 9008 |  | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9009 | /** | 
| chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9010 | * Get whether making changes to modem configurations will trigger reboot. | 
|  | 9011 | * Return value defaults to true. | 
| Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9012 | */ | 
|  | 9013 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9014 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, | 
|  | 9015 | String callingFeatureId) { | 
| chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9016 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9017 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 9018 | "doesSwitchMultiSimConfigTriggerReboot")) { | 
| chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9019 | return false; | 
|  | 9020 | } | 
| Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9021 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9022 | try { | 
|  | 9023 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); | 
|  | 9024 | } finally { | 
|  | 9025 | Binder.restoreCallingIdentity(identity); | 
|  | 9026 | } | 
|  | 9027 | } | 
|  | 9028 |  | 
| Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9029 | private void updateModemStateMetrics() { | 
|  | 9030 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); | 
|  | 9031 | // TODO: check the state for each modem if the api is ready. | 
|  | 9032 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); | 
|  | 9033 | } | 
|  | 9034 |  | 
| Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9035 | @Override | 
|  | 9036 | public int[] getSlotsMapping() { | 
|  | 9037 | enforceReadPrivilegedPermission("getSlotsMapping"); | 
|  | 9038 |  | 
|  | 9039 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9040 | try { | 
|  | 9041 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); | 
|  | 9042 | // All logical slots should have a mapping to a physical slot. | 
|  | 9043 | int[] logicalSlotsMapping = new int[phoneCount]; | 
|  | 9044 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); | 
|  | 9045 | for (int i = 0; i < slotInfos.length; i++) { | 
|  | 9046 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { | 
|  | 9047 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; | 
|  | 9048 | } | 
|  | 9049 | } | 
|  | 9050 | return logicalSlotsMapping; | 
|  | 9051 | } finally { | 
|  | 9052 | Binder.restoreCallingIdentity(identity); | 
|  | 9053 | } | 
|  | 9054 | } | 
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9055 |  | 
|  | 9056 | /** | 
|  | 9057 | * Get the IRadio HAL Version | 
|  | 9058 | */ | 
|  | 9059 | @Override | 
|  | 9060 | public int getRadioHalVersion() { | 
|  | 9061 | Phone phone = getDefaultPhone(); | 
|  | 9062 | if (phone == null) return -1; | 
|  | 9063 | HalVersion hv = phone.getHalVersion(); | 
|  | 9064 | if (hv.equals(HalVersion.UNKNOWN)) return -1; | 
|  | 9065 | return hv.major * 100 + hv.minor; | 
|  | 9066 | } | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9067 |  | 
|  | 9068 | /** | 
| Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9069 | * Get the current calling package name. | 
|  | 9070 | * @return the current calling package name | 
|  | 9071 | */ | 
|  | 9072 | @Override | 
|  | 9073 | public String getCurrentPackageName() { | 
|  | 9074 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; | 
|  | 9075 | } | 
|  | 9076 |  | 
|  | 9077 | /** | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9078 | * Return whether data is enabled for certain APN type. This will tell if framework will accept | 
|  | 9079 | * corresponding network requests on a subId. | 
|  | 9080 | * | 
|  | 9081 | *  Data is enabled if: | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9082 | *  1) user data is turned on, or | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9083 | *  2) APN is un-metered for this subscription, or | 
|  | 9084 | *  3) APN type is whitelisted. E.g. MMS is whitelisted if | 
| Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9085 | *  {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9086 | * | 
|  | 9087 | * @return whether data is allowed for a apn type. | 
|  | 9088 | * | 
|  | 9089 | * @hide | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9090 | */ | 
|  | 9091 | @Override | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9092 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { | 
| Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9093 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " | 
|  | 9094 | + "isDataEnabledForApn"); | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9095 |  | 
|  | 9096 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 9097 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9098 | try { | 
|  | 9099 | Phone phone = getPhone(subId); | 
|  | 9100 | if (phone == null) return false; | 
|  | 9101 |  | 
| Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9102 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9103 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); | 
|  | 9104 | } finally { | 
|  | 9105 | Binder.restoreCallingIdentity(identity); | 
|  | 9106 | } | 
|  | 9107 | } | 
|  | 9108 |  | 
|  | 9109 | @Override | 
| Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9110 | public boolean isApnMetered(@ApnType int apnType, int subId) { | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9111 | enforceReadPrivilegedPermission("isApnMetered"); | 
|  | 9112 |  | 
|  | 9113 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 9114 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9115 | try { | 
|  | 9116 | Phone phone = getPhone(subId); | 
|  | 9117 | if (phone == null) return true; // By default return true. | 
|  | 9118 |  | 
| Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9119 | return ApnSettingUtils.isMeteredApnType(apnType, phone); | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9120 | } finally { | 
|  | 9121 | Binder.restoreCallingIdentity(identity); | 
|  | 9122 | } | 
|  | 9123 | } | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9124 |  | 
|  | 9125 | @Override | 
| Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9126 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, | 
|  | 9127 | int subscriptionId, IBooleanConsumer resultCallback) { | 
|  | 9128 | enforceModifyPermission(); | 
|  | 9129 | long token = Binder.clearCallingIdentity(); | 
|  | 9130 | try { | 
|  | 9131 | Phone phone = getPhone(subscriptionId); | 
|  | 9132 | if (phone == null) { | 
|  | 9133 | try { | 
|  | 9134 | if (resultCallback != null) { | 
|  | 9135 | resultCallback.accept(false); | 
|  | 9136 | } | 
|  | 9137 | } catch (RemoteException e) { | 
|  | 9138 | // ignore | 
|  | 9139 | } | 
|  | 9140 | return; | 
|  | 9141 | } | 
|  | 9142 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = | 
|  | 9143 | Pair.create(specifiers, (x) -> { | 
|  | 9144 | try { | 
|  | 9145 | if (resultCallback != null) { | 
|  | 9146 | resultCallback.accept(x); | 
|  | 9147 | } | 
|  | 9148 | } catch (RemoteException e) { | 
|  | 9149 | // ignore | 
|  | 9150 | } | 
|  | 9151 | }); | 
|  | 9152 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); | 
|  | 9153 | } finally { | 
|  | 9154 | Binder.restoreCallingIdentity(token); | 
|  | 9155 | } | 
|  | 9156 | } | 
|  | 9157 |  | 
|  | 9158 | @Override | 
| Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9159 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { | 
|  | 9160 | TelephonyPermissions | 
|  | 9161 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 9162 | mApp, subId, "getSystemSelectionChannels"); | 
|  | 9163 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 9164 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9165 | try { | 
|  | 9166 | List<RadioAccessSpecifier> specifiers = | 
|  | 9167 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, | 
|  | 9168 | null, subId, workSource); | 
|  | 9169 | if (DBG) log("getSystemSelectionChannels: " + specifiers); | 
|  | 9170 | return specifiers; | 
|  | 9171 | } finally { | 
|  | 9172 | Binder.restoreCallingIdentity(identity); | 
|  | 9173 | } | 
|  | 9174 | } | 
|  | 9175 |  | 
|  | 9176 | @Override | 
| changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9177 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { | 
| changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9178 | enforceReadPrivilegedPermission("isMvnoMatched"); | 
| changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9179 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( | 
|  | 9180 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); | 
|  | 9181 | if (iccRecords == null) { | 
|  | 9182 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); | 
|  | 9183 | return false; | 
|  | 9184 | } | 
|  | 9185 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); | 
|  | 9186 | } | 
|  | 9187 |  | 
|  | 9188 | @Override | 
| Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9189 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, | 
|  | 9190 | IIntegerConsumer pendingSubIdResult) { | 
| Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9191 | if (callingPackage == null) { | 
|  | 9192 | callingPackage = getCurrentPackageName(); | 
|  | 9193 | } | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9194 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, | 
|  | 9195 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); | 
| Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9196 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, | 
|  | 9197 | "Sending message")) { | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9198 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); | 
|  | 9199 | } | 
|  | 9200 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); | 
|  | 9201 | Intent intent = new Intent(); | 
|  | 9202 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); | 
|  | 9203 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
|  | 9204 | // Bring up choose default SMS subscription dialog right now | 
|  | 9205 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, | 
|  | 9206 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); | 
|  | 9207 | mApp.startActivity(intent); | 
|  | 9208 | } | 
| chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9209 |  | 
|  | 9210 | @Override | 
|  | 9211 | public String getMmsUAProfUrl(int subId) { | 
|  | 9212 | //TODO investigate if this API should require proper permission check in R b/133791609 | 
|  | 9213 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9214 | try { | 
| Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9215 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( | 
|  | 9216 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); | 
|  | 9217 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { | 
|  | 9218 | return carrierUAProfUrl; | 
|  | 9219 | } | 
| Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9220 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) | 
|  | 9221 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); | 
| chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9222 | } finally { | 
|  | 9223 | Binder.restoreCallingIdentity(identity); | 
|  | 9224 | } | 
|  | 9225 | } | 
|  | 9226 |  | 
|  | 9227 | @Override | 
|  | 9228 | public String getMmsUserAgent(int subId) { | 
|  | 9229 | //TODO investigate if this API should require proper permission check in R b/133791609 | 
|  | 9230 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9231 | try { | 
| Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9232 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( | 
|  | 9233 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); | 
|  | 9234 | if (!TextUtils.isEmpty(carrierUserAgent)) { | 
|  | 9235 | return carrierUserAgent; | 
|  | 9236 | } | 
| Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9237 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) | 
|  | 9238 | .getString(com.android.internal.R.string.config_mms_user_agent); | 
| chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9239 | } finally { | 
|  | 9240 | Binder.restoreCallingIdentity(identity); | 
|  | 9241 | } | 
|  | 9242 | } | 
| Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9243 |  | 
|  | 9244 | @Override | 
| Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9245 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { | 
|  | 9246 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); | 
| Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9247 |  | 
| Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9248 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9249 | try { | 
| Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9250 | Phone phone = getPhone(subscriptionId); | 
| Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9251 | if (phone == null) return false; | 
|  | 9252 |  | 
| Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9253 | switch (policy) { | 
|  | 9254 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: | 
|  | 9255 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); | 
|  | 9256 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: | 
|  | 9257 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); | 
|  | 9258 | default: | 
|  | 9259 | throw new IllegalArgumentException(policy + " is not a valid policy"); | 
|  | 9260 | } | 
| Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9261 | } finally { | 
|  | 9262 | Binder.restoreCallingIdentity(identity); | 
|  | 9263 | } | 
|  | 9264 | } | 
|  | 9265 |  | 
|  | 9266 | @Override | 
| Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9267 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, | 
| Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9268 | boolean enabled) { | 
| changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9269 | enforceModifyPermission(); | 
|  | 9270 |  | 
| changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9271 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9272 | try { | 
| Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9273 | Phone phone = getPhone(subscriptionId); | 
|  | 9274 | if (phone == null) return; | 
| changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9275 |  | 
| Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9276 | switch (policy) { | 
|  | 9277 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: | 
|  | 9278 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); | 
|  | 9279 | break; | 
|  | 9280 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: | 
|  | 9281 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); | 
|  | 9282 | break; | 
|  | 9283 | default: | 
|  | 9284 | throw new IllegalArgumentException(policy + " is not a valid policy"); | 
|  | 9285 | } | 
| changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9286 | } finally { | 
|  | 9287 | Binder.restoreCallingIdentity(identity); | 
|  | 9288 | } | 
|  | 9289 | } | 
|  | 9290 |  | 
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9291 | /** | 
| Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9292 | * Updates whether conference event package handling is enabled. | 
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9293 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} | 
|  | 9294 | *                                 otherwise. | 
|  | 9295 | */ | 
|  | 9296 | @Override | 
|  | 9297 | public void setCepEnabled(boolean isCepEnabled) { | 
|  | 9298 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); | 
|  | 9299 |  | 
|  | 9300 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9301 | try { | 
|  | 9302 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); | 
|  | 9303 | for (Phone phone : PhoneFactory.getPhones()) { | 
|  | 9304 | Phone defaultPhone = phone.getImsPhone(); | 
|  | 9305 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { | 
|  | 9306 | ImsPhone imsPhone = (ImsPhone) defaultPhone; | 
|  | 9307 | ImsPhoneCallTracker imsPhoneCallTracker = | 
|  | 9308 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); | 
|  | 9309 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); | 
|  | 9310 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " | 
|  | 9311 | + imsPhone.getMsisdn()); | 
|  | 9312 | } | 
|  | 9313 | } | 
|  | 9314 | } finally { | 
|  | 9315 | Binder.restoreCallingIdentity(identity); | 
|  | 9316 | } | 
|  | 9317 | } | 
| allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9318 |  | 
|  | 9319 | /** | 
|  | 9320 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. | 
|  | 9321 | * | 
|  | 9322 | * @param config       The XML file to be read. ASCII/UTF8 encoded text if not compressed. | 
|  | 9323 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed | 
|  | 9324 | *                     before being read. | 
|  | 9325 | */ | 
|  | 9326 | @Override | 
|  | 9327 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean | 
|  | 9328 | isCompressed) { | 
|  | 9329 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 9330 | mApp, subId, "notifyRcsAutoConfigurationReceived"); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9331 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 9332 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 9333 | } | 
|  | 9334 | if (!isImsAvailableOnDevice()) { | 
|  | 9335 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 9336 | "IMS not available on device."); | 
|  | 9337 | } | 
|  | 9338 |  | 
|  | 9339 | final long identity = Binder.clearCallingIdentity(); | 
| allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9340 | try { | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9341 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); | 
|  | 9342 | } finally { | 
|  | 9343 | Binder.restoreCallingIdentity(identity); | 
| allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9344 | } | 
|  | 9345 | } | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9346 |  | 
|  | 9347 | @Override | 
|  | 9348 | public boolean isIccLockEnabled(int subId) { | 
|  | 9349 | enforceReadPrivilegedPermission("isIccLockEnabled"); | 
|  | 9350 |  | 
|  | 9351 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 9352 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9353 | try { | 
|  | 9354 | Phone phone = getPhone(subId); | 
|  | 9355 | if (phone != null && phone.getIccCard() != null) { | 
|  | 9356 | return phone.getIccCard().getIccLockEnabled(); | 
|  | 9357 | } else { | 
|  | 9358 | return false; | 
|  | 9359 | } | 
|  | 9360 | } finally { | 
|  | 9361 | Binder.restoreCallingIdentity(identity); | 
|  | 9362 | } | 
|  | 9363 | } | 
|  | 9364 |  | 
|  | 9365 | /** | 
|  | 9366 | * Set the ICC pin lock enabled or disabled. | 
|  | 9367 | * | 
|  | 9368 | * @return an integer representing the status of IccLock enabled or disabled in the following | 
|  | 9369 | * three cases: | 
|  | 9370 | *   - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock | 
|  | 9371 | *   successfully. | 
|  | 9372 | *   - Positive number and zero for remaining password attempts. | 
|  | 9373 | *   - Negative number for other failure cases (such like enabling/disabling PIN failed). | 
|  | 9374 | * | 
|  | 9375 | */ | 
|  | 9376 | @Override | 
|  | 9377 | public int setIccLockEnabled(int subId, boolean enabled, String password) { | 
|  | 9378 | enforceModifyPermission(); | 
|  | 9379 |  | 
|  | 9380 | Phone phone = getPhone(subId); | 
|  | 9381 | if (phone == null) { | 
|  | 9382 | return 0; | 
|  | 9383 | } | 
|  | 9384 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 9385 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9386 | try { | 
|  | 9387 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, | 
|  | 9388 | new Pair<Boolean, String>(enabled, password), phone, null); | 
|  | 9389 | return attemptsRemaining; | 
|  | 9390 |  | 
|  | 9391 | } catch (Exception e) { | 
|  | 9392 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); | 
|  | 9393 | } finally { | 
|  | 9394 | Binder.restoreCallingIdentity(identity); | 
|  | 9395 | } | 
|  | 9396 | return 0; | 
|  | 9397 | } | 
|  | 9398 |  | 
|  | 9399 | /** | 
|  | 9400 | * Change the ICC password used in ICC pin lock. | 
|  | 9401 | * | 
|  | 9402 | * @return an integer representing the status of IccLock changed in the following three cases: | 
|  | 9403 | *   - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. | 
|  | 9404 | *   - Positive number and zero for remaining password attempts. | 
|  | 9405 | *   - Negative number for other failure cases (such like enabling/disabling PIN failed). | 
|  | 9406 | * | 
|  | 9407 | */ | 
|  | 9408 | @Override | 
|  | 9409 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { | 
|  | 9410 | enforceModifyPermission(); | 
|  | 9411 |  | 
|  | 9412 | Phone phone = getPhone(subId); | 
|  | 9413 | if (phone == null) { | 
|  | 9414 | return 0; | 
|  | 9415 | } | 
|  | 9416 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 9417 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9418 | try { | 
|  | 9419 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, | 
|  | 9420 | new Pair<String, String>(oldPassword, newPassword), phone, null); | 
|  | 9421 | return attemptsRemaining; | 
|  | 9422 |  | 
|  | 9423 | } catch (Exception e) { | 
|  | 9424 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); | 
|  | 9425 | } finally { | 
|  | 9426 | Binder.restoreCallingIdentity(identity); | 
|  | 9427 | } | 
|  | 9428 | return 0; | 
|  | 9429 | } | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9430 |  | 
|  | 9431 | /** | 
|  | 9432 | * Request for receiving user activity notification | 
|  | 9433 | */ | 
|  | 9434 | @Override | 
|  | 9435 | public void requestUserActivityNotification() { | 
|  | 9436 | if (!mNotifyUserActivity.get() | 
|  | 9437 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { | 
|  | 9438 | mNotifyUserActivity.set(true); | 
|  | 9439 | } | 
|  | 9440 | } | 
|  | 9441 |  | 
|  | 9442 | /** | 
|  | 9443 | * Called when userActivity is signalled in the power manager. | 
|  | 9444 | * This is safe to call from any thread, with any window manager locks held or not. | 
|  | 9445 | */ | 
|  | 9446 | @Override | 
|  | 9447 | public void userActivity() { | 
|  | 9448 | // *************************************** | 
|  | 9449 | // *  Inherited from PhoneWindowManager  * | 
|  | 9450 | // *************************************** | 
|  | 9451 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER | 
|  | 9452 | // WITH ITS LOCKS HELD. | 
|  | 9453 | // | 
|  | 9454 | // This code must be VERY careful about the locks | 
|  | 9455 | // it acquires. | 
|  | 9456 | // In fact, the current code acquires way too many, | 
|  | 9457 | // and probably has lurking deadlocks. | 
|  | 9458 |  | 
|  | 9459 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { | 
|  | 9460 | throw new SecurityException("Only the OS may call notifyUserActivity()"); | 
|  | 9461 | } | 
|  | 9462 |  | 
|  | 9463 | if (mNotifyUserActivity.getAndSet(false)) { | 
|  | 9464 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, | 
|  | 9465 | USER_ACTIVITY_NOTIFICATION_DELAY); | 
|  | 9466 | } | 
|  | 9467 | } | 
| Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9468 |  | 
|  | 9469 | @Override | 
|  | 9470 | public boolean canConnectTo5GInDsdsMode() { | 
|  | 9471 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); | 
|  | 9472 | } | 
| Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9473 |  | 
|  | 9474 | @Override | 
|  | 9475 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, | 
|  | 9476 | String callingFeatureId) { | 
|  | 9477 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 9478 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { | 
|  | 9479 | throw new SecurityException("Requires READ_PHONE_STATE permission."); | 
|  | 9480 | } | 
|  | 9481 |  | 
|  | 9482 | Phone phone = getPhone(subId); | 
|  | 9483 | if (phone == null) { | 
|  | 9484 | throw new RuntimeException("phone is not available"); | 
|  | 9485 | } | 
|  | 9486 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 9487 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9488 | try { | 
|  | 9489 | return phone.getEquivalentHomePlmns(); | 
|  | 9490 | } finally { | 
|  | 9491 | Binder.restoreCallingIdentity(identity); | 
|  | 9492 | } | 
|  | 9493 | } | 
| Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9494 |  | 
|  | 9495 | @Override | 
|  | 9496 | public boolean isRadioInterfaceCapabilitySupported( | 
| Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9497 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { | 
|  | 9498 | Set<String> radioInterfaceCapabilities = | 
| Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 9499 | mRadioInterfaceCapabilities.getCapabilities(); | 
| Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9500 | if (radioInterfaceCapabilities == null) { | 
|  | 9501 | throw new RuntimeException("radio interface capabilities are not available"); | 
| Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9502 | } | 
| Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9503 | return radioInterfaceCapabilities.contains(capability); | 
| Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9504 | } | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9505 |  | 
| Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9506 | @Override | 
|  | 9507 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, | 
|  | 9508 | UaSecurityProtocolIdentifier securityProtocol, | 
| Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9509 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { | 
|  | 9510 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, | 
|  | 9511 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", | 
|  | 9512 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, | 
|  | 9513 | Manifest.permission.MODIFY_PHONE_STATE); | 
| Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9514 | if (DBG) { | 
|  | 9515 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" | 
|  | 9516 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol | 
|  | 9517 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); | 
|  | 9518 | } | 
|  | 9519 |  | 
|  | 9520 | if (!SubscriptionManager.isValidSubscriptionId(subId) | 
|  | 9521 | || appType < TelephonyManager.APPTYPE_UNKNOWN | 
|  | 9522 | || appType > TelephonyManager.APPTYPE_ISIM | 
|  | 9523 | || nafUrl == null || securityProtocol == null || callback == null) { | 
|  | 9524 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); | 
|  | 9525 | if (callback != null) { | 
|  | 9526 | try { | 
|  | 9527 | callback.onAuthenticationFailure( | 
|  | 9528 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); | 
|  | 9529 | } catch (RemoteException exception) { | 
|  | 9530 | log("Fail to notify onAuthenticationFailure due to " + exception); | 
|  | 9531 | } | 
|  | 9532 | return; | 
|  | 9533 | } | 
|  | 9534 | } | 
|  | 9535 |  | 
|  | 9536 | final long token = Binder.clearCallingIdentity(); | 
|  | 9537 | try { | 
|  | 9538 | getGbaManager(subId).bootstrapAuthenticationRequest( | 
|  | 9539 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), | 
|  | 9540 | forceBootStrapping, callback)); | 
|  | 9541 | } finally { | 
|  | 9542 | Binder.restoreCallingIdentity(token); | 
|  | 9543 | } | 
|  | 9544 | } | 
|  | 9545 |  | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9546 | /** | 
|  | 9547 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the | 
|  | 9548 | * requested radio power state will actually be set. See {@link | 
|  | 9549 | * PhoneInternalInterface#setRadioPowerForReason} for more details. | 
|  | 9550 | * | 
|  | 9551 | * @param subId the subscription ID of the phone requesting to set the radio power state. | 
|  | 9552 | * @param enable {@code true} if trying to turn radio on. | 
|  | 9553 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code | 
|  | 9554 | * false}. | 
|  | 9555 | */ | 
|  | 9556 | private boolean setRadioPowerForThermal(int subId, boolean enable) { | 
|  | 9557 | Phone phone = getPhone(subId); | 
|  | 9558 | if (phone != null) { | 
|  | 9559 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); | 
|  | 9560 | return true; | 
|  | 9561 | } | 
|  | 9562 | return false; | 
|  | 9563 | } | 
|  | 9564 |  | 
|  | 9565 | private int handleDataThrottlingRequest(int subId, | 
|  | 9566 | DataThrottlingRequest dataThrottlingRequest) { | 
|  | 9567 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return | 
|  | 9568 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. | 
|  | 9569 | if (!setRadioPowerForThermal(subId, true)) { | 
|  | 9570 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 9571 | } | 
|  | 9572 |  | 
|  | 9573 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); | 
|  | 9574 |  | 
|  | 9575 | int thermalMitigationResult = | 
|  | 9576 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); | 
|  | 9577 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { | 
|  | 9578 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); | 
|  | 9579 | } | 
|  | 9580 | return thermalMitigationResult; | 
|  | 9581 | } | 
|  | 9582 |  | 
|  | 9583 | /** | 
|  | 9584 | * Thermal mitigation request to control functionalities at modem. | 
|  | 9585 | * | 
|  | 9586 | * @param subId the id of the subscription. | 
|  | 9587 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. | 
|  | 9588 | * | 
|  | 9589 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. | 
|  | 9590 | */ | 
|  | 9591 | @Override | 
|  | 9592 | @ThermalMitigationResult | 
|  | 9593 | public int sendThermalMitigationRequest( | 
|  | 9594 | int subId, | 
|  | 9595 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { | 
|  | 9596 | enforceModifyPermission(); | 
|  | 9597 |  | 
|  | 9598 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 9599 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9600 |  | 
|  | 9601 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; | 
|  | 9602 | try { | 
|  | 9603 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); | 
|  | 9604 | switch (thermalMitigationAction) { | 
|  | 9605 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: | 
|  | 9606 | thermalMitigationResult = | 
|  | 9607 | handleDataThrottlingRequest(subId, | 
|  | 9608 | thermalMitigationRequest.getDataThrottlingRequest()); | 
|  | 9609 | break; | 
|  | 9610 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: | 
|  | 9611 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { | 
|  | 9612 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " | 
|  | 9613 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); | 
|  | 9614 | } | 
|  | 9615 |  | 
|  | 9616 | // Ensure that radio is on. If not able to power on due to phone being | 
|  | 9617 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. | 
|  | 9618 | if (!setRadioPowerForThermal(subId, true)) { | 
|  | 9619 | thermalMitigationResult = | 
|  | 9620 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 9621 | break; | 
|  | 9622 | } | 
|  | 9623 |  | 
|  | 9624 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, | 
|  | 9625 | false); | 
|  | 9626 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; | 
|  | 9627 | break; | 
|  | 9628 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: | 
|  | 9629 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { | 
|  | 9630 | throw new IllegalArgumentException("dataThrottlingRequest  must be null for" | 
|  | 9631 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); | 
|  | 9632 | } | 
|  | 9633 |  | 
|  | 9634 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); | 
|  | 9635 | if (registry != null) { | 
|  | 9636 | TelephonyConnectionService service = | 
|  | 9637 | registry.getTelephonyConnectionService(); | 
|  | 9638 | Phone phone = getPhone(subId); | 
|  | 9639 | if (phone == null) { | 
|  | 9640 | thermalMitigationResult = | 
|  | 9641 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 9642 | break; | 
|  | 9643 | } | 
|  | 9644 |  | 
|  | 9645 | if (PhoneConstantConversions.convertCallState(phone.getState()) | 
|  | 9646 | != TelephonyManager.CALL_STATE_IDLE | 
|  | 9647 | || phone.isInEmergencySmsMode() || phone.isInEcm() | 
|  | 9648 | || (service != null && service.isEmergencyCallPending())) { | 
|  | 9649 | String errorMessage = "Phone state is not valid. call state = " | 
|  | 9650 | + PhoneConstantConversions.convertCallState(phone.getState()) | 
|  | 9651 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() | 
|  | 9652 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); | 
|  | 9653 | errorMessage += service == null | 
|  | 9654 | ? " TelephonyConnectionService is null" | 
|  | 9655 | : " isEmergencyCallPending = " | 
|  | 9656 | + service.isEmergencyCallPending(); | 
|  | 9657 | Log.e(LOG_TAG, errorMessage); | 
|  | 9658 | thermalMitigationResult = | 
|  | 9659 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; | 
|  | 9660 | break; | 
|  | 9661 | } | 
|  | 9662 | } else { | 
|  | 9663 | thermalMitigationResult = | 
|  | 9664 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 9665 | break; | 
|  | 9666 | } | 
|  | 9667 |  | 
|  | 9668 | // Turn radio off. If not able to power off due to phone being unavailable, | 
|  | 9669 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. | 
|  | 9670 | if (!setRadioPowerForThermal(subId, false)) { | 
|  | 9671 | thermalMitigationResult = | 
|  | 9672 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 9673 | break; | 
|  | 9674 | } | 
|  | 9675 | thermalMitigationResult = | 
|  | 9676 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; | 
|  | 9677 | break; | 
|  | 9678 | default: | 
|  | 9679 | throw new IllegalArgumentException("the requested thermalMitigationAction does " | 
|  | 9680 | + "not exist. Requested action: " + thermalMitigationAction); | 
|  | 9681 | } | 
|  | 9682 | } catch (IllegalArgumentException e) { | 
|  | 9683 | throw e; | 
|  | 9684 | } catch (Exception e) { | 
|  | 9685 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); | 
|  | 9686 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; | 
|  | 9687 | } finally { | 
|  | 9688 | Binder.restoreCallingIdentity(identity); | 
|  | 9689 | } | 
|  | 9690 |  | 
|  | 9691 | if (DBG) { | 
|  | 9692 | log("thermalMitigationRequest returning with thermalMitigationResult: " | 
|  | 9693 | + thermalMitigationResult); | 
|  | 9694 | } | 
|  | 9695 |  | 
|  | 9696 | return thermalMitigationResult; | 
|  | 9697 | } | 
| Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9698 |  | 
|  | 9699 | /** | 
|  | 9700 | * Set the GbaService Package Name that Telephony will bind to. | 
|  | 9701 | * | 
|  | 9702 | * @param subId The sim that the GbaService is associated with. | 
|  | 9703 | * @param packageName The name of the package to be replaced with. | 
|  | 9704 | * @return true if setting the GbaService to bind to succeeded, false if it did not. | 
|  | 9705 | */ | 
|  | 9706 | @Override | 
|  | 9707 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { | 
|  | 9708 | enforceModifyPermission(); | 
|  | 9709 |  | 
|  | 9710 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9711 | try { | 
|  | 9712 | return getGbaManager(subId).overrideServicePackage(packageName); | 
|  | 9713 | } finally { | 
|  | 9714 | Binder.restoreCallingIdentity(identity); | 
|  | 9715 | } | 
|  | 9716 | } | 
|  | 9717 |  | 
|  | 9718 | /** | 
|  | 9719 | * Return the package name of the currently bound GbaService. | 
|  | 9720 | * | 
|  | 9721 | * @param subId The sim that the GbaService is associated with. | 
|  | 9722 | * @return the package name of the GbaService configuration, null if GBA is not supported. | 
|  | 9723 | */ | 
|  | 9724 | @Override | 
|  | 9725 | public String getBoundGbaService(int subId) { | 
|  | 9726 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); | 
|  | 9727 |  | 
|  | 9728 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9729 | try { | 
|  | 9730 | return getGbaManager(subId).getServicePackage(); | 
|  | 9731 | } finally { | 
|  | 9732 | Binder.restoreCallingIdentity(identity); | 
|  | 9733 | } | 
|  | 9734 | } | 
|  | 9735 |  | 
|  | 9736 | /** | 
|  | 9737 | * Set the release time for telephony to unbind GbaService. | 
|  | 9738 | * | 
|  | 9739 | * @param subId The sim that the GbaService is associated with. | 
|  | 9740 | * @param interval The release time to unbind GbaService by millisecond. | 
|  | 9741 | * @return true if setting the GbaService to bind to succeeded, false if it did not. | 
|  | 9742 | */ | 
|  | 9743 | @Override | 
|  | 9744 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { | 
|  | 9745 | enforceModifyPermission(); | 
|  | 9746 |  | 
|  | 9747 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9748 | try { | 
|  | 9749 | return getGbaManager(subId).overrideReleaseTime(interval); | 
|  | 9750 | } finally { | 
|  | 9751 | Binder.restoreCallingIdentity(identity); | 
|  | 9752 | } | 
|  | 9753 | } | 
|  | 9754 |  | 
|  | 9755 | /** | 
|  | 9756 | * Return the release time for telephony to unbind GbaService. | 
|  | 9757 | * | 
|  | 9758 | * @param subId The sim that the GbaService is associated with. | 
|  | 9759 | * @return The release time to unbind GbaService by millisecond. | 
|  | 9760 | */ | 
|  | 9761 | @Override | 
|  | 9762 | public int getGbaReleaseTime(int subId) { | 
|  | 9763 | enforceReadPrivilegedPermission("getGbaReleaseTime"); | 
|  | 9764 |  | 
|  | 9765 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9766 | try { | 
|  | 9767 | return getGbaManager(subId).getReleaseTime(); | 
|  | 9768 | } finally { | 
|  | 9769 | Binder.restoreCallingIdentity(identity); | 
|  | 9770 | } | 
|  | 9771 | } | 
|  | 9772 |  | 
|  | 9773 | private GbaManager getGbaManager(int subId) { | 
|  | 9774 | GbaManager instance = GbaManager.getInstance(subId); | 
|  | 9775 | if (instance == null) { | 
|  | 9776 | String packageName = mApp.getResources().getString(R.string.config_gba_package); | 
|  | 9777 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); | 
|  | 9778 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); | 
|  | 9779 | } | 
|  | 9780 | return instance; | 
|  | 9781 | } | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9782 |  | 
|  | 9783 | /** | 
|  | 9784 | * indicate whether the device and the carrier can support | 
|  | 9785 | * RCS VoLTE single registration. | 
|  | 9786 | */ | 
|  | 9787 | @Override | 
|  | 9788 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { | 
| Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9789 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, | 
|  | 9790 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", | 
|  | 9791 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, | 
|  | 9792 | permission.READ_PRIVILEGED_PHONE_STATE); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9793 |  | 
|  | 9794 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 9795 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 9796 | } | 
|  | 9797 |  | 
|  | 9798 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9799 | try { | 
|  | 9800 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); | 
|  | 9801 | if (rpm != null) { | 
|  | 9802 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); | 
|  | 9803 | } | 
|  | 9804 | return false; | 
|  | 9805 | } finally { | 
|  | 9806 | Binder.restoreCallingIdentity(identity); | 
|  | 9807 | } | 
|  | 9808 | } | 
|  | 9809 |  | 
|  | 9810 | /** | 
|  | 9811 | * Register RCS provisioning callback. | 
|  | 9812 | */ | 
|  | 9813 | @Override | 
| Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9814 | public void registerRcsProvisioningCallback(int subId, | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9815 | IRcsConfigCallback callback) { | 
| Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9816 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, | 
| Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9817 | Binder.getCallingUid(), "registerRcsProvisioningCallback", | 
| Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9818 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, | 
|  | 9819 | permission.READ_PRIVILEGED_PHONE_STATE); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9820 |  | 
|  | 9821 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 9822 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 9823 | } | 
|  | 9824 | if (!isImsAvailableOnDevice()) { | 
|  | 9825 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 9826 | "IMS not available on device."); | 
|  | 9827 | } | 
|  | 9828 |  | 
|  | 9829 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9830 | try { | 
| Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9831 | if (!RcsProvisioningMonitor.getInstance() | 
| Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9832 | .registerRcsProvisioningCallback(subId, callback)) { | 
| Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9833 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 9834 | "Service not available for the subscription."); | 
|  | 9835 | } | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9836 | } finally { | 
|  | 9837 | Binder.restoreCallingIdentity(identity); | 
|  | 9838 | } | 
|  | 9839 | } | 
|  | 9840 |  | 
|  | 9841 | /** | 
|  | 9842 | * Unregister RCS provisioning callback. | 
|  | 9843 | */ | 
|  | 9844 | @Override | 
| Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9845 | public void unregisterRcsProvisioningCallback(int subId, | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9846 | IRcsConfigCallback callback) { | 
| Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9847 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, | 
| Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9848 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", | 
| Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9849 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, | 
|  | 9850 | permission.READ_PRIVILEGED_PHONE_STATE); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9851 |  | 
|  | 9852 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 9853 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 9854 | } | 
|  | 9855 | if (!isImsAvailableOnDevice()) { | 
|  | 9856 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 9857 | "IMS not available on device."); | 
|  | 9858 | } | 
|  | 9859 |  | 
|  | 9860 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9861 | try { | 
| Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9862 | RcsProvisioningMonitor.getInstance() | 
| Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9863 | .unregisterRcsProvisioningCallback(subId, callback); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9864 | } finally { | 
|  | 9865 | Binder.restoreCallingIdentity(identity); | 
|  | 9866 | } | 
|  | 9867 | } | 
|  | 9868 |  | 
|  | 9869 | /** | 
|  | 9870 | * trigger RCS reconfiguration. | 
|  | 9871 | */ | 
|  | 9872 | public void triggerRcsReconfiguration(int subId) { | 
| Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9873 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), | 
|  | 9874 | "triggerRcsReconfiguration", | 
|  | 9875 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9876 |  | 
|  | 9877 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 9878 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 9879 | } | 
|  | 9880 | if (!isImsAvailableOnDevice()) { | 
|  | 9881 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 9882 | "IMS not available on device."); | 
|  | 9883 | } | 
|  | 9884 |  | 
|  | 9885 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9886 | try { | 
|  | 9887 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); | 
|  | 9888 | } finally { | 
|  | 9889 | Binder.restoreCallingIdentity(identity); | 
|  | 9890 | } | 
|  | 9891 | } | 
|  | 9892 |  | 
|  | 9893 | /** | 
|  | 9894 | * Provide the client configuration parameters of the RCS application. | 
|  | 9895 | */ | 
|  | 9896 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { | 
| Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9897 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), | 
|  | 9898 | "setRcsClientConfiguration", | 
|  | 9899 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9900 |  | 
|  | 9901 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 9902 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 9903 | } | 
|  | 9904 | if (!isImsAvailableOnDevice()) { | 
|  | 9905 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 9906 | "IMS not available on device."); | 
|  | 9907 | } | 
|  | 9908 |  | 
|  | 9909 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9910 |  | 
|  | 9911 | try { | 
|  | 9912 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); | 
|  | 9913 | if (configBinder == null) { | 
|  | 9914 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); | 
|  | 9915 | } else { | 
|  | 9916 | configBinder.setRcsClientConfiguration(rcc); | 
|  | 9917 | } | 
|  | 9918 | } catch (RemoteException e) { | 
|  | 9919 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); | 
|  | 9920 | } finally { | 
|  | 9921 | Binder.restoreCallingIdentity(identity); | 
|  | 9922 | } | 
|  | 9923 | } | 
|  | 9924 |  | 
|  | 9925 | /** | 
| Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 9926 | * Enables or disables the test mode for RCS VoLTE single registration. | 
|  | 9927 | */ | 
|  | 9928 | @Override | 
|  | 9929 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { | 
|  | 9930 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 9931 | "setRcsSingleRegistrationTestModeEnabled"); | 
|  | 9932 |  | 
|  | 9933 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); | 
|  | 9934 | } | 
|  | 9935 |  | 
|  | 9936 | /** | 
|  | 9937 | * Gets the test mode for RCS VoLTE single registration. | 
|  | 9938 | */ | 
|  | 9939 | @Override | 
|  | 9940 | public boolean getRcsSingleRegistrationTestModeEnabled() { | 
|  | 9941 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 9942 | "getRcsSingleRegistrationTestModeEnabled"); | 
|  | 9943 |  | 
|  | 9944 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); | 
|  | 9945 | } | 
|  | 9946 |  | 
|  | 9947 | /** | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9948 | * Overrides the config of RCS VoLTE single registration enabled for the device. | 
|  | 9949 | */ | 
|  | 9950 | @Override | 
|  | 9951 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { | 
|  | 9952 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 9953 | "setDeviceSingleRegistrationEnabledOverride"); | 
|  | 9954 | enforceModifyPermission(); | 
|  | 9955 |  | 
|  | 9956 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null | 
|  | 9957 | : Boolean.parseBoolean(enabledStr); | 
|  | 9958 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); | 
| Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 9959 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9960 | } | 
|  | 9961 |  | 
|  | 9962 | /** | 
| Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9963 | * Sends a device to device communication message.  Only usable via shell. | 
|  | 9964 | * @param message message to send. | 
|  | 9965 | * @param value message value. | 
|  | 9966 | */ | 
|  | 9967 | @Override | 
|  | 9968 | public void sendDeviceToDeviceMessage(int message, int value) { | 
|  | 9969 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
| Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 9970 | "sendDeviceToDeviceMessage"); | 
| Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9971 | enforceModifyPermission(); | 
|  | 9972 |  | 
|  | 9973 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9974 | try { | 
|  | 9975 | TelephonyConnectionService service = | 
|  | 9976 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); | 
|  | 9977 | if (service == null) { | 
|  | 9978 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); | 
|  | 9979 | return; | 
|  | 9980 | } | 
|  | 9981 | service.sendTestDeviceToDeviceMessage(message, value); | 
|  | 9982 | } finally { | 
|  | 9983 | Binder.restoreCallingIdentity(identity); | 
|  | 9984 | } | 
|  | 9985 | } | 
|  | 9986 |  | 
| Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 9987 | /** | 
|  | 9988 | * Sets the specified device to device transport active. | 
|  | 9989 | * @param transport The transport to set active. | 
|  | 9990 | */ | 
|  | 9991 | @Override | 
|  | 9992 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { | 
|  | 9993 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 9994 | "setActiveDeviceToDeviceTransport"); | 
|  | 9995 | enforceModifyPermission(); | 
|  | 9996 |  | 
|  | 9997 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9998 | try { | 
|  | 9999 | TelephonyConnectionService service = | 
|  | 10000 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); | 
|  | 10001 | if (service == null) { | 
|  | 10002 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); | 
|  | 10003 | return; | 
|  | 10004 | } | 
|  | 10005 | service.setActiveDeviceToDeviceTransport(transport); | 
|  | 10006 | } finally { | 
|  | 10007 | Binder.restoreCallingIdentity(identity); | 
|  | 10008 | } | 
|  | 10009 | } | 
| Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10010 |  | 
|  | 10011 | /** | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10012 | * Gets the config of RCS VoLTE single registration enabled for the device. | 
|  | 10013 | */ | 
|  | 10014 | @Override | 
|  | 10015 | public boolean getDeviceSingleRegistrationEnabled() { | 
|  | 10016 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); | 
|  | 10017 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); | 
|  | 10018 | } | 
|  | 10019 |  | 
|  | 10020 | /** | 
|  | 10021 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. | 
|  | 10022 | */ | 
|  | 10023 | @Override | 
|  | 10024 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { | 
|  | 10025 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 10026 | "setCarrierSingleRegistrationEnabledOverride"); | 
|  | 10027 | enforceModifyPermission(); | 
|  | 10028 |  | 
|  | 10029 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null | 
|  | 10030 | : Boolean.parseBoolean(enabledStr); | 
|  | 10031 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( | 
|  | 10032 | subId, enabled); | 
|  | 10033 | } | 
|  | 10034 |  | 
|  | 10035 | /** | 
|  | 10036 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. | 
|  | 10037 | */ | 
|  | 10038 | @Override | 
|  | 10039 | public boolean getCarrierSingleRegistrationEnabled(int subId) { | 
|  | 10040 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); | 
|  | 10041 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); | 
|  | 10042 | } | 
| Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10043 |  | 
|  | 10044 | /** | 
|  | 10045 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage | 
|  | 10046 | * their mobile plan. | 
|  | 10047 | */ | 
|  | 10048 | @Override | 
|  | 10049 | public String getMobileProvisioningUrl() { | 
|  | 10050 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); | 
|  | 10051 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10052 | try { | 
|  | 10053 | return getDefaultPhone().getMobileProvisioningUrl(); | 
|  | 10054 | } finally { | 
|  | 10055 | Binder.restoreCallingIdentity(identity); | 
|  | 10056 | } | 
|  | 10057 | } | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10058 |  | 
| James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10059 | /** | 
| calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10060 | * Get the EAB contact from the EAB database. | 
|  | 10061 | */ | 
|  | 10062 | @Override | 
|  | 10063 | public String getContactFromEab(String contact) { | 
|  | 10064 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); | 
|  | 10065 | enforceModifyPermission(); | 
|  | 10066 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10067 | try { | 
|  | 10068 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); | 
|  | 10069 | } finally { | 
|  | 10070 | Binder.restoreCallingIdentity(identity); | 
|  | 10071 | } | 
|  | 10072 | } | 
|  | 10073 |  | 
|  | 10074 | /** | 
| James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10075 | * Remove the EAB contacts from the EAB database. | 
|  | 10076 | */ | 
|  | 10077 | @Override | 
|  | 10078 | public int removeContactFromEab(int subId, String contacts) { | 
|  | 10079 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); | 
|  | 10080 | enforceModifyPermission(); | 
|  | 10081 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10082 | try { | 
|  | 10083 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); | 
|  | 10084 | } finally { | 
|  | 10085 | Binder.restoreCallingIdentity(identity); | 
|  | 10086 | } | 
|  | 10087 | } | 
|  | 10088 |  | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10089 | @Override | 
| James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10090 | public boolean getDeviceUceEnabled() { | 
|  | 10091 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); | 
|  | 10092 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10093 | try { | 
|  | 10094 | return mApp.getDeviceUceEnabled(); | 
|  | 10095 | } finally { | 
|  | 10096 | Binder.restoreCallingIdentity(identity); | 
|  | 10097 | } | 
|  | 10098 | } | 
|  | 10099 |  | 
|  | 10100 | @Override | 
|  | 10101 | public void setDeviceUceEnabled(boolean isEnabled) { | 
|  | 10102 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); | 
|  | 10103 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10104 | try { | 
|  | 10105 | mApp.setDeviceUceEnabled(isEnabled); | 
|  | 10106 | } finally { | 
|  | 10107 | Binder.restoreCallingIdentity(identity); | 
|  | 10108 | } | 
|  | 10109 | } | 
|  | 10110 |  | 
| Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10111 | /** | 
|  | 10112 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. | 
|  | 10113 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. | 
|  | 10114 | */ | 
|  | 10115 | // Used for SHELL command only right now. | 
|  | 10116 | @Override | 
|  | 10117 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, | 
|  | 10118 | List<String> featureTags) { | 
|  | 10119 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 10120 | "addUceRegistrationOverrideShell"); | 
|  | 10121 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10122 | try { | 
|  | 10123 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, | 
|  | 10124 | new ArraySet<>(featureTags)); | 
|  | 10125 | } catch (ImsException e) { | 
|  | 10126 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); | 
|  | 10127 | } finally { | 
|  | 10128 | Binder.restoreCallingIdentity(identity); | 
|  | 10129 | } | 
|  | 10130 | } | 
|  | 10131 |  | 
|  | 10132 | /** | 
|  | 10133 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. | 
|  | 10134 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. | 
|  | 10135 | */ | 
|  | 10136 | // Used for SHELL command only right now. | 
|  | 10137 | @Override | 
|  | 10138 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, | 
|  | 10139 | List<String> featureTags) { | 
|  | 10140 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 10141 | "removeUceRegistrationOverrideShell"); | 
|  | 10142 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10143 | try { | 
|  | 10144 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, | 
|  | 10145 | new ArraySet<>(featureTags)); | 
|  | 10146 | } catch (ImsException e) { | 
|  | 10147 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); | 
|  | 10148 | } finally { | 
|  | 10149 | Binder.restoreCallingIdentity(identity); | 
|  | 10150 | } | 
|  | 10151 | } | 
|  | 10152 |  | 
|  | 10153 | /** | 
|  | 10154 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. | 
|  | 10155 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. | 
|  | 10156 | */ | 
|  | 10157 | // Used for SHELL command only right now. | 
|  | 10158 | @Override | 
|  | 10159 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { | 
|  | 10160 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 10161 | "clearUceRegistrationOverrideShell"); | 
|  | 10162 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10163 | try { | 
|  | 10164 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); | 
|  | 10165 | } catch (ImsException e) { | 
|  | 10166 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); | 
|  | 10167 | } finally { | 
|  | 10168 | Binder.restoreCallingIdentity(identity); | 
|  | 10169 | } | 
|  | 10170 | } | 
|  | 10171 |  | 
|  | 10172 | /** | 
|  | 10173 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. | 
|  | 10174 | */ | 
|  | 10175 | // Used for SHELL command only right now. | 
|  | 10176 | @Override | 
|  | 10177 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { | 
|  | 10178 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 10179 | "getLatestRcsContactUceCapabilityShell"); | 
|  | 10180 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10181 | try { | 
|  | 10182 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); | 
|  | 10183 | } catch (ImsException e) { | 
|  | 10184 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); | 
|  | 10185 | } finally { | 
|  | 10186 | Binder.restoreCallingIdentity(identity); | 
|  | 10187 | } | 
|  | 10188 | } | 
|  | 10189 |  | 
|  | 10190 | /** | 
|  | 10191 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the | 
|  | 10192 | * device does not have an active PUBLISH. | 
|  | 10193 | */ | 
|  | 10194 | // Used for SHELL command only right now. | 
|  | 10195 | @Override | 
|  | 10196 | public String getLastUcePidfXmlShell(int subId) { | 
|  | 10197 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); | 
|  | 10198 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10199 | try { | 
|  | 10200 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); | 
|  | 10201 | } catch (ImsException e) { | 
|  | 10202 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); | 
|  | 10203 | } finally { | 
|  | 10204 | Binder.restoreCallingIdentity(identity); | 
|  | 10205 | } | 
|  | 10206 | } | 
|  | 10207 |  | 
|  | 10208 |  | 
| James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10209 | @Override | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10210 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, | 
|  | 10211 | String callingPackage) { | 
|  | 10212 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 10213 | mApp, subId, "setSignalStrengthUpdateRequest"); | 
|  | 10214 |  | 
|  | 10215 | final int callingUid = Binder.getCallingUid(); | 
|  | 10216 | // Verify that tha callingPackage belongs to the calling UID | 
|  | 10217 | mApp.getSystemService(AppOpsManager.class) | 
|  | 10218 | .checkPackage(callingUid, callingPackage); | 
|  | 10219 |  | 
|  | 10220 | validateSignalStrengthUpdateRequest(request, callingUid); | 
|  | 10221 |  | 
|  | 10222 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10223 | try { | 
|  | 10224 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, | 
|  | 10225 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); | 
|  | 10226 |  | 
|  | 10227 | if (result instanceof IllegalStateException) { | 
|  | 10228 | throw (IllegalStateException) result; | 
|  | 10229 | } | 
|  | 10230 | } finally { | 
|  | 10231 | Binder.restoreCallingIdentity(identity); | 
|  | 10232 | } | 
|  | 10233 | } | 
|  | 10234 |  | 
|  | 10235 | @Override | 
|  | 10236 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, | 
|  | 10237 | String callingPackage) { | 
|  | 10238 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 10239 | mApp, subId, "clearSignalStrengthUpdateRequest"); | 
|  | 10240 |  | 
|  | 10241 | final int callingUid = Binder.getCallingUid(); | 
|  | 10242 | // Verify that tha callingPackage belongs to the calling UID | 
|  | 10243 | mApp.getSystemService(AppOpsManager.class) | 
|  | 10244 | .checkPackage(callingUid, callingPackage); | 
|  | 10245 |  | 
|  | 10246 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10247 | try { | 
|  | 10248 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, | 
|  | 10249 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); | 
|  | 10250 |  | 
|  | 10251 | if (result instanceof IllegalStateException) { | 
|  | 10252 | throw (IllegalStateException) result; | 
|  | 10253 | } | 
|  | 10254 | } finally { | 
|  | 10255 | Binder.restoreCallingIdentity(identity); | 
|  | 10256 | } | 
|  | 10257 | } | 
|  | 10258 |  | 
|  | 10259 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, | 
|  | 10260 | int callingUid) { | 
|  | 10261 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { | 
|  | 10262 | // phone/system process do not have further restriction on request | 
|  | 10263 | return; | 
|  | 10264 | } | 
|  | 10265 |  | 
|  | 10266 | // Applications has restrictions on how to use the request: | 
|  | 10267 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle | 
|  | 10268 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { | 
|  | 10269 | // This is not system caller which has been checked above | 
|  | 10270 | throw new IllegalArgumentException( | 
|  | 10271 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); | 
|  | 10272 | } | 
|  | 10273 |  | 
|  | 10274 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { | 
|  | 10275 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. | 
|  | 10276 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED | 
|  | 10277 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED | 
|  | 10278 | || info.isEnabled()) { | 
|  | 10279 | throw new IllegalArgumentException( | 
|  | 10280 | "Only system can set hide fields in SignalThresholdInfo"); | 
|  | 10281 | } | 
|  | 10282 |  | 
|  | 10283 | // Thresholds length for each RAN need in range. This has been validated in | 
|  | 10284 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method | 
|  | 10285 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds | 
|  | 10286 | final int[] thresholds = info.getThresholds(); | 
|  | 10287 | Objects.requireNonNull(thresholds); | 
|  | 10288 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() | 
|  | 10289 | || thresholds.length | 
|  | 10290 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { | 
|  | 10291 | throw new IllegalArgumentException( | 
|  | 10292 | "thresholds length is out of range: " + thresholds.length); | 
|  | 10293 | } | 
|  | 10294 | } | 
|  | 10295 | } | 
| SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10296 |  | 
|  | 10297 | /** | 
|  | 10298 | * Gets the current phone capability. | 
|  | 10299 | * | 
|  | 10300 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 10301 | * @return the PhoneCapability which describes the data connection capability of modem. | 
|  | 10302 | * It's used to evaluate possible phone config change, for example from single | 
|  | 10303 | * SIM device to multi-SIM device. | 
|  | 10304 | */ | 
|  | 10305 | @Override | 
|  | 10306 | public PhoneCapability getPhoneCapability() { | 
|  | 10307 | enforceReadPrivilegedPermission("getPhoneCapability"); | 
|  | 10308 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10309 | try { | 
|  | 10310 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); | 
|  | 10311 | } finally { | 
|  | 10312 | Binder.restoreCallingIdentity(identity); | 
|  | 10313 | } | 
|  | 10314 | } | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10315 |  | 
|  | 10316 | /** | 
|  | 10317 | * Prepare TelephonyManager for an unattended reboot. The reboot is | 
|  | 10318 | * required to be done shortly after the API is invoked. | 
|  | 10319 | */ | 
|  | 10320 | @Override | 
|  | 10321 | @TelephonyManager.PrepareUnattendedRebootResult | 
|  | 10322 | public int prepareForUnattendedReboot() { | 
|  | 10323 | enforceRebootPermission(); | 
|  | 10324 |  | 
|  | 10325 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10326 | try { | 
|  | 10327 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); | 
|  | 10328 | } finally { | 
|  | 10329 | Binder.restoreCallingIdentity(identity); | 
|  | 10330 | } | 
|  | 10331 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10332 | } |