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); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2298 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2299 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2300 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2301 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(), |
| 2302 | null)) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2303 | return ""; |
| 2304 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2305 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2306 | if (phone != null) { |
| 2307 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2308 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2309 | if (sst != null) { |
| 2310 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2311 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2312 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2313 | return lt.getCurrentCountry(); |
| 2314 | } else if (emergencyNumberTracker != null) { |
| 2315 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2316 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2317 | } |
| 2318 | } |
| 2319 | } |
| 2320 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2321 | } finally { |
| 2322 | Binder.restoreCallingIdentity(identity); |
| 2323 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2327 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2328 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2329 | } |
| 2330 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2331 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2332 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2333 | mApp.enforceCallingOrSelfPermission( |
| 2334 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2335 | |
| 2336 | final long identity = Binder.clearCallingIdentity(); |
| 2337 | try { |
| 2338 | final Phone phone = getPhone(subId); |
| 2339 | if (phone != null) { |
| 2340 | phone.enableLocationUpdates(); |
| 2341 | } |
| 2342 | } finally { |
| 2343 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2344 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | @Override |
| 2348 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2349 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2350 | } |
| 2351 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2352 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2353 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2354 | mApp.enforceCallingOrSelfPermission( |
| 2355 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2356 | |
| 2357 | final long identity = Binder.clearCallingIdentity(); |
| 2358 | try { |
| 2359 | final Phone phone = getPhone(subId); |
| 2360 | if (phone != null) { |
| 2361 | phone.disableLocationUpdates(); |
| 2362 | } |
| 2363 | } finally { |
| 2364 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2365 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2366 | } |
| 2367 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2368 | /** |
| 2369 | * Returns the target SDK version number for a given package name. |
| 2370 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2371 | * This call MUST be invoked before clearing the calling UID. |
| 2372 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2373 | * @return target SDK if the package is found or INT_MAX. |
| 2374 | */ |
| 2375 | private int getTargetSdk(String packageName) { |
| 2376 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2377 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2378 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2379 | if (ai != null) return ai.targetSdkVersion; |
| 2380 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2381 | loge("Failed to get package info for pkg=" |
| 2382 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2383 | } |
| 2384 | return Integer.MAX_VALUE; |
| 2385 | } |
| 2386 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2387 | @Override |
| 2388 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2389 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2390 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2391 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2392 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2393 | throw new SecurityException( |
| 2394 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2395 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2396 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2397 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2398 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2399 | return null; |
| 2400 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2401 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2402 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2403 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2404 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2405 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2406 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2407 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2408 | for (CellInfo ci : info) { |
| 2409 | if (ci instanceof CellInfoGsm) { |
| 2410 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2411 | } else if (ci instanceof CellInfoWcdma) { |
| 2412 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2413 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2414 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2415 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2416 | } |
| 2417 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2418 | private List<CellInfo> getCachedCellInfo() { |
| 2419 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2420 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2421 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2422 | if (info != null) cellInfos.addAll(info); |
| 2423 | } |
| 2424 | return cellInfos; |
| 2425 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2426 | |
| 2427 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2428 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2429 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2430 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2431 | |
| 2432 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2433 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2434 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2435 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2436 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2437 | .setCallingPid(Binder.getCallingPid()) |
| 2438 | .setCallingUid(Binder.getCallingUid()) |
| 2439 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2440 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2441 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2442 | .build()); |
| 2443 | switch (locationResult) { |
| 2444 | case DENIED_HARD: |
| 2445 | throw new SecurityException("Not allowed to access cell info"); |
| 2446 | case DENIED_SOFT: |
| 2447 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2448 | } |
| 2449 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2450 | final int targetSdk = getTargetSdk(callingPackage); |
| 2451 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2452 | return getCachedCellInfo(); |
| 2453 | } |
| 2454 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2455 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2456 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2457 | final long identity = Binder.clearCallingIdentity(); |
| 2458 | try { |
| 2459 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2460 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2461 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2462 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2463 | if (info != null) cellInfos.addAll(info); |
| 2464 | } |
| 2465 | return cellInfos; |
| 2466 | } finally { |
| 2467 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2468 | } |
| 2469 | } |
| 2470 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2471 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2472 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2473 | String callingFeatureId) { |
| 2474 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2475 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2479 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2480 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2481 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2482 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2483 | } |
| 2484 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2485 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2486 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2487 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2488 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2489 | |
| 2490 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2491 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2492 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2493 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2494 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2495 | .setCallingPid(Binder.getCallingPid()) |
| 2496 | .setCallingUid(Binder.getCallingUid()) |
| 2497 | .setMethod("requestCellInfoUpdate") |
| 2498 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2499 | .build()); |
| 2500 | switch (locationResult) { |
| 2501 | case DENIED_HARD: |
| 2502 | throw new SecurityException("Not allowed to access cell info"); |
| 2503 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2504 | try { |
| 2505 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2506 | } catch (RemoteException re) { |
| 2507 | // Drop without consequences |
| 2508 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2509 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2510 | } |
| 2511 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2512 | |
| 2513 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2514 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2515 | |
| 2516 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2517 | } |
| 2518 | |
| 2519 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2520 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2521 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2522 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2523 | |
| 2524 | final long identity = Binder.clearCallingIdentity(); |
| 2525 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2526 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2527 | } finally { |
| 2528 | Binder.restoreCallingIdentity(identity); |
| 2529 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2530 | } |
| 2531 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2532 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2533 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2534 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2535 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2536 | return null; |
| 2537 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2538 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2539 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2540 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2541 | return null; |
| 2542 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2543 | |
| 2544 | final long identity = Binder.clearCallingIdentity(); |
| 2545 | try { |
| 2546 | return phone.getImei(); |
| 2547 | } finally { |
| 2548 | Binder.restoreCallingIdentity(identity); |
| 2549 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2553 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2554 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2555 | String tac = null; |
| 2556 | if (phone != null) { |
| 2557 | String imei = phone.getImei(); |
| 2558 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2559 | } |
| 2560 | return tac; |
| 2561 | } |
| 2562 | |
| 2563 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2564 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2565 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2566 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2567 | return null; |
| 2568 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2569 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2570 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2571 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2572 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2573 | return null; |
| 2574 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2575 | |
| 2576 | final long identity = Binder.clearCallingIdentity(); |
| 2577 | try { |
| 2578 | return phone.getMeid(); |
| 2579 | } finally { |
| 2580 | Binder.restoreCallingIdentity(identity); |
| 2581 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2582 | } |
| 2583 | |
| 2584 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2585 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2586 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2587 | String manufacturerCode = null; |
| 2588 | if (phone != null) { |
| 2589 | String meid = phone.getMeid(); |
| 2590 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2591 | } |
| 2592 | return manufacturerCode; |
| 2593 | } |
| 2594 | |
| 2595 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2596 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2597 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2598 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2599 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2600 | return null; |
| 2601 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2602 | int subId = phone.getSubId(); |
| 2603 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2604 | mApp, subId, callingPackage, callingFeatureId, |
| 2605 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2606 | return null; |
| 2607 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2608 | |
| 2609 | final long identity = Binder.clearCallingIdentity(); |
| 2610 | try { |
| 2611 | return phone.getDeviceSvn(); |
| 2612 | } finally { |
| 2613 | Binder.restoreCallingIdentity(identity); |
| 2614 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2615 | } |
| 2616 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2617 | @Override |
| 2618 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2619 | final long identity = Binder.clearCallingIdentity(); |
| 2620 | try { |
| 2621 | final Phone phone = getPhone(subId); |
| 2622 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2623 | } finally { |
| 2624 | Binder.restoreCallingIdentity(identity); |
| 2625 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2626 | } |
| 2627 | |
| 2628 | @Override |
| 2629 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2630 | final long identity = Binder.clearCallingIdentity(); |
| 2631 | try { |
| 2632 | final Phone phone = getPhone(subId); |
| 2633 | return phone == null ? null : phone.getCarrierName(); |
| 2634 | } finally { |
| 2635 | Binder.restoreCallingIdentity(identity); |
| 2636 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2637 | } |
| 2638 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2639 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2640 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2641 | final long identity = Binder.clearCallingIdentity(); |
| 2642 | try { |
| 2643 | final Phone phone = getPhone(subId); |
| 2644 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2645 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2646 | } finally { |
| 2647 | Binder.restoreCallingIdentity(identity); |
| 2648 | } |
| 2649 | } |
| 2650 | |
| 2651 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2652 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2653 | final long identity = Binder.clearCallingIdentity(); |
| 2654 | try { |
| 2655 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2656 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2657 | } finally { |
| 2658 | Binder.restoreCallingIdentity(identity); |
| 2659 | } |
| 2660 | } |
| 2661 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2662 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2663 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2664 | if (!isSubscriptionMccMnc) { |
| 2665 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2666 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2667 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2668 | if (phone == null) { |
| 2669 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2670 | } |
| 2671 | final long identity = Binder.clearCallingIdentity(); |
| 2672 | try { |
| 2673 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2674 | } finally { |
| 2675 | Binder.restoreCallingIdentity(identity); |
| 2676 | } |
| 2677 | } |
| 2678 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2679 | // |
| 2680 | // Internal helper methods. |
| 2681 | // |
| 2682 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2683 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2684 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2685 | * |
| 2686 | * @throws SecurityException if the caller does not have the required permission |
| 2687 | */ |
| 2688 | private void enforceModifyPermission() { |
| 2689 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2690 | } |
| 2691 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2692 | /** |
| 2693 | * Make sure the caller is system. |
| 2694 | * |
| 2695 | * @throws SecurityException if the caller is not system. |
| 2696 | */ |
| 2697 | private void enforceSystemCaller() { |
| 2698 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2699 | throw new SecurityException("Caller must be system"); |
| 2700 | } |
| 2701 | } |
| 2702 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2703 | private void enforceActiveEmergencySessionPermission() { |
| 2704 | mApp.enforceCallingOrSelfPermission( |
| 2705 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2706 | } |
| 2707 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2708 | /** |
| 2709 | * Make sure the caller has the CALL_PHONE permission. |
| 2710 | * |
| 2711 | * @throws SecurityException if the caller does not have the required permission |
| 2712 | */ |
| 2713 | private void enforceCallPermission() { |
| 2714 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2715 | } |
| 2716 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2717 | private void enforceSettingsPermission() { |
| 2718 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2719 | } |
| 2720 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2721 | private String createTelUrl(String number) { |
| 2722 | if (TextUtils.isEmpty(number)) { |
| 2723 | return null; |
| 2724 | } |
| 2725 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2726 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2727 | } |
| 2728 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2729 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2730 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2731 | } |
| 2732 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2733 | private static void logv(String msg) { |
| 2734 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2735 | } |
| 2736 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2737 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2738 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2739 | } |
| 2740 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2741 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2742 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2743 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2744 | } |
| 2745 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2746 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2747 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2748 | final long identity = Binder.clearCallingIdentity(); |
| 2749 | try { |
| 2750 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2751 | if (phone == null) { |
| 2752 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2753 | } else { |
| 2754 | return phone.getPhoneType(); |
| 2755 | } |
| 2756 | } finally { |
| 2757 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2758 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | /** |
| 2762 | * Returns the CDMA ERI icon index to display |
| 2763 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2764 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2765 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2766 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2767 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2768 | } |
| 2769 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2770 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2771 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2772 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2773 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2774 | mApp, subId, callingPackage, callingFeatureId, |
| 2775 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2776 | return -1; |
| 2777 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2778 | |
| 2779 | final long identity = Binder.clearCallingIdentity(); |
| 2780 | try { |
| 2781 | final Phone phone = getPhone(subId); |
| 2782 | if (phone != null) { |
| 2783 | return phone.getCdmaEriIconIndex(); |
| 2784 | } else { |
| 2785 | return -1; |
| 2786 | } |
| 2787 | } finally { |
| 2788 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2789 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | /** |
| 2793 | * Returns the CDMA ERI icon mode, |
| 2794 | * 0 - ON |
| 2795 | * 1 - FLASHING |
| 2796 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2797 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2798 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2799 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2800 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2801 | } |
| 2802 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2803 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2804 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2805 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2806 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2807 | mApp, subId, callingPackage, callingFeatureId, |
| 2808 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2809 | return -1; |
| 2810 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2811 | |
| 2812 | final long identity = Binder.clearCallingIdentity(); |
| 2813 | try { |
| 2814 | final Phone phone = getPhone(subId); |
| 2815 | if (phone != null) { |
| 2816 | return phone.getCdmaEriIconMode(); |
| 2817 | } else { |
| 2818 | return -1; |
| 2819 | } |
| 2820 | } finally { |
| 2821 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2822 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2823 | } |
| 2824 | |
| 2825 | /** |
| 2826 | * Returns the CDMA ERI text, |
| 2827 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2828 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2829 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2830 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2831 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2832 | } |
| 2833 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2834 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2835 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2836 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2837 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2838 | mApp, subId, callingPackage, callingFeatureId, |
| 2839 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2840 | return null; |
| 2841 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2842 | |
| 2843 | final long identity = Binder.clearCallingIdentity(); |
| 2844 | try { |
| 2845 | final Phone phone = getPhone(subId); |
| 2846 | if (phone != null) { |
| 2847 | return phone.getCdmaEriText(); |
| 2848 | } else { |
| 2849 | return null; |
| 2850 | } |
| 2851 | } finally { |
| 2852 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2853 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2857 | * Returns the CDMA MDN. |
| 2858 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2859 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2860 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2861 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2862 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2863 | |
| 2864 | final long identity = Binder.clearCallingIdentity(); |
| 2865 | try { |
| 2866 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2867 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2868 | return phone.getLine1Number(); |
| 2869 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2870 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2871 | return null; |
| 2872 | } |
| 2873 | } finally { |
| 2874 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2875 | } |
| 2876 | } |
| 2877 | |
| 2878 | /** |
| 2879 | * Returns the CDMA MIN. |
| 2880 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2881 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2882 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2883 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2884 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2885 | |
| 2886 | final long identity = Binder.clearCallingIdentity(); |
| 2887 | try { |
| 2888 | final Phone phone = getPhone(subId); |
| 2889 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2890 | return phone.getCdmaMin(); |
| 2891 | } else { |
| 2892 | return null; |
| 2893 | } |
| 2894 | } finally { |
| 2895 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2896 | } |
| 2897 | } |
| 2898 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2899 | @Override |
| 2900 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2901 | INumberVerificationCallback callback, String callingPackage) { |
| 2902 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2903 | != PERMISSION_GRANTED) { |
| 2904 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2905 | } |
| 2906 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2907 | |
| 2908 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2909 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2910 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2911 | } |
| 2912 | |
| 2913 | if (range == null) { |
| 2914 | throw new NullPointerException("Range must be non-null"); |
| 2915 | } |
| 2916 | |
| 2917 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2918 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2919 | |
| 2920 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2921 | } |
| 2922 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2923 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2924 | * Returns true if CDMA provisioning needs to run. |
| 2925 | */ |
| 2926 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2927 | final long identity = Binder.clearCallingIdentity(); |
| 2928 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2929 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2930 | } finally { |
| 2931 | Binder.restoreCallingIdentity(identity); |
| 2932 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2933 | } |
| 2934 | |
| 2935 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2936 | * Sets the voice mail number of a given subId. |
| 2937 | */ |
| 2938 | @Override |
| 2939 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2940 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2941 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2942 | |
| 2943 | final long identity = Binder.clearCallingIdentity(); |
| 2944 | try { |
| 2945 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2946 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2947 | return success; |
| 2948 | } finally { |
| 2949 | Binder.restoreCallingIdentity(identity); |
| 2950 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2951 | } |
| 2952 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2953 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2954 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2955 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2956 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2957 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2958 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2959 | throw new SecurityException("caller must be system dialer"); |
| 2960 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2961 | |
| 2962 | final long identity = Binder.clearCallingIdentity(); |
| 2963 | try { |
| 2964 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2965 | if (phoneAccountHandle == null) { |
| 2966 | return null; |
| 2967 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2968 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2969 | } finally { |
| 2970 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2971 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2972 | } |
| 2973 | |
| 2974 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2975 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2976 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2977 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2978 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2979 | mApp, subId, callingPackage, callingFeatureId, |
| 2980 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2981 | return null; |
| 2982 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2983 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2984 | final long identity = Binder.clearCallingIdentity(); |
| 2985 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2986 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2987 | } finally { |
| 2988 | Binder.restoreCallingIdentity(identity); |
| 2989 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2990 | } |
| 2991 | |
| 2992 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2993 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2994 | VisualVoicemailSmsFilterSettings settings) { |
| 2995 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2996 | |
| 2997 | final long identity = Binder.clearCallingIdentity(); |
| 2998 | try { |
| 2999 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3000 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3001 | } finally { |
| 3002 | Binder.restoreCallingIdentity(identity); |
| 3003 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3004 | } |
| 3005 | |
| 3006 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3007 | public void disableVisualVoicemailSmsFilter(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 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
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 | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3020 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3021 | String callingPackage, int subId) { |
| 3022 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3023 | |
| 3024 | final long identity = Binder.clearCallingIdentity(); |
| 3025 | try { |
| 3026 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3027 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3028 | } finally { |
| 3029 | Binder.restoreCallingIdentity(identity); |
| 3030 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3031 | } |
| 3032 | |
| 3033 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3034 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3035 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3036 | |
| 3037 | final long identity = Binder.clearCallingIdentity(); |
| 3038 | try { |
| 3039 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3040 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3041 | } finally { |
| 3042 | Binder.restoreCallingIdentity(identity); |
| 3043 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3044 | } |
| 3045 | |
| 3046 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3047 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3048 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3049 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3050 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3051 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3052 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3053 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3054 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3055 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3056 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3057 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3058 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3059 | * Sets the voice activation state of a given subId. |
| 3060 | */ |
| 3061 | @Override |
| 3062 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3063 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3064 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3065 | |
| 3066 | final long identity = Binder.clearCallingIdentity(); |
| 3067 | try { |
| 3068 | final Phone phone = getPhone(subId); |
| 3069 | if (phone != null) { |
| 3070 | phone.setVoiceActivationState(activationState); |
| 3071 | } else { |
| 3072 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3073 | } |
| 3074 | } finally { |
| 3075 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3076 | } |
| 3077 | } |
| 3078 | |
| 3079 | /** |
| 3080 | * Sets the data activation state of a given subId. |
| 3081 | */ |
| 3082 | @Override |
| 3083 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3084 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3085 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3086 | |
| 3087 | final long identity = Binder.clearCallingIdentity(); |
| 3088 | try { |
| 3089 | final Phone phone = getPhone(subId); |
| 3090 | if (phone != null) { |
| 3091 | phone.setDataActivationState(activationState); |
| 3092 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3093 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3094 | } |
| 3095 | } finally { |
| 3096 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3097 | } |
| 3098 | } |
| 3099 | |
| 3100 | /** |
| 3101 | * Returns the voice activation state of a given subId. |
| 3102 | */ |
| 3103 | @Override |
| 3104 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3105 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3106 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3107 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3108 | final long identity = Binder.clearCallingIdentity(); |
| 3109 | try { |
| 3110 | if (phone != null) { |
| 3111 | return phone.getVoiceActivationState(); |
| 3112 | } else { |
| 3113 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3114 | } |
| 3115 | } finally { |
| 3116 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3117 | } |
| 3118 | } |
| 3119 | |
| 3120 | /** |
| 3121 | * Returns the data activation state of a given subId. |
| 3122 | */ |
| 3123 | @Override |
| 3124 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3125 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3126 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3127 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3128 | final long identity = Binder.clearCallingIdentity(); |
| 3129 | try { |
| 3130 | if (phone != null) { |
| 3131 | return phone.getDataActivationState(); |
| 3132 | } else { |
| 3133 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3134 | } |
| 3135 | } finally { |
| 3136 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3137 | } |
| 3138 | } |
| 3139 | |
| 3140 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3141 | * Returns the unread count of voicemails for a subId |
| 3142 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3143 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3144 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3145 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3146 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3147 | mApp, subId, callingPackage, callingFeatureId, |
| 3148 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3149 | return 0; |
| 3150 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3151 | final long identity = Binder.clearCallingIdentity(); |
| 3152 | try { |
| 3153 | final Phone phone = getPhone(subId); |
| 3154 | if (phone != null) { |
| 3155 | return phone.getVoiceMessageCount(); |
| 3156 | } else { |
| 3157 | return 0; |
| 3158 | } |
| 3159 | } finally { |
| 3160 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3161 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3162 | } |
| 3163 | |
| 3164 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3165 | * returns true, if the device is in a state where both voice and data |
| 3166 | * are supported simultaneously. This can change based on location or network condition. |
| 3167 | */ |
| 3168 | @Override |
| 3169 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3170 | final long identity = Binder.clearCallingIdentity(); |
| 3171 | try { |
| 3172 | final Phone phone = getPhone(subId); |
| 3173 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3174 | } finally { |
| 3175 | Binder.restoreCallingIdentity(identity); |
| 3176 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3177 | } |
| 3178 | |
| 3179 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3180 | * Send the dialer code if called from the current default dialer or the caller has |
| 3181 | * carrier privilege. |
| 3182 | * @param inputCode The dialer code to send |
| 3183 | */ |
| 3184 | @Override |
| 3185 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3186 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3187 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3188 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3189 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3190 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3191 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3192 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3193 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3194 | |
| 3195 | final long identity = Binder.clearCallingIdentity(); |
| 3196 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3197 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3198 | } finally { |
| 3199 | Binder.restoreCallingIdentity(identity); |
| 3200 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3201 | } |
| 3202 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3203 | @Override |
| 3204 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3205 | TelephonyPermissions |
| 3206 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3207 | mApp, subId, "getNetworkSelectionMode"); |
| 3208 | final long identity = Binder.clearCallingIdentity(); |
| 3209 | try { |
| 3210 | if (!isActiveSubscription(subId)) { |
| 3211 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3212 | } |
| 3213 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3214 | } finally { |
| 3215 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3216 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3217 | } |
| 3218 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3219 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3220 | public boolean isInEmergencySmsMode() { |
| 3221 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3222 | final long identity = Binder.clearCallingIdentity(); |
| 3223 | try { |
| 3224 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3225 | if (phone.isInEmergencySmsMode()) { |
| 3226 | return true; |
| 3227 | } |
| 3228 | } |
| 3229 | } finally { |
| 3230 | Binder.restoreCallingIdentity(identity); |
| 3231 | } |
| 3232 | return false; |
| 3233 | } |
| 3234 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3235 | /** |
| 3236 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3237 | * @param subId The subscription to use to check the configuration. |
| 3238 | * @param c The callback that will be used to send the result. |
| 3239 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3240 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3241 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3242 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3243 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3244 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3245 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3246 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3247 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3248 | "IMS not available on device."); |
| 3249 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3250 | final long token = Binder.clearCallingIdentity(); |
| 3251 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3252 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3253 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3254 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3255 | } catch (ImsException e) { |
| 3256 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3257 | } finally { |
| 3258 | Binder.restoreCallingIdentity(token); |
| 3259 | } |
| 3260 | } |
| 3261 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3262 | /** |
| 3263 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3264 | * @param subId The subscription to use to check the configuration. |
| 3265 | * @param c The callback that will be used to send the result. |
| 3266 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3267 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3268 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3269 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3270 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3271 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3272 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3273 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3274 | final long token = Binder.clearCallingIdentity(); |
| 3275 | try { |
| 3276 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3277 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3278 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3279 | } catch (ImsException e) { |
| 3280 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3281 | + "is inactive, ignoring unregister."); |
| 3282 | // If the subscription is no longer active, just return, since the callback |
| 3283 | // will already have been removed internally. |
| 3284 | } finally { |
| 3285 | Binder.restoreCallingIdentity(token); |
| 3286 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3287 | } |
| 3288 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3289 | /** |
| 3290 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3291 | */ |
| 3292 | @Override |
| 3293 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3294 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3295 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3296 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3297 | "IMS not available on device."); |
| 3298 | } |
| 3299 | final long token = Binder.clearCallingIdentity(); |
| 3300 | try { |
| 3301 | Phone phone = getPhone(subId); |
| 3302 | if (phone == null) { |
| 3303 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3304 | + subId + "'"); |
| 3305 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3306 | } |
| 3307 | phone.getImsRegistrationState(regState -> { |
| 3308 | try { |
| 3309 | consumer.accept((regState == null) |
| 3310 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3311 | } catch (RemoteException e) { |
| 3312 | // Ignore if the remote process is no longer available to call back. |
| 3313 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3314 | } |
| 3315 | }); |
| 3316 | } finally { |
| 3317 | Binder.restoreCallingIdentity(token); |
| 3318 | } |
| 3319 | } |
| 3320 | |
| 3321 | /** |
| 3322 | * Get the transport type for the IMS service registration state. |
| 3323 | */ |
| 3324 | @Override |
| 3325 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3326 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3327 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3328 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3329 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3330 | "IMS not available on device."); |
| 3331 | } |
| 3332 | final long token = Binder.clearCallingIdentity(); |
| 3333 | try { |
| 3334 | Phone phone = getPhone(subId); |
| 3335 | if (phone == null) { |
| 3336 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3337 | + subId + "'"); |
| 3338 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3339 | } |
| 3340 | phone.getImsRegistrationTech(regTech -> { |
| 3341 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3342 | int regTechConverted = (regTech == null) |
| 3343 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3344 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3345 | regTechConverted); |
| 3346 | try { |
| 3347 | consumer.accept(regTechConverted); |
| 3348 | } catch (RemoteException e) { |
| 3349 | // Ignore if the remote process is no longer available to call back. |
| 3350 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3351 | } |
| 3352 | }); |
| 3353 | } finally { |
| 3354 | Binder.restoreCallingIdentity(token); |
| 3355 | } |
| 3356 | } |
| 3357 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3358 | /** |
| 3359 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3360 | * @param subId The subscription to use to check the configuration. |
| 3361 | * @param c The callback that will be used to send the result. |
| 3362 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3363 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3364 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3365 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3366 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3367 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3368 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3369 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3370 | "IMS not available on device."); |
| 3371 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3372 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3373 | final long token = Binder.clearCallingIdentity(); |
| 3374 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3375 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3376 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3377 | } catch (ImsException e) { |
| 3378 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3379 | } finally { |
| 3380 | Binder.restoreCallingIdentity(token); |
| 3381 | } |
| 3382 | } |
| 3383 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3384 | /** |
| 3385 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3386 | * @param subId The subscription to use to check the configuration. |
| 3387 | * @param c The callback that will be used to send the result. |
| 3388 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3389 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3390 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3391 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3392 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3393 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3394 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3395 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3396 | |
| 3397 | final long token = Binder.clearCallingIdentity(); |
| 3398 | try { |
| 3399 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3400 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3401 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3402 | } catch (ImsException e) { |
| 3403 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3404 | + "is inactive, ignoring unregister."); |
| 3405 | // If the subscription is no longer active, just return, since the callback |
| 3406 | // will already have been removed internally. |
| 3407 | } finally { |
| 3408 | Binder.restoreCallingIdentity(token); |
| 3409 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3413 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3414 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3415 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3416 | final long token = Binder.clearCallingIdentity(); |
| 3417 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3418 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3419 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3420 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3421 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3422 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3423 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3424 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3425 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3426 | } finally { |
| 3427 | Binder.restoreCallingIdentity(token); |
| 3428 | } |
| 3429 | } |
| 3430 | |
| 3431 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3432 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3433 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3434 | final long token = Binder.clearCallingIdentity(); |
| 3435 | try { |
| 3436 | Phone phone = getPhone(subId); |
| 3437 | if (phone == null) return false; |
| 3438 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3439 | } catch (com.android.ims.ImsException e) { |
| 3440 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3441 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3442 | } finally { |
| 3443 | Binder.restoreCallingIdentity(token); |
| 3444 | } |
| 3445 | } |
| 3446 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3447 | /** |
| 3448 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3449 | * subscription. |
| 3450 | * @param subId The subscription to use to check the configuration. |
| 3451 | * @param callback The callback that will be used to send the result. |
| 3452 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3453 | * @param transportType The transport type of the MmTelFeature capability. |
| 3454 | */ |
| 3455 | @Override |
| 3456 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3457 | int transportType) { |
| 3458 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3459 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3460 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3461 | "IMS not available on device."); |
| 3462 | } |
| 3463 | final long token = Binder.clearCallingIdentity(); |
| 3464 | try { |
| 3465 | int slotId = getSlotIndex(subId); |
| 3466 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3467 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3468 | + subId + "'"); |
| 3469 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3470 | } |
| 3471 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3472 | transportType, aBoolean -> { |
| 3473 | try { |
| 3474 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3475 | } catch (RemoteException e) { |
| 3476 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3477 | + "running. Ignore"); |
| 3478 | } |
| 3479 | }); |
| 3480 | } finally { |
| 3481 | Binder.restoreCallingIdentity(token); |
| 3482 | } |
| 3483 | } |
| 3484 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3485 | /** |
| 3486 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3487 | * @param subId The subscription to use to check the configuration. |
| 3488 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3489 | @Override |
| 3490 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3491 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3492 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3493 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3494 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3495 | final long token = Binder.clearCallingIdentity(); |
| 3496 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3497 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3498 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3499 | } catch (ImsException e) { |
| 3500 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3501 | } finally { |
| 3502 | Binder.restoreCallingIdentity(token); |
| 3503 | } |
| 3504 | } |
| 3505 | |
| 3506 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3507 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3508 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3509 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3510 | final long identity = Binder.clearCallingIdentity(); |
| 3511 | try { |
| 3512 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3513 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3514 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3515 | } catch (ImsException e) { |
| 3516 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3517 | } finally { |
| 3518 | Binder.restoreCallingIdentity(identity); |
| 3519 | } |
| 3520 | } |
| 3521 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3522 | /** |
| 3523 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3524 | * @param subId The subscription to use to check the configuration. |
| 3525 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3526 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3527 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3528 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3529 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3530 | final long identity = Binder.clearCallingIdentity(); |
| 3531 | try { |
| 3532 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3533 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3534 | } catch (ImsException e) { |
| 3535 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3536 | } finally { |
| 3537 | Binder.restoreCallingIdentity(identity); |
| 3538 | } |
| 3539 | } |
| 3540 | |
| 3541 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3542 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3543 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3544 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3545 | final long identity = Binder.clearCallingIdentity(); |
| 3546 | try { |
| 3547 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3548 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3549 | } catch (ImsException e) { |
| 3550 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3551 | } finally { |
| 3552 | Binder.restoreCallingIdentity(identity); |
| 3553 | } |
| 3554 | } |
| 3555 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3556 | /** |
| 3557 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3558 | * @param subId The subscription to use to check the configuration. |
| 3559 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3560 | @Override |
| 3561 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3562 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3563 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3564 | final long identity = Binder.clearCallingIdentity(); |
| 3565 | try { |
| 3566 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3567 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3568 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3569 | } catch (ImsException e) { |
| 3570 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3571 | } finally { |
| 3572 | Binder.restoreCallingIdentity(identity); |
| 3573 | } |
| 3574 | } |
| 3575 | |
| 3576 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3577 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3578 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3579 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3580 | final long identity = Binder.clearCallingIdentity(); |
| 3581 | try { |
| 3582 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3583 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3584 | } catch (ImsException e) { |
| 3585 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3586 | } finally { |
| 3587 | Binder.restoreCallingIdentity(identity); |
| 3588 | } |
| 3589 | } |
| 3590 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3591 | /** |
| 3592 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3593 | * @param subId The subscription to use to check the configuration. |
| 3594 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3595 | @Override |
| 3596 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3597 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3598 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3599 | final long identity = Binder.clearCallingIdentity(); |
| 3600 | try { |
| 3601 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3602 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3603 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3604 | } catch (ImsException e) { |
| 3605 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3606 | } finally { |
| 3607 | Binder.restoreCallingIdentity(identity); |
| 3608 | } |
| 3609 | } |
| 3610 | |
| 3611 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3612 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3613 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3614 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3615 | final long identity = Binder.clearCallingIdentity(); |
| 3616 | try { |
| 3617 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3618 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3619 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3620 | } catch (ImsException e) { |
| 3621 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3622 | } finally { |
| 3623 | Binder.restoreCallingIdentity(identity); |
| 3624 | } |
| 3625 | } |
| 3626 | |
| 3627 | @Override |
| 3628 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3629 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3630 | "setVoWiFiNonPersistent"); |
| 3631 | final long identity = Binder.clearCallingIdentity(); |
| 3632 | try { |
| 3633 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3634 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3635 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3636 | } catch (ImsException e) { |
| 3637 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3638 | } finally { |
| 3639 | Binder.restoreCallingIdentity(identity); |
| 3640 | } |
| 3641 | } |
| 3642 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3643 | /** |
| 3644 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3645 | * @param subId The subscription to use to check the configuration. |
| 3646 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3647 | @Override |
| 3648 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3649 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3650 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3651 | final long identity = Binder.clearCallingIdentity(); |
| 3652 | try { |
| 3653 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3654 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3655 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3656 | } catch (ImsException e) { |
| 3657 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3658 | } finally { |
| 3659 | Binder.restoreCallingIdentity(identity); |
| 3660 | } |
| 3661 | } |
| 3662 | |
| 3663 | @Override |
| 3664 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3665 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3666 | "setVoWiFiModeSetting"); |
| 3667 | final long identity = Binder.clearCallingIdentity(); |
| 3668 | try { |
| 3669 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3670 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3671 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3672 | } catch (ImsException e) { |
| 3673 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3674 | } finally { |
| 3675 | Binder.restoreCallingIdentity(identity); |
| 3676 | } |
| 3677 | } |
| 3678 | |
| 3679 | @Override |
| 3680 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3681 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3682 | final long identity = Binder.clearCallingIdentity(); |
| 3683 | try { |
| 3684 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3685 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3686 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3687 | } catch (ImsException e) { |
| 3688 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3689 | } finally { |
| 3690 | Binder.restoreCallingIdentity(identity); |
| 3691 | } |
| 3692 | } |
| 3693 | |
| 3694 | @Override |
| 3695 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3696 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3697 | "setVoWiFiRoamingModeSetting"); |
| 3698 | final long identity = Binder.clearCallingIdentity(); |
| 3699 | try { |
| 3700 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3701 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3702 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3703 | } catch (ImsException e) { |
| 3704 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3705 | } finally { |
| 3706 | Binder.restoreCallingIdentity(identity); |
| 3707 | } |
| 3708 | } |
| 3709 | |
| 3710 | @Override |
| 3711 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3712 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3713 | "setRttCapabilityEnabled"); |
| 3714 | final long identity = Binder.clearCallingIdentity(); |
| 3715 | try { |
| 3716 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3717 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3718 | } catch (ImsException e) { |
| 3719 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3720 | } finally { |
| 3721 | Binder.restoreCallingIdentity(identity); |
| 3722 | } |
| 3723 | } |
| 3724 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3725 | /** |
| 3726 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3727 | * @param subId The subscription to use to check the configuration. |
| 3728 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3729 | @Override |
| 3730 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3731 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3732 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3733 | final long identity = Binder.clearCallingIdentity(); |
| 3734 | try { |
| 3735 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3736 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3737 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3738 | } catch (ImsException e) { |
| 3739 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3740 | } finally { |
| 3741 | Binder.restoreCallingIdentity(identity); |
| 3742 | } |
| 3743 | } |
| 3744 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3745 | @Override |
| 3746 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3747 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3748 | final long identity = Binder.clearCallingIdentity(); |
| 3749 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3750 | if (!isImsAvailableOnDevice()) { |
| 3751 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3752 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3753 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3754 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3755 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3756 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3757 | } catch (ImsException e) { |
| 3758 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3759 | } finally { |
| 3760 | Binder.restoreCallingIdentity(identity); |
| 3761 | } |
| 3762 | } |
| 3763 | |
| 3764 | @Override |
| 3765 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3766 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3767 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3768 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3769 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3770 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3771 | try { |
| 3772 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3773 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3774 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3775 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3776 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3777 | + "is inactive, ignoring unregister."); |
| 3778 | // If the subscription is no longer active, just return, since the callback will already |
| 3779 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3780 | } finally { |
| 3781 | Binder.restoreCallingIdentity(identity); |
| 3782 | } |
| 3783 | } |
| 3784 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3785 | |
| 3786 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3787 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3788 | message); |
| 3789 | } |
| 3790 | |
| 3791 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3792 | boolean isMmtelCapability) { |
| 3793 | Phone phone = getPhone(subId); |
| 3794 | if (phone == null) { |
| 3795 | loge("phone instance null for subid " + subId); |
| 3796 | return false; |
| 3797 | } |
| 3798 | if (isMmtelCapability) { |
| 3799 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3800 | return false; |
| 3801 | } |
| 3802 | } else { |
| 3803 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3804 | return false; |
| 3805 | } |
| 3806 | } |
| 3807 | return true; |
| 3808 | } |
| 3809 | |
| 3810 | @Override |
| 3811 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3812 | boolean isProvisioned) { |
| 3813 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3814 | |
| 3815 | final long identity = Binder.clearCallingIdentity(); |
| 3816 | try { |
| 3817 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3818 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3819 | return; |
| 3820 | } |
| 3821 | |
| 3822 | // this capability requires provisioning, route to the correct API. |
| 3823 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3824 | switch (capability) { |
| 3825 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3826 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3827 | ims.setEabProvisioned(isProvisioned); |
| 3828 | break; |
| 3829 | default: { |
| 3830 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3831 | + "rcs capability '" + capability + "', which does not require " |
| 3832 | + "provisioning."); |
| 3833 | } |
| 3834 | } |
| 3835 | } finally { |
| 3836 | Binder.restoreCallingIdentity(identity); |
| 3837 | } |
| 3838 | |
| 3839 | } |
| 3840 | |
| 3841 | |
| 3842 | @Override |
| 3843 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3844 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3845 | final long identity = Binder.clearCallingIdentity(); |
| 3846 | try { |
| 3847 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3848 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3849 | return true; |
| 3850 | } |
| 3851 | |
| 3852 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3853 | switch (capability) { |
| 3854 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3855 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3856 | return ims.isEabProvisionedOnDevice(); |
| 3857 | |
| 3858 | default: { |
| 3859 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3860 | + "capability '" + capability + "', which does not require " |
| 3861 | + "provisioning."); |
| 3862 | } |
| 3863 | } |
| 3864 | |
| 3865 | } finally { |
| 3866 | Binder.restoreCallingIdentity(identity); |
| 3867 | } |
| 3868 | } |
| 3869 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3870 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3871 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3872 | boolean isProvisioned) { |
| 3873 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3874 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3875 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3876 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3877 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3878 | final long identity = Binder.clearCallingIdentity(); |
| 3879 | try { |
| 3880 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3881 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3882 | return; |
| 3883 | } |
| 3884 | |
| 3885 | // this capability requires provisioning, route to the correct API. |
| 3886 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3887 | switch (capability) { |
| 3888 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3889 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3890 | ims.setVolteProvisioned(isProvisioned); |
| 3891 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3892 | ims.setWfcProvisioned(isProvisioned); |
| 3893 | } |
| 3894 | break; |
| 3895 | } |
| 3896 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3897 | // There is currently no difference in VT provisioning type. |
| 3898 | ims.setVtProvisioned(isProvisioned); |
| 3899 | break; |
| 3900 | } |
| 3901 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3902 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3903 | // change the capability of the feature instead if needed. |
| 3904 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3905 | == isProvisioned) { |
| 3906 | // No change in provisioning. |
| 3907 | return; |
| 3908 | } |
| 3909 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3910 | try { |
| 3911 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3912 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3913 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3914 | + ", Exception" + e.getMessage()); |
| 3915 | } |
| 3916 | break; |
| 3917 | } |
| 3918 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3919 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3920 | + "MmTel capability '" + capability + "', which does not require " |
| 3921 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3922 | } |
| 3923 | } |
| 3924 | |
| 3925 | } finally { |
| 3926 | Binder.restoreCallingIdentity(identity); |
| 3927 | } |
| 3928 | } |
| 3929 | |
| 3930 | @Override |
| 3931 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3932 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3933 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3934 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3935 | } |
| 3936 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3937 | final long identity = Binder.clearCallingIdentity(); |
| 3938 | try { |
| 3939 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3940 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3941 | return true; |
| 3942 | } |
| 3943 | |
| 3944 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3945 | switch (capability) { |
| 3946 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3947 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3948 | return ims.isVolteProvisionedOnDevice(); |
| 3949 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3950 | return ims.isWfcProvisionedOnDevice(); |
| 3951 | } |
| 3952 | // This should never happen, since we are checking tech above to make sure it |
| 3953 | // is either LTE or IWLAN. |
| 3954 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3955 | + "capability."); |
| 3956 | } |
| 3957 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3958 | // There is currently no difference in VT provisioning type. |
| 3959 | return ims.isVtProvisionedOnDevice(); |
| 3960 | } |
| 3961 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3962 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3963 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3964 | } |
| 3965 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3966 | throw new IllegalArgumentException( |
| 3967 | "Tried to get provisioning for MmTel capability '" + capability |
| 3968 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3969 | } |
| 3970 | } |
| 3971 | |
| 3972 | } finally { |
| 3973 | Binder.restoreCallingIdentity(identity); |
| 3974 | } |
| 3975 | } |
| 3976 | |
| 3977 | @Override |
| 3978 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3979 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3980 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3981 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3982 | } |
| 3983 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3984 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3985 | return (provisionedBits & capability) > 0; |
| 3986 | } |
| 3987 | |
| 3988 | @Override |
| 3989 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3990 | boolean isProvisioned) { |
| 3991 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3992 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3993 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3994 | } |
| 3995 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3996 | "setProvisioningStatusForCapability"); |
| 3997 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3998 | // If the current provisioning status for capability already matches isProvisioned, |
| 3999 | // do nothing. |
| 4000 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4001 | return; |
| 4002 | } |
| 4003 | if (isProvisioned) { |
| 4004 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4005 | } else { |
| 4006 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4007 | } |
| 4008 | } |
| 4009 | |
| 4010 | /** |
| 4011 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4012 | * technology. The bitfield should mirror the bitfield defined by |
| 4013 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4014 | */ |
| 4015 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4016 | String key = getMmTelProvisioningKey(subId, tech); |
| 4017 | // Default is no capabilities are provisioned. |
| 4018 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4019 | } |
| 4020 | |
| 4021 | /** |
| 4022 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4023 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4024 | * technology specified. |
| 4025 | * |
| 4026 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4027 | */ |
| 4028 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4029 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4030 | String key = getMmTelProvisioningKey(subId, tech); |
| 4031 | editor.putInt(key, newField); |
| 4032 | editor.commit(); |
| 4033 | } |
| 4034 | |
| 4035 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4036 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4037 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4038 | } |
| 4039 | |
| 4040 | /** |
| 4041 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4042 | * carrier associated with the subscription id. |
| 4043 | */ |
| 4044 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4045 | int capability) { |
| 4046 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4047 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4048 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4049 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4050 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4051 | false); |
| 4052 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4053 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4054 | |
| 4055 | // First check to make sure that the capability requires provisioning. |
| 4056 | switch (capability) { |
| 4057 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4058 | // intentional fallthrough |
| 4059 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4060 | if (requireVoiceVtProvisioning) { |
| 4061 | // Voice and Video requires provisioning |
| 4062 | return true; |
| 4063 | } |
| 4064 | break; |
| 4065 | } |
| 4066 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4067 | if (requireUtProvisioning) { |
| 4068 | // UT requires provisioning |
| 4069 | return true; |
| 4070 | } |
| 4071 | break; |
| 4072 | } |
| 4073 | } |
| 4074 | return false; |
| 4075 | } |
| 4076 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4077 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4078 | int capability) { |
| 4079 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4080 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4081 | |
| 4082 | boolean requireRcsProvisioning = c.getBoolean( |
| 4083 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4084 | |
| 4085 | // First check to make sure that the capability requires provisioning. |
| 4086 | switch (capability) { |
| 4087 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4088 | // intentional fallthrough |
| 4089 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4090 | if (requireRcsProvisioning) { |
| 4091 | // OPTION or PRESENCE requires provisioning |
| 4092 | return true; |
| 4093 | } |
| 4094 | break; |
| 4095 | } |
| 4096 | } |
| 4097 | return false; |
| 4098 | } |
| 4099 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4100 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4101 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4102 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4103 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4104 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4105 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4106 | final long identity = Binder.clearCallingIdentity(); |
| 4107 | try { |
| 4108 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4109 | int slotId = getSlotIndex(subId); |
| 4110 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4111 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4112 | + subId + "' for key:" + key); |
| 4113 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4114 | } |
| 4115 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4116 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4117 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4118 | + subId + "' for key:" + key); |
| 4119 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4120 | } finally { |
| 4121 | Binder.restoreCallingIdentity(identity); |
| 4122 | } |
| 4123 | } |
| 4124 | |
| 4125 | @Override |
| 4126 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4127 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4128 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4129 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4130 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4131 | final long identity = Binder.clearCallingIdentity(); |
| 4132 | try { |
| 4133 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4134 | int slotId = getSlotIndex(subId); |
| 4135 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4136 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4137 | + subId + "' for key:" + key); |
| 4138 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4139 | } |
| 4140 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4141 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4142 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4143 | + subId + "' for key:" + key); |
| 4144 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4145 | } finally { |
| 4146 | Binder.restoreCallingIdentity(identity); |
| 4147 | } |
| 4148 | } |
| 4149 | |
| 4150 | @Override |
| 4151 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4152 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4153 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4154 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4155 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4156 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4157 | final long identity = Binder.clearCallingIdentity(); |
| 4158 | try { |
| 4159 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4160 | int slotId = getSlotIndex(subId); |
| 4161 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4162 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4163 | + subId + "' for key:" + key); |
| 4164 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4165 | } |
| 4166 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4167 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4168 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4169 | + "' for key:" + key); |
| 4170 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4171 | } finally { |
| 4172 | Binder.restoreCallingIdentity(identity); |
| 4173 | } |
| 4174 | } |
| 4175 | |
| 4176 | @Override |
| 4177 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4178 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4179 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4180 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4181 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4182 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4183 | final long identity = Binder.clearCallingIdentity(); |
| 4184 | try { |
| 4185 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4186 | int slotId = getSlotIndex(subId); |
| 4187 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4188 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4189 | + subId + "' for key:" + key); |
| 4190 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4191 | } |
| 4192 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4193 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4194 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4195 | + "' for key:" + key); |
| 4196 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4197 | } finally { |
| 4198 | Binder.restoreCallingIdentity(identity); |
| 4199 | } |
| 4200 | } |
| 4201 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4202 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4203 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4204 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4205 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4206 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4207 | } |
| 4208 | return slotId; |
| 4209 | } |
| 4210 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4211 | private int getSlotIndex(int subId) { |
| 4212 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4213 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4214 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4215 | } |
| 4216 | return slotId; |
| 4217 | } |
| 4218 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4219 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4220 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4221 | */ |
| 4222 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4223 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4224 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4225 | final int targetSdk = getTargetSdk(callingPackage); |
| 4226 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4227 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4228 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4229 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4230 | mApp, subId, callingPackage, callingFeatureId, |
| 4231 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4232 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4233 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4234 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4235 | final long identity = Binder.clearCallingIdentity(); |
| 4236 | try { |
| 4237 | final Phone phone = getPhone(subId); |
| 4238 | if (phone != null) { |
| 4239 | return phone.getServiceState().getDataNetworkType(); |
| 4240 | } else { |
| 4241 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4242 | } |
| 4243 | } finally { |
| 4244 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4245 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4246 | } |
| 4247 | |
| 4248 | /** |
| 4249 | * Returns the data network type |
| 4250 | */ |
| 4251 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4252 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4253 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4254 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | /** |
| 4258 | * Returns the data network type for a subId |
| 4259 | */ |
| 4260 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4261 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4262 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4263 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4264 | mApp, subId, callingPackage, callingFeatureId, |
| 4265 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4266 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4267 | } |
| 4268 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4269 | final long identity = Binder.clearCallingIdentity(); |
| 4270 | try { |
| 4271 | final Phone phone = getPhone(subId); |
| 4272 | if (phone != null) { |
| 4273 | return phone.getServiceState().getDataNetworkType(); |
| 4274 | } else { |
| 4275 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4276 | } |
| 4277 | } finally { |
| 4278 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4279 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4280 | } |
| 4281 | |
| 4282 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4283 | * Returns the Voice network type for a subId |
| 4284 | */ |
| 4285 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4286 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4287 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4288 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4289 | mApp, subId, callingPackage, callingFeatureId, |
| 4290 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4291 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4292 | } |
| 4293 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4294 | final long identity = Binder.clearCallingIdentity(); |
| 4295 | try { |
| 4296 | final Phone phone = getPhone(subId); |
| 4297 | if (phone != null) { |
| 4298 | return phone.getServiceState().getVoiceNetworkType(); |
| 4299 | } else { |
| 4300 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4301 | } |
| 4302 | } finally { |
| 4303 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4304 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4305 | } |
| 4306 | |
| 4307 | /** |
| 4308 | * @return true if a ICC card is present |
| 4309 | */ |
| 4310 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4311 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4312 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4313 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4314 | } |
| 4315 | |
| 4316 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4317 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4318 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4319 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4320 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4321 | final long identity = Binder.clearCallingIdentity(); |
| 4322 | try { |
| 4323 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4324 | if (phone != null) { |
| 4325 | return phone.getIccCard().hasIccCard(); |
| 4326 | } else { |
| 4327 | return false; |
| 4328 | } |
| 4329 | } finally { |
| 4330 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4331 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4332 | } |
| 4333 | |
| 4334 | /** |
| 4335 | * Return if the current radio is LTE on CDMA. This |
| 4336 | * is a tri-state return value as for a period of time |
| 4337 | * the mode may be unknown. |
| 4338 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4339 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4340 | * @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] | 4341 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4342 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4343 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4344 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4345 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4346 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4347 | } |
| 4348 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4349 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4350 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4351 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4352 | try { |
| 4353 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4354 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4355 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4356 | } |
| 4357 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4358 | final long identity = Binder.clearCallingIdentity(); |
| 4359 | try { |
| 4360 | final Phone phone = getPhone(subId); |
| 4361 | if (phone == null) { |
| 4362 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4363 | } else { |
| 4364 | return phone.getLteOnCdmaMode(); |
| 4365 | } |
| 4366 | } finally { |
| 4367 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4368 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4369 | } |
| 4370 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4371 | /** |
| 4372 | * {@hide} |
| 4373 | * Returns Default subId, 0 in the case of single standby. |
| 4374 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4375 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4376 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4377 | } |
| 4378 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4379 | private int getSlotForDefaultSubscription() { |
| 4380 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4381 | } |
| 4382 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4383 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4384 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4385 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4386 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4387 | private boolean isActiveSubscription(int subId) { |
| 4388 | return mSubscriptionController.isActiveSubId(subId); |
| 4389 | } |
| 4390 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4391 | /** |
| 4392 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4393 | */ |
| 4394 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4395 | final long identity = Binder.clearCallingIdentity(); |
| 4396 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4397 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4398 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4399 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4400 | } finally { |
| 4401 | Binder.restoreCallingIdentity(identity); |
| 4402 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4403 | } |
| 4404 | |
| 4405 | /** |
| 4406 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4407 | */ |
| 4408 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4409 | final long identity = Binder.clearCallingIdentity(); |
| 4410 | try { |
| 4411 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4412 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4413 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4414 | } finally { |
| 4415 | Binder.restoreCallingIdentity(identity); |
| 4416 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4417 | } |
| 4418 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4419 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4420 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4421 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4422 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4423 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4424 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4425 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4426 | if (phoneId == -1) { |
| 4427 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4428 | + " does not correspond to an active phone"); |
| 4429 | } |
| 4430 | return PhoneFactory.getPhone(phoneId); |
| 4431 | } |
| 4432 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4433 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4434 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4435 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4436 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4437 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4438 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4439 | if (DBG) { |
| 4440 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4441 | } |
| 4442 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4443 | p2); |
| 4444 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4445 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4446 | |
| 4447 | @Override |
| 4448 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4449 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4450 | enforceModifyPermission(); |
| 4451 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4452 | if (DBG) { |
| 4453 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4454 | } |
| 4455 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4456 | callingPackage, aid, p2); |
| 4457 | } |
| 4458 | |
| 4459 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4460 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4461 | final long identity = Binder.clearCallingIdentity(); |
| 4462 | try { |
| 4463 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4464 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4465 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4466 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4467 | if (bestComponent == null |
| 4468 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4469 | loge("The calling package is not allowed to access ISD-R."); |
| 4470 | throw new SecurityException( |
| 4471 | "The calling package is not allowed to access ISD-R."); |
| 4472 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4473 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4474 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4475 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4476 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4477 | null /* workSource */); |
| 4478 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4479 | return response; |
| 4480 | } finally { |
| 4481 | Binder.restoreCallingIdentity(identity); |
| 4482 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4483 | } |
| 4484 | |
| 4485 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4486 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4487 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4488 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4489 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4490 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4491 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4492 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4493 | @Override |
| 4494 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4495 | enforceModifyPermission(); |
| 4496 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4497 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4498 | channel); |
| 4499 | } |
| 4500 | |
| 4501 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4502 | final long identity = Binder.clearCallingIdentity(); |
| 4503 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4504 | if (channel < 0) { |
| 4505 | return false; |
| 4506 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4507 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4508 | null /* workSource */); |
| 4509 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4510 | return success; |
| 4511 | } finally { |
| 4512 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4513 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4514 | } |
| 4515 | |
| 4516 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4517 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4518 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4519 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4520 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4521 | if (DBG) { |
| 4522 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4523 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4524 | + p3 + " data=" + data); |
| 4525 | } |
| 4526 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4527 | command, p1, p2, p3, data); |
| 4528 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4529 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4530 | @Override |
| 4531 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4532 | int command, int p1, int p2, int p3, String data) { |
| 4533 | enforceModifyPermission(); |
| 4534 | if (DBG) { |
| 4535 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4536 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4537 | + p3 + " data=" + data); |
| 4538 | } |
| 4539 | return iccTransmitApduLogicalChannelWithPermission( |
| 4540 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4541 | data); |
| 4542 | } |
| 4543 | |
| 4544 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4545 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4546 | final long identity = Binder.clearCallingIdentity(); |
| 4547 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4548 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4549 | return ""; |
| 4550 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4551 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4552 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4553 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4554 | null /* workSource */); |
| 4555 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4556 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4557 | // Append the returned status code to the end of the response payload. |
| 4558 | String s = Integer.toHexString( |
| 4559 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4560 | if (response.payload != null) { |
| 4561 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4562 | } |
| 4563 | return s; |
| 4564 | } finally { |
| 4565 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4566 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4567 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4568 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4569 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4570 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4571 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4572 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4573 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4574 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4575 | if (DBG) { |
| 4576 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4577 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4578 | } |
| 4579 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4580 | cla, command, p1, p2, p3, data); |
| 4581 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4582 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4583 | @Override |
| 4584 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4585 | int command, int p1, int p2, int p3, String data) { |
| 4586 | enforceModifyPermission(); |
| 4587 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4588 | if (DBG) { |
| 4589 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4590 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4591 | + " data=" + data); |
| 4592 | } |
| 4593 | |
| 4594 | return iccTransmitApduBasicChannelWithPermission( |
| 4595 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4596 | p2, p3, data); |
| 4597 | } |
| 4598 | |
| 4599 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4600 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4601 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4602 | final long identity = Binder.clearCallingIdentity(); |
| 4603 | try { |
| 4604 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4605 | && TextUtils.equals(ISDR_AID, data)) { |
| 4606 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4607 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4608 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4609 | if (bestComponent == null |
| 4610 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4611 | loge("The calling package is not allowed to select ISD-R."); |
| 4612 | throw new SecurityException( |
| 4613 | "The calling package is not allowed to select ISD-R."); |
| 4614 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4615 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4616 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4617 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4618 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4619 | null /* workSource */); |
| 4620 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4621 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4622 | // Append the returned status code to the end of the response payload. |
| 4623 | String s = Integer.toHexString( |
| 4624 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4625 | if (response.payload != null) { |
| 4626 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4627 | } |
| 4628 | return s; |
| 4629 | } finally { |
| 4630 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4631 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4632 | } |
| 4633 | |
| 4634 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4635 | 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] | 4636 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4637 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4638 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4639 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4640 | final long identity = Binder.clearCallingIdentity(); |
| 4641 | try { |
| 4642 | if (DBG) { |
| 4643 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4644 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4645 | } |
| 4646 | |
| 4647 | IccIoResult response = |
| 4648 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4649 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4650 | subId); |
| 4651 | |
| 4652 | if (DBG) { |
| 4653 | log("Exchange SIM_IO [R]" + response); |
| 4654 | } |
| 4655 | |
| 4656 | byte[] result = null; |
| 4657 | int length = 2; |
| 4658 | if (response.payload != null) { |
| 4659 | length = 2 + response.payload.length; |
| 4660 | result = new byte[length]; |
| 4661 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4662 | } else { |
| 4663 | result = new byte[length]; |
| 4664 | } |
| 4665 | |
| 4666 | result[length - 1] = (byte) response.sw2; |
| 4667 | result[length - 2] = (byte) response.sw1; |
| 4668 | return result; |
| 4669 | } finally { |
| 4670 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4671 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4672 | } |
| 4673 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4674 | /** |
| 4675 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4676 | * on a particular subscription |
| 4677 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4678 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4679 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4680 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4681 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4682 | return null; |
| 4683 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4684 | |
| 4685 | final long identity = Binder.clearCallingIdentity(); |
| 4686 | try { |
| 4687 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4688 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4689 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4690 | return null; |
| 4691 | } |
| 4692 | Object response = sendRequest( |
| 4693 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4694 | if (response instanceof String[]) { |
| 4695 | return (String[]) response; |
| 4696 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4697 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4698 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4699 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4700 | } finally { |
| 4701 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4702 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4703 | } |
| 4704 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4705 | /** |
| 4706 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4707 | * subscription. |
| 4708 | * |
| 4709 | * @param subId the id of the subscription. |
| 4710 | * @param appType the uicc app type, must be USIM or SIM. |
| 4711 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4712 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4713 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4714 | * @return number of fplmns that is successfully written to the SIM. |
| 4715 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4716 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4717 | String callingFeatureId) { |
| 4718 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4719 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4720 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4721 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4722 | } |
| 4723 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4724 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4725 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4726 | } |
| 4727 | if (fplmns == null) { |
| 4728 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4729 | } |
| 4730 | for (String fplmn : fplmns) { |
| 4731 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4732 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4733 | } |
| 4734 | } |
| 4735 | final long identity = Binder.clearCallingIdentity(); |
| 4736 | try { |
| 4737 | Object response = sendRequest( |
| 4738 | CMD_SET_FORBIDDEN_PLMNS, |
| 4739 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4740 | subId); |
| 4741 | return (int) response; |
| 4742 | } finally { |
| 4743 | Binder.restoreCallingIdentity(identity); |
| 4744 | } |
| 4745 | } |
| 4746 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4747 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4748 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4749 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4750 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4751 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4752 | final long identity = Binder.clearCallingIdentity(); |
| 4753 | try { |
| 4754 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4755 | if (response.payload == null) { |
| 4756 | return ""; |
| 4757 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4758 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4759 | // Append the returned status code to the end of the response payload. |
| 4760 | String s = Integer.toHexString( |
| 4761 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4762 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4763 | return s; |
| 4764 | } finally { |
| 4765 | Binder.restoreCallingIdentity(identity); |
| 4766 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4767 | } |
| 4768 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4769 | /** |
| 4770 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4771 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4772 | * |
| 4773 | * @param itemID the ID of the item to read |
| 4774 | * @return the NV item as a String, or null on error. |
| 4775 | */ |
| 4776 | @Override |
| 4777 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4778 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4779 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4780 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4781 | |
| 4782 | final long identity = Binder.clearCallingIdentity(); |
| 4783 | try { |
| 4784 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4785 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4786 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4787 | return value; |
| 4788 | } finally { |
| 4789 | Binder.restoreCallingIdentity(identity); |
| 4790 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4791 | } |
| 4792 | |
| 4793 | /** |
| 4794 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4795 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4796 | * |
| 4797 | * @param itemID the ID of the item to read |
| 4798 | * @param itemValue the value to write, as a String |
| 4799 | * @return true on success; false on any failure |
| 4800 | */ |
| 4801 | @Override |
| 4802 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4803 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4804 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4805 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4806 | |
| 4807 | final long identity = Binder.clearCallingIdentity(); |
| 4808 | try { |
| 4809 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4810 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4811 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4812 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4813 | return success; |
| 4814 | } finally { |
| 4815 | Binder.restoreCallingIdentity(identity); |
| 4816 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4817 | } |
| 4818 | |
| 4819 | /** |
| 4820 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4821 | * Used for device configuration by some CDMA operators. |
| 4822 | * |
| 4823 | * @param preferredRoamingList byte array containing the new PRL |
| 4824 | * @return true on success; false on any failure |
| 4825 | */ |
| 4826 | @Override |
| 4827 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4828 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4829 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4830 | |
| 4831 | final long identity = Binder.clearCallingIdentity(); |
| 4832 | try { |
| 4833 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4834 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4835 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4836 | return success; |
| 4837 | } finally { |
| 4838 | Binder.restoreCallingIdentity(identity); |
| 4839 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4840 | } |
| 4841 | |
| 4842 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4843 | * 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] | 4844 | * Used for device configuration by some CDMA operators. |
| 4845 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4846 | * @param slotIndex - device slot. |
| 4847 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4848 | * @return true on success; false on any failure |
| 4849 | */ |
| 4850 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4851 | public boolean resetModemConfig(int slotIndex) { |
| 4852 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4853 | if (phone != null) { |
| 4854 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4855 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4856 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4857 | final long identity = Binder.clearCallingIdentity(); |
| 4858 | try { |
| 4859 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4860 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4861 | return success; |
| 4862 | } finally { |
| 4863 | Binder.restoreCallingIdentity(identity); |
| 4864 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4865 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4866 | return false; |
| 4867 | } |
| 4868 | |
| 4869 | /** |
| 4870 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4871 | * |
| 4872 | * @param slotIndex - device slot. |
| 4873 | * |
| 4874 | * @return true on success; false on any failure |
| 4875 | */ |
| 4876 | @Override |
| 4877 | public boolean rebootModem(int slotIndex) { |
| 4878 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4879 | if (phone != null) { |
| 4880 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4881 | mApp, phone.getSubId(), "rebootModem"); |
| 4882 | |
| 4883 | final long identity = Binder.clearCallingIdentity(); |
| 4884 | try { |
| 4885 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4886 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4887 | return success; |
| 4888 | } finally { |
| 4889 | Binder.restoreCallingIdentity(identity); |
| 4890 | } |
| 4891 | } |
| 4892 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4893 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4894 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4895 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4896 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4897 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4898 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4899 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4900 | return new String[0]; |
| 4901 | } |
| 4902 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4903 | final long identity = Binder.clearCallingIdentity(); |
| 4904 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4905 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4906 | } finally { |
| 4907 | Binder.restoreCallingIdentity(identity); |
| 4908 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4909 | } |
| 4910 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4911 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 4912 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 4913 | * {@link #disableIms(int)}. |
| 4914 | * @param slotIndex device slot. |
| 4915 | */ |
| 4916 | public void resetIms(int slotIndex) { |
| 4917 | enforceModifyPermission(); |
| 4918 | |
| 4919 | final long identity = Binder.clearCallingIdentity(); |
| 4920 | try { |
| 4921 | if (mImsResolver == null) { |
| 4922 | // may happen if the does not support IMS. |
| 4923 | return; |
| 4924 | } |
| 4925 | mImsResolver.disableIms(slotIndex); |
| 4926 | mImsResolver.enableIms(slotIndex); |
| 4927 | } finally { |
| 4928 | Binder.restoreCallingIdentity(identity); |
| 4929 | } |
| 4930 | } |
| 4931 | |
| 4932 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4933 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4934 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4935 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4936 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4937 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4938 | |
| 4939 | final long identity = Binder.clearCallingIdentity(); |
| 4940 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4941 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4942 | // may happen if the device does not support IMS. |
| 4943 | return; |
| 4944 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4945 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4946 | } finally { |
| 4947 | Binder.restoreCallingIdentity(identity); |
| 4948 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4949 | } |
| 4950 | |
| 4951 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4952 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4953 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4954 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4955 | public void disableIms(int slotId) { |
| 4956 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4957 | |
| 4958 | final long identity = Binder.clearCallingIdentity(); |
| 4959 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4960 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4961 | // may happen if the device does not support IMS. |
| 4962 | return; |
| 4963 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4964 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4965 | } finally { |
| 4966 | Binder.restoreCallingIdentity(identity); |
| 4967 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4968 | } |
| 4969 | |
| 4970 | /** |
| 4971 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4972 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4973 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4974 | */ |
| 4975 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4976 | IImsServiceFeatureCallback callback) { |
| 4977 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4978 | |
| 4979 | final long identity = Binder.clearCallingIdentity(); |
| 4980 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4981 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4982 | // may happen if the device does not support IMS. |
| 4983 | return null; |
| 4984 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4985 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4986 | } finally { |
| 4987 | Binder.restoreCallingIdentity(identity); |
| 4988 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4989 | } |
| 4990 | |
| 4991 | /** |
| 4992 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4993 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4994 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4995 | * listener for feature updates. |
| 4996 | */ |
| 4997 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4998 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4999 | |
| 5000 | final long identity = Binder.clearCallingIdentity(); |
| 5001 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5002 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5003 | // may happen if the device does not support IMS. |
| 5004 | return null; |
| 5005 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5006 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5007 | } finally { |
| 5008 | Binder.restoreCallingIdentity(identity); |
| 5009 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5010 | } |
| 5011 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5012 | /** |
| 5013 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5014 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5015 | */ |
| 5016 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5017 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5018 | |
| 5019 | final long identity = Binder.clearCallingIdentity(); |
| 5020 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5021 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5022 | // may happen if the device does not support IMS. |
| 5023 | return null; |
| 5024 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5025 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5026 | } finally { |
| 5027 | Binder.restoreCallingIdentity(identity); |
| 5028 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5029 | } |
| 5030 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5031 | /** |
| 5032 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5033 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5034 | */ |
| 5035 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5036 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5037 | |
| 5038 | final long identity = Binder.clearCallingIdentity(); |
| 5039 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5040 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5041 | // may happen if the device does not support IMS. |
| 5042 | return null; |
| 5043 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5044 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5045 | } finally { |
| 5046 | Binder.restoreCallingIdentity(identity); |
| 5047 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5048 | } |
| 5049 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5050 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5051 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5052 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5053 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5054 | * @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] | 5055 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5056 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5057 | * @param packageName The name of the package that the current configuration will be replaced |
| 5058 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5059 | * @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] | 5060 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5061 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5062 | int[] featureTypes, String packageName) { |
| 5063 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5064 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5065 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5066 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5067 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5068 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5069 | final long identity = Binder.clearCallingIdentity(); |
| 5070 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5071 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5072 | // may happen if the device does not support IMS. |
| 5073 | return false; |
| 5074 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5075 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5076 | for (int featureType : featureTypes) { |
| 5077 | featureConfig.put(featureType, packageName); |
| 5078 | } |
| 5079 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5080 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5081 | } finally { |
| 5082 | Binder.restoreCallingIdentity(identity); |
| 5083 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5084 | } |
| 5085 | |
| 5086 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5087 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5088 | * |
| 5089 | * @param slotId The slot that the ImsService is associated with. |
| 5090 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5091 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5092 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5093 | * @return the package name of the ImsService configuration. |
| 5094 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5095 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5096 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5097 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5098 | TelephonyPermissions |
| 5099 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5100 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5101 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5102 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5103 | final long identity = Binder.clearCallingIdentity(); |
| 5104 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5105 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5106 | // may happen if the device does not support IMS. |
| 5107 | return ""; |
| 5108 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5109 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5110 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5111 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5112 | } finally { |
| 5113 | Binder.restoreCallingIdentity(identity); |
| 5114 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5115 | } |
| 5116 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5117 | /** |
| 5118 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5119 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5120 | * @param callback A callback with an integer containing the |
| 5121 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5122 | */ |
| 5123 | @Override |
| 5124 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5125 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5126 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5127 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5128 | "IMS not available on device."); |
| 5129 | } |
| 5130 | final long token = Binder.clearCallingIdentity(); |
| 5131 | try { |
| 5132 | int slotId = getSlotIndex(subId); |
| 5133 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5134 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5135 | + subId + "'"); |
| 5136 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5137 | } |
| 5138 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5139 | try { |
| 5140 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5141 | } catch (RemoteException e) { |
| 5142 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5143 | + "Ignore"); |
| 5144 | } |
| 5145 | }); |
| 5146 | } finally { |
| 5147 | Binder.restoreCallingIdentity(token); |
| 5148 | } |
| 5149 | } |
| 5150 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5151 | public void setImsRegistrationState(boolean registered) { |
| 5152 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5153 | |
| 5154 | final long identity = Binder.clearCallingIdentity(); |
| 5155 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5156 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5157 | } finally { |
| 5158 | Binder.restoreCallingIdentity(identity); |
| 5159 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5160 | } |
| 5161 | |
| 5162 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5163 | * Set the network selection mode to automatic. |
| 5164 | * |
| 5165 | */ |
| 5166 | @Override |
| 5167 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5168 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5169 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5170 | |
| 5171 | final long identity = Binder.clearCallingIdentity(); |
| 5172 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5173 | if (!isActiveSubscription(subId)) { |
| 5174 | return; |
| 5175 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5176 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5177 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5178 | } finally { |
| 5179 | Binder.restoreCallingIdentity(identity); |
| 5180 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5181 | } |
| 5182 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5183 | /** |
| 5184 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5185 | * |
| 5186 | * @param subId the id of the subscription. |
| 5187 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5188 | * the operator to attach to. |
| 5189 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5190 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5191 | * normal network selection next time. |
| 5192 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5193 | */ |
| 5194 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5195 | public boolean setNetworkSelectionModeManual( |
| 5196 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5197 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5198 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5199 | |
| 5200 | if (!isActiveSubscription(subId)) { |
| 5201 | return false; |
| 5202 | } |
| 5203 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5204 | final long identity = Binder.clearCallingIdentity(); |
| 5205 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5206 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5207 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5208 | if (DBG) { |
| 5209 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5210 | + " operator: " + operatorInfo); |
| 5211 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5212 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5213 | } finally { |
| 5214 | Binder.restoreCallingIdentity(identity); |
| 5215 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5216 | } |
| 5217 | |
| 5218 | /** |
| 5219 | * Scans for available networks. |
| 5220 | */ |
| 5221 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5222 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5223 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5224 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5225 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5226 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5227 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5228 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5229 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5230 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5231 | .setCallingPid(Binder.getCallingPid()) |
| 5232 | .setCallingUid(Binder.getCallingUid()) |
| 5233 | .setMethod("getCellNetworkScanResults") |
| 5234 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5235 | .build()); |
| 5236 | switch (locationResult) { |
| 5237 | case DENIED_HARD: |
| 5238 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5239 | case DENIED_SOFT: |
| 5240 | return null; |
| 5241 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5242 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5243 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5244 | try { |
| 5245 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5246 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5247 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5248 | } finally { |
| 5249 | Binder.restoreCallingIdentity(identity); |
| 5250 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5251 | } |
| 5252 | |
| 5253 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5254 | * Get the call forwarding info, given the call forwarding reason. |
| 5255 | */ |
| 5256 | @Override |
| 5257 | public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) { |
| 5258 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5259 | long identity = Binder.clearCallingIdentity(); |
| 5260 | try { |
| 5261 | if (DBG) { |
| 5262 | log("getCallForwarding: subId " + subId |
| 5263 | + " callForwardingReason" + callForwardingReason); |
| 5264 | } |
| 5265 | return (CallForwardingInfo) sendRequest( |
| 5266 | CMD_GET_CALL_FORWARDING, callForwardingReason, subId); |
| 5267 | } finally { |
| 5268 | Binder.restoreCallingIdentity(identity); |
| 5269 | } |
| 5270 | } |
| 5271 | |
| 5272 | /** |
| 5273 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5274 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5275 | */ |
| 5276 | @Override |
| 5277 | public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) { |
| 5278 | enforceModifyPermission(); |
| 5279 | long identity = Binder.clearCallingIdentity(); |
| 5280 | try { |
| 5281 | if (DBG) { |
| 5282 | log("setCallForwarding: subId " + subId |
| 5283 | + " callForwardingInfo" + callForwardingInfo); |
| 5284 | } |
| 5285 | return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId); |
| 5286 | } finally { |
| 5287 | Binder.restoreCallingIdentity(identity); |
| 5288 | } |
| 5289 | } |
| 5290 | |
| 5291 | /** |
| 5292 | * Get the call forwarding info, given the call forwarding reason. |
| 5293 | */ |
| 5294 | @Override |
| 5295 | public int getCallWaitingStatus(int subId) { |
| 5296 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5297 | long identity = Binder.clearCallingIdentity(); |
| 5298 | try { |
| 5299 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 5300 | return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId); |
| 5301 | } finally { |
| 5302 | Binder.restoreCallingIdentity(identity); |
| 5303 | } |
| 5304 | } |
| 5305 | |
| 5306 | /** |
| 5307 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5308 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5309 | */ |
| 5310 | @Override |
| 5311 | public boolean setCallWaitingStatus(int subId, boolean isEnable) { |
| 5312 | enforceModifyPermission(); |
| 5313 | long identity = Binder.clearCallingIdentity(); |
| 5314 | try { |
| 5315 | if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable); |
| 5316 | return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId); |
| 5317 | } finally { |
| 5318 | Binder.restoreCallingIdentity(identity); |
| 5319 | } |
| 5320 | } |
| 5321 | |
| 5322 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5323 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5324 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5325 | * @param subId id of the subscription |
| 5326 | * @param request contains the radio access networks with bands/channels to scan |
| 5327 | * @param messenger callback messenger for scan results or errors |
| 5328 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5329 | * @return the id of the requested scan which can be used to stop the scan. |
| 5330 | */ |
| 5331 | @Override |
| 5332 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5333 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5334 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5335 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5336 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5337 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5338 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5339 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5340 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5341 | .setCallingPid(Binder.getCallingPid()) |
| 5342 | .setCallingUid(Binder.getCallingUid()) |
| 5343 | .setMethod("requestNetworkScan") |
| 5344 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5345 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5346 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5347 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5348 | if (e != null) { |
| 5349 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5350 | throw e; |
| 5351 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5352 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5353 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5354 | } |
| 5355 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5356 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5357 | int callingUid = Binder.getCallingUid(); |
| 5358 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5359 | final long identity = Binder.clearCallingIdentity(); |
| 5360 | try { |
| 5361 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5362 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5363 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5364 | } finally { |
| 5365 | Binder.restoreCallingIdentity(identity); |
| 5366 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5367 | } |
| 5368 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5369 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5370 | NetworkScanRequest request, int subId) { |
| 5371 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5372 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5373 | boolean hasNetworkScanPermission = |
| 5374 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5375 | == PERMISSION_GRANTED; |
| 5376 | |
| 5377 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5378 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5379 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5383 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5384 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5385 | return new SecurityException("Specific channels must not be" |
| 5386 | + " scanned without location access."); |
| 5387 | } |
| 5388 | } |
| 5389 | } |
| 5390 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5391 | return null; |
| 5392 | } |
| 5393 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5394 | /** |
| 5395 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5396 | * |
| 5397 | * @param subId id of the subscription |
| 5398 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5399 | */ |
| 5400 | @Override |
| 5401 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5402 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5403 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5404 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5405 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5406 | final long identity = Binder.clearCallingIdentity(); |
| 5407 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5408 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5409 | } finally { |
| 5410 | Binder.restoreCallingIdentity(identity); |
| 5411 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5412 | } |
| 5413 | |
| 5414 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5415 | * Get the calculated preferred network type. |
| 5416 | * Used for debugging incorrect network type. |
| 5417 | * |
| 5418 | * @return the preferred network type, defined in RILConstants.java. |
| 5419 | */ |
| 5420 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5421 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5422 | final Phone defaultPhone = getDefaultPhone(); |
| 5423 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5424 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5425 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5426 | } |
| 5427 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5428 | final long identity = Binder.clearCallingIdentity(); |
| 5429 | try { |
| 5430 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5431 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5432 | } finally { |
| 5433 | Binder.restoreCallingIdentity(identity); |
| 5434 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5435 | } |
| 5436 | |
| 5437 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5438 | * Get the preferred network type. |
| 5439 | * Used for device configuration by some CDMA operators. |
| 5440 | * |
| 5441 | * @return the preferred network type, defined in RILConstants.java. |
| 5442 | */ |
| 5443 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5444 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5445 | TelephonyPermissions |
| 5446 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5447 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5448 | |
| 5449 | final long identity = Binder.clearCallingIdentity(); |
| 5450 | try { |
| 5451 | if (DBG) log("getPreferredNetworkType"); |
| 5452 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5453 | int networkType = (result != null ? result[0] : -1); |
| 5454 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5455 | return networkType; |
| 5456 | } finally { |
| 5457 | Binder.restoreCallingIdentity(identity); |
| 5458 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5459 | } |
| 5460 | |
| 5461 | /** |
| 5462 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5463 | * |
| 5464 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5465 | * @return true on success; false on any failure. |
| 5466 | */ |
| 5467 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5468 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5469 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5470 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5471 | |
| 5472 | final long identity = Binder.clearCallingIdentity(); |
| 5473 | try { |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5474 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5475 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5476 | |
| 5477 | Boolean success = (Boolean) sendRequest( |
| 5478 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 5479 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5480 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5481 | } finally { |
| 5482 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5483 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5484 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5485 | |
| 5486 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5487 | * Get the allowed network types that store in the telephony provider. |
| 5488 | * |
| 5489 | * @param subId the id of the subscription. |
| 5490 | * @return allowedNetworkTypes the allowed network types. |
| 5491 | */ |
| 5492 | @Override |
| 5493 | public long getAllowedNetworkTypes(int subId) { |
| 5494 | TelephonyPermissions |
| 5495 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5496 | mApp, subId, "getAllowedNetworkTypes"); |
| 5497 | |
| 5498 | final long identity = Binder.clearCallingIdentity(); |
| 5499 | try { |
| 5500 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5501 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5502 | } finally { |
| 5503 | Binder.restoreCallingIdentity(identity); |
| 5504 | } |
| 5505 | } |
| 5506 | |
| 5507 | /** |
| 5508 | * Set the allowed network types. |
| 5509 | * |
| 5510 | * @param subId the id of the subscription. |
| 5511 | * @param allowedNetworkTypes the allowed network types. |
| 5512 | * @return true on success; false on any failure. |
| 5513 | */ |
| 5514 | @Override |
| 5515 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5516 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5517 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5518 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5519 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5520 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5521 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5522 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5523 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5524 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5525 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5526 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5527 | } |
| 5528 | |
| 5529 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5530 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5531 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5532 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5533 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5534 | * @hide |
| 5535 | */ |
| 5536 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5537 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5538 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5539 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5540 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5541 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5542 | if (phone != null) { |
| 5543 | return phone.hasMatchedTetherApnSetting(); |
| 5544 | } else { |
| 5545 | return false; |
| 5546 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5547 | } finally { |
| 5548 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5549 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5550 | } |
| 5551 | |
| 5552 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5553 | * Set mobile data enabled |
| 5554 | * Used by the user through settings etc to turn on/off mobile data |
| 5555 | * |
| 5556 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5557 | */ |
| 5558 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5559 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5560 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5561 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5562 | |
| 5563 | final long identity = Binder.clearCallingIdentity(); |
| 5564 | try { |
| 5565 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5566 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5567 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5568 | if (phone != null) { |
| 5569 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5570 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5571 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5572 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5573 | } |
| 5574 | } finally { |
| 5575 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5576 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5577 | } |
| 5578 | |
| 5579 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5580 | * Enable or disable always reporting signal strength changes from radio. |
| 5581 | * |
| 5582 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5583 | */ |
| 5584 | @Override |
| 5585 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5586 | enforceModifyPermission(); |
| 5587 | enforceSystemCaller(); |
| 5588 | |
| 5589 | final long identity = Binder.clearCallingIdentity(); |
| 5590 | final Phone phone = getPhone(subId); |
| 5591 | try { |
| 5592 | if (phone != null) { |
| 5593 | if (DBG) { |
| 5594 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5595 | + " isEnable=" + isEnable); |
| 5596 | } |
| 5597 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5598 | } else { |
| 5599 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5600 | + subId); |
| 5601 | } |
| 5602 | } finally { |
| 5603 | Binder.restoreCallingIdentity(identity); |
| 5604 | } |
| 5605 | } |
| 5606 | |
| 5607 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5608 | * Get the user enabled state of Mobile Data. |
| 5609 | * |
| 5610 | * TODO: remove and use isUserDataEnabled. |
| 5611 | * This can't be removed now because some vendor codes |
| 5612 | * calls through ITelephony directly while they should |
| 5613 | * use TelephonyManager. |
| 5614 | * |
| 5615 | * @return true on enabled |
| 5616 | */ |
| 5617 | @Override |
| 5618 | public boolean getDataEnabled(int subId) { |
| 5619 | return isUserDataEnabled(subId); |
| 5620 | } |
| 5621 | |
| 5622 | /** |
| 5623 | * Get whether mobile data is enabled per user setting. |
| 5624 | * |
| 5625 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5626 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5627 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5628 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5629 | * |
| 5630 | * @return {@code true} if data is enabled else {@code false} |
| 5631 | */ |
| 5632 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5633 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5634 | try { |
| 5635 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5636 | null); |
| 5637 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5638 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5639 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5640 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5641 | |
| 5642 | final long identity = Binder.clearCallingIdentity(); |
| 5643 | try { |
| 5644 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5645 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5646 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5647 | if (phone != null) { |
| 5648 | boolean retVal = phone.isUserDataEnabled(); |
| 5649 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5650 | return retVal; |
| 5651 | } else { |
| 5652 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5653 | return false; |
| 5654 | } |
| 5655 | } finally { |
| 5656 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5657 | } |
| 5658 | } |
| 5659 | |
| 5660 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5661 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5662 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5663 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5664 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5665 | * @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] | 5666 | */ |
| 5667 | @Override |
| 5668 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5669 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5670 | |
| 5671 | final long identity = Binder.clearCallingIdentity(); |
| 5672 | try { |
| 5673 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5674 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5675 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5676 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5677 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5678 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5679 | return retVal; |
| 5680 | } else { |
| 5681 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5682 | return false; |
| 5683 | } |
| 5684 | } finally { |
| 5685 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5686 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5687 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5688 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5689 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5690 | Phone phone) { |
| 5691 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5692 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5693 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5694 | || subController == null) return privilegeFromSim; |
| 5695 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5696 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5697 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5698 | |
| 5699 | final long identity = Binder.clearCallingIdentity(); |
| 5700 | try { |
| 5701 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5702 | SubscriptionManager subManager = (SubscriptionManager) |
| 5703 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5704 | for (String pkg : packages) { |
| 5705 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5706 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5707 | } |
| 5708 | } |
| 5709 | return privilegeFromSim; |
| 5710 | } finally { |
| 5711 | Binder.restoreCallingIdentity(identity); |
| 5712 | } |
| 5713 | } |
| 5714 | |
| 5715 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5716 | String pkgName) { |
| 5717 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5718 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5719 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5720 | || subController == null) return privilegeFromSim; |
| 5721 | |
| 5722 | final long identity = Binder.clearCallingIdentity(); |
| 5723 | try { |
| 5724 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5725 | SubscriptionManager subManager = (SubscriptionManager) |
| 5726 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5727 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5728 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5729 | } finally { |
| 5730 | Binder.restoreCallingIdentity(identity); |
| 5731 | } |
| 5732 | } |
| 5733 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5734 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5735 | public int getCarrierPrivilegeStatus(int subId) { |
| 5736 | final Phone phone = getPhone(subId); |
| 5737 | if (phone == null) { |
| 5738 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5739 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5740 | } |
| 5741 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5742 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5743 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5744 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5745 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5746 | |
| 5747 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5748 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5749 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5750 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5751 | |
| 5752 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5753 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5754 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5755 | final Phone phone = getPhone(subId); |
| 5756 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5757 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5758 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5759 | } |
| 5760 | UiccProfile profile = |
| 5761 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5762 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5763 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5764 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5765 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5766 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5767 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5768 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5769 | } |
| 5770 | |
| 5771 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5772 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5773 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5774 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5775 | } |
| 5776 | |
| 5777 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5778 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5779 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5780 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5781 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5782 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5783 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5784 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5785 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5786 | } |
| 5787 | |
| 5788 | @Override |
| 5789 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5790 | if (TextUtils.isEmpty(pkgName)) |
| 5791 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5792 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5793 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5794 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5795 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5796 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5797 | continue; |
| 5798 | } |
| 5799 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5800 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5801 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5802 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5803 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5804 | break; |
| 5805 | } |
| 5806 | } |
| 5807 | |
| 5808 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5809 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5810 | |
| 5811 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5812 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5813 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5814 | loge("phoneId " + phoneId + " is not valid."); |
| 5815 | return null; |
| 5816 | } |
| 5817 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5818 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5819 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5820 | return null ; |
| 5821 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5822 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5823 | } |
| 5824 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5825 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5826 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5827 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5828 | List<String> privilegedPackages = new ArrayList<>(); |
| 5829 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5830 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5831 | // has UICC in that slot. |
| 5832 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5833 | if (card.hasCarrierPrivilegeRules()) { |
| 5834 | if (packages == null) { |
| 5835 | // Only check packages in user 0 for now |
| 5836 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5837 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5838 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5839 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5840 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5841 | } |
| 5842 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5843 | PackageInfo pkgInfo = packages.get(p); |
| 5844 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5845 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5846 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5847 | privilegedPackages.add(pkgInfo.packageName); |
| 5848 | } |
| 5849 | } |
| 5850 | } |
| 5851 | } |
| 5852 | return privilegedPackages; |
| 5853 | } |
| 5854 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5855 | @Override |
| 5856 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5857 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5858 | |
| 5859 | final long identity = Binder.clearCallingIdentity(); |
| 5860 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5861 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5862 | try { |
| 5863 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5864 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5865 | } |
| 5866 | } finally { |
| 5867 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5868 | } |
| 5869 | return privilegedPackages; |
| 5870 | } |
| 5871 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5872 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5873 | final Phone phone = getPhone(subId); |
| 5874 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5875 | if (card == null) { |
| 5876 | loge("getIccId: No UICC"); |
| 5877 | return null; |
| 5878 | } |
| 5879 | String iccId = card.getIccId(); |
| 5880 | if (TextUtils.isEmpty(iccId)) { |
| 5881 | loge("getIccId: ICC ID is null or empty."); |
| 5882 | return null; |
| 5883 | } |
| 5884 | return iccId; |
| 5885 | } |
| 5886 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5887 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5888 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5889 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5890 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5891 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5892 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5893 | final long identity = Binder.clearCallingIdentity(); |
| 5894 | try { |
| 5895 | final String iccId = getIccId(subId); |
| 5896 | final Phone phone = getPhone(subId); |
| 5897 | if (phone == null) { |
| 5898 | return false; |
| 5899 | } |
| 5900 | final String subscriberId = phone.getSubscriberId(); |
| 5901 | |
| 5902 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5903 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5904 | + subscriberId + " to " + number); |
| 5905 | } |
| 5906 | |
| 5907 | if (TextUtils.isEmpty(iccId)) { |
| 5908 | return false; |
| 5909 | } |
| 5910 | |
| 5911 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5912 | |
| 5913 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5914 | if (alphaTag == null) { |
| 5915 | editor.remove(alphaTagPrefKey); |
| 5916 | } else { |
| 5917 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5918 | } |
| 5919 | |
| 5920 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5921 | // track all merged IMSIs based on line number |
| 5922 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5923 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5924 | if (number == null) { |
| 5925 | editor.remove(numberPrefKey); |
| 5926 | editor.remove(subscriberPrefKey); |
| 5927 | } else { |
| 5928 | editor.putString(numberPrefKey, number); |
| 5929 | editor.putString(subscriberPrefKey, subscriberId); |
| 5930 | } |
| 5931 | |
| 5932 | editor.commit(); |
| 5933 | return true; |
| 5934 | } finally { |
| 5935 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5936 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5937 | } |
| 5938 | |
| 5939 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5940 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 5941 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5942 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5943 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5944 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5945 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5946 | return null; |
| 5947 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5948 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5949 | final long identity = Binder.clearCallingIdentity(); |
| 5950 | try { |
| 5951 | String iccId = getIccId(subId); |
| 5952 | if (iccId != null) { |
| 5953 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5954 | if (DBG_MERGE) { |
| 5955 | log("getLine1NumberForDisplay returning " |
| 5956 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5957 | } |
| 5958 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5959 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5960 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5961 | return null; |
| 5962 | } finally { |
| 5963 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5964 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5965 | } |
| 5966 | |
| 5967 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5968 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 5969 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5970 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5971 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5972 | return null; |
| 5973 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5974 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5975 | final long identity = Binder.clearCallingIdentity(); |
| 5976 | try { |
| 5977 | String iccId = getIccId(subId); |
| 5978 | if (iccId != null) { |
| 5979 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5980 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5981 | } |
| 5982 | return null; |
| 5983 | } finally { |
| 5984 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5985 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5986 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5987 | |
| 5988 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5989 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 5990 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5991 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5992 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5993 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5994 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5995 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5996 | return null; |
| 5997 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5998 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5999 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6000 | // the process, where TelephonyManager was instantiated. |
| 6001 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6002 | final long identity = Binder.clearCallingIdentity(); |
| 6003 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6004 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6005 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6006 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6007 | |
| 6008 | // Figure out what subscribers are currently active |
| 6009 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6010 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6011 | // Only consider subs which match the current subId |
| 6012 | // This logic can be simplified. See b/131189269 for progress. |
| 6013 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6014 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6015 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6016 | |
| 6017 | // First pass, find a number override for an active subscriber |
| 6018 | String mergeNumber = null; |
| 6019 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6020 | for (String key : prefs.keySet()) { |
| 6021 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6022 | final String subscriberId = (String) prefs.get(key); |
| 6023 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6024 | final String iccId = key.substring( |
| 6025 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6026 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6027 | mergeNumber = (String) prefs.get(numberKey); |
| 6028 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6029 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6030 | + " for active subscriber " + subscriberId); |
| 6031 | } |
| 6032 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6033 | break; |
| 6034 | } |
| 6035 | } |
| 6036 | } |
| 6037 | } |
| 6038 | |
| 6039 | // Shortcut when no active merged subscribers |
| 6040 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6041 | return null; |
| 6042 | } |
| 6043 | |
| 6044 | // Second pass, find all subscribers under that line override |
| 6045 | final ArraySet<String> result = new ArraySet<>(); |
| 6046 | for (String key : prefs.keySet()) { |
| 6047 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6048 | final String number = (String) prefs.get(key); |
| 6049 | if (mergeNumber.equals(number)) { |
| 6050 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6051 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6052 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6053 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6054 | result.add(subscriberId); |
| 6055 | } |
| 6056 | } |
| 6057 | } |
| 6058 | } |
| 6059 | |
| 6060 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6061 | Arrays.sort(resultArray); |
| 6062 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6063 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6064 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6065 | } |
| 6066 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6067 | } finally { |
| 6068 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6069 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6070 | } |
| 6071 | |
| 6072 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6073 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 6074 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 6075 | |
| 6076 | final long identity = Binder.clearCallingIdentity(); |
| 6077 | try { |
| 6078 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6079 | TelephonyManager.class); |
| 6080 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6081 | if (subscriberId == null) { |
| 6082 | if (DBG) { |
| 6083 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 6084 | + subId); |
| 6085 | } |
| 6086 | return null; |
| 6087 | } |
| 6088 | |
| 6089 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6090 | .getSubscriptionInfo(subId); |
| 6091 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6092 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6093 | if (groupUuid == null) { |
| 6094 | return new String[]{subscriberId}; |
| 6095 | } |
| 6096 | |
| 6097 | // Get all subscriberIds from the group. |
| 6098 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6099 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6100 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 6101 | null); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6102 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6103 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6104 | if (subscriberId != null) { |
| 6105 | mergedSubscriberIds.add(subscriberId); |
| 6106 | } |
| 6107 | } |
| 6108 | |
| 6109 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6110 | } finally { |
| 6111 | Binder.restoreCallingIdentity(identity); |
| 6112 | |
| 6113 | } |
| 6114 | } |
| 6115 | |
| 6116 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6117 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6118 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6119 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6120 | |
| 6121 | final long identity = Binder.clearCallingIdentity(); |
| 6122 | try { |
| 6123 | final Phone phone = getPhone(subId); |
| 6124 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6125 | } finally { |
| 6126 | Binder.restoreCallingIdentity(identity); |
| 6127 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6128 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6129 | |
| 6130 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6131 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6132 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6133 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6134 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6135 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6136 | |
| 6137 | final long identity = Binder.clearCallingIdentity(); |
| 6138 | try { |
| 6139 | final Phone phone = getPhone(subId); |
| 6140 | if (phone == null) { |
| 6141 | return false; |
| 6142 | } |
| 6143 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6144 | cdmaNonRoamingList); |
| 6145 | } finally { |
| 6146 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6147 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6148 | } |
| 6149 | |
| 6150 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6151 | @Deprecated |
| 6152 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6153 | enforceModifyPermission(); |
| 6154 | |
| 6155 | int returnValue = 0; |
| 6156 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6157 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6158 | if(result.exception == null) { |
| 6159 | if (result.result != null) { |
| 6160 | byte[] responseData = (byte[])(result.result); |
| 6161 | if(responseData.length > oemResp.length) { |
| 6162 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6163 | responseData.length + "bytes. Buffer Size is " + |
| 6164 | oemResp.length + "bytes."); |
| 6165 | } |
| 6166 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6167 | returnValue = responseData.length; |
| 6168 | } |
| 6169 | } else { |
| 6170 | CommandException ex = (CommandException) result.exception; |
| 6171 | returnValue = ex.getCommandError().ordinal(); |
| 6172 | if(returnValue > 0) returnValue *= -1; |
| 6173 | } |
| 6174 | } catch (RuntimeException e) { |
| 6175 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6176 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6177 | if(returnValue > 0) returnValue *= -1; |
| 6178 | } |
| 6179 | |
| 6180 | return returnValue; |
| 6181 | } |
| 6182 | |
| 6183 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6184 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6185 | try { |
| 6186 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6187 | } catch (RuntimeException e) { |
| 6188 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6189 | } |
| 6190 | } |
| 6191 | |
| 6192 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6193 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6194 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6195 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6196 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6197 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6198 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6199 | final long identity = Binder.clearCallingIdentity(); |
| 6200 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6201 | TelephonyPermissions |
| 6202 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6203 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6204 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6205 | } finally { |
| 6206 | Binder.restoreCallingIdentity(identity); |
| 6207 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6208 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6209 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6210 | |
| 6211 | @Override |
| 6212 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6213 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6214 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6215 | |
| 6216 | final long identity = Binder.clearCallingIdentity(); |
| 6217 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6218 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6219 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6220 | } finally { |
| 6221 | Binder.restoreCallingIdentity(identity); |
| 6222 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6226 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6227 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6228 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6229 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6230 | return false; |
| 6231 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6232 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6233 | final long identity = Binder.clearCallingIdentity(); |
| 6234 | try { |
| 6235 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6236 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6237 | // In the long run, we may instead need to check if there exists a connection service |
| 6238 | // which can support video calling. |
| 6239 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6240 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6241 | return imsManager.isVtEnabledByPlatform() |
| 6242 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6243 | && imsManager.isVtEnabledByUser(); |
| 6244 | } finally { |
| 6245 | Binder.restoreCallingIdentity(identity); |
| 6246 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6247 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6248 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6249 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6250 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6251 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6252 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6253 | mApp, subId, callingPackage, callingFeatureId, |
| 6254 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6255 | return false; |
| 6256 | } |
| 6257 | |
| 6258 | final long identity = Binder.clearCallingIdentity(); |
| 6259 | try { |
| 6260 | CarrierConfigManager configManager = |
| 6261 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6262 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6263 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6264 | } finally { |
| 6265 | Binder.restoreCallingIdentity(identity); |
| 6266 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6267 | } |
| 6268 | |
| 6269 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6270 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6271 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6272 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6273 | return false; |
| 6274 | } |
| 6275 | |
| 6276 | final long identity = Binder.clearCallingIdentity(); |
| 6277 | try { |
| 6278 | CarrierConfigManager configManager = |
| 6279 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6280 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6281 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6282 | } finally { |
| 6283 | Binder.restoreCallingIdentity(identity); |
| 6284 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6285 | } |
| 6286 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6287 | @Override |
| 6288 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6289 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6290 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6291 | } |
| 6292 | |
| 6293 | @Override |
| 6294 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6295 | final long identity = Binder.clearCallingIdentity(); |
| 6296 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6297 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6298 | } finally { |
| 6299 | Binder.restoreCallingIdentity(identity); |
| 6300 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6301 | } |
| 6302 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6303 | /** |
| 6304 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6305 | * support for the feature and device firmware support. |
| 6306 | * |
| 6307 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6308 | */ |
| 6309 | @Override |
| 6310 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6311 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6312 | final Phone phone = getPhone(subscriptionId); |
| 6313 | if (phone == null) { |
| 6314 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6315 | return false; |
| 6316 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6317 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6318 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6319 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6320 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6321 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6322 | return isCarrierSupported && isDeviceSupported; |
| 6323 | } finally { |
| 6324 | Binder.restoreCallingIdentity(identity); |
| 6325 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6326 | } |
| 6327 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6328 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6329 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6330 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6331 | * 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] | 6332 | */ |
| 6333 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6334 | final long identity = Binder.clearCallingIdentity(); |
| 6335 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6336 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6337 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6338 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6339 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6340 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6341 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6342 | } finally { |
| 6343 | Binder.restoreCallingIdentity(identity); |
| 6344 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6345 | } |
| 6346 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6347 | @Deprecated |
| 6348 | @Override |
| 6349 | public String getDeviceId(String callingPackage) { |
| 6350 | return getDeviceIdWithFeature(callingPackage, null); |
| 6351 | } |
| 6352 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6353 | /** |
| 6354 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6355 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6356 | * |
| 6357 | * <p>Requires Permission: |
| 6358 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6359 | */ |
| 6360 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6361 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6362 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6363 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6364 | return null; |
| 6365 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6366 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6367 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6368 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6369 | return null; |
| 6370 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6371 | |
| 6372 | final long identity = Binder.clearCallingIdentity(); |
| 6373 | try { |
| 6374 | return phone.getDeviceId(); |
| 6375 | } finally { |
| 6376 | Binder.restoreCallingIdentity(identity); |
| 6377 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6378 | } |
| 6379 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6380 | /** |
| 6381 | * {@hide} |
| 6382 | * Returns the IMS Registration Status on a particular subid |
| 6383 | * |
| 6384 | * @param subId |
| 6385 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6386 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6387 | Phone phone = getPhone(subId); |
| 6388 | if (phone != null) { |
| 6389 | return phone.isImsRegistered(); |
| 6390 | } else { |
| 6391 | return false; |
| 6392 | } |
| 6393 | } |
| 6394 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6395 | @Override |
| 6396 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6397 | final long identity = Binder.clearCallingIdentity(); |
| 6398 | try { |
| 6399 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6400 | } finally { |
| 6401 | Binder.restoreCallingIdentity(identity); |
| 6402 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6403 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6404 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6405 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6406 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6407 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6408 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6409 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6410 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6411 | } |
| 6412 | final long identity = Binder.clearCallingIdentity(); |
| 6413 | try { |
| 6414 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6415 | } finally { |
| 6416 | Binder.restoreCallingIdentity(identity); |
| 6417 | } |
| 6418 | } |
| 6419 | |
| 6420 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6421 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6422 | final long identity = Binder.clearCallingIdentity(); |
| 6423 | try { |
| 6424 | Phone phone = getPhone(subscriptionId); |
| 6425 | if (phone == null) { |
| 6426 | return null; |
| 6427 | } |
| 6428 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6429 | } finally { |
| 6430 | Binder.restoreCallingIdentity(identity); |
| 6431 | } |
| 6432 | } |
| 6433 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6434 | /** |
| 6435 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6436 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6437 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6438 | final long identity = Binder.clearCallingIdentity(); |
| 6439 | try { |
| 6440 | Phone phone = getPhone(subId); |
| 6441 | if (phone != null) { |
| 6442 | return phone.isWifiCallingEnabled(); |
| 6443 | } else { |
| 6444 | return false; |
| 6445 | } |
| 6446 | } finally { |
| 6447 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6448 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6449 | } |
| 6450 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6451 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6452 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6453 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6454 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6455 | final long identity = Binder.clearCallingIdentity(); |
| 6456 | try { |
| 6457 | Phone phone = getPhone(subId); |
| 6458 | if (phone != null) { |
| 6459 | return phone.isVideoEnabled(); |
| 6460 | } else { |
| 6461 | return false; |
| 6462 | } |
| 6463 | } finally { |
| 6464 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6465 | } |
| 6466 | } |
| 6467 | |
| 6468 | /** |
| 6469 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6470 | * defined in {@link ImsRegistrationImplBase}. |
| 6471 | */ |
| 6472 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6473 | final long identity = Binder.clearCallingIdentity(); |
| 6474 | try { |
| 6475 | Phone phone = getPhone(subId); |
| 6476 | if (phone != null) { |
| 6477 | return phone.getImsRegistrationTech(); |
| 6478 | } else { |
| 6479 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6480 | } |
| 6481 | } finally { |
| 6482 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6483 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6484 | } |
| 6485 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6486 | @Override |
| 6487 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6488 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6489 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6490 | return; |
| 6491 | } |
| 6492 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6493 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6494 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6495 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6496 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6497 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6498 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6499 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6500 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6501 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6502 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6503 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6504 | // There has been issues when Sms raw table somehow stores orphan |
| 6505 | // fragments. They lead to garbled message when new fragments come |
| 6506 | // in and combined with those stale ones. In case this happens again, |
| 6507 | // user can reset all network settings which will clean up this table. |
| 6508 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6509 | // Clean up IMS settings as well here. |
| 6510 | int slotId = getSlotIndex(subId); |
| 6511 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6512 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6513 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6514 | |
| 6515 | // Erase modem config if erase modem on network setting is enabled. |
| 6516 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6517 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6518 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6519 | sendEraseModemConfig(getDefaultPhone()); |
| 6520 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6521 | } finally { |
| 6522 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6523 | } |
| 6524 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6525 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6526 | private void cleanUpSmsRawTable(Context context) { |
| 6527 | ContentResolver resolver = context.getContentResolver(); |
| 6528 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6529 | resolver.delete(uri, null, null); |
| 6530 | } |
| 6531 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6532 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6533 | public String getSimLocaleForSubscriber(int subId) { |
| 6534 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6535 | final Phone phone = getPhone(subId); |
| 6536 | if (phone == null) { |
| 6537 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6538 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6539 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6540 | final long identity = Binder.clearCallingIdentity(); |
| 6541 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6542 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6543 | phone.getContext().getOpPackageName(), null); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6544 | if (info == null) { |
| 6545 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6546 | return null; |
| 6547 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6548 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6549 | // preferences (EF-PL and EF-LI)... |
| 6550 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6551 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6552 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6553 | if (localeFromDefaultSim != null) { |
| 6554 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6555 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6556 | + localeFromDefaultSim); |
| 6557 | return localeFromDefaultSim.toLanguageTag(); |
| 6558 | } else { |
| 6559 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6560 | } |
| 6561 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6562 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6563 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6564 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6565 | // the SIM and carrier preferences does not include a country we add the country |
| 6566 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6567 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6568 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6569 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6570 | return mccLocale.toLanguageTag(); |
| 6571 | } |
| 6572 | |
| 6573 | if (DBG) log("No locale found - returning null"); |
| 6574 | return null; |
| 6575 | } finally { |
| 6576 | Binder.restoreCallingIdentity(identity); |
| 6577 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6578 | } |
| 6579 | |
| 6580 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6581 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 6582 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6583 | } |
| 6584 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6585 | /** |
| 6586 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6587 | */ |
| 6588 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6589 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 6590 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6591 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6592 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6593 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6594 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6595 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6596 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6597 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6598 | * representing the state of the modem. |
| 6599 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6600 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6601 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6602 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6603 | */ |
| 6604 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6605 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6606 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6607 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6608 | |
| 6609 | final long identity = Binder.clearCallingIdentity(); |
| 6610 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 6611 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6612 | } finally { |
| 6613 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6614 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6615 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6616 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6617 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6618 | // less than total activity duration. |
| 6619 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6620 | if (info == null) { |
| 6621 | return false; |
| 6622 | } |
| 6623 | int activityDurationMs = |
| 6624 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6625 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6626 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6627 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6628 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6629 | } |
| 6630 | return (info.isValid() |
| 6631 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6632 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6633 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6634 | && (totalTxTimeMs <= activityDurationMs)); |
| 6635 | } |
| 6636 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6637 | /** |
| 6638 | * {@hide} |
| 6639 | * Returns the service state information on specified subscription. |
| 6640 | */ |
| 6641 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6642 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6643 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6644 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6645 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6646 | return null; |
| 6647 | } |
| 6648 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6649 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6650 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6651 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6652 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6653 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6654 | .setCallingPid(Binder.getCallingPid()) |
| 6655 | .setCallingUid(Binder.getCallingUid()) |
| 6656 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6657 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6658 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6659 | .build()); |
| 6660 | |
| 6661 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6662 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6663 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6664 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6665 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6666 | .setCallingPid(Binder.getCallingPid()) |
| 6667 | .setCallingUid(Binder.getCallingUid()) |
| 6668 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6669 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6670 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6671 | .build()); |
| 6672 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6673 | boolean hasFinePermission = |
| 6674 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6675 | boolean hasCoarsePermission = |
| 6676 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6677 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6678 | final long identity = Binder.clearCallingIdentity(); |
| 6679 | try { |
| 6680 | final Phone phone = getPhone(subId); |
| 6681 | if (phone == null) { |
| 6682 | return null; |
| 6683 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6684 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6685 | ServiceState ss = phone.getServiceState(); |
| 6686 | |
| 6687 | // Scrub out the location info in ServiceState depending on what level of access |
| 6688 | // the caller has. |
| 6689 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6690 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6691 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6692 | } finally { |
| 6693 | Binder.restoreCallingIdentity(identity); |
| 6694 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6695 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6696 | |
| 6697 | /** |
| 6698 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6699 | * |
| 6700 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6701 | * voicemail ringtone. |
| 6702 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6703 | * PhoneAccount. |
| 6704 | */ |
| 6705 | @Override |
| 6706 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6707 | final long identity = Binder.clearCallingIdentity(); |
| 6708 | try { |
| 6709 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6710 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6711 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6712 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6713 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6714 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6715 | } finally { |
| 6716 | Binder.restoreCallingIdentity(identity); |
| 6717 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6718 | } |
| 6719 | |
| 6720 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6721 | * Sets the per-account voicemail ringtone. |
| 6722 | * |
| 6723 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6724 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6725 | * |
| 6726 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6727 | * voicemail ringtone. |
| 6728 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6729 | * PhoneAccount. |
| 6730 | */ |
| 6731 | @Override |
| 6732 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6733 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6734 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6735 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6736 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6737 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6738 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6739 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6740 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6741 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6742 | |
| 6743 | final long identity = Binder.clearCallingIdentity(); |
| 6744 | try { |
| 6745 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6746 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6747 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6748 | } |
| 6749 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6750 | } finally { |
| 6751 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6752 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6753 | } |
| 6754 | |
| 6755 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6756 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6757 | * |
| 6758 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6759 | * voicemail vibration setting. |
| 6760 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6761 | */ |
| 6762 | @Override |
| 6763 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6764 | final long identity = Binder.clearCallingIdentity(); |
| 6765 | try { |
| 6766 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6767 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6768 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6769 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6770 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6771 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6772 | } finally { |
| 6773 | Binder.restoreCallingIdentity(identity); |
| 6774 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6775 | } |
| 6776 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6777 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6778 | * Sets the per-account voicemail vibration. |
| 6779 | * |
| 6780 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6781 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6782 | * |
| 6783 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6784 | * voicemail vibration setting. |
| 6785 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6786 | * specific PhoneAccount. |
| 6787 | */ |
| 6788 | @Override |
| 6789 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6790 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6791 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6792 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6793 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6794 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6795 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6796 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6797 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6798 | } |
| 6799 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6800 | final long identity = Binder.clearCallingIdentity(); |
| 6801 | try { |
| 6802 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6803 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6804 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6805 | } |
| 6806 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6807 | } finally { |
| 6808 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6809 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6810 | } |
| 6811 | |
| 6812 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6813 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6814 | * |
| 6815 | * @throws SecurityException if the caller does not have the required permission |
| 6816 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6817 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6818 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6819 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6820 | } |
| 6821 | |
| 6822 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6823 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6824 | * permission. |
| 6825 | * |
| 6826 | * @throws SecurityException if the caller does not have the required permission |
| 6827 | */ |
| 6828 | private void enforceSendSmsPermission() { |
| 6829 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6830 | } |
| 6831 | |
| 6832 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6833 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6834 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6835 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6836 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6837 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6838 | final long identity = Binder.clearCallingIdentity(); |
| 6839 | try { |
| 6840 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6841 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6842 | if (componentName == null) { |
| 6843 | throw new SecurityException( |
| 6844 | "Caller not current active visual voicemail package[null]"); |
| 6845 | } |
| 6846 | String vvmPackage = componentName.getPackageName(); |
| 6847 | if (!callingPackage.equals(vvmPackage)) { |
| 6848 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6849 | + vvmPackage + "]"); |
| 6850 | } |
| 6851 | } finally { |
| 6852 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6853 | } |
| 6854 | } |
| 6855 | |
| 6856 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6857 | * Return the application ID for the app type. |
| 6858 | * |
| 6859 | * @param subId the subscription ID that this request applies to. |
| 6860 | * @param appType the uicc app type. |
| 6861 | * @return Application ID for specificied app type, or null if no uicc. |
| 6862 | */ |
| 6863 | @Override |
| 6864 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6865 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6866 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6867 | |
| 6868 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6869 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6870 | if (phone == null) { |
| 6871 | return null; |
| 6872 | } |
| 6873 | String aid = null; |
| 6874 | try { |
| 6875 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6876 | .getApplicationByType(appType).getAid(); |
| 6877 | } catch (Exception e) { |
| 6878 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6879 | } |
| 6880 | return aid; |
| 6881 | } finally { |
| 6882 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6883 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6884 | } |
| 6885 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6886 | /** |
| 6887 | * Return the Electronic Serial Number. |
| 6888 | * |
| 6889 | * @param subId the subscription ID that this request applies to. |
| 6890 | * @return ESN or null if error. |
| 6891 | */ |
| 6892 | @Override |
| 6893 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6894 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6895 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6896 | |
| 6897 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6898 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6899 | if (phone == null) { |
| 6900 | return null; |
| 6901 | } |
| 6902 | String esn = null; |
| 6903 | try { |
| 6904 | esn = phone.getEsn(); |
| 6905 | } catch (Exception e) { |
| 6906 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6907 | } |
| 6908 | return esn; |
| 6909 | } finally { |
| 6910 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6911 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6912 | } |
| 6913 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6914 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6915 | * Return the Preferred Roaming List Version. |
| 6916 | * |
| 6917 | * @param subId the subscription ID that this request applies to. |
| 6918 | * @return PRLVersion or null if error. |
| 6919 | */ |
| 6920 | @Override |
| 6921 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6922 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6923 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6924 | |
| 6925 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6926 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6927 | if (phone == null) { |
| 6928 | return null; |
| 6929 | } |
| 6930 | String cdmaPrlVersion = null; |
| 6931 | try { |
| 6932 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6933 | } catch (Exception e) { |
| 6934 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6935 | } |
| 6936 | return cdmaPrlVersion; |
| 6937 | } finally { |
| 6938 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6939 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6940 | } |
| 6941 | |
| 6942 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6943 | * Get snapshot of Telephony histograms |
| 6944 | * @return List of Telephony histograms |
| 6945 | * @hide |
| 6946 | */ |
| 6947 | @Override |
| 6948 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6949 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6950 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6951 | |
| 6952 | final long identity = Binder.clearCallingIdentity(); |
| 6953 | try { |
| 6954 | return RIL.getTelephonyRILTimingHistograms(); |
| 6955 | } finally { |
| 6956 | Binder.restoreCallingIdentity(identity); |
| 6957 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6958 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6959 | |
| 6960 | /** |
| 6961 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6962 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6963 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6964 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6965 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6966 | * @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] | 6967 | */ |
| 6968 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6969 | @TelephonyManager.SetCarrierRestrictionResult |
| 6970 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6971 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6972 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6973 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6974 | if (carrierRestrictionRules == null) { |
| 6975 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6976 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6977 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6978 | final long identity = Binder.clearCallingIdentity(); |
| 6979 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6980 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6981 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6982 | } finally { |
| 6983 | Binder.restoreCallingIdentity(identity); |
| 6984 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6985 | } |
| 6986 | |
| 6987 | /** |
| 6988 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6989 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6990 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6991 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6992 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6993 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6994 | */ |
| 6995 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6996 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6997 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6998 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6999 | |
| 7000 | final long identity = Binder.clearCallingIdentity(); |
| 7001 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7002 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7003 | if (response instanceof CarrierRestrictionRules) { |
| 7004 | return (CarrierRestrictionRules) response; |
| 7005 | } |
| 7006 | // Response is an Exception of some kind, |
| 7007 | // which is signalled to the user as a NULL retval |
| 7008 | return null; |
| 7009 | } catch (Exception e) { |
| 7010 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7011 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7012 | } finally { |
| 7013 | Binder.restoreCallingIdentity(identity); |
| 7014 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7015 | } |
| 7016 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7017 | /** |
| 7018 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 7019 | * @param subId the subscription ID that this action applies to. |
| 7020 | * @param enabled control enable or disable metered apns. |
| 7021 | * {@hide} |
| 7022 | */ |
| 7023 | @Override |
| 7024 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 7025 | enforceModifyPermission(); |
| 7026 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7027 | |
| 7028 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7029 | if (phone == null) { |
| 7030 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 7031 | return; |
| 7032 | } |
| 7033 | try { |
| 7034 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7035 | } catch (Exception e) { |
| 7036 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7037 | } finally { |
| 7038 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7039 | } |
| 7040 | } |
| 7041 | |
| 7042 | /** |
| 7043 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7044 | * @param subId the subscription ID that this action applies to. |
| 7045 | * @param enabled control enable or disable radio. |
| 7046 | * {@hide} |
| 7047 | */ |
| 7048 | @Override |
| 7049 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7050 | enforceModifyPermission(); |
| 7051 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7052 | |
| 7053 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7054 | if (phone == null) { |
| 7055 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7056 | return; |
| 7057 | } |
| 7058 | try { |
| 7059 | phone.carrierActionSetRadioEnabled(enabled); |
| 7060 | } catch (Exception e) { |
| 7061 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7062 | } finally { |
| 7063 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7064 | } |
| 7065 | } |
| 7066 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7067 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7068 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7069 | * network status based on which carrier apps could apply actions accordingly, |
| 7070 | * enable/disable default url handler for example. |
| 7071 | * |
| 7072 | * @param subId the subscription ID that this action applies to. |
| 7073 | * @param report control start/stop reporting the default network status. |
| 7074 | * {@hide} |
| 7075 | */ |
| 7076 | @Override |
| 7077 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7078 | enforceModifyPermission(); |
| 7079 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7080 | |
| 7081 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7082 | if (phone == null) { |
| 7083 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7084 | return; |
| 7085 | } |
| 7086 | try { |
| 7087 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7088 | } catch (Exception e) { |
| 7089 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7090 | } finally { |
| 7091 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7092 | } |
| 7093 | } |
| 7094 | |
| 7095 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7096 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7097 | * @param subId the subscription ID that this action applies to. |
| 7098 | * {@hide} |
| 7099 | */ |
| 7100 | @Override |
| 7101 | public void carrierActionResetAll(int subId) { |
| 7102 | enforceModifyPermission(); |
| 7103 | final Phone phone = getPhone(subId); |
| 7104 | if (phone == null) { |
| 7105 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7106 | return; |
| 7107 | } |
| 7108 | try { |
| 7109 | phone.carrierActionResetAll(); |
| 7110 | } catch (Exception e) { |
| 7111 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7112 | } |
| 7113 | } |
| 7114 | |
| 7115 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7116 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7117 | * bug report is being generated. |
| 7118 | */ |
| 7119 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7120 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7121 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7122 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7123 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7124 | + Binder.getCallingPid() |
| 7125 | + ", uid=" + Binder.getCallingUid() |
| 7126 | + "without permission " |
| 7127 | + android.Manifest.permission.DUMP); |
| 7128 | return; |
| 7129 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7130 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7131 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7132 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7133 | @Override |
| 7134 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 7135 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 7136 | throws RemoteException { |
Torbjorn Eklund | 1050cb0 | 2018-11-16 14:05:38 +0100 | [diff] [blame] | 7137 | (new TelephonyShellCommand(this, getDefaultPhone().getContext())) |
| 7138 | .exec(this, in, out, err, args, callback, resultReceiver); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7139 | } |
| 7140 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7141 | /** |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7142 | * Policy control of data connection. Usually used when data limit is passed. |
| 7143 | * @param enabled True if enabling the data, otherwise disabling. |
| 7144 | * @param subId Subscription index |
| 7145 | * {@hide} |
| 7146 | */ |
| 7147 | @Override |
| 7148 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 7149 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7150 | |
| 7151 | final long identity = Binder.clearCallingIdentity(); |
| 7152 | try { |
| 7153 | Phone phone = getPhone(subId); |
| 7154 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 7155 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7156 | } |
| 7157 | } finally { |
| 7158 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7159 | } |
| 7160 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7161 | |
| 7162 | /** |
| 7163 | * Get Client request stats |
| 7164 | * @return List of Client Request Stats |
| 7165 | * @hide |
| 7166 | */ |
| 7167 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7168 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7169 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7170 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7171 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7172 | return null; |
| 7173 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7174 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7175 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7176 | final long identity = Binder.clearCallingIdentity(); |
| 7177 | try { |
| 7178 | if (phone != null) { |
| 7179 | return phone.getClientRequestStats(); |
| 7180 | } |
| 7181 | |
| 7182 | return null; |
| 7183 | } finally { |
| 7184 | Binder.restoreCallingIdentity(identity); |
| 7185 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7186 | } |
| 7187 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7188 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7189 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7190 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7191 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7192 | |
| 7193 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7194 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7195 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7196 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7197 | * @param state State of SIM (power down, power up, pass through) |
| 7198 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7199 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7200 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7201 | * |
| 7202 | **/ |
| 7203 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7204 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7205 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7206 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7207 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7208 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7209 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7210 | final long identity = Binder.clearCallingIdentity(); |
| 7211 | try { |
| 7212 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7213 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7214 | } |
| 7215 | } finally { |
| 7216 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7217 | } |
| 7218 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7219 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7220 | private boolean isUssdApiAllowed(int subId) { |
| 7221 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7222 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7223 | if (configManager == null) { |
| 7224 | return false; |
| 7225 | } |
| 7226 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7227 | if (pb == null) { |
| 7228 | return false; |
| 7229 | } |
| 7230 | return pb.getBoolean( |
| 7231 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7232 | } |
| 7233 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7234 | /** |
| 7235 | * Check if phone is in emergency callback mode |
| 7236 | * @return true if phone is in emergency callback mode |
| 7237 | * @param subId sub id |
| 7238 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7239 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7240 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7241 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7242 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7243 | |
| 7244 | final long identity = Binder.clearCallingIdentity(); |
| 7245 | try { |
| 7246 | if (phone != null) { |
| 7247 | return phone.isInEcm(); |
| 7248 | } else { |
| 7249 | return false; |
| 7250 | } |
| 7251 | } finally { |
| 7252 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7253 | } |
| 7254 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7255 | |
| 7256 | /** |
| 7257 | * Get the current signal strength information for the given subscription. |
| 7258 | * Because this information is not updated when the device is in a low power state |
| 7259 | * it should not be relied-upon to be current. |
| 7260 | * @param subId Subscription index |
| 7261 | * @return the most recent cached signal strength info from the modem |
| 7262 | */ |
| 7263 | @Override |
| 7264 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7265 | final long identity = Binder.clearCallingIdentity(); |
| 7266 | try { |
| 7267 | Phone p = getPhone(subId); |
| 7268 | if (p == null) { |
| 7269 | return null; |
| 7270 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7271 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7272 | return p.getSignalStrength(); |
| 7273 | } finally { |
| 7274 | Binder.restoreCallingIdentity(identity); |
| 7275 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7276 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7277 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7278 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7279 | * Get the current modem radio state for the given slot. |
| 7280 | * @param slotIndex slot index. |
| 7281 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7282 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7283 | * @return the current radio power state from the modem |
| 7284 | */ |
| 7285 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7286 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7287 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7288 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7289 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7290 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7291 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7292 | } |
| 7293 | |
| 7294 | final long identity = Binder.clearCallingIdentity(); |
| 7295 | try { |
| 7296 | return phone.getRadioPowerState(); |
| 7297 | } finally { |
| 7298 | Binder.restoreCallingIdentity(identity); |
| 7299 | } |
| 7300 | } |
| 7301 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7302 | } |
| 7303 | |
| 7304 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7305 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7306 | * |
| 7307 | * <p>Requires one of the following permissions: |
| 7308 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7309 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7310 | * privileges. |
| 7311 | * |
| 7312 | * @param subId subscription id |
| 7313 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7314 | * {@code false}. |
| 7315 | */ |
| 7316 | @Override |
| 7317 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7318 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7319 | null /* message */); |
| 7320 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7321 | boolean isEnabled = false; |
| 7322 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7323 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7324 | Phone phone = getPhone(subId); |
| 7325 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7326 | } catch (Exception e) { |
| 7327 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7328 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7329 | } finally { |
| 7330 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7331 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7332 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7333 | } |
| 7334 | |
| 7335 | |
| 7336 | /** |
| 7337 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7338 | * |
| 7339 | * <p> Requires permission: |
| 7340 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7341 | * privileges. |
| 7342 | * |
| 7343 | * @param subId subscription id |
| 7344 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7345 | */ |
| 7346 | @Override |
| 7347 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7348 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7349 | mApp, subId, "setDataRoamingEnabled"); |
| 7350 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7351 | final long identity = Binder.clearCallingIdentity(); |
| 7352 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7353 | Phone phone = getPhone(subId); |
| 7354 | if (phone != null) { |
| 7355 | phone.setDataRoamingEnabled(isEnabled); |
| 7356 | } |
| 7357 | } finally { |
| 7358 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7359 | } |
| 7360 | } |
| 7361 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7362 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7363 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7364 | TelephonyPermissions |
| 7365 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7366 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7367 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7368 | boolean isAllowed = true; |
| 7369 | final long identity = Binder.clearCallingIdentity(); |
| 7370 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7371 | Phone phone = getPhone(subId); |
| 7372 | if (phone != null) { |
| 7373 | isAllowed = phone.isCspPlmnEnabled(); |
| 7374 | } |
| 7375 | } finally { |
| 7376 | Binder.restoreCallingIdentity(identity); |
| 7377 | } |
| 7378 | return isAllowed; |
| 7379 | } |
| 7380 | |
| 7381 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7382 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7383 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7384 | try { |
| 7385 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7386 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7387 | } catch (SecurityException e) { |
| 7388 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7389 | // has carrier privileges on an active UICC |
| 7390 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7391 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7392 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7393 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7394 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7395 | |
| 7396 | final long identity = Binder.clearCallingIdentity(); |
| 7397 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7398 | UiccController uiccController = UiccController.getInstance(); |
| 7399 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7400 | if (hasReadPermission) { |
| 7401 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7402 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7403 | |
| 7404 | // Remove private info if the caller doesn't have access |
| 7405 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7406 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7407 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7408 | // is available |
| 7409 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7410 | if (card == null || card.getUiccProfile() == null) { |
| 7411 | // assume no access if the card or profile is unavailable |
| 7412 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7413 | continue; |
| 7414 | } |
| 7415 | UiccProfile profile = card.getUiccProfile(); |
| 7416 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7417 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7418 | filteredInfos.add(cardInfo); |
| 7419 | } else { |
| 7420 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7421 | } |
| 7422 | } |
| 7423 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7424 | } finally { |
| 7425 | Binder.restoreCallingIdentity(identity); |
| 7426 | } |
| 7427 | } |
| 7428 | |
| 7429 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7430 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7431 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7432 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7433 | final long identity = Binder.clearCallingIdentity(); |
| 7434 | try { |
| 7435 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7436 | if (slots == null) { |
| 7437 | Rlog.i(LOG_TAG, "slots is null."); |
| 7438 | return null; |
| 7439 | } |
| 7440 | |
| 7441 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7442 | for (int i = 0; i < slots.length; i++) { |
| 7443 | UiccSlot slot = slots[i]; |
| 7444 | if (slot == null) { |
| 7445 | continue; |
| 7446 | } |
| 7447 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7448 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7449 | UiccCard card = slot.getUiccCard(); |
| 7450 | if (card != null) { |
| 7451 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7452 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7453 | cardId = slot.getEid(); |
| 7454 | if (TextUtils.isEmpty(cardId)) { |
| 7455 | cardId = slot.getIccId(); |
| 7456 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7457 | } |
| 7458 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7459 | if (cardId != null) { |
| 7460 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7461 | // if cardId is an EID, it's all digits so this is fine |
| 7462 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7463 | } |
| 7464 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7465 | int cardState = 0; |
| 7466 | switch (slot.getCardState()) { |
| 7467 | case CARDSTATE_ABSENT: |
| 7468 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7469 | break; |
| 7470 | case CARDSTATE_PRESENT: |
| 7471 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7472 | break; |
| 7473 | case CARDSTATE_ERROR: |
| 7474 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7475 | break; |
| 7476 | case CARDSTATE_RESTRICTED: |
| 7477 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7478 | break; |
| 7479 | default: |
| 7480 | break; |
| 7481 | |
| 7482 | } |
| 7483 | |
| 7484 | infos[i] = new UiccSlotInfo( |
| 7485 | slot.isActive(), |
| 7486 | slot.isEuicc(), |
| 7487 | cardId, |
| 7488 | cardState, |
| 7489 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7490 | slot.isExtendedApduSupported(), |
| 7491 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7492 | } |
| 7493 | return infos; |
| 7494 | } finally { |
| 7495 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7496 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7497 | } |
| 7498 | |
| 7499 | @Override |
| 7500 | public boolean switchSlots(int[] physicalSlots) { |
| 7501 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7502 | |
| 7503 | final long identity = Binder.clearCallingIdentity(); |
| 7504 | try { |
| 7505 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7506 | } finally { |
| 7507 | Binder.restoreCallingIdentity(identity); |
| 7508 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7509 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7510 | |
| 7511 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7512 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7513 | final long identity = Binder.clearCallingIdentity(); |
| 7514 | try { |
| 7515 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7516 | } finally { |
| 7517 | Binder.restoreCallingIdentity(identity); |
| 7518 | } |
| 7519 | } |
| 7520 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7521 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7522 | * A test API to reload the UICC profile. |
| 7523 | * |
| 7524 | * <p>Requires that the calling app has permission |
| 7525 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7526 | * @hide |
| 7527 | */ |
| 7528 | @Override |
| 7529 | public void refreshUiccProfile(int subId) { |
| 7530 | enforceModifyPermission(); |
| 7531 | |
| 7532 | final long identity = Binder.clearCallingIdentity(); |
| 7533 | try { |
| 7534 | Phone phone = getPhone(subId); |
| 7535 | if (phone == null) { |
| 7536 | return; |
| 7537 | } |
| 7538 | UiccCard uiccCard = phone.getUiccCard(); |
| 7539 | if (uiccCard == null) { |
| 7540 | return; |
| 7541 | } |
| 7542 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7543 | if (uiccProfile == null) { |
| 7544 | return; |
| 7545 | } |
| 7546 | uiccProfile.refresh(); |
| 7547 | } finally { |
| 7548 | Binder.restoreCallingIdentity(identity); |
| 7549 | } |
| 7550 | } |
| 7551 | |
| 7552 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7553 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7554 | */ |
| 7555 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7556 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7557 | } |
| 7558 | |
| 7559 | /** |
| 7560 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7561 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7562 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7563 | */ |
| 7564 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7565 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7566 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7567 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7568 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7569 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7570 | return isDataRoamingEnabled; |
| 7571 | } |
| 7572 | |
| 7573 | /** |
| 7574 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7575 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7576 | */ |
| 7577 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7578 | List<Integer> list = TelephonyProperties.default_network(); |
| 7579 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7580 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7581 | return list.get(phoneId); |
| 7582 | } |
| 7583 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7584 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7585 | |
| 7586 | @Override |
| 7587 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7588 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7589 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7590 | |
| 7591 | final long identity = Binder.clearCallingIdentity(); |
| 7592 | try { |
| 7593 | final Phone phone = getPhone(subId); |
| 7594 | if (phone == null) { |
| 7595 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7596 | return; |
| 7597 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7598 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7599 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7600 | } finally { |
| 7601 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7602 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7603 | } |
| 7604 | |
| 7605 | @Override |
| 7606 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7607 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7608 | |
| 7609 | final long identity = Binder.clearCallingIdentity(); |
| 7610 | try { |
| 7611 | final Phone phone = getPhone(subId); |
| 7612 | if (phone == null) { |
| 7613 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7614 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7615 | } |
| 7616 | return phone.getCarrierIdListVersion(); |
| 7617 | } finally { |
| 7618 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7619 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7620 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7621 | |
| 7622 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7623 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7624 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7625 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7626 | mApp, subId, callingPackage, callingFeatureId, |
| 7627 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7628 | return -1; |
| 7629 | } |
| 7630 | |
| 7631 | final long identity = Binder.clearCallingIdentity(); |
| 7632 | try { |
| 7633 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7634 | } finally { |
| 7635 | Binder.restoreCallingIdentity(identity); |
| 7636 | } |
| 7637 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7638 | |
| 7639 | @Override |
| 7640 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7641 | TelephonyPermissions |
| 7642 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7643 | mApp, subId, "getCdmaRoamingMode"); |
| 7644 | |
| 7645 | final long identity = Binder.clearCallingIdentity(); |
| 7646 | try { |
| 7647 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7648 | } finally { |
| 7649 | Binder.restoreCallingIdentity(identity); |
| 7650 | } |
| 7651 | } |
| 7652 | |
| 7653 | @Override |
| 7654 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7655 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7656 | mApp, subId, "setCdmaRoamingMode"); |
| 7657 | |
| 7658 | final long identity = Binder.clearCallingIdentity(); |
| 7659 | try { |
| 7660 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7661 | } finally { |
| 7662 | Binder.restoreCallingIdentity(identity); |
| 7663 | } |
| 7664 | } |
| 7665 | |
| 7666 | @Override |
| 7667 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7668 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7669 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7670 | |
| 7671 | final long identity = Binder.clearCallingIdentity(); |
| 7672 | try { |
| 7673 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7674 | } finally { |
| 7675 | Binder.restoreCallingIdentity(identity); |
| 7676 | } |
| 7677 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7678 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7679 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7680 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7681 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7682 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7683 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7684 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7685 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7686 | } |
| 7687 | final long identity = Binder.clearCallingIdentity(); |
| 7688 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7689 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7690 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7691 | if (phone.getEmergencyNumberTracker() != null |
| 7692 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7693 | emergencyNumberListInternal.put( |
| 7694 | phone.getSubId(), |
| 7695 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7696 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7697 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7698 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7699 | } finally { |
| 7700 | Binder.restoreCallingIdentity(identity); |
| 7701 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7702 | } |
| 7703 | |
| 7704 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7705 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7706 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7707 | if (!exactMatch) { |
| 7708 | TelephonyPermissions |
| 7709 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7710 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7711 | } |
| 7712 | final long identity = Binder.clearCallingIdentity(); |
| 7713 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7714 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7715 | if (phone.getEmergencyNumberTracker() != null |
| 7716 | && phone.getEmergencyNumberTracker() != null) { |
| 7717 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7718 | number, exactMatch)) { |
| 7719 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7720 | } |
| 7721 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7722 | } |
| 7723 | return false; |
| 7724 | } finally { |
| 7725 | Binder.restoreCallingIdentity(identity); |
| 7726 | } |
| 7727 | } |
| 7728 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7729 | /** |
| 7730 | * Update emergency number list for test mode. |
| 7731 | */ |
| 7732 | @Override |
| 7733 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7734 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7735 | "updateEmergencyNumberListTestMode"); |
| 7736 | |
| 7737 | final long identity = Binder.clearCallingIdentity(); |
| 7738 | try { |
| 7739 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7740 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7741 | if (tracker != null) { |
| 7742 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7743 | } |
| 7744 | } |
| 7745 | } finally { |
| 7746 | Binder.restoreCallingIdentity(identity); |
| 7747 | } |
| 7748 | } |
| 7749 | |
| 7750 | /** |
| 7751 | * Get the full emergency number list for test mode. |
| 7752 | */ |
| 7753 | @Override |
| 7754 | public List<String> getEmergencyNumberListTestMode() { |
| 7755 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7756 | "getEmergencyNumberListTestMode"); |
| 7757 | |
| 7758 | final long identity = Binder.clearCallingIdentity(); |
| 7759 | try { |
| 7760 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7761 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7762 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7763 | if (tracker != null) { |
| 7764 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7765 | emergencyNumbers.add(num.getNumber()); |
| 7766 | } |
| 7767 | } |
| 7768 | } |
| 7769 | return new ArrayList<>(emergencyNumbers); |
| 7770 | } finally { |
| 7771 | Binder.restoreCallingIdentity(identity); |
| 7772 | } |
| 7773 | } |
| 7774 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7775 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7776 | public int getEmergencyNumberDbVersion(int subId) { |
| 7777 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7778 | |
| 7779 | final long identity = Binder.clearCallingIdentity(); |
| 7780 | try { |
| 7781 | final Phone phone = getPhone(subId); |
| 7782 | if (phone == null) { |
| 7783 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7784 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7785 | } |
| 7786 | return phone.getEmergencyNumberDbVersion(); |
| 7787 | } finally { |
| 7788 | Binder.restoreCallingIdentity(identity); |
| 7789 | } |
| 7790 | } |
| 7791 | |
| 7792 | @Override |
| 7793 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7794 | enforceModifyPermission(); |
| 7795 | |
| 7796 | final long identity = Binder.clearCallingIdentity(); |
| 7797 | try { |
| 7798 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7799 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7800 | if (tracker != null) { |
| 7801 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7802 | } |
| 7803 | } |
| 7804 | } finally { |
| 7805 | Binder.restoreCallingIdentity(identity); |
| 7806 | } |
| 7807 | } |
| 7808 | |
| 7809 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 7810 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7811 | enforceActiveEmergencySessionPermission(); |
| 7812 | |
| 7813 | final long identity = Binder.clearCallingIdentity(); |
| 7814 | try { |
| 7815 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7816 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7817 | if (tracker != null) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 7818 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 7819 | } |
| 7820 | } |
| 7821 | } finally { |
| 7822 | Binder.restoreCallingIdentity(identity); |
| 7823 | } |
| 7824 | } |
| 7825 | |
| 7826 | @Override |
| 7827 | public void resetOtaEmergencyNumberDbFilePath() { |
| 7828 | enforceActiveEmergencySessionPermission(); |
| 7829 | |
| 7830 | final long identity = Binder.clearCallingIdentity(); |
| 7831 | try { |
| 7832 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7833 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7834 | if (tracker != null) { |
| 7835 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7836 | } |
| 7837 | } |
| 7838 | } finally { |
| 7839 | Binder.restoreCallingIdentity(identity); |
| 7840 | } |
| 7841 | } |
| 7842 | |
| 7843 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7844 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7845 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7846 | Phone phone = getPhone(subId); |
| 7847 | if (phone == null) { |
| 7848 | return null; |
| 7849 | } |
| 7850 | final long identity = Binder.clearCallingIdentity(); |
| 7851 | try { |
| 7852 | UiccProfile profile = UiccController.getInstance() |
| 7853 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7854 | if (profile != null) { |
| 7855 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7856 | } |
| 7857 | } finally { |
| 7858 | Binder.restoreCallingIdentity(identity); |
| 7859 | } |
| 7860 | return null; |
| 7861 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7862 | |
| 7863 | /** |
| 7864 | * Enable or disable a modem stack. |
| 7865 | */ |
| 7866 | @Override |
| 7867 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7868 | enforceModifyPermission(); |
| 7869 | |
| 7870 | final long identity = Binder.clearCallingIdentity(); |
| 7871 | try { |
| 7872 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7873 | if (phone == null) { |
| 7874 | return false; |
| 7875 | } else { |
| 7876 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7877 | } |
| 7878 | } finally { |
| 7879 | Binder.restoreCallingIdentity(identity); |
| 7880 | } |
| 7881 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7882 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7883 | /** |
| 7884 | * Whether a modem stack is enabled or not. |
| 7885 | */ |
| 7886 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7887 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7888 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7889 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7890 | if (phone == null) return false; |
| 7891 | |
| 7892 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7893 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7894 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7895 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7896 | } |
| 7897 | |
| 7898 | final long identity = Binder.clearCallingIdentity(); |
| 7899 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7900 | try { |
| 7901 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7902 | } catch (NoSuchElementException ex) { |
| 7903 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7904 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7905 | } finally { |
| 7906 | Binder.restoreCallingIdentity(identity); |
| 7907 | } |
| 7908 | } |
| 7909 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7910 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7911 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7912 | enforceModifyPermission(); |
| 7913 | |
| 7914 | final long identity = Binder.clearCallingIdentity(); |
| 7915 | try { |
| 7916 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7917 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7918 | .commit(); |
| 7919 | } finally { |
| 7920 | Binder.restoreCallingIdentity(identity); |
| 7921 | } |
| 7922 | } |
| 7923 | |
| 7924 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7925 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7926 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7927 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7928 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 7929 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7930 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7931 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7932 | |
| 7933 | final long identity = Binder.clearCallingIdentity(); |
| 7934 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7935 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7936 | } finally { |
| 7937 | Binder.restoreCallingIdentity(identity); |
| 7938 | } |
| 7939 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7940 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7941 | @TelephonyManager.IsMultiSimSupportedResult |
| 7942 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7943 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7944 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7945 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7946 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7947 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7948 | } |
| 7949 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7950 | // supported by the modem, indicate that it is restricted. |
| 7951 | PhoneCapability staticCapability = |
| 7952 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7953 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7954 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7955 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7956 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 7957 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7958 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7959 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7960 | } |
| 7961 | // Check if support of multiple SIMs is restricted by carrier |
| 7962 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7963 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7964 | } |
| 7965 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7966 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7967 | } |
| 7968 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7969 | /** |
| 7970 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7971 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7972 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7973 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7974 | * @param numOfSims number of active sims we want to switch to |
| 7975 | */ |
| 7976 | @Override |
| 7977 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7978 | if (numOfSims == 1) { |
| 7979 | enforceModifyPermission(); |
| 7980 | } else { |
| 7981 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7982 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7983 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7984 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7985 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7986 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7987 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7988 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7989 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7990 | return; |
| 7991 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7992 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7993 | } finally { |
| 7994 | Binder.restoreCallingIdentity(identity); |
| 7995 | } |
| 7996 | } |
| 7997 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 7998 | @Override |
| 7999 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8000 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8001 | Phone phone = getPhone(subId); |
| 8002 | if (phone == null) { |
| 8003 | return false; |
| 8004 | } |
| 8005 | final long identity = Binder.clearCallingIdentity(); |
| 8006 | try { |
| 8007 | UiccCard uiccCard = phone.getUiccCard(); |
| 8008 | if (uiccCard == null) { |
| 8009 | return false; |
| 8010 | } |
| 8011 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8012 | if (uiccProfile == null) { |
| 8013 | return false; |
| 8014 | } |
| 8015 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8016 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8017 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8018 | } |
| 8019 | return false; |
| 8020 | } finally { |
| 8021 | Binder.restoreCallingIdentity(identity); |
| 8022 | } |
| 8023 | } |
| 8024 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8025 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8026 | * Get whether making changes to modem configurations will trigger reboot. |
| 8027 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8028 | */ |
| 8029 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8030 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8031 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8032 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8033 | mApp, subId, callingPackage, callingFeatureId, |
| 8034 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8035 | return false; |
| 8036 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8037 | final long identity = Binder.clearCallingIdentity(); |
| 8038 | try { |
| 8039 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8040 | } finally { |
| 8041 | Binder.restoreCallingIdentity(identity); |
| 8042 | } |
| 8043 | } |
| 8044 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8045 | private void updateModemStateMetrics() { |
| 8046 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8047 | // TODO: check the state for each modem if the api is ready. |
| 8048 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8049 | } |
| 8050 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8051 | @Override |
| 8052 | public int[] getSlotsMapping() { |
| 8053 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8054 | |
| 8055 | final long identity = Binder.clearCallingIdentity(); |
| 8056 | try { |
| 8057 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8058 | // All logical slots should have a mapping to a physical slot. |
| 8059 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8060 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8061 | for (int i = 0; i < slotInfos.length; i++) { |
| 8062 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8063 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8064 | } |
| 8065 | } |
| 8066 | return logicalSlotsMapping; |
| 8067 | } finally { |
| 8068 | Binder.restoreCallingIdentity(identity); |
| 8069 | } |
| 8070 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8071 | |
| 8072 | /** |
| 8073 | * Get the IRadio HAL Version |
| 8074 | */ |
| 8075 | @Override |
| 8076 | public int getRadioHalVersion() { |
| 8077 | Phone phone = getDefaultPhone(); |
| 8078 | if (phone == null) return -1; |
| 8079 | HalVersion hv = phone.getHalVersion(); |
| 8080 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8081 | return hv.major * 100 + hv.minor; |
| 8082 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8083 | |
| 8084 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8085 | * Get the current calling package name. |
| 8086 | * @return the current calling package name |
| 8087 | */ |
| 8088 | @Override |
| 8089 | public String getCurrentPackageName() { |
| 8090 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8091 | } |
| 8092 | |
| 8093 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8094 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8095 | * corresponding network requests on a subId. |
| 8096 | * |
| 8097 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8098 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8099 | * 2) APN is un-metered for this subscription, or |
| 8100 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8101 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8102 | * |
| 8103 | * @return whether data is allowed for a apn type. |
| 8104 | * |
| 8105 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8106 | */ |
| 8107 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8108 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8109 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8110 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8111 | |
| 8112 | // Now that all security checks passes, perform the operation as ourselves. |
| 8113 | final long identity = Binder.clearCallingIdentity(); |
| 8114 | try { |
| 8115 | Phone phone = getPhone(subId); |
| 8116 | if (phone == null) return false; |
| 8117 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8118 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8119 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8120 | } finally { |
| 8121 | Binder.restoreCallingIdentity(identity); |
| 8122 | } |
| 8123 | } |
| 8124 | |
| 8125 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8126 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8127 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8128 | |
| 8129 | // Now that all security checks passes, perform the operation as ourselves. |
| 8130 | final long identity = Binder.clearCallingIdentity(); |
| 8131 | try { |
| 8132 | Phone phone = getPhone(subId); |
| 8133 | if (phone == null) return true; // By default return true. |
| 8134 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8135 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8136 | } finally { |
| 8137 | Binder.restoreCallingIdentity(identity); |
| 8138 | } |
| 8139 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8140 | |
| 8141 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8142 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8143 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8144 | enforceModifyPermission(); |
| 8145 | long token = Binder.clearCallingIdentity(); |
| 8146 | try { |
| 8147 | Phone phone = getPhone(subscriptionId); |
| 8148 | if (phone == null) { |
| 8149 | try { |
| 8150 | if (resultCallback != null) { |
| 8151 | resultCallback.accept(false); |
| 8152 | } |
| 8153 | } catch (RemoteException e) { |
| 8154 | // ignore |
| 8155 | } |
| 8156 | return; |
| 8157 | } |
| 8158 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8159 | Pair.create(specifiers, (x) -> { |
| 8160 | try { |
| 8161 | if (resultCallback != null) { |
| 8162 | resultCallback.accept(x); |
| 8163 | } |
| 8164 | } catch (RemoteException e) { |
| 8165 | // ignore |
| 8166 | } |
| 8167 | }); |
| 8168 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8169 | } finally { |
| 8170 | Binder.restoreCallingIdentity(token); |
| 8171 | } |
| 8172 | } |
| 8173 | |
| 8174 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8175 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
| 8176 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8177 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8178 | if (iccRecords == null) { |
| 8179 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8180 | return false; |
| 8181 | } |
| 8182 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8183 | } |
| 8184 | |
| 8185 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8186 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 8187 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8188 | if (callingPackage == null) { |
| 8189 | callingPackage = getCurrentPackageName(); |
| 8190 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8191 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8192 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8193 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 8194 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8195 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8196 | } |
| 8197 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8198 | Intent intent = new Intent(); |
| 8199 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8200 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8201 | // Bring up choose default SMS subscription dialog right now |
| 8202 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8203 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8204 | mApp.startActivity(intent); |
| 8205 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8206 | |
| 8207 | @Override |
| 8208 | public String getMmsUAProfUrl(int subId) { |
| 8209 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8210 | final long identity = Binder.clearCallingIdentity(); |
| 8211 | try { |
| 8212 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8213 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 8214 | } finally { |
| 8215 | Binder.restoreCallingIdentity(identity); |
| 8216 | } |
| 8217 | } |
| 8218 | |
| 8219 | @Override |
| 8220 | public String getMmsUserAgent(int subId) { |
| 8221 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8222 | final long identity = Binder.clearCallingIdentity(); |
| 8223 | try { |
| 8224 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8225 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8226 | } finally { |
| 8227 | Binder.restoreCallingIdentity(identity); |
| 8228 | } |
| 8229 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8230 | |
| 8231 | @Override |
| 8232 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 8233 | enforceModifyPermission(); |
| 8234 | |
| 8235 | // Now that all security checks passes, perform the operation as ourselves. |
| 8236 | final long identity = Binder.clearCallingIdentity(); |
| 8237 | try { |
| 8238 | Phone phone = getPhone(subId); |
| 8239 | if (phone == null) return false; |
| 8240 | |
| 8241 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 8242 | } finally { |
| 8243 | Binder.restoreCallingIdentity(identity); |
| 8244 | } |
| 8245 | } |
| 8246 | |
| 8247 | @Override |
| 8248 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 8249 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 8250 | |
| 8251 | // Now that all security checks passes, perform the operation as ourselves. |
| 8252 | final long identity = Binder.clearCallingIdentity(); |
| 8253 | try { |
| 8254 | Phone phone = getPhone(subId); |
| 8255 | if (phone == null) return false; |
| 8256 | |
| 8257 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8258 | } finally { |
| 8259 | Binder.restoreCallingIdentity(identity); |
| 8260 | } |
| 8261 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8262 | |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8263 | @Override |
| 8264 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8265 | enforceModifyPermission(); |
| 8266 | |
| 8267 | // Now that all security checks passes, perform the operation as ourselves. |
| 8268 | final long identity = Binder.clearCallingIdentity(); |
| 8269 | try { |
| 8270 | Phone phone = getPhone(subId); |
| 8271 | if (phone == null) return false; |
| 8272 | |
| 8273 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8274 | } finally { |
| 8275 | Binder.restoreCallingIdentity(identity); |
| 8276 | } |
| 8277 | } |
| 8278 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8279 | /** |
| 8280 | * Updates whether conference event pacakge handling is enabled. |
| 8281 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8282 | * otherwise. |
| 8283 | */ |
| 8284 | @Override |
| 8285 | public void setCepEnabled(boolean isCepEnabled) { |
| 8286 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8287 | |
| 8288 | final long identity = Binder.clearCallingIdentity(); |
| 8289 | try { |
| 8290 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8291 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8292 | Phone defaultPhone = phone.getImsPhone(); |
| 8293 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8294 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8295 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8296 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8297 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8298 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8299 | + imsPhone.getMsisdn()); |
| 8300 | } |
| 8301 | } |
| 8302 | } finally { |
| 8303 | Binder.restoreCallingIdentity(identity); |
| 8304 | } |
| 8305 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8306 | |
| 8307 | /** |
| 8308 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8309 | * |
| 8310 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8311 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8312 | * before being read. |
| 8313 | */ |
| 8314 | @Override |
| 8315 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8316 | isCompressed) { |
| 8317 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8318 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8319 | try { |
| 8320 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8321 | if (configBinder == null) { |
| 8322 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8323 | } else { |
| 8324 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8325 | } |
| 8326 | } catch (RemoteException e) { |
| 8327 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8328 | } |
| 8329 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8330 | |
| 8331 | @Override |
| 8332 | public boolean isIccLockEnabled(int subId) { |
| 8333 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8334 | |
| 8335 | // Now that all security checks passes, perform the operation as ourselves. |
| 8336 | final long identity = Binder.clearCallingIdentity(); |
| 8337 | try { |
| 8338 | Phone phone = getPhone(subId); |
| 8339 | if (phone != null && phone.getIccCard() != null) { |
| 8340 | return phone.getIccCard().getIccLockEnabled(); |
| 8341 | } else { |
| 8342 | return false; |
| 8343 | } |
| 8344 | } finally { |
| 8345 | Binder.restoreCallingIdentity(identity); |
| 8346 | } |
| 8347 | } |
| 8348 | |
| 8349 | /** |
| 8350 | * Set the ICC pin lock enabled or disabled.. |
| 8351 | * |
| 8352 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8353 | * 0 or a positive integer as the attempts remaining value. |
| 8354 | * |
| 8355 | */ |
| 8356 | @Override |
| 8357 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8358 | enforceModifyPermission(); |
| 8359 | |
| 8360 | Phone phone = getPhone(subId); |
| 8361 | if (phone == null) { |
| 8362 | return 0; |
| 8363 | } |
| 8364 | // Now that all security checks passes, perform the operation as ourselves. |
| 8365 | final long identity = Binder.clearCallingIdentity(); |
| 8366 | try { |
| 8367 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8368 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8369 | return attemptsRemaining; |
| 8370 | |
| 8371 | } catch (Exception e) { |
| 8372 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8373 | } finally { |
| 8374 | Binder.restoreCallingIdentity(identity); |
| 8375 | } |
| 8376 | return 0; |
| 8377 | } |
| 8378 | |
| 8379 | /** |
| 8380 | * Change the ICC password used in ICC pin lock. |
| 8381 | * |
| 8382 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8383 | * 0 or a positive integer as the attempts remaining value. |
| 8384 | * |
| 8385 | */ |
| 8386 | @Override |
| 8387 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8388 | enforceModifyPermission(); |
| 8389 | |
| 8390 | Phone phone = getPhone(subId); |
| 8391 | if (phone == null) { |
| 8392 | return 0; |
| 8393 | } |
| 8394 | // Now that all security checks passes, perform the operation as ourselves. |
| 8395 | final long identity = Binder.clearCallingIdentity(); |
| 8396 | try { |
| 8397 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8398 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8399 | return attemptsRemaining; |
| 8400 | |
| 8401 | } catch (Exception e) { |
| 8402 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8403 | } finally { |
| 8404 | Binder.restoreCallingIdentity(identity); |
| 8405 | } |
| 8406 | return 0; |
| 8407 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8408 | } |