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; |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 48 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 49 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 50 | import android.os.PersistableBundle; |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 51 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 53 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | import android.os.ServiceManager; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 55 | import android.os.ServiceSpecificException; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 56 | import android.os.ShellCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 58 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 59 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 60 | import android.preference.PreferenceManager; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 61 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 62 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 63 | import android.provider.Telephony; |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 64 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 65 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 66 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 67 | import android.telecom.TelecomManager; |
Chen Xu | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 68 | import android.telephony.Annotation.ApnType; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 69 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 70 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 71 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 72 | import android.telephony.CellIdentity; |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 73 | import android.telephony.CellIdentityCdma; |
| 74 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 76 | import android.telephony.CellInfoGsm; |
| 77 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 78 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 79 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 80 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 81 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 82 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 83 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 84 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 85 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 86 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 87 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 88 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 89 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 90 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 91 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 92 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 93 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 94 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 95 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 96 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 97 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 98 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 99 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 100 | import android.telephony.data.ApnSetting; |
| 101 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 102 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 103 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 104 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 108 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 109 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 110 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 111 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 112 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 113 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 114 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 115 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 116 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 117 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 118 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 119 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 120 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 121 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 122 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 123 | import com.android.ims.internal.IImsServiceFeatureCallback; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 124 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 128 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 131 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.IBooleanConsumer; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 160 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 171 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 172 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 174 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 175 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 176 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 177 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 178 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 179 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 180 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 181 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 182 | import java.io.FileDescriptor; |
| 183 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 184 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 185 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 186 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 187 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 188 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 189 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 190 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 191 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 192 | import java.util.Set; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 193 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 194 | |
| 195 | /** |
| 196 | * Implementation of the ITelephony interface. |
| 197 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 198 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 199 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 200 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 201 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 202 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 203 | |
| 204 | // Message codes used with mMainThreadHandler |
| 205 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 206 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 207 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 208 | private static final int CMD_OPEN_CHANNEL = 9; |
| 209 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 210 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 211 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 212 | private static final int CMD_NV_READ_ITEM = 13; |
| 213 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 214 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 215 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 216 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 217 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 218 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 219 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 220 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 221 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 222 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 223 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 224 | private static final int CMD_SEND_ENVELOPE = 25; |
| 225 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 226 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 227 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 228 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 229 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 230 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 231 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 232 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 233 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 234 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 235 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 236 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 237 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 238 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 239 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 240 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 241 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 242 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 243 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 244 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 245 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 246 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 247 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 248 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 249 | private static final int CMD_SWITCH_SLOTS = 50; |
| 250 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 251 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 252 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 253 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 254 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 255 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 256 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 257 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 258 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 259 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 260 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 261 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 262 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 263 | private static final int CMD_MODEM_REBOOT = 64; |
| 264 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 265 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 266 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 267 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 268 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 269 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 270 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 271 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 272 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 273 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 274 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 275 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 276 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 277 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 278 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 279 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 280 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 281 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 282 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 283 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 284 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 285 | private static final int CMD_GET_CALL_WAITING = 87; |
| 286 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 287 | private static final int CMD_SET_CALL_WAITING = 89; |
| 288 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 289 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 290 | // Parameters of select command. |
| 291 | private static final int SELECT_COMMAND = 0xA4; |
| 292 | private static final int SELECT_P1 = 0x04; |
| 293 | private static final int SELECT_P2 = 0; |
| 294 | private static final int SELECT_P3 = 0x10; |
| 295 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 296 | /** The singleton instance. */ |
| 297 | private static PhoneInterfaceManager sInstance; |
| 298 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 299 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 300 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 301 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 302 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 303 | private AppOpsManager mAppOps; |
| 304 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 305 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 306 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 307 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 308 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 309 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 310 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 311 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 312 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 313 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 314 | // String to store multi SIM allowed |
| 315 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 316 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 317 | // The AID of ISD-R. |
| 318 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 319 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 320 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 321 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 322 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 323 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 324 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 325 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 326 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 327 | */ |
| 328 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 329 | "reset_network_erase_modem_config_enabled"; |
| 330 | |
| 331 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 332 | * A request object to use for transmitting data to an ICC. |
| 333 | */ |
| 334 | private static final class IccAPDUArgument { |
| 335 | public int channel, cla, command, p1, p2, p3; |
| 336 | public String data; |
| 337 | |
| 338 | public IccAPDUArgument(int channel, int cla, int command, |
| 339 | int p1, int p2, int p3, String data) { |
| 340 | this.channel = channel; |
| 341 | this.cla = cla; |
| 342 | this.command = command; |
| 343 | this.p1 = p1; |
| 344 | this.p2 = p2; |
| 345 | this.p3 = p3; |
| 346 | this.data = data; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 351 | * A request object to use for transmitting data to an ICC. |
| 352 | */ |
| 353 | private static final class ManualNetworkSelectionArgument { |
| 354 | public OperatorInfo operatorInfo; |
| 355 | public boolean persistSelection; |
| 356 | |
| 357 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 358 | this.operatorInfo = operatorInfo; |
| 359 | this.persistSelection = persistSelection; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 364 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 365 | * request after sending. The main thread will notify the request when it is complete. |
| 366 | */ |
| 367 | private static final class MainThreadRequest { |
| 368 | /** The argument to use for the request */ |
| 369 | public Object argument; |
| 370 | /** The result of the request that is run on the main thread */ |
| 371 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 372 | // The subscriber id that this request applies to. Defaults to |
| 373 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 374 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 375 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 376 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 377 | public Phone phone; |
| 378 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 379 | public WorkSource workSource; |
| 380 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 381 | public MainThreadRequest(Object argument) { |
| 382 | this.argument = argument; |
| 383 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 384 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 385 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 386 | this.argument = argument; |
| 387 | if (phone != null) { |
| 388 | this.phone = phone; |
| 389 | } |
| 390 | this.workSource = workSource; |
| 391 | } |
| 392 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 393 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 394 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 395 | if (subId != null) { |
| 396 | this.subId = subId; |
| 397 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 398 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 399 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 402 | private static final class IncomingThirdPartyCallArgs { |
| 403 | public final ComponentName component; |
| 404 | public final String callId; |
| 405 | public final String callerDisplayName; |
| 406 | |
| 407 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 408 | String callerDisplayName) { |
| 409 | this.component = component; |
| 410 | this.callId = callId; |
| 411 | this.callerDisplayName = callerDisplayName; |
| 412 | } |
| 413 | } |
| 414 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 415 | /** |
| 416 | * A handler that processes messages on the main thread in the phone process. Since many |
| 417 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 418 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 419 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 420 | * on, which will be notified when the operation completes and will contain the result of the |
| 421 | * request. |
| 422 | * |
| 423 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 424 | * note that request.result must be set to something non-null for the calling thread to |
| 425 | * unblock. |
| 426 | */ |
| 427 | private final class MainThreadHandler extends Handler { |
| 428 | @Override |
| 429 | public void handleMessage(Message msg) { |
| 430 | MainThreadRequest request; |
| 431 | Message onCompleted; |
| 432 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 433 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 434 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 435 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 436 | |
| 437 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 438 | case CMD_HANDLE_USSD_REQUEST: { |
| 439 | request = (MainThreadRequest) msg.obj; |
| 440 | final Phone phone = getPhoneFromRequest(request); |
| 441 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 442 | String ussdRequest = ussdObject.first; |
| 443 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 444 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 445 | if (!isUssdApiAllowed(request.subId)) { |
| 446 | // Carrier does not support use of this API, return failure. |
| 447 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 448 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 449 | Bundle returnData = new Bundle(); |
| 450 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 451 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
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 | request.result = true; |
| 454 | notifyRequester(request); |
| 455 | return; |
| 456 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 457 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 458 | try { |
| 459 | request.result = phone != null |
| 460 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 461 | } catch (CallStateException cse) { |
| 462 | request.result = false; |
| 463 | } |
| 464 | // Wake up the requesting thread |
| 465 | notifyRequester(request); |
| 466 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 469 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 470 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 471 | final Phone phone = getPhoneFromRequest(request); |
| 472 | request.result = phone != null ? |
| 473 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 474 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 475 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 476 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 477 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 478 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 479 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 480 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 481 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 482 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 483 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 484 | if (uiccCard == null) { |
| 485 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 486 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 487 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 488 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 489 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 490 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 491 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 492 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 493 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 494 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 495 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 496 | break; |
| 497 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 498 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 499 | ar = (AsyncResult) msg.obj; |
| 500 | request = (MainThreadRequest) ar.userObj; |
| 501 | if (ar.exception == null && ar.result != null) { |
| 502 | request.result = ar.result; |
| 503 | } else { |
| 504 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 505 | if (ar.result == null) { |
| 506 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 507 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 508 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 509 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 510 | } else { |
| 511 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 512 | } |
| 513 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 514 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 515 | break; |
| 516 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 517 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 518 | request = (MainThreadRequest) msg.obj; |
| 519 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 520 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 521 | if (uiccCard == null) { |
| 522 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 523 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 524 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 525 | } else { |
| 526 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 527 | request); |
| 528 | uiccCard.iccTransmitApduBasicChannel( |
| 529 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 530 | iccArgument.p3, iccArgument.data, onCompleted); |
| 531 | } |
| 532 | break; |
| 533 | |
| 534 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 535 | ar = (AsyncResult) msg.obj; |
| 536 | request = (MainThreadRequest) ar.userObj; |
| 537 | if (ar.exception == null && ar.result != null) { |
| 538 | request.result = ar.result; |
| 539 | } else { |
| 540 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 541 | if (ar.result == null) { |
| 542 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 543 | } else if (ar.exception instanceof CommandException) { |
| 544 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 545 | ar.exception); |
| 546 | } else { |
| 547 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 548 | } |
| 549 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 550 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 551 | break; |
| 552 | |
| 553 | case CMD_EXCHANGE_SIM_IO: |
| 554 | request = (MainThreadRequest) msg.obj; |
| 555 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 556 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 557 | if (uiccCard == null) { |
| 558 | loge("iccExchangeSimIO: No UICC"); |
| 559 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 560 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 561 | } else { |
| 562 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 563 | request); |
| 564 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 565 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 566 | iccArgument.data, onCompleted); |
| 567 | } |
| 568 | break; |
| 569 | |
| 570 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 571 | ar = (AsyncResult) msg.obj; |
| 572 | request = (MainThreadRequest) ar.userObj; |
| 573 | if (ar.exception == null && ar.result != null) { |
| 574 | request.result = ar.result; |
| 575 | } else { |
| 576 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 577 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 578 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 579 | break; |
| 580 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 581 | case CMD_SEND_ENVELOPE: |
| 582 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 583 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 584 | if (uiccCard == null) { |
| 585 | loge("sendEnvelopeWithStatus: No UICC"); |
| 586 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 587 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 588 | } else { |
| 589 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 590 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 591 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 592 | break; |
| 593 | |
| 594 | case EVENT_SEND_ENVELOPE_DONE: |
| 595 | ar = (AsyncResult) msg.obj; |
| 596 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 597 | if (ar.exception == null && ar.result != null) { |
| 598 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 599 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 600 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 601 | if (ar.result == null) { |
| 602 | loge("sendEnvelopeWithStatus: Empty response"); |
| 603 | } else if (ar.exception instanceof CommandException) { |
| 604 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 605 | ar.exception); |
| 606 | } else { |
| 607 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 608 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 609 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 610 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 611 | break; |
| 612 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 613 | case CMD_OPEN_CHANNEL: |
| 614 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 615 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 616 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 617 | if (uiccCard == null) { |
| 618 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 619 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 620 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 621 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 622 | } else { |
| 623 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 624 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 625 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 626 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 627 | break; |
| 628 | |
| 629 | case EVENT_OPEN_CHANNEL_DONE: |
| 630 | ar = (AsyncResult) msg.obj; |
| 631 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 632 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 633 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 634 | int[] result = (int[]) ar.result; |
| 635 | int channelId = result[0]; |
| 636 | byte[] selectResponse = null; |
| 637 | if (result.length > 1) { |
| 638 | selectResponse = new byte[result.length - 1]; |
| 639 | for (int i = 1; i < result.length; ++i) { |
| 640 | selectResponse[i - 1] = (byte) result[i]; |
| 641 | } |
| 642 | } |
| 643 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 644 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 645 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 646 | if (ar.result == null) { |
| 647 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 648 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 649 | if (ar.exception != null) { |
| 650 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 651 | } |
| 652 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 653 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 654 | if (ar.exception instanceof CommandException) { |
| 655 | CommandException.Error error = |
| 656 | ((CommandException) (ar.exception)).getCommandError(); |
| 657 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 658 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 659 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 660 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 661 | } |
| 662 | } |
| 663 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 664 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 665 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 666 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 667 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 668 | break; |
| 669 | |
| 670 | case CMD_CLOSE_CHANNEL: |
| 671 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 672 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 673 | if (uiccCard == null) { |
| 674 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 675 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 676 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 677 | } else { |
| 678 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 679 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 680 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 681 | break; |
| 682 | |
| 683 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 684 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 685 | break; |
| 686 | |
| 687 | case CMD_NV_READ_ITEM: |
| 688 | request = (MainThreadRequest) msg.obj; |
| 689 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 690 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 691 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 692 | break; |
| 693 | |
| 694 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 695 | ar = (AsyncResult) msg.obj; |
| 696 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 697 | if (ar.exception == null && ar.result != null) { |
| 698 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 699 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 700 | request.result = ""; |
| 701 | if (ar.result == null) { |
| 702 | loge("nvReadItem: Empty response"); |
| 703 | } else if (ar.exception instanceof CommandException) { |
| 704 | loge("nvReadItem: CommandException: " + |
| 705 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 706 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 707 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 708 | } |
| 709 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 710 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 711 | break; |
| 712 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 713 | case CMD_NV_WRITE_ITEM: |
| 714 | request = (MainThreadRequest) msg.obj; |
| 715 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 716 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 717 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 718 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 719 | break; |
| 720 | |
| 721 | case EVENT_NV_WRITE_ITEM_DONE: |
| 722 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 723 | break; |
| 724 | |
| 725 | case CMD_NV_WRITE_CDMA_PRL: |
| 726 | request = (MainThreadRequest) msg.obj; |
| 727 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 728 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 729 | break; |
| 730 | |
| 731 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 732 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 733 | break; |
| 734 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 735 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 736 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 737 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 738 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 739 | break; |
| 740 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 741 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 742 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 743 | break; |
| 744 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 745 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 746 | request = (MainThreadRequest) msg.obj; |
| 747 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 748 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 749 | break; |
| 750 | |
| 751 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 752 | ar = (AsyncResult) msg.obj; |
| 753 | request = (MainThreadRequest) ar.userObj; |
| 754 | if (ar.exception == null && ar.result != null) { |
| 755 | request.result = ar.result; // Integer |
| 756 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 757 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 758 | if (ar.result == null) { |
| 759 | loge("getPreferredNetworkType: Empty response"); |
| 760 | } else if (ar.exception instanceof CommandException) { |
| 761 | loge("getPreferredNetworkType: CommandException: " + |
| 762 | ar.exception); |
| 763 | } else { |
| 764 | loge("getPreferredNetworkType: Unknown exception"); |
| 765 | } |
| 766 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 767 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 768 | break; |
| 769 | |
| 770 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 771 | request = (MainThreadRequest) msg.obj; |
| 772 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 773 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 774 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 775 | break; |
| 776 | |
| 777 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 778 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 779 | break; |
| 780 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 781 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 782 | request = (MainThreadRequest)msg.obj; |
| 783 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 784 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 785 | break; |
| 786 | |
| 787 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 788 | ar = (AsyncResult)msg.obj; |
| 789 | request = (MainThreadRequest)ar.userObj; |
| 790 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 791 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 792 | break; |
| 793 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 794 | case CMD_SET_VOICEMAIL_NUMBER: |
| 795 | request = (MainThreadRequest) msg.obj; |
| 796 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 797 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 798 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 799 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 800 | break; |
| 801 | |
| 802 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 803 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 804 | break; |
| 805 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 806 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 807 | request = (MainThreadRequest) msg.obj; |
| 808 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 809 | request); |
| 810 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 811 | break; |
| 812 | |
| 813 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 814 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 815 | break; |
| 816 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 817 | case CMD_PERFORM_NETWORK_SCAN: |
| 818 | request = (MainThreadRequest) msg.obj; |
| 819 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 820 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 821 | break; |
| 822 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 823 | case CMD_GET_CALL_FORWARDING: |
| 824 | request = (MainThreadRequest) msg.obj; |
| 825 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
| 826 | int callForwardingReason = (Integer) request.argument; |
| 827 | getPhoneFromRequest(request).getCallForwardingOption( |
| 828 | callForwardingReason, onCompleted); |
| 829 | break; |
| 830 | |
| 831 | case EVENT_GET_CALL_FORWARDING_DONE: |
| 832 | ar = (AsyncResult) msg.obj; |
| 833 | request = (MainThreadRequest) ar.userObj; |
| 834 | CallForwardingInfo callForwardingInfo = null; |
| 835 | if (ar.exception == null && ar.result != null) { |
| 836 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 837 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 838 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 839 | // any service for voice call. |
| 840 | if ((callForwardInfo.serviceClass |
| 841 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
| 842 | callForwardingInfo = new CallForwardingInfo( |
| 843 | callForwardInfo.serviceClass, callForwardInfo.reason, |
| 844 | callForwardInfo.number, |
| 845 | callForwardInfo.timeSeconds); |
| 846 | break; |
| 847 | } |
| 848 | } |
| 849 | // Didn't find a call forward info for voice call. |
| 850 | if (callForwardingInfo == null) { |
| 851 | callForwardingInfo = new CallForwardingInfo( |
| 852 | CallForwardingInfo.STATUS_UNKNOWN_ERROR, |
| 853 | 0 /* reason */, null /* number */, 0 /* timeout */); |
| 854 | } |
| 855 | } else { |
| 856 | if (ar.result == null) { |
| 857 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 858 | } |
| 859 | if (ar.exception != null) { |
| 860 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 861 | } |
| 862 | int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR; |
| 863 | if (ar.exception instanceof CommandException) { |
| 864 | CommandException.Error error = |
| 865 | ((CommandException) (ar.exception)).getCommandError(); |
| 866 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 867 | errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE; |
| 868 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 869 | errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED; |
| 870 | } |
| 871 | } |
| 872 | callForwardingInfo = new CallForwardingInfo( |
| 873 | errorCode, 0 /* reason */, null /* number */, 0 /* timeout */); |
| 874 | } |
| 875 | request.result = callForwardingInfo; |
| 876 | notifyRequester(request); |
| 877 | break; |
| 878 | |
| 879 | case CMD_SET_CALL_FORWARDING: |
| 880 | request = (MainThreadRequest) msg.obj; |
| 881 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
| 882 | CallForwardingInfo callForwardingInfoToSet = |
| 883 | (CallForwardingInfo) request.argument; |
| 884 | getPhoneFromRequest(request).setCallForwardingOption( |
| 885 | callForwardingInfoToSet.getStatus(), |
| 886 | callForwardingInfoToSet.getReason(), |
| 887 | callForwardingInfoToSet.getNumber(), |
| 888 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 889 | break; |
| 890 | |
| 891 | case EVENT_SET_CALL_FORWARDING_DONE: |
| 892 | ar = (AsyncResult) msg.obj; |
| 893 | request = (MainThreadRequest) ar.userObj; |
| 894 | if (ar.exception == null) { |
| 895 | request.result = true; |
| 896 | } else { |
| 897 | request.result = false; |
| 898 | loge("setCallForwarding exception: " + ar.exception); |
| 899 | } |
| 900 | notifyRequester(request); |
| 901 | break; |
| 902 | |
| 903 | case CMD_GET_CALL_WAITING: |
| 904 | request = (MainThreadRequest) msg.obj; |
| 905 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 906 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 907 | break; |
| 908 | |
| 909 | case EVENT_GET_CALL_WAITING_DONE: |
| 910 | ar = (AsyncResult) msg.obj; |
| 911 | request = (MainThreadRequest) ar.userObj; |
| 912 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 913 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 914 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 915 | // Service Class is a bit mask per 3gpp 27.007. |
| 916 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 917 | if (callForwardResults.length > 1 |
| 918 | && ((callForwardResults[1] |
| 919 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
| 920 | callForwardingStatus = callForwardResults[0] == 0 |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 921 | ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE |
| 922 | : TelephonyManager.CALL_WAITING_STATUS_ACTIVE; |
| 923 | } else { |
| 924 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE; |
| 925 | } |
| 926 | } else { |
| 927 | if (ar.result == null) { |
| 928 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 929 | } |
| 930 | if (ar.exception != null) { |
| 931 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 932 | } |
| 933 | if (ar.exception instanceof CommandException) { |
| 934 | CommandException.Error error = |
| 935 | ((CommandException) (ar.exception)).getCommandError(); |
| 936 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 937 | callForwardingStatus = |
| 938 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 939 | } |
| 940 | } |
| 941 | } |
| 942 | request.result = callForwardingStatus; |
| 943 | notifyRequester(request); |
| 944 | break; |
| 945 | |
| 946 | case CMD_SET_CALL_WAITING: |
| 947 | request = (MainThreadRequest) msg.obj; |
| 948 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
| 949 | boolean isEnable = (Boolean) request.argument; |
| 950 | getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted); |
| 951 | break; |
| 952 | |
| 953 | case EVENT_SET_CALL_WAITING_DONE: |
| 954 | ar = (AsyncResult) msg.obj; |
| 955 | request = (MainThreadRequest) ar.userObj; |
| 956 | if (ar.exception == null) { |
| 957 | request.result = true; |
| 958 | } else { |
| 959 | request.result = false; |
| 960 | loge("setCallWaiting exception: " + ar.exception); |
| 961 | } |
| 962 | notifyRequester(request); |
| 963 | break; |
| 964 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 965 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 966 | ar = (AsyncResult) msg.obj; |
| 967 | request = (MainThreadRequest) ar.userObj; |
| 968 | CellNetworkScanResult cellScanResult; |
| 969 | if (ar.exception == null && ar.result != null) { |
| 970 | cellScanResult = new CellNetworkScanResult( |
| 971 | CellNetworkScanResult.STATUS_SUCCESS, |
| 972 | (List<OperatorInfo>) ar.result); |
| 973 | } else { |
| 974 | if (ar.result == null) { |
| 975 | loge("getCellNetworkScanResults: Empty response"); |
| 976 | } |
| 977 | if (ar.exception != null) { |
| 978 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 979 | } |
| 980 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 981 | if (ar.exception instanceof CommandException) { |
| 982 | CommandException.Error error = |
| 983 | ((CommandException) (ar.exception)).getCommandError(); |
| 984 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 985 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 986 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 987 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 988 | } |
| 989 | } |
| 990 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 991 | } |
| 992 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 993 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 994 | break; |
| 995 | |
| 996 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 997 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 998 | ManualNetworkSelectionArgument selArg = |
| 999 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1000 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1001 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1002 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1003 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1004 | break; |
| 1005 | |
| 1006 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1007 | ar = (AsyncResult) msg.obj; |
| 1008 | request = (MainThreadRequest) ar.userObj; |
| 1009 | if (ar.exception == null) { |
| 1010 | request.result = true; |
| 1011 | } else { |
| 1012 | request.result = false; |
| 1013 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1014 | } |
| 1015 | notifyRequester(request); |
| 1016 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1017 | break; |
| 1018 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1019 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1020 | request = (MainThreadRequest) msg.obj; |
| 1021 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1022 | if (defaultPhone != null) { |
| 1023 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1024 | } else { |
| 1025 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1026 | Bundle bundle = new Bundle(); |
| 1027 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1028 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1029 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1030 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1031 | break; |
| 1032 | |
| 1033 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1034 | ar = (AsyncResult) msg.obj; |
| 1035 | request = (MainThreadRequest) ar.userObj; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1036 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1037 | |
| 1038 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1039 | if (ar.exception == null && ar.result != null) { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1040 | // Update the last modem activity info and the result of the request. |
| 1041 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1042 | if (isModemActivityInfoValid(info)) { |
| 1043 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1044 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1045 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1046 | .getTransmitTimeMillis(); |
| 1047 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1048 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1049 | } |
| 1050 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1051 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1052 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1053 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1054 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1055 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1056 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1057 | info.getReceiveTimeMillis() |
| 1058 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1059 | } |
| 1060 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1061 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1062 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1063 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1064 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1065 | } else { |
| 1066 | if (ar.result == null) { |
| 1067 | loge("queryModemActivityInfo: Empty response"); |
| 1068 | } else if (ar.exception instanceof CommandException) { |
| 1069 | loge("queryModemActivityInfo: CommandException: " + |
| 1070 | ar.exception); |
| 1071 | } else { |
| 1072 | loge("queryModemActivityInfo: Unknown exception"); |
| 1073 | } |
| 1074 | } |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1075 | Bundle bundle = new Bundle(); |
| 1076 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1077 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1078 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1079 | break; |
| 1080 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1081 | case CMD_SET_ALLOWED_CARRIERS: |
| 1082 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1083 | CarrierRestrictionRules argument = |
| 1084 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1085 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1086 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1087 | break; |
| 1088 | |
| 1089 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1090 | ar = (AsyncResult) msg.obj; |
| 1091 | request = (MainThreadRequest) ar.userObj; |
| 1092 | if (ar.exception == null && ar.result != null) { |
| 1093 | request.result = ar.result; |
| 1094 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1095 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1096 | if (ar.exception instanceof CommandException) { |
| 1097 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1098 | CommandException.Error error = |
| 1099 | ((CommandException) (ar.exception)).getCommandError(); |
| 1100 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1101 | request.result = |
| 1102 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1103 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1104 | } else { |
| 1105 | loge("setAllowedCarriers: Unknown exception"); |
| 1106 | } |
| 1107 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1108 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1109 | break; |
| 1110 | |
| 1111 | case CMD_GET_ALLOWED_CARRIERS: |
| 1112 | request = (MainThreadRequest) msg.obj; |
| 1113 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1114 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1115 | break; |
| 1116 | |
| 1117 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1118 | ar = (AsyncResult) msg.obj; |
| 1119 | request = (MainThreadRequest) ar.userObj; |
| 1120 | if (ar.exception == null && ar.result != null) { |
| 1121 | request.result = ar.result; |
| 1122 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1123 | request.result = new IllegalStateException( |
| 1124 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1125 | if (ar.result == null) { |
| 1126 | loge("getAllowedCarriers: Empty response"); |
| 1127 | } else if (ar.exception instanceof CommandException) { |
| 1128 | loge("getAllowedCarriers: CommandException: " + |
| 1129 | ar.exception); |
| 1130 | } else { |
| 1131 | loge("getAllowedCarriers: Unknown exception"); |
| 1132 | } |
| 1133 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1134 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1135 | break; |
| 1136 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1137 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1138 | ar = (AsyncResult) msg.obj; |
| 1139 | request = (MainThreadRequest) ar.userObj; |
| 1140 | if (ar.exception == null && ar.result != null) { |
| 1141 | request.result = ar.result; |
| 1142 | } else { |
| 1143 | request.result = new IllegalArgumentException( |
| 1144 | "Failed to retrieve Forbidden Plmns"); |
| 1145 | if (ar.result == null) { |
| 1146 | loge("getForbiddenPlmns: Empty response"); |
| 1147 | } else { |
| 1148 | loge("getForbiddenPlmns: Unknown exception"); |
| 1149 | } |
| 1150 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1151 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1152 | break; |
| 1153 | |
| 1154 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1155 | request = (MainThreadRequest) msg.obj; |
| 1156 | uiccCard = getUiccCardFromRequest(request); |
| 1157 | if (uiccCard == null) { |
| 1158 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1159 | request.result = new IllegalArgumentException( |
| 1160 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1161 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1162 | break; |
| 1163 | } |
| 1164 | Integer appType = (Integer) request.argument; |
| 1165 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1166 | if (uiccApp == null) { |
| 1167 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1168 | + appType); |
| 1169 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1170 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1171 | break; |
| 1172 | } else { |
| 1173 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1174 | + " specified type -- " + appType); |
| 1175 | } |
| 1176 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1177 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1178 | onCompleted); |
| 1179 | break; |
| 1180 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1181 | case CMD_SWITCH_SLOTS: |
| 1182 | request = (MainThreadRequest) msg.obj; |
| 1183 | int[] physicalSlots = (int[]) request.argument; |
| 1184 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1185 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1186 | break; |
| 1187 | |
| 1188 | case EVENT_SWITCH_SLOTS_DONE: |
| 1189 | ar = (AsyncResult) msg.obj; |
| 1190 | request = (MainThreadRequest) ar.userObj; |
| 1191 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1192 | notifyRequester(request); |
| 1193 | break; |
| 1194 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1195 | request = (MainThreadRequest) msg.obj; |
| 1196 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1197 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1198 | break; |
| 1199 | |
| 1200 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1201 | ar = (AsyncResult) msg.obj; |
| 1202 | request = (MainThreadRequest) ar.userObj; |
| 1203 | if (ar.exception != null) { |
| 1204 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1205 | } else { |
| 1206 | int mode = ((int[]) ar.result)[0]; |
| 1207 | if (mode == 0) { |
| 1208 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1209 | } else { |
| 1210 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1211 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1212 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1213 | notifyRequester(request); |
| 1214 | break; |
| 1215 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1216 | request = (MainThreadRequest) msg.obj; |
| 1217 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1218 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1219 | break; |
| 1220 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1221 | ar = (AsyncResult) msg.obj; |
| 1222 | request = (MainThreadRequest) ar.userObj; |
| 1223 | if (ar.exception != null) { |
| 1224 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1225 | } else { |
| 1226 | request.result = ((int[]) ar.result)[0]; |
| 1227 | } |
| 1228 | notifyRequester(request); |
| 1229 | break; |
| 1230 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1231 | request = (MainThreadRequest) msg.obj; |
| 1232 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1233 | int mode = (int) request.argument; |
| 1234 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1235 | break; |
| 1236 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1237 | ar = (AsyncResult) msg.obj; |
| 1238 | request = (MainThreadRequest) ar.userObj; |
| 1239 | request.result = ar.exception == null; |
| 1240 | notifyRequester(request); |
| 1241 | break; |
| 1242 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1243 | request = (MainThreadRequest) msg.obj; |
| 1244 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1245 | int subscriptionMode = (int) request.argument; |
| 1246 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1247 | break; |
| 1248 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1249 | ar = (AsyncResult) msg.obj; |
| 1250 | request = (MainThreadRequest) ar.userObj; |
| 1251 | request.result = ar.exception == null; |
| 1252 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1253 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1254 | case CMD_GET_ALL_CELL_INFO: |
| 1255 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1256 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1257 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1258 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1259 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1260 | ar = (AsyncResult) msg.obj; |
| 1261 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1262 | // If a timeout occurs, the response will be null |
| 1263 | request.result = (ar.exception == null && ar.result != null) |
| 1264 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1265 | synchronized (request) { |
| 1266 | request.notifyAll(); |
| 1267 | } |
| 1268 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1269 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1270 | request = (MainThreadRequest) msg.obj; |
| 1271 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1272 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1273 | break; |
| 1274 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1275 | ar = (AsyncResult) msg.obj; |
| 1276 | request = (MainThreadRequest) ar.userObj; |
| 1277 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1278 | try { |
| 1279 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1280 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1281 | cb.onError( |
| 1282 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1283 | ar.exception.getClass().getName(), |
| 1284 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1285 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1286 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1287 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1288 | } else { |
| 1289 | // use the result as returned |
| 1290 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1291 | } |
| 1292 | } catch (RemoteException re) { |
| 1293 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1294 | } |
| 1295 | break; |
| 1296 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1297 | request = (MainThreadRequest) msg.obj; |
| 1298 | WorkSource ws = (WorkSource) request.argument; |
| 1299 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1300 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1301 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1302 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1303 | ar = (AsyncResult) msg.obj; |
| 1304 | request = (MainThreadRequest) ar.userObj; |
| 1305 | if (ar.exception == null) { |
| 1306 | request.result = ar.result; |
| 1307 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1308 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1309 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1310 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | synchronized (request) { |
| 1314 | request.notifyAll(); |
| 1315 | } |
| 1316 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1317 | case CMD_MODEM_REBOOT: |
| 1318 | request = (MainThreadRequest) msg.obj; |
| 1319 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1320 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1321 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1322 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1323 | handleNullReturnEvent(msg, "rebootModem"); |
| 1324 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1325 | case CMD_REQUEST_ENABLE_MODEM: |
| 1326 | request = (MainThreadRequest) msg.obj; |
| 1327 | boolean enable = (boolean) request.argument; |
| 1328 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1329 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1330 | PhoneConfigurationManager.getInstance() |
| 1331 | .enablePhone(request.phone, enable, onCompleted); |
| 1332 | break; |
| 1333 | case EVENT_ENABLE_MODEM_DONE: |
| 1334 | ar = (AsyncResult) msg.obj; |
| 1335 | request = (MainThreadRequest) ar.userObj; |
| 1336 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1337 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1338 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1339 | if ((boolean) request.result) { |
| 1340 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1341 | updateModemStateMetrics(); |
| 1342 | } else { |
| 1343 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1344 | + ar.exception); |
| 1345 | } |
| 1346 | notifyRequester(request); |
| 1347 | break; |
| 1348 | case CMD_GET_MODEM_STATUS: |
| 1349 | request = (MainThreadRequest) msg.obj; |
| 1350 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1351 | PhoneConfigurationManager.getInstance() |
| 1352 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1353 | break; |
| 1354 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1355 | ar = (AsyncResult) msg.obj; |
| 1356 | request = (MainThreadRequest) ar.userObj; |
| 1357 | int id = request.phone.getPhoneId(); |
| 1358 | if (ar.exception == null && ar.result != null) { |
| 1359 | request.result = ar.result; |
| 1360 | //update the cache as modem status has changed |
| 1361 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1362 | (boolean) request.result); |
| 1363 | } else { |
| 1364 | // Return true if modem status cannot be retrieved. For most cases, |
| 1365 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1366 | // and disable modem are not supported. Modem is always on. |
| 1367 | // TODO: this should be fixed in R to support a third |
| 1368 | // status UNKNOWN b/131631629 |
| 1369 | request.result = true; |
| 1370 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1371 | + ar.exception); |
| 1372 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1373 | notifyRequester(request); |
| 1374 | break; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1375 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1376 | request = (MainThreadRequest) msg.obj; |
| 1377 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1378 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1379 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1380 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1381 | break; |
| 1382 | } |
| 1383 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1384 | ar = (AsyncResult) msg.obj; |
| 1385 | request = (MainThreadRequest) ar.userObj; |
| 1386 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1387 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1388 | args.second.accept(ar.exception == null); |
| 1389 | notifyRequester(request); |
| 1390 | break; |
| 1391 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1392 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1393 | ar = (AsyncResult) msg.obj; |
| 1394 | request = (MainThreadRequest) ar.userObj; |
| 1395 | if (ar.exception == null && ar.result != null) { |
| 1396 | request.result = ar.result; |
| 1397 | } else { |
| 1398 | request.result = -1; |
| 1399 | loge("Failed to set Forbidden Plmns"); |
| 1400 | if (ar.result == null) { |
| 1401 | loge("setForbidenPlmns: Empty response"); |
| 1402 | } else if (ar.exception != null) { |
| 1403 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1404 | request.result = -1; |
| 1405 | } else { |
| 1406 | loge("setForbiddenPlmns: Unknown exception"); |
| 1407 | } |
| 1408 | } |
| 1409 | notifyRequester(request); |
| 1410 | break; |
| 1411 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1412 | request = (MainThreadRequest) msg.obj; |
| 1413 | uiccCard = getUiccCardFromRequest(request); |
| 1414 | if (uiccCard == null) { |
| 1415 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1416 | request.result = -1; |
| 1417 | notifyRequester(request); |
| 1418 | break; |
| 1419 | } |
| 1420 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1421 | (Pair<Integer, List<String>>) request.argument; |
| 1422 | appType = setFplmnsArgs.first; |
| 1423 | List<String> fplmns = setFplmnsArgs.second; |
| 1424 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1425 | if (uiccApp == null) { |
| 1426 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1427 | request.result = -1; |
| 1428 | loge("Failed to get UICC App"); |
| 1429 | notifyRequester(request); |
| 1430 | } else { |
| 1431 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1432 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1433 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1434 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1435 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1436 | case CMD_ERASE_MODEM_CONFIG: |
| 1437 | request = (MainThreadRequest) msg.obj; |
| 1438 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1439 | defaultPhone.eraseModemConfig(onCompleted); |
| 1440 | break; |
| 1441 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1442 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1443 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1444 | |
| 1445 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1446 | request = (MainThreadRequest) msg.obj; |
| 1447 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1448 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1449 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1450 | changed.first, changed.second, onCompleted); |
| 1451 | break; |
| 1452 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1453 | ar = (AsyncResult) msg.obj; |
| 1454 | request = (MainThreadRequest) ar.userObj; |
| 1455 | if (ar.exception == null) { |
| 1456 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1457 | } else { |
| 1458 | request.result = msg.arg1; |
| 1459 | } |
| 1460 | notifyRequester(request); |
| 1461 | break; |
| 1462 | |
| 1463 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1464 | request = (MainThreadRequest) msg.obj; |
| 1465 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1466 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1467 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1468 | enabled.first, enabled.second, onCompleted); |
| 1469 | break; |
| 1470 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1471 | ar = (AsyncResult) msg.obj; |
| 1472 | request = (MainThreadRequest) ar.userObj; |
| 1473 | if (ar.exception == null) { |
| 1474 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1475 | } else { |
| 1476 | request.result = msg.arg1; |
| 1477 | } |
| 1478 | notifyRequester(request); |
| 1479 | break; |
| 1480 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1481 | default: |
| 1482 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1483 | break; |
| 1484 | } |
| 1485 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1486 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1487 | private void notifyRequester(MainThreadRequest request) { |
| 1488 | synchronized (request) { |
| 1489 | request.notifyAll(); |
| 1490 | } |
| 1491 | } |
| 1492 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1493 | private void handleNullReturnEvent(Message msg, String command) { |
| 1494 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1495 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1496 | if (ar.exception == null) { |
| 1497 | request.result = true; |
| 1498 | } else { |
| 1499 | request.result = false; |
| 1500 | if (ar.exception instanceof CommandException) { |
| 1501 | loge(command + ": CommandException: " + ar.exception); |
| 1502 | } else { |
| 1503 | loge(command + ": Unknown exception"); |
| 1504 | } |
| 1505 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1506 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1507 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | /** |
| 1511 | * Posts the specified command to be executed on the main thread, |
| 1512 | * waits for the request to complete, and returns the result. |
| 1513 | * @see #sendRequestAsync |
| 1514 | */ |
| 1515 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1516 | return sendRequest( |
| 1517 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | /** |
| 1521 | * Posts the specified command to be executed on the main thread, |
| 1522 | * waits for the request to complete, and returns the result. |
| 1523 | * @see #sendRequestAsync |
| 1524 | */ |
| 1525 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1526 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1527 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | /** |
| 1531 | * Posts the specified command to be executed on the main thread, |
| 1532 | * waits for the request to complete, and returns the result. |
| 1533 | * @see #sendRequestAsync |
| 1534 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1535 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1536 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | /** |
| 1540 | * Posts the specified command to be executed on the main thread, |
| 1541 | * waits for the request to complete, and returns the result. |
| 1542 | * @see #sendRequestAsync |
| 1543 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1544 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1545 | return sendRequest(command, argument, subId, null, workSource); |
| 1546 | } |
| 1547 | |
| 1548 | /** |
| 1549 | * Posts the specified command to be executed on the main thread, |
| 1550 | * waits for the request to complete, and returns the result. |
| 1551 | * @see #sendRequestAsync |
| 1552 | */ |
| 1553 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1554 | return sendRequest( |
| 1555 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1556 | } |
| 1557 | |
| 1558 | /** |
| 1559 | * Posts the specified command to be executed on the main thread, |
| 1560 | * waits for the request to complete, and returns the result. |
| 1561 | * @see #sendRequestAsync |
| 1562 | */ |
| 1563 | private Object sendRequest( |
| 1564 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1565 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1566 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1567 | } |
| 1568 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1569 | MainThreadRequest request = null; |
| 1570 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1571 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1572 | } else if (phone != null) { |
| 1573 | request = new MainThreadRequest(argument, phone, workSource); |
| 1574 | } else { |
| 1575 | request = new MainThreadRequest(argument, subId, workSource); |
| 1576 | } |
| 1577 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1578 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1579 | msg.sendToTarget(); |
| 1580 | |
| 1581 | // Wait for the request to complete |
| 1582 | synchronized (request) { |
| 1583 | while (request.result == null) { |
| 1584 | try { |
| 1585 | request.wait(); |
| 1586 | } catch (InterruptedException e) { |
| 1587 | // Do nothing, go back and wait until the request is complete |
| 1588 | } |
| 1589 | } |
| 1590 | } |
| 1591 | return request.result; |
| 1592 | } |
| 1593 | |
| 1594 | /** |
| 1595 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1596 | * Posts the specified command to be executed on the main thread, and |
| 1597 | * returns immediately. |
| 1598 | * @see #sendRequest |
| 1599 | */ |
| 1600 | private void sendRequestAsync(int command) { |
| 1601 | mMainThreadHandler.sendEmptyMessage(command); |
| 1602 | } |
| 1603 | |
| 1604 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1605 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1606 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1607 | */ |
| 1608 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1609 | sendRequestAsync(command, argument, null, null); |
| 1610 | } |
| 1611 | |
| 1612 | /** |
| 1613 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1614 | * @see {@link #sendRequest(int,Object)} |
| 1615 | */ |
| 1616 | private void sendRequestAsync( |
| 1617 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1618 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1619 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1620 | msg.sendToTarget(); |
| 1621 | } |
| 1622 | |
| 1623 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1624 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1625 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1626 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1627 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1628 | synchronized (PhoneInterfaceManager.class) { |
| 1629 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1630 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1631 | } else { |
| 1632 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1633 | } |
| 1634 | return sInstance; |
| 1635 | } |
| 1636 | } |
| 1637 | |
| 1638 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1639 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1640 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1641 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1642 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1643 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1644 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1645 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1646 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1647 | mTelephonySharedPreferences = |
| 1648 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1649 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1650 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1651 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1652 | publish(); |
| 1653 | } |
| 1654 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1655 | private Phone getDefaultPhone() { |
| 1656 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1657 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1658 | } |
| 1659 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1660 | private void publish() { |
| 1661 | if (DBG) log("publish: " + this); |
| 1662 | |
| 1663 | ServiceManager.addService("phone", this); |
| 1664 | } |
| 1665 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1666 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1667 | if (request.phone != null) { |
| 1668 | return request.phone; |
| 1669 | } else { |
| 1670 | return getPhoneFromSubId(request.subId); |
| 1671 | } |
| 1672 | } |
| 1673 | |
| 1674 | private Phone getPhoneFromSubId(int subId) { |
| 1675 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1676 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1677 | } |
| 1678 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1679 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1680 | Phone phone = getPhoneFromRequest(request); |
| 1681 | return phone == null ? null : |
| 1682 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1683 | } |
| 1684 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1685 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1686 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1687 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1688 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1689 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1690 | private void sendEraseModemConfig(Phone phone) { |
| 1691 | if (phone != null) { |
| 1692 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1693 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1694 | final long identity = Binder.clearCallingIdentity(); |
| 1695 | try { |
| 1696 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1697 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1698 | } finally { |
| 1699 | Binder.restoreCallingIdentity(identity); |
| 1700 | } |
| 1701 | } |
| 1702 | } |
| 1703 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1704 | private boolean isImsAvailableOnDevice() { |
| 1705 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1706 | if (pm == null) { |
| 1707 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1708 | // so do not throw error and allow. |
| 1709 | return true; |
| 1710 | } |
| 1711 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1712 | } |
| 1713 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1714 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1715 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1716 | } |
| 1717 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1718 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1719 | if (DBG) log("dial: " + number); |
| 1720 | // No permission check needed here: This is just a wrapper around the |
| 1721 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1722 | // the UI before it does anything. |
| 1723 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1724 | final long identity = Binder.clearCallingIdentity(); |
| 1725 | try { |
| 1726 | String url = createTelUrl(number); |
| 1727 | if (url == null) { |
| 1728 | return; |
| 1729 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1730 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1731 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1732 | PhoneConstants.State state = mCM.getState(subId); |
| 1733 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1734 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1735 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1736 | mApp.startActivity(intent); |
| 1737 | } |
| 1738 | } finally { |
| 1739 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1740 | } |
| 1741 | } |
| 1742 | |
| 1743 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1744 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1745 | } |
| 1746 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1747 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1748 | if (DBG) log("call: " + number); |
| 1749 | |
| 1750 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1751 | // need to do a permission check since we're calling startActivity() |
| 1752 | // from the context of the phone app. |
| 1753 | enforceCallPermission(); |
| 1754 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1755 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1756 | != AppOpsManager.MODE_ALLOWED) { |
| 1757 | return; |
| 1758 | } |
| 1759 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1760 | final long identity = Binder.clearCallingIdentity(); |
| 1761 | try { |
| 1762 | String url = createTelUrl(number); |
| 1763 | if (url == null) { |
| 1764 | return; |
| 1765 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1766 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1767 | boolean isValid = false; |
| 1768 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1769 | if (slist != null) { |
| 1770 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1771 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1772 | isValid = true; |
| 1773 | break; |
| 1774 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1775 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1776 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1777 | if (!isValid) { |
| 1778 | return; |
| 1779 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1780 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1781 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1782 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1783 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1784 | mApp.startActivity(intent); |
| 1785 | } finally { |
| 1786 | Binder.restoreCallingIdentity(identity); |
| 1787 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1788 | } |
| 1789 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1790 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1791 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1792 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1793 | } |
| 1794 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1795 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1796 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1797 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1798 | } |
| 1799 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1800 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1801 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1802 | |
| 1803 | final long identity = Binder.clearCallingIdentity(); |
| 1804 | try { |
| 1805 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1806 | checkSimPin.start(); |
| 1807 | return checkSimPin.unlockSim(null, pin); |
| 1808 | } finally { |
| 1809 | Binder.restoreCallingIdentity(identity); |
| 1810 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1813 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1814 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1815 | |
| 1816 | final long identity = Binder.clearCallingIdentity(); |
| 1817 | try { |
| 1818 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1819 | checkSimPuk.start(); |
| 1820 | return checkSimPuk.unlockSim(puk, pin); |
| 1821 | } finally { |
| 1822 | Binder.restoreCallingIdentity(identity); |
| 1823 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1827 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1828 | * a synchronous one. |
| 1829 | */ |
| 1830 | private static class UnlockSim extends Thread { |
| 1831 | |
| 1832 | private final IccCard mSimCard; |
| 1833 | |
| 1834 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1835 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1836 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1837 | |
| 1838 | // For replies from SimCard interface |
| 1839 | private Handler mHandler; |
| 1840 | |
| 1841 | // For async handler to identify request type |
| 1842 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1843 | |
| 1844 | public UnlockSim(IccCard simCard) { |
| 1845 | mSimCard = simCard; |
| 1846 | } |
| 1847 | |
| 1848 | @Override |
| 1849 | public void run() { |
| 1850 | Looper.prepare(); |
| 1851 | synchronized (UnlockSim.this) { |
| 1852 | mHandler = new Handler() { |
| 1853 | @Override |
| 1854 | public void handleMessage(Message msg) { |
| 1855 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1856 | switch (msg.what) { |
| 1857 | case SUPPLY_PIN_COMPLETE: |
| 1858 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1859 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1860 | mRetryCount = msg.arg1; |
| 1861 | if (ar.exception != null) { |
| 1862 | if (ar.exception instanceof CommandException && |
| 1863 | ((CommandException)(ar.exception)).getCommandError() |
| 1864 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1865 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1866 | } else { |
| 1867 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1868 | } |
| 1869 | } else { |
| 1870 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1871 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1872 | mDone = true; |
| 1873 | UnlockSim.this.notifyAll(); |
| 1874 | } |
| 1875 | break; |
| 1876 | } |
| 1877 | } |
| 1878 | }; |
| 1879 | UnlockSim.this.notifyAll(); |
| 1880 | } |
| 1881 | Looper.loop(); |
| 1882 | } |
| 1883 | |
| 1884 | /* |
| 1885 | * Use PIN or PUK to unlock SIM card |
| 1886 | * |
| 1887 | * If PUK is null, unlock SIM card with PIN |
| 1888 | * |
| 1889 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1890 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1891 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1892 | |
| 1893 | while (mHandler == null) { |
| 1894 | try { |
| 1895 | wait(); |
| 1896 | } catch (InterruptedException e) { |
| 1897 | Thread.currentThread().interrupt(); |
| 1898 | } |
| 1899 | } |
| 1900 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1901 | |
| 1902 | if (puk == null) { |
| 1903 | mSimCard.supplyPin(pin, callback); |
| 1904 | } else { |
| 1905 | mSimCard.supplyPuk(puk, pin, callback); |
| 1906 | } |
| 1907 | |
| 1908 | while (!mDone) { |
| 1909 | try { |
| 1910 | Log.d(LOG_TAG, "wait for done"); |
| 1911 | wait(); |
| 1912 | } catch (InterruptedException e) { |
| 1913 | // Restore the interrupted status |
| 1914 | Thread.currentThread().interrupt(); |
| 1915 | } |
| 1916 | } |
| 1917 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1918 | int[] resultArray = new int[2]; |
| 1919 | resultArray[0] = mResult; |
| 1920 | resultArray[1] = mRetryCount; |
| 1921 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1922 | } |
| 1923 | } |
| 1924 | |
| 1925 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1926 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1927 | |
| 1928 | } |
| 1929 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1930 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1931 | // No permission check needed here: this call is harmless, and it's |
| 1932 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1933 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1934 | final long identity = Binder.clearCallingIdentity(); |
| 1935 | try { |
| 1936 | final Phone phone = getPhone(subId); |
| 1937 | if (phone != null) { |
| 1938 | phone.updateServiceLocation(); |
| 1939 | } |
| 1940 | } finally { |
| 1941 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1942 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1945 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1946 | @Override |
| 1947 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1948 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1949 | } |
| 1950 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1951 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1952 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1953 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1954 | callingFeatureId); |
| 1955 | } |
| 1956 | |
| 1957 | @Deprecated |
| 1958 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1959 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1960 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 1961 | } |
| 1962 | |
| 1963 | @Override |
| 1964 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1965 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1966 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1967 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1968 | return false; |
| 1969 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1970 | |
| 1971 | final long identity = Binder.clearCallingIdentity(); |
| 1972 | try { |
| 1973 | return isRadioOnForSubscriber(subId); |
| 1974 | } finally { |
| 1975 | Binder.restoreCallingIdentity(identity); |
| 1976 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1980 | final long identity = Binder.clearCallingIdentity(); |
| 1981 | try { |
| 1982 | final Phone phone = getPhone(subId); |
| 1983 | if (phone != null) { |
| 1984 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1985 | } else { |
| 1986 | return false; |
| 1987 | } |
| 1988 | } finally { |
| 1989 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1990 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1994 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1995 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1996 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1997 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1998 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1999 | |
| 2000 | final long identity = Binder.clearCallingIdentity(); |
| 2001 | try { |
| 2002 | final Phone phone = getPhone(subId); |
| 2003 | if (phone != null) { |
| 2004 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2005 | } |
| 2006 | } finally { |
| 2007 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2008 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2012 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2015 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2016 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2017 | |
| 2018 | final long identity = Binder.clearCallingIdentity(); |
| 2019 | try { |
| 2020 | final Phone phone = getPhone(subId); |
| 2021 | if (phone == null) { |
| 2022 | return false; |
| 2023 | } |
| 2024 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2025 | toggleRadioOnOffForSubscriber(subId); |
| 2026 | } |
| 2027 | return true; |
| 2028 | } finally { |
| 2029 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2030 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2031 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2032 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2033 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2034 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2035 | /* |
| 2036 | * If any of the Radios are available, it will need to be |
| 2037 | * shutdown. So return true if any Radio is available. |
| 2038 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2039 | final long identity = Binder.clearCallingIdentity(); |
| 2040 | try { |
| 2041 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2042 | Phone phone = PhoneFactory.getPhone(i); |
| 2043 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2044 | } |
| 2045 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2046 | return false; |
| 2047 | } finally { |
| 2048 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2049 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2050 | } |
| 2051 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2052 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2053 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2054 | enforceModifyPermission(); |
| 2055 | |
| 2056 | final long identity = Binder.clearCallingIdentity(); |
| 2057 | try { |
| 2058 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2059 | logv("Shutting down Phone " + i); |
| 2060 | shutdownRadioUsingPhoneId(i); |
| 2061 | } |
| 2062 | } finally { |
| 2063 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2064 | } |
| 2065 | } |
| 2066 | |
| 2067 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2068 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2069 | if (phone != null && phone.isRadioAvailable()) { |
| 2070 | phone.shutdownRadio(); |
| 2071 | } |
| 2072 | } |
| 2073 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2074 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2075 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2076 | |
| 2077 | final long identity = Binder.clearCallingIdentity(); |
| 2078 | try { |
| 2079 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2080 | if (defaultPhone != null) { |
| 2081 | defaultPhone.setRadioPower(turnOn); |
| 2082 | return true; |
| 2083 | } else { |
| 2084 | loge("There's no default phone."); |
| 2085 | return false; |
| 2086 | } |
| 2087 | } finally { |
| 2088 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2089 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2090 | } |
| 2091 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2092 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2093 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2094 | |
| 2095 | final long identity = Binder.clearCallingIdentity(); |
| 2096 | try { |
| 2097 | final Phone phone = getPhone(subId); |
| 2098 | if (phone != null) { |
| 2099 | phone.setRadioPower(turnOn); |
| 2100 | return true; |
| 2101 | } else { |
| 2102 | return false; |
| 2103 | } |
| 2104 | } finally { |
| 2105 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2106 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2107 | } |
| 2108 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2109 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2110 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2111 | public boolean enableDataConnectivity() { |
| 2112 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2113 | |
| 2114 | final long identity = Binder.clearCallingIdentity(); |
| 2115 | try { |
| 2116 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2117 | final Phone phone = getPhone(subId); |
| 2118 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2119 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2120 | return true; |
| 2121 | } else { |
| 2122 | return false; |
| 2123 | } |
| 2124 | } finally { |
| 2125 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2126 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2127 | } |
| 2128 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2129 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2130 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2131 | public boolean disableDataConnectivity() { |
| 2132 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2133 | |
| 2134 | final long identity = Binder.clearCallingIdentity(); |
| 2135 | try { |
| 2136 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2137 | final Phone phone = getPhone(subId); |
| 2138 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2139 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2140 | return true; |
| 2141 | } else { |
| 2142 | return false; |
| 2143 | } |
| 2144 | } finally { |
| 2145 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2146 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2147 | } |
| 2148 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2149 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2150 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2151 | final long identity = Binder.clearCallingIdentity(); |
| 2152 | try { |
| 2153 | final Phone phone = getPhone(subId); |
| 2154 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2155 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2156 | } else { |
| 2157 | return false; |
| 2158 | } |
| 2159 | } finally { |
| 2160 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2161 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2165 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2166 | } |
| 2167 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2168 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2169 | enforceCallPermission(); |
| 2170 | |
| 2171 | final long identity = Binder.clearCallingIdentity(); |
| 2172 | try { |
| 2173 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2174 | return; |
| 2175 | } |
| 2176 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2177 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2178 | } finally { |
| 2179 | Binder.restoreCallingIdentity(identity); |
| 2180 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2181 | }; |
| 2182 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2183 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2184 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2185 | |
| 2186 | final long identity = Binder.clearCallingIdentity(); |
| 2187 | try { |
| 2188 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2189 | return false; |
| 2190 | } |
| 2191 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2192 | } finally { |
| 2193 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2194 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2195 | } |
| 2196 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2197 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2198 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2199 | } |
| 2200 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2201 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2202 | final long identity = Binder.clearCallingIdentity(); |
| 2203 | try { |
| 2204 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2205 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2206 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2207 | } finally { |
| 2208 | Binder.restoreCallingIdentity(identity); |
| 2209 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2210 | } |
| 2211 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2212 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2213 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2214 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2215 | } |
| 2216 | |
| 2217 | @Override |
| 2218 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2219 | final long identity = Binder.clearCallingIdentity(); |
| 2220 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2221 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2222 | if (phone != null) { |
| 2223 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2224 | } else { |
| 2225 | return PhoneConstantConversions.convertDataState( |
| 2226 | PhoneConstants.DataState.DISCONNECTED); |
| 2227 | } |
| 2228 | } finally { |
| 2229 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2230 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2231 | } |
| 2232 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2233 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2234 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2235 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2236 | } |
| 2237 | |
| 2238 | @Override |
| 2239 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2240 | final long identity = Binder.clearCallingIdentity(); |
| 2241 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2242 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2243 | if (phone != null) { |
| 2244 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2245 | } else { |
| 2246 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2247 | } |
| 2248 | } finally { |
| 2249 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2250 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2251 | } |
| 2252 | |
| 2253 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2254 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2255 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2256 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2257 | |
| 2258 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2259 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2260 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2261 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2262 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2263 | .setCallingPid(Binder.getCallingPid()) |
| 2264 | .setCallingUid(Binder.getCallingUid()) |
| 2265 | .setMethod("getCellLocation") |
| 2266 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2267 | .build()); |
| 2268 | switch (locationResult) { |
| 2269 | case DENIED_HARD: |
| 2270 | throw new SecurityException("Not allowed to access cell location"); |
| 2271 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2272 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2273 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2274 | } |
| 2275 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2276 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2277 | final long identity = Binder.clearCallingIdentity(); |
| 2278 | try { |
| 2279 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2280 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2281 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2282 | } finally { |
| 2283 | Binder.restoreCallingIdentity(identity); |
| 2284 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2285 | } |
| 2286 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2287 | @Override |
Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2288 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2289 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2290 | // registered cell info, so return a NULL country instead. |
| 2291 | final long identity = Binder.clearCallingIdentity(); |
| 2292 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2293 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2294 | // Get default phone in this case. |
| 2295 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2296 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2297 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2298 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame^] | 2299 | if (phone == null) return ""; |
| 2300 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2301 | if (sst == null) return ""; |
| 2302 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2303 | if (lt == null) return ""; |
| 2304 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2305 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2306 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2307 | } finally { |
| 2308 | Binder.restoreCallingIdentity(identity); |
| 2309 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2313 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2314 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2315 | } |
| 2316 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2317 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2318 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2319 | mApp.enforceCallingOrSelfPermission( |
| 2320 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2321 | |
| 2322 | final long identity = Binder.clearCallingIdentity(); |
| 2323 | try { |
| 2324 | final Phone phone = getPhone(subId); |
| 2325 | if (phone != null) { |
| 2326 | phone.enableLocationUpdates(); |
| 2327 | } |
| 2328 | } finally { |
| 2329 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2330 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | @Override |
| 2334 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2335 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2336 | } |
| 2337 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2338 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2339 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2340 | mApp.enforceCallingOrSelfPermission( |
| 2341 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2342 | |
| 2343 | final long identity = Binder.clearCallingIdentity(); |
| 2344 | try { |
| 2345 | final Phone phone = getPhone(subId); |
| 2346 | if (phone != null) { |
| 2347 | phone.disableLocationUpdates(); |
| 2348 | } |
| 2349 | } finally { |
| 2350 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2351 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2352 | } |
| 2353 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2354 | /** |
| 2355 | * Returns the target SDK version number for a given package name. |
| 2356 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2357 | * This call MUST be invoked before clearing the calling UID. |
| 2358 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2359 | * @return target SDK if the package is found or INT_MAX. |
| 2360 | */ |
| 2361 | private int getTargetSdk(String packageName) { |
| 2362 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2363 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2364 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2365 | if (ai != null) return ai.targetSdkVersion; |
| 2366 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2367 | loge("Failed to get package info for pkg=" |
| 2368 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2369 | } |
| 2370 | return Integer.MAX_VALUE; |
| 2371 | } |
| 2372 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2373 | @Override |
| 2374 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2375 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2376 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2377 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2378 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2379 | throw new SecurityException( |
| 2380 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2381 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2382 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2383 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2384 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2385 | return null; |
| 2386 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2387 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2388 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2389 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2390 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2391 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2392 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2393 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2394 | for (CellInfo ci : info) { |
| 2395 | if (ci instanceof CellInfoGsm) { |
| 2396 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2397 | } else if (ci instanceof CellInfoWcdma) { |
| 2398 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2399 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2400 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2401 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2402 | } |
| 2403 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2404 | private List<CellInfo> getCachedCellInfo() { |
| 2405 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2406 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2407 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2408 | if (info != null) cellInfos.addAll(info); |
| 2409 | } |
| 2410 | return cellInfos; |
| 2411 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2412 | |
| 2413 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2414 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2415 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2416 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2417 | |
| 2418 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2419 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2420 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2421 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2422 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2423 | .setCallingPid(Binder.getCallingPid()) |
| 2424 | .setCallingUid(Binder.getCallingUid()) |
| 2425 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2426 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2427 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2428 | .build()); |
| 2429 | switch (locationResult) { |
| 2430 | case DENIED_HARD: |
| 2431 | throw new SecurityException("Not allowed to access cell info"); |
| 2432 | case DENIED_SOFT: |
| 2433 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2434 | } |
| 2435 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2436 | final int targetSdk = getTargetSdk(callingPackage); |
| 2437 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2438 | return getCachedCellInfo(); |
| 2439 | } |
| 2440 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2441 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2442 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2443 | final long identity = Binder.clearCallingIdentity(); |
| 2444 | try { |
| 2445 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2446 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2447 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2448 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2449 | if (info != null) cellInfos.addAll(info); |
| 2450 | } |
| 2451 | return cellInfos; |
| 2452 | } finally { |
| 2453 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2454 | } |
| 2455 | } |
| 2456 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2457 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2458 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2459 | String callingFeatureId) { |
| 2460 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2461 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2462 | } |
| 2463 | |
| 2464 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2465 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2466 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2467 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2468 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2469 | } |
| 2470 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2471 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2472 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2473 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2474 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2475 | |
| 2476 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2477 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2478 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2479 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2480 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2481 | .setCallingPid(Binder.getCallingPid()) |
| 2482 | .setCallingUid(Binder.getCallingUid()) |
| 2483 | .setMethod("requestCellInfoUpdate") |
| 2484 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2485 | .build()); |
| 2486 | switch (locationResult) { |
| 2487 | case DENIED_HARD: |
| 2488 | throw new SecurityException("Not allowed to access cell info"); |
| 2489 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2490 | try { |
| 2491 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2492 | } catch (RemoteException re) { |
| 2493 | // Drop without consequences |
| 2494 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2495 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2496 | } |
| 2497 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2498 | |
| 2499 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2500 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2501 | |
| 2502 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2503 | } |
| 2504 | |
| 2505 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2506 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2507 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2508 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2509 | |
| 2510 | final long identity = Binder.clearCallingIdentity(); |
| 2511 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2512 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2513 | } finally { |
| 2514 | Binder.restoreCallingIdentity(identity); |
| 2515 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2516 | } |
| 2517 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2518 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2519 | public String getImeiForSlot(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) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2522 | return null; |
| 2523 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2524 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2525 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2526 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2527 | return null; |
| 2528 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2529 | |
| 2530 | final long identity = Binder.clearCallingIdentity(); |
| 2531 | try { |
| 2532 | return phone.getImei(); |
| 2533 | } finally { |
| 2534 | Binder.restoreCallingIdentity(identity); |
| 2535 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2536 | } |
| 2537 | |
| 2538 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2539 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2540 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2541 | String tac = null; |
| 2542 | if (phone != null) { |
| 2543 | String imei = phone.getImei(); |
| 2544 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2545 | } |
| 2546 | return tac; |
| 2547 | } |
| 2548 | |
| 2549 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2550 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2551 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2552 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2553 | return null; |
| 2554 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2555 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2556 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2557 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2558 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2559 | return null; |
| 2560 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2561 | |
| 2562 | final long identity = Binder.clearCallingIdentity(); |
| 2563 | try { |
| 2564 | return phone.getMeid(); |
| 2565 | } finally { |
| 2566 | Binder.restoreCallingIdentity(identity); |
| 2567 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2571 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2572 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2573 | String manufacturerCode = null; |
| 2574 | if (phone != null) { |
| 2575 | String meid = phone.getMeid(); |
| 2576 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2577 | } |
| 2578 | return manufacturerCode; |
| 2579 | } |
| 2580 | |
| 2581 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2582 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2583 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2584 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2585 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2586 | return null; |
| 2587 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2588 | int subId = phone.getSubId(); |
| 2589 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2590 | mApp, subId, callingPackage, callingFeatureId, |
| 2591 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2592 | return null; |
| 2593 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2594 | |
| 2595 | final long identity = Binder.clearCallingIdentity(); |
| 2596 | try { |
| 2597 | return phone.getDeviceSvn(); |
| 2598 | } finally { |
| 2599 | Binder.restoreCallingIdentity(identity); |
| 2600 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2601 | } |
| 2602 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2603 | @Override |
| 2604 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2605 | final long identity = Binder.clearCallingIdentity(); |
| 2606 | try { |
| 2607 | final Phone phone = getPhone(subId); |
| 2608 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2609 | } finally { |
| 2610 | Binder.restoreCallingIdentity(identity); |
| 2611 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | @Override |
| 2615 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2616 | final long identity = Binder.clearCallingIdentity(); |
| 2617 | try { |
| 2618 | final Phone phone = getPhone(subId); |
| 2619 | return phone == null ? null : phone.getCarrierName(); |
| 2620 | } finally { |
| 2621 | Binder.restoreCallingIdentity(identity); |
| 2622 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2623 | } |
| 2624 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2625 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2626 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2627 | final long identity = Binder.clearCallingIdentity(); |
| 2628 | try { |
| 2629 | final Phone phone = getPhone(subId); |
| 2630 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2631 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2632 | } finally { |
| 2633 | Binder.restoreCallingIdentity(identity); |
| 2634 | } |
| 2635 | } |
| 2636 | |
| 2637 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2638 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2639 | final long identity = Binder.clearCallingIdentity(); |
| 2640 | try { |
| 2641 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2642 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2643 | } finally { |
| 2644 | Binder.restoreCallingIdentity(identity); |
| 2645 | } |
| 2646 | } |
| 2647 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2648 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2649 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2650 | if (!isSubscriptionMccMnc) { |
| 2651 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2652 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2653 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2654 | if (phone == null) { |
| 2655 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2656 | } |
| 2657 | final long identity = Binder.clearCallingIdentity(); |
| 2658 | try { |
| 2659 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2660 | } finally { |
| 2661 | Binder.restoreCallingIdentity(identity); |
| 2662 | } |
| 2663 | } |
| 2664 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2665 | // |
| 2666 | // Internal helper methods. |
| 2667 | // |
| 2668 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2669 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2670 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2671 | * |
| 2672 | * @throws SecurityException if the caller does not have the required permission |
| 2673 | */ |
| 2674 | private void enforceModifyPermission() { |
| 2675 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2676 | } |
| 2677 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2678 | /** |
| 2679 | * Make sure the caller is system. |
| 2680 | * |
| 2681 | * @throws SecurityException if the caller is not system. |
| 2682 | */ |
| 2683 | private void enforceSystemCaller() { |
| 2684 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2685 | throw new SecurityException("Caller must be system"); |
| 2686 | } |
| 2687 | } |
| 2688 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2689 | private void enforceActiveEmergencySessionPermission() { |
| 2690 | mApp.enforceCallingOrSelfPermission( |
| 2691 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2692 | } |
| 2693 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2694 | /** |
| 2695 | * Make sure the caller has the CALL_PHONE permission. |
| 2696 | * |
| 2697 | * @throws SecurityException if the caller does not have the required permission |
| 2698 | */ |
| 2699 | private void enforceCallPermission() { |
| 2700 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2701 | } |
| 2702 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2703 | private void enforceSettingsPermission() { |
| 2704 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2705 | } |
| 2706 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2707 | private String createTelUrl(String number) { |
| 2708 | if (TextUtils.isEmpty(number)) { |
| 2709 | return null; |
| 2710 | } |
| 2711 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2712 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2715 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2716 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2717 | } |
| 2718 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2719 | private static void logv(String msg) { |
| 2720 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2721 | } |
| 2722 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2723 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2724 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2725 | } |
| 2726 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2727 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2728 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2729 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2730 | } |
| 2731 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2732 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2733 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2734 | final long identity = Binder.clearCallingIdentity(); |
| 2735 | try { |
| 2736 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2737 | if (phone == null) { |
| 2738 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2739 | } else { |
| 2740 | return phone.getPhoneType(); |
| 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 index to display |
| 2749 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2750 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2751 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2752 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2753 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2754 | } |
| 2755 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2756 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2757 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2758 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2759 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2760 | mApp, subId, callingPackage, callingFeatureId, |
| 2761 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2762 | return -1; |
| 2763 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2764 | |
| 2765 | final long identity = Binder.clearCallingIdentity(); |
| 2766 | try { |
| 2767 | final Phone phone = getPhone(subId); |
| 2768 | if (phone != null) { |
| 2769 | return phone.getCdmaEriIconIndex(); |
| 2770 | } else { |
| 2771 | return -1; |
| 2772 | } |
| 2773 | } finally { |
| 2774 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2775 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2776 | } |
| 2777 | |
| 2778 | /** |
| 2779 | * Returns the CDMA ERI icon mode, |
| 2780 | * 0 - ON |
| 2781 | * 1 - FLASHING |
| 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 int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2785 | return getCdmaEriIconModeForSubscriber(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 int getCdmaEriIconModeForSubscriber(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 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2795 | return -1; |
| 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.getCdmaEriIconMode(); |
| 2803 | } else { |
| 2804 | return -1; |
| 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 | /** |
| 2812 | * Returns the CDMA ERI text, |
| 2813 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2814 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2815 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2816 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2817 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2818 | } |
| 2819 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2820 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2821 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2822 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2823 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2824 | mApp, subId, callingPackage, callingFeatureId, |
| 2825 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2826 | return null; |
| 2827 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2828 | |
| 2829 | final long identity = Binder.clearCallingIdentity(); |
| 2830 | try { |
| 2831 | final Phone phone = getPhone(subId); |
| 2832 | if (phone != null) { |
| 2833 | return phone.getCdmaEriText(); |
| 2834 | } else { |
| 2835 | return null; |
| 2836 | } |
| 2837 | } finally { |
| 2838 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2839 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2843 | * Returns the CDMA MDN. |
| 2844 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2845 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2846 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2847 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2848 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2849 | |
| 2850 | final long identity = Binder.clearCallingIdentity(); |
| 2851 | try { |
| 2852 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2853 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2854 | return phone.getLine1Number(); |
| 2855 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2856 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2857 | return null; |
| 2858 | } |
| 2859 | } finally { |
| 2860 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2861 | } |
| 2862 | } |
| 2863 | |
| 2864 | /** |
| 2865 | * Returns the CDMA MIN. |
| 2866 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2867 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2868 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2869 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2870 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2871 | |
| 2872 | final long identity = Binder.clearCallingIdentity(); |
| 2873 | try { |
| 2874 | final Phone phone = getPhone(subId); |
| 2875 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2876 | return phone.getCdmaMin(); |
| 2877 | } else { |
| 2878 | return null; |
| 2879 | } |
| 2880 | } finally { |
| 2881 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2882 | } |
| 2883 | } |
| 2884 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2885 | @Override |
| 2886 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2887 | INumberVerificationCallback callback, String callingPackage) { |
| 2888 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2889 | != PERMISSION_GRANTED) { |
| 2890 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2891 | } |
| 2892 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2893 | |
| 2894 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2895 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2896 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2897 | } |
| 2898 | |
| 2899 | if (range == null) { |
| 2900 | throw new NullPointerException("Range must be non-null"); |
| 2901 | } |
| 2902 | |
| 2903 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2904 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2905 | |
| 2906 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2907 | } |
| 2908 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2909 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2910 | * Returns true if CDMA provisioning needs to run. |
| 2911 | */ |
| 2912 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2913 | final long identity = Binder.clearCallingIdentity(); |
| 2914 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2915 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2916 | } finally { |
| 2917 | Binder.restoreCallingIdentity(identity); |
| 2918 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2922 | * Sets the voice mail number of a given subId. |
| 2923 | */ |
| 2924 | @Override |
| 2925 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2926 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2927 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2928 | |
| 2929 | final long identity = Binder.clearCallingIdentity(); |
| 2930 | try { |
| 2931 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2932 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2933 | return success; |
| 2934 | } finally { |
| 2935 | Binder.restoreCallingIdentity(identity); |
| 2936 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2937 | } |
| 2938 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2939 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2940 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2941 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2942 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2943 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2944 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2945 | throw new SecurityException("caller must be system dialer"); |
| 2946 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2947 | |
| 2948 | final long identity = Binder.clearCallingIdentity(); |
| 2949 | try { |
| 2950 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2951 | if (phoneAccountHandle == null) { |
| 2952 | return null; |
| 2953 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2954 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2955 | } finally { |
| 2956 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2957 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2958 | } |
| 2959 | |
| 2960 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2961 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2962 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2963 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2964 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2965 | mApp, subId, callingPackage, callingFeatureId, |
| 2966 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2967 | return null; |
| 2968 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2969 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2970 | final long identity = Binder.clearCallingIdentity(); |
| 2971 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2972 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2973 | } finally { |
| 2974 | Binder.restoreCallingIdentity(identity); |
| 2975 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2976 | } |
| 2977 | |
| 2978 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2979 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2980 | VisualVoicemailSmsFilterSettings settings) { |
| 2981 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2982 | |
| 2983 | final long identity = Binder.clearCallingIdentity(); |
| 2984 | try { |
| 2985 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2986 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2987 | } finally { |
| 2988 | Binder.restoreCallingIdentity(identity); |
| 2989 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2990 | } |
| 2991 | |
| 2992 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2993 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2994 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2995 | |
| 2996 | final long identity = Binder.clearCallingIdentity(); |
| 2997 | try { |
| 2998 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2999 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3000 | } finally { |
| 3001 | Binder.restoreCallingIdentity(identity); |
| 3002 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3003 | } |
| 3004 | |
| 3005 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3006 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3007 | String callingPackage, int subId) { |
| 3008 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3009 | |
| 3010 | final long identity = Binder.clearCallingIdentity(); |
| 3011 | try { |
| 3012 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3013 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3014 | } finally { |
| 3015 | Binder.restoreCallingIdentity(identity); |
| 3016 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3017 | } |
| 3018 | |
| 3019 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3020 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3021 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3022 | |
| 3023 | final long identity = Binder.clearCallingIdentity(); |
| 3024 | try { |
| 3025 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3026 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3027 | } finally { |
| 3028 | Binder.restoreCallingIdentity(identity); |
| 3029 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3030 | } |
| 3031 | |
| 3032 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3033 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3034 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3035 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3036 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3037 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3038 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3039 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3040 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3041 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3042 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3043 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3044 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3045 | * Sets the voice activation state of a given subId. |
| 3046 | */ |
| 3047 | @Override |
| 3048 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3049 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3050 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3051 | |
| 3052 | final long identity = Binder.clearCallingIdentity(); |
| 3053 | try { |
| 3054 | final Phone phone = getPhone(subId); |
| 3055 | if (phone != null) { |
| 3056 | phone.setVoiceActivationState(activationState); |
| 3057 | } else { |
| 3058 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3059 | } |
| 3060 | } finally { |
| 3061 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3062 | } |
| 3063 | } |
| 3064 | |
| 3065 | /** |
| 3066 | * Sets the data activation state of a given subId. |
| 3067 | */ |
| 3068 | @Override |
| 3069 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3070 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3071 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3072 | |
| 3073 | final long identity = Binder.clearCallingIdentity(); |
| 3074 | try { |
| 3075 | final Phone phone = getPhone(subId); |
| 3076 | if (phone != null) { |
| 3077 | phone.setDataActivationState(activationState); |
| 3078 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3079 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3080 | } |
| 3081 | } finally { |
| 3082 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3083 | } |
| 3084 | } |
| 3085 | |
| 3086 | /** |
| 3087 | * Returns the voice activation state of a given subId. |
| 3088 | */ |
| 3089 | @Override |
| 3090 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3091 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3092 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3093 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3094 | final long identity = Binder.clearCallingIdentity(); |
| 3095 | try { |
| 3096 | if (phone != null) { |
| 3097 | return phone.getVoiceActivationState(); |
| 3098 | } else { |
| 3099 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3100 | } |
| 3101 | } finally { |
| 3102 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3103 | } |
| 3104 | } |
| 3105 | |
| 3106 | /** |
| 3107 | * Returns the data activation state of a given subId. |
| 3108 | */ |
| 3109 | @Override |
| 3110 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3111 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3112 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3113 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3114 | final long identity = Binder.clearCallingIdentity(); |
| 3115 | try { |
| 3116 | if (phone != null) { |
| 3117 | return phone.getDataActivationState(); |
| 3118 | } else { |
| 3119 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3120 | } |
| 3121 | } finally { |
| 3122 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3123 | } |
| 3124 | } |
| 3125 | |
| 3126 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3127 | * Returns the unread count of voicemails for a subId |
| 3128 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3129 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3130 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3131 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3132 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3133 | mApp, subId, callingPackage, callingFeatureId, |
| 3134 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3135 | return 0; |
| 3136 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3137 | final long identity = Binder.clearCallingIdentity(); |
| 3138 | try { |
| 3139 | final Phone phone = getPhone(subId); |
| 3140 | if (phone != null) { |
| 3141 | return phone.getVoiceMessageCount(); |
| 3142 | } else { |
| 3143 | return 0; |
| 3144 | } |
| 3145 | } finally { |
| 3146 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3147 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3148 | } |
| 3149 | |
| 3150 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3151 | * returns true, if the device is in a state where both voice and data |
| 3152 | * are supported simultaneously. This can change based on location or network condition. |
| 3153 | */ |
| 3154 | @Override |
| 3155 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3156 | final long identity = Binder.clearCallingIdentity(); |
| 3157 | try { |
| 3158 | final Phone phone = getPhone(subId); |
| 3159 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3160 | } finally { |
| 3161 | Binder.restoreCallingIdentity(identity); |
| 3162 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3166 | * Send the dialer code if called from the current default dialer or the caller has |
| 3167 | * carrier privilege. |
| 3168 | * @param inputCode The dialer code to send |
| 3169 | */ |
| 3170 | @Override |
| 3171 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3172 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3173 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3174 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3175 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3176 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3177 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3178 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3179 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3180 | |
| 3181 | final long identity = Binder.clearCallingIdentity(); |
| 3182 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3183 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3184 | } finally { |
| 3185 | Binder.restoreCallingIdentity(identity); |
| 3186 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3187 | } |
| 3188 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3189 | @Override |
| 3190 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3191 | TelephonyPermissions |
| 3192 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3193 | mApp, subId, "getNetworkSelectionMode"); |
| 3194 | final long identity = Binder.clearCallingIdentity(); |
| 3195 | try { |
| 3196 | if (!isActiveSubscription(subId)) { |
| 3197 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3198 | } |
| 3199 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3200 | } finally { |
| 3201 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3202 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3203 | } |
| 3204 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3205 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3206 | public boolean isInEmergencySmsMode() { |
| 3207 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3208 | final long identity = Binder.clearCallingIdentity(); |
| 3209 | try { |
| 3210 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3211 | if (phone.isInEmergencySmsMode()) { |
| 3212 | return true; |
| 3213 | } |
| 3214 | } |
| 3215 | } finally { |
| 3216 | Binder.restoreCallingIdentity(identity); |
| 3217 | } |
| 3218 | return false; |
| 3219 | } |
| 3220 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3221 | /** |
| 3222 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3223 | * @param subId The subscription to use to check the configuration. |
| 3224 | * @param c The callback that will be used to send the result. |
| 3225 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3226 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3227 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3228 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3229 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3230 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3231 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3232 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3233 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3234 | "IMS not available on device."); |
| 3235 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3236 | final long token = Binder.clearCallingIdentity(); |
| 3237 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3238 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3239 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3240 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3241 | } catch (ImsException e) { |
| 3242 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3243 | } finally { |
| 3244 | Binder.restoreCallingIdentity(token); |
| 3245 | } |
| 3246 | } |
| 3247 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3248 | /** |
| 3249 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3250 | * @param subId The subscription to use to check the configuration. |
| 3251 | * @param c The callback that will be used to send the result. |
| 3252 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3253 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3254 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3255 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3256 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3257 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3258 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3259 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3260 | final long token = Binder.clearCallingIdentity(); |
| 3261 | try { |
| 3262 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3263 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3264 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3265 | } catch (ImsException e) { |
| 3266 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3267 | + "is inactive, ignoring unregister."); |
| 3268 | // If the subscription is no longer active, just return, since the callback |
| 3269 | // will already have been removed internally. |
| 3270 | } finally { |
| 3271 | Binder.restoreCallingIdentity(token); |
| 3272 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3273 | } |
| 3274 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3275 | /** |
| 3276 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3277 | */ |
| 3278 | @Override |
| 3279 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3280 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3281 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3282 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3283 | "IMS not available on device."); |
| 3284 | } |
| 3285 | final long token = Binder.clearCallingIdentity(); |
| 3286 | try { |
| 3287 | Phone phone = getPhone(subId); |
| 3288 | if (phone == null) { |
| 3289 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3290 | + subId + "'"); |
| 3291 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3292 | } |
| 3293 | phone.getImsRegistrationState(regState -> { |
| 3294 | try { |
| 3295 | consumer.accept((regState == null) |
| 3296 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3297 | } catch (RemoteException e) { |
| 3298 | // Ignore if the remote process is no longer available to call back. |
| 3299 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3300 | } |
| 3301 | }); |
| 3302 | } finally { |
| 3303 | Binder.restoreCallingIdentity(token); |
| 3304 | } |
| 3305 | } |
| 3306 | |
| 3307 | /** |
| 3308 | * Get the transport type for the IMS service registration state. |
| 3309 | */ |
| 3310 | @Override |
| 3311 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3312 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3313 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3314 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3315 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3316 | "IMS not available on device."); |
| 3317 | } |
| 3318 | final long token = Binder.clearCallingIdentity(); |
| 3319 | try { |
| 3320 | Phone phone = getPhone(subId); |
| 3321 | if (phone == null) { |
| 3322 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3323 | + subId + "'"); |
| 3324 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3325 | } |
| 3326 | phone.getImsRegistrationTech(regTech -> { |
| 3327 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3328 | int regTechConverted = (regTech == null) |
| 3329 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3330 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3331 | regTechConverted); |
| 3332 | try { |
| 3333 | consumer.accept(regTechConverted); |
| 3334 | } catch (RemoteException e) { |
| 3335 | // Ignore if the remote process is no longer available to call back. |
| 3336 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3337 | } |
| 3338 | }); |
| 3339 | } finally { |
| 3340 | Binder.restoreCallingIdentity(token); |
| 3341 | } |
| 3342 | } |
| 3343 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3344 | /** |
| 3345 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3346 | * @param subId The subscription to use to check the configuration. |
| 3347 | * @param c The callback that will be used to send the result. |
| 3348 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3349 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3350 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3351 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3352 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3353 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3354 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3355 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3356 | "IMS not available on device."); |
| 3357 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3358 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3359 | final long token = Binder.clearCallingIdentity(); |
| 3360 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3361 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3362 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3363 | } catch (ImsException e) { |
| 3364 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3365 | } finally { |
| 3366 | Binder.restoreCallingIdentity(token); |
| 3367 | } |
| 3368 | } |
| 3369 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3370 | /** |
| 3371 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3372 | * @param subId The subscription to use to check the configuration. |
| 3373 | * @param c The callback that will be used to send the result. |
| 3374 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3375 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3376 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3377 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3378 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3379 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3380 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3381 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3382 | |
| 3383 | final long token = Binder.clearCallingIdentity(); |
| 3384 | try { |
| 3385 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3386 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3387 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3388 | } catch (ImsException e) { |
| 3389 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3390 | + "is inactive, ignoring unregister."); |
| 3391 | // If the subscription is no longer active, just return, since the callback |
| 3392 | // will already have been removed internally. |
| 3393 | } finally { |
| 3394 | Binder.restoreCallingIdentity(token); |
| 3395 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3396 | } |
| 3397 | |
| 3398 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3399 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3400 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3401 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3402 | final long token = Binder.clearCallingIdentity(); |
| 3403 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3404 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3405 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3406 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3407 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3408 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3409 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3410 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3411 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3412 | } finally { |
| 3413 | Binder.restoreCallingIdentity(token); |
| 3414 | } |
| 3415 | } |
| 3416 | |
| 3417 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3418 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3419 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3420 | final long token = Binder.clearCallingIdentity(); |
| 3421 | try { |
| 3422 | Phone phone = getPhone(subId); |
| 3423 | if (phone == null) return false; |
| 3424 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3425 | } catch (com.android.ims.ImsException e) { |
| 3426 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3427 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3428 | } finally { |
| 3429 | Binder.restoreCallingIdentity(token); |
| 3430 | } |
| 3431 | } |
| 3432 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3433 | /** |
| 3434 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3435 | * subscription. |
| 3436 | * @param subId The subscription to use to check the configuration. |
| 3437 | * @param callback The callback that will be used to send the result. |
| 3438 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3439 | * @param transportType The transport type of the MmTelFeature capability. |
| 3440 | */ |
| 3441 | @Override |
| 3442 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3443 | int transportType) { |
| 3444 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3445 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3446 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3447 | "IMS not available on device."); |
| 3448 | } |
| 3449 | final long token = Binder.clearCallingIdentity(); |
| 3450 | try { |
| 3451 | int slotId = getSlotIndex(subId); |
| 3452 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3453 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3454 | + subId + "'"); |
| 3455 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3456 | } |
| 3457 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3458 | transportType, aBoolean -> { |
| 3459 | try { |
| 3460 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3461 | } catch (RemoteException e) { |
| 3462 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3463 | + "running. Ignore"); |
| 3464 | } |
| 3465 | }); |
| 3466 | } finally { |
| 3467 | Binder.restoreCallingIdentity(token); |
| 3468 | } |
| 3469 | } |
| 3470 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3471 | /** |
| 3472 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3473 | * @param subId The subscription to use to check the configuration. |
| 3474 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3475 | @Override |
| 3476 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3477 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3478 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3479 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3480 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3481 | final long token = Binder.clearCallingIdentity(); |
| 3482 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3483 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3484 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 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(token); |
| 3489 | } |
| 3490 | } |
| 3491 | |
| 3492 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3493 | public void setAdvancedCallingSettingEnabled(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 | "setAdvancedCallingSettingEnabled"); |
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, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3500 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3501 | } catch (ImsException e) { |
| 3502 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3503 | } finally { |
| 3504 | Binder.restoreCallingIdentity(identity); |
| 3505 | } |
| 3506 | } |
| 3507 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3508 | /** |
| 3509 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3510 | * @param subId The subscription to use to check the configuration. |
| 3511 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3512 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3513 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3514 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3515 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3516 | final long identity = Binder.clearCallingIdentity(); |
| 3517 | try { |
| 3518 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3519 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 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 setVtSettingEnabled(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 | "setVtSettingEnabled"); |
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)).setVtSetting(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 isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3548 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3549 | mApp, subId, "isVoWiFiSettingEnabled"); |
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)).isWfcEnabledByUser(); |
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 setVoWiFiSettingEnabled(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 | "setVoWiFiSettingEnabled"); |
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, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3570 | } catch (ImsException e) { |
| 3571 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3572 | } finally { |
| 3573 | Binder.restoreCallingIdentity(identity); |
| 3574 | } |
| 3575 | } |
| 3576 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3577 | /** |
| 3578 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3579 | * @param subId The subscription to use to check the configuration. |
| 3580 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3581 | @Override |
| 3582 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3583 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3584 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3585 | final long identity = Binder.clearCallingIdentity(); |
| 3586 | try { |
| 3587 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3588 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3589 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3590 | } catch (ImsException e) { |
| 3591 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3592 | } finally { |
| 3593 | Binder.restoreCallingIdentity(identity); |
| 3594 | } |
| 3595 | } |
| 3596 | |
| 3597 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3598 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3599 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3600 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3601 | final long identity = Binder.clearCallingIdentity(); |
| 3602 | try { |
| 3603 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3604 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3605 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3606 | } catch (ImsException e) { |
| 3607 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3608 | } finally { |
| 3609 | Binder.restoreCallingIdentity(identity); |
| 3610 | } |
| 3611 | } |
| 3612 | |
| 3613 | @Override |
| 3614 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3615 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3616 | "setVoWiFiNonPersistent"); |
| 3617 | final long identity = Binder.clearCallingIdentity(); |
| 3618 | try { |
| 3619 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3620 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3621 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3622 | } catch (ImsException e) { |
| 3623 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3624 | } finally { |
| 3625 | Binder.restoreCallingIdentity(identity); |
| 3626 | } |
| 3627 | } |
| 3628 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3629 | /** |
| 3630 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3631 | * @param subId The subscription to use to check the configuration. |
| 3632 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3633 | @Override |
| 3634 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3635 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3636 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3637 | final long identity = Binder.clearCallingIdentity(); |
| 3638 | try { |
| 3639 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3640 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3641 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3642 | } catch (ImsException e) { |
| 3643 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3644 | } finally { |
| 3645 | Binder.restoreCallingIdentity(identity); |
| 3646 | } |
| 3647 | } |
| 3648 | |
| 3649 | @Override |
| 3650 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3651 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3652 | "setVoWiFiModeSetting"); |
| 3653 | final long identity = Binder.clearCallingIdentity(); |
| 3654 | try { |
| 3655 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3656 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3657 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3658 | } catch (ImsException e) { |
| 3659 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3660 | } finally { |
| 3661 | Binder.restoreCallingIdentity(identity); |
| 3662 | } |
| 3663 | } |
| 3664 | |
| 3665 | @Override |
| 3666 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3667 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3668 | final long identity = Binder.clearCallingIdentity(); |
| 3669 | try { |
| 3670 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3671 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3672 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3673 | } catch (ImsException e) { |
| 3674 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3675 | } finally { |
| 3676 | Binder.restoreCallingIdentity(identity); |
| 3677 | } |
| 3678 | } |
| 3679 | |
| 3680 | @Override |
| 3681 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3682 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3683 | "setVoWiFiRoamingModeSetting"); |
| 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 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3688 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
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 | |
| 3696 | @Override |
| 3697 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3698 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3699 | "setRttCapabilityEnabled"); |
| 3700 | final long identity = Binder.clearCallingIdentity(); |
| 3701 | try { |
| 3702 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3703 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3704 | } catch (ImsException e) { |
| 3705 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3706 | } finally { |
| 3707 | Binder.restoreCallingIdentity(identity); |
| 3708 | } |
| 3709 | } |
| 3710 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3711 | /** |
| 3712 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3713 | * @param subId The subscription to use to check the configuration. |
| 3714 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3715 | @Override |
| 3716 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3717 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3718 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3719 | final long identity = Binder.clearCallingIdentity(); |
| 3720 | try { |
| 3721 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3722 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3723 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3724 | } catch (ImsException e) { |
| 3725 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3726 | } finally { |
| 3727 | Binder.restoreCallingIdentity(identity); |
| 3728 | } |
| 3729 | } |
| 3730 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3731 | @Override |
| 3732 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3733 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3734 | final long identity = Binder.clearCallingIdentity(); |
| 3735 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3736 | if (!isImsAvailableOnDevice()) { |
| 3737 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3738 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3739 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3740 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3741 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3742 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3743 | } catch (ImsException e) { |
| 3744 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3745 | } finally { |
| 3746 | Binder.restoreCallingIdentity(identity); |
| 3747 | } |
| 3748 | } |
| 3749 | |
| 3750 | @Override |
| 3751 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3752 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3753 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3754 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3755 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3756 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3757 | try { |
| 3758 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3759 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3760 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3761 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3762 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3763 | + "is inactive, ignoring unregister."); |
| 3764 | // If the subscription is no longer active, just return, since the callback will already |
| 3765 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3766 | } finally { |
| 3767 | Binder.restoreCallingIdentity(identity); |
| 3768 | } |
| 3769 | } |
| 3770 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3771 | |
| 3772 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3773 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3774 | message); |
| 3775 | } |
| 3776 | |
| 3777 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3778 | boolean isMmtelCapability) { |
| 3779 | Phone phone = getPhone(subId); |
| 3780 | if (phone == null) { |
| 3781 | loge("phone instance null for subid " + subId); |
| 3782 | return false; |
| 3783 | } |
| 3784 | if (isMmtelCapability) { |
| 3785 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3786 | return false; |
| 3787 | } |
| 3788 | } else { |
| 3789 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3790 | return false; |
| 3791 | } |
| 3792 | } |
| 3793 | return true; |
| 3794 | } |
| 3795 | |
| 3796 | @Override |
| 3797 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3798 | boolean isProvisioned) { |
| 3799 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3800 | |
| 3801 | final long identity = Binder.clearCallingIdentity(); |
| 3802 | try { |
| 3803 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3804 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3805 | return; |
| 3806 | } |
| 3807 | |
| 3808 | // this capability requires provisioning, route to the correct API. |
| 3809 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3810 | switch (capability) { |
| 3811 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3812 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3813 | ims.setEabProvisioned(isProvisioned); |
| 3814 | break; |
| 3815 | default: { |
| 3816 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3817 | + "rcs capability '" + capability + "', which does not require " |
| 3818 | + "provisioning."); |
| 3819 | } |
| 3820 | } |
| 3821 | } finally { |
| 3822 | Binder.restoreCallingIdentity(identity); |
| 3823 | } |
| 3824 | |
| 3825 | } |
| 3826 | |
| 3827 | |
| 3828 | @Override |
| 3829 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3830 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3831 | final long identity = Binder.clearCallingIdentity(); |
| 3832 | try { |
| 3833 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3834 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3835 | return true; |
| 3836 | } |
| 3837 | |
| 3838 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3839 | switch (capability) { |
| 3840 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3841 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3842 | return ims.isEabProvisionedOnDevice(); |
| 3843 | |
| 3844 | default: { |
| 3845 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3846 | + "capability '" + capability + "', which does not require " |
| 3847 | + "provisioning."); |
| 3848 | } |
| 3849 | } |
| 3850 | |
| 3851 | } finally { |
| 3852 | Binder.restoreCallingIdentity(identity); |
| 3853 | } |
| 3854 | } |
| 3855 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3856 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3857 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3858 | boolean isProvisioned) { |
| 3859 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3860 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3861 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3862 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3863 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3864 | final long identity = Binder.clearCallingIdentity(); |
| 3865 | try { |
| 3866 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3867 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3868 | return; |
| 3869 | } |
| 3870 | |
| 3871 | // this capability requires provisioning, route to the correct API. |
| 3872 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3873 | switch (capability) { |
| 3874 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3875 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3876 | ims.setVolteProvisioned(isProvisioned); |
| 3877 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3878 | ims.setWfcProvisioned(isProvisioned); |
| 3879 | } |
| 3880 | break; |
| 3881 | } |
| 3882 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3883 | // There is currently no difference in VT provisioning type. |
| 3884 | ims.setVtProvisioned(isProvisioned); |
| 3885 | break; |
| 3886 | } |
| 3887 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3888 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3889 | // change the capability of the feature instead if needed. |
| 3890 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3891 | == isProvisioned) { |
| 3892 | // No change in provisioning. |
| 3893 | return; |
| 3894 | } |
| 3895 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3896 | try { |
| 3897 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3898 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3899 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3900 | + ", Exception" + e.getMessage()); |
| 3901 | } |
| 3902 | break; |
| 3903 | } |
| 3904 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3905 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3906 | + "MmTel capability '" + capability + "', which does not require " |
| 3907 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3908 | } |
| 3909 | } |
| 3910 | |
| 3911 | } finally { |
| 3912 | Binder.restoreCallingIdentity(identity); |
| 3913 | } |
| 3914 | } |
| 3915 | |
| 3916 | @Override |
| 3917 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3918 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3919 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3920 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3921 | } |
| 3922 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3923 | final long identity = Binder.clearCallingIdentity(); |
| 3924 | try { |
| 3925 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3926 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3927 | return true; |
| 3928 | } |
| 3929 | |
| 3930 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3931 | switch (capability) { |
| 3932 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3933 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3934 | return ims.isVolteProvisionedOnDevice(); |
| 3935 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3936 | return ims.isWfcProvisionedOnDevice(); |
| 3937 | } |
| 3938 | // This should never happen, since we are checking tech above to make sure it |
| 3939 | // is either LTE or IWLAN. |
| 3940 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3941 | + "capability."); |
| 3942 | } |
| 3943 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3944 | // There is currently no difference in VT provisioning type. |
| 3945 | return ims.isVtProvisionedOnDevice(); |
| 3946 | } |
| 3947 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3948 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3949 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3950 | } |
| 3951 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3952 | throw new IllegalArgumentException( |
| 3953 | "Tried to get provisioning for MmTel capability '" + capability |
| 3954 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3955 | } |
| 3956 | } |
| 3957 | |
| 3958 | } finally { |
| 3959 | Binder.restoreCallingIdentity(identity); |
| 3960 | } |
| 3961 | } |
| 3962 | |
| 3963 | @Override |
| 3964 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3965 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3966 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3967 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3968 | } |
| 3969 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3970 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3971 | return (provisionedBits & capability) > 0; |
| 3972 | } |
| 3973 | |
| 3974 | @Override |
| 3975 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3976 | boolean isProvisioned) { |
| 3977 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3978 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3979 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3980 | } |
| 3981 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3982 | "setProvisioningStatusForCapability"); |
| 3983 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3984 | // If the current provisioning status for capability already matches isProvisioned, |
| 3985 | // do nothing. |
| 3986 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3987 | return; |
| 3988 | } |
| 3989 | if (isProvisioned) { |
| 3990 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3991 | } else { |
| 3992 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3993 | } |
| 3994 | } |
| 3995 | |
| 3996 | /** |
| 3997 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3998 | * technology. The bitfield should mirror the bitfield defined by |
| 3999 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4000 | */ |
| 4001 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4002 | String key = getMmTelProvisioningKey(subId, tech); |
| 4003 | // Default is no capabilities are provisioned. |
| 4004 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4005 | } |
| 4006 | |
| 4007 | /** |
| 4008 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4009 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4010 | * technology specified. |
| 4011 | * |
| 4012 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4013 | */ |
| 4014 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4015 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4016 | String key = getMmTelProvisioningKey(subId, tech); |
| 4017 | editor.putInt(key, newField); |
| 4018 | editor.commit(); |
| 4019 | } |
| 4020 | |
| 4021 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4022 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4023 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4024 | } |
| 4025 | |
| 4026 | /** |
| 4027 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4028 | * carrier associated with the subscription id. |
| 4029 | */ |
| 4030 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4031 | int capability) { |
| 4032 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4033 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4034 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4035 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4036 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4037 | false); |
| 4038 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4039 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4040 | |
| 4041 | // First check to make sure that the capability requires provisioning. |
| 4042 | switch (capability) { |
| 4043 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4044 | // intentional fallthrough |
| 4045 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4046 | if (requireVoiceVtProvisioning) { |
| 4047 | // Voice and Video requires provisioning |
| 4048 | return true; |
| 4049 | } |
| 4050 | break; |
| 4051 | } |
| 4052 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4053 | if (requireUtProvisioning) { |
| 4054 | // UT requires provisioning |
| 4055 | return true; |
| 4056 | } |
| 4057 | break; |
| 4058 | } |
| 4059 | } |
| 4060 | return false; |
| 4061 | } |
| 4062 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4063 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4064 | int capability) { |
| 4065 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4066 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4067 | |
| 4068 | boolean requireRcsProvisioning = c.getBoolean( |
| 4069 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4070 | |
| 4071 | // First check to make sure that the capability requires provisioning. |
| 4072 | switch (capability) { |
| 4073 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4074 | // intentional fallthrough |
| 4075 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4076 | if (requireRcsProvisioning) { |
| 4077 | // OPTION or PRESENCE requires provisioning |
| 4078 | return true; |
| 4079 | } |
| 4080 | break; |
| 4081 | } |
| 4082 | } |
| 4083 | return false; |
| 4084 | } |
| 4085 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4086 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4087 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4088 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4089 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4090 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4091 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4092 | final long identity = Binder.clearCallingIdentity(); |
| 4093 | try { |
| 4094 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4095 | int slotId = getSlotIndex(subId); |
| 4096 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4097 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4098 | + subId + "' for key:" + key); |
| 4099 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4100 | } |
| 4101 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4102 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4103 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4104 | + subId + "' for key:" + key); |
| 4105 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4106 | } finally { |
| 4107 | Binder.restoreCallingIdentity(identity); |
| 4108 | } |
| 4109 | } |
| 4110 | |
| 4111 | @Override |
| 4112 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4113 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4114 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4115 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4116 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4117 | final long identity = Binder.clearCallingIdentity(); |
| 4118 | try { |
| 4119 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4120 | int slotId = getSlotIndex(subId); |
| 4121 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4122 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4123 | + subId + "' for key:" + key); |
| 4124 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4125 | } |
| 4126 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4127 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4128 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4129 | + subId + "' for key:" + key); |
| 4130 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4131 | } finally { |
| 4132 | Binder.restoreCallingIdentity(identity); |
| 4133 | } |
| 4134 | } |
| 4135 | |
| 4136 | @Override |
| 4137 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4138 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4139 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4140 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4141 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4142 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4143 | final long identity = Binder.clearCallingIdentity(); |
| 4144 | try { |
| 4145 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4146 | int slotId = getSlotIndex(subId); |
| 4147 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4148 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4149 | + subId + "' for key:" + key); |
| 4150 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4151 | } |
| 4152 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4153 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4154 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4155 | + "' for key:" + key); |
| 4156 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4157 | } finally { |
| 4158 | Binder.restoreCallingIdentity(identity); |
| 4159 | } |
| 4160 | } |
| 4161 | |
| 4162 | @Override |
| 4163 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4164 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4165 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4166 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4167 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4168 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4169 | final long identity = Binder.clearCallingIdentity(); |
| 4170 | try { |
| 4171 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4172 | int slotId = getSlotIndex(subId); |
| 4173 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4174 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4175 | + subId + "' for key:" + key); |
| 4176 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4177 | } |
| 4178 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4179 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4180 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4181 | + "' for key:" + key); |
| 4182 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4183 | } finally { |
| 4184 | Binder.restoreCallingIdentity(identity); |
| 4185 | } |
| 4186 | } |
| 4187 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4188 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4189 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4190 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4191 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4192 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4193 | } |
| 4194 | return slotId; |
| 4195 | } |
| 4196 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4197 | private int getSlotIndex(int subId) { |
| 4198 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4199 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4200 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4201 | } |
| 4202 | return slotId; |
| 4203 | } |
| 4204 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4205 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4206 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4207 | */ |
| 4208 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4209 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4210 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4211 | final int targetSdk = getTargetSdk(callingPackage); |
| 4212 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4213 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4214 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4215 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4216 | mApp, subId, callingPackage, callingFeatureId, |
| 4217 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4218 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4219 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4220 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4221 | final long identity = Binder.clearCallingIdentity(); |
| 4222 | try { |
| 4223 | final Phone phone = getPhone(subId); |
| 4224 | if (phone != null) { |
| 4225 | return phone.getServiceState().getDataNetworkType(); |
| 4226 | } else { |
| 4227 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4228 | } |
| 4229 | } finally { |
| 4230 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4231 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4232 | } |
| 4233 | |
| 4234 | /** |
| 4235 | * Returns the data network type |
| 4236 | */ |
| 4237 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4238 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4239 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4240 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4241 | } |
| 4242 | |
| 4243 | /** |
| 4244 | * Returns the data network type for a subId |
| 4245 | */ |
| 4246 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4247 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4248 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4249 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4250 | mApp, subId, callingPackage, callingFeatureId, |
| 4251 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4252 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4253 | } |
| 4254 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4255 | final long identity = Binder.clearCallingIdentity(); |
| 4256 | try { |
| 4257 | final Phone phone = getPhone(subId); |
| 4258 | if (phone != null) { |
| 4259 | return phone.getServiceState().getDataNetworkType(); |
| 4260 | } else { |
| 4261 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4262 | } |
| 4263 | } finally { |
| 4264 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4265 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4266 | } |
| 4267 | |
| 4268 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4269 | * Returns the Voice network type for a subId |
| 4270 | */ |
| 4271 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4272 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4273 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4274 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4275 | mApp, subId, callingPackage, callingFeatureId, |
| 4276 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4277 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4278 | } |
| 4279 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4280 | final long identity = Binder.clearCallingIdentity(); |
| 4281 | try { |
| 4282 | final Phone phone = getPhone(subId); |
| 4283 | if (phone != null) { |
| 4284 | return phone.getServiceState().getVoiceNetworkType(); |
| 4285 | } else { |
| 4286 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4287 | } |
| 4288 | } finally { |
| 4289 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4290 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4291 | } |
| 4292 | |
| 4293 | /** |
| 4294 | * @return true if a ICC card is present |
| 4295 | */ |
| 4296 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4297 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4298 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4299 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4300 | } |
| 4301 | |
| 4302 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4303 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4304 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4305 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4306 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4307 | final long identity = Binder.clearCallingIdentity(); |
| 4308 | try { |
| 4309 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4310 | if (phone != null) { |
| 4311 | return phone.getIccCard().hasIccCard(); |
| 4312 | } else { |
| 4313 | return false; |
| 4314 | } |
| 4315 | } finally { |
| 4316 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4317 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4318 | } |
| 4319 | |
| 4320 | /** |
| 4321 | * Return if the current radio is LTE on CDMA. This |
| 4322 | * is a tri-state return value as for a period of time |
| 4323 | * the mode may be unknown. |
| 4324 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4325 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4326 | * @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] | 4327 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4328 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4329 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4330 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4331 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4332 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4333 | } |
| 4334 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4335 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4336 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4337 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4338 | try { |
| 4339 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4340 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4341 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4342 | } |
| 4343 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4344 | final long identity = Binder.clearCallingIdentity(); |
| 4345 | try { |
| 4346 | final Phone phone = getPhone(subId); |
| 4347 | if (phone == null) { |
| 4348 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4349 | } else { |
| 4350 | return phone.getLteOnCdmaMode(); |
| 4351 | } |
| 4352 | } finally { |
| 4353 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4354 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4355 | } |
| 4356 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4357 | /** |
| 4358 | * {@hide} |
| 4359 | * Returns Default subId, 0 in the case of single standby. |
| 4360 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4361 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4362 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4363 | } |
| 4364 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4365 | private int getSlotForDefaultSubscription() { |
| 4366 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4367 | } |
| 4368 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4369 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4370 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4371 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4372 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4373 | private boolean isActiveSubscription(int subId) { |
| 4374 | return mSubscriptionController.isActiveSubId(subId); |
| 4375 | } |
| 4376 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4377 | /** |
| 4378 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4379 | */ |
| 4380 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4381 | final long identity = Binder.clearCallingIdentity(); |
| 4382 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4383 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4384 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4385 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4386 | } finally { |
| 4387 | Binder.restoreCallingIdentity(identity); |
| 4388 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4389 | } |
| 4390 | |
| 4391 | /** |
| 4392 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4393 | */ |
| 4394 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4395 | final long identity = Binder.clearCallingIdentity(); |
| 4396 | try { |
| 4397 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4398 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4399 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4400 | } finally { |
| 4401 | Binder.restoreCallingIdentity(identity); |
| 4402 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4403 | } |
| 4404 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4405 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4406 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4407 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4408 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4409 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4410 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4411 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4412 | if (phoneId == -1) { |
| 4413 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4414 | + " does not correspond to an active phone"); |
| 4415 | } |
| 4416 | return PhoneFactory.getPhone(phoneId); |
| 4417 | } |
| 4418 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4419 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4420 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4421 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4422 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4423 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4424 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4425 | if (DBG) { |
| 4426 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4427 | } |
| 4428 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4429 | p2); |
| 4430 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4431 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4432 | |
| 4433 | @Override |
| 4434 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4435 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4436 | enforceModifyPermission(); |
| 4437 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4438 | if (DBG) { |
| 4439 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4440 | } |
| 4441 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4442 | callingPackage, aid, p2); |
| 4443 | } |
| 4444 | |
| 4445 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4446 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4447 | final long identity = Binder.clearCallingIdentity(); |
| 4448 | try { |
| 4449 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4450 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4451 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4452 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4453 | if (bestComponent == null |
| 4454 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4455 | loge("The calling package is not allowed to access ISD-R."); |
| 4456 | throw new SecurityException( |
| 4457 | "The calling package is not allowed to access ISD-R."); |
| 4458 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4459 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4460 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4461 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4462 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4463 | null /* workSource */); |
| 4464 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4465 | return response; |
| 4466 | } finally { |
| 4467 | Binder.restoreCallingIdentity(identity); |
| 4468 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4469 | } |
| 4470 | |
| 4471 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4472 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4473 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4474 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4475 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4476 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4477 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4478 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4479 | @Override |
| 4480 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4481 | enforceModifyPermission(); |
| 4482 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4483 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4484 | channel); |
| 4485 | } |
| 4486 | |
| 4487 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4488 | final long identity = Binder.clearCallingIdentity(); |
| 4489 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4490 | if (channel < 0) { |
| 4491 | return false; |
| 4492 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4493 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4494 | null /* workSource */); |
| 4495 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4496 | return success; |
| 4497 | } finally { |
| 4498 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4499 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4500 | } |
| 4501 | |
| 4502 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4503 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4504 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4505 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4506 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4507 | if (DBG) { |
| 4508 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4509 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4510 | + p3 + " data=" + data); |
| 4511 | } |
| 4512 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4513 | command, p1, p2, p3, data); |
| 4514 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4515 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4516 | @Override |
| 4517 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4518 | int command, int p1, int p2, int p3, String data) { |
| 4519 | enforceModifyPermission(); |
| 4520 | if (DBG) { |
| 4521 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4522 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4523 | + p3 + " data=" + data); |
| 4524 | } |
| 4525 | return iccTransmitApduLogicalChannelWithPermission( |
| 4526 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4527 | data); |
| 4528 | } |
| 4529 | |
| 4530 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4531 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4532 | final long identity = Binder.clearCallingIdentity(); |
| 4533 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4534 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4535 | return ""; |
| 4536 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4537 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4538 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4539 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4540 | null /* workSource */); |
| 4541 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4542 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4543 | // Append the returned status code to the end of the response payload. |
| 4544 | String s = Integer.toHexString( |
| 4545 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4546 | if (response.payload != null) { |
| 4547 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4548 | } |
| 4549 | return s; |
| 4550 | } finally { |
| 4551 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4552 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4553 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4554 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4555 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4556 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4557 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4558 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4559 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4560 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4561 | if (DBG) { |
| 4562 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4563 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4564 | } |
| 4565 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4566 | cla, command, p1, p2, p3, data); |
| 4567 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4568 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4569 | @Override |
| 4570 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4571 | int command, int p1, int p2, int p3, String data) { |
| 4572 | enforceModifyPermission(); |
| 4573 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4574 | if (DBG) { |
| 4575 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4576 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4577 | + " data=" + data); |
| 4578 | } |
| 4579 | |
| 4580 | return iccTransmitApduBasicChannelWithPermission( |
| 4581 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4582 | p2, p3, data); |
| 4583 | } |
| 4584 | |
| 4585 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4586 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4587 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4588 | final long identity = Binder.clearCallingIdentity(); |
| 4589 | try { |
| 4590 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4591 | && TextUtils.equals(ISDR_AID, data)) { |
| 4592 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4593 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4594 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4595 | if (bestComponent == null |
| 4596 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4597 | loge("The calling package is not allowed to select ISD-R."); |
| 4598 | throw new SecurityException( |
| 4599 | "The calling package is not allowed to select ISD-R."); |
| 4600 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4601 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4602 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4603 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4604 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4605 | null /* workSource */); |
| 4606 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4607 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4608 | // Append the returned status code to the end of the response payload. |
| 4609 | String s = Integer.toHexString( |
| 4610 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4611 | if (response.payload != null) { |
| 4612 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4613 | } |
| 4614 | return s; |
| 4615 | } finally { |
| 4616 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4617 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4618 | } |
| 4619 | |
| 4620 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4621 | 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] | 4622 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4623 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4624 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4625 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4626 | final long identity = Binder.clearCallingIdentity(); |
| 4627 | try { |
| 4628 | if (DBG) { |
| 4629 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4630 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4631 | } |
| 4632 | |
| 4633 | IccIoResult response = |
| 4634 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4635 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4636 | subId); |
| 4637 | |
| 4638 | if (DBG) { |
| 4639 | log("Exchange SIM_IO [R]" + response); |
| 4640 | } |
| 4641 | |
| 4642 | byte[] result = null; |
| 4643 | int length = 2; |
| 4644 | if (response.payload != null) { |
| 4645 | length = 2 + response.payload.length; |
| 4646 | result = new byte[length]; |
| 4647 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4648 | } else { |
| 4649 | result = new byte[length]; |
| 4650 | } |
| 4651 | |
| 4652 | result[length - 1] = (byte) response.sw2; |
| 4653 | result[length - 2] = (byte) response.sw1; |
| 4654 | return result; |
| 4655 | } finally { |
| 4656 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4657 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4658 | } |
| 4659 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4660 | /** |
| 4661 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4662 | * on a particular subscription |
| 4663 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4664 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4665 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4666 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4667 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4668 | return null; |
| 4669 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4670 | |
| 4671 | final long identity = Binder.clearCallingIdentity(); |
| 4672 | try { |
| 4673 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4674 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4675 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4676 | return null; |
| 4677 | } |
| 4678 | Object response = sendRequest( |
| 4679 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4680 | if (response instanceof String[]) { |
| 4681 | return (String[]) response; |
| 4682 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4683 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4684 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4685 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4686 | } finally { |
| 4687 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4688 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4689 | } |
| 4690 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4691 | /** |
| 4692 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4693 | * subscription. |
| 4694 | * |
| 4695 | * @param subId the id of the subscription. |
| 4696 | * @param appType the uicc app type, must be USIM or SIM. |
| 4697 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4698 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4699 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4700 | * @return number of fplmns that is successfully written to the SIM. |
| 4701 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4702 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4703 | String callingFeatureId) { |
| 4704 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4705 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4706 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4707 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4708 | } |
| 4709 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4710 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4711 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4712 | } |
| 4713 | if (fplmns == null) { |
| 4714 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4715 | } |
| 4716 | for (String fplmn : fplmns) { |
| 4717 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4718 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4719 | } |
| 4720 | } |
| 4721 | final long identity = Binder.clearCallingIdentity(); |
| 4722 | try { |
| 4723 | Object response = sendRequest( |
| 4724 | CMD_SET_FORBIDDEN_PLMNS, |
| 4725 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4726 | subId); |
| 4727 | return (int) response; |
| 4728 | } finally { |
| 4729 | Binder.restoreCallingIdentity(identity); |
| 4730 | } |
| 4731 | } |
| 4732 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4733 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4734 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4735 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4736 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4737 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4738 | final long identity = Binder.clearCallingIdentity(); |
| 4739 | try { |
| 4740 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4741 | if (response.payload == null) { |
| 4742 | return ""; |
| 4743 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4744 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4745 | // Append the returned status code to the end of the response payload. |
| 4746 | String s = Integer.toHexString( |
| 4747 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4748 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4749 | return s; |
| 4750 | } finally { |
| 4751 | Binder.restoreCallingIdentity(identity); |
| 4752 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4753 | } |
| 4754 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4755 | /** |
| 4756 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4757 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4758 | * |
| 4759 | * @param itemID the ID of the item to read |
| 4760 | * @return the NV item as a String, or null on error. |
| 4761 | */ |
| 4762 | @Override |
| 4763 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4764 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4765 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4766 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4767 | |
| 4768 | final long identity = Binder.clearCallingIdentity(); |
| 4769 | try { |
| 4770 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4771 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4772 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4773 | return value; |
| 4774 | } finally { |
| 4775 | Binder.restoreCallingIdentity(identity); |
| 4776 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4777 | } |
| 4778 | |
| 4779 | /** |
| 4780 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4781 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4782 | * |
| 4783 | * @param itemID the ID of the item to read |
| 4784 | * @param itemValue the value to write, as a String |
| 4785 | * @return true on success; false on any failure |
| 4786 | */ |
| 4787 | @Override |
| 4788 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4789 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4790 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4791 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4792 | |
| 4793 | final long identity = Binder.clearCallingIdentity(); |
| 4794 | try { |
| 4795 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4796 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4797 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4798 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4799 | return success; |
| 4800 | } finally { |
| 4801 | Binder.restoreCallingIdentity(identity); |
| 4802 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4803 | } |
| 4804 | |
| 4805 | /** |
| 4806 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4807 | * Used for device configuration by some CDMA operators. |
| 4808 | * |
| 4809 | * @param preferredRoamingList byte array containing the new PRL |
| 4810 | * @return true on success; false on any failure |
| 4811 | */ |
| 4812 | @Override |
| 4813 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4814 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4815 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4816 | |
| 4817 | final long identity = Binder.clearCallingIdentity(); |
| 4818 | try { |
| 4819 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4820 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4821 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4822 | return success; |
| 4823 | } finally { |
| 4824 | Binder.restoreCallingIdentity(identity); |
| 4825 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4826 | } |
| 4827 | |
| 4828 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4829 | * 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] | 4830 | * Used for device configuration by some CDMA operators. |
| 4831 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4832 | * @param slotIndex - device slot. |
| 4833 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4834 | * @return true on success; false on any failure |
| 4835 | */ |
| 4836 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4837 | public boolean resetModemConfig(int slotIndex) { |
| 4838 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4839 | if (phone != null) { |
| 4840 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4841 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4842 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4843 | final long identity = Binder.clearCallingIdentity(); |
| 4844 | try { |
| 4845 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4846 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4847 | return success; |
| 4848 | } finally { |
| 4849 | Binder.restoreCallingIdentity(identity); |
| 4850 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4851 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4852 | return false; |
| 4853 | } |
| 4854 | |
| 4855 | /** |
| 4856 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4857 | * |
| 4858 | * @param slotIndex - device slot. |
| 4859 | * |
| 4860 | * @return true on success; false on any failure |
| 4861 | */ |
| 4862 | @Override |
| 4863 | public boolean rebootModem(int slotIndex) { |
| 4864 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4865 | if (phone != null) { |
| 4866 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4867 | mApp, phone.getSubId(), "rebootModem"); |
| 4868 | |
| 4869 | final long identity = Binder.clearCallingIdentity(); |
| 4870 | try { |
| 4871 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4872 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4873 | return success; |
| 4874 | } finally { |
| 4875 | Binder.restoreCallingIdentity(identity); |
| 4876 | } |
| 4877 | } |
| 4878 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4879 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4880 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4881 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4882 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4883 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4884 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4885 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4886 | return new String[0]; |
| 4887 | } |
| 4888 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4889 | final long identity = Binder.clearCallingIdentity(); |
| 4890 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4891 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4892 | } finally { |
| 4893 | Binder.restoreCallingIdentity(identity); |
| 4894 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4895 | } |
| 4896 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4897 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 4898 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 4899 | * {@link #disableIms(int)}. |
| 4900 | * @param slotIndex device slot. |
| 4901 | */ |
| 4902 | public void resetIms(int slotIndex) { |
| 4903 | enforceModifyPermission(); |
| 4904 | |
| 4905 | final long identity = Binder.clearCallingIdentity(); |
| 4906 | try { |
| 4907 | if (mImsResolver == null) { |
| 4908 | // may happen if the does not support IMS. |
| 4909 | return; |
| 4910 | } |
| 4911 | mImsResolver.disableIms(slotIndex); |
| 4912 | mImsResolver.enableIms(slotIndex); |
| 4913 | } finally { |
| 4914 | Binder.restoreCallingIdentity(identity); |
| 4915 | } |
| 4916 | } |
| 4917 | |
| 4918 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4919 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4920 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4921 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4922 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4923 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4924 | |
| 4925 | final long identity = Binder.clearCallingIdentity(); |
| 4926 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4927 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4928 | // may happen if the device does not support IMS. |
| 4929 | return; |
| 4930 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4931 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4932 | } finally { |
| 4933 | Binder.restoreCallingIdentity(identity); |
| 4934 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4935 | } |
| 4936 | |
| 4937 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4938 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4939 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4940 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4941 | public void disableIms(int slotId) { |
| 4942 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4943 | |
| 4944 | final long identity = Binder.clearCallingIdentity(); |
| 4945 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4946 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4947 | // may happen if the device does not support IMS. |
| 4948 | return; |
| 4949 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4950 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4951 | } finally { |
| 4952 | Binder.restoreCallingIdentity(identity); |
| 4953 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4954 | } |
| 4955 | |
| 4956 | /** |
| 4957 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4958 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4959 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4960 | */ |
| 4961 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4962 | IImsServiceFeatureCallback callback) { |
| 4963 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4964 | |
| 4965 | final long identity = Binder.clearCallingIdentity(); |
| 4966 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4967 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4968 | // may happen if the device does not support IMS. |
| 4969 | return null; |
| 4970 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4971 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4972 | } finally { |
| 4973 | Binder.restoreCallingIdentity(identity); |
| 4974 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4975 | } |
| 4976 | |
| 4977 | /** |
| 4978 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4979 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4980 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4981 | * listener for feature updates. |
| 4982 | */ |
| 4983 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4984 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4985 | |
| 4986 | final long identity = Binder.clearCallingIdentity(); |
| 4987 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4988 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4989 | // may happen if the device does not support IMS. |
| 4990 | return null; |
| 4991 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4992 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4993 | } finally { |
| 4994 | Binder.restoreCallingIdentity(identity); |
| 4995 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4996 | } |
| 4997 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4998 | /** |
| 4999 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5000 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5001 | */ |
| 5002 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5003 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5004 | |
| 5005 | final long identity = Binder.clearCallingIdentity(); |
| 5006 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5007 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5008 | // may happen if the device does not support IMS. |
| 5009 | return null; |
| 5010 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5011 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5012 | } finally { |
| 5013 | Binder.restoreCallingIdentity(identity); |
| 5014 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5015 | } |
| 5016 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5017 | /** |
| 5018 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5019 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5020 | */ |
| 5021 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5022 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5023 | |
| 5024 | final long identity = Binder.clearCallingIdentity(); |
| 5025 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5026 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5027 | // may happen if the device does not support IMS. |
| 5028 | return null; |
| 5029 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5030 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5031 | } finally { |
| 5032 | Binder.restoreCallingIdentity(identity); |
| 5033 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5034 | } |
| 5035 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5036 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5037 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5038 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5039 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5040 | * @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] | 5041 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5042 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5043 | * @param packageName The name of the package that the current configuration will be replaced |
| 5044 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5045 | * @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] | 5046 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5047 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5048 | int[] featureTypes, String packageName) { |
| 5049 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5050 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5051 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5052 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5053 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5054 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5055 | final long identity = Binder.clearCallingIdentity(); |
| 5056 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5057 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5058 | // may happen if the device does not support IMS. |
| 5059 | return false; |
| 5060 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5061 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5062 | for (int featureType : featureTypes) { |
| 5063 | featureConfig.put(featureType, packageName); |
| 5064 | } |
| 5065 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5066 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5067 | } finally { |
| 5068 | Binder.restoreCallingIdentity(identity); |
| 5069 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5070 | } |
| 5071 | |
| 5072 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5073 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5074 | * |
| 5075 | * @param slotId The slot that the ImsService is associated with. |
| 5076 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5077 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5078 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5079 | * @return the package name of the ImsService configuration. |
| 5080 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5081 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5082 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5083 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5084 | TelephonyPermissions |
| 5085 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5086 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5087 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5088 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5089 | final long identity = Binder.clearCallingIdentity(); |
| 5090 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5091 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5092 | // may happen if the device does not support IMS. |
| 5093 | return ""; |
| 5094 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5095 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5096 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5097 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5098 | } finally { |
| 5099 | Binder.restoreCallingIdentity(identity); |
| 5100 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5101 | } |
| 5102 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5103 | /** |
| 5104 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5105 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5106 | * @param callback A callback with an integer containing the |
| 5107 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5108 | */ |
| 5109 | @Override |
| 5110 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5111 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5112 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5113 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5114 | "IMS not available on device."); |
| 5115 | } |
| 5116 | final long token = Binder.clearCallingIdentity(); |
| 5117 | try { |
| 5118 | int slotId = getSlotIndex(subId); |
| 5119 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5120 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5121 | + subId + "'"); |
| 5122 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5123 | } |
| 5124 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5125 | try { |
| 5126 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5127 | } catch (RemoteException e) { |
| 5128 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5129 | + "Ignore"); |
| 5130 | } |
| 5131 | }); |
| 5132 | } finally { |
| 5133 | Binder.restoreCallingIdentity(token); |
| 5134 | } |
| 5135 | } |
| 5136 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5137 | public void setImsRegistrationState(boolean registered) { |
| 5138 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5139 | |
| 5140 | final long identity = Binder.clearCallingIdentity(); |
| 5141 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5142 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5143 | } finally { |
| 5144 | Binder.restoreCallingIdentity(identity); |
| 5145 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5146 | } |
| 5147 | |
| 5148 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5149 | * Set the network selection mode to automatic. |
| 5150 | * |
| 5151 | */ |
| 5152 | @Override |
| 5153 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5154 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5155 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5156 | |
| 5157 | final long identity = Binder.clearCallingIdentity(); |
| 5158 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5159 | if (!isActiveSubscription(subId)) { |
| 5160 | return; |
| 5161 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5162 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5163 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5164 | } finally { |
| 5165 | Binder.restoreCallingIdentity(identity); |
| 5166 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5167 | } |
| 5168 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5169 | /** |
| 5170 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5171 | * |
| 5172 | * @param subId the id of the subscription. |
| 5173 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5174 | * the operator to attach to. |
| 5175 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5176 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5177 | * normal network selection next time. |
| 5178 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5179 | */ |
| 5180 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5181 | public boolean setNetworkSelectionModeManual( |
| 5182 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5183 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5184 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5185 | |
| 5186 | if (!isActiveSubscription(subId)) { |
| 5187 | return false; |
| 5188 | } |
| 5189 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5190 | final long identity = Binder.clearCallingIdentity(); |
| 5191 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5192 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5193 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5194 | if (DBG) { |
| 5195 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5196 | + " operator: " + operatorInfo); |
| 5197 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5198 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5199 | } finally { |
| 5200 | Binder.restoreCallingIdentity(identity); |
| 5201 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5202 | } |
| 5203 | |
| 5204 | /** |
| 5205 | * Scans for available networks. |
| 5206 | */ |
| 5207 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5208 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5209 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5210 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5211 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5212 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5213 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5214 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5215 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5216 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5217 | .setCallingPid(Binder.getCallingPid()) |
| 5218 | .setCallingUid(Binder.getCallingUid()) |
| 5219 | .setMethod("getCellNetworkScanResults") |
| 5220 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5221 | .build()); |
| 5222 | switch (locationResult) { |
| 5223 | case DENIED_HARD: |
| 5224 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5225 | case DENIED_SOFT: |
| 5226 | return null; |
| 5227 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5228 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5229 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5230 | try { |
| 5231 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5232 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5233 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5234 | } finally { |
| 5235 | Binder.restoreCallingIdentity(identity); |
| 5236 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5237 | } |
| 5238 | |
| 5239 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5240 | * Get the call forwarding info, given the call forwarding reason. |
| 5241 | */ |
| 5242 | @Override |
| 5243 | public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) { |
| 5244 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5245 | long identity = Binder.clearCallingIdentity(); |
| 5246 | try { |
| 5247 | if (DBG) { |
| 5248 | log("getCallForwarding: subId " + subId |
| 5249 | + " callForwardingReason" + callForwardingReason); |
| 5250 | } |
| 5251 | return (CallForwardingInfo) sendRequest( |
| 5252 | CMD_GET_CALL_FORWARDING, callForwardingReason, subId); |
| 5253 | } finally { |
| 5254 | Binder.restoreCallingIdentity(identity); |
| 5255 | } |
| 5256 | } |
| 5257 | |
| 5258 | /** |
| 5259 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5260 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5261 | */ |
| 5262 | @Override |
| 5263 | public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) { |
| 5264 | enforceModifyPermission(); |
| 5265 | long identity = Binder.clearCallingIdentity(); |
| 5266 | try { |
| 5267 | if (DBG) { |
| 5268 | log("setCallForwarding: subId " + subId |
| 5269 | + " callForwardingInfo" + callForwardingInfo); |
| 5270 | } |
| 5271 | return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId); |
| 5272 | } finally { |
| 5273 | Binder.restoreCallingIdentity(identity); |
| 5274 | } |
| 5275 | } |
| 5276 | |
| 5277 | /** |
| 5278 | * Get the call forwarding info, given the call forwarding reason. |
| 5279 | */ |
| 5280 | @Override |
| 5281 | public int getCallWaitingStatus(int subId) { |
| 5282 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5283 | long identity = Binder.clearCallingIdentity(); |
| 5284 | try { |
| 5285 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 5286 | return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId); |
| 5287 | } finally { |
| 5288 | Binder.restoreCallingIdentity(identity); |
| 5289 | } |
| 5290 | } |
| 5291 | |
| 5292 | /** |
| 5293 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5294 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5295 | */ |
| 5296 | @Override |
| 5297 | public boolean setCallWaitingStatus(int subId, boolean isEnable) { |
| 5298 | enforceModifyPermission(); |
| 5299 | long identity = Binder.clearCallingIdentity(); |
| 5300 | try { |
| 5301 | if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable); |
| 5302 | return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId); |
| 5303 | } finally { |
| 5304 | Binder.restoreCallingIdentity(identity); |
| 5305 | } |
| 5306 | } |
| 5307 | |
| 5308 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5309 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5310 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5311 | * @param subId id of the subscription |
| 5312 | * @param request contains the radio access networks with bands/channels to scan |
| 5313 | * @param messenger callback messenger for scan results or errors |
| 5314 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5315 | * @return the id of the requested scan which can be used to stop the scan. |
| 5316 | */ |
| 5317 | @Override |
| 5318 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5319 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5320 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5321 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5322 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5323 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5324 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5325 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5326 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5327 | .setCallingPid(Binder.getCallingPid()) |
| 5328 | .setCallingUid(Binder.getCallingUid()) |
| 5329 | .setMethod("requestNetworkScan") |
| 5330 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5331 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5332 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5333 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5334 | if (e != null) { |
| 5335 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5336 | throw e; |
| 5337 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5338 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5339 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5340 | } |
| 5341 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5342 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5343 | int callingUid = Binder.getCallingUid(); |
| 5344 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5345 | final long identity = Binder.clearCallingIdentity(); |
| 5346 | try { |
| 5347 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5348 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5349 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5350 | } finally { |
| 5351 | Binder.restoreCallingIdentity(identity); |
| 5352 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5353 | } |
| 5354 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5355 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5356 | NetworkScanRequest request, int subId) { |
| 5357 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5358 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5359 | boolean hasNetworkScanPermission = |
| 5360 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5361 | == PERMISSION_GRANTED; |
| 5362 | |
| 5363 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5364 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5365 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5366 | } |
| 5367 | |
| 5368 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5369 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5370 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5371 | return new SecurityException("Specific channels must not be" |
| 5372 | + " scanned without location access."); |
| 5373 | } |
| 5374 | } |
| 5375 | } |
| 5376 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5377 | return null; |
| 5378 | } |
| 5379 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5380 | /** |
| 5381 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5382 | * |
| 5383 | * @param subId id of the subscription |
| 5384 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5385 | */ |
| 5386 | @Override |
| 5387 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5388 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5389 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5390 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5391 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5392 | final long identity = Binder.clearCallingIdentity(); |
| 5393 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5394 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5395 | } finally { |
| 5396 | Binder.restoreCallingIdentity(identity); |
| 5397 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5398 | } |
| 5399 | |
| 5400 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5401 | * Get the calculated preferred network type. |
| 5402 | * Used for debugging incorrect network type. |
| 5403 | * |
| 5404 | * @return the preferred network type, defined in RILConstants.java. |
| 5405 | */ |
| 5406 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5407 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5408 | final Phone defaultPhone = getDefaultPhone(); |
| 5409 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5410 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5411 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5412 | } |
| 5413 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5414 | final long identity = Binder.clearCallingIdentity(); |
| 5415 | try { |
| 5416 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5417 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5418 | } finally { |
| 5419 | Binder.restoreCallingIdentity(identity); |
| 5420 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5421 | } |
| 5422 | |
| 5423 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5424 | * Get the preferred network type. |
| 5425 | * Used for device configuration by some CDMA operators. |
| 5426 | * |
| 5427 | * @return the preferred network type, defined in RILConstants.java. |
| 5428 | */ |
| 5429 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5430 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5431 | TelephonyPermissions |
| 5432 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5433 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5434 | |
| 5435 | final long identity = Binder.clearCallingIdentity(); |
| 5436 | try { |
| 5437 | if (DBG) log("getPreferredNetworkType"); |
| 5438 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5439 | int networkType = (result != null ? result[0] : -1); |
| 5440 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5441 | return networkType; |
| 5442 | } finally { |
| 5443 | Binder.restoreCallingIdentity(identity); |
| 5444 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5445 | } |
| 5446 | |
| 5447 | /** |
| 5448 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5449 | * |
| 5450 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5451 | * @return true on success; false on any failure. |
| 5452 | */ |
| 5453 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5454 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5455 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5456 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5457 | |
| 5458 | final long identity = Binder.clearCallingIdentity(); |
| 5459 | try { |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5460 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5461 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5462 | |
| 5463 | Boolean success = (Boolean) sendRequest( |
| 5464 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 5465 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5466 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5467 | } finally { |
| 5468 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5469 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5470 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5471 | |
| 5472 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5473 | * Get the allowed network types that store in the telephony provider. |
| 5474 | * |
| 5475 | * @param subId the id of the subscription. |
| 5476 | * @return allowedNetworkTypes the allowed network types. |
| 5477 | */ |
| 5478 | @Override |
| 5479 | public long getAllowedNetworkTypes(int subId) { |
| 5480 | TelephonyPermissions |
| 5481 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5482 | mApp, subId, "getAllowedNetworkTypes"); |
| 5483 | |
| 5484 | final long identity = Binder.clearCallingIdentity(); |
| 5485 | try { |
| 5486 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5487 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5488 | } finally { |
| 5489 | Binder.restoreCallingIdentity(identity); |
| 5490 | } |
| 5491 | } |
| 5492 | |
| 5493 | /** |
| 5494 | * Set the allowed network types. |
| 5495 | * |
| 5496 | * @param subId the id of the subscription. |
| 5497 | * @param allowedNetworkTypes the allowed network types. |
| 5498 | * @return true on success; false on any failure. |
| 5499 | */ |
| 5500 | @Override |
| 5501 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5502 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5503 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5504 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5505 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5506 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5507 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5508 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5509 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5510 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5511 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5512 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5513 | } |
| 5514 | |
| 5515 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5516 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5517 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5518 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5519 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5520 | * @hide |
| 5521 | */ |
| 5522 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5523 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5524 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5525 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5526 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5527 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5528 | if (phone != null) { |
| 5529 | return phone.hasMatchedTetherApnSetting(); |
| 5530 | } else { |
| 5531 | return false; |
| 5532 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5533 | } finally { |
| 5534 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5535 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5536 | } |
| 5537 | |
| 5538 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5539 | * Set mobile data enabled |
| 5540 | * Used by the user through settings etc to turn on/off mobile data |
| 5541 | * |
| 5542 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5543 | */ |
| 5544 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5545 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5546 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5547 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5548 | |
| 5549 | final long identity = Binder.clearCallingIdentity(); |
| 5550 | try { |
| 5551 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5552 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5553 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5554 | if (phone != null) { |
| 5555 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5556 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5557 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5558 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5559 | } |
| 5560 | } finally { |
| 5561 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5562 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5563 | } |
| 5564 | |
| 5565 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5566 | * Enable or disable always reporting signal strength changes from radio. |
| 5567 | * |
| 5568 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5569 | */ |
| 5570 | @Override |
| 5571 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5572 | enforceModifyPermission(); |
| 5573 | enforceSystemCaller(); |
| 5574 | |
| 5575 | final long identity = Binder.clearCallingIdentity(); |
| 5576 | final Phone phone = getPhone(subId); |
| 5577 | try { |
| 5578 | if (phone != null) { |
| 5579 | if (DBG) { |
| 5580 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5581 | + " isEnable=" + isEnable); |
| 5582 | } |
| 5583 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5584 | } else { |
| 5585 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5586 | + subId); |
| 5587 | } |
| 5588 | } finally { |
| 5589 | Binder.restoreCallingIdentity(identity); |
| 5590 | } |
| 5591 | } |
| 5592 | |
| 5593 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5594 | * Get the user enabled state of Mobile Data. |
| 5595 | * |
| 5596 | * TODO: remove and use isUserDataEnabled. |
| 5597 | * This can't be removed now because some vendor codes |
| 5598 | * calls through ITelephony directly while they should |
| 5599 | * use TelephonyManager. |
| 5600 | * |
| 5601 | * @return true on enabled |
| 5602 | */ |
| 5603 | @Override |
| 5604 | public boolean getDataEnabled(int subId) { |
| 5605 | return isUserDataEnabled(subId); |
| 5606 | } |
| 5607 | |
| 5608 | /** |
| 5609 | * Get whether mobile data is enabled per user setting. |
| 5610 | * |
| 5611 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5612 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5613 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5614 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5615 | * |
| 5616 | * @return {@code true} if data is enabled else {@code false} |
| 5617 | */ |
| 5618 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5619 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5620 | try { |
| 5621 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5622 | null); |
| 5623 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5624 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5625 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5626 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5627 | |
| 5628 | final long identity = Binder.clearCallingIdentity(); |
| 5629 | try { |
| 5630 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5631 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5632 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5633 | if (phone != null) { |
| 5634 | boolean retVal = phone.isUserDataEnabled(); |
| 5635 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5636 | return retVal; |
| 5637 | } else { |
| 5638 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5639 | return false; |
| 5640 | } |
| 5641 | } finally { |
| 5642 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5643 | } |
| 5644 | } |
| 5645 | |
| 5646 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5647 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5648 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5649 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5650 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5651 | * @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] | 5652 | */ |
| 5653 | @Override |
| 5654 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5655 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5656 | |
| 5657 | final long identity = Binder.clearCallingIdentity(); |
| 5658 | try { |
| 5659 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5660 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5661 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5662 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5663 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5664 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5665 | return retVal; |
| 5666 | } else { |
| 5667 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5668 | return false; |
| 5669 | } |
| 5670 | } finally { |
| 5671 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5672 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5673 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5674 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5675 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5676 | Phone phone) { |
| 5677 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5678 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5679 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5680 | || subController == null) return privilegeFromSim; |
| 5681 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5682 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5683 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5684 | |
| 5685 | final long identity = Binder.clearCallingIdentity(); |
| 5686 | try { |
| 5687 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5688 | SubscriptionManager subManager = (SubscriptionManager) |
| 5689 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5690 | for (String pkg : packages) { |
| 5691 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5692 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5693 | } |
| 5694 | } |
| 5695 | return privilegeFromSim; |
| 5696 | } finally { |
| 5697 | Binder.restoreCallingIdentity(identity); |
| 5698 | } |
| 5699 | } |
| 5700 | |
| 5701 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5702 | String pkgName) { |
| 5703 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5704 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5705 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5706 | || subController == null) return privilegeFromSim; |
| 5707 | |
| 5708 | final long identity = Binder.clearCallingIdentity(); |
| 5709 | try { |
| 5710 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5711 | SubscriptionManager subManager = (SubscriptionManager) |
| 5712 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5713 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5714 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5715 | } finally { |
| 5716 | Binder.restoreCallingIdentity(identity); |
| 5717 | } |
| 5718 | } |
| 5719 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5720 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5721 | public int getCarrierPrivilegeStatus(int subId) { |
| 5722 | final Phone phone = getPhone(subId); |
| 5723 | if (phone == null) { |
| 5724 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5725 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5726 | } |
| 5727 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5728 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5729 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5730 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5731 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5732 | |
| 5733 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5734 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5735 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5736 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5737 | |
| 5738 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5739 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5740 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5741 | final Phone phone = getPhone(subId); |
| 5742 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5743 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5744 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5745 | } |
| 5746 | UiccProfile profile = |
| 5747 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5748 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5749 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5750 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5751 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5752 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5753 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5754 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5755 | } |
| 5756 | |
| 5757 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5758 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5759 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5760 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5761 | } |
| 5762 | |
| 5763 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5764 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5765 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5766 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5767 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5768 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5769 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5770 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5771 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5772 | } |
| 5773 | |
| 5774 | @Override |
| 5775 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5776 | if (TextUtils.isEmpty(pkgName)) |
| 5777 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5778 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5779 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5780 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5781 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5782 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5783 | continue; |
| 5784 | } |
| 5785 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5786 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5787 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5788 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5789 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5790 | break; |
| 5791 | } |
| 5792 | } |
| 5793 | |
| 5794 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5795 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5796 | |
| 5797 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5798 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5799 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5800 | loge("phoneId " + phoneId + " is not valid."); |
| 5801 | return null; |
| 5802 | } |
| 5803 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5804 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5805 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5806 | return null ; |
| 5807 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5808 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5809 | } |
| 5810 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5811 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5812 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5813 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5814 | List<String> privilegedPackages = new ArrayList<>(); |
| 5815 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5816 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5817 | // has UICC in that slot. |
| 5818 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5819 | if (card.hasCarrierPrivilegeRules()) { |
| 5820 | if (packages == null) { |
| 5821 | // Only check packages in user 0 for now |
| 5822 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5823 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5824 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5825 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5826 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5827 | } |
| 5828 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5829 | PackageInfo pkgInfo = packages.get(p); |
| 5830 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5831 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5832 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5833 | privilegedPackages.add(pkgInfo.packageName); |
| 5834 | } |
| 5835 | } |
| 5836 | } |
| 5837 | } |
| 5838 | return privilegedPackages; |
| 5839 | } |
| 5840 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5841 | @Override |
| 5842 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5843 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5844 | |
| 5845 | final long identity = Binder.clearCallingIdentity(); |
| 5846 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5847 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5848 | try { |
| 5849 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5850 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5851 | } |
| 5852 | } finally { |
| 5853 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5854 | } |
| 5855 | return privilegedPackages; |
| 5856 | } |
| 5857 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5858 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5859 | final Phone phone = getPhone(subId); |
| 5860 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5861 | if (card == null) { |
| 5862 | loge("getIccId: No UICC"); |
| 5863 | return null; |
| 5864 | } |
| 5865 | String iccId = card.getIccId(); |
| 5866 | if (TextUtils.isEmpty(iccId)) { |
| 5867 | loge("getIccId: ICC ID is null or empty."); |
| 5868 | return null; |
| 5869 | } |
| 5870 | return iccId; |
| 5871 | } |
| 5872 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5873 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5874 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5875 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5876 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5877 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5878 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5879 | final long identity = Binder.clearCallingIdentity(); |
| 5880 | try { |
| 5881 | final String iccId = getIccId(subId); |
| 5882 | final Phone phone = getPhone(subId); |
| 5883 | if (phone == null) { |
| 5884 | return false; |
| 5885 | } |
| 5886 | final String subscriberId = phone.getSubscriberId(); |
| 5887 | |
| 5888 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5889 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5890 | + subscriberId + " to " + number); |
| 5891 | } |
| 5892 | |
| 5893 | if (TextUtils.isEmpty(iccId)) { |
| 5894 | return false; |
| 5895 | } |
| 5896 | |
| 5897 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5898 | |
| 5899 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5900 | if (alphaTag == null) { |
| 5901 | editor.remove(alphaTagPrefKey); |
| 5902 | } else { |
| 5903 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5904 | } |
| 5905 | |
| 5906 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5907 | // track all merged IMSIs based on line number |
| 5908 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5909 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5910 | if (number == null) { |
| 5911 | editor.remove(numberPrefKey); |
| 5912 | editor.remove(subscriberPrefKey); |
| 5913 | } else { |
| 5914 | editor.putString(numberPrefKey, number); |
| 5915 | editor.putString(subscriberPrefKey, subscriberId); |
| 5916 | } |
| 5917 | |
| 5918 | editor.commit(); |
| 5919 | return true; |
| 5920 | } finally { |
| 5921 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5922 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5923 | } |
| 5924 | |
| 5925 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5926 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 5927 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5928 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5929 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5930 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5931 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5932 | return null; |
| 5933 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5934 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5935 | final long identity = Binder.clearCallingIdentity(); |
| 5936 | try { |
| 5937 | String iccId = getIccId(subId); |
| 5938 | if (iccId != null) { |
| 5939 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5940 | if (DBG_MERGE) { |
| 5941 | log("getLine1NumberForDisplay returning " |
| 5942 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5943 | } |
| 5944 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5945 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5946 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5947 | return null; |
| 5948 | } finally { |
| 5949 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5950 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5951 | } |
| 5952 | |
| 5953 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5954 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 5955 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5956 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5957 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5958 | return null; |
| 5959 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5960 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5961 | final long identity = Binder.clearCallingIdentity(); |
| 5962 | try { |
| 5963 | String iccId = getIccId(subId); |
| 5964 | if (iccId != null) { |
| 5965 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5966 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5967 | } |
| 5968 | return null; |
| 5969 | } finally { |
| 5970 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5971 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5972 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5973 | |
| 5974 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5975 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 5976 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5977 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5978 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5979 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5980 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5981 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5982 | return null; |
| 5983 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5984 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5985 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5986 | // the process, where TelephonyManager was instantiated. |
| 5987 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5988 | final long identity = Binder.clearCallingIdentity(); |
| 5989 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5990 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5991 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5992 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5993 | |
| 5994 | // Figure out what subscribers are currently active |
| 5995 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5996 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5997 | // Only consider subs which match the current subId |
| 5998 | // This logic can be simplified. See b/131189269 for progress. |
| 5999 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6000 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6001 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6002 | |
| 6003 | // First pass, find a number override for an active subscriber |
| 6004 | String mergeNumber = null; |
| 6005 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6006 | for (String key : prefs.keySet()) { |
| 6007 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6008 | final String subscriberId = (String) prefs.get(key); |
| 6009 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6010 | final String iccId = key.substring( |
| 6011 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6012 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6013 | mergeNumber = (String) prefs.get(numberKey); |
| 6014 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6015 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6016 | + " for active subscriber " + subscriberId); |
| 6017 | } |
| 6018 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6019 | break; |
| 6020 | } |
| 6021 | } |
| 6022 | } |
| 6023 | } |
| 6024 | |
| 6025 | // Shortcut when no active merged subscribers |
| 6026 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6027 | return null; |
| 6028 | } |
| 6029 | |
| 6030 | // Second pass, find all subscribers under that line override |
| 6031 | final ArraySet<String> result = new ArraySet<>(); |
| 6032 | for (String key : prefs.keySet()) { |
| 6033 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6034 | final String number = (String) prefs.get(key); |
| 6035 | if (mergeNumber.equals(number)) { |
| 6036 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6037 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6038 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6039 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6040 | result.add(subscriberId); |
| 6041 | } |
| 6042 | } |
| 6043 | } |
| 6044 | } |
| 6045 | |
| 6046 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6047 | Arrays.sort(resultArray); |
| 6048 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6049 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6050 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6051 | } |
| 6052 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6053 | } finally { |
| 6054 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6055 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6056 | } |
| 6057 | |
| 6058 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6059 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 6060 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 6061 | |
| 6062 | final long identity = Binder.clearCallingIdentity(); |
| 6063 | try { |
| 6064 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6065 | TelephonyManager.class); |
| 6066 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6067 | if (subscriberId == null) { |
| 6068 | if (DBG) { |
| 6069 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 6070 | + subId); |
| 6071 | } |
| 6072 | return null; |
| 6073 | } |
| 6074 | |
| 6075 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6076 | .getSubscriptionInfo(subId); |
| 6077 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6078 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6079 | if (groupUuid == null) { |
| 6080 | return new String[]{subscriberId}; |
| 6081 | } |
| 6082 | |
| 6083 | // Get all subscriberIds from the group. |
| 6084 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6085 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6086 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 6087 | null); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6088 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6089 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6090 | if (subscriberId != null) { |
| 6091 | mergedSubscriberIds.add(subscriberId); |
| 6092 | } |
| 6093 | } |
| 6094 | |
| 6095 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6096 | } finally { |
| 6097 | Binder.restoreCallingIdentity(identity); |
| 6098 | |
| 6099 | } |
| 6100 | } |
| 6101 | |
| 6102 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6103 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6104 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6105 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6106 | |
| 6107 | final long identity = Binder.clearCallingIdentity(); |
| 6108 | try { |
| 6109 | final Phone phone = getPhone(subId); |
| 6110 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6111 | } finally { |
| 6112 | Binder.restoreCallingIdentity(identity); |
| 6113 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6114 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6115 | |
| 6116 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6117 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6118 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6119 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6120 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6121 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6122 | |
| 6123 | final long identity = Binder.clearCallingIdentity(); |
| 6124 | try { |
| 6125 | final Phone phone = getPhone(subId); |
| 6126 | if (phone == null) { |
| 6127 | return false; |
| 6128 | } |
| 6129 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6130 | cdmaNonRoamingList); |
| 6131 | } finally { |
| 6132 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6133 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6134 | } |
| 6135 | |
| 6136 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6137 | @Deprecated |
| 6138 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6139 | enforceModifyPermission(); |
| 6140 | |
| 6141 | int returnValue = 0; |
| 6142 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6143 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6144 | if(result.exception == null) { |
| 6145 | if (result.result != null) { |
| 6146 | byte[] responseData = (byte[])(result.result); |
| 6147 | if(responseData.length > oemResp.length) { |
| 6148 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6149 | responseData.length + "bytes. Buffer Size is " + |
| 6150 | oemResp.length + "bytes."); |
| 6151 | } |
| 6152 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6153 | returnValue = responseData.length; |
| 6154 | } |
| 6155 | } else { |
| 6156 | CommandException ex = (CommandException) result.exception; |
| 6157 | returnValue = ex.getCommandError().ordinal(); |
| 6158 | if(returnValue > 0) returnValue *= -1; |
| 6159 | } |
| 6160 | } catch (RuntimeException e) { |
| 6161 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6162 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6163 | if(returnValue > 0) returnValue *= -1; |
| 6164 | } |
| 6165 | |
| 6166 | return returnValue; |
| 6167 | } |
| 6168 | |
| 6169 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6170 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6171 | try { |
| 6172 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6173 | } catch (RuntimeException e) { |
| 6174 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6175 | } |
| 6176 | } |
| 6177 | |
| 6178 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6179 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6180 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6181 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6182 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6183 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6184 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6185 | final long identity = Binder.clearCallingIdentity(); |
| 6186 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6187 | TelephonyPermissions |
| 6188 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6189 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6190 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6191 | } finally { |
| 6192 | Binder.restoreCallingIdentity(identity); |
| 6193 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6194 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6195 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6196 | |
| 6197 | @Override |
| 6198 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6199 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6200 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6201 | |
| 6202 | final long identity = Binder.clearCallingIdentity(); |
| 6203 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6204 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6205 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6206 | } finally { |
| 6207 | Binder.restoreCallingIdentity(identity); |
| 6208 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6209 | } |
| 6210 | |
| 6211 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6212 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6213 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6214 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6215 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6216 | return false; |
| 6217 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6218 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6219 | final long identity = Binder.clearCallingIdentity(); |
| 6220 | try { |
| 6221 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6222 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6223 | // In the long run, we may instead need to check if there exists a connection service |
| 6224 | // which can support video calling. |
| 6225 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6226 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6227 | return imsManager.isVtEnabledByPlatform() |
| 6228 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6229 | && imsManager.isVtEnabledByUser(); |
| 6230 | } finally { |
| 6231 | Binder.restoreCallingIdentity(identity); |
| 6232 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6233 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6234 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6235 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6236 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6237 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6238 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6239 | mApp, subId, callingPackage, callingFeatureId, |
| 6240 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6241 | return false; |
| 6242 | } |
| 6243 | |
| 6244 | final long identity = Binder.clearCallingIdentity(); |
| 6245 | try { |
| 6246 | CarrierConfigManager configManager = |
| 6247 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6248 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6249 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6250 | } finally { |
| 6251 | Binder.restoreCallingIdentity(identity); |
| 6252 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6253 | } |
| 6254 | |
| 6255 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6256 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6257 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6258 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6259 | return false; |
| 6260 | } |
| 6261 | |
| 6262 | final long identity = Binder.clearCallingIdentity(); |
| 6263 | try { |
| 6264 | CarrierConfigManager configManager = |
| 6265 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6266 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6267 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6268 | } finally { |
| 6269 | Binder.restoreCallingIdentity(identity); |
| 6270 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6271 | } |
| 6272 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6273 | @Override |
| 6274 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6275 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6276 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6277 | } |
| 6278 | |
| 6279 | @Override |
| 6280 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6281 | final long identity = Binder.clearCallingIdentity(); |
| 6282 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6283 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6284 | } finally { |
| 6285 | Binder.restoreCallingIdentity(identity); |
| 6286 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6287 | } |
| 6288 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6289 | /** |
| 6290 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6291 | * support for the feature and device firmware support. |
| 6292 | * |
| 6293 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6294 | */ |
| 6295 | @Override |
| 6296 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6297 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6298 | final Phone phone = getPhone(subscriptionId); |
| 6299 | if (phone == null) { |
| 6300 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6301 | return false; |
| 6302 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6303 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6304 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6305 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6306 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6307 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6308 | return isCarrierSupported && isDeviceSupported; |
| 6309 | } finally { |
| 6310 | Binder.restoreCallingIdentity(identity); |
| 6311 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6312 | } |
| 6313 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6314 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6315 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6316 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6317 | * 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] | 6318 | */ |
| 6319 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6320 | final long identity = Binder.clearCallingIdentity(); |
| 6321 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6322 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6323 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6324 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6325 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6326 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6327 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6328 | } finally { |
| 6329 | Binder.restoreCallingIdentity(identity); |
| 6330 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6331 | } |
| 6332 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6333 | @Deprecated |
| 6334 | @Override |
| 6335 | public String getDeviceId(String callingPackage) { |
| 6336 | return getDeviceIdWithFeature(callingPackage, null); |
| 6337 | } |
| 6338 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6339 | /** |
| 6340 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6341 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6342 | * |
| 6343 | * <p>Requires Permission: |
| 6344 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6345 | */ |
| 6346 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6347 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6348 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6349 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6350 | return null; |
| 6351 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6352 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6353 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6354 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6355 | return null; |
| 6356 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6357 | |
| 6358 | final long identity = Binder.clearCallingIdentity(); |
| 6359 | try { |
| 6360 | return phone.getDeviceId(); |
| 6361 | } finally { |
| 6362 | Binder.restoreCallingIdentity(identity); |
| 6363 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6364 | } |
| 6365 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6366 | /** |
| 6367 | * {@hide} |
| 6368 | * Returns the IMS Registration Status on a particular subid |
| 6369 | * |
| 6370 | * @param subId |
| 6371 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6372 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6373 | Phone phone = getPhone(subId); |
| 6374 | if (phone != null) { |
| 6375 | return phone.isImsRegistered(); |
| 6376 | } else { |
| 6377 | return false; |
| 6378 | } |
| 6379 | } |
| 6380 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6381 | @Override |
| 6382 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6383 | final long identity = Binder.clearCallingIdentity(); |
| 6384 | try { |
| 6385 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6386 | } finally { |
| 6387 | Binder.restoreCallingIdentity(identity); |
| 6388 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6389 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6390 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6391 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6392 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6393 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6394 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6395 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6396 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6397 | } |
| 6398 | final long identity = Binder.clearCallingIdentity(); |
| 6399 | try { |
| 6400 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6401 | } finally { |
| 6402 | Binder.restoreCallingIdentity(identity); |
| 6403 | } |
| 6404 | } |
| 6405 | |
| 6406 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6407 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6408 | final long identity = Binder.clearCallingIdentity(); |
| 6409 | try { |
| 6410 | Phone phone = getPhone(subscriptionId); |
| 6411 | if (phone == null) { |
| 6412 | return null; |
| 6413 | } |
| 6414 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6415 | } finally { |
| 6416 | Binder.restoreCallingIdentity(identity); |
| 6417 | } |
| 6418 | } |
| 6419 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6420 | /** |
| 6421 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6422 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6423 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6424 | final long identity = Binder.clearCallingIdentity(); |
| 6425 | try { |
| 6426 | Phone phone = getPhone(subId); |
| 6427 | if (phone != null) { |
| 6428 | return phone.isWifiCallingEnabled(); |
| 6429 | } else { |
| 6430 | return false; |
| 6431 | } |
| 6432 | } finally { |
| 6433 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6434 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6435 | } |
| 6436 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6437 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6438 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6439 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6440 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6441 | final long identity = Binder.clearCallingIdentity(); |
| 6442 | try { |
| 6443 | Phone phone = getPhone(subId); |
| 6444 | if (phone != null) { |
| 6445 | return phone.isVideoEnabled(); |
| 6446 | } else { |
| 6447 | return false; |
| 6448 | } |
| 6449 | } finally { |
| 6450 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6451 | } |
| 6452 | } |
| 6453 | |
| 6454 | /** |
| 6455 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6456 | * defined in {@link ImsRegistrationImplBase}. |
| 6457 | */ |
| 6458 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6459 | final long identity = Binder.clearCallingIdentity(); |
| 6460 | try { |
| 6461 | Phone phone = getPhone(subId); |
| 6462 | if (phone != null) { |
| 6463 | return phone.getImsRegistrationTech(); |
| 6464 | } else { |
| 6465 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6466 | } |
| 6467 | } finally { |
| 6468 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6469 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6470 | } |
| 6471 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6472 | @Override |
| 6473 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6474 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6475 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6476 | return; |
| 6477 | } |
| 6478 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6479 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6480 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6481 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6482 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6483 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6484 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6485 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6486 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6487 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6488 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6489 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6490 | // There has been issues when Sms raw table somehow stores orphan |
| 6491 | // fragments. They lead to garbled message when new fragments come |
| 6492 | // in and combined with those stale ones. In case this happens again, |
| 6493 | // user can reset all network settings which will clean up this table. |
| 6494 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6495 | // Clean up IMS settings as well here. |
| 6496 | int slotId = getSlotIndex(subId); |
| 6497 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6498 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6499 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6500 | |
| 6501 | // Erase modem config if erase modem on network setting is enabled. |
| 6502 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6503 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6504 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6505 | sendEraseModemConfig(getDefaultPhone()); |
| 6506 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6507 | } finally { |
| 6508 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6509 | } |
| 6510 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6511 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6512 | private void cleanUpSmsRawTable(Context context) { |
| 6513 | ContentResolver resolver = context.getContentResolver(); |
| 6514 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6515 | resolver.delete(uri, null, null); |
| 6516 | } |
| 6517 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6518 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6519 | public String getSimLocaleForSubscriber(int subId) { |
| 6520 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6521 | final Phone phone = getPhone(subId); |
| 6522 | if (phone == null) { |
| 6523 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6524 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6525 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6526 | final long identity = Binder.clearCallingIdentity(); |
| 6527 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6528 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6529 | phone.getContext().getOpPackageName(), null); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6530 | if (info == null) { |
| 6531 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6532 | return null; |
| 6533 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6534 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6535 | // preferences (EF-PL and EF-LI)... |
| 6536 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6537 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6538 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6539 | if (localeFromDefaultSim != null) { |
| 6540 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6541 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6542 | + localeFromDefaultSim); |
| 6543 | return localeFromDefaultSim.toLanguageTag(); |
| 6544 | } else { |
| 6545 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6546 | } |
| 6547 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6548 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6549 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6550 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6551 | // the SIM and carrier preferences does not include a country we add the country |
| 6552 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6553 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6554 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6555 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6556 | return mccLocale.toLanguageTag(); |
| 6557 | } |
| 6558 | |
| 6559 | if (DBG) log("No locale found - returning null"); |
| 6560 | return null; |
| 6561 | } finally { |
| 6562 | Binder.restoreCallingIdentity(identity); |
| 6563 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6564 | } |
| 6565 | |
| 6566 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6567 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 6568 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6569 | } |
| 6570 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6571 | /** |
| 6572 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6573 | */ |
| 6574 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6575 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 6576 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6577 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6578 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6579 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6580 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6581 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6582 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6583 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6584 | * representing the state of the modem. |
| 6585 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6586 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6587 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6588 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6589 | */ |
| 6590 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6591 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6592 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6593 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6594 | |
| 6595 | final long identity = Binder.clearCallingIdentity(); |
| 6596 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 6597 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6598 | } finally { |
| 6599 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6600 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6601 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6602 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6603 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6604 | // less than total activity duration. |
| 6605 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6606 | if (info == null) { |
| 6607 | return false; |
| 6608 | } |
| 6609 | int activityDurationMs = |
| 6610 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6611 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6612 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6613 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6614 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6615 | } |
| 6616 | return (info.isValid() |
| 6617 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6618 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6619 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6620 | && (totalTxTimeMs <= activityDurationMs)); |
| 6621 | } |
| 6622 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6623 | /** |
| 6624 | * {@hide} |
| 6625 | * Returns the service state information on specified subscription. |
| 6626 | */ |
| 6627 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6628 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6629 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6630 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6631 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6632 | return null; |
| 6633 | } |
| 6634 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6635 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6636 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6637 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6638 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6639 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6640 | .setCallingPid(Binder.getCallingPid()) |
| 6641 | .setCallingUid(Binder.getCallingUid()) |
| 6642 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6643 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6644 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6645 | .build()); |
| 6646 | |
| 6647 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6648 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6649 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6650 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6651 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6652 | .setCallingPid(Binder.getCallingPid()) |
| 6653 | .setCallingUid(Binder.getCallingUid()) |
| 6654 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6655 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6656 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6657 | .build()); |
| 6658 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6659 | boolean hasFinePermission = |
| 6660 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6661 | boolean hasCoarsePermission = |
| 6662 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6663 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6664 | final long identity = Binder.clearCallingIdentity(); |
| 6665 | try { |
| 6666 | final Phone phone = getPhone(subId); |
| 6667 | if (phone == null) { |
| 6668 | return null; |
| 6669 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6670 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6671 | ServiceState ss = phone.getServiceState(); |
| 6672 | |
| 6673 | // Scrub out the location info in ServiceState depending on what level of access |
| 6674 | // the caller has. |
| 6675 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6676 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6677 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6678 | } finally { |
| 6679 | Binder.restoreCallingIdentity(identity); |
| 6680 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6681 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6682 | |
| 6683 | /** |
| 6684 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6685 | * |
| 6686 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6687 | * voicemail ringtone. |
| 6688 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6689 | * PhoneAccount. |
| 6690 | */ |
| 6691 | @Override |
| 6692 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6693 | final long identity = Binder.clearCallingIdentity(); |
| 6694 | try { |
| 6695 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6696 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6697 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6698 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6699 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6700 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6701 | } finally { |
| 6702 | Binder.restoreCallingIdentity(identity); |
| 6703 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6704 | } |
| 6705 | |
| 6706 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6707 | * Sets the per-account voicemail ringtone. |
| 6708 | * |
| 6709 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6710 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6711 | * |
| 6712 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6713 | * voicemail ringtone. |
| 6714 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6715 | * PhoneAccount. |
| 6716 | */ |
| 6717 | @Override |
| 6718 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6719 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6720 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6721 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6722 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6723 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6724 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6725 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6726 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6727 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6728 | |
| 6729 | final long identity = Binder.clearCallingIdentity(); |
| 6730 | try { |
| 6731 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6732 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6733 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6734 | } |
| 6735 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6736 | } finally { |
| 6737 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6738 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6739 | } |
| 6740 | |
| 6741 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6742 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6743 | * |
| 6744 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6745 | * voicemail vibration setting. |
| 6746 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6747 | */ |
| 6748 | @Override |
| 6749 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6750 | final long identity = Binder.clearCallingIdentity(); |
| 6751 | try { |
| 6752 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6753 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6754 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6755 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6756 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6757 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6758 | } finally { |
| 6759 | Binder.restoreCallingIdentity(identity); |
| 6760 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6761 | } |
| 6762 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6763 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6764 | * Sets the per-account voicemail vibration. |
| 6765 | * |
| 6766 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6767 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6768 | * |
| 6769 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6770 | * voicemail vibration setting. |
| 6771 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6772 | * specific PhoneAccount. |
| 6773 | */ |
| 6774 | @Override |
| 6775 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6776 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6777 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6778 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6779 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6780 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6781 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6782 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6783 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6784 | } |
| 6785 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6786 | final long identity = Binder.clearCallingIdentity(); |
| 6787 | try { |
| 6788 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6789 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6790 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6791 | } |
| 6792 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6793 | } finally { |
| 6794 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6795 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6796 | } |
| 6797 | |
| 6798 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6799 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6800 | * |
| 6801 | * @throws SecurityException if the caller does not have the required permission |
| 6802 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6803 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6804 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6805 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6806 | } |
| 6807 | |
| 6808 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6809 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6810 | * permission. |
| 6811 | * |
| 6812 | * @throws SecurityException if the caller does not have the required permission |
| 6813 | */ |
| 6814 | private void enforceSendSmsPermission() { |
| 6815 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6816 | } |
| 6817 | |
| 6818 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6819 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6820 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6821 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6822 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6823 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6824 | final long identity = Binder.clearCallingIdentity(); |
| 6825 | try { |
| 6826 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6827 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6828 | if (componentName == null) { |
| 6829 | throw new SecurityException( |
| 6830 | "Caller not current active visual voicemail package[null]"); |
| 6831 | } |
| 6832 | String vvmPackage = componentName.getPackageName(); |
| 6833 | if (!callingPackage.equals(vvmPackage)) { |
| 6834 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6835 | + vvmPackage + "]"); |
| 6836 | } |
| 6837 | } finally { |
| 6838 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6839 | } |
| 6840 | } |
| 6841 | |
| 6842 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6843 | * Return the application ID for the app type. |
| 6844 | * |
| 6845 | * @param subId the subscription ID that this request applies to. |
| 6846 | * @param appType the uicc app type. |
| 6847 | * @return Application ID for specificied app type, or null if no uicc. |
| 6848 | */ |
| 6849 | @Override |
| 6850 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6851 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6852 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6853 | |
| 6854 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6855 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6856 | if (phone == null) { |
| 6857 | return null; |
| 6858 | } |
| 6859 | String aid = null; |
| 6860 | try { |
| 6861 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6862 | .getApplicationByType(appType).getAid(); |
| 6863 | } catch (Exception e) { |
| 6864 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6865 | } |
| 6866 | return aid; |
| 6867 | } finally { |
| 6868 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6869 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6870 | } |
| 6871 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6872 | /** |
| 6873 | * Return the Electronic Serial Number. |
| 6874 | * |
| 6875 | * @param subId the subscription ID that this request applies to. |
| 6876 | * @return ESN or null if error. |
| 6877 | */ |
| 6878 | @Override |
| 6879 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6880 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6881 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6882 | |
| 6883 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6884 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6885 | if (phone == null) { |
| 6886 | return null; |
| 6887 | } |
| 6888 | String esn = null; |
| 6889 | try { |
| 6890 | esn = phone.getEsn(); |
| 6891 | } catch (Exception e) { |
| 6892 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6893 | } |
| 6894 | return esn; |
| 6895 | } finally { |
| 6896 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6897 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6898 | } |
| 6899 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6900 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6901 | * Return the Preferred Roaming List Version. |
| 6902 | * |
| 6903 | * @param subId the subscription ID that this request applies to. |
| 6904 | * @return PRLVersion or null if error. |
| 6905 | */ |
| 6906 | @Override |
| 6907 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6908 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6909 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6910 | |
| 6911 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6912 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6913 | if (phone == null) { |
| 6914 | return null; |
| 6915 | } |
| 6916 | String cdmaPrlVersion = null; |
| 6917 | try { |
| 6918 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6919 | } catch (Exception e) { |
| 6920 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6921 | } |
| 6922 | return cdmaPrlVersion; |
| 6923 | } finally { |
| 6924 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6925 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6926 | } |
| 6927 | |
| 6928 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6929 | * Get snapshot of Telephony histograms |
| 6930 | * @return List of Telephony histograms |
| 6931 | * @hide |
| 6932 | */ |
| 6933 | @Override |
| 6934 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6935 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6936 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6937 | |
| 6938 | final long identity = Binder.clearCallingIdentity(); |
| 6939 | try { |
| 6940 | return RIL.getTelephonyRILTimingHistograms(); |
| 6941 | } finally { |
| 6942 | Binder.restoreCallingIdentity(identity); |
| 6943 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6944 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6945 | |
| 6946 | /** |
| 6947 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6948 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6949 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6950 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6951 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6952 | * @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] | 6953 | */ |
| 6954 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6955 | @TelephonyManager.SetCarrierRestrictionResult |
| 6956 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6957 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6958 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6959 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6960 | if (carrierRestrictionRules == null) { |
| 6961 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6962 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6963 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6964 | final long identity = Binder.clearCallingIdentity(); |
| 6965 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6966 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6967 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6968 | } finally { |
| 6969 | Binder.restoreCallingIdentity(identity); |
| 6970 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6971 | } |
| 6972 | |
| 6973 | /** |
| 6974 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6975 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6976 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6977 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6978 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6979 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6980 | */ |
| 6981 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6982 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6983 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6984 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6985 | |
| 6986 | final long identity = Binder.clearCallingIdentity(); |
| 6987 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6988 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 6989 | if (response instanceof CarrierRestrictionRules) { |
| 6990 | return (CarrierRestrictionRules) response; |
| 6991 | } |
| 6992 | // Response is an Exception of some kind, |
| 6993 | // which is signalled to the user as a NULL retval |
| 6994 | return null; |
| 6995 | } catch (Exception e) { |
| 6996 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 6997 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6998 | } finally { |
| 6999 | Binder.restoreCallingIdentity(identity); |
| 7000 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7001 | } |
| 7002 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7003 | /** |
| 7004 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 7005 | * @param subId the subscription ID that this action applies to. |
| 7006 | * @param enabled control enable or disable metered apns. |
| 7007 | * {@hide} |
| 7008 | */ |
| 7009 | @Override |
| 7010 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 7011 | enforceModifyPermission(); |
| 7012 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7013 | |
| 7014 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7015 | if (phone == null) { |
| 7016 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 7017 | return; |
| 7018 | } |
| 7019 | try { |
| 7020 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7021 | } catch (Exception e) { |
| 7022 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7023 | } finally { |
| 7024 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7025 | } |
| 7026 | } |
| 7027 | |
| 7028 | /** |
| 7029 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7030 | * @param subId the subscription ID that this action applies to. |
| 7031 | * @param enabled control enable or disable radio. |
| 7032 | * {@hide} |
| 7033 | */ |
| 7034 | @Override |
| 7035 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7036 | enforceModifyPermission(); |
| 7037 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7038 | |
| 7039 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7040 | if (phone == null) { |
| 7041 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7042 | return; |
| 7043 | } |
| 7044 | try { |
| 7045 | phone.carrierActionSetRadioEnabled(enabled); |
| 7046 | } catch (Exception e) { |
| 7047 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7048 | } finally { |
| 7049 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7050 | } |
| 7051 | } |
| 7052 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7053 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7054 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7055 | * network status based on which carrier apps could apply actions accordingly, |
| 7056 | * enable/disable default url handler for example. |
| 7057 | * |
| 7058 | * @param subId the subscription ID that this action applies to. |
| 7059 | * @param report control start/stop reporting the default network status. |
| 7060 | * {@hide} |
| 7061 | */ |
| 7062 | @Override |
| 7063 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7064 | enforceModifyPermission(); |
| 7065 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7066 | |
| 7067 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7068 | if (phone == null) { |
| 7069 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7070 | return; |
| 7071 | } |
| 7072 | try { |
| 7073 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7074 | } catch (Exception e) { |
| 7075 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7076 | } finally { |
| 7077 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7078 | } |
| 7079 | } |
| 7080 | |
| 7081 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7082 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7083 | * @param subId the subscription ID that this action applies to. |
| 7084 | * {@hide} |
| 7085 | */ |
| 7086 | @Override |
| 7087 | public void carrierActionResetAll(int subId) { |
| 7088 | enforceModifyPermission(); |
| 7089 | final Phone phone = getPhone(subId); |
| 7090 | if (phone == null) { |
| 7091 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7092 | return; |
| 7093 | } |
| 7094 | try { |
| 7095 | phone.carrierActionResetAll(); |
| 7096 | } catch (Exception e) { |
| 7097 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7098 | } |
| 7099 | } |
| 7100 | |
| 7101 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7102 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7103 | * bug report is being generated. |
| 7104 | */ |
| 7105 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7106 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7107 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7108 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7109 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7110 | + Binder.getCallingPid() |
| 7111 | + ", uid=" + Binder.getCallingUid() |
| 7112 | + "without permission " |
| 7113 | + android.Manifest.permission.DUMP); |
| 7114 | return; |
| 7115 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7116 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7117 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7118 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7119 | @Override |
| 7120 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 7121 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 7122 | throws RemoteException { |
Torbjorn Eklund | 1050cb0 | 2018-11-16 14:05:38 +0100 | [diff] [blame] | 7123 | (new TelephonyShellCommand(this, getDefaultPhone().getContext())) |
| 7124 | .exec(this, in, out, err, args, callback, resultReceiver); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7125 | } |
| 7126 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7127 | /** |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7128 | * Policy control of data connection. Usually used when data limit is passed. |
| 7129 | * @param enabled True if enabling the data, otherwise disabling. |
| 7130 | * @param subId Subscription index |
| 7131 | * {@hide} |
| 7132 | */ |
| 7133 | @Override |
| 7134 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 7135 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7136 | |
| 7137 | final long identity = Binder.clearCallingIdentity(); |
| 7138 | try { |
| 7139 | Phone phone = getPhone(subId); |
| 7140 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 7141 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7142 | } |
| 7143 | } finally { |
| 7144 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7145 | } |
| 7146 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7147 | |
| 7148 | /** |
| 7149 | * Get Client request stats |
| 7150 | * @return List of Client Request Stats |
| 7151 | * @hide |
| 7152 | */ |
| 7153 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7154 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7155 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7156 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7157 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7158 | return null; |
| 7159 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7160 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7161 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7162 | final long identity = Binder.clearCallingIdentity(); |
| 7163 | try { |
| 7164 | if (phone != null) { |
| 7165 | return phone.getClientRequestStats(); |
| 7166 | } |
| 7167 | |
| 7168 | return null; |
| 7169 | } finally { |
| 7170 | Binder.restoreCallingIdentity(identity); |
| 7171 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7172 | } |
| 7173 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7174 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7175 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7176 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7177 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7178 | |
| 7179 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7180 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7181 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7182 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7183 | * @param state State of SIM (power down, power up, pass through) |
| 7184 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7185 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7186 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7187 | * |
| 7188 | **/ |
| 7189 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7190 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7191 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7192 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7193 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7194 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7195 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7196 | final long identity = Binder.clearCallingIdentity(); |
| 7197 | try { |
| 7198 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7199 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7200 | } |
| 7201 | } finally { |
| 7202 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7203 | } |
| 7204 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7205 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7206 | private boolean isUssdApiAllowed(int subId) { |
| 7207 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7208 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7209 | if (configManager == null) { |
| 7210 | return false; |
| 7211 | } |
| 7212 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7213 | if (pb == null) { |
| 7214 | return false; |
| 7215 | } |
| 7216 | return pb.getBoolean( |
| 7217 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7218 | } |
| 7219 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7220 | /** |
| 7221 | * Check if phone is in emergency callback mode |
| 7222 | * @return true if phone is in emergency callback mode |
| 7223 | * @param subId sub id |
| 7224 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7225 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7226 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7227 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7228 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7229 | |
| 7230 | final long identity = Binder.clearCallingIdentity(); |
| 7231 | try { |
| 7232 | if (phone != null) { |
| 7233 | return phone.isInEcm(); |
| 7234 | } else { |
| 7235 | return false; |
| 7236 | } |
| 7237 | } finally { |
| 7238 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7239 | } |
| 7240 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7241 | |
| 7242 | /** |
| 7243 | * Get the current signal strength information for the given subscription. |
| 7244 | * Because this information is not updated when the device is in a low power state |
| 7245 | * it should not be relied-upon to be current. |
| 7246 | * @param subId Subscription index |
| 7247 | * @return the most recent cached signal strength info from the modem |
| 7248 | */ |
| 7249 | @Override |
| 7250 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7251 | final long identity = Binder.clearCallingIdentity(); |
| 7252 | try { |
| 7253 | Phone p = getPhone(subId); |
| 7254 | if (p == null) { |
| 7255 | return null; |
| 7256 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7257 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7258 | return p.getSignalStrength(); |
| 7259 | } finally { |
| 7260 | Binder.restoreCallingIdentity(identity); |
| 7261 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7262 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7263 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7264 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7265 | * Get the current modem radio state for the given slot. |
| 7266 | * @param slotIndex slot index. |
| 7267 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7268 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7269 | * @return the current radio power state from the modem |
| 7270 | */ |
| 7271 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7272 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7273 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7274 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7275 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7276 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7277 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7278 | } |
| 7279 | |
| 7280 | final long identity = Binder.clearCallingIdentity(); |
| 7281 | try { |
| 7282 | return phone.getRadioPowerState(); |
| 7283 | } finally { |
| 7284 | Binder.restoreCallingIdentity(identity); |
| 7285 | } |
| 7286 | } |
| 7287 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7288 | } |
| 7289 | |
| 7290 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7291 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7292 | * |
| 7293 | * <p>Requires one of the following permissions: |
| 7294 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7295 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7296 | * privileges. |
| 7297 | * |
| 7298 | * @param subId subscription id |
| 7299 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7300 | * {@code false}. |
| 7301 | */ |
| 7302 | @Override |
| 7303 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7304 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7305 | null /* message */); |
| 7306 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7307 | boolean isEnabled = false; |
| 7308 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7309 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7310 | Phone phone = getPhone(subId); |
| 7311 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7312 | } catch (Exception e) { |
| 7313 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7314 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7315 | } finally { |
| 7316 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7317 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7318 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7319 | } |
| 7320 | |
| 7321 | |
| 7322 | /** |
| 7323 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7324 | * |
| 7325 | * <p> Requires permission: |
| 7326 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7327 | * privileges. |
| 7328 | * |
| 7329 | * @param subId subscription id |
| 7330 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7331 | */ |
| 7332 | @Override |
| 7333 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7334 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7335 | mApp, subId, "setDataRoamingEnabled"); |
| 7336 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7337 | final long identity = Binder.clearCallingIdentity(); |
| 7338 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7339 | Phone phone = getPhone(subId); |
| 7340 | if (phone != null) { |
| 7341 | phone.setDataRoamingEnabled(isEnabled); |
| 7342 | } |
| 7343 | } finally { |
| 7344 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7345 | } |
| 7346 | } |
| 7347 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7348 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7349 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7350 | TelephonyPermissions |
| 7351 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7352 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7353 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7354 | boolean isAllowed = true; |
| 7355 | final long identity = Binder.clearCallingIdentity(); |
| 7356 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7357 | Phone phone = getPhone(subId); |
| 7358 | if (phone != null) { |
| 7359 | isAllowed = phone.isCspPlmnEnabled(); |
| 7360 | } |
| 7361 | } finally { |
| 7362 | Binder.restoreCallingIdentity(identity); |
| 7363 | } |
| 7364 | return isAllowed; |
| 7365 | } |
| 7366 | |
| 7367 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7368 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7369 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7370 | try { |
| 7371 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7372 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7373 | } catch (SecurityException e) { |
| 7374 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7375 | // has carrier privileges on an active UICC |
| 7376 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7377 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7378 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7379 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7380 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7381 | |
| 7382 | final long identity = Binder.clearCallingIdentity(); |
| 7383 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7384 | UiccController uiccController = UiccController.getInstance(); |
| 7385 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7386 | if (hasReadPermission) { |
| 7387 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7388 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7389 | |
| 7390 | // Remove private info if the caller doesn't have access |
| 7391 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7392 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7393 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7394 | // is available |
| 7395 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7396 | if (card == null || card.getUiccProfile() == null) { |
| 7397 | // assume no access if the card or profile is unavailable |
| 7398 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7399 | continue; |
| 7400 | } |
| 7401 | UiccProfile profile = card.getUiccProfile(); |
| 7402 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7403 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7404 | filteredInfos.add(cardInfo); |
| 7405 | } else { |
| 7406 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7407 | } |
| 7408 | } |
| 7409 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7410 | } finally { |
| 7411 | Binder.restoreCallingIdentity(identity); |
| 7412 | } |
| 7413 | } |
| 7414 | |
| 7415 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7416 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7417 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7418 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7419 | final long identity = Binder.clearCallingIdentity(); |
| 7420 | try { |
| 7421 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7422 | if (slots == null) { |
| 7423 | Rlog.i(LOG_TAG, "slots is null."); |
| 7424 | return null; |
| 7425 | } |
| 7426 | |
| 7427 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7428 | for (int i = 0; i < slots.length; i++) { |
| 7429 | UiccSlot slot = slots[i]; |
| 7430 | if (slot == null) { |
| 7431 | continue; |
| 7432 | } |
| 7433 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7434 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7435 | UiccCard card = slot.getUiccCard(); |
| 7436 | if (card != null) { |
| 7437 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7438 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7439 | cardId = slot.getEid(); |
| 7440 | if (TextUtils.isEmpty(cardId)) { |
| 7441 | cardId = slot.getIccId(); |
| 7442 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7443 | } |
| 7444 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7445 | if (cardId != null) { |
| 7446 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7447 | // if cardId is an EID, it's all digits so this is fine |
| 7448 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7449 | } |
| 7450 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7451 | int cardState = 0; |
| 7452 | switch (slot.getCardState()) { |
| 7453 | case CARDSTATE_ABSENT: |
| 7454 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7455 | break; |
| 7456 | case CARDSTATE_PRESENT: |
| 7457 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7458 | break; |
| 7459 | case CARDSTATE_ERROR: |
| 7460 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7461 | break; |
| 7462 | case CARDSTATE_RESTRICTED: |
| 7463 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7464 | break; |
| 7465 | default: |
| 7466 | break; |
| 7467 | |
| 7468 | } |
| 7469 | |
| 7470 | infos[i] = new UiccSlotInfo( |
| 7471 | slot.isActive(), |
| 7472 | slot.isEuicc(), |
| 7473 | cardId, |
| 7474 | cardState, |
| 7475 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7476 | slot.isExtendedApduSupported(), |
| 7477 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7478 | } |
| 7479 | return infos; |
| 7480 | } finally { |
| 7481 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7482 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7483 | } |
| 7484 | |
| 7485 | @Override |
| 7486 | public boolean switchSlots(int[] physicalSlots) { |
| 7487 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7488 | |
| 7489 | final long identity = Binder.clearCallingIdentity(); |
| 7490 | try { |
| 7491 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7492 | } finally { |
| 7493 | Binder.restoreCallingIdentity(identity); |
| 7494 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7495 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7496 | |
| 7497 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7498 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7499 | final long identity = Binder.clearCallingIdentity(); |
| 7500 | try { |
| 7501 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7502 | } finally { |
| 7503 | Binder.restoreCallingIdentity(identity); |
| 7504 | } |
| 7505 | } |
| 7506 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7507 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7508 | * A test API to reload the UICC profile. |
| 7509 | * |
| 7510 | * <p>Requires that the calling app has permission |
| 7511 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7512 | * @hide |
| 7513 | */ |
| 7514 | @Override |
| 7515 | public void refreshUiccProfile(int subId) { |
| 7516 | enforceModifyPermission(); |
| 7517 | |
| 7518 | final long identity = Binder.clearCallingIdentity(); |
| 7519 | try { |
| 7520 | Phone phone = getPhone(subId); |
| 7521 | if (phone == null) { |
| 7522 | return; |
| 7523 | } |
| 7524 | UiccCard uiccCard = phone.getUiccCard(); |
| 7525 | if (uiccCard == null) { |
| 7526 | return; |
| 7527 | } |
| 7528 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7529 | if (uiccProfile == null) { |
| 7530 | return; |
| 7531 | } |
| 7532 | uiccProfile.refresh(); |
| 7533 | } finally { |
| 7534 | Binder.restoreCallingIdentity(identity); |
| 7535 | } |
| 7536 | } |
| 7537 | |
| 7538 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7539 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7540 | */ |
| 7541 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7542 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7543 | } |
| 7544 | |
| 7545 | /** |
| 7546 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7547 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7548 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7549 | */ |
| 7550 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7551 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7552 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7553 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7554 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7555 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7556 | return isDataRoamingEnabled; |
| 7557 | } |
| 7558 | |
| 7559 | /** |
| 7560 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7561 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7562 | */ |
| 7563 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7564 | List<Integer> list = TelephonyProperties.default_network(); |
| 7565 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7566 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7567 | return list.get(phoneId); |
| 7568 | } |
| 7569 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7570 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7571 | |
| 7572 | @Override |
| 7573 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7574 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7575 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7576 | |
| 7577 | final long identity = Binder.clearCallingIdentity(); |
| 7578 | try { |
| 7579 | final Phone phone = getPhone(subId); |
| 7580 | if (phone == null) { |
| 7581 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7582 | return; |
| 7583 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7584 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7585 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7586 | } finally { |
| 7587 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7588 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7589 | } |
| 7590 | |
| 7591 | @Override |
| 7592 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7593 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7594 | |
| 7595 | final long identity = Binder.clearCallingIdentity(); |
| 7596 | try { |
| 7597 | final Phone phone = getPhone(subId); |
| 7598 | if (phone == null) { |
| 7599 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7600 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7601 | } |
| 7602 | return phone.getCarrierIdListVersion(); |
| 7603 | } finally { |
| 7604 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7605 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7606 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7607 | |
| 7608 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7609 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7610 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7611 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7612 | mApp, subId, callingPackage, callingFeatureId, |
| 7613 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7614 | return -1; |
| 7615 | } |
| 7616 | |
| 7617 | final long identity = Binder.clearCallingIdentity(); |
| 7618 | try { |
| 7619 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7620 | } finally { |
| 7621 | Binder.restoreCallingIdentity(identity); |
| 7622 | } |
| 7623 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7624 | |
| 7625 | @Override |
| 7626 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7627 | TelephonyPermissions |
| 7628 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7629 | mApp, subId, "getCdmaRoamingMode"); |
| 7630 | |
| 7631 | final long identity = Binder.clearCallingIdentity(); |
| 7632 | try { |
| 7633 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7634 | } finally { |
| 7635 | Binder.restoreCallingIdentity(identity); |
| 7636 | } |
| 7637 | } |
| 7638 | |
| 7639 | @Override |
| 7640 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7641 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7642 | mApp, subId, "setCdmaRoamingMode"); |
| 7643 | |
| 7644 | final long identity = Binder.clearCallingIdentity(); |
| 7645 | try { |
| 7646 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7647 | } finally { |
| 7648 | Binder.restoreCallingIdentity(identity); |
| 7649 | } |
| 7650 | } |
| 7651 | |
| 7652 | @Override |
| 7653 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7654 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7655 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7656 | |
| 7657 | final long identity = Binder.clearCallingIdentity(); |
| 7658 | try { |
| 7659 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7660 | } finally { |
| 7661 | Binder.restoreCallingIdentity(identity); |
| 7662 | } |
| 7663 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7664 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7665 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7666 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7667 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7668 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7669 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7670 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7671 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7672 | } |
| 7673 | final long identity = Binder.clearCallingIdentity(); |
| 7674 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7675 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7676 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7677 | if (phone.getEmergencyNumberTracker() != null |
| 7678 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7679 | emergencyNumberListInternal.put( |
| 7680 | phone.getSubId(), |
| 7681 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7682 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7683 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7684 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7685 | } finally { |
| 7686 | Binder.restoreCallingIdentity(identity); |
| 7687 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7688 | } |
| 7689 | |
| 7690 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7691 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7692 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7693 | if (!exactMatch) { |
| 7694 | TelephonyPermissions |
| 7695 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7696 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7697 | } |
| 7698 | final long identity = Binder.clearCallingIdentity(); |
| 7699 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7700 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7701 | if (phone.getEmergencyNumberTracker() != null |
| 7702 | && phone.getEmergencyNumberTracker() != null) { |
| 7703 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7704 | number, exactMatch)) { |
| 7705 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7706 | } |
| 7707 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7708 | } |
| 7709 | return false; |
| 7710 | } finally { |
| 7711 | Binder.restoreCallingIdentity(identity); |
| 7712 | } |
| 7713 | } |
| 7714 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7715 | /** |
| 7716 | * Update emergency number list for test mode. |
| 7717 | */ |
| 7718 | @Override |
| 7719 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7720 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7721 | "updateEmergencyNumberListTestMode"); |
| 7722 | |
| 7723 | final long identity = Binder.clearCallingIdentity(); |
| 7724 | try { |
| 7725 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7726 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7727 | if (tracker != null) { |
| 7728 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7729 | } |
| 7730 | } |
| 7731 | } finally { |
| 7732 | Binder.restoreCallingIdentity(identity); |
| 7733 | } |
| 7734 | } |
| 7735 | |
| 7736 | /** |
| 7737 | * Get the full emergency number list for test mode. |
| 7738 | */ |
| 7739 | @Override |
| 7740 | public List<String> getEmergencyNumberListTestMode() { |
| 7741 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7742 | "getEmergencyNumberListTestMode"); |
| 7743 | |
| 7744 | final long identity = Binder.clearCallingIdentity(); |
| 7745 | try { |
| 7746 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7747 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7748 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7749 | if (tracker != null) { |
| 7750 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7751 | emergencyNumbers.add(num.getNumber()); |
| 7752 | } |
| 7753 | } |
| 7754 | } |
| 7755 | return new ArrayList<>(emergencyNumbers); |
| 7756 | } finally { |
| 7757 | Binder.restoreCallingIdentity(identity); |
| 7758 | } |
| 7759 | } |
| 7760 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7761 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7762 | public int getEmergencyNumberDbVersion(int subId) { |
| 7763 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7764 | |
| 7765 | final long identity = Binder.clearCallingIdentity(); |
| 7766 | try { |
| 7767 | final Phone phone = getPhone(subId); |
| 7768 | if (phone == null) { |
| 7769 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7770 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7771 | } |
| 7772 | return phone.getEmergencyNumberDbVersion(); |
| 7773 | } finally { |
| 7774 | Binder.restoreCallingIdentity(identity); |
| 7775 | } |
| 7776 | } |
| 7777 | |
| 7778 | @Override |
| 7779 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7780 | enforceModifyPermission(); |
| 7781 | |
| 7782 | final long identity = Binder.clearCallingIdentity(); |
| 7783 | try { |
| 7784 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7785 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7786 | if (tracker != null) { |
| 7787 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7788 | } |
| 7789 | } |
| 7790 | } finally { |
| 7791 | Binder.restoreCallingIdentity(identity); |
| 7792 | } |
| 7793 | } |
| 7794 | |
| 7795 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 7796 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7797 | enforceActiveEmergencySessionPermission(); |
| 7798 | |
| 7799 | final long identity = Binder.clearCallingIdentity(); |
| 7800 | try { |
| 7801 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7802 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7803 | if (tracker != null) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 7804 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 7805 | } |
| 7806 | } |
| 7807 | } finally { |
| 7808 | Binder.restoreCallingIdentity(identity); |
| 7809 | } |
| 7810 | } |
| 7811 | |
| 7812 | @Override |
| 7813 | public void resetOtaEmergencyNumberDbFilePath() { |
| 7814 | enforceActiveEmergencySessionPermission(); |
| 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.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7822 | } |
| 7823 | } |
| 7824 | } finally { |
| 7825 | Binder.restoreCallingIdentity(identity); |
| 7826 | } |
| 7827 | } |
| 7828 | |
| 7829 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7830 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7831 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7832 | Phone phone = getPhone(subId); |
| 7833 | if (phone == null) { |
| 7834 | return null; |
| 7835 | } |
| 7836 | final long identity = Binder.clearCallingIdentity(); |
| 7837 | try { |
| 7838 | UiccProfile profile = UiccController.getInstance() |
| 7839 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7840 | if (profile != null) { |
| 7841 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7842 | } |
| 7843 | } finally { |
| 7844 | Binder.restoreCallingIdentity(identity); |
| 7845 | } |
| 7846 | return null; |
| 7847 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7848 | |
| 7849 | /** |
| 7850 | * Enable or disable a modem stack. |
| 7851 | */ |
| 7852 | @Override |
| 7853 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7854 | enforceModifyPermission(); |
| 7855 | |
| 7856 | final long identity = Binder.clearCallingIdentity(); |
| 7857 | try { |
| 7858 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7859 | if (phone == null) { |
| 7860 | return false; |
| 7861 | } else { |
| 7862 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7863 | } |
| 7864 | } finally { |
| 7865 | Binder.restoreCallingIdentity(identity); |
| 7866 | } |
| 7867 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7868 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7869 | /** |
| 7870 | * Whether a modem stack is enabled or not. |
| 7871 | */ |
| 7872 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7873 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7874 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7875 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7876 | if (phone == null) return false; |
| 7877 | |
| 7878 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7879 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7880 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7881 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7882 | } |
| 7883 | |
| 7884 | final long identity = Binder.clearCallingIdentity(); |
| 7885 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7886 | try { |
| 7887 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7888 | } catch (NoSuchElementException ex) { |
| 7889 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7890 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7891 | } finally { |
| 7892 | Binder.restoreCallingIdentity(identity); |
| 7893 | } |
| 7894 | } |
| 7895 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7896 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7897 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7898 | enforceModifyPermission(); |
| 7899 | |
| 7900 | final long identity = Binder.clearCallingIdentity(); |
| 7901 | try { |
| 7902 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7903 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7904 | .commit(); |
| 7905 | } finally { |
| 7906 | Binder.restoreCallingIdentity(identity); |
| 7907 | } |
| 7908 | } |
| 7909 | |
| 7910 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7911 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7912 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7913 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7914 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 7915 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7916 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7917 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7918 | |
| 7919 | final long identity = Binder.clearCallingIdentity(); |
| 7920 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7921 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7922 | } finally { |
| 7923 | Binder.restoreCallingIdentity(identity); |
| 7924 | } |
| 7925 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7926 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7927 | @TelephonyManager.IsMultiSimSupportedResult |
| 7928 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7929 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7930 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7931 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7932 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7933 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7934 | } |
| 7935 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7936 | // supported by the modem, indicate that it is restricted. |
| 7937 | PhoneCapability staticCapability = |
| 7938 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7939 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7940 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7941 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7942 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 7943 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7944 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7945 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7946 | } |
| 7947 | // Check if support of multiple SIMs is restricted by carrier |
| 7948 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7949 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7950 | } |
| 7951 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7952 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7953 | } |
| 7954 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7955 | /** |
| 7956 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7957 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7958 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7959 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7960 | * @param numOfSims number of active sims we want to switch to |
| 7961 | */ |
| 7962 | @Override |
| 7963 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7964 | if (numOfSims == 1) { |
| 7965 | enforceModifyPermission(); |
| 7966 | } else { |
| 7967 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7968 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7969 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7970 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7971 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7972 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7973 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7974 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7975 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7976 | return; |
| 7977 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7978 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7979 | } finally { |
| 7980 | Binder.restoreCallingIdentity(identity); |
| 7981 | } |
| 7982 | } |
| 7983 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 7984 | @Override |
| 7985 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 7986 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 7987 | Phone phone = getPhone(subId); |
| 7988 | if (phone == null) { |
| 7989 | return false; |
| 7990 | } |
| 7991 | final long identity = Binder.clearCallingIdentity(); |
| 7992 | try { |
| 7993 | UiccCard uiccCard = phone.getUiccCard(); |
| 7994 | if (uiccCard == null) { |
| 7995 | return false; |
| 7996 | } |
| 7997 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7998 | if (uiccProfile == null) { |
| 7999 | return false; |
| 8000 | } |
| 8001 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8002 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8003 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8004 | } |
| 8005 | return false; |
| 8006 | } finally { |
| 8007 | Binder.restoreCallingIdentity(identity); |
| 8008 | } |
| 8009 | } |
| 8010 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8011 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8012 | * Get whether making changes to modem configurations will trigger reboot. |
| 8013 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8014 | */ |
| 8015 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8016 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8017 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8018 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8019 | mApp, subId, callingPackage, callingFeatureId, |
| 8020 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8021 | return false; |
| 8022 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8023 | final long identity = Binder.clearCallingIdentity(); |
| 8024 | try { |
| 8025 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8026 | } finally { |
| 8027 | Binder.restoreCallingIdentity(identity); |
| 8028 | } |
| 8029 | } |
| 8030 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8031 | private void updateModemStateMetrics() { |
| 8032 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8033 | // TODO: check the state for each modem if the api is ready. |
| 8034 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8035 | } |
| 8036 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8037 | @Override |
| 8038 | public int[] getSlotsMapping() { |
| 8039 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8040 | |
| 8041 | final long identity = Binder.clearCallingIdentity(); |
| 8042 | try { |
| 8043 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8044 | // All logical slots should have a mapping to a physical slot. |
| 8045 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8046 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8047 | for (int i = 0; i < slotInfos.length; i++) { |
| 8048 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8049 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8050 | } |
| 8051 | } |
| 8052 | return logicalSlotsMapping; |
| 8053 | } finally { |
| 8054 | Binder.restoreCallingIdentity(identity); |
| 8055 | } |
| 8056 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8057 | |
| 8058 | /** |
| 8059 | * Get the IRadio HAL Version |
| 8060 | */ |
| 8061 | @Override |
| 8062 | public int getRadioHalVersion() { |
| 8063 | Phone phone = getDefaultPhone(); |
| 8064 | if (phone == null) return -1; |
| 8065 | HalVersion hv = phone.getHalVersion(); |
| 8066 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8067 | return hv.major * 100 + hv.minor; |
| 8068 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8069 | |
| 8070 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8071 | * Get the current calling package name. |
| 8072 | * @return the current calling package name |
| 8073 | */ |
| 8074 | @Override |
| 8075 | public String getCurrentPackageName() { |
| 8076 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8077 | } |
| 8078 | |
| 8079 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8080 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8081 | * corresponding network requests on a subId. |
| 8082 | * |
| 8083 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8084 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8085 | * 2) APN is un-metered for this subscription, or |
| 8086 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8087 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8088 | * |
| 8089 | * @return whether data is allowed for a apn type. |
| 8090 | * |
| 8091 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8092 | */ |
| 8093 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8094 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8095 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8096 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8097 | |
| 8098 | // Now that all security checks passes, perform the operation as ourselves. |
| 8099 | final long identity = Binder.clearCallingIdentity(); |
| 8100 | try { |
| 8101 | Phone phone = getPhone(subId); |
| 8102 | if (phone == null) return false; |
| 8103 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8104 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8105 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8106 | } finally { |
| 8107 | Binder.restoreCallingIdentity(identity); |
| 8108 | } |
| 8109 | } |
| 8110 | |
| 8111 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8112 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8113 | enforceReadPrivilegedPermission("isApnMetered"); |
| 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 true; // By default return true. |
| 8120 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8121 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8122 | } finally { |
| 8123 | Binder.restoreCallingIdentity(identity); |
| 8124 | } |
| 8125 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8126 | |
| 8127 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8128 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8129 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8130 | enforceModifyPermission(); |
| 8131 | long token = Binder.clearCallingIdentity(); |
| 8132 | try { |
| 8133 | Phone phone = getPhone(subscriptionId); |
| 8134 | if (phone == null) { |
| 8135 | try { |
| 8136 | if (resultCallback != null) { |
| 8137 | resultCallback.accept(false); |
| 8138 | } |
| 8139 | } catch (RemoteException e) { |
| 8140 | // ignore |
| 8141 | } |
| 8142 | return; |
| 8143 | } |
| 8144 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8145 | Pair.create(specifiers, (x) -> { |
| 8146 | try { |
| 8147 | if (resultCallback != null) { |
| 8148 | resultCallback.accept(x); |
| 8149 | } |
| 8150 | } catch (RemoteException e) { |
| 8151 | // ignore |
| 8152 | } |
| 8153 | }); |
| 8154 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8155 | } finally { |
| 8156 | Binder.restoreCallingIdentity(token); |
| 8157 | } |
| 8158 | } |
| 8159 | |
| 8160 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8161 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
| 8162 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8163 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8164 | if (iccRecords == null) { |
| 8165 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8166 | return false; |
| 8167 | } |
| 8168 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8169 | } |
| 8170 | |
| 8171 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8172 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 8173 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8174 | if (callingPackage == null) { |
| 8175 | callingPackage = getCurrentPackageName(); |
| 8176 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8177 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8178 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8179 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 8180 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8181 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8182 | } |
| 8183 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8184 | Intent intent = new Intent(); |
| 8185 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8186 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8187 | // Bring up choose default SMS subscription dialog right now |
| 8188 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8189 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8190 | mApp.startActivity(intent); |
| 8191 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8192 | |
| 8193 | @Override |
| 8194 | public String getMmsUAProfUrl(int subId) { |
| 8195 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8196 | final long identity = Binder.clearCallingIdentity(); |
| 8197 | try { |
| 8198 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8199 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 8200 | } finally { |
| 8201 | Binder.restoreCallingIdentity(identity); |
| 8202 | } |
| 8203 | } |
| 8204 | |
| 8205 | @Override |
| 8206 | public String getMmsUserAgent(int subId) { |
| 8207 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8208 | final long identity = Binder.clearCallingIdentity(); |
| 8209 | try { |
| 8210 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8211 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8212 | } finally { |
| 8213 | Binder.restoreCallingIdentity(identity); |
| 8214 | } |
| 8215 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8216 | |
| 8217 | @Override |
| 8218 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 8219 | enforceModifyPermission(); |
| 8220 | |
| 8221 | // Now that all security checks passes, perform the operation as ourselves. |
| 8222 | final long identity = Binder.clearCallingIdentity(); |
| 8223 | try { |
| 8224 | Phone phone = getPhone(subId); |
| 8225 | if (phone == null) return false; |
| 8226 | |
| 8227 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 8228 | } finally { |
| 8229 | Binder.restoreCallingIdentity(identity); |
| 8230 | } |
| 8231 | } |
| 8232 | |
| 8233 | @Override |
| 8234 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 8235 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 8236 | |
| 8237 | // Now that all security checks passes, perform the operation as ourselves. |
| 8238 | final long identity = Binder.clearCallingIdentity(); |
| 8239 | try { |
| 8240 | Phone phone = getPhone(subId); |
| 8241 | if (phone == null) return false; |
| 8242 | |
| 8243 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8244 | } finally { |
| 8245 | Binder.restoreCallingIdentity(identity); |
| 8246 | } |
| 8247 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8248 | |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8249 | @Override |
| 8250 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8251 | enforceModifyPermission(); |
| 8252 | |
| 8253 | // Now that all security checks passes, perform the operation as ourselves. |
| 8254 | final long identity = Binder.clearCallingIdentity(); |
| 8255 | try { |
| 8256 | Phone phone = getPhone(subId); |
| 8257 | if (phone == null) return false; |
| 8258 | |
| 8259 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8260 | } finally { |
| 8261 | Binder.restoreCallingIdentity(identity); |
| 8262 | } |
| 8263 | } |
| 8264 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8265 | /** |
| 8266 | * Updates whether conference event pacakge handling is enabled. |
| 8267 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8268 | * otherwise. |
| 8269 | */ |
| 8270 | @Override |
| 8271 | public void setCepEnabled(boolean isCepEnabled) { |
| 8272 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8273 | |
| 8274 | final long identity = Binder.clearCallingIdentity(); |
| 8275 | try { |
| 8276 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8277 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8278 | Phone defaultPhone = phone.getImsPhone(); |
| 8279 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8280 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8281 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8282 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8283 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8284 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8285 | + imsPhone.getMsisdn()); |
| 8286 | } |
| 8287 | } |
| 8288 | } finally { |
| 8289 | Binder.restoreCallingIdentity(identity); |
| 8290 | } |
| 8291 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8292 | |
| 8293 | /** |
| 8294 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8295 | * |
| 8296 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8297 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8298 | * before being read. |
| 8299 | */ |
| 8300 | @Override |
| 8301 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8302 | isCompressed) { |
| 8303 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8304 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8305 | try { |
| 8306 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8307 | if (configBinder == null) { |
| 8308 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8309 | } else { |
| 8310 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8311 | } |
| 8312 | } catch (RemoteException e) { |
| 8313 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8314 | } |
| 8315 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8316 | |
| 8317 | @Override |
| 8318 | public boolean isIccLockEnabled(int subId) { |
| 8319 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8320 | |
| 8321 | // Now that all security checks passes, perform the operation as ourselves. |
| 8322 | final long identity = Binder.clearCallingIdentity(); |
| 8323 | try { |
| 8324 | Phone phone = getPhone(subId); |
| 8325 | if (phone != null && phone.getIccCard() != null) { |
| 8326 | return phone.getIccCard().getIccLockEnabled(); |
| 8327 | } else { |
| 8328 | return false; |
| 8329 | } |
| 8330 | } finally { |
| 8331 | Binder.restoreCallingIdentity(identity); |
| 8332 | } |
| 8333 | } |
| 8334 | |
| 8335 | /** |
| 8336 | * Set the ICC pin lock enabled or disabled.. |
| 8337 | * |
| 8338 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8339 | * 0 or a positive integer as the attempts remaining value. |
| 8340 | * |
| 8341 | */ |
| 8342 | @Override |
| 8343 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8344 | enforceModifyPermission(); |
| 8345 | |
| 8346 | Phone phone = getPhone(subId); |
| 8347 | if (phone == null) { |
| 8348 | return 0; |
| 8349 | } |
| 8350 | // Now that all security checks passes, perform the operation as ourselves. |
| 8351 | final long identity = Binder.clearCallingIdentity(); |
| 8352 | try { |
| 8353 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8354 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8355 | return attemptsRemaining; |
| 8356 | |
| 8357 | } catch (Exception e) { |
| 8358 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8359 | } finally { |
| 8360 | Binder.restoreCallingIdentity(identity); |
| 8361 | } |
| 8362 | return 0; |
| 8363 | } |
| 8364 | |
| 8365 | /** |
| 8366 | * Change the ICC password used in ICC pin lock. |
| 8367 | * |
| 8368 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8369 | * 0 or a positive integer as the attempts remaining value. |
| 8370 | * |
| 8371 | */ |
| 8372 | @Override |
| 8373 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8374 | enforceModifyPermission(); |
| 8375 | |
| 8376 | Phone phone = getPhone(subId); |
| 8377 | if (phone == null) { |
| 8378 | return 0; |
| 8379 | } |
| 8380 | // Now that all security checks passes, perform the operation as ourselves. |
| 8381 | final long identity = Binder.clearCallingIdentity(); |
| 8382 | try { |
| 8383 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8384 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8385 | return attemptsRemaining; |
| 8386 | |
| 8387 | } catch (Exception e) { |
| 8388 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8389 | } finally { |
| 8390 | Binder.restoreCallingIdentity(identity); |
| 8391 | } |
| 8392 | return 0; |
| 8393 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8394 | } |