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 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 22 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 23 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 24 | import android.Manifest.permission; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 25 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 30 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 33 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 34 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 35 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 48 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 49 | import android.os.PersistableBundle; |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 50 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 51 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 52 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.ServiceManager; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 55 | import android.os.ShellCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 57 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 58 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 59 | import android.preference.PreferenceManager; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 60 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 61 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 62 | import android.provider.Telephony; |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 63 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 65 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 66 | import android.telecom.TelecomManager; |
Chen Xu | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 67 | import android.telephony.Annotation.ApnType; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 68 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 69 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 70 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 71 | import android.telephony.CellIdentity; |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 72 | import android.telephony.CellIdentityCdma; |
| 73 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfoGsm; |
| 76 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 77 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 78 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 79 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 80 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 81 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 82 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 83 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 84 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 85 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 86 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 87 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 88 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 89 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 90 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 91 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 92 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 93 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 94 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 95 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 96 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 97 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 98 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 99 | import android.telephony.data.ApnSetting; |
| 100 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 101 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 102 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 103 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 108 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 109 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 110 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 111 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 112 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 113 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 114 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 115 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 116 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 117 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 118 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 119 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 120 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 121 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 122 | import com.android.ims.internal.IImsServiceFeatureCallback; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 123 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.HalVersion; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 158 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 160 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 170 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 172 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 173 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 174 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 175 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 176 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 177 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 178 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 179 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 180 | import java.io.FileDescriptor; |
| 181 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 182 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 183 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 184 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 185 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 186 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 187 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 188 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 189 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 190 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 191 | |
| 192 | /** |
| 193 | * Implementation of the ITelephony interface. |
| 194 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 195 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 196 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 197 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 198 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 199 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 200 | |
| 201 | // Message codes used with mMainThreadHandler |
| 202 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 203 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 204 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 205 | private static final int CMD_OPEN_CHANNEL = 9; |
| 206 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 207 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 208 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 209 | private static final int CMD_NV_READ_ITEM = 13; |
| 210 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 211 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 212 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 213 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 214 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 215 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 216 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 217 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 218 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 219 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 220 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 221 | private static final int CMD_SEND_ENVELOPE = 25; |
| 222 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 223 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 224 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 225 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 226 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 227 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 228 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 229 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 230 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 231 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 232 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 233 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 234 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 235 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 236 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 237 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 238 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 239 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 240 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 241 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 242 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 243 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 244 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 245 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 246 | private static final int CMD_SWITCH_SLOTS = 50; |
| 247 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 248 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 249 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 250 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 251 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 252 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 253 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 254 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 255 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 256 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 257 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 258 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 259 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 260 | private static final int CMD_MODEM_REBOOT = 64; |
| 261 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 262 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 263 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 264 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 265 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 266 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 267 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 268 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 269 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 270 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 271 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 272 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 273 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 274 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 275 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 276 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 277 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 278 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 279 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 280 | private static final int CMD_GET_CALL_WAITING = 87; |
| 281 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 282 | private static final int CMD_SET_CALL_WAITING = 89; |
| 283 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 284 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 285 | // Parameters of select command. |
| 286 | private static final int SELECT_COMMAND = 0xA4; |
| 287 | private static final int SELECT_P1 = 0x04; |
| 288 | private static final int SELECT_P2 = 0; |
| 289 | private static final int SELECT_P3 = 0x10; |
| 290 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 291 | /** The singleton instance. */ |
| 292 | private static PhoneInterfaceManager sInstance; |
| 293 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 294 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 295 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 296 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 297 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 298 | private AppOpsManager mAppOps; |
| 299 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 300 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 301 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 302 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 303 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 304 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 305 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 306 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 307 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 308 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 309 | // String to store multi SIM allowed |
| 310 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 311 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 312 | // The AID of ISD-R. |
| 313 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 314 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 315 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 316 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 317 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 318 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 319 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 320 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 321 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 322 | */ |
| 323 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 324 | "reset_network_erase_modem_config_enabled"; |
| 325 | |
| 326 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 327 | * A request object to use for transmitting data to an ICC. |
| 328 | */ |
| 329 | private static final class IccAPDUArgument { |
| 330 | public int channel, cla, command, p1, p2, p3; |
| 331 | public String data; |
| 332 | |
| 333 | public IccAPDUArgument(int channel, int cla, int command, |
| 334 | int p1, int p2, int p3, String data) { |
| 335 | this.channel = channel; |
| 336 | this.cla = cla; |
| 337 | this.command = command; |
| 338 | this.p1 = p1; |
| 339 | this.p2 = p2; |
| 340 | this.p3 = p3; |
| 341 | this.data = data; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 346 | * A request object to use for transmitting data to an ICC. |
| 347 | */ |
| 348 | private static final class ManualNetworkSelectionArgument { |
| 349 | public OperatorInfo operatorInfo; |
| 350 | public boolean persistSelection; |
| 351 | |
| 352 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 353 | this.operatorInfo = operatorInfo; |
| 354 | this.persistSelection = persistSelection; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 359 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 360 | * request after sending. The main thread will notify the request when it is complete. |
| 361 | */ |
| 362 | private static final class MainThreadRequest { |
| 363 | /** The argument to use for the request */ |
| 364 | public Object argument; |
| 365 | /** The result of the request that is run on the main thread */ |
| 366 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 367 | // The subscriber id that this request applies to. Defaults to |
| 368 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 369 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 370 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 371 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 372 | public Phone phone; |
| 373 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 374 | public WorkSource workSource; |
| 375 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 376 | public MainThreadRequest(Object argument) { |
| 377 | this.argument = argument; |
| 378 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 379 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 380 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 381 | this.argument = argument; |
| 382 | if (phone != null) { |
| 383 | this.phone = phone; |
| 384 | } |
| 385 | this.workSource = workSource; |
| 386 | } |
| 387 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 388 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 389 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 390 | if (subId != null) { |
| 391 | this.subId = subId; |
| 392 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 393 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 394 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 397 | private static final class IncomingThirdPartyCallArgs { |
| 398 | public final ComponentName component; |
| 399 | public final String callId; |
| 400 | public final String callerDisplayName; |
| 401 | |
| 402 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 403 | String callerDisplayName) { |
| 404 | this.component = component; |
| 405 | this.callId = callId; |
| 406 | this.callerDisplayName = callerDisplayName; |
| 407 | } |
| 408 | } |
| 409 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 410 | /** |
| 411 | * A handler that processes messages on the main thread in the phone process. Since many |
| 412 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 413 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 414 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 415 | * on, which will be notified when the operation completes and will contain the result of the |
| 416 | * request. |
| 417 | * |
| 418 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 419 | * note that request.result must be set to something non-null for the calling thread to |
| 420 | * unblock. |
| 421 | */ |
| 422 | private final class MainThreadHandler extends Handler { |
| 423 | @Override |
| 424 | public void handleMessage(Message msg) { |
| 425 | MainThreadRequest request; |
| 426 | Message onCompleted; |
| 427 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 428 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 429 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 430 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 431 | |
| 432 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 433 | case CMD_HANDLE_USSD_REQUEST: { |
| 434 | request = (MainThreadRequest) msg.obj; |
| 435 | final Phone phone = getPhoneFromRequest(request); |
| 436 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 437 | String ussdRequest = ussdObject.first; |
| 438 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 439 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 440 | if (!isUssdApiAllowed(request.subId)) { |
| 441 | // Carrier does not support use of this API, return failure. |
| 442 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 443 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 444 | Bundle returnData = new Bundle(); |
| 445 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 446 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 447 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 448 | request.result = true; |
| 449 | notifyRequester(request); |
| 450 | return; |
| 451 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 452 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 453 | try { |
| 454 | request.result = phone != null |
| 455 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 456 | } catch (CallStateException cse) { |
| 457 | request.result = false; |
| 458 | } |
| 459 | // Wake up the requesting thread |
| 460 | notifyRequester(request); |
| 461 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 464 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 465 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 466 | final Phone phone = getPhoneFromRequest(request); |
| 467 | request.result = phone != null ? |
| 468 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 469 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 470 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 471 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 472 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 473 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 474 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 475 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 476 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 477 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 478 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 479 | if (uiccCard == null) { |
| 480 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 481 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 482 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 483 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 484 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 485 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 486 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 487 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 488 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 489 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 490 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 491 | break; |
| 492 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 493 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 494 | ar = (AsyncResult) msg.obj; |
| 495 | request = (MainThreadRequest) ar.userObj; |
| 496 | if (ar.exception == null && ar.result != null) { |
| 497 | request.result = ar.result; |
| 498 | } else { |
| 499 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 500 | if (ar.result == null) { |
| 501 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 502 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 503 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 504 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 505 | } else { |
| 506 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 507 | } |
| 508 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 509 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 510 | break; |
| 511 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 512 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 513 | request = (MainThreadRequest) msg.obj; |
| 514 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 515 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 516 | if (uiccCard == null) { |
| 517 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 518 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 519 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 520 | } else { |
| 521 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 522 | request); |
| 523 | uiccCard.iccTransmitApduBasicChannel( |
| 524 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 525 | iccArgument.p3, iccArgument.data, onCompleted); |
| 526 | } |
| 527 | break; |
| 528 | |
| 529 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 530 | ar = (AsyncResult) msg.obj; |
| 531 | request = (MainThreadRequest) ar.userObj; |
| 532 | if (ar.exception == null && ar.result != null) { |
| 533 | request.result = ar.result; |
| 534 | } else { |
| 535 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 536 | if (ar.result == null) { |
| 537 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 538 | } else if (ar.exception instanceof CommandException) { |
| 539 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 540 | ar.exception); |
| 541 | } else { |
| 542 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 543 | } |
| 544 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 545 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 546 | break; |
| 547 | |
| 548 | case CMD_EXCHANGE_SIM_IO: |
| 549 | request = (MainThreadRequest) msg.obj; |
| 550 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 551 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 552 | if (uiccCard == null) { |
| 553 | loge("iccExchangeSimIO: No UICC"); |
| 554 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 555 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 556 | } else { |
| 557 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 558 | request); |
| 559 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 560 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 561 | iccArgument.data, onCompleted); |
| 562 | } |
| 563 | break; |
| 564 | |
| 565 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 566 | ar = (AsyncResult) msg.obj; |
| 567 | request = (MainThreadRequest) ar.userObj; |
| 568 | if (ar.exception == null && ar.result != null) { |
| 569 | request.result = ar.result; |
| 570 | } else { |
| 571 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 572 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 573 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 574 | break; |
| 575 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 576 | case CMD_SEND_ENVELOPE: |
| 577 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 578 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 579 | if (uiccCard == null) { |
| 580 | loge("sendEnvelopeWithStatus: No UICC"); |
| 581 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 582 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 583 | } else { |
| 584 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 585 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 586 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 587 | break; |
| 588 | |
| 589 | case EVENT_SEND_ENVELOPE_DONE: |
| 590 | ar = (AsyncResult) msg.obj; |
| 591 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 592 | if (ar.exception == null && ar.result != null) { |
| 593 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 594 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 595 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 596 | if (ar.result == null) { |
| 597 | loge("sendEnvelopeWithStatus: Empty response"); |
| 598 | } else if (ar.exception instanceof CommandException) { |
| 599 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 600 | ar.exception); |
| 601 | } else { |
| 602 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 603 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 604 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 605 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 606 | break; |
| 607 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 608 | case CMD_OPEN_CHANNEL: |
| 609 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 610 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 611 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 612 | if (uiccCard == null) { |
| 613 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 614 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 615 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 616 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 617 | } else { |
| 618 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 619 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 620 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 621 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 622 | break; |
| 623 | |
| 624 | case EVENT_OPEN_CHANNEL_DONE: |
| 625 | ar = (AsyncResult) msg.obj; |
| 626 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 627 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 628 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 629 | int[] result = (int[]) ar.result; |
| 630 | int channelId = result[0]; |
| 631 | byte[] selectResponse = null; |
| 632 | if (result.length > 1) { |
| 633 | selectResponse = new byte[result.length - 1]; |
| 634 | for (int i = 1; i < result.length; ++i) { |
| 635 | selectResponse[i - 1] = (byte) result[i]; |
| 636 | } |
| 637 | } |
| 638 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 639 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 640 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 641 | if (ar.result == null) { |
| 642 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 643 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 644 | if (ar.exception != null) { |
| 645 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 646 | } |
| 647 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 648 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 649 | if (ar.exception instanceof CommandException) { |
| 650 | CommandException.Error error = |
| 651 | ((CommandException) (ar.exception)).getCommandError(); |
| 652 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 653 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 654 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 655 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 659 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 660 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 661 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 662 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | break; |
| 664 | |
| 665 | case CMD_CLOSE_CHANNEL: |
| 666 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 667 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 668 | if (uiccCard == null) { |
| 669 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 670 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 671 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 672 | } else { |
| 673 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 674 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 675 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 676 | break; |
| 677 | |
| 678 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 679 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 680 | break; |
| 681 | |
| 682 | case CMD_NV_READ_ITEM: |
| 683 | request = (MainThreadRequest) msg.obj; |
| 684 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 685 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 686 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 687 | break; |
| 688 | |
| 689 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 690 | ar = (AsyncResult) msg.obj; |
| 691 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 692 | if (ar.exception == null && ar.result != null) { |
| 693 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 694 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 695 | request.result = ""; |
| 696 | if (ar.result == null) { |
| 697 | loge("nvReadItem: Empty response"); |
| 698 | } else if (ar.exception instanceof CommandException) { |
| 699 | loge("nvReadItem: CommandException: " + |
| 700 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 701 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 702 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 703 | } |
| 704 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 705 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 706 | break; |
| 707 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 708 | case CMD_NV_WRITE_ITEM: |
| 709 | request = (MainThreadRequest) msg.obj; |
| 710 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 711 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 712 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 713 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 714 | break; |
| 715 | |
| 716 | case EVENT_NV_WRITE_ITEM_DONE: |
| 717 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 718 | break; |
| 719 | |
| 720 | case CMD_NV_WRITE_CDMA_PRL: |
| 721 | request = (MainThreadRequest) msg.obj; |
| 722 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 723 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 724 | break; |
| 725 | |
| 726 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 727 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 728 | break; |
| 729 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 730 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 731 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 732 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 733 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 734 | break; |
| 735 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 736 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 737 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 738 | break; |
| 739 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 740 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 741 | request = (MainThreadRequest) msg.obj; |
| 742 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 743 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 744 | break; |
| 745 | |
| 746 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 747 | ar = (AsyncResult) msg.obj; |
| 748 | request = (MainThreadRequest) ar.userObj; |
| 749 | if (ar.exception == null && ar.result != null) { |
| 750 | request.result = ar.result; // Integer |
| 751 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 752 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 753 | if (ar.result == null) { |
| 754 | loge("getPreferredNetworkType: Empty response"); |
| 755 | } else if (ar.exception instanceof CommandException) { |
| 756 | loge("getPreferredNetworkType: CommandException: " + |
| 757 | ar.exception); |
| 758 | } else { |
| 759 | loge("getPreferredNetworkType: Unknown exception"); |
| 760 | } |
| 761 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 762 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 763 | break; |
| 764 | |
| 765 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 766 | request = (MainThreadRequest) msg.obj; |
| 767 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 768 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 769 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 770 | break; |
| 771 | |
| 772 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 773 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 774 | break; |
| 775 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 776 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 777 | request = (MainThreadRequest)msg.obj; |
| 778 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 779 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 780 | break; |
| 781 | |
| 782 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 783 | ar = (AsyncResult)msg.obj; |
| 784 | request = (MainThreadRequest)ar.userObj; |
| 785 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 786 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 787 | break; |
| 788 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 789 | case CMD_SET_VOICEMAIL_NUMBER: |
| 790 | request = (MainThreadRequest) msg.obj; |
| 791 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 792 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 793 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 794 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 795 | break; |
| 796 | |
| 797 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 798 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 799 | break; |
| 800 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 801 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 802 | request = (MainThreadRequest) msg.obj; |
| 803 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 804 | request); |
| 805 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 806 | break; |
| 807 | |
| 808 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 809 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 810 | break; |
| 811 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 812 | case CMD_PERFORM_NETWORK_SCAN: |
| 813 | request = (MainThreadRequest) msg.obj; |
| 814 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 815 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 816 | break; |
| 817 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 818 | case CMD_GET_CALL_FORWARDING: |
| 819 | request = (MainThreadRequest) msg.obj; |
| 820 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
| 821 | int callForwardingReason = (Integer) request.argument; |
| 822 | getPhoneFromRequest(request).getCallForwardingOption( |
| 823 | callForwardingReason, onCompleted); |
| 824 | break; |
| 825 | |
| 826 | case EVENT_GET_CALL_FORWARDING_DONE: |
| 827 | ar = (AsyncResult) msg.obj; |
| 828 | request = (MainThreadRequest) ar.userObj; |
| 829 | CallForwardingInfo callForwardingInfo = null; |
| 830 | if (ar.exception == null && ar.result != null) { |
| 831 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 832 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 833 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 834 | // any service for voice call. |
| 835 | if ((callForwardInfo.serviceClass |
| 836 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
| 837 | callForwardingInfo = new CallForwardingInfo( |
| 838 | callForwardInfo.serviceClass, callForwardInfo.reason, |
| 839 | callForwardInfo.number, |
| 840 | callForwardInfo.timeSeconds); |
| 841 | break; |
| 842 | } |
| 843 | } |
| 844 | // Didn't find a call forward info for voice call. |
| 845 | if (callForwardingInfo == null) { |
| 846 | callForwardingInfo = new CallForwardingInfo( |
| 847 | CallForwardingInfo.STATUS_UNKNOWN_ERROR, |
| 848 | 0 /* reason */, null /* number */, 0 /* timeout */); |
| 849 | } |
| 850 | } else { |
| 851 | if (ar.result == null) { |
| 852 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 853 | } |
| 854 | if (ar.exception != null) { |
| 855 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 856 | } |
| 857 | int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR; |
| 858 | if (ar.exception instanceof CommandException) { |
| 859 | CommandException.Error error = |
| 860 | ((CommandException) (ar.exception)).getCommandError(); |
| 861 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 862 | errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE; |
| 863 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 864 | errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED; |
| 865 | } |
| 866 | } |
| 867 | callForwardingInfo = new CallForwardingInfo( |
| 868 | errorCode, 0 /* reason */, null /* number */, 0 /* timeout */); |
| 869 | } |
| 870 | request.result = callForwardingInfo; |
| 871 | notifyRequester(request); |
| 872 | break; |
| 873 | |
| 874 | case CMD_SET_CALL_FORWARDING: |
| 875 | request = (MainThreadRequest) msg.obj; |
| 876 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
| 877 | CallForwardingInfo callForwardingInfoToSet = |
| 878 | (CallForwardingInfo) request.argument; |
| 879 | getPhoneFromRequest(request).setCallForwardingOption( |
| 880 | callForwardingInfoToSet.getStatus(), |
| 881 | callForwardingInfoToSet.getReason(), |
| 882 | callForwardingInfoToSet.getNumber(), |
| 883 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 884 | break; |
| 885 | |
| 886 | case EVENT_SET_CALL_FORWARDING_DONE: |
| 887 | ar = (AsyncResult) msg.obj; |
| 888 | request = (MainThreadRequest) ar.userObj; |
| 889 | if (ar.exception == null) { |
| 890 | request.result = true; |
| 891 | } else { |
| 892 | request.result = false; |
| 893 | loge("setCallForwarding exception: " + ar.exception); |
| 894 | } |
| 895 | notifyRequester(request); |
| 896 | break; |
| 897 | |
| 898 | case CMD_GET_CALL_WAITING: |
| 899 | request = (MainThreadRequest) msg.obj; |
| 900 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 901 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 902 | break; |
| 903 | |
| 904 | case EVENT_GET_CALL_WAITING_DONE: |
| 905 | ar = (AsyncResult) msg.obj; |
| 906 | request = (MainThreadRequest) ar.userObj; |
| 907 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 908 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 909 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 910 | // Service Class is a bit mask per 3gpp 27.007. |
| 911 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 912 | if (callForwardResults.length > 1 |
| 913 | && ((callForwardResults[1] |
| 914 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
| 915 | callForwardingStatus = callForwardResults[0] == 0 |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 916 | ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE |
| 917 | : TelephonyManager.CALL_WAITING_STATUS_ACTIVE; |
| 918 | } else { |
| 919 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE; |
| 920 | } |
| 921 | } else { |
| 922 | if (ar.result == null) { |
| 923 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 924 | } |
| 925 | if (ar.exception != null) { |
| 926 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 927 | } |
| 928 | if (ar.exception instanceof CommandException) { |
| 929 | CommandException.Error error = |
| 930 | ((CommandException) (ar.exception)).getCommandError(); |
| 931 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 932 | callForwardingStatus = |
| 933 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 934 | } |
| 935 | } |
| 936 | } |
| 937 | request.result = callForwardingStatus; |
| 938 | notifyRequester(request); |
| 939 | break; |
| 940 | |
| 941 | case CMD_SET_CALL_WAITING: |
| 942 | request = (MainThreadRequest) msg.obj; |
| 943 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
| 944 | boolean isEnable = (Boolean) request.argument; |
| 945 | getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted); |
| 946 | break; |
| 947 | |
| 948 | case EVENT_SET_CALL_WAITING_DONE: |
| 949 | ar = (AsyncResult) msg.obj; |
| 950 | request = (MainThreadRequest) ar.userObj; |
| 951 | if (ar.exception == null) { |
| 952 | request.result = true; |
| 953 | } else { |
| 954 | request.result = false; |
| 955 | loge("setCallWaiting exception: " + ar.exception); |
| 956 | } |
| 957 | notifyRequester(request); |
| 958 | break; |
| 959 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 960 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 961 | ar = (AsyncResult) msg.obj; |
| 962 | request = (MainThreadRequest) ar.userObj; |
| 963 | CellNetworkScanResult cellScanResult; |
| 964 | if (ar.exception == null && ar.result != null) { |
| 965 | cellScanResult = new CellNetworkScanResult( |
| 966 | CellNetworkScanResult.STATUS_SUCCESS, |
| 967 | (List<OperatorInfo>) ar.result); |
| 968 | } else { |
| 969 | if (ar.result == null) { |
| 970 | loge("getCellNetworkScanResults: Empty response"); |
| 971 | } |
| 972 | if (ar.exception != null) { |
| 973 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 974 | } |
| 975 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 976 | if (ar.exception instanceof CommandException) { |
| 977 | CommandException.Error error = |
| 978 | ((CommandException) (ar.exception)).getCommandError(); |
| 979 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 980 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 981 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 982 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 983 | } |
| 984 | } |
| 985 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 986 | } |
| 987 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 988 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 989 | break; |
| 990 | |
| 991 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 992 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 993 | ManualNetworkSelectionArgument selArg = |
| 994 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 995 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 996 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 997 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 998 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 999 | break; |
| 1000 | |
| 1001 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1002 | ar = (AsyncResult) msg.obj; |
| 1003 | request = (MainThreadRequest) ar.userObj; |
| 1004 | if (ar.exception == null) { |
| 1005 | request.result = true; |
| 1006 | } else { |
| 1007 | request.result = false; |
| 1008 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1009 | } |
| 1010 | notifyRequester(request); |
| 1011 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1012 | break; |
| 1013 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1014 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1015 | request = (MainThreadRequest) msg.obj; |
| 1016 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1017 | if (defaultPhone != null) { |
| 1018 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 1019 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1020 | break; |
| 1021 | |
| 1022 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1023 | ar = (AsyncResult) msg.obj; |
| 1024 | request = (MainThreadRequest) ar.userObj; |
| 1025 | if (ar.exception == null && ar.result != null) { |
| 1026 | request.result = ar.result; |
| 1027 | } else { |
| 1028 | if (ar.result == null) { |
| 1029 | loge("queryModemActivityInfo: Empty response"); |
| 1030 | } else if (ar.exception instanceof CommandException) { |
| 1031 | loge("queryModemActivityInfo: CommandException: " + |
| 1032 | ar.exception); |
| 1033 | } else { |
| 1034 | loge("queryModemActivityInfo: Unknown exception"); |
| 1035 | } |
| 1036 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 1037 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 1038 | if (request.result == null) { |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 1039 | request.result = new ModemActivityInfo(0, 0, 0, null, 0); |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 1040 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1041 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1042 | break; |
| 1043 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1044 | case CMD_SET_ALLOWED_CARRIERS: |
| 1045 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1046 | CarrierRestrictionRules argument = |
| 1047 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1048 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1049 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1050 | break; |
| 1051 | |
| 1052 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1053 | ar = (AsyncResult) msg.obj; |
| 1054 | request = (MainThreadRequest) ar.userObj; |
| 1055 | if (ar.exception == null && ar.result != null) { |
| 1056 | request.result = ar.result; |
| 1057 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1058 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1059 | if (ar.exception instanceof CommandException) { |
| 1060 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1061 | CommandException.Error error = |
| 1062 | ((CommandException) (ar.exception)).getCommandError(); |
| 1063 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1064 | request.result = |
| 1065 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1066 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1067 | } else { |
| 1068 | loge("setAllowedCarriers: Unknown exception"); |
| 1069 | } |
| 1070 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1071 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1072 | break; |
| 1073 | |
| 1074 | case CMD_GET_ALLOWED_CARRIERS: |
| 1075 | request = (MainThreadRequest) msg.obj; |
| 1076 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1077 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1078 | break; |
| 1079 | |
| 1080 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1081 | ar = (AsyncResult) msg.obj; |
| 1082 | request = (MainThreadRequest) ar.userObj; |
| 1083 | if (ar.exception == null && ar.result != null) { |
| 1084 | request.result = ar.result; |
| 1085 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1086 | request.result = new IllegalStateException( |
| 1087 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1088 | if (ar.result == null) { |
| 1089 | loge("getAllowedCarriers: Empty response"); |
| 1090 | } else if (ar.exception instanceof CommandException) { |
| 1091 | loge("getAllowedCarriers: CommandException: " + |
| 1092 | ar.exception); |
| 1093 | } else { |
| 1094 | loge("getAllowedCarriers: Unknown exception"); |
| 1095 | } |
| 1096 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1097 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1098 | break; |
| 1099 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1100 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1101 | ar = (AsyncResult) msg.obj; |
| 1102 | request = (MainThreadRequest) ar.userObj; |
| 1103 | if (ar.exception == null && ar.result != null) { |
| 1104 | request.result = ar.result; |
| 1105 | } else { |
| 1106 | request.result = new IllegalArgumentException( |
| 1107 | "Failed to retrieve Forbidden Plmns"); |
| 1108 | if (ar.result == null) { |
| 1109 | loge("getForbiddenPlmns: Empty response"); |
| 1110 | } else { |
| 1111 | loge("getForbiddenPlmns: Unknown exception"); |
| 1112 | } |
| 1113 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1114 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1115 | break; |
| 1116 | |
| 1117 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1118 | request = (MainThreadRequest) msg.obj; |
| 1119 | uiccCard = getUiccCardFromRequest(request); |
| 1120 | if (uiccCard == null) { |
| 1121 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1122 | request.result = new IllegalArgumentException( |
| 1123 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1124 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1125 | break; |
| 1126 | } |
| 1127 | Integer appType = (Integer) request.argument; |
| 1128 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1129 | if (uiccApp == null) { |
| 1130 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1131 | + appType); |
| 1132 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1133 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1134 | break; |
| 1135 | } else { |
| 1136 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1137 | + " specified type -- " + appType); |
| 1138 | } |
| 1139 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1140 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1141 | onCompleted); |
| 1142 | break; |
| 1143 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1144 | case CMD_SWITCH_SLOTS: |
| 1145 | request = (MainThreadRequest) msg.obj; |
| 1146 | int[] physicalSlots = (int[]) request.argument; |
| 1147 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1148 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1149 | break; |
| 1150 | |
| 1151 | case EVENT_SWITCH_SLOTS_DONE: |
| 1152 | ar = (AsyncResult) msg.obj; |
| 1153 | request = (MainThreadRequest) ar.userObj; |
| 1154 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1155 | notifyRequester(request); |
| 1156 | break; |
| 1157 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1158 | request = (MainThreadRequest) msg.obj; |
| 1159 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1160 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1161 | break; |
| 1162 | |
| 1163 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1164 | ar = (AsyncResult) msg.obj; |
| 1165 | request = (MainThreadRequest) ar.userObj; |
| 1166 | if (ar.exception != null) { |
| 1167 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1168 | } else { |
| 1169 | int mode = ((int[]) ar.result)[0]; |
| 1170 | if (mode == 0) { |
| 1171 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1172 | } else { |
| 1173 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1174 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1175 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1176 | notifyRequester(request); |
| 1177 | break; |
| 1178 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1179 | request = (MainThreadRequest) msg.obj; |
| 1180 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1181 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1182 | break; |
| 1183 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1184 | ar = (AsyncResult) msg.obj; |
| 1185 | request = (MainThreadRequest) ar.userObj; |
| 1186 | if (ar.exception != null) { |
| 1187 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1188 | } else { |
| 1189 | request.result = ((int[]) ar.result)[0]; |
| 1190 | } |
| 1191 | notifyRequester(request); |
| 1192 | break; |
| 1193 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1194 | request = (MainThreadRequest) msg.obj; |
| 1195 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1196 | int mode = (int) request.argument; |
| 1197 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1198 | break; |
| 1199 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1200 | ar = (AsyncResult) msg.obj; |
| 1201 | request = (MainThreadRequest) ar.userObj; |
| 1202 | request.result = ar.exception == null; |
| 1203 | notifyRequester(request); |
| 1204 | break; |
| 1205 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1206 | request = (MainThreadRequest) msg.obj; |
| 1207 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1208 | int subscriptionMode = (int) request.argument; |
| 1209 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1210 | break; |
| 1211 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1212 | ar = (AsyncResult) msg.obj; |
| 1213 | request = (MainThreadRequest) ar.userObj; |
| 1214 | request.result = ar.exception == null; |
| 1215 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1216 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1217 | case CMD_GET_ALL_CELL_INFO: |
| 1218 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1219 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1220 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1221 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1222 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1223 | ar = (AsyncResult) msg.obj; |
| 1224 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1225 | // If a timeout occurs, the response will be null |
| 1226 | request.result = (ar.exception == null && ar.result != null) |
| 1227 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1228 | synchronized (request) { |
| 1229 | request.notifyAll(); |
| 1230 | } |
| 1231 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1232 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1233 | request = (MainThreadRequest) msg.obj; |
| 1234 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1235 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1236 | break; |
| 1237 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1238 | ar = (AsyncResult) msg.obj; |
| 1239 | request = (MainThreadRequest) ar.userObj; |
| 1240 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1241 | try { |
| 1242 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1243 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1244 | cb.onError( |
| 1245 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1246 | ar.exception.getClass().getName(), |
| 1247 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1248 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1249 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1250 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1251 | } else { |
| 1252 | // use the result as returned |
| 1253 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1254 | } |
| 1255 | } catch (RemoteException re) { |
| 1256 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1257 | } |
| 1258 | break; |
| 1259 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1260 | request = (MainThreadRequest) msg.obj; |
| 1261 | WorkSource ws = (WorkSource) request.argument; |
| 1262 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1263 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1264 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1265 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1266 | ar = (AsyncResult) msg.obj; |
| 1267 | request = (MainThreadRequest) ar.userObj; |
| 1268 | if (ar.exception == null) { |
| 1269 | request.result = ar.result; |
| 1270 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1271 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1272 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1273 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | synchronized (request) { |
| 1277 | request.notifyAll(); |
| 1278 | } |
| 1279 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1280 | case CMD_MODEM_REBOOT: |
| 1281 | request = (MainThreadRequest) msg.obj; |
| 1282 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1283 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1284 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1285 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1286 | handleNullReturnEvent(msg, "rebootModem"); |
| 1287 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1288 | case CMD_REQUEST_ENABLE_MODEM: |
| 1289 | request = (MainThreadRequest) msg.obj; |
| 1290 | boolean enable = (boolean) request.argument; |
| 1291 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1292 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1293 | PhoneConfigurationManager.getInstance() |
| 1294 | .enablePhone(request.phone, enable, onCompleted); |
| 1295 | break; |
| 1296 | case EVENT_ENABLE_MODEM_DONE: |
| 1297 | ar = (AsyncResult) msg.obj; |
| 1298 | request = (MainThreadRequest) ar.userObj; |
| 1299 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1300 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1301 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1302 | if ((boolean) request.result) { |
| 1303 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1304 | updateModemStateMetrics(); |
| 1305 | } else { |
| 1306 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1307 | + ar.exception); |
| 1308 | } |
| 1309 | notifyRequester(request); |
| 1310 | break; |
| 1311 | case CMD_GET_MODEM_STATUS: |
| 1312 | request = (MainThreadRequest) msg.obj; |
| 1313 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1314 | PhoneConfigurationManager.getInstance() |
| 1315 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1316 | break; |
| 1317 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1318 | ar = (AsyncResult) msg.obj; |
| 1319 | request = (MainThreadRequest) ar.userObj; |
| 1320 | int id = request.phone.getPhoneId(); |
| 1321 | if (ar.exception == null && ar.result != null) { |
| 1322 | request.result = ar.result; |
| 1323 | //update the cache as modem status has changed |
| 1324 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1325 | (boolean) request.result); |
| 1326 | } else { |
| 1327 | // Return true if modem status cannot be retrieved. For most cases, |
| 1328 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1329 | // and disable modem are not supported. Modem is always on. |
| 1330 | // TODO: this should be fixed in R to support a third |
| 1331 | // status UNKNOWN b/131631629 |
| 1332 | request.result = true; |
| 1333 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1334 | + ar.exception); |
| 1335 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1336 | notifyRequester(request); |
| 1337 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1338 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1339 | ar = (AsyncResult) msg.obj; |
| 1340 | request = (MainThreadRequest) ar.userObj; |
| 1341 | if (ar.exception == null && ar.result != null) { |
| 1342 | request.result = ar.result; |
| 1343 | } else { |
| 1344 | request.result = -1; |
| 1345 | loge("Failed to set Forbidden Plmns"); |
| 1346 | if (ar.result == null) { |
| 1347 | loge("setForbidenPlmns: Empty response"); |
| 1348 | } else if (ar.exception != null) { |
| 1349 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1350 | request.result = -1; |
| 1351 | } else { |
| 1352 | loge("setForbiddenPlmns: Unknown exception"); |
| 1353 | } |
| 1354 | } |
| 1355 | notifyRequester(request); |
| 1356 | break; |
| 1357 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1358 | request = (MainThreadRequest) msg.obj; |
| 1359 | uiccCard = getUiccCardFromRequest(request); |
| 1360 | if (uiccCard == null) { |
| 1361 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1362 | request.result = -1; |
| 1363 | notifyRequester(request); |
| 1364 | break; |
| 1365 | } |
| 1366 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1367 | (Pair<Integer, List<String>>) request.argument; |
| 1368 | appType = setFplmnsArgs.first; |
| 1369 | List<String> fplmns = setFplmnsArgs.second; |
| 1370 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1371 | if (uiccApp == null) { |
| 1372 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1373 | request.result = -1; |
| 1374 | loge("Failed to get UICC App"); |
| 1375 | notifyRequester(request); |
| 1376 | } else { |
| 1377 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1378 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1379 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1380 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1381 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1382 | case CMD_ERASE_MODEM_CONFIG: |
| 1383 | request = (MainThreadRequest) msg.obj; |
| 1384 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1385 | defaultPhone.eraseModemConfig(onCompleted); |
| 1386 | break; |
| 1387 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1388 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1389 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1390 | |
| 1391 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1392 | request = (MainThreadRequest) msg.obj; |
| 1393 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1394 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1395 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1396 | changed.first, changed.second, onCompleted); |
| 1397 | break; |
| 1398 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1399 | ar = (AsyncResult) msg.obj; |
| 1400 | request = (MainThreadRequest) ar.userObj; |
| 1401 | if (ar.exception == null) { |
| 1402 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1403 | } else { |
| 1404 | request.result = msg.arg1; |
| 1405 | } |
| 1406 | notifyRequester(request); |
| 1407 | break; |
| 1408 | |
| 1409 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1410 | request = (MainThreadRequest) msg.obj; |
| 1411 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1412 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1413 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1414 | enabled.first, enabled.second, onCompleted); |
| 1415 | break; |
| 1416 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1417 | ar = (AsyncResult) msg.obj; |
| 1418 | request = (MainThreadRequest) ar.userObj; |
| 1419 | if (ar.exception == null) { |
| 1420 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1421 | } else { |
| 1422 | request.result = msg.arg1; |
| 1423 | } |
| 1424 | notifyRequester(request); |
| 1425 | break; |
| 1426 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1427 | default: |
| 1428 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1429 | break; |
| 1430 | } |
| 1431 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1432 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1433 | private void notifyRequester(MainThreadRequest request) { |
| 1434 | synchronized (request) { |
| 1435 | request.notifyAll(); |
| 1436 | } |
| 1437 | } |
| 1438 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1439 | private void handleNullReturnEvent(Message msg, String command) { |
| 1440 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1441 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1442 | if (ar.exception == null) { |
| 1443 | request.result = true; |
| 1444 | } else { |
| 1445 | request.result = false; |
| 1446 | if (ar.exception instanceof CommandException) { |
| 1447 | loge(command + ": CommandException: " + ar.exception); |
| 1448 | } else { |
| 1449 | loge(command + ": Unknown exception"); |
| 1450 | } |
| 1451 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1452 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1453 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | /** |
| 1457 | * Posts the specified command to be executed on the main thread, |
| 1458 | * waits for the request to complete, and returns the result. |
| 1459 | * @see #sendRequestAsync |
| 1460 | */ |
| 1461 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1462 | return sendRequest( |
| 1463 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | /** |
| 1467 | * Posts the specified command to be executed on the main thread, |
| 1468 | * waits for the request to complete, and returns the result. |
| 1469 | * @see #sendRequestAsync |
| 1470 | */ |
| 1471 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1472 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1473 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | /** |
| 1477 | * Posts the specified command to be executed on the main thread, |
| 1478 | * waits for the request to complete, and returns the result. |
| 1479 | * @see #sendRequestAsync |
| 1480 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1481 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1482 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | /** |
| 1486 | * Posts the specified command to be executed on the main thread, |
| 1487 | * waits for the request to complete, and returns the result. |
| 1488 | * @see #sendRequestAsync |
| 1489 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1490 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1491 | return sendRequest(command, argument, subId, null, workSource); |
| 1492 | } |
| 1493 | |
| 1494 | /** |
| 1495 | * Posts the specified command to be executed on the main thread, |
| 1496 | * waits for the request to complete, and returns the result. |
| 1497 | * @see #sendRequestAsync |
| 1498 | */ |
| 1499 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1500 | return sendRequest( |
| 1501 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1502 | } |
| 1503 | |
| 1504 | /** |
| 1505 | * Posts the specified command to be executed on the main thread, |
| 1506 | * waits for the request to complete, and returns the result. |
| 1507 | * @see #sendRequestAsync |
| 1508 | */ |
| 1509 | private Object sendRequest( |
| 1510 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1511 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1512 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1513 | } |
| 1514 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1515 | MainThreadRequest request = null; |
| 1516 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1517 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1518 | } else if (phone != null) { |
| 1519 | request = new MainThreadRequest(argument, phone, workSource); |
| 1520 | } else { |
| 1521 | request = new MainThreadRequest(argument, subId, workSource); |
| 1522 | } |
| 1523 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1524 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1525 | msg.sendToTarget(); |
| 1526 | |
| 1527 | // Wait for the request to complete |
| 1528 | synchronized (request) { |
| 1529 | while (request.result == null) { |
| 1530 | try { |
| 1531 | request.wait(); |
| 1532 | } catch (InterruptedException e) { |
| 1533 | // Do nothing, go back and wait until the request is complete |
| 1534 | } |
| 1535 | } |
| 1536 | } |
| 1537 | return request.result; |
| 1538 | } |
| 1539 | |
| 1540 | /** |
| 1541 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1542 | * Posts the specified command to be executed on the main thread, and |
| 1543 | * returns immediately. |
| 1544 | * @see #sendRequest |
| 1545 | */ |
| 1546 | private void sendRequestAsync(int command) { |
| 1547 | mMainThreadHandler.sendEmptyMessage(command); |
| 1548 | } |
| 1549 | |
| 1550 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1551 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1552 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1553 | */ |
| 1554 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1555 | sendRequestAsync(command, argument, null, null); |
| 1556 | } |
| 1557 | |
| 1558 | /** |
| 1559 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1560 | * @see {@link #sendRequest(int,Object)} |
| 1561 | */ |
| 1562 | private void sendRequestAsync( |
| 1563 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1564 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1565 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1566 | msg.sendToTarget(); |
| 1567 | } |
| 1568 | |
| 1569 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1570 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1571 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1572 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1573 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1574 | synchronized (PhoneInterfaceManager.class) { |
| 1575 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1576 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1577 | } else { |
| 1578 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1579 | } |
| 1580 | return sInstance; |
| 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1585 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1586 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1587 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1588 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1589 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1590 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1591 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1592 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1593 | mTelephonySharedPreferences = |
| 1594 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1595 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1596 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1597 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1598 | publish(); |
| 1599 | } |
| 1600 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1601 | private Phone getDefaultPhone() { |
| 1602 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1603 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1604 | } |
| 1605 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1606 | private void publish() { |
| 1607 | if (DBG) log("publish: " + this); |
| 1608 | |
| 1609 | ServiceManager.addService("phone", this); |
| 1610 | } |
| 1611 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1612 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1613 | if (request.phone != null) { |
| 1614 | return request.phone; |
| 1615 | } else { |
| 1616 | return getPhoneFromSubId(request.subId); |
| 1617 | } |
| 1618 | } |
| 1619 | |
| 1620 | private Phone getPhoneFromSubId(int subId) { |
| 1621 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1622 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1623 | } |
| 1624 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1625 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1626 | Phone phone = getPhoneFromRequest(request); |
| 1627 | return phone == null ? null : |
| 1628 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1629 | } |
| 1630 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1631 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1632 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1633 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1634 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1635 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1636 | private void sendEraseModemConfig(Phone phone) { |
| 1637 | if (phone != null) { |
| 1638 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1639 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1640 | final long identity = Binder.clearCallingIdentity(); |
| 1641 | try { |
| 1642 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1643 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1644 | } finally { |
| 1645 | Binder.restoreCallingIdentity(identity); |
| 1646 | } |
| 1647 | } |
| 1648 | } |
| 1649 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1650 | private boolean isImsAvailableOnDevice() { |
| 1651 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1652 | if (pm == null) { |
| 1653 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1654 | // so do not throw error and allow. |
| 1655 | return true; |
| 1656 | } |
| 1657 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1658 | } |
| 1659 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1660 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1661 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1662 | } |
| 1663 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1664 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1665 | if (DBG) log("dial: " + number); |
| 1666 | // No permission check needed here: This is just a wrapper around the |
| 1667 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1668 | // the UI before it does anything. |
| 1669 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1670 | final long identity = Binder.clearCallingIdentity(); |
| 1671 | try { |
| 1672 | String url = createTelUrl(number); |
| 1673 | if (url == null) { |
| 1674 | return; |
| 1675 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1676 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1677 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1678 | PhoneConstants.State state = mCM.getState(subId); |
| 1679 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1680 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1681 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1682 | mApp.startActivity(intent); |
| 1683 | } |
| 1684 | } finally { |
| 1685 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1686 | } |
| 1687 | } |
| 1688 | |
| 1689 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1690 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1693 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1694 | if (DBG) log("call: " + number); |
| 1695 | |
| 1696 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1697 | // need to do a permission check since we're calling startActivity() |
| 1698 | // from the context of the phone app. |
| 1699 | enforceCallPermission(); |
| 1700 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1701 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1702 | != AppOpsManager.MODE_ALLOWED) { |
| 1703 | return; |
| 1704 | } |
| 1705 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1706 | final long identity = Binder.clearCallingIdentity(); |
| 1707 | try { |
| 1708 | String url = createTelUrl(number); |
| 1709 | if (url == null) { |
| 1710 | return; |
| 1711 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1712 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1713 | boolean isValid = false; |
| 1714 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1715 | if (slist != null) { |
| 1716 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1717 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1718 | isValid = true; |
| 1719 | break; |
| 1720 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1721 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1722 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1723 | if (!isValid) { |
| 1724 | return; |
| 1725 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1726 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1727 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1728 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1729 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1730 | mApp.startActivity(intent); |
| 1731 | } finally { |
| 1732 | Binder.restoreCallingIdentity(identity); |
| 1733 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1736 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1737 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1738 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1739 | } |
| 1740 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1741 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1742 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1743 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1744 | } |
| 1745 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1746 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1747 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1748 | |
| 1749 | final long identity = Binder.clearCallingIdentity(); |
| 1750 | try { |
| 1751 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1752 | checkSimPin.start(); |
| 1753 | return checkSimPin.unlockSim(null, pin); |
| 1754 | } finally { |
| 1755 | Binder.restoreCallingIdentity(identity); |
| 1756 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1759 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1760 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1761 | |
| 1762 | final long identity = Binder.clearCallingIdentity(); |
| 1763 | try { |
| 1764 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1765 | checkSimPuk.start(); |
| 1766 | return checkSimPuk.unlockSim(puk, pin); |
| 1767 | } finally { |
| 1768 | Binder.restoreCallingIdentity(identity); |
| 1769 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1773 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1774 | * a synchronous one. |
| 1775 | */ |
| 1776 | private static class UnlockSim extends Thread { |
| 1777 | |
| 1778 | private final IccCard mSimCard; |
| 1779 | |
| 1780 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1781 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1782 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1783 | |
| 1784 | // For replies from SimCard interface |
| 1785 | private Handler mHandler; |
| 1786 | |
| 1787 | // For async handler to identify request type |
| 1788 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1789 | |
| 1790 | public UnlockSim(IccCard simCard) { |
| 1791 | mSimCard = simCard; |
| 1792 | } |
| 1793 | |
| 1794 | @Override |
| 1795 | public void run() { |
| 1796 | Looper.prepare(); |
| 1797 | synchronized (UnlockSim.this) { |
| 1798 | mHandler = new Handler() { |
| 1799 | @Override |
| 1800 | public void handleMessage(Message msg) { |
| 1801 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1802 | switch (msg.what) { |
| 1803 | case SUPPLY_PIN_COMPLETE: |
| 1804 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1805 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1806 | mRetryCount = msg.arg1; |
| 1807 | if (ar.exception != null) { |
| 1808 | if (ar.exception instanceof CommandException && |
| 1809 | ((CommandException)(ar.exception)).getCommandError() |
| 1810 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1811 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1812 | } else { |
| 1813 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1814 | } |
| 1815 | } else { |
| 1816 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1817 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1818 | mDone = true; |
| 1819 | UnlockSim.this.notifyAll(); |
| 1820 | } |
| 1821 | break; |
| 1822 | } |
| 1823 | } |
| 1824 | }; |
| 1825 | UnlockSim.this.notifyAll(); |
| 1826 | } |
| 1827 | Looper.loop(); |
| 1828 | } |
| 1829 | |
| 1830 | /* |
| 1831 | * Use PIN or PUK to unlock SIM card |
| 1832 | * |
| 1833 | * If PUK is null, unlock SIM card with PIN |
| 1834 | * |
| 1835 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1836 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1837 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1838 | |
| 1839 | while (mHandler == null) { |
| 1840 | try { |
| 1841 | wait(); |
| 1842 | } catch (InterruptedException e) { |
| 1843 | Thread.currentThread().interrupt(); |
| 1844 | } |
| 1845 | } |
| 1846 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1847 | |
| 1848 | if (puk == null) { |
| 1849 | mSimCard.supplyPin(pin, callback); |
| 1850 | } else { |
| 1851 | mSimCard.supplyPuk(puk, pin, callback); |
| 1852 | } |
| 1853 | |
| 1854 | while (!mDone) { |
| 1855 | try { |
| 1856 | Log.d(LOG_TAG, "wait for done"); |
| 1857 | wait(); |
| 1858 | } catch (InterruptedException e) { |
| 1859 | // Restore the interrupted status |
| 1860 | Thread.currentThread().interrupt(); |
| 1861 | } |
| 1862 | } |
| 1863 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1864 | int[] resultArray = new int[2]; |
| 1865 | resultArray[0] = mResult; |
| 1866 | resultArray[1] = mRetryCount; |
| 1867 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1868 | } |
| 1869 | } |
| 1870 | |
| 1871 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1872 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1873 | |
| 1874 | } |
| 1875 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1876 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1877 | // No permission check needed here: this call is harmless, and it's |
| 1878 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1879 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1880 | final long identity = Binder.clearCallingIdentity(); |
| 1881 | try { |
| 1882 | final Phone phone = getPhone(subId); |
| 1883 | if (phone != null) { |
| 1884 | phone.updateServiceLocation(); |
| 1885 | } |
| 1886 | } finally { |
| 1887 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1888 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1889 | } |
| 1890 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1891 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1892 | @Override |
| 1893 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1894 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1897 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1898 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1899 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1900 | callingFeatureId); |
| 1901 | } |
| 1902 | |
| 1903 | @Deprecated |
| 1904 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1905 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1906 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 1907 | } |
| 1908 | |
| 1909 | @Override |
| 1910 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1911 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1912 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1913 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1914 | return false; |
| 1915 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1916 | |
| 1917 | final long identity = Binder.clearCallingIdentity(); |
| 1918 | try { |
| 1919 | return isRadioOnForSubscriber(subId); |
| 1920 | } finally { |
| 1921 | Binder.restoreCallingIdentity(identity); |
| 1922 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1926 | final long identity = Binder.clearCallingIdentity(); |
| 1927 | try { |
| 1928 | final Phone phone = getPhone(subId); |
| 1929 | if (phone != null) { |
| 1930 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1931 | } else { |
| 1932 | return false; |
| 1933 | } |
| 1934 | } finally { |
| 1935 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1936 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1940 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1941 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1942 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1943 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1944 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1945 | |
| 1946 | final long identity = Binder.clearCallingIdentity(); |
| 1947 | try { |
| 1948 | final Phone phone = getPhone(subId); |
| 1949 | if (phone != null) { |
| 1950 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1951 | } |
| 1952 | } finally { |
| 1953 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1954 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1958 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1961 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1962 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1963 | |
| 1964 | final long identity = Binder.clearCallingIdentity(); |
| 1965 | try { |
| 1966 | final Phone phone = getPhone(subId); |
| 1967 | if (phone == null) { |
| 1968 | return false; |
| 1969 | } |
| 1970 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1971 | toggleRadioOnOffForSubscriber(subId); |
| 1972 | } |
| 1973 | return true; |
| 1974 | } finally { |
| 1975 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1976 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1977 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1978 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1979 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 1980 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1981 | /* |
| 1982 | * If any of the Radios are available, it will need to be |
| 1983 | * shutdown. So return true if any Radio is available. |
| 1984 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1985 | final long identity = Binder.clearCallingIdentity(); |
| 1986 | try { |
| 1987 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1988 | Phone phone = PhoneFactory.getPhone(i); |
| 1989 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1990 | } |
| 1991 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1992 | return false; |
| 1993 | } finally { |
| 1994 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1995 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1998 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1999 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2000 | enforceModifyPermission(); |
| 2001 | |
| 2002 | final long identity = Binder.clearCallingIdentity(); |
| 2003 | try { |
| 2004 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2005 | logv("Shutting down Phone " + i); |
| 2006 | shutdownRadioUsingPhoneId(i); |
| 2007 | } |
| 2008 | } finally { |
| 2009 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2010 | } |
| 2011 | } |
| 2012 | |
| 2013 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2014 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2015 | if (phone != null && phone.isRadioAvailable()) { |
| 2016 | phone.shutdownRadio(); |
| 2017 | } |
| 2018 | } |
| 2019 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2020 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2021 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2022 | |
| 2023 | final long identity = Binder.clearCallingIdentity(); |
| 2024 | try { |
| 2025 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2026 | if (defaultPhone != null) { |
| 2027 | defaultPhone.setRadioPower(turnOn); |
| 2028 | return true; |
| 2029 | } else { |
| 2030 | loge("There's no default phone."); |
| 2031 | return false; |
| 2032 | } |
| 2033 | } finally { |
| 2034 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2035 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2038 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2039 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2040 | |
| 2041 | final long identity = Binder.clearCallingIdentity(); |
| 2042 | try { |
| 2043 | final Phone phone = getPhone(subId); |
| 2044 | if (phone != null) { |
| 2045 | phone.setRadioPower(turnOn); |
| 2046 | return true; |
| 2047 | } else { |
| 2048 | return false; |
| 2049 | } |
| 2050 | } finally { |
| 2051 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2052 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2053 | } |
| 2054 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2055 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2056 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2057 | public boolean enableDataConnectivity() { |
| 2058 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2059 | |
| 2060 | final long identity = Binder.clearCallingIdentity(); |
| 2061 | try { |
| 2062 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2063 | final Phone phone = getPhone(subId); |
| 2064 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2065 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2066 | return true; |
| 2067 | } else { |
| 2068 | return false; |
| 2069 | } |
| 2070 | } finally { |
| 2071 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2072 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2073 | } |
| 2074 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2075 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2076 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2077 | public boolean disableDataConnectivity() { |
| 2078 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2079 | |
| 2080 | final long identity = Binder.clearCallingIdentity(); |
| 2081 | try { |
| 2082 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2083 | final Phone phone = getPhone(subId); |
| 2084 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2085 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2086 | return true; |
| 2087 | } else { |
| 2088 | return false; |
| 2089 | } |
| 2090 | } finally { |
| 2091 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2092 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2095 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2096 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2097 | final long identity = Binder.clearCallingIdentity(); |
| 2098 | try { |
| 2099 | final Phone phone = getPhone(subId); |
| 2100 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2101 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2102 | } else { |
| 2103 | return false; |
| 2104 | } |
| 2105 | } finally { |
| 2106 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2107 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
| 2110 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2111 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2114 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2115 | enforceCallPermission(); |
| 2116 | |
| 2117 | final long identity = Binder.clearCallingIdentity(); |
| 2118 | try { |
| 2119 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2120 | return; |
| 2121 | } |
| 2122 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2123 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2124 | } finally { |
| 2125 | Binder.restoreCallingIdentity(identity); |
| 2126 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2127 | }; |
| 2128 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2129 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2130 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2131 | |
| 2132 | final long identity = Binder.clearCallingIdentity(); |
| 2133 | try { |
| 2134 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2135 | return false; |
| 2136 | } |
| 2137 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2138 | } finally { |
| 2139 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2140 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2141 | } |
| 2142 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2143 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2144 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2145 | } |
| 2146 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2147 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2148 | final long identity = Binder.clearCallingIdentity(); |
| 2149 | try { |
| 2150 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2151 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2152 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2153 | } finally { |
| 2154 | Binder.restoreCallingIdentity(identity); |
| 2155 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2156 | } |
| 2157 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2158 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2159 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2160 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2161 | } |
| 2162 | |
| 2163 | @Override |
| 2164 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2165 | final long identity = Binder.clearCallingIdentity(); |
| 2166 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2167 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2168 | if (phone != null) { |
| 2169 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2170 | } else { |
| 2171 | return PhoneConstantConversions.convertDataState( |
| 2172 | PhoneConstants.DataState.DISCONNECTED); |
| 2173 | } |
| 2174 | } finally { |
| 2175 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2176 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2177 | } |
| 2178 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2179 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2180 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2181 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2182 | } |
| 2183 | |
| 2184 | @Override |
| 2185 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2186 | final long identity = Binder.clearCallingIdentity(); |
| 2187 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2188 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2189 | if (phone != null) { |
| 2190 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2191 | } else { |
| 2192 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2193 | } |
| 2194 | } finally { |
| 2195 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2196 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2200 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2201 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2202 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2203 | |
| 2204 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2205 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2206 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2207 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2208 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2209 | .setCallingPid(Binder.getCallingPid()) |
| 2210 | .setCallingUid(Binder.getCallingUid()) |
| 2211 | .setMethod("getCellLocation") |
| 2212 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2213 | .build()); |
| 2214 | switch (locationResult) { |
| 2215 | case DENIED_HARD: |
| 2216 | throw new SecurityException("Not allowed to access cell location"); |
| 2217 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2218 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2219 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2220 | } |
| 2221 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2222 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2223 | final long identity = Binder.clearCallingIdentity(); |
| 2224 | try { |
| 2225 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2226 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2227 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2228 | } finally { |
| 2229 | Binder.restoreCallingIdentity(identity); |
| 2230 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2231 | } |
| 2232 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2233 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2234 | public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage, |
| 2235 | String callingFeatureId) { |
Jack Yu | 7c5d91a | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2236 | if (!TextUtils.isEmpty(callingPackage)) { |
| 2237 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2238 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2239 | callingFeatureId, "getNetworkCountryIsoForPhone")) { |
Jack Yu | 7c5d91a | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2240 | return ""; |
| 2241 | } |
| 2242 | } |
| 2243 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2244 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2245 | // registered cell info, so return a NULL country instead. |
| 2246 | final long identity = Binder.clearCallingIdentity(); |
| 2247 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2248 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2249 | // Get default phone in this case. |
| 2250 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2251 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2252 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2253 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2254 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2255 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2256 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(), |
| 2257 | null)) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2258 | return ""; |
| 2259 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2260 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2261 | if (phone != null) { |
| 2262 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2263 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2264 | if (sst != null) { |
| 2265 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2266 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2267 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2268 | return lt.getCurrentCountry(); |
| 2269 | } else if (emergencyNumberTracker != null) { |
| 2270 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2271 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2272 | } |
| 2273 | } |
| 2274 | } |
| 2275 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2276 | } finally { |
| 2277 | Binder.restoreCallingIdentity(identity); |
| 2278 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2282 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2283 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2286 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2287 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2288 | mApp.enforceCallingOrSelfPermission( |
| 2289 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2290 | |
| 2291 | final long identity = Binder.clearCallingIdentity(); |
| 2292 | try { |
| 2293 | final Phone phone = getPhone(subId); |
| 2294 | if (phone != null) { |
| 2295 | phone.enableLocationUpdates(); |
| 2296 | } |
| 2297 | } finally { |
| 2298 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2299 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | @Override |
| 2303 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2304 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2307 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2308 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2309 | mApp.enforceCallingOrSelfPermission( |
| 2310 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2311 | |
| 2312 | final long identity = Binder.clearCallingIdentity(); |
| 2313 | try { |
| 2314 | final Phone phone = getPhone(subId); |
| 2315 | if (phone != null) { |
| 2316 | phone.disableLocationUpdates(); |
| 2317 | } |
| 2318 | } finally { |
| 2319 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2320 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2321 | } |
| 2322 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2323 | /** |
| 2324 | * Returns the target SDK version number for a given package name. |
| 2325 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2326 | * This call MUST be invoked before clearing the calling UID. |
| 2327 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2328 | * @return target SDK if the package is found or INT_MAX. |
| 2329 | */ |
| 2330 | private int getTargetSdk(String packageName) { |
| 2331 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2332 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2333 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2334 | if (ai != null) return ai.targetSdkVersion; |
| 2335 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2336 | loge("Failed to get package info for pkg=" |
| 2337 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2338 | } |
| 2339 | return Integer.MAX_VALUE; |
| 2340 | } |
| 2341 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2342 | @Override |
| 2343 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2344 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2345 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2346 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2347 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2348 | throw new SecurityException( |
| 2349 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2350 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2351 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2352 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2353 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2354 | return null; |
| 2355 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2356 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2357 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2358 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2359 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2360 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2361 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2362 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2363 | for (CellInfo ci : info) { |
| 2364 | if (ci instanceof CellInfoGsm) { |
| 2365 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2366 | } else if (ci instanceof CellInfoWcdma) { |
| 2367 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2368 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2369 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2370 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2371 | } |
| 2372 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2373 | private List<CellInfo> getCachedCellInfo() { |
| 2374 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2375 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2376 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2377 | if (info != null) cellInfos.addAll(info); |
| 2378 | } |
| 2379 | return cellInfos; |
| 2380 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2381 | |
| 2382 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2383 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2384 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2385 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2386 | |
| 2387 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2388 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2389 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2390 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2391 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2392 | .setCallingPid(Binder.getCallingPid()) |
| 2393 | .setCallingUid(Binder.getCallingUid()) |
| 2394 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2395 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2396 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2397 | .build()); |
| 2398 | switch (locationResult) { |
| 2399 | case DENIED_HARD: |
| 2400 | throw new SecurityException("Not allowed to access cell info"); |
| 2401 | case DENIED_SOFT: |
| 2402 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2403 | } |
| 2404 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2405 | final int targetSdk = getTargetSdk(callingPackage); |
| 2406 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2407 | return getCachedCellInfo(); |
| 2408 | } |
| 2409 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2410 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2411 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2412 | final long identity = Binder.clearCallingIdentity(); |
| 2413 | try { |
| 2414 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2415 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2416 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2417 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2418 | if (info != null) cellInfos.addAll(info); |
| 2419 | } |
| 2420 | return cellInfos; |
| 2421 | } finally { |
| 2422 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2423 | } |
| 2424 | } |
| 2425 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2426 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2427 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2428 | String callingFeatureId) { |
| 2429 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2430 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2434 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2435 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2436 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2437 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2440 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2441 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2442 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2443 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2444 | |
| 2445 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2446 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2447 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2448 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2449 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2450 | .setCallingPid(Binder.getCallingPid()) |
| 2451 | .setCallingUid(Binder.getCallingUid()) |
| 2452 | .setMethod("requestCellInfoUpdate") |
| 2453 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2454 | .build()); |
| 2455 | switch (locationResult) { |
| 2456 | case DENIED_HARD: |
| 2457 | throw new SecurityException("Not allowed to access cell info"); |
| 2458 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2459 | try { |
| 2460 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2461 | } catch (RemoteException re) { |
| 2462 | // Drop without consequences |
| 2463 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2464 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2465 | } |
| 2466 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2467 | |
| 2468 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2469 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2470 | |
| 2471 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2472 | } |
| 2473 | |
| 2474 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2475 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2476 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2477 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2478 | |
| 2479 | final long identity = Binder.clearCallingIdentity(); |
| 2480 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2481 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2482 | } finally { |
| 2483 | Binder.restoreCallingIdentity(identity); |
| 2484 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2485 | } |
| 2486 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2487 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2488 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2489 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2490 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2491 | return null; |
| 2492 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2493 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2494 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2495 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2496 | return null; |
| 2497 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2498 | |
| 2499 | final long identity = Binder.clearCallingIdentity(); |
| 2500 | try { |
| 2501 | return phone.getImei(); |
| 2502 | } finally { |
| 2503 | Binder.restoreCallingIdentity(identity); |
| 2504 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2505 | } |
| 2506 | |
| 2507 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2508 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2509 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2510 | String tac = null; |
| 2511 | if (phone != null) { |
| 2512 | String imei = phone.getImei(); |
| 2513 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2514 | } |
| 2515 | return tac; |
| 2516 | } |
| 2517 | |
| 2518 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2519 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2520 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2521 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2522 | return null; |
| 2523 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2524 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2525 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2526 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2527 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2528 | return null; |
| 2529 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2530 | |
| 2531 | final long identity = Binder.clearCallingIdentity(); |
| 2532 | try { |
| 2533 | return phone.getMeid(); |
| 2534 | } finally { |
| 2535 | Binder.restoreCallingIdentity(identity); |
| 2536 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2540 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2541 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2542 | String manufacturerCode = null; |
| 2543 | if (phone != null) { |
| 2544 | String meid = phone.getMeid(); |
| 2545 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2546 | } |
| 2547 | return manufacturerCode; |
| 2548 | } |
| 2549 | |
| 2550 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2551 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2552 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2553 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2554 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2555 | return null; |
| 2556 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2557 | int subId = phone.getSubId(); |
| 2558 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2559 | mApp, subId, callingPackage, callingFeatureId, |
| 2560 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2561 | return null; |
| 2562 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2563 | |
| 2564 | final long identity = Binder.clearCallingIdentity(); |
| 2565 | try { |
| 2566 | return phone.getDeviceSvn(); |
| 2567 | } finally { |
| 2568 | Binder.restoreCallingIdentity(identity); |
| 2569 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2570 | } |
| 2571 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2572 | @Override |
| 2573 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2574 | final long identity = Binder.clearCallingIdentity(); |
| 2575 | try { |
| 2576 | final Phone phone = getPhone(subId); |
| 2577 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2578 | } finally { |
| 2579 | Binder.restoreCallingIdentity(identity); |
| 2580 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | @Override |
| 2584 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2585 | final long identity = Binder.clearCallingIdentity(); |
| 2586 | try { |
| 2587 | final Phone phone = getPhone(subId); |
| 2588 | return phone == null ? null : phone.getCarrierName(); |
| 2589 | } finally { |
| 2590 | Binder.restoreCallingIdentity(identity); |
| 2591 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2592 | } |
| 2593 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2594 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2595 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2596 | final long identity = Binder.clearCallingIdentity(); |
| 2597 | try { |
| 2598 | final Phone phone = getPhone(subId); |
| 2599 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2600 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2601 | } finally { |
| 2602 | Binder.restoreCallingIdentity(identity); |
| 2603 | } |
| 2604 | } |
| 2605 | |
| 2606 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2607 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2608 | final long identity = Binder.clearCallingIdentity(); |
| 2609 | try { |
| 2610 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2611 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2612 | } finally { |
| 2613 | Binder.restoreCallingIdentity(identity); |
| 2614 | } |
| 2615 | } |
| 2616 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2617 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2618 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2619 | if (!isSubscriptionMccMnc) { |
| 2620 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2621 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2622 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2623 | if (phone == null) { |
| 2624 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2625 | } |
| 2626 | final long identity = Binder.clearCallingIdentity(); |
| 2627 | try { |
| 2628 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2629 | } finally { |
| 2630 | Binder.restoreCallingIdentity(identity); |
| 2631 | } |
| 2632 | } |
| 2633 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2634 | // |
| 2635 | // Internal helper methods. |
| 2636 | // |
| 2637 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2638 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2639 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2640 | * |
| 2641 | * @throws SecurityException if the caller does not have the required permission |
| 2642 | */ |
| 2643 | private void enforceModifyPermission() { |
| 2644 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2645 | } |
| 2646 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2647 | /** |
| 2648 | * Make sure the caller is system. |
| 2649 | * |
| 2650 | * @throws SecurityException if the caller is not system. |
| 2651 | */ |
| 2652 | private void enforceSystemCaller() { |
| 2653 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2654 | throw new SecurityException("Caller must be system"); |
| 2655 | } |
| 2656 | } |
| 2657 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2658 | private void enforceActiveEmergencySessionPermission() { |
| 2659 | mApp.enforceCallingOrSelfPermission( |
| 2660 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2661 | } |
| 2662 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2663 | /** |
| 2664 | * Make sure the caller has the CALL_PHONE permission. |
| 2665 | * |
| 2666 | * @throws SecurityException if the caller does not have the required permission |
| 2667 | */ |
| 2668 | private void enforceCallPermission() { |
| 2669 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2670 | } |
| 2671 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2672 | private void enforceSettingsPermission() { |
| 2673 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2674 | } |
| 2675 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2676 | private String createTelUrl(String number) { |
| 2677 | if (TextUtils.isEmpty(number)) { |
| 2678 | return null; |
| 2679 | } |
| 2680 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2681 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2682 | } |
| 2683 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2684 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2685 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2686 | } |
| 2687 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2688 | private static void logv(String msg) { |
| 2689 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2690 | } |
| 2691 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2692 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2693 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2694 | } |
| 2695 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2696 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2697 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2698 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2699 | } |
| 2700 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2701 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2702 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2703 | final long identity = Binder.clearCallingIdentity(); |
| 2704 | try { |
| 2705 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2706 | if (phone == null) { |
| 2707 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2708 | } else { |
| 2709 | return phone.getPhoneType(); |
| 2710 | } |
| 2711 | } finally { |
| 2712 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2713 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | /** |
| 2717 | * Returns the CDMA ERI icon index to display |
| 2718 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2719 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2720 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2721 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2722 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2723 | } |
| 2724 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2725 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2726 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2727 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2728 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2729 | mApp, subId, callingPackage, callingFeatureId, |
| 2730 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2731 | return -1; |
| 2732 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2733 | |
| 2734 | final long identity = Binder.clearCallingIdentity(); |
| 2735 | try { |
| 2736 | final Phone phone = getPhone(subId); |
| 2737 | if (phone != null) { |
| 2738 | return phone.getCdmaEriIconIndex(); |
| 2739 | } else { |
| 2740 | return -1; |
| 2741 | } |
| 2742 | } finally { |
| 2743 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2744 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2745 | } |
| 2746 | |
| 2747 | /** |
| 2748 | * Returns the CDMA ERI icon mode, |
| 2749 | * 0 - ON |
| 2750 | * 1 - FLASHING |
| 2751 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2752 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2753 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2754 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2755 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2756 | } |
| 2757 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2758 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2759 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2760 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2761 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2762 | mApp, subId, callingPackage, callingFeatureId, |
| 2763 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2764 | return -1; |
| 2765 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2766 | |
| 2767 | final long identity = Binder.clearCallingIdentity(); |
| 2768 | try { |
| 2769 | final Phone phone = getPhone(subId); |
| 2770 | if (phone != null) { |
| 2771 | return phone.getCdmaEriIconMode(); |
| 2772 | } else { |
| 2773 | return -1; |
| 2774 | } |
| 2775 | } finally { |
| 2776 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2777 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2778 | } |
| 2779 | |
| 2780 | /** |
| 2781 | * Returns the CDMA ERI text, |
| 2782 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2783 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2784 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2785 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2786 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2787 | } |
| 2788 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2789 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2790 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2791 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2792 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2793 | mApp, subId, callingPackage, callingFeatureId, |
| 2794 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2795 | return null; |
| 2796 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2797 | |
| 2798 | final long identity = Binder.clearCallingIdentity(); |
| 2799 | try { |
| 2800 | final Phone phone = getPhone(subId); |
| 2801 | if (phone != null) { |
| 2802 | return phone.getCdmaEriText(); |
| 2803 | } else { |
| 2804 | return null; |
| 2805 | } |
| 2806 | } finally { |
| 2807 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2808 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2809 | } |
| 2810 | |
| 2811 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2812 | * Returns the CDMA MDN. |
| 2813 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2814 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2815 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2816 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2817 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2818 | |
| 2819 | final long identity = Binder.clearCallingIdentity(); |
| 2820 | try { |
| 2821 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2822 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2823 | return phone.getLine1Number(); |
| 2824 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2825 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2826 | return null; |
| 2827 | } |
| 2828 | } finally { |
| 2829 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2830 | } |
| 2831 | } |
| 2832 | |
| 2833 | /** |
| 2834 | * Returns the CDMA MIN. |
| 2835 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2836 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2837 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2838 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2839 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2840 | |
| 2841 | final long identity = Binder.clearCallingIdentity(); |
| 2842 | try { |
| 2843 | final Phone phone = getPhone(subId); |
| 2844 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2845 | return phone.getCdmaMin(); |
| 2846 | } else { |
| 2847 | return null; |
| 2848 | } |
| 2849 | } finally { |
| 2850 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2851 | } |
| 2852 | } |
| 2853 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2854 | @Override |
| 2855 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2856 | INumberVerificationCallback callback, String callingPackage) { |
| 2857 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2858 | != PERMISSION_GRANTED) { |
| 2859 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2860 | } |
| 2861 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2862 | |
| 2863 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2864 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2865 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2866 | } |
| 2867 | |
| 2868 | if (range == null) { |
| 2869 | throw new NullPointerException("Range must be non-null"); |
| 2870 | } |
| 2871 | |
| 2872 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2873 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2874 | |
| 2875 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2876 | } |
| 2877 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2878 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2879 | * Returns true if CDMA provisioning needs to run. |
| 2880 | */ |
| 2881 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2882 | final long identity = Binder.clearCallingIdentity(); |
| 2883 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2884 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2885 | } finally { |
| 2886 | Binder.restoreCallingIdentity(identity); |
| 2887 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2891 | * Sets the voice mail number of a given subId. |
| 2892 | */ |
| 2893 | @Override |
| 2894 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2895 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2896 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2897 | |
| 2898 | final long identity = Binder.clearCallingIdentity(); |
| 2899 | try { |
| 2900 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2901 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2902 | return success; |
| 2903 | } finally { |
| 2904 | Binder.restoreCallingIdentity(identity); |
| 2905 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2906 | } |
| 2907 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2908 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2909 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2910 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2911 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2912 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2913 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2914 | throw new SecurityException("caller must be system dialer"); |
| 2915 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2916 | |
| 2917 | final long identity = Binder.clearCallingIdentity(); |
| 2918 | try { |
| 2919 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2920 | if (phoneAccountHandle == null) { |
| 2921 | return null; |
| 2922 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2923 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2924 | } finally { |
| 2925 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2926 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2930 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2931 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2932 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2933 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2934 | mApp, subId, callingPackage, callingFeatureId, |
| 2935 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2936 | return null; |
| 2937 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2938 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2939 | final long identity = Binder.clearCallingIdentity(); |
| 2940 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2941 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2942 | } finally { |
| 2943 | Binder.restoreCallingIdentity(identity); |
| 2944 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2948 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2949 | VisualVoicemailSmsFilterSettings settings) { |
| 2950 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2951 | |
| 2952 | final long identity = Binder.clearCallingIdentity(); |
| 2953 | try { |
| 2954 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2955 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2956 | } finally { |
| 2957 | Binder.restoreCallingIdentity(identity); |
| 2958 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2962 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2963 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2964 | |
| 2965 | final long identity = Binder.clearCallingIdentity(); |
| 2966 | try { |
| 2967 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2968 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2969 | } finally { |
| 2970 | Binder.restoreCallingIdentity(identity); |
| 2971 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2972 | } |
| 2973 | |
| 2974 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2975 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2976 | String callingPackage, int subId) { |
| 2977 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2978 | |
| 2979 | final long identity = Binder.clearCallingIdentity(); |
| 2980 | try { |
| 2981 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2982 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2983 | } finally { |
| 2984 | Binder.restoreCallingIdentity(identity); |
| 2985 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2989 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2990 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2991 | |
| 2992 | final long identity = Binder.clearCallingIdentity(); |
| 2993 | try { |
| 2994 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2995 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2996 | } finally { |
| 2997 | Binder.restoreCallingIdentity(identity); |
| 2998 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2999 | } |
| 3000 | |
| 3001 | @Override |
| 3002 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 3003 | String number, int port, String text, PendingIntent sentIntent) { |
| 3004 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3005 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3006 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3007 | SmsController smsController = PhoneFactory.getSmsController(); |
| 3008 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 3009 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3010 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3011 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3012 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3013 | * Sets the voice activation state of a given subId. |
| 3014 | */ |
| 3015 | @Override |
| 3016 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3017 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3018 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3019 | |
| 3020 | final long identity = Binder.clearCallingIdentity(); |
| 3021 | try { |
| 3022 | final Phone phone = getPhone(subId); |
| 3023 | if (phone != null) { |
| 3024 | phone.setVoiceActivationState(activationState); |
| 3025 | } else { |
| 3026 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3027 | } |
| 3028 | } finally { |
| 3029 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3030 | } |
| 3031 | } |
| 3032 | |
| 3033 | /** |
| 3034 | * Sets the data activation state of a given subId. |
| 3035 | */ |
| 3036 | @Override |
| 3037 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3038 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3039 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3040 | |
| 3041 | final long identity = Binder.clearCallingIdentity(); |
| 3042 | try { |
| 3043 | final Phone phone = getPhone(subId); |
| 3044 | if (phone != null) { |
| 3045 | phone.setDataActivationState(activationState); |
| 3046 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3047 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3048 | } |
| 3049 | } finally { |
| 3050 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3051 | } |
| 3052 | } |
| 3053 | |
| 3054 | /** |
| 3055 | * Returns the voice activation state of a given subId. |
| 3056 | */ |
| 3057 | @Override |
| 3058 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3059 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3060 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3061 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3062 | final long identity = Binder.clearCallingIdentity(); |
| 3063 | try { |
| 3064 | if (phone != null) { |
| 3065 | return phone.getVoiceActivationState(); |
| 3066 | } else { |
| 3067 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3068 | } |
| 3069 | } finally { |
| 3070 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3071 | } |
| 3072 | } |
| 3073 | |
| 3074 | /** |
| 3075 | * Returns the data activation state of a given subId. |
| 3076 | */ |
| 3077 | @Override |
| 3078 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3079 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3080 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3081 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3082 | final long identity = Binder.clearCallingIdentity(); |
| 3083 | try { |
| 3084 | if (phone != null) { |
| 3085 | return phone.getDataActivationState(); |
| 3086 | } else { |
| 3087 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3088 | } |
| 3089 | } finally { |
| 3090 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3091 | } |
| 3092 | } |
| 3093 | |
| 3094 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3095 | * Returns the unread count of voicemails for a subId |
| 3096 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3097 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3098 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3099 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3100 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3101 | mApp, subId, callingPackage, callingFeatureId, |
| 3102 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3103 | return 0; |
| 3104 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3105 | final long identity = Binder.clearCallingIdentity(); |
| 3106 | try { |
| 3107 | final Phone phone = getPhone(subId); |
| 3108 | if (phone != null) { |
| 3109 | return phone.getVoiceMessageCount(); |
| 3110 | } else { |
| 3111 | return 0; |
| 3112 | } |
| 3113 | } finally { |
| 3114 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3115 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3116 | } |
| 3117 | |
| 3118 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3119 | * returns true, if the device is in a state where both voice and data |
| 3120 | * are supported simultaneously. This can change based on location or network condition. |
| 3121 | */ |
| 3122 | @Override |
| 3123 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3124 | final long identity = Binder.clearCallingIdentity(); |
| 3125 | try { |
| 3126 | final Phone phone = getPhone(subId); |
| 3127 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3128 | } finally { |
| 3129 | Binder.restoreCallingIdentity(identity); |
| 3130 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3131 | } |
| 3132 | |
| 3133 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3134 | * Send the dialer code if called from the current default dialer or the caller has |
| 3135 | * carrier privilege. |
| 3136 | * @param inputCode The dialer code to send |
| 3137 | */ |
| 3138 | @Override |
| 3139 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3140 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3141 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3142 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3143 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3144 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3145 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3146 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3147 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3148 | |
| 3149 | final long identity = Binder.clearCallingIdentity(); |
| 3150 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3151 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3152 | } finally { |
| 3153 | Binder.restoreCallingIdentity(identity); |
| 3154 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3155 | } |
| 3156 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3157 | @Override |
| 3158 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3159 | TelephonyPermissions |
| 3160 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3161 | mApp, subId, "getNetworkSelectionMode"); |
| 3162 | final long identity = Binder.clearCallingIdentity(); |
| 3163 | try { |
| 3164 | if (!isActiveSubscription(subId)) { |
| 3165 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3166 | } |
| 3167 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3168 | } finally { |
| 3169 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3170 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3171 | } |
| 3172 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3173 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3174 | public boolean isInEmergencySmsMode() { |
| 3175 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3176 | final long identity = Binder.clearCallingIdentity(); |
| 3177 | try { |
| 3178 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3179 | if (phone.isInEmergencySmsMode()) { |
| 3180 | return true; |
| 3181 | } |
| 3182 | } |
| 3183 | } finally { |
| 3184 | Binder.restoreCallingIdentity(identity); |
| 3185 | } |
| 3186 | return false; |
| 3187 | } |
| 3188 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3189 | /** |
| 3190 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3191 | * @param subId The subscription to use to check the configuration. |
| 3192 | * @param c The callback that will be used to send the result. |
| 3193 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3194 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3195 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3196 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3197 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3198 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3199 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3200 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3201 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3202 | "IMS not available on device."); |
| 3203 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3204 | final long token = Binder.clearCallingIdentity(); |
| 3205 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3206 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3207 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3208 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3209 | } catch (ImsException e) { |
| 3210 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3211 | } finally { |
| 3212 | Binder.restoreCallingIdentity(token); |
| 3213 | } |
| 3214 | } |
| 3215 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3216 | /** |
| 3217 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3218 | * @param subId The subscription to use to check the configuration. |
| 3219 | * @param c The callback that will be used to send the result. |
| 3220 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3221 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3222 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3223 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3224 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3225 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3226 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3227 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3228 | final long token = Binder.clearCallingIdentity(); |
| 3229 | try { |
| 3230 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3231 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3232 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3233 | } catch (ImsException e) { |
| 3234 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3235 | + "is inactive, ignoring unregister."); |
| 3236 | // If the subscription is no longer active, just return, since the callback |
| 3237 | // will already have been removed internally. |
| 3238 | } finally { |
| 3239 | Binder.restoreCallingIdentity(token); |
| 3240 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3241 | } |
| 3242 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3243 | /** |
| 3244 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3245 | */ |
| 3246 | @Override |
| 3247 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3248 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3249 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3250 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3251 | "IMS not available on device."); |
| 3252 | } |
| 3253 | final long token = Binder.clearCallingIdentity(); |
| 3254 | try { |
| 3255 | Phone phone = getPhone(subId); |
| 3256 | if (phone == null) { |
| 3257 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3258 | + subId + "'"); |
| 3259 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3260 | } |
| 3261 | phone.getImsRegistrationState(regState -> { |
| 3262 | try { |
| 3263 | consumer.accept((regState == null) |
| 3264 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3265 | } catch (RemoteException e) { |
| 3266 | // Ignore if the remote process is no longer available to call back. |
| 3267 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3268 | } |
| 3269 | }); |
| 3270 | } finally { |
| 3271 | Binder.restoreCallingIdentity(token); |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | /** |
| 3276 | * Get the transport type for the IMS service registration state. |
| 3277 | */ |
| 3278 | @Override |
| 3279 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3280 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3281 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3282 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3283 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3284 | "IMS not available on device."); |
| 3285 | } |
| 3286 | final long token = Binder.clearCallingIdentity(); |
| 3287 | try { |
| 3288 | Phone phone = getPhone(subId); |
| 3289 | if (phone == null) { |
| 3290 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3291 | + subId + "'"); |
| 3292 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3293 | } |
| 3294 | phone.getImsRegistrationTech(regTech -> { |
| 3295 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3296 | int regTechConverted = (regTech == null) |
| 3297 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3298 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3299 | regTechConverted); |
| 3300 | try { |
| 3301 | consumer.accept(regTechConverted); |
| 3302 | } catch (RemoteException e) { |
| 3303 | // Ignore if the remote process is no longer available to call back. |
| 3304 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3305 | } |
| 3306 | }); |
| 3307 | } finally { |
| 3308 | Binder.restoreCallingIdentity(token); |
| 3309 | } |
| 3310 | } |
| 3311 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3312 | /** |
| 3313 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3314 | * @param subId The subscription to use to check the configuration. |
| 3315 | * @param c The callback that will be used to send the result. |
| 3316 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3317 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3318 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3319 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3320 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3321 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3322 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3323 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3324 | "IMS not available on device."); |
| 3325 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3326 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3327 | final long token = Binder.clearCallingIdentity(); |
| 3328 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3329 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3330 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3331 | } catch (ImsException e) { |
| 3332 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3333 | } finally { |
| 3334 | Binder.restoreCallingIdentity(token); |
| 3335 | } |
| 3336 | } |
| 3337 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3338 | /** |
| 3339 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3340 | * @param subId The subscription to use to check the configuration. |
| 3341 | * @param c The callback that will be used to send the result. |
| 3342 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3343 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3344 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3345 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3346 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3347 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3348 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3349 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3350 | |
| 3351 | final long token = Binder.clearCallingIdentity(); |
| 3352 | try { |
| 3353 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3354 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3355 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3356 | } catch (ImsException e) { |
| 3357 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3358 | + "is inactive, ignoring unregister."); |
| 3359 | // If the subscription is no longer active, just return, since the callback |
| 3360 | // will already have been removed internally. |
| 3361 | } finally { |
| 3362 | Binder.restoreCallingIdentity(token); |
| 3363 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3364 | } |
| 3365 | |
| 3366 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3367 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3368 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3369 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3370 | final long token = Binder.clearCallingIdentity(); |
| 3371 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3372 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3373 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3374 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3375 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3376 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3377 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3378 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3379 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3380 | } finally { |
| 3381 | Binder.restoreCallingIdentity(token); |
| 3382 | } |
| 3383 | } |
| 3384 | |
| 3385 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3386 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3387 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3388 | final long token = Binder.clearCallingIdentity(); |
| 3389 | try { |
| 3390 | Phone phone = getPhone(subId); |
| 3391 | if (phone == null) return false; |
| 3392 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3393 | } finally { |
| 3394 | Binder.restoreCallingIdentity(token); |
| 3395 | } |
| 3396 | } |
| 3397 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3398 | /** |
| 3399 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3400 | * subscription. |
| 3401 | * @param subId The subscription to use to check the configuration. |
| 3402 | * @param callback The callback that will be used to send the result. |
| 3403 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3404 | * @param transportType The transport type of the MmTelFeature capability. |
| 3405 | */ |
| 3406 | @Override |
| 3407 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3408 | int transportType) { |
| 3409 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3410 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3411 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3412 | "IMS not available on device."); |
| 3413 | } |
| 3414 | final long token = Binder.clearCallingIdentity(); |
| 3415 | try { |
| 3416 | int slotId = getSlotIndex(subId); |
| 3417 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3418 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3419 | + subId + "'"); |
| 3420 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3421 | } |
| 3422 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3423 | transportType, aBoolean -> { |
| 3424 | try { |
| 3425 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3426 | } catch (RemoteException e) { |
| 3427 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3428 | + "running. Ignore"); |
| 3429 | } |
| 3430 | }); |
| 3431 | } finally { |
| 3432 | Binder.restoreCallingIdentity(token); |
| 3433 | } |
| 3434 | } |
| 3435 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3436 | /** |
| 3437 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3438 | * @param subId The subscription to use to check the configuration. |
| 3439 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3440 | @Override |
| 3441 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3442 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3443 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3444 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3445 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3446 | final long token = Binder.clearCallingIdentity(); |
| 3447 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3448 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3449 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3450 | } catch (ImsException e) { |
| 3451 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3452 | } finally { |
| 3453 | Binder.restoreCallingIdentity(token); |
| 3454 | } |
| 3455 | } |
| 3456 | |
| 3457 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3458 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3459 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3460 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3461 | final long identity = Binder.clearCallingIdentity(); |
| 3462 | try { |
| 3463 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3464 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3465 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3466 | } catch (ImsException e) { |
| 3467 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3468 | } finally { |
| 3469 | Binder.restoreCallingIdentity(identity); |
| 3470 | } |
| 3471 | } |
| 3472 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3473 | /** |
| 3474 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3475 | * @param subId The subscription to use to check the configuration. |
| 3476 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3477 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3478 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3479 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3480 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3481 | final long identity = Binder.clearCallingIdentity(); |
| 3482 | try { |
| 3483 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3484 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3485 | } catch (ImsException e) { |
| 3486 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3487 | } finally { |
| 3488 | Binder.restoreCallingIdentity(identity); |
| 3489 | } |
| 3490 | } |
| 3491 | |
| 3492 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3493 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3494 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3495 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3496 | final long identity = Binder.clearCallingIdentity(); |
| 3497 | try { |
| 3498 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3499 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3500 | } catch (ImsException e) { |
| 3501 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3502 | } finally { |
| 3503 | Binder.restoreCallingIdentity(identity); |
| 3504 | } |
| 3505 | } |
| 3506 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3507 | /** |
| 3508 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3509 | * @param subId The subscription to use to check the configuration. |
| 3510 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3511 | @Override |
| 3512 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3513 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3514 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3515 | final long identity = Binder.clearCallingIdentity(); |
| 3516 | try { |
| 3517 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3518 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3519 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3520 | } catch (ImsException e) { |
| 3521 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3522 | } finally { |
| 3523 | Binder.restoreCallingIdentity(identity); |
| 3524 | } |
| 3525 | } |
| 3526 | |
| 3527 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3528 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3529 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3530 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3531 | final long identity = Binder.clearCallingIdentity(); |
| 3532 | try { |
| 3533 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3534 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3535 | } catch (ImsException e) { |
| 3536 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3537 | } finally { |
| 3538 | Binder.restoreCallingIdentity(identity); |
| 3539 | } |
| 3540 | } |
| 3541 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3542 | /** |
| 3543 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3544 | * @param subId The subscription to use to check the configuration. |
| 3545 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3546 | @Override |
| 3547 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3548 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3549 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3550 | final long identity = Binder.clearCallingIdentity(); |
| 3551 | try { |
| 3552 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3553 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3554 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3555 | } catch (ImsException e) { |
| 3556 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3557 | } finally { |
| 3558 | Binder.restoreCallingIdentity(identity); |
| 3559 | } |
| 3560 | } |
| 3561 | |
| 3562 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3563 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3564 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3565 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3566 | final long identity = Binder.clearCallingIdentity(); |
| 3567 | try { |
| 3568 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3569 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3570 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3571 | } catch (ImsException e) { |
| 3572 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3573 | } finally { |
| 3574 | Binder.restoreCallingIdentity(identity); |
| 3575 | } |
| 3576 | } |
| 3577 | |
| 3578 | @Override |
| 3579 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3580 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3581 | "setVoWiFiNonPersistent"); |
| 3582 | final long identity = Binder.clearCallingIdentity(); |
| 3583 | try { |
| 3584 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3585 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3586 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3587 | } catch (ImsException e) { |
| 3588 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3589 | } finally { |
| 3590 | Binder.restoreCallingIdentity(identity); |
| 3591 | } |
| 3592 | } |
| 3593 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3594 | /** |
| 3595 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3596 | * @param subId The subscription to use to check the configuration. |
| 3597 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3598 | @Override |
| 3599 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3600 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3601 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3602 | final long identity = Binder.clearCallingIdentity(); |
| 3603 | try { |
| 3604 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3605 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3606 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3607 | } catch (ImsException e) { |
| 3608 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3609 | } finally { |
| 3610 | Binder.restoreCallingIdentity(identity); |
| 3611 | } |
| 3612 | } |
| 3613 | |
| 3614 | @Override |
| 3615 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3616 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3617 | "setVoWiFiModeSetting"); |
| 3618 | final long identity = Binder.clearCallingIdentity(); |
| 3619 | try { |
| 3620 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3621 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3622 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3623 | } catch (ImsException e) { |
| 3624 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3625 | } finally { |
| 3626 | Binder.restoreCallingIdentity(identity); |
| 3627 | } |
| 3628 | } |
| 3629 | |
| 3630 | @Override |
| 3631 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3632 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3633 | final long identity = Binder.clearCallingIdentity(); |
| 3634 | try { |
| 3635 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3636 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3637 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3638 | } catch (ImsException e) { |
| 3639 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3640 | } finally { |
| 3641 | Binder.restoreCallingIdentity(identity); |
| 3642 | } |
| 3643 | } |
| 3644 | |
| 3645 | @Override |
| 3646 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3647 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3648 | "setVoWiFiRoamingModeSetting"); |
| 3649 | final long identity = Binder.clearCallingIdentity(); |
| 3650 | try { |
| 3651 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3652 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3653 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3654 | } catch (ImsException e) { |
| 3655 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3656 | } finally { |
| 3657 | Binder.restoreCallingIdentity(identity); |
| 3658 | } |
| 3659 | } |
| 3660 | |
| 3661 | @Override |
| 3662 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3663 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3664 | "setRttCapabilityEnabled"); |
| 3665 | final long identity = Binder.clearCallingIdentity(); |
| 3666 | try { |
| 3667 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3668 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3669 | } catch (ImsException e) { |
| 3670 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3671 | } finally { |
| 3672 | Binder.restoreCallingIdentity(identity); |
| 3673 | } |
| 3674 | } |
| 3675 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3676 | /** |
| 3677 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3678 | * @param subId The subscription to use to check the configuration. |
| 3679 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3680 | @Override |
| 3681 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3682 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3683 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3684 | final long identity = Binder.clearCallingIdentity(); |
| 3685 | try { |
| 3686 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3687 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3688 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3689 | } catch (ImsException e) { |
| 3690 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3691 | } finally { |
| 3692 | Binder.restoreCallingIdentity(identity); |
| 3693 | } |
| 3694 | } |
| 3695 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3696 | @Override |
| 3697 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3698 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3699 | final long identity = Binder.clearCallingIdentity(); |
| 3700 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3701 | if (!isImsAvailableOnDevice()) { |
| 3702 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3703 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3704 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3705 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3706 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3707 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3708 | } catch (ImsException e) { |
| 3709 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3710 | } finally { |
| 3711 | Binder.restoreCallingIdentity(identity); |
| 3712 | } |
| 3713 | } |
| 3714 | |
| 3715 | @Override |
| 3716 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3717 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3718 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3719 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3720 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3721 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3722 | try { |
| 3723 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3724 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3725 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3726 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3727 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3728 | + "is inactive, ignoring unregister."); |
| 3729 | // If the subscription is no longer active, just return, since the callback will already |
| 3730 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3731 | } finally { |
| 3732 | Binder.restoreCallingIdentity(identity); |
| 3733 | } |
| 3734 | } |
| 3735 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3736 | |
| 3737 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3738 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3739 | message); |
| 3740 | } |
| 3741 | |
| 3742 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3743 | boolean isMmtelCapability) { |
| 3744 | Phone phone = getPhone(subId); |
| 3745 | if (phone == null) { |
| 3746 | loge("phone instance null for subid " + subId); |
| 3747 | return false; |
| 3748 | } |
| 3749 | if (isMmtelCapability) { |
| 3750 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3751 | return false; |
| 3752 | } |
| 3753 | } else { |
| 3754 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3755 | return false; |
| 3756 | } |
| 3757 | } |
| 3758 | return true; |
| 3759 | } |
| 3760 | |
| 3761 | @Override |
| 3762 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3763 | boolean isProvisioned) { |
| 3764 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3765 | |
| 3766 | final long identity = Binder.clearCallingIdentity(); |
| 3767 | try { |
| 3768 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3769 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3770 | return; |
| 3771 | } |
| 3772 | |
| 3773 | // this capability requires provisioning, route to the correct API. |
| 3774 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3775 | switch (capability) { |
| 3776 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3777 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3778 | ims.setEabProvisioned(isProvisioned); |
| 3779 | break; |
| 3780 | default: { |
| 3781 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3782 | + "rcs capability '" + capability + "', which does not require " |
| 3783 | + "provisioning."); |
| 3784 | } |
| 3785 | } |
| 3786 | } finally { |
| 3787 | Binder.restoreCallingIdentity(identity); |
| 3788 | } |
| 3789 | |
| 3790 | } |
| 3791 | |
| 3792 | |
| 3793 | @Override |
| 3794 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3795 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3796 | final long identity = Binder.clearCallingIdentity(); |
| 3797 | try { |
| 3798 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3799 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3800 | return true; |
| 3801 | } |
| 3802 | |
| 3803 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3804 | switch (capability) { |
| 3805 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3806 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3807 | return ims.isEabProvisionedOnDevice(); |
| 3808 | |
| 3809 | default: { |
| 3810 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3811 | + "capability '" + capability + "', which does not require " |
| 3812 | + "provisioning."); |
| 3813 | } |
| 3814 | } |
| 3815 | |
| 3816 | } finally { |
| 3817 | Binder.restoreCallingIdentity(identity); |
| 3818 | } |
| 3819 | } |
| 3820 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3821 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3822 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3823 | boolean isProvisioned) { |
| 3824 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3825 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3826 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3827 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3828 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3829 | final long identity = Binder.clearCallingIdentity(); |
| 3830 | try { |
| 3831 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3832 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3833 | return; |
| 3834 | } |
| 3835 | |
| 3836 | // this capability requires provisioning, route to the correct API. |
| 3837 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3838 | switch (capability) { |
| 3839 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3840 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3841 | ims.setVolteProvisioned(isProvisioned); |
| 3842 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3843 | ims.setWfcProvisioned(isProvisioned); |
| 3844 | } |
| 3845 | break; |
| 3846 | } |
| 3847 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3848 | // There is currently no difference in VT provisioning type. |
| 3849 | ims.setVtProvisioned(isProvisioned); |
| 3850 | break; |
| 3851 | } |
| 3852 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3853 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3854 | // change the capability of the feature instead if needed. |
| 3855 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3856 | == isProvisioned) { |
| 3857 | // No change in provisioning. |
| 3858 | return; |
| 3859 | } |
| 3860 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3861 | try { |
| 3862 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3863 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3864 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3865 | + ", Exception" + e.getMessage()); |
| 3866 | } |
| 3867 | break; |
| 3868 | } |
| 3869 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3870 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3871 | + "MmTel capability '" + capability + "', which does not require " |
| 3872 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3873 | } |
| 3874 | } |
| 3875 | |
| 3876 | } finally { |
| 3877 | Binder.restoreCallingIdentity(identity); |
| 3878 | } |
| 3879 | } |
| 3880 | |
| 3881 | @Override |
| 3882 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3883 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3884 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3885 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3886 | } |
| 3887 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3888 | final long identity = Binder.clearCallingIdentity(); |
| 3889 | try { |
| 3890 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3891 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3892 | return true; |
| 3893 | } |
| 3894 | |
| 3895 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3896 | switch (capability) { |
| 3897 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3898 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3899 | return ims.isVolteProvisionedOnDevice(); |
| 3900 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3901 | return ims.isWfcProvisionedOnDevice(); |
| 3902 | } |
| 3903 | // This should never happen, since we are checking tech above to make sure it |
| 3904 | // is either LTE or IWLAN. |
| 3905 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3906 | + "capability."); |
| 3907 | } |
| 3908 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3909 | // There is currently no difference in VT provisioning type. |
| 3910 | return ims.isVtProvisionedOnDevice(); |
| 3911 | } |
| 3912 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3913 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3914 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3915 | } |
| 3916 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3917 | throw new IllegalArgumentException( |
| 3918 | "Tried to get provisioning for MmTel capability '" + capability |
| 3919 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3920 | } |
| 3921 | } |
| 3922 | |
| 3923 | } finally { |
| 3924 | Binder.restoreCallingIdentity(identity); |
| 3925 | } |
| 3926 | } |
| 3927 | |
| 3928 | @Override |
| 3929 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3930 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3931 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3932 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3933 | } |
| 3934 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3935 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3936 | return (provisionedBits & capability) > 0; |
| 3937 | } |
| 3938 | |
| 3939 | @Override |
| 3940 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3941 | boolean isProvisioned) { |
| 3942 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3943 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3944 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3945 | } |
| 3946 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3947 | "setProvisioningStatusForCapability"); |
| 3948 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3949 | // If the current provisioning status for capability already matches isProvisioned, |
| 3950 | // do nothing. |
| 3951 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3952 | return; |
| 3953 | } |
| 3954 | if (isProvisioned) { |
| 3955 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3956 | } else { |
| 3957 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3958 | } |
| 3959 | } |
| 3960 | |
| 3961 | /** |
| 3962 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3963 | * technology. The bitfield should mirror the bitfield defined by |
| 3964 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3965 | */ |
| 3966 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3967 | String key = getMmTelProvisioningKey(subId, tech); |
| 3968 | // Default is no capabilities are provisioned. |
| 3969 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3970 | } |
| 3971 | |
| 3972 | /** |
| 3973 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3974 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3975 | * technology specified. |
| 3976 | * |
| 3977 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3978 | */ |
| 3979 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3980 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3981 | String key = getMmTelProvisioningKey(subId, tech); |
| 3982 | editor.putInt(key, newField); |
| 3983 | editor.commit(); |
| 3984 | } |
| 3985 | |
| 3986 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3987 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3988 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3989 | } |
| 3990 | |
| 3991 | /** |
| 3992 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3993 | * carrier associated with the subscription id. |
| 3994 | */ |
| 3995 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3996 | int capability) { |
| 3997 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3998 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3999 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4000 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4001 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4002 | false); |
| 4003 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4004 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4005 | |
| 4006 | // First check to make sure that the capability requires provisioning. |
| 4007 | switch (capability) { |
| 4008 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4009 | // intentional fallthrough |
| 4010 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4011 | if (requireVoiceVtProvisioning) { |
| 4012 | // Voice and Video requires provisioning |
| 4013 | return true; |
| 4014 | } |
| 4015 | break; |
| 4016 | } |
| 4017 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4018 | if (requireUtProvisioning) { |
| 4019 | // UT requires provisioning |
| 4020 | return true; |
| 4021 | } |
| 4022 | break; |
| 4023 | } |
| 4024 | } |
| 4025 | return false; |
| 4026 | } |
| 4027 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4028 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4029 | int capability) { |
| 4030 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4031 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4032 | |
| 4033 | boolean requireRcsProvisioning = c.getBoolean( |
| 4034 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4035 | |
| 4036 | // First check to make sure that the capability requires provisioning. |
| 4037 | switch (capability) { |
| 4038 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4039 | // intentional fallthrough |
| 4040 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4041 | if (requireRcsProvisioning) { |
| 4042 | // OPTION or PRESENCE requires provisioning |
| 4043 | return true; |
| 4044 | } |
| 4045 | break; |
| 4046 | } |
| 4047 | } |
| 4048 | return false; |
| 4049 | } |
| 4050 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4051 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4052 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4053 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4054 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4055 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4056 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4057 | final long identity = Binder.clearCallingIdentity(); |
| 4058 | try { |
| 4059 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4060 | int slotId = getSlotIndex(subId); |
| 4061 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4062 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4063 | + subId + "' for key:" + key); |
| 4064 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4065 | } |
| 4066 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4067 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4068 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4069 | + subId + "' for key:" + key); |
| 4070 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4071 | } finally { |
| 4072 | Binder.restoreCallingIdentity(identity); |
| 4073 | } |
| 4074 | } |
| 4075 | |
| 4076 | @Override |
| 4077 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4078 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4079 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4080 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4081 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4082 | final long identity = Binder.clearCallingIdentity(); |
| 4083 | try { |
| 4084 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4085 | int slotId = getSlotIndex(subId); |
| 4086 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4087 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4088 | + subId + "' for key:" + key); |
| 4089 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4090 | } |
| 4091 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4092 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4093 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4094 | + subId + "' for key:" + key); |
| 4095 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4096 | } finally { |
| 4097 | Binder.restoreCallingIdentity(identity); |
| 4098 | } |
| 4099 | } |
| 4100 | |
| 4101 | @Override |
| 4102 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4103 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4104 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4105 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4106 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4107 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4108 | final long identity = Binder.clearCallingIdentity(); |
| 4109 | try { |
| 4110 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4111 | int slotId = getSlotIndex(subId); |
| 4112 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4113 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4114 | + subId + "' for key:" + key); |
| 4115 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4116 | } |
| 4117 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4118 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4119 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4120 | + "' for key:" + key); |
| 4121 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4122 | } finally { |
| 4123 | Binder.restoreCallingIdentity(identity); |
| 4124 | } |
| 4125 | } |
| 4126 | |
| 4127 | @Override |
| 4128 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4129 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4130 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4131 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4132 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4133 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4134 | final long identity = Binder.clearCallingIdentity(); |
| 4135 | try { |
| 4136 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4137 | int slotId = getSlotIndex(subId); |
| 4138 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4139 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4140 | + subId + "' for key:" + key); |
| 4141 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4142 | } |
| 4143 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4144 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4145 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4146 | + "' for key:" + key); |
| 4147 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4148 | } finally { |
| 4149 | Binder.restoreCallingIdentity(identity); |
| 4150 | } |
| 4151 | } |
| 4152 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4153 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4154 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4155 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4156 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4157 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4158 | } |
| 4159 | return slotId; |
| 4160 | } |
| 4161 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4162 | private int getSlotIndex(int subId) { |
| 4163 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4164 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4165 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4166 | } |
| 4167 | return slotId; |
| 4168 | } |
| 4169 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4170 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4171 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4172 | */ |
| 4173 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4174 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4175 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4176 | final int targetSdk = getTargetSdk(callingPackage); |
| 4177 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4178 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4179 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4180 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4181 | mApp, subId, callingPackage, callingFeatureId, |
| 4182 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4183 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4184 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4185 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4186 | final long identity = Binder.clearCallingIdentity(); |
| 4187 | try { |
| 4188 | final Phone phone = getPhone(subId); |
| 4189 | if (phone != null) { |
| 4190 | return phone.getServiceState().getDataNetworkType(); |
| 4191 | } else { |
| 4192 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4193 | } |
| 4194 | } finally { |
| 4195 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4196 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4197 | } |
| 4198 | |
| 4199 | /** |
| 4200 | * Returns the data network type |
| 4201 | */ |
| 4202 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4203 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4204 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4205 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4206 | } |
| 4207 | |
| 4208 | /** |
| 4209 | * Returns the data network type for a subId |
| 4210 | */ |
| 4211 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4212 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4213 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4214 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4215 | mApp, subId, callingPackage, callingFeatureId, |
| 4216 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4217 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4218 | } |
| 4219 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4220 | final long identity = Binder.clearCallingIdentity(); |
| 4221 | try { |
| 4222 | final Phone phone = getPhone(subId); |
| 4223 | if (phone != null) { |
| 4224 | return phone.getServiceState().getDataNetworkType(); |
| 4225 | } else { |
| 4226 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4227 | } |
| 4228 | } finally { |
| 4229 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4230 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4231 | } |
| 4232 | |
| 4233 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4234 | * Returns the Voice network type for a subId |
| 4235 | */ |
| 4236 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4237 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4238 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4239 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4240 | mApp, subId, callingPackage, callingFeatureId, |
| 4241 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4242 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4243 | } |
| 4244 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4245 | final long identity = Binder.clearCallingIdentity(); |
| 4246 | try { |
| 4247 | final Phone phone = getPhone(subId); |
| 4248 | if (phone != null) { |
| 4249 | return phone.getServiceState().getVoiceNetworkType(); |
| 4250 | } else { |
| 4251 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4252 | } |
| 4253 | } finally { |
| 4254 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4255 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4256 | } |
| 4257 | |
| 4258 | /** |
| 4259 | * @return true if a ICC card is present |
| 4260 | */ |
| 4261 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4262 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4263 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4264 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4265 | } |
| 4266 | |
| 4267 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4268 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4269 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4270 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4271 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4272 | final long identity = Binder.clearCallingIdentity(); |
| 4273 | try { |
| 4274 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4275 | if (phone != null) { |
| 4276 | return phone.getIccCard().hasIccCard(); |
| 4277 | } else { |
| 4278 | return false; |
| 4279 | } |
| 4280 | } finally { |
| 4281 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4282 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4283 | } |
| 4284 | |
| 4285 | /** |
| 4286 | * Return if the current radio is LTE on CDMA. This |
| 4287 | * is a tri-state return value as for a period of time |
| 4288 | * the mode may be unknown. |
| 4289 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4290 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4291 | * @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] | 4292 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4293 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4294 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4295 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4296 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4297 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4298 | } |
| 4299 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4300 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4301 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4302 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4303 | try { |
| 4304 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4305 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4306 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4307 | } |
| 4308 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4309 | final long identity = Binder.clearCallingIdentity(); |
| 4310 | try { |
| 4311 | final Phone phone = getPhone(subId); |
| 4312 | if (phone == null) { |
| 4313 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4314 | } else { |
| 4315 | return phone.getLteOnCdmaMode(); |
| 4316 | } |
| 4317 | } finally { |
| 4318 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4319 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4320 | } |
| 4321 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4322 | /** |
| 4323 | * {@hide} |
| 4324 | * Returns Default subId, 0 in the case of single standby. |
| 4325 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4326 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4327 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4328 | } |
| 4329 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4330 | private int getSlotForDefaultSubscription() { |
| 4331 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4332 | } |
| 4333 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4334 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4335 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4336 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4337 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4338 | private boolean isActiveSubscription(int subId) { |
| 4339 | return mSubscriptionController.isActiveSubId(subId); |
| 4340 | } |
| 4341 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4342 | /** |
| 4343 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4344 | */ |
| 4345 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4346 | final long identity = Binder.clearCallingIdentity(); |
| 4347 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4348 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4349 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4350 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4351 | } finally { |
| 4352 | Binder.restoreCallingIdentity(identity); |
| 4353 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4354 | } |
| 4355 | |
| 4356 | /** |
| 4357 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4358 | */ |
| 4359 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4360 | final long identity = Binder.clearCallingIdentity(); |
| 4361 | try { |
| 4362 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4363 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4364 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4365 | } finally { |
| 4366 | Binder.restoreCallingIdentity(identity); |
| 4367 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4368 | } |
| 4369 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4370 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4371 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4372 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4373 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4374 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4375 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4376 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4377 | if (phoneId == -1) { |
| 4378 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4379 | + " does not correspond to an active phone"); |
| 4380 | } |
| 4381 | return PhoneFactory.getPhone(phoneId); |
| 4382 | } |
| 4383 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4384 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4385 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4386 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4387 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4388 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4389 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4390 | if (DBG) { |
| 4391 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4392 | } |
| 4393 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4394 | p2); |
| 4395 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4396 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4397 | |
| 4398 | @Override |
| 4399 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4400 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4401 | enforceModifyPermission(); |
| 4402 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4403 | if (DBG) { |
| 4404 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4405 | } |
| 4406 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4407 | callingPackage, aid, p2); |
| 4408 | } |
| 4409 | |
| 4410 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4411 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4412 | final long identity = Binder.clearCallingIdentity(); |
| 4413 | try { |
| 4414 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4415 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4416 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4417 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4418 | if (bestComponent == null |
| 4419 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4420 | loge("The calling package is not allowed to access ISD-R."); |
| 4421 | throw new SecurityException( |
| 4422 | "The calling package is not allowed to access ISD-R."); |
| 4423 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4424 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4425 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4426 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4427 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4428 | null /* workSource */); |
| 4429 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4430 | return response; |
| 4431 | } finally { |
| 4432 | Binder.restoreCallingIdentity(identity); |
| 4433 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4434 | } |
| 4435 | |
| 4436 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4437 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4438 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4439 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4440 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4441 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4442 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4443 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4444 | @Override |
| 4445 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4446 | enforceModifyPermission(); |
| 4447 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4448 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4449 | channel); |
| 4450 | } |
| 4451 | |
| 4452 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4453 | final long identity = Binder.clearCallingIdentity(); |
| 4454 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4455 | if (channel < 0) { |
| 4456 | return false; |
| 4457 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4458 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4459 | null /* workSource */); |
| 4460 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4461 | return success; |
| 4462 | } finally { |
| 4463 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4464 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4465 | } |
| 4466 | |
| 4467 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4468 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4469 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4470 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4471 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4472 | if (DBG) { |
| 4473 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4474 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4475 | + p3 + " data=" + data); |
| 4476 | } |
| 4477 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4478 | command, p1, p2, p3, data); |
| 4479 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4480 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4481 | @Override |
| 4482 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4483 | int command, int p1, int p2, int p3, String data) { |
| 4484 | enforceModifyPermission(); |
| 4485 | if (DBG) { |
| 4486 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4487 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4488 | + p3 + " data=" + data); |
| 4489 | } |
| 4490 | return iccTransmitApduLogicalChannelWithPermission( |
| 4491 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4492 | data); |
| 4493 | } |
| 4494 | |
| 4495 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4496 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4497 | final long identity = Binder.clearCallingIdentity(); |
| 4498 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4499 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4500 | return ""; |
| 4501 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4502 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4503 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4504 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4505 | null /* workSource */); |
| 4506 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4507 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4508 | // Append the returned status code to the end of the response payload. |
| 4509 | String s = Integer.toHexString( |
| 4510 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4511 | if (response.payload != null) { |
| 4512 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4513 | } |
| 4514 | return s; |
| 4515 | } finally { |
| 4516 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4517 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4518 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4519 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4520 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4521 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4522 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4523 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4524 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4525 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4526 | if (DBG) { |
| 4527 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4528 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4529 | } |
| 4530 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4531 | cla, command, p1, p2, p3, data); |
| 4532 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4533 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4534 | @Override |
| 4535 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4536 | int command, int p1, int p2, int p3, String data) { |
| 4537 | enforceModifyPermission(); |
| 4538 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4539 | if (DBG) { |
| 4540 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4541 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4542 | + " data=" + data); |
| 4543 | } |
| 4544 | |
| 4545 | return iccTransmitApduBasicChannelWithPermission( |
| 4546 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4547 | p2, p3, data); |
| 4548 | } |
| 4549 | |
| 4550 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4551 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4552 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4553 | final long identity = Binder.clearCallingIdentity(); |
| 4554 | try { |
| 4555 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4556 | && TextUtils.equals(ISDR_AID, data)) { |
| 4557 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4558 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4559 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4560 | if (bestComponent == null |
| 4561 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4562 | loge("The calling package is not allowed to select ISD-R."); |
| 4563 | throw new SecurityException( |
| 4564 | "The calling package is not allowed to select ISD-R."); |
| 4565 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4566 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4567 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4568 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4569 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4570 | null /* workSource */); |
| 4571 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4572 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4573 | // Append the returned status code to the end of the response payload. |
| 4574 | String s = Integer.toHexString( |
| 4575 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4576 | if (response.payload != null) { |
| 4577 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4578 | } |
| 4579 | return s; |
| 4580 | } finally { |
| 4581 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4582 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4583 | } |
| 4584 | |
| 4585 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4586 | 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] | 4587 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4588 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4589 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4590 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4591 | final long identity = Binder.clearCallingIdentity(); |
| 4592 | try { |
| 4593 | if (DBG) { |
| 4594 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4595 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4596 | } |
| 4597 | |
| 4598 | IccIoResult response = |
| 4599 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4600 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4601 | subId); |
| 4602 | |
| 4603 | if (DBG) { |
| 4604 | log("Exchange SIM_IO [R]" + response); |
| 4605 | } |
| 4606 | |
| 4607 | byte[] result = null; |
| 4608 | int length = 2; |
| 4609 | if (response.payload != null) { |
| 4610 | length = 2 + response.payload.length; |
| 4611 | result = new byte[length]; |
| 4612 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4613 | } else { |
| 4614 | result = new byte[length]; |
| 4615 | } |
| 4616 | |
| 4617 | result[length - 1] = (byte) response.sw2; |
| 4618 | result[length - 2] = (byte) response.sw1; |
| 4619 | return result; |
| 4620 | } finally { |
| 4621 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4622 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4623 | } |
| 4624 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4625 | /** |
| 4626 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4627 | * on a particular subscription |
| 4628 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4629 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4630 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4631 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4632 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4633 | return null; |
| 4634 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4635 | |
| 4636 | final long identity = Binder.clearCallingIdentity(); |
| 4637 | try { |
| 4638 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4639 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4640 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4641 | return null; |
| 4642 | } |
| 4643 | Object response = sendRequest( |
| 4644 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4645 | if (response instanceof String[]) { |
| 4646 | return (String[]) response; |
| 4647 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4648 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4649 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4650 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4651 | } finally { |
| 4652 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4653 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4654 | } |
| 4655 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4656 | /** |
| 4657 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4658 | * subscription. |
| 4659 | * |
| 4660 | * @param subId the id of the subscription. |
| 4661 | * @param appType the uicc app type, must be USIM or SIM. |
| 4662 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4663 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4664 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4665 | * @return number of fplmns that is successfully written to the SIM. |
| 4666 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4667 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4668 | String callingFeatureId) { |
| 4669 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4670 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4671 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4672 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4673 | } |
| 4674 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4675 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4676 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4677 | } |
| 4678 | if (fplmns == null) { |
| 4679 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4680 | } |
| 4681 | for (String fplmn : fplmns) { |
| 4682 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4683 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4684 | } |
| 4685 | } |
| 4686 | final long identity = Binder.clearCallingIdentity(); |
| 4687 | try { |
| 4688 | Object response = sendRequest( |
| 4689 | CMD_SET_FORBIDDEN_PLMNS, |
| 4690 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4691 | subId); |
| 4692 | return (int) response; |
| 4693 | } finally { |
| 4694 | Binder.restoreCallingIdentity(identity); |
| 4695 | } |
| 4696 | } |
| 4697 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4698 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4699 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4700 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4701 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4702 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4703 | final long identity = Binder.clearCallingIdentity(); |
| 4704 | try { |
| 4705 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4706 | if (response.payload == null) { |
| 4707 | return ""; |
| 4708 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4709 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4710 | // Append the returned status code to the end of the response payload. |
| 4711 | String s = Integer.toHexString( |
| 4712 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4713 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4714 | return s; |
| 4715 | } finally { |
| 4716 | Binder.restoreCallingIdentity(identity); |
| 4717 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4718 | } |
| 4719 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4720 | /** |
| 4721 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4722 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4723 | * |
| 4724 | * @param itemID the ID of the item to read |
| 4725 | * @return the NV item as a String, or null on error. |
| 4726 | */ |
| 4727 | @Override |
| 4728 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4729 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4730 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4731 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4732 | |
| 4733 | final long identity = Binder.clearCallingIdentity(); |
| 4734 | try { |
| 4735 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4736 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4737 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4738 | return value; |
| 4739 | } finally { |
| 4740 | Binder.restoreCallingIdentity(identity); |
| 4741 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4742 | } |
| 4743 | |
| 4744 | /** |
| 4745 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4746 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4747 | * |
| 4748 | * @param itemID the ID of the item to read |
| 4749 | * @param itemValue the value to write, as a String |
| 4750 | * @return true on success; false on any failure |
| 4751 | */ |
| 4752 | @Override |
| 4753 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4754 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4755 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4756 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4757 | |
| 4758 | final long identity = Binder.clearCallingIdentity(); |
| 4759 | try { |
| 4760 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4761 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4762 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4763 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4764 | return success; |
| 4765 | } finally { |
| 4766 | Binder.restoreCallingIdentity(identity); |
| 4767 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4768 | } |
| 4769 | |
| 4770 | /** |
| 4771 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4772 | * Used for device configuration by some CDMA operators. |
| 4773 | * |
| 4774 | * @param preferredRoamingList byte array containing the new PRL |
| 4775 | * @return true on success; false on any failure |
| 4776 | */ |
| 4777 | @Override |
| 4778 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4779 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4780 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4781 | |
| 4782 | final long identity = Binder.clearCallingIdentity(); |
| 4783 | try { |
| 4784 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4785 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4786 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4787 | return success; |
| 4788 | } finally { |
| 4789 | Binder.restoreCallingIdentity(identity); |
| 4790 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4791 | } |
| 4792 | |
| 4793 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4794 | * 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] | 4795 | * Used for device configuration by some CDMA operators. |
| 4796 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4797 | * @param slotIndex - device slot. |
| 4798 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4799 | * @return true on success; false on any failure |
| 4800 | */ |
| 4801 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4802 | public boolean resetModemConfig(int slotIndex) { |
| 4803 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4804 | if (phone != null) { |
| 4805 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4806 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4807 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4808 | final long identity = Binder.clearCallingIdentity(); |
| 4809 | try { |
| 4810 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4811 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4812 | return success; |
| 4813 | } finally { |
| 4814 | Binder.restoreCallingIdentity(identity); |
| 4815 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4816 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4817 | return false; |
| 4818 | } |
| 4819 | |
| 4820 | /** |
| 4821 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4822 | * |
| 4823 | * @param slotIndex - device slot. |
| 4824 | * |
| 4825 | * @return true on success; false on any failure |
| 4826 | */ |
| 4827 | @Override |
| 4828 | public boolean rebootModem(int slotIndex) { |
| 4829 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4830 | if (phone != null) { |
| 4831 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4832 | mApp, phone.getSubId(), "rebootModem"); |
| 4833 | |
| 4834 | final long identity = Binder.clearCallingIdentity(); |
| 4835 | try { |
| 4836 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4837 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4838 | return success; |
| 4839 | } finally { |
| 4840 | Binder.restoreCallingIdentity(identity); |
| 4841 | } |
| 4842 | } |
| 4843 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4844 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4845 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4846 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4847 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4848 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4849 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4850 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4851 | return new String[0]; |
| 4852 | } |
| 4853 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4854 | final long identity = Binder.clearCallingIdentity(); |
| 4855 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4856 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4857 | } finally { |
| 4858 | Binder.restoreCallingIdentity(identity); |
| 4859 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4860 | } |
| 4861 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4862 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 4863 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 4864 | * {@link #disableIms(int)}. |
| 4865 | * @param slotIndex device slot. |
| 4866 | */ |
| 4867 | public void resetIms(int slotIndex) { |
| 4868 | enforceModifyPermission(); |
| 4869 | |
| 4870 | final long identity = Binder.clearCallingIdentity(); |
| 4871 | try { |
| 4872 | if (mImsResolver == null) { |
| 4873 | // may happen if the does not support IMS. |
| 4874 | return; |
| 4875 | } |
| 4876 | mImsResolver.disableIms(slotIndex); |
| 4877 | mImsResolver.enableIms(slotIndex); |
| 4878 | } finally { |
| 4879 | Binder.restoreCallingIdentity(identity); |
| 4880 | } |
| 4881 | } |
| 4882 | |
| 4883 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4884 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4885 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4886 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4887 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4888 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4889 | |
| 4890 | final long identity = Binder.clearCallingIdentity(); |
| 4891 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4892 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4893 | // may happen if the device does not support IMS. |
| 4894 | return; |
| 4895 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4896 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4897 | } finally { |
| 4898 | Binder.restoreCallingIdentity(identity); |
| 4899 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4900 | } |
| 4901 | |
| 4902 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4903 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4904 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4905 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4906 | public void disableIms(int slotId) { |
| 4907 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4908 | |
| 4909 | final long identity = Binder.clearCallingIdentity(); |
| 4910 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4911 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4912 | // may happen if the device does not support IMS. |
| 4913 | return; |
| 4914 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4915 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4916 | } finally { |
| 4917 | Binder.restoreCallingIdentity(identity); |
| 4918 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4919 | } |
| 4920 | |
| 4921 | /** |
| 4922 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4923 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4924 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4925 | */ |
| 4926 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4927 | IImsServiceFeatureCallback callback) { |
| 4928 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4929 | |
| 4930 | final long identity = Binder.clearCallingIdentity(); |
| 4931 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4932 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4933 | // may happen if the device does not support IMS. |
| 4934 | return null; |
| 4935 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4936 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4937 | } finally { |
| 4938 | Binder.restoreCallingIdentity(identity); |
| 4939 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4940 | } |
| 4941 | |
| 4942 | /** |
| 4943 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4944 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4945 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4946 | * listener for feature updates. |
| 4947 | */ |
| 4948 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4949 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4950 | |
| 4951 | final long identity = Binder.clearCallingIdentity(); |
| 4952 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4953 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4954 | // may happen if the device does not support IMS. |
| 4955 | return null; |
| 4956 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4957 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4958 | } finally { |
| 4959 | Binder.restoreCallingIdentity(identity); |
| 4960 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4961 | } |
| 4962 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4963 | /** |
| 4964 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4965 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4966 | */ |
| 4967 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4968 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4969 | |
| 4970 | final long identity = Binder.clearCallingIdentity(); |
| 4971 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4972 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4973 | // may happen if the device does not support IMS. |
| 4974 | return null; |
| 4975 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4976 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4977 | } finally { |
| 4978 | Binder.restoreCallingIdentity(identity); |
| 4979 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4980 | } |
| 4981 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4982 | /** |
| 4983 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4984 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4985 | */ |
| 4986 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4987 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4988 | |
| 4989 | final long identity = Binder.clearCallingIdentity(); |
| 4990 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4991 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4992 | // may happen if the device does not support IMS. |
| 4993 | return null; |
| 4994 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4995 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4996 | } finally { |
| 4997 | Binder.restoreCallingIdentity(identity); |
| 4998 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4999 | } |
| 5000 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5001 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5002 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5003 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5004 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5005 | * @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] | 5006 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5007 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5008 | * @param packageName The name of the package that the current configuration will be replaced |
| 5009 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5010 | * @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] | 5011 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5012 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5013 | int[] featureTypes, String packageName) { |
| 5014 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5015 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5016 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5017 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5018 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5019 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5020 | final long identity = Binder.clearCallingIdentity(); |
| 5021 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5022 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5023 | // may happen if the device does not support IMS. |
| 5024 | return false; |
| 5025 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5026 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5027 | for (int featureType : featureTypes) { |
| 5028 | featureConfig.put(featureType, packageName); |
| 5029 | } |
| 5030 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5031 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5032 | } finally { |
| 5033 | Binder.restoreCallingIdentity(identity); |
| 5034 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5035 | } |
| 5036 | |
| 5037 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5038 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5039 | * |
| 5040 | * @param slotId The slot that the ImsService is associated with. |
| 5041 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5042 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5043 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5044 | * @return the package name of the ImsService configuration. |
| 5045 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5046 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5047 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5048 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5049 | TelephonyPermissions |
| 5050 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5051 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5052 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5053 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5054 | final long identity = Binder.clearCallingIdentity(); |
| 5055 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5056 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5057 | // may happen if the device does not support IMS. |
| 5058 | return ""; |
| 5059 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5060 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5061 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5062 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5063 | } finally { |
| 5064 | Binder.restoreCallingIdentity(identity); |
| 5065 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5066 | } |
| 5067 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5068 | /** |
| 5069 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5070 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5071 | * @param callback A callback with an integer containing the |
| 5072 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5073 | */ |
| 5074 | @Override |
| 5075 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5076 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5077 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5078 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5079 | "IMS not available on device."); |
| 5080 | } |
| 5081 | final long token = Binder.clearCallingIdentity(); |
| 5082 | try { |
| 5083 | int slotId = getSlotIndex(subId); |
| 5084 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5085 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5086 | + subId + "'"); |
| 5087 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5088 | } |
| 5089 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5090 | try { |
| 5091 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5092 | } catch (RemoteException e) { |
| 5093 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5094 | + "Ignore"); |
| 5095 | } |
| 5096 | }); |
| 5097 | } finally { |
| 5098 | Binder.restoreCallingIdentity(token); |
| 5099 | } |
| 5100 | } |
| 5101 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5102 | public void setImsRegistrationState(boolean registered) { |
| 5103 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5104 | |
| 5105 | final long identity = Binder.clearCallingIdentity(); |
| 5106 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5107 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5108 | } finally { |
| 5109 | Binder.restoreCallingIdentity(identity); |
| 5110 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5111 | } |
| 5112 | |
| 5113 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5114 | * Set the network selection mode to automatic. |
| 5115 | * |
| 5116 | */ |
| 5117 | @Override |
| 5118 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5119 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5120 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5121 | |
| 5122 | final long identity = Binder.clearCallingIdentity(); |
| 5123 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5124 | if (!isActiveSubscription(subId)) { |
| 5125 | return; |
| 5126 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5127 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5128 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5129 | } finally { |
| 5130 | Binder.restoreCallingIdentity(identity); |
| 5131 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5132 | } |
| 5133 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5134 | /** |
| 5135 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5136 | * |
| 5137 | * @param subId the id of the subscription. |
| 5138 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5139 | * the operator to attach to. |
| 5140 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5141 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5142 | * normal network selection next time. |
| 5143 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5144 | */ |
| 5145 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5146 | public boolean setNetworkSelectionModeManual( |
| 5147 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5148 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5149 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5150 | |
| 5151 | if (!isActiveSubscription(subId)) { |
| 5152 | return false; |
| 5153 | } |
| 5154 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5155 | final long identity = Binder.clearCallingIdentity(); |
| 5156 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5157 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5158 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5159 | if (DBG) { |
| 5160 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5161 | + " operator: " + operatorInfo); |
| 5162 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5163 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5164 | } finally { |
| 5165 | Binder.restoreCallingIdentity(identity); |
| 5166 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5167 | } |
| 5168 | |
| 5169 | /** |
| 5170 | * Scans for available networks. |
| 5171 | */ |
| 5172 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5173 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5174 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5175 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5176 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5177 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5178 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5179 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5180 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5181 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5182 | .setCallingPid(Binder.getCallingPid()) |
| 5183 | .setCallingUid(Binder.getCallingUid()) |
| 5184 | .setMethod("getCellNetworkScanResults") |
| 5185 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5186 | .build()); |
| 5187 | switch (locationResult) { |
| 5188 | case DENIED_HARD: |
| 5189 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5190 | case DENIED_SOFT: |
| 5191 | return null; |
| 5192 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5193 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5194 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5195 | try { |
| 5196 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5197 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5198 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5199 | } finally { |
| 5200 | Binder.restoreCallingIdentity(identity); |
| 5201 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5202 | } |
| 5203 | |
| 5204 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5205 | * Get the call forwarding info, given the call forwarding reason. |
| 5206 | */ |
| 5207 | @Override |
| 5208 | public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) { |
| 5209 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5210 | long identity = Binder.clearCallingIdentity(); |
| 5211 | try { |
| 5212 | if (DBG) { |
| 5213 | log("getCallForwarding: subId " + subId |
| 5214 | + " callForwardingReason" + callForwardingReason); |
| 5215 | } |
| 5216 | return (CallForwardingInfo) sendRequest( |
| 5217 | CMD_GET_CALL_FORWARDING, callForwardingReason, subId); |
| 5218 | } finally { |
| 5219 | Binder.restoreCallingIdentity(identity); |
| 5220 | } |
| 5221 | } |
| 5222 | |
| 5223 | /** |
| 5224 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5225 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5226 | */ |
| 5227 | @Override |
| 5228 | public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) { |
| 5229 | enforceModifyPermission(); |
| 5230 | long identity = Binder.clearCallingIdentity(); |
| 5231 | try { |
| 5232 | if (DBG) { |
| 5233 | log("setCallForwarding: subId " + subId |
| 5234 | + " callForwardingInfo" + callForwardingInfo); |
| 5235 | } |
| 5236 | return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId); |
| 5237 | } finally { |
| 5238 | Binder.restoreCallingIdentity(identity); |
| 5239 | } |
| 5240 | } |
| 5241 | |
| 5242 | /** |
| 5243 | * Get the call forwarding info, given the call forwarding reason. |
| 5244 | */ |
| 5245 | @Override |
| 5246 | public int getCallWaitingStatus(int subId) { |
| 5247 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5248 | long identity = Binder.clearCallingIdentity(); |
| 5249 | try { |
| 5250 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 5251 | return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId); |
| 5252 | } finally { |
| 5253 | Binder.restoreCallingIdentity(identity); |
| 5254 | } |
| 5255 | } |
| 5256 | |
| 5257 | /** |
| 5258 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5259 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5260 | */ |
| 5261 | @Override |
| 5262 | public boolean setCallWaitingStatus(int subId, boolean isEnable) { |
| 5263 | enforceModifyPermission(); |
| 5264 | long identity = Binder.clearCallingIdentity(); |
| 5265 | try { |
| 5266 | if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable); |
| 5267 | return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId); |
| 5268 | } finally { |
| 5269 | Binder.restoreCallingIdentity(identity); |
| 5270 | } |
| 5271 | } |
| 5272 | |
| 5273 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5274 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5275 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5276 | * @param subId id of the subscription |
| 5277 | * @param request contains the radio access networks with bands/channels to scan |
| 5278 | * @param messenger callback messenger for scan results or errors |
| 5279 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5280 | * @return the id of the requested scan which can be used to stop the scan. |
| 5281 | */ |
| 5282 | @Override |
| 5283 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5284 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5285 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5286 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5287 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5288 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5289 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5290 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5291 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5292 | .setCallingPid(Binder.getCallingPid()) |
| 5293 | .setCallingUid(Binder.getCallingUid()) |
| 5294 | .setMethod("requestNetworkScan") |
| 5295 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5296 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5297 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5298 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5299 | if (e != null) { |
| 5300 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5301 | throw e; |
| 5302 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5303 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5304 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5305 | } |
| 5306 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5307 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5308 | int callingUid = Binder.getCallingUid(); |
| 5309 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5310 | final long identity = Binder.clearCallingIdentity(); |
| 5311 | try { |
| 5312 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5313 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5314 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5315 | } finally { |
| 5316 | Binder.restoreCallingIdentity(identity); |
| 5317 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5318 | } |
| 5319 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5320 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5321 | NetworkScanRequest request, int subId) { |
| 5322 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5323 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5324 | boolean hasNetworkScanPermission = |
| 5325 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5326 | == PERMISSION_GRANTED; |
| 5327 | |
| 5328 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5329 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5330 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5331 | } |
| 5332 | |
| 5333 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5334 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5335 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5336 | return new SecurityException("Specific channels must not be" |
| 5337 | + " scanned without location access."); |
| 5338 | } |
| 5339 | } |
| 5340 | } |
| 5341 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5342 | return null; |
| 5343 | } |
| 5344 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5345 | /** |
| 5346 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5347 | * |
| 5348 | * @param subId id of the subscription |
| 5349 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5350 | */ |
| 5351 | @Override |
| 5352 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5353 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5354 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5355 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5356 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5357 | final long identity = Binder.clearCallingIdentity(); |
| 5358 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5359 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5360 | } finally { |
| 5361 | Binder.restoreCallingIdentity(identity); |
| 5362 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5363 | } |
| 5364 | |
| 5365 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5366 | * Get the calculated preferred network type. |
| 5367 | * Used for debugging incorrect network type. |
| 5368 | * |
| 5369 | * @return the preferred network type, defined in RILConstants.java. |
| 5370 | */ |
| 5371 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5372 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5373 | final Phone defaultPhone = getDefaultPhone(); |
| 5374 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5375 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5376 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5377 | } |
| 5378 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5379 | final long identity = Binder.clearCallingIdentity(); |
| 5380 | try { |
| 5381 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5382 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5383 | } finally { |
| 5384 | Binder.restoreCallingIdentity(identity); |
| 5385 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5386 | } |
| 5387 | |
| 5388 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5389 | * Get the preferred network type. |
| 5390 | * Used for device configuration by some CDMA operators. |
| 5391 | * |
| 5392 | * @return the preferred network type, defined in RILConstants.java. |
| 5393 | */ |
| 5394 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5395 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5396 | TelephonyPermissions |
| 5397 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5398 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5399 | |
| 5400 | final long identity = Binder.clearCallingIdentity(); |
| 5401 | try { |
| 5402 | if (DBG) log("getPreferredNetworkType"); |
| 5403 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5404 | int networkType = (result != null ? result[0] : -1); |
| 5405 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5406 | return networkType; |
| 5407 | } finally { |
| 5408 | Binder.restoreCallingIdentity(identity); |
| 5409 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5410 | } |
| 5411 | |
| 5412 | /** |
| 5413 | * Set the preferred network type. |
| 5414 | * Used for device configuration by some CDMA operators. |
| 5415 | * |
| 5416 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5417 | * @return true on success; false on any failure. |
| 5418 | */ |
| 5419 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5420 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5421 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5422 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5423 | |
| 5424 | final long identity = Binder.clearCallingIdentity(); |
| 5425 | try { |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5426 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5427 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5428 | return setPreferredNetworkTypesInternal(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5429 | } finally { |
| 5430 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5431 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5432 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5433 | |
| 5434 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5435 | * Get the allowed network types that store in the telephony provider. |
| 5436 | * |
| 5437 | * @param subId the id of the subscription. |
| 5438 | * @return allowedNetworkTypes the allowed network types. |
| 5439 | */ |
| 5440 | @Override |
| 5441 | public long getAllowedNetworkTypes(int subId) { |
| 5442 | TelephonyPermissions |
| 5443 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5444 | mApp, subId, "getAllowedNetworkTypes"); |
| 5445 | |
| 5446 | final long identity = Binder.clearCallingIdentity(); |
| 5447 | try { |
| 5448 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5449 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5450 | } finally { |
| 5451 | Binder.restoreCallingIdentity(identity); |
| 5452 | } |
| 5453 | } |
| 5454 | |
| 5455 | /** |
| 5456 | * Set the allowed network types. |
| 5457 | * |
| 5458 | * @param subId the id of the subscription. |
| 5459 | * @param allowedNetworkTypes the allowed network types. |
| 5460 | * @return true on success; false on any failure. |
| 5461 | */ |
| 5462 | @Override |
| 5463 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5464 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5465 | mApp, subId, "setAllowedNetworkTypes"); |
| 5466 | final long identity = Binder.clearCallingIdentity(); |
| 5467 | try { |
| 5468 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5469 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5470 | String.valueOf(allowedNetworkTypes)); |
| 5471 | return setPreferredNetworkTypesInternal(subId); |
| 5472 | } finally { |
| 5473 | Binder.restoreCallingIdentity(identity); |
| 5474 | } |
| 5475 | } |
| 5476 | |
| 5477 | private boolean setPreferredNetworkTypesInternal(int subId) { |
| 5478 | long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType( |
| 5479 | Settings.Global.getInt(mApp.getContentResolver(), |
| 5480 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5481 | RILConstants.PREFERRED_NETWORK_MODE)); |
| 5482 | long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty( |
| 5483 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5484 | int networkMode = RadioAccessFamily.getNetworkTypeFromRaf( |
| 5485 | (int) (networkTypeBitMask & allowedNetworkTypes)); |
| 5486 | |
| 5487 | if (DBG) { |
| 5488 | log("setPreferredNetworkTypesInternal: subId " + subId |
| 5489 | + " networkTypes " + networkTypeBitMask |
| 5490 | + " allowedNetworkTypes " + allowedNetworkTypes |
| 5491 | + " networkMode " + networkMode); |
| 5492 | } |
| 5493 | |
| 5494 | Boolean success = (Boolean) sendRequest( |
| 5495 | CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId); |
| 5496 | if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail")); |
| 5497 | return success; |
| 5498 | } |
| 5499 | |
| 5500 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5501 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5502 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5503 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5504 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5505 | * @hide |
| 5506 | */ |
| 5507 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5508 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5509 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5510 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5511 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5512 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5513 | if (phone != null) { |
| 5514 | return phone.hasMatchedTetherApnSetting(); |
| 5515 | } else { |
| 5516 | return false; |
| 5517 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5518 | } finally { |
| 5519 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5520 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5521 | } |
| 5522 | |
| 5523 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5524 | * Set mobile data enabled |
| 5525 | * Used by the user through settings etc to turn on/off mobile data |
| 5526 | * |
| 5527 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5528 | */ |
| 5529 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5530 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5531 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5532 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5533 | |
| 5534 | final long identity = Binder.clearCallingIdentity(); |
| 5535 | try { |
| 5536 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5537 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5538 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5539 | if (phone != null) { |
| 5540 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5541 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5542 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5543 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5544 | } |
| 5545 | } finally { |
| 5546 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5547 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5548 | } |
| 5549 | |
| 5550 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5551 | * Enable or disable always reporting signal strength changes from radio. |
| 5552 | * |
| 5553 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5554 | */ |
| 5555 | @Override |
| 5556 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5557 | enforceModifyPermission(); |
| 5558 | enforceSystemCaller(); |
| 5559 | |
| 5560 | final long identity = Binder.clearCallingIdentity(); |
| 5561 | final Phone phone = getPhone(subId); |
| 5562 | try { |
| 5563 | if (phone != null) { |
| 5564 | if (DBG) { |
| 5565 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5566 | + " isEnable=" + isEnable); |
| 5567 | } |
| 5568 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5569 | } else { |
| 5570 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5571 | + subId); |
| 5572 | } |
| 5573 | } finally { |
| 5574 | Binder.restoreCallingIdentity(identity); |
| 5575 | } |
| 5576 | } |
| 5577 | |
| 5578 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5579 | * Get the user enabled state of Mobile Data. |
| 5580 | * |
| 5581 | * TODO: remove and use isUserDataEnabled. |
| 5582 | * This can't be removed now because some vendor codes |
| 5583 | * calls through ITelephony directly while they should |
| 5584 | * use TelephonyManager. |
| 5585 | * |
| 5586 | * @return true on enabled |
| 5587 | */ |
| 5588 | @Override |
| 5589 | public boolean getDataEnabled(int subId) { |
| 5590 | return isUserDataEnabled(subId); |
| 5591 | } |
| 5592 | |
| 5593 | /** |
| 5594 | * Get whether mobile data is enabled per user setting. |
| 5595 | * |
| 5596 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5597 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5598 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5599 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5600 | * |
| 5601 | * @return {@code true} if data is enabled else {@code false} |
| 5602 | */ |
| 5603 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5604 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5605 | try { |
| 5606 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5607 | null); |
| 5608 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5609 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5610 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5611 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5612 | |
| 5613 | final long identity = Binder.clearCallingIdentity(); |
| 5614 | try { |
| 5615 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5616 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5617 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5618 | if (phone != null) { |
| 5619 | boolean retVal = phone.isUserDataEnabled(); |
| 5620 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5621 | return retVal; |
| 5622 | } else { |
| 5623 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5624 | return false; |
| 5625 | } |
| 5626 | } finally { |
| 5627 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5628 | } |
| 5629 | } |
| 5630 | |
| 5631 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5632 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5633 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5634 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5635 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5636 | * @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] | 5637 | */ |
| 5638 | @Override |
| 5639 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5640 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5641 | |
| 5642 | final long identity = Binder.clearCallingIdentity(); |
| 5643 | try { |
| 5644 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5645 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5646 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5647 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5648 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5649 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5650 | return retVal; |
| 5651 | } else { |
| 5652 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5653 | return false; |
| 5654 | } |
| 5655 | } finally { |
| 5656 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5657 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5658 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5659 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5660 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 5661 | Phone phone) { |
| 5662 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5663 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5664 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5665 | || subController == null) return privilegeFromSim; |
| 5666 | |
| 5667 | int uid = Binder.getCallingUid(); |
| 5668 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5669 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5670 | |
| 5671 | final long identity = Binder.clearCallingIdentity(); |
| 5672 | try { |
| 5673 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5674 | SubscriptionManager subManager = (SubscriptionManager) |
| 5675 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5676 | for (String pkg : packages) { |
| 5677 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5678 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5679 | } |
| 5680 | } |
| 5681 | return privilegeFromSim; |
| 5682 | } finally { |
| 5683 | Binder.restoreCallingIdentity(identity); |
| 5684 | } |
| 5685 | } |
| 5686 | |
| 5687 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5688 | String pkgName) { |
| 5689 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5690 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5691 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5692 | || subController == null) return privilegeFromSim; |
| 5693 | |
| 5694 | final long identity = Binder.clearCallingIdentity(); |
| 5695 | try { |
| 5696 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5697 | SubscriptionManager subManager = (SubscriptionManager) |
| 5698 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5699 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5700 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5701 | } finally { |
| 5702 | Binder.restoreCallingIdentity(identity); |
| 5703 | } |
| 5704 | } |
| 5705 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5706 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5707 | public int getCarrierPrivilegeStatus(int subId) { |
| 5708 | final Phone phone = getPhone(subId); |
| 5709 | if (phone == null) { |
| 5710 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5711 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5712 | } |
| 5713 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5714 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5715 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5716 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5717 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5718 | |
| 5719 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5720 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 5721 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5722 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5723 | |
| 5724 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5725 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5726 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5727 | final Phone phone = getPhone(subId); |
| 5728 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5729 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5730 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5731 | } |
| 5732 | UiccProfile profile = |
| 5733 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5734 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5735 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5736 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5737 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5738 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5739 | profile.getCarrierPrivilegeStatusForUid( |
| 5740 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5741 | } |
| 5742 | |
| 5743 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5744 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5745 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5746 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5747 | } |
| 5748 | |
| 5749 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5750 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5751 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5752 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5753 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5754 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5755 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5756 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5757 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5758 | } |
| 5759 | |
| 5760 | @Override |
| 5761 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5762 | if (TextUtils.isEmpty(pkgName)) |
| 5763 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5764 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5765 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5766 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5767 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5768 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5769 | continue; |
| 5770 | } |
| 5771 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5772 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5773 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5774 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5775 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5776 | break; |
| 5777 | } |
| 5778 | } |
| 5779 | |
| 5780 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5781 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5782 | |
| 5783 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5784 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5785 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5786 | loge("phoneId " + phoneId + " is not valid."); |
| 5787 | return null; |
| 5788 | } |
| 5789 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5790 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5791 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5792 | return null ; |
| 5793 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5794 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5795 | } |
| 5796 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5797 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5798 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5799 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5800 | List<String> privilegedPackages = new ArrayList<>(); |
| 5801 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5802 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5803 | // has UICC in that slot. |
| 5804 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5805 | if (card.hasCarrierPrivilegeRules()) { |
| 5806 | if (packages == null) { |
| 5807 | // Only check packages in user 0 for now |
| 5808 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5809 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5810 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5811 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5812 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5813 | } |
| 5814 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5815 | PackageInfo pkgInfo = packages.get(p); |
| 5816 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5817 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5818 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5819 | privilegedPackages.add(pkgInfo.packageName); |
| 5820 | } |
| 5821 | } |
| 5822 | } |
| 5823 | } |
| 5824 | return privilegedPackages; |
| 5825 | } |
| 5826 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5827 | @Override |
| 5828 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5829 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5830 | |
| 5831 | final long identity = Binder.clearCallingIdentity(); |
| 5832 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5833 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5834 | try { |
| 5835 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5836 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5837 | } |
| 5838 | } finally { |
| 5839 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5840 | } |
| 5841 | return privilegedPackages; |
| 5842 | } |
| 5843 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5844 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5845 | final Phone phone = getPhone(subId); |
| 5846 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5847 | if (card == null) { |
| 5848 | loge("getIccId: No UICC"); |
| 5849 | return null; |
| 5850 | } |
| 5851 | String iccId = card.getIccId(); |
| 5852 | if (TextUtils.isEmpty(iccId)) { |
| 5853 | loge("getIccId: ICC ID is null or empty."); |
| 5854 | return null; |
| 5855 | } |
| 5856 | return iccId; |
| 5857 | } |
| 5858 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5859 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5860 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5861 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5862 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5863 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5864 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5865 | final long identity = Binder.clearCallingIdentity(); |
| 5866 | try { |
| 5867 | final String iccId = getIccId(subId); |
| 5868 | final Phone phone = getPhone(subId); |
| 5869 | if (phone == null) { |
| 5870 | return false; |
| 5871 | } |
| 5872 | final String subscriberId = phone.getSubscriberId(); |
| 5873 | |
| 5874 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5875 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5876 | + subscriberId + " to " + number); |
| 5877 | } |
| 5878 | |
| 5879 | if (TextUtils.isEmpty(iccId)) { |
| 5880 | return false; |
| 5881 | } |
| 5882 | |
| 5883 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5884 | |
| 5885 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5886 | if (alphaTag == null) { |
| 5887 | editor.remove(alphaTagPrefKey); |
| 5888 | } else { |
| 5889 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5890 | } |
| 5891 | |
| 5892 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5893 | // track all merged IMSIs based on line number |
| 5894 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5895 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5896 | if (number == null) { |
| 5897 | editor.remove(numberPrefKey); |
| 5898 | editor.remove(subscriberPrefKey); |
| 5899 | } else { |
| 5900 | editor.putString(numberPrefKey, number); |
| 5901 | editor.putString(subscriberPrefKey, subscriberId); |
| 5902 | } |
| 5903 | |
| 5904 | editor.commit(); |
| 5905 | return true; |
| 5906 | } finally { |
| 5907 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5908 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5909 | } |
| 5910 | |
| 5911 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5912 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 5913 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5914 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5915 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5916 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5917 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5918 | return null; |
| 5919 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5920 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5921 | final long identity = Binder.clearCallingIdentity(); |
| 5922 | try { |
| 5923 | String iccId = getIccId(subId); |
| 5924 | if (iccId != null) { |
| 5925 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5926 | if (DBG_MERGE) { |
| 5927 | log("getLine1NumberForDisplay returning " |
| 5928 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5929 | } |
| 5930 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5931 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5932 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5933 | return null; |
| 5934 | } finally { |
| 5935 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5936 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5937 | } |
| 5938 | |
| 5939 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5940 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 5941 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5942 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5943 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5944 | return null; |
| 5945 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5946 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5947 | final long identity = Binder.clearCallingIdentity(); |
| 5948 | try { |
| 5949 | String iccId = getIccId(subId); |
| 5950 | if (iccId != null) { |
| 5951 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5952 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5953 | } |
| 5954 | return null; |
| 5955 | } finally { |
| 5956 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5957 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5958 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5959 | |
| 5960 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5961 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 5962 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5963 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5964 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5965 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5966 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5967 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5968 | return null; |
| 5969 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5970 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5971 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5972 | // the process, where TelephonyManager was instantiated. |
| 5973 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5974 | final long identity = Binder.clearCallingIdentity(); |
| 5975 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5976 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5977 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5978 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5979 | |
| 5980 | // Figure out what subscribers are currently active |
| 5981 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5982 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5983 | // Only consider subs which match the current subId |
| 5984 | // This logic can be simplified. See b/131189269 for progress. |
| 5985 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5986 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5987 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5988 | |
| 5989 | // First pass, find a number override for an active subscriber |
| 5990 | String mergeNumber = null; |
| 5991 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5992 | for (String key : prefs.keySet()) { |
| 5993 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5994 | final String subscriberId = (String) prefs.get(key); |
| 5995 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5996 | final String iccId = key.substring( |
| 5997 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5998 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5999 | mergeNumber = (String) prefs.get(numberKey); |
| 6000 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6001 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6002 | + " for active subscriber " + subscriberId); |
| 6003 | } |
| 6004 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6005 | break; |
| 6006 | } |
| 6007 | } |
| 6008 | } |
| 6009 | } |
| 6010 | |
| 6011 | // Shortcut when no active merged subscribers |
| 6012 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6013 | return null; |
| 6014 | } |
| 6015 | |
| 6016 | // Second pass, find all subscribers under that line override |
| 6017 | final ArraySet<String> result = new ArraySet<>(); |
| 6018 | for (String key : prefs.keySet()) { |
| 6019 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6020 | final String number = (String) prefs.get(key); |
| 6021 | if (mergeNumber.equals(number)) { |
| 6022 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6023 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6024 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6025 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6026 | result.add(subscriberId); |
| 6027 | } |
| 6028 | } |
| 6029 | } |
| 6030 | } |
| 6031 | |
| 6032 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6033 | Arrays.sort(resultArray); |
| 6034 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6035 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6036 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6037 | } |
| 6038 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6039 | } finally { |
| 6040 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6041 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6042 | } |
| 6043 | |
| 6044 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6045 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 6046 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 6047 | |
| 6048 | final long identity = Binder.clearCallingIdentity(); |
| 6049 | try { |
| 6050 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6051 | TelephonyManager.class); |
| 6052 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6053 | if (subscriberId == null) { |
| 6054 | if (DBG) { |
| 6055 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 6056 | + subId); |
| 6057 | } |
| 6058 | return null; |
| 6059 | } |
| 6060 | |
| 6061 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6062 | .getSubscriptionInfo(subId); |
| 6063 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6064 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6065 | if (groupUuid == null) { |
| 6066 | return new String[]{subscriberId}; |
| 6067 | } |
| 6068 | |
| 6069 | // Get all subscriberIds from the group. |
| 6070 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6071 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6072 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 6073 | null); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6074 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6075 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6076 | if (subscriberId != null) { |
| 6077 | mergedSubscriberIds.add(subscriberId); |
| 6078 | } |
| 6079 | } |
| 6080 | |
| 6081 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6082 | } finally { |
| 6083 | Binder.restoreCallingIdentity(identity); |
| 6084 | |
| 6085 | } |
| 6086 | } |
| 6087 | |
| 6088 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6089 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6090 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6091 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6092 | |
| 6093 | final long identity = Binder.clearCallingIdentity(); |
| 6094 | try { |
| 6095 | final Phone phone = getPhone(subId); |
| 6096 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6097 | } finally { |
| 6098 | Binder.restoreCallingIdentity(identity); |
| 6099 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6100 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6101 | |
| 6102 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6103 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6104 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6105 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6106 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6107 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6108 | |
| 6109 | final long identity = Binder.clearCallingIdentity(); |
| 6110 | try { |
| 6111 | final Phone phone = getPhone(subId); |
| 6112 | if (phone == null) { |
| 6113 | return false; |
| 6114 | } |
| 6115 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6116 | cdmaNonRoamingList); |
| 6117 | } finally { |
| 6118 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6119 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6120 | } |
| 6121 | |
| 6122 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6123 | @Deprecated |
| 6124 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6125 | enforceModifyPermission(); |
| 6126 | |
| 6127 | int returnValue = 0; |
| 6128 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6129 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6130 | if(result.exception == null) { |
| 6131 | if (result.result != null) { |
| 6132 | byte[] responseData = (byte[])(result.result); |
| 6133 | if(responseData.length > oemResp.length) { |
| 6134 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6135 | responseData.length + "bytes. Buffer Size is " + |
| 6136 | oemResp.length + "bytes."); |
| 6137 | } |
| 6138 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6139 | returnValue = responseData.length; |
| 6140 | } |
| 6141 | } else { |
| 6142 | CommandException ex = (CommandException) result.exception; |
| 6143 | returnValue = ex.getCommandError().ordinal(); |
| 6144 | if(returnValue > 0) returnValue *= -1; |
| 6145 | } |
| 6146 | } catch (RuntimeException e) { |
| 6147 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6148 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6149 | if(returnValue > 0) returnValue *= -1; |
| 6150 | } |
| 6151 | |
| 6152 | return returnValue; |
| 6153 | } |
| 6154 | |
| 6155 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6156 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6157 | try { |
| 6158 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6159 | } catch (RuntimeException e) { |
| 6160 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6161 | } |
| 6162 | } |
| 6163 | |
| 6164 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6165 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6166 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6167 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6168 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6169 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6170 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6171 | final long identity = Binder.clearCallingIdentity(); |
| 6172 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6173 | TelephonyPermissions |
| 6174 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6175 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6176 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6177 | } finally { |
| 6178 | Binder.restoreCallingIdentity(identity); |
| 6179 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6180 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6181 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6182 | |
| 6183 | @Override |
| 6184 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6185 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6186 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6187 | |
| 6188 | final long identity = Binder.clearCallingIdentity(); |
| 6189 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6190 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6191 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6192 | } finally { |
| 6193 | Binder.restoreCallingIdentity(identity); |
| 6194 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6195 | } |
| 6196 | |
| 6197 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6198 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6199 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6200 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6201 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6202 | return false; |
| 6203 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6204 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6205 | final long identity = Binder.clearCallingIdentity(); |
| 6206 | try { |
| 6207 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6208 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6209 | // In the long run, we may instead need to check if there exists a connection service |
| 6210 | // which can support video calling. |
| 6211 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6212 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6213 | return imsManager.isVtEnabledByPlatform() |
| 6214 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6215 | && imsManager.isVtEnabledByUser(); |
| 6216 | } finally { |
| 6217 | Binder.restoreCallingIdentity(identity); |
| 6218 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6219 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6220 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6221 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6222 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6223 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6224 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6225 | mApp, subId, callingPackage, callingFeatureId, |
| 6226 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6227 | return false; |
| 6228 | } |
| 6229 | |
| 6230 | final long identity = Binder.clearCallingIdentity(); |
| 6231 | try { |
| 6232 | CarrierConfigManager configManager = |
| 6233 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6234 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6235 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6236 | } finally { |
| 6237 | Binder.restoreCallingIdentity(identity); |
| 6238 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6239 | } |
| 6240 | |
| 6241 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6242 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6243 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6244 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6245 | return false; |
| 6246 | } |
| 6247 | |
| 6248 | final long identity = Binder.clearCallingIdentity(); |
| 6249 | try { |
| 6250 | CarrierConfigManager configManager = |
| 6251 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6252 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6253 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6254 | } finally { |
| 6255 | Binder.restoreCallingIdentity(identity); |
| 6256 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6257 | } |
| 6258 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6259 | @Override |
| 6260 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6261 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6262 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6263 | } |
| 6264 | |
| 6265 | @Override |
| 6266 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6267 | final long identity = Binder.clearCallingIdentity(); |
| 6268 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6269 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6270 | } finally { |
| 6271 | Binder.restoreCallingIdentity(identity); |
| 6272 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6273 | } |
| 6274 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6275 | /** |
| 6276 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6277 | * support for the feature and device firmware support. |
| 6278 | * |
| 6279 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6280 | */ |
| 6281 | @Override |
| 6282 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6283 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6284 | final Phone phone = getPhone(subscriptionId); |
| 6285 | if (phone == null) { |
| 6286 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6287 | return false; |
| 6288 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6289 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6290 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6291 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6292 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6293 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6294 | return isCarrierSupported && isDeviceSupported; |
| 6295 | } finally { |
| 6296 | Binder.restoreCallingIdentity(identity); |
| 6297 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6298 | } |
| 6299 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6300 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6301 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6302 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6303 | * 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] | 6304 | */ |
| 6305 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6306 | final long identity = Binder.clearCallingIdentity(); |
| 6307 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6308 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6309 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6310 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6311 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6312 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6313 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6314 | } finally { |
| 6315 | Binder.restoreCallingIdentity(identity); |
| 6316 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6317 | } |
| 6318 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6319 | @Deprecated |
| 6320 | @Override |
| 6321 | public String getDeviceId(String callingPackage) { |
| 6322 | return getDeviceIdWithFeature(callingPackage, null); |
| 6323 | } |
| 6324 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6325 | /** |
| 6326 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6327 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6328 | * |
| 6329 | * <p>Requires Permission: |
| 6330 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6331 | */ |
| 6332 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6333 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6334 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6335 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6336 | return null; |
| 6337 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6338 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6339 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6340 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6341 | return null; |
| 6342 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6343 | |
| 6344 | final long identity = Binder.clearCallingIdentity(); |
| 6345 | try { |
| 6346 | return phone.getDeviceId(); |
| 6347 | } finally { |
| 6348 | Binder.restoreCallingIdentity(identity); |
| 6349 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6350 | } |
| 6351 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6352 | /** |
| 6353 | * {@hide} |
| 6354 | * Returns the IMS Registration Status on a particular subid |
| 6355 | * |
| 6356 | * @param subId |
| 6357 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6358 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6359 | Phone phone = getPhone(subId); |
| 6360 | if (phone != null) { |
| 6361 | return phone.isImsRegistered(); |
| 6362 | } else { |
| 6363 | return false; |
| 6364 | } |
| 6365 | } |
| 6366 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6367 | @Override |
| 6368 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6369 | final long identity = Binder.clearCallingIdentity(); |
| 6370 | try { |
| 6371 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6372 | } finally { |
| 6373 | Binder.restoreCallingIdentity(identity); |
| 6374 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6375 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6376 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6377 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6378 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6379 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6380 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6381 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6382 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6383 | } |
| 6384 | final long identity = Binder.clearCallingIdentity(); |
| 6385 | try { |
| 6386 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6387 | } finally { |
| 6388 | Binder.restoreCallingIdentity(identity); |
| 6389 | } |
| 6390 | } |
| 6391 | |
| 6392 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6393 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6394 | final long identity = Binder.clearCallingIdentity(); |
| 6395 | try { |
| 6396 | Phone phone = getPhone(subscriptionId); |
| 6397 | if (phone == null) { |
| 6398 | return null; |
| 6399 | } |
| 6400 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6401 | } finally { |
| 6402 | Binder.restoreCallingIdentity(identity); |
| 6403 | } |
| 6404 | } |
| 6405 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6406 | /** |
| 6407 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6408 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6409 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6410 | final long identity = Binder.clearCallingIdentity(); |
| 6411 | try { |
| 6412 | Phone phone = getPhone(subId); |
| 6413 | if (phone != null) { |
| 6414 | return phone.isWifiCallingEnabled(); |
| 6415 | } else { |
| 6416 | return false; |
| 6417 | } |
| 6418 | } finally { |
| 6419 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6420 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6421 | } |
| 6422 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6423 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6424 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6425 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6426 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6427 | final long identity = Binder.clearCallingIdentity(); |
| 6428 | try { |
| 6429 | Phone phone = getPhone(subId); |
| 6430 | if (phone != null) { |
| 6431 | return phone.isVideoEnabled(); |
| 6432 | } else { |
| 6433 | return false; |
| 6434 | } |
| 6435 | } finally { |
| 6436 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6437 | } |
| 6438 | } |
| 6439 | |
| 6440 | /** |
| 6441 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6442 | * defined in {@link ImsRegistrationImplBase}. |
| 6443 | */ |
| 6444 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6445 | final long identity = Binder.clearCallingIdentity(); |
| 6446 | try { |
| 6447 | Phone phone = getPhone(subId); |
| 6448 | if (phone != null) { |
| 6449 | return phone.getImsRegistrationTech(); |
| 6450 | } else { |
| 6451 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6452 | } |
| 6453 | } finally { |
| 6454 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6455 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6456 | } |
| 6457 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6458 | @Override |
| 6459 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6460 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6461 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6462 | return; |
| 6463 | } |
| 6464 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6465 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6466 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6467 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6468 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6469 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6470 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6471 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6472 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6473 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6474 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6475 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6476 | // There has been issues when Sms raw table somehow stores orphan |
| 6477 | // fragments. They lead to garbled message when new fragments come |
| 6478 | // in and combined with those stale ones. In case this happens again, |
| 6479 | // user can reset all network settings which will clean up this table. |
| 6480 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6481 | // Clean up IMS settings as well here. |
| 6482 | int slotId = getSlotIndex(subId); |
| 6483 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6484 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6485 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6486 | |
| 6487 | // Erase modem config if erase modem on network setting is enabled. |
| 6488 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6489 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6490 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6491 | sendEraseModemConfig(getDefaultPhone()); |
| 6492 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6493 | } finally { |
| 6494 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6495 | } |
| 6496 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6497 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6498 | private void cleanUpSmsRawTable(Context context) { |
| 6499 | ContentResolver resolver = context.getContentResolver(); |
| 6500 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6501 | resolver.delete(uri, null, null); |
| 6502 | } |
| 6503 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6504 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6505 | public String getSimLocaleForSubscriber(int subId) { |
| 6506 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6507 | final Phone phone = getPhone(subId); |
| 6508 | if (phone == null) { |
| 6509 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6510 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6511 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6512 | final long identity = Binder.clearCallingIdentity(); |
| 6513 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6514 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6515 | phone.getContext().getOpPackageName(), null); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6516 | if (info == null) { |
| 6517 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6518 | return null; |
| 6519 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6520 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6521 | // preferences (EF-PL and EF-LI)... |
| 6522 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6523 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6524 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6525 | if (localeFromDefaultSim != null) { |
| 6526 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6527 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6528 | + localeFromDefaultSim); |
| 6529 | return localeFromDefaultSim.toLanguageTag(); |
| 6530 | } else { |
| 6531 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6532 | } |
| 6533 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6534 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6535 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6536 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6537 | // the SIM and carrier preferences does not include a country we add the country |
| 6538 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6539 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6540 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6541 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6542 | return mccLocale.toLanguageTag(); |
| 6543 | } |
| 6544 | |
| 6545 | if (DBG) log("No locale found - returning null"); |
| 6546 | return null; |
| 6547 | } finally { |
| 6548 | Binder.restoreCallingIdentity(identity); |
| 6549 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6550 | } |
| 6551 | |
| 6552 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6553 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 6554 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6555 | } |
| 6556 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6557 | /** |
| 6558 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6559 | */ |
| 6560 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6561 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 6562 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6563 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6564 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6565 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6566 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6567 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6568 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6569 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6570 | * representing the state of the modem. |
| 6571 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6572 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6573 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6574 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6575 | */ |
| 6576 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6577 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6578 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6579 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6580 | |
| 6581 | final long identity = Binder.clearCallingIdentity(); |
| 6582 | try { |
| 6583 | ModemActivityInfo ret = null; |
| 6584 | synchronized (mLastModemActivityInfo) { |
| 6585 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 6586 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6587 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6588 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6589 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6590 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6591 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6592 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6593 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6594 | } |
| 6595 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6596 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 6597 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6598 | mLastModemActivityInfo.setIdleTimeMillis( |
| 6599 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6600 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 6601 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 6602 | info.getReceiveTimeMillis() + mLastModemActivityInfo |
| 6603 | .getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6604 | } |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6605 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6606 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 6607 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 6608 | mLastModemActivityInfo.getIdleTimeMillis(), |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6609 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 6610 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6611 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6612 | Bundle bundle = new Bundle(); |
| 6613 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 6614 | result.send(0, bundle); |
| 6615 | } finally { |
| 6616 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6617 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6618 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6619 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6620 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6621 | // less than total activity duration. |
| 6622 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6623 | if (info == null) { |
| 6624 | return false; |
| 6625 | } |
| 6626 | int activityDurationMs = |
| 6627 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6628 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6629 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6630 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6631 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6632 | } |
| 6633 | return (info.isValid() |
| 6634 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6635 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6636 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6637 | && (totalTxTimeMs <= activityDurationMs)); |
| 6638 | } |
| 6639 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6640 | /** |
| 6641 | * {@hide} |
| 6642 | * Returns the service state information on specified subscription. |
| 6643 | */ |
| 6644 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6645 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6646 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6647 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6648 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6649 | return null; |
| 6650 | } |
| 6651 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6652 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6653 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6654 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6655 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6656 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6657 | .setCallingPid(Binder.getCallingPid()) |
| 6658 | .setCallingUid(Binder.getCallingUid()) |
| 6659 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6660 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6661 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6662 | .build()); |
| 6663 | |
| 6664 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6665 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6666 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6667 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6668 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6669 | .setCallingPid(Binder.getCallingPid()) |
| 6670 | .setCallingUid(Binder.getCallingUid()) |
| 6671 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6672 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6673 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6674 | .build()); |
| 6675 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6676 | boolean hasFinePermission = |
| 6677 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6678 | boolean hasCoarsePermission = |
| 6679 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6680 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6681 | final long identity = Binder.clearCallingIdentity(); |
| 6682 | try { |
| 6683 | final Phone phone = getPhone(subId); |
| 6684 | if (phone == null) { |
| 6685 | return null; |
| 6686 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6687 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6688 | ServiceState ss = phone.getServiceState(); |
| 6689 | |
| 6690 | // Scrub out the location info in ServiceState depending on what level of access |
| 6691 | // the caller has. |
| 6692 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6693 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6694 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6695 | } finally { |
| 6696 | Binder.restoreCallingIdentity(identity); |
| 6697 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6698 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6699 | |
| 6700 | /** |
| 6701 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6702 | * |
| 6703 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6704 | * voicemail ringtone. |
| 6705 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6706 | * PhoneAccount. |
| 6707 | */ |
| 6708 | @Override |
| 6709 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6710 | final long identity = Binder.clearCallingIdentity(); |
| 6711 | try { |
| 6712 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6713 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6714 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6715 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6716 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6717 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6718 | } finally { |
| 6719 | Binder.restoreCallingIdentity(identity); |
| 6720 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6721 | } |
| 6722 | |
| 6723 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6724 | * Sets the per-account voicemail ringtone. |
| 6725 | * |
| 6726 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6727 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6728 | * |
| 6729 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6730 | * voicemail ringtone. |
| 6731 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6732 | * PhoneAccount. |
| 6733 | */ |
| 6734 | @Override |
| 6735 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6736 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6737 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6738 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6739 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6740 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6741 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6742 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6743 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6744 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6745 | |
| 6746 | final long identity = Binder.clearCallingIdentity(); |
| 6747 | try { |
| 6748 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6749 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6750 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6751 | } |
| 6752 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6753 | } finally { |
| 6754 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6755 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6756 | } |
| 6757 | |
| 6758 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6759 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6760 | * |
| 6761 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6762 | * voicemail vibration setting. |
| 6763 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6764 | */ |
| 6765 | @Override |
| 6766 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6767 | final long identity = Binder.clearCallingIdentity(); |
| 6768 | try { |
| 6769 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6770 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6771 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6772 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6773 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6774 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6775 | } finally { |
| 6776 | Binder.restoreCallingIdentity(identity); |
| 6777 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6778 | } |
| 6779 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6780 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6781 | * Sets the per-account voicemail vibration. |
| 6782 | * |
| 6783 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6784 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6785 | * |
| 6786 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6787 | * voicemail vibration setting. |
| 6788 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6789 | * specific PhoneAccount. |
| 6790 | */ |
| 6791 | @Override |
| 6792 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6793 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6794 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6795 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6796 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6797 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6798 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6799 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6800 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6801 | } |
| 6802 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6803 | final long identity = Binder.clearCallingIdentity(); |
| 6804 | try { |
| 6805 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6806 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6807 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6808 | } |
| 6809 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6810 | } finally { |
| 6811 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6812 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6813 | } |
| 6814 | |
| 6815 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6816 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6817 | * |
| 6818 | * @throws SecurityException if the caller does not have the required permission |
| 6819 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6820 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6821 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6822 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6823 | } |
| 6824 | |
| 6825 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6826 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6827 | * permission. |
| 6828 | * |
| 6829 | * @throws SecurityException if the caller does not have the required permission |
| 6830 | */ |
| 6831 | private void enforceSendSmsPermission() { |
| 6832 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6833 | } |
| 6834 | |
| 6835 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6836 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6837 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6838 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6839 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6840 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6841 | final long identity = Binder.clearCallingIdentity(); |
| 6842 | try { |
| 6843 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6844 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6845 | if (componentName == null) { |
| 6846 | throw new SecurityException( |
| 6847 | "Caller not current active visual voicemail package[null]"); |
| 6848 | } |
| 6849 | String vvmPackage = componentName.getPackageName(); |
| 6850 | if (!callingPackage.equals(vvmPackage)) { |
| 6851 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6852 | + vvmPackage + "]"); |
| 6853 | } |
| 6854 | } finally { |
| 6855 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6856 | } |
| 6857 | } |
| 6858 | |
| 6859 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6860 | * Return the application ID for the app type. |
| 6861 | * |
| 6862 | * @param subId the subscription ID that this request applies to. |
| 6863 | * @param appType the uicc app type. |
| 6864 | * @return Application ID for specificied app type, or null if no uicc. |
| 6865 | */ |
| 6866 | @Override |
| 6867 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6868 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6869 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6870 | |
| 6871 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6872 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6873 | if (phone == null) { |
| 6874 | return null; |
| 6875 | } |
| 6876 | String aid = null; |
| 6877 | try { |
| 6878 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6879 | .getApplicationByType(appType).getAid(); |
| 6880 | } catch (Exception e) { |
| 6881 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6882 | } |
| 6883 | return aid; |
| 6884 | } finally { |
| 6885 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6886 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6887 | } |
| 6888 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6889 | /** |
| 6890 | * Return the Electronic Serial Number. |
| 6891 | * |
| 6892 | * @param subId the subscription ID that this request applies to. |
| 6893 | * @return ESN or null if error. |
| 6894 | */ |
| 6895 | @Override |
| 6896 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6897 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6898 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6899 | |
| 6900 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6901 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6902 | if (phone == null) { |
| 6903 | return null; |
| 6904 | } |
| 6905 | String esn = null; |
| 6906 | try { |
| 6907 | esn = phone.getEsn(); |
| 6908 | } catch (Exception e) { |
| 6909 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6910 | } |
| 6911 | return esn; |
| 6912 | } finally { |
| 6913 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6914 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6915 | } |
| 6916 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6917 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6918 | * Return the Preferred Roaming List Version. |
| 6919 | * |
| 6920 | * @param subId the subscription ID that this request applies to. |
| 6921 | * @return PRLVersion or null if error. |
| 6922 | */ |
| 6923 | @Override |
| 6924 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6925 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6926 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6927 | |
| 6928 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6929 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6930 | if (phone == null) { |
| 6931 | return null; |
| 6932 | } |
| 6933 | String cdmaPrlVersion = null; |
| 6934 | try { |
| 6935 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6936 | } catch (Exception e) { |
| 6937 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6938 | } |
| 6939 | return cdmaPrlVersion; |
| 6940 | } finally { |
| 6941 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6942 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6943 | } |
| 6944 | |
| 6945 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6946 | * Get snapshot of Telephony histograms |
| 6947 | * @return List of Telephony histograms |
| 6948 | * @hide |
| 6949 | */ |
| 6950 | @Override |
| 6951 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6952 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6953 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6954 | |
| 6955 | final long identity = Binder.clearCallingIdentity(); |
| 6956 | try { |
| 6957 | return RIL.getTelephonyRILTimingHistograms(); |
| 6958 | } finally { |
| 6959 | Binder.restoreCallingIdentity(identity); |
| 6960 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6961 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6962 | |
| 6963 | /** |
| 6964 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6965 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6966 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6967 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6968 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6969 | * @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] | 6970 | */ |
| 6971 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6972 | @TelephonyManager.SetCarrierRestrictionResult |
| 6973 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6974 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6975 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6976 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6977 | if (carrierRestrictionRules == null) { |
| 6978 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6979 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6980 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6981 | final long identity = Binder.clearCallingIdentity(); |
| 6982 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6983 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6984 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6985 | } finally { |
| 6986 | Binder.restoreCallingIdentity(identity); |
| 6987 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6988 | } |
| 6989 | |
| 6990 | /** |
| 6991 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6992 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6993 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6994 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6995 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6996 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6997 | */ |
| 6998 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6999 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7000 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7001 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7002 | |
| 7003 | final long identity = Binder.clearCallingIdentity(); |
| 7004 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7005 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7006 | if (response instanceof CarrierRestrictionRules) { |
| 7007 | return (CarrierRestrictionRules) response; |
| 7008 | } |
| 7009 | // Response is an Exception of some kind, |
| 7010 | // which is signalled to the user as a NULL retval |
| 7011 | return null; |
| 7012 | } catch (Exception e) { |
| 7013 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7014 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7015 | } finally { |
| 7016 | Binder.restoreCallingIdentity(identity); |
| 7017 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7018 | } |
| 7019 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7020 | /** |
| 7021 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 7022 | * @param subId the subscription ID that this action applies to. |
| 7023 | * @param enabled control enable or disable metered apns. |
| 7024 | * {@hide} |
| 7025 | */ |
| 7026 | @Override |
| 7027 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 7028 | enforceModifyPermission(); |
| 7029 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7030 | |
| 7031 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7032 | if (phone == null) { |
| 7033 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 7034 | return; |
| 7035 | } |
| 7036 | try { |
| 7037 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7038 | } catch (Exception e) { |
| 7039 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7040 | } finally { |
| 7041 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7042 | } |
| 7043 | } |
| 7044 | |
| 7045 | /** |
| 7046 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7047 | * @param subId the subscription ID that this action applies to. |
| 7048 | * @param enabled control enable or disable radio. |
| 7049 | * {@hide} |
| 7050 | */ |
| 7051 | @Override |
| 7052 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7053 | enforceModifyPermission(); |
| 7054 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7055 | |
| 7056 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7057 | if (phone == null) { |
| 7058 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7059 | return; |
| 7060 | } |
| 7061 | try { |
| 7062 | phone.carrierActionSetRadioEnabled(enabled); |
| 7063 | } catch (Exception e) { |
| 7064 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7065 | } finally { |
| 7066 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7067 | } |
| 7068 | } |
| 7069 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7070 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7071 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7072 | * network status based on which carrier apps could apply actions accordingly, |
| 7073 | * enable/disable default url handler for example. |
| 7074 | * |
| 7075 | * @param subId the subscription ID that this action applies to. |
| 7076 | * @param report control start/stop reporting the default network status. |
| 7077 | * {@hide} |
| 7078 | */ |
| 7079 | @Override |
| 7080 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7081 | enforceModifyPermission(); |
| 7082 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7083 | |
| 7084 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7085 | if (phone == null) { |
| 7086 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7087 | return; |
| 7088 | } |
| 7089 | try { |
| 7090 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7091 | } catch (Exception e) { |
| 7092 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7093 | } finally { |
| 7094 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7095 | } |
| 7096 | } |
| 7097 | |
| 7098 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7099 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7100 | * @param subId the subscription ID that this action applies to. |
| 7101 | * {@hide} |
| 7102 | */ |
| 7103 | @Override |
| 7104 | public void carrierActionResetAll(int subId) { |
| 7105 | enforceModifyPermission(); |
| 7106 | final Phone phone = getPhone(subId); |
| 7107 | if (phone == null) { |
| 7108 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7109 | return; |
| 7110 | } |
| 7111 | try { |
| 7112 | phone.carrierActionResetAll(); |
| 7113 | } catch (Exception e) { |
| 7114 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7115 | } |
| 7116 | } |
| 7117 | |
| 7118 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7119 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7120 | * bug report is being generated. |
| 7121 | */ |
| 7122 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7123 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7124 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7125 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7126 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7127 | + Binder.getCallingPid() |
| 7128 | + ", uid=" + Binder.getCallingUid() |
| 7129 | + "without permission " |
| 7130 | + android.Manifest.permission.DUMP); |
| 7131 | return; |
| 7132 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7133 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7134 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7135 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7136 | @Override |
| 7137 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 7138 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 7139 | throws RemoteException { |
Torbjorn Eklund | 1050cb0 | 2018-11-16 14:05:38 +0100 | [diff] [blame] | 7140 | (new TelephonyShellCommand(this, getDefaultPhone().getContext())) |
| 7141 | .exec(this, in, out, err, args, callback, resultReceiver); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7142 | } |
| 7143 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7144 | /** |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7145 | * Policy control of data connection. Usually used when data limit is passed. |
| 7146 | * @param enabled True if enabling the data, otherwise disabling. |
| 7147 | * @param subId Subscription index |
| 7148 | * {@hide} |
| 7149 | */ |
| 7150 | @Override |
| 7151 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 7152 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7153 | |
| 7154 | final long identity = Binder.clearCallingIdentity(); |
| 7155 | try { |
| 7156 | Phone phone = getPhone(subId); |
| 7157 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 7158 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7159 | } |
| 7160 | } finally { |
| 7161 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7162 | } |
| 7163 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7164 | |
| 7165 | /** |
| 7166 | * Get Client request stats |
| 7167 | * @return List of Client Request Stats |
| 7168 | * @hide |
| 7169 | */ |
| 7170 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7171 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7172 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7173 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7174 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7175 | return null; |
| 7176 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7177 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7178 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7179 | final long identity = Binder.clearCallingIdentity(); |
| 7180 | try { |
| 7181 | if (phone != null) { |
| 7182 | return phone.getClientRequestStats(); |
| 7183 | } |
| 7184 | |
| 7185 | return null; |
| 7186 | } finally { |
| 7187 | Binder.restoreCallingIdentity(identity); |
| 7188 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7189 | } |
| 7190 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7191 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7192 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7193 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7194 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7195 | |
| 7196 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7197 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7198 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7199 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7200 | * @param state State of SIM (power down, power up, pass through) |
| 7201 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7202 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7203 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7204 | * |
| 7205 | **/ |
| 7206 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7207 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7208 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7209 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7210 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7211 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7212 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7213 | final long identity = Binder.clearCallingIdentity(); |
| 7214 | try { |
| 7215 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7216 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7217 | } |
| 7218 | } finally { |
| 7219 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7220 | } |
| 7221 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7222 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7223 | private boolean isUssdApiAllowed(int subId) { |
| 7224 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7225 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7226 | if (configManager == null) { |
| 7227 | return false; |
| 7228 | } |
| 7229 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7230 | if (pb == null) { |
| 7231 | return false; |
| 7232 | } |
| 7233 | return pb.getBoolean( |
| 7234 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7235 | } |
| 7236 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7237 | /** |
| 7238 | * Check if phone is in emergency callback mode |
| 7239 | * @return true if phone is in emergency callback mode |
| 7240 | * @param subId sub id |
| 7241 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7242 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7243 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7244 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7245 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7246 | |
| 7247 | final long identity = Binder.clearCallingIdentity(); |
| 7248 | try { |
| 7249 | if (phone != null) { |
| 7250 | return phone.isInEcm(); |
| 7251 | } else { |
| 7252 | return false; |
| 7253 | } |
| 7254 | } finally { |
| 7255 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7256 | } |
| 7257 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7258 | |
| 7259 | /** |
| 7260 | * Get the current signal strength information for the given subscription. |
| 7261 | * Because this information is not updated when the device is in a low power state |
| 7262 | * it should not be relied-upon to be current. |
| 7263 | * @param subId Subscription index |
| 7264 | * @return the most recent cached signal strength info from the modem |
| 7265 | */ |
| 7266 | @Override |
| 7267 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7268 | final long identity = Binder.clearCallingIdentity(); |
| 7269 | try { |
| 7270 | Phone p = getPhone(subId); |
| 7271 | if (p == null) { |
| 7272 | return null; |
| 7273 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7274 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7275 | return p.getSignalStrength(); |
| 7276 | } finally { |
| 7277 | Binder.restoreCallingIdentity(identity); |
| 7278 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7279 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7280 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7281 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7282 | * Get the current modem radio state for the given slot. |
| 7283 | * @param slotIndex slot index. |
| 7284 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7285 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7286 | * @return the current radio power state from the modem |
| 7287 | */ |
| 7288 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7289 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7290 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7291 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7292 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7293 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7294 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7295 | } |
| 7296 | |
| 7297 | final long identity = Binder.clearCallingIdentity(); |
| 7298 | try { |
| 7299 | return phone.getRadioPowerState(); |
| 7300 | } finally { |
| 7301 | Binder.restoreCallingIdentity(identity); |
| 7302 | } |
| 7303 | } |
| 7304 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7305 | } |
| 7306 | |
| 7307 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7308 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7309 | * |
| 7310 | * <p>Requires one of the following permissions: |
| 7311 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7312 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7313 | * privileges. |
| 7314 | * |
| 7315 | * @param subId subscription id |
| 7316 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7317 | * {@code false}. |
| 7318 | */ |
| 7319 | @Override |
| 7320 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7321 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7322 | null /* message */); |
| 7323 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7324 | boolean isEnabled = false; |
| 7325 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7326 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7327 | Phone phone = getPhone(subId); |
| 7328 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7329 | } catch (Exception e) { |
| 7330 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7331 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7332 | } finally { |
| 7333 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7334 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7335 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7336 | } |
| 7337 | |
| 7338 | |
| 7339 | /** |
| 7340 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7341 | * |
| 7342 | * <p> Requires permission: |
| 7343 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7344 | * privileges. |
| 7345 | * |
| 7346 | * @param subId subscription id |
| 7347 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7348 | */ |
| 7349 | @Override |
| 7350 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7351 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7352 | mApp, subId, "setDataRoamingEnabled"); |
| 7353 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7354 | final long identity = Binder.clearCallingIdentity(); |
| 7355 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7356 | Phone phone = getPhone(subId); |
| 7357 | if (phone != null) { |
| 7358 | phone.setDataRoamingEnabled(isEnabled); |
| 7359 | } |
| 7360 | } finally { |
| 7361 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7362 | } |
| 7363 | } |
| 7364 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7365 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7366 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7367 | TelephonyPermissions |
| 7368 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7369 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7370 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7371 | boolean isAllowed = true; |
| 7372 | final long identity = Binder.clearCallingIdentity(); |
| 7373 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7374 | Phone phone = getPhone(subId); |
| 7375 | if (phone != null) { |
| 7376 | isAllowed = phone.isCspPlmnEnabled(); |
| 7377 | } |
| 7378 | } finally { |
| 7379 | Binder.restoreCallingIdentity(identity); |
| 7380 | } |
| 7381 | return isAllowed; |
| 7382 | } |
| 7383 | |
| 7384 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7385 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7386 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7387 | try { |
| 7388 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7389 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7390 | } catch (SecurityException e) { |
| 7391 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7392 | // has carrier privileges on an active UICC |
| 7393 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7394 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7395 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7396 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7397 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7398 | |
| 7399 | final long identity = Binder.clearCallingIdentity(); |
| 7400 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7401 | UiccController uiccController = UiccController.getInstance(); |
| 7402 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7403 | if (hasReadPermission) { |
| 7404 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7405 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7406 | |
| 7407 | // Remove private info if the caller doesn't have access |
| 7408 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7409 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7410 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7411 | // is available |
| 7412 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7413 | if (card == null || card.getUiccProfile() == null) { |
| 7414 | // assume no access if the card or profile is unavailable |
| 7415 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7416 | continue; |
| 7417 | } |
| 7418 | UiccProfile profile = card.getUiccProfile(); |
| 7419 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7420 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7421 | filteredInfos.add(cardInfo); |
| 7422 | } else { |
| 7423 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7424 | } |
| 7425 | } |
| 7426 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7427 | } finally { |
| 7428 | Binder.restoreCallingIdentity(identity); |
| 7429 | } |
| 7430 | } |
| 7431 | |
| 7432 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7433 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7434 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7435 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7436 | final long identity = Binder.clearCallingIdentity(); |
| 7437 | try { |
| 7438 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7439 | if (slots == null) { |
| 7440 | Rlog.i(LOG_TAG, "slots is null."); |
| 7441 | return null; |
| 7442 | } |
| 7443 | |
| 7444 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7445 | for (int i = 0; i < slots.length; i++) { |
| 7446 | UiccSlot slot = slots[i]; |
| 7447 | if (slot == null) { |
| 7448 | continue; |
| 7449 | } |
| 7450 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7451 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7452 | UiccCard card = slot.getUiccCard(); |
| 7453 | if (card != null) { |
| 7454 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7455 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7456 | cardId = slot.getEid(); |
| 7457 | if (TextUtils.isEmpty(cardId)) { |
| 7458 | cardId = slot.getIccId(); |
| 7459 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7460 | } |
| 7461 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7462 | if (cardId != null) { |
| 7463 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7464 | // if cardId is an EID, it's all digits so this is fine |
| 7465 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7466 | } |
| 7467 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7468 | int cardState = 0; |
| 7469 | switch (slot.getCardState()) { |
| 7470 | case CARDSTATE_ABSENT: |
| 7471 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7472 | break; |
| 7473 | case CARDSTATE_PRESENT: |
| 7474 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7475 | break; |
| 7476 | case CARDSTATE_ERROR: |
| 7477 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7478 | break; |
| 7479 | case CARDSTATE_RESTRICTED: |
| 7480 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7481 | break; |
| 7482 | default: |
| 7483 | break; |
| 7484 | |
| 7485 | } |
| 7486 | |
| 7487 | infos[i] = new UiccSlotInfo( |
| 7488 | slot.isActive(), |
| 7489 | slot.isEuicc(), |
| 7490 | cardId, |
| 7491 | cardState, |
| 7492 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7493 | slot.isExtendedApduSupported(), |
| 7494 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7495 | } |
| 7496 | return infos; |
| 7497 | } finally { |
| 7498 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7499 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7500 | } |
| 7501 | |
| 7502 | @Override |
| 7503 | public boolean switchSlots(int[] physicalSlots) { |
| 7504 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7505 | |
| 7506 | final long identity = Binder.clearCallingIdentity(); |
| 7507 | try { |
| 7508 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7509 | } finally { |
| 7510 | Binder.restoreCallingIdentity(identity); |
| 7511 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7512 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7513 | |
| 7514 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7515 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7516 | final long identity = Binder.clearCallingIdentity(); |
| 7517 | try { |
| 7518 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7519 | } finally { |
| 7520 | Binder.restoreCallingIdentity(identity); |
| 7521 | } |
| 7522 | } |
| 7523 | |
| 7524 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7525 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 7526 | enforceModifyPermission(); |
| 7527 | final Phone phone = getPhone(subId); |
| 7528 | if (phone == null) { |
| 7529 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 7530 | return; |
| 7531 | } |
| 7532 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7533 | final long identity = Binder.clearCallingIdentity(); |
| 7534 | try { |
| 7535 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 7536 | } finally { |
| 7537 | Binder.restoreCallingIdentity(identity); |
| 7538 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7539 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7540 | |
| 7541 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7542 | * A test API to reload the UICC profile. |
| 7543 | * |
| 7544 | * <p>Requires that the calling app has permission |
| 7545 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7546 | * @hide |
| 7547 | */ |
| 7548 | @Override |
| 7549 | public void refreshUiccProfile(int subId) { |
| 7550 | enforceModifyPermission(); |
| 7551 | |
| 7552 | final long identity = Binder.clearCallingIdentity(); |
| 7553 | try { |
| 7554 | Phone phone = getPhone(subId); |
| 7555 | if (phone == null) { |
| 7556 | return; |
| 7557 | } |
| 7558 | UiccCard uiccCard = phone.getUiccCard(); |
| 7559 | if (uiccCard == null) { |
| 7560 | return; |
| 7561 | } |
| 7562 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7563 | if (uiccProfile == null) { |
| 7564 | return; |
| 7565 | } |
| 7566 | uiccProfile.refresh(); |
| 7567 | } finally { |
| 7568 | Binder.restoreCallingIdentity(identity); |
| 7569 | } |
| 7570 | } |
| 7571 | |
| 7572 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7573 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7574 | */ |
| 7575 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7576 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7577 | } |
| 7578 | |
| 7579 | /** |
| 7580 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7581 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7582 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7583 | */ |
| 7584 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7585 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7586 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7587 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7588 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7589 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7590 | return isDataRoamingEnabled; |
| 7591 | } |
| 7592 | |
| 7593 | /** |
| 7594 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7595 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7596 | */ |
| 7597 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7598 | List<Integer> list = TelephonyProperties.default_network(); |
| 7599 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7600 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7601 | return list.get(phoneId); |
| 7602 | } |
| 7603 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7604 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7605 | |
| 7606 | @Override |
| 7607 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7608 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7609 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7610 | |
| 7611 | final long identity = Binder.clearCallingIdentity(); |
| 7612 | try { |
| 7613 | final Phone phone = getPhone(subId); |
| 7614 | if (phone == null) { |
| 7615 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7616 | return; |
| 7617 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7618 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7619 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7620 | } finally { |
| 7621 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7622 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7623 | } |
| 7624 | |
| 7625 | @Override |
| 7626 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7627 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7628 | |
| 7629 | final long identity = Binder.clearCallingIdentity(); |
| 7630 | try { |
| 7631 | final Phone phone = getPhone(subId); |
| 7632 | if (phone == null) { |
| 7633 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7634 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7635 | } |
| 7636 | return phone.getCarrierIdListVersion(); |
| 7637 | } finally { |
| 7638 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7639 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7640 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7641 | |
| 7642 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7643 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7644 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7645 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7646 | mApp, subId, callingPackage, callingFeatureId, |
| 7647 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7648 | return -1; |
| 7649 | } |
| 7650 | |
| 7651 | final long identity = Binder.clearCallingIdentity(); |
| 7652 | try { |
| 7653 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7654 | } finally { |
| 7655 | Binder.restoreCallingIdentity(identity); |
| 7656 | } |
| 7657 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7658 | |
| 7659 | @Override |
| 7660 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7661 | TelephonyPermissions |
| 7662 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7663 | mApp, subId, "getCdmaRoamingMode"); |
| 7664 | |
| 7665 | final long identity = Binder.clearCallingIdentity(); |
| 7666 | try { |
| 7667 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7668 | } finally { |
| 7669 | Binder.restoreCallingIdentity(identity); |
| 7670 | } |
| 7671 | } |
| 7672 | |
| 7673 | @Override |
| 7674 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7675 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7676 | mApp, subId, "setCdmaRoamingMode"); |
| 7677 | |
| 7678 | final long identity = Binder.clearCallingIdentity(); |
| 7679 | try { |
| 7680 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7681 | } finally { |
| 7682 | Binder.restoreCallingIdentity(identity); |
| 7683 | } |
| 7684 | } |
| 7685 | |
| 7686 | @Override |
| 7687 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7688 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7689 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7690 | |
| 7691 | final long identity = Binder.clearCallingIdentity(); |
| 7692 | try { |
| 7693 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7694 | } finally { |
| 7695 | Binder.restoreCallingIdentity(identity); |
| 7696 | } |
| 7697 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7698 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7699 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7700 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7701 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7702 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7703 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7704 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7705 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7706 | } |
| 7707 | final long identity = Binder.clearCallingIdentity(); |
| 7708 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7709 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7710 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7711 | if (phone.getEmergencyNumberTracker() != null |
| 7712 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7713 | emergencyNumberListInternal.put( |
| 7714 | phone.getSubId(), |
| 7715 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7716 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7717 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7718 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7719 | } finally { |
| 7720 | Binder.restoreCallingIdentity(identity); |
| 7721 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7722 | } |
| 7723 | |
| 7724 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7725 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7726 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7727 | if (!exactMatch) { |
| 7728 | TelephonyPermissions |
| 7729 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7730 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7731 | } |
| 7732 | final long identity = Binder.clearCallingIdentity(); |
| 7733 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7734 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7735 | if (phone.getEmergencyNumberTracker() != null |
| 7736 | && phone.getEmergencyNumberTracker() != null) { |
| 7737 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7738 | number, exactMatch)) { |
| 7739 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7740 | } |
| 7741 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7742 | } |
| 7743 | return false; |
| 7744 | } finally { |
| 7745 | Binder.restoreCallingIdentity(identity); |
| 7746 | } |
| 7747 | } |
| 7748 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7749 | /** |
| 7750 | * Update emergency number list for test mode. |
| 7751 | */ |
| 7752 | @Override |
| 7753 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7754 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7755 | "updateEmergencyNumberListTestMode"); |
| 7756 | |
| 7757 | final long identity = Binder.clearCallingIdentity(); |
| 7758 | try { |
| 7759 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7760 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7761 | if (tracker != null) { |
| 7762 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7763 | } |
| 7764 | } |
| 7765 | } finally { |
| 7766 | Binder.restoreCallingIdentity(identity); |
| 7767 | } |
| 7768 | } |
| 7769 | |
| 7770 | /** |
| 7771 | * Get the full emergency number list for test mode. |
| 7772 | */ |
| 7773 | @Override |
| 7774 | public List<String> getEmergencyNumberListTestMode() { |
| 7775 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7776 | "getEmergencyNumberListTestMode"); |
| 7777 | |
| 7778 | final long identity = Binder.clearCallingIdentity(); |
| 7779 | try { |
| 7780 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7781 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7782 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7783 | if (tracker != null) { |
| 7784 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7785 | emergencyNumbers.add(num.getNumber()); |
| 7786 | } |
| 7787 | } |
| 7788 | } |
| 7789 | return new ArrayList<>(emergencyNumbers); |
| 7790 | } finally { |
| 7791 | Binder.restoreCallingIdentity(identity); |
| 7792 | } |
| 7793 | } |
| 7794 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7795 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7796 | public int getEmergencyNumberDbVersion(int subId) { |
| 7797 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7798 | |
| 7799 | final long identity = Binder.clearCallingIdentity(); |
| 7800 | try { |
| 7801 | final Phone phone = getPhone(subId); |
| 7802 | if (phone == null) { |
| 7803 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7804 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7805 | } |
| 7806 | return phone.getEmergencyNumberDbVersion(); |
| 7807 | } finally { |
| 7808 | Binder.restoreCallingIdentity(identity); |
| 7809 | } |
| 7810 | } |
| 7811 | |
| 7812 | @Override |
| 7813 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7814 | enforceModifyPermission(); |
| 7815 | |
| 7816 | final long identity = Binder.clearCallingIdentity(); |
| 7817 | try { |
| 7818 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7819 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7820 | if (tracker != null) { |
| 7821 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7822 | } |
| 7823 | } |
| 7824 | } finally { |
| 7825 | Binder.restoreCallingIdentity(identity); |
| 7826 | } |
| 7827 | } |
| 7828 | |
| 7829 | @Override |
| 7830 | public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) { |
| 7831 | enforceActiveEmergencySessionPermission(); |
| 7832 | |
| 7833 | final long identity = Binder.clearCallingIdentity(); |
| 7834 | try { |
| 7835 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7836 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7837 | if (tracker != null) { |
| 7838 | tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath); |
| 7839 | } |
| 7840 | } |
| 7841 | } finally { |
| 7842 | Binder.restoreCallingIdentity(identity); |
| 7843 | } |
| 7844 | } |
| 7845 | |
| 7846 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7847 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7848 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7849 | Phone phone = getPhone(subId); |
| 7850 | if (phone == null) { |
| 7851 | return null; |
| 7852 | } |
| 7853 | final long identity = Binder.clearCallingIdentity(); |
| 7854 | try { |
| 7855 | UiccProfile profile = UiccController.getInstance() |
| 7856 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7857 | if (profile != null) { |
| 7858 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7859 | } |
| 7860 | } finally { |
| 7861 | Binder.restoreCallingIdentity(identity); |
| 7862 | } |
| 7863 | return null; |
| 7864 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7865 | |
| 7866 | /** |
| 7867 | * Enable or disable a modem stack. |
| 7868 | */ |
| 7869 | @Override |
| 7870 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7871 | enforceModifyPermission(); |
| 7872 | |
| 7873 | final long identity = Binder.clearCallingIdentity(); |
| 7874 | try { |
| 7875 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7876 | if (phone == null) { |
| 7877 | return false; |
| 7878 | } else { |
| 7879 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7880 | } |
| 7881 | } finally { |
| 7882 | Binder.restoreCallingIdentity(identity); |
| 7883 | } |
| 7884 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7885 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7886 | /** |
| 7887 | * Whether a modem stack is enabled or not. |
| 7888 | */ |
| 7889 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7890 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7891 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7892 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7893 | if (phone == null) return false; |
| 7894 | |
| 7895 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7896 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7897 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7898 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7899 | } |
| 7900 | |
| 7901 | final long identity = Binder.clearCallingIdentity(); |
| 7902 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7903 | try { |
| 7904 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7905 | } catch (NoSuchElementException ex) { |
| 7906 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7907 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7908 | } finally { |
| 7909 | Binder.restoreCallingIdentity(identity); |
| 7910 | } |
| 7911 | } |
| 7912 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7913 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7914 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7915 | enforceModifyPermission(); |
| 7916 | |
| 7917 | final long identity = Binder.clearCallingIdentity(); |
| 7918 | try { |
| 7919 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7920 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7921 | .commit(); |
| 7922 | } finally { |
| 7923 | Binder.restoreCallingIdentity(identity); |
| 7924 | } |
| 7925 | } |
| 7926 | |
| 7927 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7928 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7929 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7930 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7931 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 7932 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7933 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7934 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7935 | |
| 7936 | final long identity = Binder.clearCallingIdentity(); |
| 7937 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7938 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7939 | } finally { |
| 7940 | Binder.restoreCallingIdentity(identity); |
| 7941 | } |
| 7942 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7943 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7944 | @TelephonyManager.IsMultiSimSupportedResult |
| 7945 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7946 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7947 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7948 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7949 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7950 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7951 | } |
| 7952 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7953 | // supported by the modem, indicate that it is restricted. |
| 7954 | PhoneCapability staticCapability = |
| 7955 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7956 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7957 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7958 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7959 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 7960 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7961 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7962 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7963 | } |
| 7964 | // Check if support of multiple SIMs is restricted by carrier |
| 7965 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7966 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7967 | } |
| 7968 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7969 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7970 | } |
| 7971 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7972 | /** |
| 7973 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7974 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7975 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7976 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7977 | * @param numOfSims number of active sims we want to switch to |
| 7978 | */ |
| 7979 | @Override |
| 7980 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7981 | if (numOfSims == 1) { |
| 7982 | enforceModifyPermission(); |
| 7983 | } else { |
| 7984 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7985 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7986 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7987 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7988 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7989 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7990 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7991 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7992 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7993 | return; |
| 7994 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7995 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7996 | } finally { |
| 7997 | Binder.restoreCallingIdentity(identity); |
| 7998 | } |
| 7999 | } |
| 8000 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8001 | @Override |
| 8002 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8003 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8004 | Phone phone = getPhone(subId); |
| 8005 | if (phone == null) { |
| 8006 | return false; |
| 8007 | } |
| 8008 | final long identity = Binder.clearCallingIdentity(); |
| 8009 | try { |
| 8010 | UiccCard uiccCard = phone.getUiccCard(); |
| 8011 | if (uiccCard == null) { |
| 8012 | return false; |
| 8013 | } |
| 8014 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8015 | if (uiccProfile == null) { |
| 8016 | return false; |
| 8017 | } |
| 8018 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8019 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8020 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8021 | } |
| 8022 | return false; |
| 8023 | } finally { |
| 8024 | Binder.restoreCallingIdentity(identity); |
| 8025 | } |
| 8026 | } |
| 8027 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8028 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8029 | * Get whether making changes to modem configurations will trigger reboot. |
| 8030 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8031 | */ |
| 8032 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8033 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8034 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8035 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8036 | mApp, subId, callingPackage, callingFeatureId, |
| 8037 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8038 | return false; |
| 8039 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8040 | final long identity = Binder.clearCallingIdentity(); |
| 8041 | try { |
| 8042 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8043 | } finally { |
| 8044 | Binder.restoreCallingIdentity(identity); |
| 8045 | } |
| 8046 | } |
| 8047 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8048 | private void updateModemStateMetrics() { |
| 8049 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8050 | // TODO: check the state for each modem if the api is ready. |
| 8051 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8052 | } |
| 8053 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8054 | @Override |
| 8055 | public int[] getSlotsMapping() { |
| 8056 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8057 | |
| 8058 | final long identity = Binder.clearCallingIdentity(); |
| 8059 | try { |
| 8060 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8061 | // All logical slots should have a mapping to a physical slot. |
| 8062 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8063 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8064 | for (int i = 0; i < slotInfos.length; i++) { |
| 8065 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8066 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8067 | } |
| 8068 | } |
| 8069 | return logicalSlotsMapping; |
| 8070 | } finally { |
| 8071 | Binder.restoreCallingIdentity(identity); |
| 8072 | } |
| 8073 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8074 | |
| 8075 | /** |
| 8076 | * Get the IRadio HAL Version |
| 8077 | */ |
| 8078 | @Override |
| 8079 | public int getRadioHalVersion() { |
| 8080 | Phone phone = getDefaultPhone(); |
| 8081 | if (phone == null) return -1; |
| 8082 | HalVersion hv = phone.getHalVersion(); |
| 8083 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8084 | return hv.major * 100 + hv.minor; |
| 8085 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8086 | |
| 8087 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8088 | * Get the current calling package name. |
| 8089 | * @return the current calling package name |
| 8090 | */ |
| 8091 | @Override |
| 8092 | public String getCurrentPackageName() { |
| 8093 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8094 | } |
| 8095 | |
| 8096 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8097 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8098 | * corresponding network requests on a subId. |
| 8099 | * |
| 8100 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8101 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8102 | * 2) APN is un-metered for this subscription, or |
| 8103 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8104 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8105 | * |
| 8106 | * @return whether data is allowed for a apn type. |
| 8107 | * |
| 8108 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8109 | */ |
| 8110 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8111 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8112 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8113 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8114 | |
| 8115 | // Now that all security checks passes, perform the operation as ourselves. |
| 8116 | final long identity = Binder.clearCallingIdentity(); |
| 8117 | try { |
| 8118 | Phone phone = getPhone(subId); |
| 8119 | if (phone == null) return false; |
| 8120 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8121 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8122 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8123 | } finally { |
| 8124 | Binder.restoreCallingIdentity(identity); |
| 8125 | } |
| 8126 | } |
| 8127 | |
| 8128 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8129 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8130 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8131 | |
| 8132 | // Now that all security checks passes, perform the operation as ourselves. |
| 8133 | final long identity = Binder.clearCallingIdentity(); |
| 8134 | try { |
| 8135 | Phone phone = getPhone(subId); |
| 8136 | if (phone == null) return true; // By default return true. |
| 8137 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8138 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8139 | } finally { |
| 8140 | Binder.restoreCallingIdentity(identity); |
| 8141 | } |
| 8142 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8143 | |
| 8144 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8145 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
| 8146 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8147 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8148 | if (iccRecords == null) { |
| 8149 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8150 | return false; |
| 8151 | } |
| 8152 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8153 | } |
| 8154 | |
| 8155 | @Override |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8156 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8157 | if (callingPackage == null) { |
| 8158 | callingPackage = getCurrentPackageName(); |
| 8159 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8160 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8161 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 8162 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 8163 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8164 | } |
| 8165 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8166 | Intent intent = new Intent(); |
| 8167 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8168 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8169 | // Bring up choose default SMS subscription dialog right now |
| 8170 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8171 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8172 | mApp.startActivity(intent); |
| 8173 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8174 | |
| 8175 | @Override |
| 8176 | public String getMmsUAProfUrl(int subId) { |
| 8177 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8178 | final long identity = Binder.clearCallingIdentity(); |
| 8179 | try { |
| 8180 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8181 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 8182 | } finally { |
| 8183 | Binder.restoreCallingIdentity(identity); |
| 8184 | } |
| 8185 | } |
| 8186 | |
| 8187 | @Override |
| 8188 | public String getMmsUserAgent(int subId) { |
| 8189 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8190 | final long identity = Binder.clearCallingIdentity(); |
| 8191 | try { |
| 8192 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8193 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8194 | } finally { |
| 8195 | Binder.restoreCallingIdentity(identity); |
| 8196 | } |
| 8197 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8198 | |
| 8199 | @Override |
| 8200 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 8201 | enforceModifyPermission(); |
| 8202 | |
| 8203 | // Now that all security checks passes, perform the operation as ourselves. |
| 8204 | final long identity = Binder.clearCallingIdentity(); |
| 8205 | try { |
| 8206 | Phone phone = getPhone(subId); |
| 8207 | if (phone == null) return false; |
| 8208 | |
| 8209 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 8210 | } finally { |
| 8211 | Binder.restoreCallingIdentity(identity); |
| 8212 | } |
| 8213 | } |
| 8214 | |
| 8215 | @Override |
| 8216 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 8217 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 8218 | |
| 8219 | // Now that all security checks passes, perform the operation as ourselves. |
| 8220 | final long identity = Binder.clearCallingIdentity(); |
| 8221 | try { |
| 8222 | Phone phone = getPhone(subId); |
| 8223 | if (phone == null) return false; |
| 8224 | |
| 8225 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8226 | } finally { |
| 8227 | Binder.restoreCallingIdentity(identity); |
| 8228 | } |
| 8229 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8230 | |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8231 | @Override |
| 8232 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8233 | enforceModifyPermission(); |
| 8234 | |
| 8235 | // Now that all security checks passes, perform the operation as ourselves. |
| 8236 | final long identity = Binder.clearCallingIdentity(); |
| 8237 | try { |
| 8238 | Phone phone = getPhone(subId); |
| 8239 | if (phone == null) return false; |
| 8240 | |
| 8241 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8242 | } finally { |
| 8243 | Binder.restoreCallingIdentity(identity); |
| 8244 | } |
| 8245 | } |
| 8246 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8247 | /** |
| 8248 | * Updates whether conference event pacakge handling is enabled. |
| 8249 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8250 | * otherwise. |
| 8251 | */ |
| 8252 | @Override |
| 8253 | public void setCepEnabled(boolean isCepEnabled) { |
| 8254 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8255 | |
| 8256 | final long identity = Binder.clearCallingIdentity(); |
| 8257 | try { |
| 8258 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8259 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8260 | Phone defaultPhone = phone.getImsPhone(); |
| 8261 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8262 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8263 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8264 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8265 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8266 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8267 | + imsPhone.getMsisdn()); |
| 8268 | } |
| 8269 | } |
| 8270 | } finally { |
| 8271 | Binder.restoreCallingIdentity(identity); |
| 8272 | } |
| 8273 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8274 | |
| 8275 | /** |
| 8276 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8277 | * |
| 8278 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8279 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8280 | * before being read. |
| 8281 | */ |
| 8282 | @Override |
| 8283 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8284 | isCompressed) { |
| 8285 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8286 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8287 | try { |
| 8288 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8289 | if (configBinder == null) { |
| 8290 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8291 | } else { |
| 8292 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8293 | } |
| 8294 | } catch (RemoteException e) { |
| 8295 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8296 | } |
| 8297 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8298 | |
| 8299 | @Override |
| 8300 | public boolean isIccLockEnabled(int subId) { |
| 8301 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8302 | |
| 8303 | // Now that all security checks passes, perform the operation as ourselves. |
| 8304 | final long identity = Binder.clearCallingIdentity(); |
| 8305 | try { |
| 8306 | Phone phone = getPhone(subId); |
| 8307 | if (phone != null && phone.getIccCard() != null) { |
| 8308 | return phone.getIccCard().getIccLockEnabled(); |
| 8309 | } else { |
| 8310 | return false; |
| 8311 | } |
| 8312 | } finally { |
| 8313 | Binder.restoreCallingIdentity(identity); |
| 8314 | } |
| 8315 | } |
| 8316 | |
| 8317 | /** |
| 8318 | * Set the ICC pin lock enabled or disabled.. |
| 8319 | * |
| 8320 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8321 | * 0 or a positive integer as the attempts remaining value. |
| 8322 | * |
| 8323 | */ |
| 8324 | @Override |
| 8325 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8326 | enforceModifyPermission(); |
| 8327 | |
| 8328 | Phone phone = getPhone(subId); |
| 8329 | if (phone == null) { |
| 8330 | return 0; |
| 8331 | } |
| 8332 | // Now that all security checks passes, perform the operation as ourselves. |
| 8333 | final long identity = Binder.clearCallingIdentity(); |
| 8334 | try { |
| 8335 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8336 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8337 | return attemptsRemaining; |
| 8338 | |
| 8339 | } catch (Exception e) { |
| 8340 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8341 | } finally { |
| 8342 | Binder.restoreCallingIdentity(identity); |
| 8343 | } |
| 8344 | return 0; |
| 8345 | } |
| 8346 | |
| 8347 | /** |
| 8348 | * Change the ICC password used in ICC pin lock. |
| 8349 | * |
| 8350 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8351 | * 0 or a positive integer as the attempts remaining value. |
| 8352 | * |
| 8353 | */ |
| 8354 | @Override |
| 8355 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8356 | enforceModifyPermission(); |
| 8357 | |
| 8358 | Phone phone = getPhone(subId); |
| 8359 | if (phone == null) { |
| 8360 | return 0; |
| 8361 | } |
| 8362 | // Now that all security checks passes, perform the operation as ourselves. |
| 8363 | final long identity = Binder.clearCallingIdentity(); |
| 8364 | try { |
| 8365 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8366 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8367 | return attemptsRemaining; |
| 8368 | |
| 8369 | } catch (Exception e) { |
| 8370 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8371 | } finally { |
| 8372 | Binder.restoreCallingIdentity(identity); |
| 8373 | } |
| 8374 | return 0; |
| 8375 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8376 | } |