Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 22 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 23 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 24 | import android.Manifest.permission; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 25 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 30 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 33 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 34 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 35 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 48 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 49 | import android.os.PersistableBundle; |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 50 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 51 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 52 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.ServiceManager; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 55 | import android.os.ShellCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 57 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 58 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 59 | import android.preference.PreferenceManager; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 60 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 61 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 62 | import android.provider.Telephony; |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 63 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 65 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 66 | import android.telecom.TelecomManager; |
Chen Xu | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 67 | import android.telephony.Annotation.ApnType; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 68 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 69 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 70 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 71 | import android.telephony.CellIdentity; |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 72 | import android.telephony.CellIdentityCdma; |
| 73 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfoGsm; |
| 76 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 77 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 78 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 79 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 80 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 81 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 82 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 83 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 84 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 85 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 86 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 87 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 88 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 89 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 90 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 91 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 92 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 93 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 94 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 95 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 96 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 97 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 98 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 99 | import android.telephony.data.ApnSetting; |
| 100 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 101 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 102 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 103 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 108 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 109 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 110 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 111 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 112 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 113 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 114 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 115 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 116 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 117 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 118 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 119 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 120 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 121 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 122 | import com.android.ims.internal.IImsServiceFeatureCallback; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 123 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.IBooleanConsumer; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 135 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 159 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 161 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 170 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 171 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 173 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 174 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 175 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 176 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 177 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 178 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 179 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 180 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 181 | import java.io.FileDescriptor; |
| 182 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 183 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 184 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 185 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 186 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 187 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 188 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 189 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 190 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 191 | import java.util.Set; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 192 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 193 | |
| 194 | /** |
| 195 | * Implementation of the ITelephony interface. |
| 196 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 197 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 198 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 199 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 200 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 201 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 202 | |
| 203 | // Message codes used with mMainThreadHandler |
| 204 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 205 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 206 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 207 | private static final int CMD_OPEN_CHANNEL = 9; |
| 208 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 209 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 210 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 211 | private static final int CMD_NV_READ_ITEM = 13; |
| 212 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 213 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 214 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 215 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 216 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 217 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 218 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 219 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 220 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 221 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 222 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 223 | private static final int CMD_SEND_ENVELOPE = 25; |
| 224 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 225 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 226 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 227 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 228 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 229 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 230 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 231 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 232 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 233 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 234 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 235 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 236 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 237 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 238 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 239 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 240 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 241 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 242 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 243 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 244 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 245 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 246 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 247 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 248 | private static final int CMD_SWITCH_SLOTS = 50; |
| 249 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 250 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 251 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 252 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 253 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 254 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 255 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 256 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 257 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 258 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 259 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 260 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 261 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 262 | private static final int CMD_MODEM_REBOOT = 64; |
| 263 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 264 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 265 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 266 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 267 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 268 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 269 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 270 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 271 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 272 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 273 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 274 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 275 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 276 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 277 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 278 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 279 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 280 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 281 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 282 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 283 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 284 | private static final int CMD_GET_CALL_WAITING = 87; |
| 285 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 286 | private static final int CMD_SET_CALL_WAITING = 89; |
| 287 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 288 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 289 | // Parameters of select command. |
| 290 | private static final int SELECT_COMMAND = 0xA4; |
| 291 | private static final int SELECT_P1 = 0x04; |
| 292 | private static final int SELECT_P2 = 0; |
| 293 | private static final int SELECT_P3 = 0x10; |
| 294 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 295 | /** The singleton instance. */ |
| 296 | private static PhoneInterfaceManager sInstance; |
| 297 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 298 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 299 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 300 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 301 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 302 | private AppOpsManager mAppOps; |
| 303 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 304 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 305 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 306 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 307 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 308 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 309 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 310 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 311 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 312 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 313 | // String to store multi SIM allowed |
| 314 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 315 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 316 | // The AID of ISD-R. |
| 317 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 318 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 319 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 320 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 321 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 322 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 323 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 324 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 325 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 326 | */ |
| 327 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 328 | "reset_network_erase_modem_config_enabled"; |
| 329 | |
| 330 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 331 | * A request object to use for transmitting data to an ICC. |
| 332 | */ |
| 333 | private static final class IccAPDUArgument { |
| 334 | public int channel, cla, command, p1, p2, p3; |
| 335 | public String data; |
| 336 | |
| 337 | public IccAPDUArgument(int channel, int cla, int command, |
| 338 | int p1, int p2, int p3, String data) { |
| 339 | this.channel = channel; |
| 340 | this.cla = cla; |
| 341 | this.command = command; |
| 342 | this.p1 = p1; |
| 343 | this.p2 = p2; |
| 344 | this.p3 = p3; |
| 345 | this.data = data; |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 350 | * A request object to use for transmitting data to an ICC. |
| 351 | */ |
| 352 | private static final class ManualNetworkSelectionArgument { |
| 353 | public OperatorInfo operatorInfo; |
| 354 | public boolean persistSelection; |
| 355 | |
| 356 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 357 | this.operatorInfo = operatorInfo; |
| 358 | this.persistSelection = persistSelection; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 363 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 364 | * request after sending. The main thread will notify the request when it is complete. |
| 365 | */ |
| 366 | private static final class MainThreadRequest { |
| 367 | /** The argument to use for the request */ |
| 368 | public Object argument; |
| 369 | /** The result of the request that is run on the main thread */ |
| 370 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 371 | // The subscriber id that this request applies to. Defaults to |
| 372 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 373 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 374 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 375 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 376 | public Phone phone; |
| 377 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 378 | public WorkSource workSource; |
| 379 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 380 | public MainThreadRequest(Object argument) { |
| 381 | this.argument = argument; |
| 382 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 383 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 384 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 385 | this.argument = argument; |
| 386 | if (phone != null) { |
| 387 | this.phone = phone; |
| 388 | } |
| 389 | this.workSource = workSource; |
| 390 | } |
| 391 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 392 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 393 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 394 | if (subId != null) { |
| 395 | this.subId = subId; |
| 396 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 397 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 398 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 401 | private static final class IncomingThirdPartyCallArgs { |
| 402 | public final ComponentName component; |
| 403 | public final String callId; |
| 404 | public final String callerDisplayName; |
| 405 | |
| 406 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 407 | String callerDisplayName) { |
| 408 | this.component = component; |
| 409 | this.callId = callId; |
| 410 | this.callerDisplayName = callerDisplayName; |
| 411 | } |
| 412 | } |
| 413 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 414 | /** |
| 415 | * A handler that processes messages on the main thread in the phone process. Since many |
| 416 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 417 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 418 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 419 | * on, which will be notified when the operation completes and will contain the result of the |
| 420 | * request. |
| 421 | * |
| 422 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 423 | * note that request.result must be set to something non-null for the calling thread to |
| 424 | * unblock. |
| 425 | */ |
| 426 | private final class MainThreadHandler extends Handler { |
| 427 | @Override |
| 428 | public void handleMessage(Message msg) { |
| 429 | MainThreadRequest request; |
| 430 | Message onCompleted; |
| 431 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 432 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 433 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 434 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 435 | |
| 436 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 437 | case CMD_HANDLE_USSD_REQUEST: { |
| 438 | request = (MainThreadRequest) msg.obj; |
| 439 | final Phone phone = getPhoneFromRequest(request); |
| 440 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 441 | String ussdRequest = ussdObject.first; |
| 442 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 443 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 444 | if (!isUssdApiAllowed(request.subId)) { |
| 445 | // Carrier does not support use of this API, return failure. |
| 446 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 447 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 448 | Bundle returnData = new Bundle(); |
| 449 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 450 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 451 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 452 | request.result = true; |
| 453 | notifyRequester(request); |
| 454 | return; |
| 455 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 456 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 457 | try { |
| 458 | request.result = phone != null |
| 459 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 460 | } catch (CallStateException cse) { |
| 461 | request.result = false; |
| 462 | } |
| 463 | // Wake up the requesting thread |
| 464 | notifyRequester(request); |
| 465 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 468 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 469 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 470 | final Phone phone = getPhoneFromRequest(request); |
| 471 | request.result = phone != null ? |
| 472 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 473 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 474 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 475 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 476 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 477 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 478 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 479 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 480 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 481 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 482 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 483 | if (uiccCard == null) { |
| 484 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 485 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 486 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 487 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 488 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 489 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 490 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 491 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 492 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 493 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 494 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 495 | break; |
| 496 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 497 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 498 | ar = (AsyncResult) msg.obj; |
| 499 | request = (MainThreadRequest) ar.userObj; |
| 500 | if (ar.exception == null && ar.result != null) { |
| 501 | request.result = ar.result; |
| 502 | } else { |
| 503 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 504 | if (ar.result == null) { |
| 505 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 506 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 507 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 508 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 509 | } else { |
| 510 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 511 | } |
| 512 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 513 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 514 | break; |
| 515 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 516 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 517 | request = (MainThreadRequest) msg.obj; |
| 518 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 519 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 520 | if (uiccCard == null) { |
| 521 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 522 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 523 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 524 | } else { |
| 525 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 526 | request); |
| 527 | uiccCard.iccTransmitApduBasicChannel( |
| 528 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 529 | iccArgument.p3, iccArgument.data, onCompleted); |
| 530 | } |
| 531 | break; |
| 532 | |
| 533 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 534 | ar = (AsyncResult) msg.obj; |
| 535 | request = (MainThreadRequest) ar.userObj; |
| 536 | if (ar.exception == null && ar.result != null) { |
| 537 | request.result = ar.result; |
| 538 | } else { |
| 539 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 540 | if (ar.result == null) { |
| 541 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 542 | } else if (ar.exception instanceof CommandException) { |
| 543 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 544 | ar.exception); |
| 545 | } else { |
| 546 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 547 | } |
| 548 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 549 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 550 | break; |
| 551 | |
| 552 | case CMD_EXCHANGE_SIM_IO: |
| 553 | request = (MainThreadRequest) msg.obj; |
| 554 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 555 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 556 | if (uiccCard == null) { |
| 557 | loge("iccExchangeSimIO: No UICC"); |
| 558 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 559 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 560 | } else { |
| 561 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 562 | request); |
| 563 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 564 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 565 | iccArgument.data, onCompleted); |
| 566 | } |
| 567 | break; |
| 568 | |
| 569 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 570 | ar = (AsyncResult) msg.obj; |
| 571 | request = (MainThreadRequest) ar.userObj; |
| 572 | if (ar.exception == null && ar.result != null) { |
| 573 | request.result = ar.result; |
| 574 | } else { |
| 575 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 576 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 577 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 578 | break; |
| 579 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 580 | case CMD_SEND_ENVELOPE: |
| 581 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 582 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 583 | if (uiccCard == null) { |
| 584 | loge("sendEnvelopeWithStatus: No UICC"); |
| 585 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 586 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 587 | } else { |
| 588 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 589 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 590 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 591 | break; |
| 592 | |
| 593 | case EVENT_SEND_ENVELOPE_DONE: |
| 594 | ar = (AsyncResult) msg.obj; |
| 595 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 596 | if (ar.exception == null && ar.result != null) { |
| 597 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 598 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 599 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 600 | if (ar.result == null) { |
| 601 | loge("sendEnvelopeWithStatus: Empty response"); |
| 602 | } else if (ar.exception instanceof CommandException) { |
| 603 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 604 | ar.exception); |
| 605 | } else { |
| 606 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 607 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 608 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 609 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 610 | break; |
| 611 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 612 | case CMD_OPEN_CHANNEL: |
| 613 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 614 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 615 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 616 | if (uiccCard == null) { |
| 617 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 618 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 619 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 620 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 621 | } else { |
| 622 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 623 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 624 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 625 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 626 | break; |
| 627 | |
| 628 | case EVENT_OPEN_CHANNEL_DONE: |
| 629 | ar = (AsyncResult) msg.obj; |
| 630 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 631 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 632 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 633 | int[] result = (int[]) ar.result; |
| 634 | int channelId = result[0]; |
| 635 | byte[] selectResponse = null; |
| 636 | if (result.length > 1) { |
| 637 | selectResponse = new byte[result.length - 1]; |
| 638 | for (int i = 1; i < result.length; ++i) { |
| 639 | selectResponse[i - 1] = (byte) result[i]; |
| 640 | } |
| 641 | } |
| 642 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 643 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 644 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 645 | if (ar.result == null) { |
| 646 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 647 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 648 | if (ar.exception != null) { |
| 649 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 650 | } |
| 651 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 652 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 653 | if (ar.exception instanceof CommandException) { |
| 654 | CommandException.Error error = |
| 655 | ((CommandException) (ar.exception)).getCommandError(); |
| 656 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 657 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 658 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 659 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 660 | } |
| 661 | } |
| 662 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 663 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 664 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 665 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 666 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 667 | break; |
| 668 | |
| 669 | case CMD_CLOSE_CHANNEL: |
| 670 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 671 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 672 | if (uiccCard == null) { |
| 673 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 674 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 675 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 676 | } else { |
| 677 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 678 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 679 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 680 | break; |
| 681 | |
| 682 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 683 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 684 | break; |
| 685 | |
| 686 | case CMD_NV_READ_ITEM: |
| 687 | request = (MainThreadRequest) msg.obj; |
| 688 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 689 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 690 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 691 | break; |
| 692 | |
| 693 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 694 | ar = (AsyncResult) msg.obj; |
| 695 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 696 | if (ar.exception == null && ar.result != null) { |
| 697 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 698 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 699 | request.result = ""; |
| 700 | if (ar.result == null) { |
| 701 | loge("nvReadItem: Empty response"); |
| 702 | } else if (ar.exception instanceof CommandException) { |
| 703 | loge("nvReadItem: CommandException: " + |
| 704 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 705 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 706 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 707 | } |
| 708 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 709 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 710 | break; |
| 711 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 712 | case CMD_NV_WRITE_ITEM: |
| 713 | request = (MainThreadRequest) msg.obj; |
| 714 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 715 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 716 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 717 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 718 | break; |
| 719 | |
| 720 | case EVENT_NV_WRITE_ITEM_DONE: |
| 721 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 722 | break; |
| 723 | |
| 724 | case CMD_NV_WRITE_CDMA_PRL: |
| 725 | request = (MainThreadRequest) msg.obj; |
| 726 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 727 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 728 | break; |
| 729 | |
| 730 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 731 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 732 | break; |
| 733 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 734 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 735 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 736 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 737 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 738 | break; |
| 739 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 740 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 741 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 742 | break; |
| 743 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 744 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 745 | request = (MainThreadRequest) msg.obj; |
| 746 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 747 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 748 | break; |
| 749 | |
| 750 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 751 | ar = (AsyncResult) msg.obj; |
| 752 | request = (MainThreadRequest) ar.userObj; |
| 753 | if (ar.exception == null && ar.result != null) { |
| 754 | request.result = ar.result; // Integer |
| 755 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 756 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 757 | if (ar.result == null) { |
| 758 | loge("getPreferredNetworkType: Empty response"); |
| 759 | } else if (ar.exception instanceof CommandException) { |
| 760 | loge("getPreferredNetworkType: CommandException: " + |
| 761 | ar.exception); |
| 762 | } else { |
| 763 | loge("getPreferredNetworkType: Unknown exception"); |
| 764 | } |
| 765 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 766 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 767 | break; |
| 768 | |
| 769 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 770 | request = (MainThreadRequest) msg.obj; |
| 771 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 772 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 773 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 774 | break; |
| 775 | |
| 776 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 777 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 778 | break; |
| 779 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 780 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 781 | request = (MainThreadRequest)msg.obj; |
| 782 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 783 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 784 | break; |
| 785 | |
| 786 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 787 | ar = (AsyncResult)msg.obj; |
| 788 | request = (MainThreadRequest)ar.userObj; |
| 789 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 790 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 791 | break; |
| 792 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 793 | case CMD_SET_VOICEMAIL_NUMBER: |
| 794 | request = (MainThreadRequest) msg.obj; |
| 795 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 796 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 797 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 798 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 799 | break; |
| 800 | |
| 801 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 802 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 803 | break; |
| 804 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 805 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 806 | request = (MainThreadRequest) msg.obj; |
| 807 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 808 | request); |
| 809 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 810 | break; |
| 811 | |
| 812 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 813 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 814 | break; |
| 815 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 816 | case CMD_PERFORM_NETWORK_SCAN: |
| 817 | request = (MainThreadRequest) msg.obj; |
| 818 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 819 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 820 | break; |
| 821 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 822 | case CMD_GET_CALL_FORWARDING: |
| 823 | request = (MainThreadRequest) msg.obj; |
| 824 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
| 825 | int callForwardingReason = (Integer) request.argument; |
| 826 | getPhoneFromRequest(request).getCallForwardingOption( |
| 827 | callForwardingReason, onCompleted); |
| 828 | break; |
| 829 | |
| 830 | case EVENT_GET_CALL_FORWARDING_DONE: |
| 831 | ar = (AsyncResult) msg.obj; |
| 832 | request = (MainThreadRequest) ar.userObj; |
| 833 | CallForwardingInfo callForwardingInfo = null; |
| 834 | if (ar.exception == null && ar.result != null) { |
| 835 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 836 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 837 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 838 | // any service for voice call. |
| 839 | if ((callForwardInfo.serviceClass |
| 840 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
| 841 | callForwardingInfo = new CallForwardingInfo( |
| 842 | callForwardInfo.serviceClass, callForwardInfo.reason, |
| 843 | callForwardInfo.number, |
| 844 | callForwardInfo.timeSeconds); |
| 845 | break; |
| 846 | } |
| 847 | } |
| 848 | // Didn't find a call forward info for voice call. |
| 849 | if (callForwardingInfo == null) { |
| 850 | callForwardingInfo = new CallForwardingInfo( |
| 851 | CallForwardingInfo.STATUS_UNKNOWN_ERROR, |
| 852 | 0 /* reason */, null /* number */, 0 /* timeout */); |
| 853 | } |
| 854 | } else { |
| 855 | if (ar.result == null) { |
| 856 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 857 | } |
| 858 | if (ar.exception != null) { |
| 859 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 860 | } |
| 861 | int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR; |
| 862 | if (ar.exception instanceof CommandException) { |
| 863 | CommandException.Error error = |
| 864 | ((CommandException) (ar.exception)).getCommandError(); |
| 865 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 866 | errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE; |
| 867 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 868 | errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED; |
| 869 | } |
| 870 | } |
| 871 | callForwardingInfo = new CallForwardingInfo( |
| 872 | errorCode, 0 /* reason */, null /* number */, 0 /* timeout */); |
| 873 | } |
| 874 | request.result = callForwardingInfo; |
| 875 | notifyRequester(request); |
| 876 | break; |
| 877 | |
| 878 | case CMD_SET_CALL_FORWARDING: |
| 879 | request = (MainThreadRequest) msg.obj; |
| 880 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
| 881 | CallForwardingInfo callForwardingInfoToSet = |
| 882 | (CallForwardingInfo) request.argument; |
| 883 | getPhoneFromRequest(request).setCallForwardingOption( |
| 884 | callForwardingInfoToSet.getStatus(), |
| 885 | callForwardingInfoToSet.getReason(), |
| 886 | callForwardingInfoToSet.getNumber(), |
| 887 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 888 | break; |
| 889 | |
| 890 | case EVENT_SET_CALL_FORWARDING_DONE: |
| 891 | ar = (AsyncResult) msg.obj; |
| 892 | request = (MainThreadRequest) ar.userObj; |
| 893 | if (ar.exception == null) { |
| 894 | request.result = true; |
| 895 | } else { |
| 896 | request.result = false; |
| 897 | loge("setCallForwarding exception: " + ar.exception); |
| 898 | } |
| 899 | notifyRequester(request); |
| 900 | break; |
| 901 | |
| 902 | case CMD_GET_CALL_WAITING: |
| 903 | request = (MainThreadRequest) msg.obj; |
| 904 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 905 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 906 | break; |
| 907 | |
| 908 | case EVENT_GET_CALL_WAITING_DONE: |
| 909 | ar = (AsyncResult) msg.obj; |
| 910 | request = (MainThreadRequest) ar.userObj; |
| 911 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 912 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 913 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 914 | // Service Class is a bit mask per 3gpp 27.007. |
| 915 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 916 | if (callForwardResults.length > 1 |
| 917 | && ((callForwardResults[1] |
| 918 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
| 919 | callForwardingStatus = callForwardResults[0] == 0 |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 920 | ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE |
| 921 | : TelephonyManager.CALL_WAITING_STATUS_ACTIVE; |
| 922 | } else { |
| 923 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE; |
| 924 | } |
| 925 | } else { |
| 926 | if (ar.result == null) { |
| 927 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 928 | } |
| 929 | if (ar.exception != null) { |
| 930 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 931 | } |
| 932 | if (ar.exception instanceof CommandException) { |
| 933 | CommandException.Error error = |
| 934 | ((CommandException) (ar.exception)).getCommandError(); |
| 935 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 936 | callForwardingStatus = |
| 937 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 938 | } |
| 939 | } |
| 940 | } |
| 941 | request.result = callForwardingStatus; |
| 942 | notifyRequester(request); |
| 943 | break; |
| 944 | |
| 945 | case CMD_SET_CALL_WAITING: |
| 946 | request = (MainThreadRequest) msg.obj; |
| 947 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
| 948 | boolean isEnable = (Boolean) request.argument; |
| 949 | getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted); |
| 950 | break; |
| 951 | |
| 952 | case EVENT_SET_CALL_WAITING_DONE: |
| 953 | ar = (AsyncResult) msg.obj; |
| 954 | request = (MainThreadRequest) ar.userObj; |
| 955 | if (ar.exception == null) { |
| 956 | request.result = true; |
| 957 | } else { |
| 958 | request.result = false; |
| 959 | loge("setCallWaiting exception: " + ar.exception); |
| 960 | } |
| 961 | notifyRequester(request); |
| 962 | break; |
| 963 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 964 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 965 | ar = (AsyncResult) msg.obj; |
| 966 | request = (MainThreadRequest) ar.userObj; |
| 967 | CellNetworkScanResult cellScanResult; |
| 968 | if (ar.exception == null && ar.result != null) { |
| 969 | cellScanResult = new CellNetworkScanResult( |
| 970 | CellNetworkScanResult.STATUS_SUCCESS, |
| 971 | (List<OperatorInfo>) ar.result); |
| 972 | } else { |
| 973 | if (ar.result == null) { |
| 974 | loge("getCellNetworkScanResults: Empty response"); |
| 975 | } |
| 976 | if (ar.exception != null) { |
| 977 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 978 | } |
| 979 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 980 | if (ar.exception instanceof CommandException) { |
| 981 | CommandException.Error error = |
| 982 | ((CommandException) (ar.exception)).getCommandError(); |
| 983 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 984 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 985 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 986 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 987 | } |
| 988 | } |
| 989 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 990 | } |
| 991 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 992 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 993 | break; |
| 994 | |
| 995 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 996 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 997 | ManualNetworkSelectionArgument selArg = |
| 998 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 999 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1000 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1001 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1002 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1003 | break; |
| 1004 | |
| 1005 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1006 | ar = (AsyncResult) msg.obj; |
| 1007 | request = (MainThreadRequest) ar.userObj; |
| 1008 | if (ar.exception == null) { |
| 1009 | request.result = true; |
| 1010 | } else { |
| 1011 | request.result = false; |
| 1012 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1013 | } |
| 1014 | notifyRequester(request); |
| 1015 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1016 | break; |
| 1017 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1018 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1019 | request = (MainThreadRequest) msg.obj; |
| 1020 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1021 | if (defaultPhone != null) { |
| 1022 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1023 | } else { |
| 1024 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1025 | Bundle bundle = new Bundle(); |
| 1026 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1027 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1028 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1029 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1030 | break; |
| 1031 | |
| 1032 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1033 | ar = (AsyncResult) msg.obj; |
| 1034 | request = (MainThreadRequest) ar.userObj; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1035 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1036 | |
| 1037 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1038 | if (ar.exception == null && ar.result != null) { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1039 | // Update the last modem activity info and the result of the request. |
| 1040 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1041 | if (isModemActivityInfoValid(info)) { |
| 1042 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1043 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1044 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1045 | .getTransmitTimeMillis(); |
| 1046 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1047 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1048 | } |
| 1049 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1050 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1051 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1052 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1053 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1054 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1055 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1056 | info.getReceiveTimeMillis() |
| 1057 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1058 | } |
| 1059 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1060 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1061 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1062 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1063 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1064 | } else { |
| 1065 | if (ar.result == null) { |
| 1066 | loge("queryModemActivityInfo: Empty response"); |
| 1067 | } else if (ar.exception instanceof CommandException) { |
| 1068 | loge("queryModemActivityInfo: CommandException: " + |
| 1069 | ar.exception); |
| 1070 | } else { |
| 1071 | loge("queryModemActivityInfo: Unknown exception"); |
| 1072 | } |
| 1073 | } |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1074 | Bundle bundle = new Bundle(); |
| 1075 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1076 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1077 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1078 | break; |
| 1079 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1080 | case CMD_SET_ALLOWED_CARRIERS: |
| 1081 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1082 | CarrierRestrictionRules argument = |
| 1083 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1084 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1085 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1086 | break; |
| 1087 | |
| 1088 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1089 | ar = (AsyncResult) msg.obj; |
| 1090 | request = (MainThreadRequest) ar.userObj; |
| 1091 | if (ar.exception == null && ar.result != null) { |
| 1092 | request.result = ar.result; |
| 1093 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1094 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1095 | if (ar.exception instanceof CommandException) { |
| 1096 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1097 | CommandException.Error error = |
| 1098 | ((CommandException) (ar.exception)).getCommandError(); |
| 1099 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1100 | request.result = |
| 1101 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1102 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1103 | } else { |
| 1104 | loge("setAllowedCarriers: Unknown exception"); |
| 1105 | } |
| 1106 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1107 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1108 | break; |
| 1109 | |
| 1110 | case CMD_GET_ALLOWED_CARRIERS: |
| 1111 | request = (MainThreadRequest) msg.obj; |
| 1112 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1113 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1114 | break; |
| 1115 | |
| 1116 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1117 | ar = (AsyncResult) msg.obj; |
| 1118 | request = (MainThreadRequest) ar.userObj; |
| 1119 | if (ar.exception == null && ar.result != null) { |
| 1120 | request.result = ar.result; |
| 1121 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1122 | request.result = new IllegalStateException( |
| 1123 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1124 | if (ar.result == null) { |
| 1125 | loge("getAllowedCarriers: Empty response"); |
| 1126 | } else if (ar.exception instanceof CommandException) { |
| 1127 | loge("getAllowedCarriers: CommandException: " + |
| 1128 | ar.exception); |
| 1129 | } else { |
| 1130 | loge("getAllowedCarriers: Unknown exception"); |
| 1131 | } |
| 1132 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1133 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1134 | break; |
| 1135 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1136 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1137 | ar = (AsyncResult) msg.obj; |
| 1138 | request = (MainThreadRequest) ar.userObj; |
| 1139 | if (ar.exception == null && ar.result != null) { |
| 1140 | request.result = ar.result; |
| 1141 | } else { |
| 1142 | request.result = new IllegalArgumentException( |
| 1143 | "Failed to retrieve Forbidden Plmns"); |
| 1144 | if (ar.result == null) { |
| 1145 | loge("getForbiddenPlmns: Empty response"); |
| 1146 | } else { |
| 1147 | loge("getForbiddenPlmns: Unknown exception"); |
| 1148 | } |
| 1149 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1150 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1151 | break; |
| 1152 | |
| 1153 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1154 | request = (MainThreadRequest) msg.obj; |
| 1155 | uiccCard = getUiccCardFromRequest(request); |
| 1156 | if (uiccCard == null) { |
| 1157 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1158 | request.result = new IllegalArgumentException( |
| 1159 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1160 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1161 | break; |
| 1162 | } |
| 1163 | Integer appType = (Integer) request.argument; |
| 1164 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1165 | if (uiccApp == null) { |
| 1166 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1167 | + appType); |
| 1168 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1169 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1170 | break; |
| 1171 | } else { |
| 1172 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1173 | + " specified type -- " + appType); |
| 1174 | } |
| 1175 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1176 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1177 | onCompleted); |
| 1178 | break; |
| 1179 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1180 | case CMD_SWITCH_SLOTS: |
| 1181 | request = (MainThreadRequest) msg.obj; |
| 1182 | int[] physicalSlots = (int[]) request.argument; |
| 1183 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1184 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1185 | break; |
| 1186 | |
| 1187 | case EVENT_SWITCH_SLOTS_DONE: |
| 1188 | ar = (AsyncResult) msg.obj; |
| 1189 | request = (MainThreadRequest) ar.userObj; |
| 1190 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1191 | notifyRequester(request); |
| 1192 | break; |
| 1193 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1194 | request = (MainThreadRequest) msg.obj; |
| 1195 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1196 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1197 | break; |
| 1198 | |
| 1199 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1200 | ar = (AsyncResult) msg.obj; |
| 1201 | request = (MainThreadRequest) ar.userObj; |
| 1202 | if (ar.exception != null) { |
| 1203 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1204 | } else { |
| 1205 | int mode = ((int[]) ar.result)[0]; |
| 1206 | if (mode == 0) { |
| 1207 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1208 | } else { |
| 1209 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1210 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1211 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1212 | notifyRequester(request); |
| 1213 | break; |
| 1214 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1215 | request = (MainThreadRequest) msg.obj; |
| 1216 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1217 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1218 | break; |
| 1219 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1220 | ar = (AsyncResult) msg.obj; |
| 1221 | request = (MainThreadRequest) ar.userObj; |
| 1222 | if (ar.exception != null) { |
| 1223 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1224 | } else { |
| 1225 | request.result = ((int[]) ar.result)[0]; |
| 1226 | } |
| 1227 | notifyRequester(request); |
| 1228 | break; |
| 1229 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1230 | request = (MainThreadRequest) msg.obj; |
| 1231 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1232 | int mode = (int) request.argument; |
| 1233 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1234 | break; |
| 1235 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1236 | ar = (AsyncResult) msg.obj; |
| 1237 | request = (MainThreadRequest) ar.userObj; |
| 1238 | request.result = ar.exception == null; |
| 1239 | notifyRequester(request); |
| 1240 | break; |
| 1241 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1242 | request = (MainThreadRequest) msg.obj; |
| 1243 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1244 | int subscriptionMode = (int) request.argument; |
| 1245 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1246 | break; |
| 1247 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1248 | ar = (AsyncResult) msg.obj; |
| 1249 | request = (MainThreadRequest) ar.userObj; |
| 1250 | request.result = ar.exception == null; |
| 1251 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1252 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1253 | case CMD_GET_ALL_CELL_INFO: |
| 1254 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1255 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1256 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1257 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1258 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1259 | ar = (AsyncResult) msg.obj; |
| 1260 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1261 | // If a timeout occurs, the response will be null |
| 1262 | request.result = (ar.exception == null && ar.result != null) |
| 1263 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1264 | synchronized (request) { |
| 1265 | request.notifyAll(); |
| 1266 | } |
| 1267 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1268 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1269 | request = (MainThreadRequest) msg.obj; |
| 1270 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1271 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1272 | break; |
| 1273 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1274 | ar = (AsyncResult) msg.obj; |
| 1275 | request = (MainThreadRequest) ar.userObj; |
| 1276 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1277 | try { |
| 1278 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1279 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1280 | cb.onError( |
| 1281 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1282 | ar.exception.getClass().getName(), |
| 1283 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1284 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1285 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1286 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1287 | } else { |
| 1288 | // use the result as returned |
| 1289 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1290 | } |
| 1291 | } catch (RemoteException re) { |
| 1292 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1293 | } |
| 1294 | break; |
| 1295 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1296 | request = (MainThreadRequest) msg.obj; |
| 1297 | WorkSource ws = (WorkSource) request.argument; |
| 1298 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1299 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1300 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1301 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1302 | ar = (AsyncResult) msg.obj; |
| 1303 | request = (MainThreadRequest) ar.userObj; |
| 1304 | if (ar.exception == null) { |
| 1305 | request.result = ar.result; |
| 1306 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1307 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1308 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1309 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | synchronized (request) { |
| 1313 | request.notifyAll(); |
| 1314 | } |
| 1315 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1316 | case CMD_MODEM_REBOOT: |
| 1317 | request = (MainThreadRequest) msg.obj; |
| 1318 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1319 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1320 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1321 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1322 | handleNullReturnEvent(msg, "rebootModem"); |
| 1323 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1324 | case CMD_REQUEST_ENABLE_MODEM: |
| 1325 | request = (MainThreadRequest) msg.obj; |
| 1326 | boolean enable = (boolean) request.argument; |
| 1327 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1328 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1329 | PhoneConfigurationManager.getInstance() |
| 1330 | .enablePhone(request.phone, enable, onCompleted); |
| 1331 | break; |
| 1332 | case EVENT_ENABLE_MODEM_DONE: |
| 1333 | ar = (AsyncResult) msg.obj; |
| 1334 | request = (MainThreadRequest) ar.userObj; |
| 1335 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1336 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1337 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1338 | if ((boolean) request.result) { |
| 1339 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1340 | updateModemStateMetrics(); |
| 1341 | } else { |
| 1342 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1343 | + ar.exception); |
| 1344 | } |
| 1345 | notifyRequester(request); |
| 1346 | break; |
| 1347 | case CMD_GET_MODEM_STATUS: |
| 1348 | request = (MainThreadRequest) msg.obj; |
| 1349 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1350 | PhoneConfigurationManager.getInstance() |
| 1351 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1352 | break; |
| 1353 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1354 | ar = (AsyncResult) msg.obj; |
| 1355 | request = (MainThreadRequest) ar.userObj; |
| 1356 | int id = request.phone.getPhoneId(); |
| 1357 | if (ar.exception == null && ar.result != null) { |
| 1358 | request.result = ar.result; |
| 1359 | //update the cache as modem status has changed |
| 1360 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1361 | (boolean) request.result); |
| 1362 | } else { |
| 1363 | // Return true if modem status cannot be retrieved. For most cases, |
| 1364 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1365 | // and disable modem are not supported. Modem is always on. |
| 1366 | // TODO: this should be fixed in R to support a third |
| 1367 | // status UNKNOWN b/131631629 |
| 1368 | request.result = true; |
| 1369 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1370 | + ar.exception); |
| 1371 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1372 | notifyRequester(request); |
| 1373 | break; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1374 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1375 | request = (MainThreadRequest) msg.obj; |
| 1376 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1377 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1378 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1379 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1380 | break; |
| 1381 | } |
| 1382 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1383 | ar = (AsyncResult) msg.obj; |
| 1384 | request = (MainThreadRequest) ar.userObj; |
| 1385 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1386 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1387 | args.second.accept(ar.exception == null); |
| 1388 | notifyRequester(request); |
| 1389 | break; |
| 1390 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1391 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1392 | ar = (AsyncResult) msg.obj; |
| 1393 | request = (MainThreadRequest) ar.userObj; |
| 1394 | if (ar.exception == null && ar.result != null) { |
| 1395 | request.result = ar.result; |
| 1396 | } else { |
| 1397 | request.result = -1; |
| 1398 | loge("Failed to set Forbidden Plmns"); |
| 1399 | if (ar.result == null) { |
| 1400 | loge("setForbidenPlmns: Empty response"); |
| 1401 | } else if (ar.exception != null) { |
| 1402 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1403 | request.result = -1; |
| 1404 | } else { |
| 1405 | loge("setForbiddenPlmns: Unknown exception"); |
| 1406 | } |
| 1407 | } |
| 1408 | notifyRequester(request); |
| 1409 | break; |
| 1410 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1411 | request = (MainThreadRequest) msg.obj; |
| 1412 | uiccCard = getUiccCardFromRequest(request); |
| 1413 | if (uiccCard == null) { |
| 1414 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1415 | request.result = -1; |
| 1416 | notifyRequester(request); |
| 1417 | break; |
| 1418 | } |
| 1419 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1420 | (Pair<Integer, List<String>>) request.argument; |
| 1421 | appType = setFplmnsArgs.first; |
| 1422 | List<String> fplmns = setFplmnsArgs.second; |
| 1423 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1424 | if (uiccApp == null) { |
| 1425 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1426 | request.result = -1; |
| 1427 | loge("Failed to get UICC App"); |
| 1428 | notifyRequester(request); |
| 1429 | } else { |
| 1430 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1431 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1432 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1433 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1434 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1435 | case CMD_ERASE_MODEM_CONFIG: |
| 1436 | request = (MainThreadRequest) msg.obj; |
| 1437 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1438 | defaultPhone.eraseModemConfig(onCompleted); |
| 1439 | break; |
| 1440 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1441 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1442 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1443 | |
| 1444 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1445 | request = (MainThreadRequest) msg.obj; |
| 1446 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1447 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1448 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1449 | changed.first, changed.second, onCompleted); |
| 1450 | break; |
| 1451 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1452 | ar = (AsyncResult) msg.obj; |
| 1453 | request = (MainThreadRequest) ar.userObj; |
| 1454 | if (ar.exception == null) { |
| 1455 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1456 | } else { |
| 1457 | request.result = msg.arg1; |
| 1458 | } |
| 1459 | notifyRequester(request); |
| 1460 | break; |
| 1461 | |
| 1462 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1463 | request = (MainThreadRequest) msg.obj; |
| 1464 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1465 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1466 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1467 | enabled.first, enabled.second, onCompleted); |
| 1468 | break; |
| 1469 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1470 | ar = (AsyncResult) msg.obj; |
| 1471 | request = (MainThreadRequest) ar.userObj; |
| 1472 | if (ar.exception == null) { |
| 1473 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1474 | } else { |
| 1475 | request.result = msg.arg1; |
| 1476 | } |
| 1477 | notifyRequester(request); |
| 1478 | break; |
| 1479 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1480 | default: |
| 1481 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1482 | break; |
| 1483 | } |
| 1484 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1485 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1486 | private void notifyRequester(MainThreadRequest request) { |
| 1487 | synchronized (request) { |
| 1488 | request.notifyAll(); |
| 1489 | } |
| 1490 | } |
| 1491 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1492 | private void handleNullReturnEvent(Message msg, String command) { |
| 1493 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1494 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1495 | if (ar.exception == null) { |
| 1496 | request.result = true; |
| 1497 | } else { |
| 1498 | request.result = false; |
| 1499 | if (ar.exception instanceof CommandException) { |
| 1500 | loge(command + ": CommandException: " + ar.exception); |
| 1501 | } else { |
| 1502 | loge(command + ": Unknown exception"); |
| 1503 | } |
| 1504 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1505 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1506 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | /** |
| 1510 | * Posts the specified command to be executed on the main thread, |
| 1511 | * waits for the request to complete, and returns the result. |
| 1512 | * @see #sendRequestAsync |
| 1513 | */ |
| 1514 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1515 | return sendRequest( |
| 1516 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | /** |
| 1520 | * Posts the specified command to be executed on the main thread, |
| 1521 | * waits for the request to complete, and returns the result. |
| 1522 | * @see #sendRequestAsync |
| 1523 | */ |
| 1524 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1525 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1526 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | /** |
| 1530 | * Posts the specified command to be executed on the main thread, |
| 1531 | * waits for the request to complete, and returns the result. |
| 1532 | * @see #sendRequestAsync |
| 1533 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1534 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1535 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | /** |
| 1539 | * Posts the specified command to be executed on the main thread, |
| 1540 | * waits for the request to complete, and returns the result. |
| 1541 | * @see #sendRequestAsync |
| 1542 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1543 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1544 | return sendRequest(command, argument, subId, null, workSource); |
| 1545 | } |
| 1546 | |
| 1547 | /** |
| 1548 | * Posts the specified command to be executed on the main thread, |
| 1549 | * waits for the request to complete, and returns the result. |
| 1550 | * @see #sendRequestAsync |
| 1551 | */ |
| 1552 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1553 | return sendRequest( |
| 1554 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1555 | } |
| 1556 | |
| 1557 | /** |
| 1558 | * Posts the specified command to be executed on the main thread, |
| 1559 | * waits for the request to complete, and returns the result. |
| 1560 | * @see #sendRequestAsync |
| 1561 | */ |
| 1562 | private Object sendRequest( |
| 1563 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1564 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1565 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1566 | } |
| 1567 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1568 | MainThreadRequest request = null; |
| 1569 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1570 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1571 | } else if (phone != null) { |
| 1572 | request = new MainThreadRequest(argument, phone, workSource); |
| 1573 | } else { |
| 1574 | request = new MainThreadRequest(argument, subId, workSource); |
| 1575 | } |
| 1576 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1577 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1578 | msg.sendToTarget(); |
| 1579 | |
| 1580 | // Wait for the request to complete |
| 1581 | synchronized (request) { |
| 1582 | while (request.result == null) { |
| 1583 | try { |
| 1584 | request.wait(); |
| 1585 | } catch (InterruptedException e) { |
| 1586 | // Do nothing, go back and wait until the request is complete |
| 1587 | } |
| 1588 | } |
| 1589 | } |
| 1590 | return request.result; |
| 1591 | } |
| 1592 | |
| 1593 | /** |
| 1594 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1595 | * Posts the specified command to be executed on the main thread, and |
| 1596 | * returns immediately. |
| 1597 | * @see #sendRequest |
| 1598 | */ |
| 1599 | private void sendRequestAsync(int command) { |
| 1600 | mMainThreadHandler.sendEmptyMessage(command); |
| 1601 | } |
| 1602 | |
| 1603 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1604 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1605 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1606 | */ |
| 1607 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1608 | sendRequestAsync(command, argument, null, null); |
| 1609 | } |
| 1610 | |
| 1611 | /** |
| 1612 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1613 | * @see {@link #sendRequest(int,Object)} |
| 1614 | */ |
| 1615 | private void sendRequestAsync( |
| 1616 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1617 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1618 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1619 | msg.sendToTarget(); |
| 1620 | } |
| 1621 | |
| 1622 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1623 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1624 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1625 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1626 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1627 | synchronized (PhoneInterfaceManager.class) { |
| 1628 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1629 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1630 | } else { |
| 1631 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1632 | } |
| 1633 | return sInstance; |
| 1634 | } |
| 1635 | } |
| 1636 | |
| 1637 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1638 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1639 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1640 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1641 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1642 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1643 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1644 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1645 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1646 | mTelephonySharedPreferences = |
| 1647 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1648 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1649 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1650 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1651 | publish(); |
| 1652 | } |
| 1653 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1654 | private Phone getDefaultPhone() { |
| 1655 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1656 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1657 | } |
| 1658 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1659 | private void publish() { |
| 1660 | if (DBG) log("publish: " + this); |
| 1661 | |
| 1662 | ServiceManager.addService("phone", this); |
| 1663 | } |
| 1664 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1665 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1666 | if (request.phone != null) { |
| 1667 | return request.phone; |
| 1668 | } else { |
| 1669 | return getPhoneFromSubId(request.subId); |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | private Phone getPhoneFromSubId(int subId) { |
| 1674 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1675 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1676 | } |
| 1677 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1678 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1679 | Phone phone = getPhoneFromRequest(request); |
| 1680 | return phone == null ? null : |
| 1681 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1682 | } |
| 1683 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1684 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1685 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1686 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1687 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1688 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1689 | private void sendEraseModemConfig(Phone phone) { |
| 1690 | if (phone != null) { |
| 1691 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1692 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1693 | final long identity = Binder.clearCallingIdentity(); |
| 1694 | try { |
| 1695 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1696 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1697 | } finally { |
| 1698 | Binder.restoreCallingIdentity(identity); |
| 1699 | } |
| 1700 | } |
| 1701 | } |
| 1702 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1703 | private boolean isImsAvailableOnDevice() { |
| 1704 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1705 | if (pm == null) { |
| 1706 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1707 | // so do not throw error and allow. |
| 1708 | return true; |
| 1709 | } |
| 1710 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1711 | } |
| 1712 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1713 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1714 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1715 | } |
| 1716 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1717 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1718 | if (DBG) log("dial: " + number); |
| 1719 | // No permission check needed here: This is just a wrapper around the |
| 1720 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1721 | // the UI before it does anything. |
| 1722 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1723 | final long identity = Binder.clearCallingIdentity(); |
| 1724 | try { |
| 1725 | String url = createTelUrl(number); |
| 1726 | if (url == null) { |
| 1727 | return; |
| 1728 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1729 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1730 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1731 | PhoneConstants.State state = mCM.getState(subId); |
| 1732 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1733 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1734 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1735 | mApp.startActivity(intent); |
| 1736 | } |
| 1737 | } finally { |
| 1738 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1739 | } |
| 1740 | } |
| 1741 | |
| 1742 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1743 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1744 | } |
| 1745 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1746 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1747 | if (DBG) log("call: " + number); |
| 1748 | |
| 1749 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1750 | // need to do a permission check since we're calling startActivity() |
| 1751 | // from the context of the phone app. |
| 1752 | enforceCallPermission(); |
| 1753 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1754 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1755 | != AppOpsManager.MODE_ALLOWED) { |
| 1756 | return; |
| 1757 | } |
| 1758 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1759 | final long identity = Binder.clearCallingIdentity(); |
| 1760 | try { |
| 1761 | String url = createTelUrl(number); |
| 1762 | if (url == null) { |
| 1763 | return; |
| 1764 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1765 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1766 | boolean isValid = false; |
| 1767 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1768 | if (slist != null) { |
| 1769 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1770 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1771 | isValid = true; |
| 1772 | break; |
| 1773 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1774 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1775 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1776 | if (!isValid) { |
| 1777 | return; |
| 1778 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1779 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1780 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1781 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1782 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1783 | mApp.startActivity(intent); |
| 1784 | } finally { |
| 1785 | Binder.restoreCallingIdentity(identity); |
| 1786 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1789 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1790 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1791 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1792 | } |
| 1793 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1794 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1795 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1796 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1797 | } |
| 1798 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1799 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1800 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1801 | |
| 1802 | final long identity = Binder.clearCallingIdentity(); |
| 1803 | try { |
| 1804 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1805 | checkSimPin.start(); |
| 1806 | return checkSimPin.unlockSim(null, pin); |
| 1807 | } finally { |
| 1808 | Binder.restoreCallingIdentity(identity); |
| 1809 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1810 | } |
| 1811 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1812 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1813 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1814 | |
| 1815 | final long identity = Binder.clearCallingIdentity(); |
| 1816 | try { |
| 1817 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1818 | checkSimPuk.start(); |
| 1819 | return checkSimPuk.unlockSim(puk, pin); |
| 1820 | } finally { |
| 1821 | Binder.restoreCallingIdentity(identity); |
| 1822 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1826 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1827 | * a synchronous one. |
| 1828 | */ |
| 1829 | private static class UnlockSim extends Thread { |
| 1830 | |
| 1831 | private final IccCard mSimCard; |
| 1832 | |
| 1833 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1834 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1835 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1836 | |
| 1837 | // For replies from SimCard interface |
| 1838 | private Handler mHandler; |
| 1839 | |
| 1840 | // For async handler to identify request type |
| 1841 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1842 | |
| 1843 | public UnlockSim(IccCard simCard) { |
| 1844 | mSimCard = simCard; |
| 1845 | } |
| 1846 | |
| 1847 | @Override |
| 1848 | public void run() { |
| 1849 | Looper.prepare(); |
| 1850 | synchronized (UnlockSim.this) { |
| 1851 | mHandler = new Handler() { |
| 1852 | @Override |
| 1853 | public void handleMessage(Message msg) { |
| 1854 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1855 | switch (msg.what) { |
| 1856 | case SUPPLY_PIN_COMPLETE: |
| 1857 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1858 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1859 | mRetryCount = msg.arg1; |
| 1860 | if (ar.exception != null) { |
| 1861 | if (ar.exception instanceof CommandException && |
| 1862 | ((CommandException)(ar.exception)).getCommandError() |
| 1863 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1864 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1865 | } else { |
| 1866 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1867 | } |
| 1868 | } else { |
| 1869 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1870 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1871 | mDone = true; |
| 1872 | UnlockSim.this.notifyAll(); |
| 1873 | } |
| 1874 | break; |
| 1875 | } |
| 1876 | } |
| 1877 | }; |
| 1878 | UnlockSim.this.notifyAll(); |
| 1879 | } |
| 1880 | Looper.loop(); |
| 1881 | } |
| 1882 | |
| 1883 | /* |
| 1884 | * Use PIN or PUK to unlock SIM card |
| 1885 | * |
| 1886 | * If PUK is null, unlock SIM card with PIN |
| 1887 | * |
| 1888 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1889 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1890 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1891 | |
| 1892 | while (mHandler == null) { |
| 1893 | try { |
| 1894 | wait(); |
| 1895 | } catch (InterruptedException e) { |
| 1896 | Thread.currentThread().interrupt(); |
| 1897 | } |
| 1898 | } |
| 1899 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1900 | |
| 1901 | if (puk == null) { |
| 1902 | mSimCard.supplyPin(pin, callback); |
| 1903 | } else { |
| 1904 | mSimCard.supplyPuk(puk, pin, callback); |
| 1905 | } |
| 1906 | |
| 1907 | while (!mDone) { |
| 1908 | try { |
| 1909 | Log.d(LOG_TAG, "wait for done"); |
| 1910 | wait(); |
| 1911 | } catch (InterruptedException e) { |
| 1912 | // Restore the interrupted status |
| 1913 | Thread.currentThread().interrupt(); |
| 1914 | } |
| 1915 | } |
| 1916 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1917 | int[] resultArray = new int[2]; |
| 1918 | resultArray[0] = mResult; |
| 1919 | resultArray[1] = mRetryCount; |
| 1920 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1921 | } |
| 1922 | } |
| 1923 | |
| 1924 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1925 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1926 | |
| 1927 | } |
| 1928 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1929 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1930 | // No permission check needed here: this call is harmless, and it's |
| 1931 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1932 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1933 | final long identity = Binder.clearCallingIdentity(); |
| 1934 | try { |
| 1935 | final Phone phone = getPhone(subId); |
| 1936 | if (phone != null) { |
| 1937 | phone.updateServiceLocation(); |
| 1938 | } |
| 1939 | } finally { |
| 1940 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1941 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1942 | } |
| 1943 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1944 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1945 | @Override |
| 1946 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1947 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1950 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1951 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1952 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1953 | callingFeatureId); |
| 1954 | } |
| 1955 | |
| 1956 | @Deprecated |
| 1957 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1958 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1959 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 1960 | } |
| 1961 | |
| 1962 | @Override |
| 1963 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1964 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1965 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1966 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1967 | return false; |
| 1968 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1969 | |
| 1970 | final long identity = Binder.clearCallingIdentity(); |
| 1971 | try { |
| 1972 | return isRadioOnForSubscriber(subId); |
| 1973 | } finally { |
| 1974 | Binder.restoreCallingIdentity(identity); |
| 1975 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1976 | } |
| 1977 | |
| 1978 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1979 | final long identity = Binder.clearCallingIdentity(); |
| 1980 | try { |
| 1981 | final Phone phone = getPhone(subId); |
| 1982 | if (phone != null) { |
| 1983 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1984 | } else { |
| 1985 | return false; |
| 1986 | } |
| 1987 | } finally { |
| 1988 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1989 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1993 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1994 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1995 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1996 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1997 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1998 | |
| 1999 | final long identity = Binder.clearCallingIdentity(); |
| 2000 | try { |
| 2001 | final Phone phone = getPhone(subId); |
| 2002 | if (phone != null) { |
| 2003 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2004 | } |
| 2005 | } finally { |
| 2006 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2007 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2011 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2012 | } |
| 2013 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2014 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2015 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2016 | |
| 2017 | final long identity = Binder.clearCallingIdentity(); |
| 2018 | try { |
| 2019 | final Phone phone = getPhone(subId); |
| 2020 | if (phone == null) { |
| 2021 | return false; |
| 2022 | } |
| 2023 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2024 | toggleRadioOnOffForSubscriber(subId); |
| 2025 | } |
| 2026 | return true; |
| 2027 | } finally { |
| 2028 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2029 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2030 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2031 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2032 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2033 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2034 | /* |
| 2035 | * If any of the Radios are available, it will need to be |
| 2036 | * shutdown. So return true if any Radio is available. |
| 2037 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2038 | final long identity = Binder.clearCallingIdentity(); |
| 2039 | try { |
| 2040 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2041 | Phone phone = PhoneFactory.getPhone(i); |
| 2042 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2043 | } |
| 2044 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2045 | return false; |
| 2046 | } finally { |
| 2047 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2048 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2049 | } |
| 2050 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2051 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2052 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2053 | enforceModifyPermission(); |
| 2054 | |
| 2055 | final long identity = Binder.clearCallingIdentity(); |
| 2056 | try { |
| 2057 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2058 | logv("Shutting down Phone " + i); |
| 2059 | shutdownRadioUsingPhoneId(i); |
| 2060 | } |
| 2061 | } finally { |
| 2062 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2067 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2068 | if (phone != null && phone.isRadioAvailable()) { |
| 2069 | phone.shutdownRadio(); |
| 2070 | } |
| 2071 | } |
| 2072 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2073 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2074 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2075 | |
| 2076 | final long identity = Binder.clearCallingIdentity(); |
| 2077 | try { |
| 2078 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2079 | if (defaultPhone != null) { |
| 2080 | defaultPhone.setRadioPower(turnOn); |
| 2081 | return true; |
| 2082 | } else { |
| 2083 | loge("There's no default phone."); |
| 2084 | return false; |
| 2085 | } |
| 2086 | } finally { |
| 2087 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2088 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2089 | } |
| 2090 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2091 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2092 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2093 | |
| 2094 | final long identity = Binder.clearCallingIdentity(); |
| 2095 | try { |
| 2096 | final Phone phone = getPhone(subId); |
| 2097 | if (phone != null) { |
| 2098 | phone.setRadioPower(turnOn); |
| 2099 | return true; |
| 2100 | } else { |
| 2101 | return false; |
| 2102 | } |
| 2103 | } finally { |
| 2104 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2105 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2108 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2109 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2110 | public boolean enableDataConnectivity() { |
| 2111 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2112 | |
| 2113 | final long identity = Binder.clearCallingIdentity(); |
| 2114 | try { |
| 2115 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2116 | final Phone phone = getPhone(subId); |
| 2117 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2118 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2119 | return true; |
| 2120 | } else { |
| 2121 | return false; |
| 2122 | } |
| 2123 | } finally { |
| 2124 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2125 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2126 | } |
| 2127 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2128 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2129 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2130 | public boolean disableDataConnectivity() { |
| 2131 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2132 | |
| 2133 | final long identity = Binder.clearCallingIdentity(); |
| 2134 | try { |
| 2135 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2136 | final Phone phone = getPhone(subId); |
| 2137 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2138 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2139 | return true; |
| 2140 | } else { |
| 2141 | return false; |
| 2142 | } |
| 2143 | } finally { |
| 2144 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2145 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2146 | } |
| 2147 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2148 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2149 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2150 | final long identity = Binder.clearCallingIdentity(); |
| 2151 | try { |
| 2152 | final Phone phone = getPhone(subId); |
| 2153 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2154 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2155 | } else { |
| 2156 | return false; |
| 2157 | } |
| 2158 | } finally { |
| 2159 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2160 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2161 | } |
| 2162 | |
| 2163 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2164 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2165 | } |
| 2166 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2167 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2168 | enforceCallPermission(); |
| 2169 | |
| 2170 | final long identity = Binder.clearCallingIdentity(); |
| 2171 | try { |
| 2172 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2173 | return; |
| 2174 | } |
| 2175 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2176 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2177 | } finally { |
| 2178 | Binder.restoreCallingIdentity(identity); |
| 2179 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2180 | }; |
| 2181 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2182 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2183 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2184 | |
| 2185 | final long identity = Binder.clearCallingIdentity(); |
| 2186 | try { |
| 2187 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2188 | return false; |
| 2189 | } |
| 2190 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2191 | } finally { |
| 2192 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2193 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2194 | } |
| 2195 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2196 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2197 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2198 | } |
| 2199 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2200 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2201 | final long identity = Binder.clearCallingIdentity(); |
| 2202 | try { |
| 2203 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2204 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2205 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2206 | } finally { |
| 2207 | Binder.restoreCallingIdentity(identity); |
| 2208 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2209 | } |
| 2210 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2211 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2212 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2213 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2214 | } |
| 2215 | |
| 2216 | @Override |
| 2217 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2218 | final long identity = Binder.clearCallingIdentity(); |
| 2219 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2220 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2221 | if (phone != null) { |
| 2222 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2223 | } else { |
| 2224 | return PhoneConstantConversions.convertDataState( |
| 2225 | PhoneConstants.DataState.DISCONNECTED); |
| 2226 | } |
| 2227 | } finally { |
| 2228 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2229 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2230 | } |
| 2231 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2232 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2233 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2234 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2235 | } |
| 2236 | |
| 2237 | @Override |
| 2238 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2239 | final long identity = Binder.clearCallingIdentity(); |
| 2240 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2241 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2242 | if (phone != null) { |
| 2243 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2244 | } else { |
| 2245 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2246 | } |
| 2247 | } finally { |
| 2248 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2249 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2250 | } |
| 2251 | |
| 2252 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2253 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2254 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2255 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2256 | |
| 2257 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2258 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2259 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2260 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2261 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2262 | .setCallingPid(Binder.getCallingPid()) |
| 2263 | .setCallingUid(Binder.getCallingUid()) |
| 2264 | .setMethod("getCellLocation") |
| 2265 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2266 | .build()); |
| 2267 | switch (locationResult) { |
| 2268 | case DENIED_HARD: |
| 2269 | throw new SecurityException("Not allowed to access cell location"); |
| 2270 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2271 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2272 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2273 | } |
| 2274 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2275 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2276 | final long identity = Binder.clearCallingIdentity(); |
| 2277 | try { |
| 2278 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2279 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2280 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2281 | } finally { |
| 2282 | Binder.restoreCallingIdentity(identity); |
| 2283 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2286 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2287 | public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage, |
| 2288 | String callingFeatureId) { |
Jack Yu | 7c5d91a | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2289 | if (!TextUtils.isEmpty(callingPackage)) { |
| 2290 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2291 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2292 | callingFeatureId, "getNetworkCountryIsoForPhone")) { |
Jack Yu | 7c5d91a | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2293 | return ""; |
| 2294 | } |
| 2295 | } |
| 2296 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2297 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2298 | // registered cell info, so return a NULL country instead. |
| 2299 | final long identity = Binder.clearCallingIdentity(); |
| 2300 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2301 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2302 | // Get default phone in this case. |
| 2303 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2304 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2305 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2306 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2307 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2308 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2309 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(), |
| 2310 | null)) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2311 | return ""; |
| 2312 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2313 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2314 | if (phone != null) { |
| 2315 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2316 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2317 | if (sst != null) { |
| 2318 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2319 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2320 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2321 | return lt.getCurrentCountry(); |
| 2322 | } else if (emergencyNumberTracker != null) { |
| 2323 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2324 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2325 | } |
| 2326 | } |
| 2327 | } |
| 2328 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2329 | } finally { |
| 2330 | Binder.restoreCallingIdentity(identity); |
| 2331 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2335 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2336 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2337 | } |
| 2338 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2339 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2340 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2341 | mApp.enforceCallingOrSelfPermission( |
| 2342 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2343 | |
| 2344 | final long identity = Binder.clearCallingIdentity(); |
| 2345 | try { |
| 2346 | final Phone phone = getPhone(subId); |
| 2347 | if (phone != null) { |
| 2348 | phone.enableLocationUpdates(); |
| 2349 | } |
| 2350 | } finally { |
| 2351 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2352 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | @Override |
| 2356 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2357 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2358 | } |
| 2359 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2360 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2361 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2362 | mApp.enforceCallingOrSelfPermission( |
| 2363 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2364 | |
| 2365 | final long identity = Binder.clearCallingIdentity(); |
| 2366 | try { |
| 2367 | final Phone phone = getPhone(subId); |
| 2368 | if (phone != null) { |
| 2369 | phone.disableLocationUpdates(); |
| 2370 | } |
| 2371 | } finally { |
| 2372 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2373 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2374 | } |
| 2375 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2376 | /** |
| 2377 | * Returns the target SDK version number for a given package name. |
| 2378 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2379 | * This call MUST be invoked before clearing the calling UID. |
| 2380 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2381 | * @return target SDK if the package is found or INT_MAX. |
| 2382 | */ |
| 2383 | private int getTargetSdk(String packageName) { |
| 2384 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2385 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2386 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2387 | if (ai != null) return ai.targetSdkVersion; |
| 2388 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2389 | loge("Failed to get package info for pkg=" |
| 2390 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2391 | } |
| 2392 | return Integer.MAX_VALUE; |
| 2393 | } |
| 2394 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2395 | @Override |
| 2396 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2397 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2398 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2399 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2400 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2401 | throw new SecurityException( |
| 2402 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2403 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2404 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2405 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2406 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2407 | return null; |
| 2408 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2409 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2410 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2411 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2412 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2413 | if (info == null) return null; |
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 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2416 | for (CellInfo ci : info) { |
| 2417 | if (ci instanceof CellInfoGsm) { |
| 2418 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2419 | } else if (ci instanceof CellInfoWcdma) { |
| 2420 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2421 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2422 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2423 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2424 | } |
| 2425 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2426 | private List<CellInfo> getCachedCellInfo() { |
| 2427 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2428 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2429 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2430 | if (info != null) cellInfos.addAll(info); |
| 2431 | } |
| 2432 | return cellInfos; |
| 2433 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2434 | |
| 2435 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2436 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2437 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2438 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2439 | |
| 2440 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2441 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2442 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2443 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2444 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2445 | .setCallingPid(Binder.getCallingPid()) |
| 2446 | .setCallingUid(Binder.getCallingUid()) |
| 2447 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2448 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2449 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2450 | .build()); |
| 2451 | switch (locationResult) { |
| 2452 | case DENIED_HARD: |
| 2453 | throw new SecurityException("Not allowed to access cell info"); |
| 2454 | case DENIED_SOFT: |
| 2455 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2456 | } |
| 2457 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2458 | final int targetSdk = getTargetSdk(callingPackage); |
| 2459 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2460 | return getCachedCellInfo(); |
| 2461 | } |
| 2462 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2463 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2464 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2465 | final long identity = Binder.clearCallingIdentity(); |
| 2466 | try { |
| 2467 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2468 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2469 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2470 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2471 | if (info != null) cellInfos.addAll(info); |
| 2472 | } |
| 2473 | return cellInfos; |
| 2474 | } finally { |
| 2475 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2476 | } |
| 2477 | } |
| 2478 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2479 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2480 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2481 | String callingFeatureId) { |
| 2482 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2483 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2487 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2488 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2489 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2490 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2491 | } |
| 2492 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2493 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2494 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2495 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2496 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2497 | |
| 2498 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2499 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2500 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2501 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2502 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2503 | .setCallingPid(Binder.getCallingPid()) |
| 2504 | .setCallingUid(Binder.getCallingUid()) |
| 2505 | .setMethod("requestCellInfoUpdate") |
| 2506 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2507 | .build()); |
| 2508 | switch (locationResult) { |
| 2509 | case DENIED_HARD: |
| 2510 | throw new SecurityException("Not allowed to access cell info"); |
| 2511 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2512 | try { |
| 2513 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2514 | } catch (RemoteException re) { |
| 2515 | // Drop without consequences |
| 2516 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2517 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2518 | } |
| 2519 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2520 | |
| 2521 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2522 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2523 | |
| 2524 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2525 | } |
| 2526 | |
| 2527 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2528 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2529 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2530 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2531 | |
| 2532 | final long identity = Binder.clearCallingIdentity(); |
| 2533 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2534 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2535 | } finally { |
| 2536 | Binder.restoreCallingIdentity(identity); |
| 2537 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2538 | } |
| 2539 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2540 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2541 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2542 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2543 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2544 | return null; |
| 2545 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2546 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2547 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2548 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2549 | return null; |
| 2550 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2551 | |
| 2552 | final long identity = Binder.clearCallingIdentity(); |
| 2553 | try { |
| 2554 | return phone.getImei(); |
| 2555 | } finally { |
| 2556 | Binder.restoreCallingIdentity(identity); |
| 2557 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2558 | } |
| 2559 | |
| 2560 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2561 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2562 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2563 | String tac = null; |
| 2564 | if (phone != null) { |
| 2565 | String imei = phone.getImei(); |
| 2566 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2567 | } |
| 2568 | return tac; |
| 2569 | } |
| 2570 | |
| 2571 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2572 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2573 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2574 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2575 | return null; |
| 2576 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2577 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2578 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2579 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2580 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2581 | return null; |
| 2582 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2583 | |
| 2584 | final long identity = Binder.clearCallingIdentity(); |
| 2585 | try { |
| 2586 | return phone.getMeid(); |
| 2587 | } finally { |
| 2588 | Binder.restoreCallingIdentity(identity); |
| 2589 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2593 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2594 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2595 | String manufacturerCode = null; |
| 2596 | if (phone != null) { |
| 2597 | String meid = phone.getMeid(); |
| 2598 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2599 | } |
| 2600 | return manufacturerCode; |
| 2601 | } |
| 2602 | |
| 2603 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2604 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2605 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2606 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2607 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2608 | return null; |
| 2609 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2610 | int subId = phone.getSubId(); |
| 2611 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2612 | mApp, subId, callingPackage, callingFeatureId, |
| 2613 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2614 | return null; |
| 2615 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2616 | |
| 2617 | final long identity = Binder.clearCallingIdentity(); |
| 2618 | try { |
| 2619 | return phone.getDeviceSvn(); |
| 2620 | } finally { |
| 2621 | Binder.restoreCallingIdentity(identity); |
| 2622 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2623 | } |
| 2624 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2625 | @Override |
| 2626 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2627 | final long identity = Binder.clearCallingIdentity(); |
| 2628 | try { |
| 2629 | final Phone phone = getPhone(subId); |
| 2630 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2631 | } finally { |
| 2632 | Binder.restoreCallingIdentity(identity); |
| 2633 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2634 | } |
| 2635 | |
| 2636 | @Override |
| 2637 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2638 | final long identity = Binder.clearCallingIdentity(); |
| 2639 | try { |
| 2640 | final Phone phone = getPhone(subId); |
| 2641 | return phone == null ? null : phone.getCarrierName(); |
| 2642 | } finally { |
| 2643 | Binder.restoreCallingIdentity(identity); |
| 2644 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2645 | } |
| 2646 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2647 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2648 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2649 | final long identity = Binder.clearCallingIdentity(); |
| 2650 | try { |
| 2651 | final Phone phone = getPhone(subId); |
| 2652 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2653 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2654 | } finally { |
| 2655 | Binder.restoreCallingIdentity(identity); |
| 2656 | } |
| 2657 | } |
| 2658 | |
| 2659 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2660 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2661 | final long identity = Binder.clearCallingIdentity(); |
| 2662 | try { |
| 2663 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2664 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2665 | } finally { |
| 2666 | Binder.restoreCallingIdentity(identity); |
| 2667 | } |
| 2668 | } |
| 2669 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2670 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2671 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2672 | if (!isSubscriptionMccMnc) { |
| 2673 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2674 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2675 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2676 | if (phone == null) { |
| 2677 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2678 | } |
| 2679 | final long identity = Binder.clearCallingIdentity(); |
| 2680 | try { |
| 2681 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2682 | } finally { |
| 2683 | Binder.restoreCallingIdentity(identity); |
| 2684 | } |
| 2685 | } |
| 2686 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2687 | // |
| 2688 | // Internal helper methods. |
| 2689 | // |
| 2690 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2691 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2692 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2693 | * |
| 2694 | * @throws SecurityException if the caller does not have the required permission |
| 2695 | */ |
| 2696 | private void enforceModifyPermission() { |
| 2697 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2698 | } |
| 2699 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2700 | /** |
| 2701 | * Make sure the caller is system. |
| 2702 | * |
| 2703 | * @throws SecurityException if the caller is not system. |
| 2704 | */ |
| 2705 | private void enforceSystemCaller() { |
| 2706 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2707 | throw new SecurityException("Caller must be system"); |
| 2708 | } |
| 2709 | } |
| 2710 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2711 | private void enforceActiveEmergencySessionPermission() { |
| 2712 | mApp.enforceCallingOrSelfPermission( |
| 2713 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2714 | } |
| 2715 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2716 | /** |
| 2717 | * Make sure the caller has the CALL_PHONE permission. |
| 2718 | * |
| 2719 | * @throws SecurityException if the caller does not have the required permission |
| 2720 | */ |
| 2721 | private void enforceCallPermission() { |
| 2722 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2723 | } |
| 2724 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2725 | private void enforceSettingsPermission() { |
| 2726 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2727 | } |
| 2728 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2729 | private String createTelUrl(String number) { |
| 2730 | if (TextUtils.isEmpty(number)) { |
| 2731 | return null; |
| 2732 | } |
| 2733 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2734 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2735 | } |
| 2736 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2737 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2738 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2739 | } |
| 2740 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2741 | private static void logv(String msg) { |
| 2742 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2743 | } |
| 2744 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2745 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2746 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2747 | } |
| 2748 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2749 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2750 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2751 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2752 | } |
| 2753 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2754 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2755 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2756 | final long identity = Binder.clearCallingIdentity(); |
| 2757 | try { |
| 2758 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2759 | if (phone == null) { |
| 2760 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2761 | } else { |
| 2762 | return phone.getPhoneType(); |
| 2763 | } |
| 2764 | } finally { |
| 2765 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2766 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | /** |
| 2770 | * Returns the CDMA ERI icon index to display |
| 2771 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2772 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2773 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2774 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2775 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2776 | } |
| 2777 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2778 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2779 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2780 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2781 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2782 | mApp, subId, callingPackage, callingFeatureId, |
| 2783 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2784 | return -1; |
| 2785 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2786 | |
| 2787 | final long identity = Binder.clearCallingIdentity(); |
| 2788 | try { |
| 2789 | final Phone phone = getPhone(subId); |
| 2790 | if (phone != null) { |
| 2791 | return phone.getCdmaEriIconIndex(); |
| 2792 | } else { |
| 2793 | return -1; |
| 2794 | } |
| 2795 | } finally { |
| 2796 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2797 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2798 | } |
| 2799 | |
| 2800 | /** |
| 2801 | * Returns the CDMA ERI icon mode, |
| 2802 | * 0 - ON |
| 2803 | * 1 - FLASHING |
| 2804 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2805 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2806 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2807 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2808 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2809 | } |
| 2810 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2811 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2812 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2813 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2814 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2815 | mApp, subId, callingPackage, callingFeatureId, |
| 2816 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2817 | return -1; |
| 2818 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2819 | |
| 2820 | final long identity = Binder.clearCallingIdentity(); |
| 2821 | try { |
| 2822 | final Phone phone = getPhone(subId); |
| 2823 | if (phone != null) { |
| 2824 | return phone.getCdmaEriIconMode(); |
| 2825 | } else { |
| 2826 | return -1; |
| 2827 | } |
| 2828 | } finally { |
| 2829 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2830 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2831 | } |
| 2832 | |
| 2833 | /** |
| 2834 | * Returns the CDMA ERI text, |
| 2835 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2836 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2837 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2838 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2839 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2840 | } |
| 2841 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2842 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2843 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2844 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2845 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2846 | mApp, subId, callingPackage, callingFeatureId, |
| 2847 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2848 | return null; |
| 2849 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2850 | |
| 2851 | final long identity = Binder.clearCallingIdentity(); |
| 2852 | try { |
| 2853 | final Phone phone = getPhone(subId); |
| 2854 | if (phone != null) { |
| 2855 | return phone.getCdmaEriText(); |
| 2856 | } else { |
| 2857 | return null; |
| 2858 | } |
| 2859 | } finally { |
| 2860 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2861 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2862 | } |
| 2863 | |
| 2864 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2865 | * Returns the CDMA MDN. |
| 2866 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2867 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2868 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2869 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2870 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2871 | |
| 2872 | final long identity = Binder.clearCallingIdentity(); |
| 2873 | try { |
| 2874 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2875 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2876 | return phone.getLine1Number(); |
| 2877 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2878 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2879 | return null; |
| 2880 | } |
| 2881 | } finally { |
| 2882 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2883 | } |
| 2884 | } |
| 2885 | |
| 2886 | /** |
| 2887 | * Returns the CDMA MIN. |
| 2888 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2889 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2890 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2891 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2892 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2893 | |
| 2894 | final long identity = Binder.clearCallingIdentity(); |
| 2895 | try { |
| 2896 | final Phone phone = getPhone(subId); |
| 2897 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2898 | return phone.getCdmaMin(); |
| 2899 | } else { |
| 2900 | return null; |
| 2901 | } |
| 2902 | } finally { |
| 2903 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2904 | } |
| 2905 | } |
| 2906 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2907 | @Override |
| 2908 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2909 | INumberVerificationCallback callback, String callingPackage) { |
| 2910 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2911 | != PERMISSION_GRANTED) { |
| 2912 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2913 | } |
| 2914 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2915 | |
| 2916 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2917 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2918 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2919 | } |
| 2920 | |
| 2921 | if (range == null) { |
| 2922 | throw new NullPointerException("Range must be non-null"); |
| 2923 | } |
| 2924 | |
| 2925 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2926 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2927 | |
| 2928 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2929 | } |
| 2930 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2931 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2932 | * Returns true if CDMA provisioning needs to run. |
| 2933 | */ |
| 2934 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2935 | final long identity = Binder.clearCallingIdentity(); |
| 2936 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2937 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2938 | } finally { |
| 2939 | Binder.restoreCallingIdentity(identity); |
| 2940 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2941 | } |
| 2942 | |
| 2943 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2944 | * Sets the voice mail number of a given subId. |
| 2945 | */ |
| 2946 | @Override |
| 2947 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2948 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2949 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2950 | |
| 2951 | final long identity = Binder.clearCallingIdentity(); |
| 2952 | try { |
| 2953 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2954 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2955 | return success; |
| 2956 | } finally { |
| 2957 | Binder.restoreCallingIdentity(identity); |
| 2958 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2959 | } |
| 2960 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2961 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2962 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2963 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2964 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2965 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2966 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2967 | throw new SecurityException("caller must be system dialer"); |
| 2968 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2969 | |
| 2970 | final long identity = Binder.clearCallingIdentity(); |
| 2971 | try { |
| 2972 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2973 | if (phoneAccountHandle == null) { |
| 2974 | return null; |
| 2975 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2976 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2977 | } finally { |
| 2978 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2979 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2980 | } |
| 2981 | |
| 2982 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2983 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2984 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2985 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2986 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2987 | mApp, subId, callingPackage, callingFeatureId, |
| 2988 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2989 | return null; |
| 2990 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2991 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2992 | final long identity = Binder.clearCallingIdentity(); |
| 2993 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2994 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2995 | } finally { |
| 2996 | Binder.restoreCallingIdentity(identity); |
| 2997 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2998 | } |
| 2999 | |
| 3000 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3001 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3002 | VisualVoicemailSmsFilterSettings settings) { |
| 3003 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3004 | |
| 3005 | final long identity = Binder.clearCallingIdentity(); |
| 3006 | try { |
| 3007 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3008 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3009 | } finally { |
| 3010 | Binder.restoreCallingIdentity(identity); |
| 3011 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3012 | } |
| 3013 | |
| 3014 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3015 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3016 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3017 | |
| 3018 | final long identity = Binder.clearCallingIdentity(); |
| 3019 | try { |
| 3020 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3021 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3022 | } finally { |
| 3023 | Binder.restoreCallingIdentity(identity); |
| 3024 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3025 | } |
| 3026 | |
| 3027 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3028 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3029 | String callingPackage, int subId) { |
| 3030 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3031 | |
| 3032 | final long identity = Binder.clearCallingIdentity(); |
| 3033 | try { |
| 3034 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3035 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3036 | } finally { |
| 3037 | Binder.restoreCallingIdentity(identity); |
| 3038 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3039 | } |
| 3040 | |
| 3041 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3042 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3043 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3044 | |
| 3045 | final long identity = Binder.clearCallingIdentity(); |
| 3046 | try { |
| 3047 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3048 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3049 | } finally { |
| 3050 | Binder.restoreCallingIdentity(identity); |
| 3051 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3052 | } |
| 3053 | |
| 3054 | @Override |
| 3055 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 3056 | String number, int port, String text, PendingIntent sentIntent) { |
| 3057 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3058 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3059 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3060 | SmsController smsController = PhoneFactory.getSmsController(); |
| 3061 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 3062 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3063 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3064 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3065 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3066 | * Sets the voice activation state of a given subId. |
| 3067 | */ |
| 3068 | @Override |
| 3069 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3070 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3071 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3072 | |
| 3073 | final long identity = Binder.clearCallingIdentity(); |
| 3074 | try { |
| 3075 | final Phone phone = getPhone(subId); |
| 3076 | if (phone != null) { |
| 3077 | phone.setVoiceActivationState(activationState); |
| 3078 | } else { |
| 3079 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3080 | } |
| 3081 | } finally { |
| 3082 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3083 | } |
| 3084 | } |
| 3085 | |
| 3086 | /** |
| 3087 | * Sets the data activation state of a given subId. |
| 3088 | */ |
| 3089 | @Override |
| 3090 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3091 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3092 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3093 | |
| 3094 | final long identity = Binder.clearCallingIdentity(); |
| 3095 | try { |
| 3096 | final Phone phone = getPhone(subId); |
| 3097 | if (phone != null) { |
| 3098 | phone.setDataActivationState(activationState); |
| 3099 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3100 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3101 | } |
| 3102 | } finally { |
| 3103 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3104 | } |
| 3105 | } |
| 3106 | |
| 3107 | /** |
| 3108 | * Returns the voice activation state of a given subId. |
| 3109 | */ |
| 3110 | @Override |
| 3111 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3112 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3113 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3114 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3115 | final long identity = Binder.clearCallingIdentity(); |
| 3116 | try { |
| 3117 | if (phone != null) { |
| 3118 | return phone.getVoiceActivationState(); |
| 3119 | } else { |
| 3120 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3121 | } |
| 3122 | } finally { |
| 3123 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3124 | } |
| 3125 | } |
| 3126 | |
| 3127 | /** |
| 3128 | * Returns the data activation state of a given subId. |
| 3129 | */ |
| 3130 | @Override |
| 3131 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3132 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3133 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3134 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3135 | final long identity = Binder.clearCallingIdentity(); |
| 3136 | try { |
| 3137 | if (phone != null) { |
| 3138 | return phone.getDataActivationState(); |
| 3139 | } else { |
| 3140 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3141 | } |
| 3142 | } finally { |
| 3143 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3144 | } |
| 3145 | } |
| 3146 | |
| 3147 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3148 | * Returns the unread count of voicemails for a subId |
| 3149 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3150 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3151 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3152 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3153 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3154 | mApp, subId, callingPackage, callingFeatureId, |
| 3155 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3156 | return 0; |
| 3157 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3158 | final long identity = Binder.clearCallingIdentity(); |
| 3159 | try { |
| 3160 | final Phone phone = getPhone(subId); |
| 3161 | if (phone != null) { |
| 3162 | return phone.getVoiceMessageCount(); |
| 3163 | } else { |
| 3164 | return 0; |
| 3165 | } |
| 3166 | } finally { |
| 3167 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3168 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3169 | } |
| 3170 | |
| 3171 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3172 | * returns true, if the device is in a state where both voice and data |
| 3173 | * are supported simultaneously. This can change based on location or network condition. |
| 3174 | */ |
| 3175 | @Override |
| 3176 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3177 | final long identity = Binder.clearCallingIdentity(); |
| 3178 | try { |
| 3179 | final Phone phone = getPhone(subId); |
| 3180 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3181 | } finally { |
| 3182 | Binder.restoreCallingIdentity(identity); |
| 3183 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3184 | } |
| 3185 | |
| 3186 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3187 | * Send the dialer code if called from the current default dialer or the caller has |
| 3188 | * carrier privilege. |
| 3189 | * @param inputCode The dialer code to send |
| 3190 | */ |
| 3191 | @Override |
| 3192 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3193 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3194 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3195 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3196 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3197 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3198 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3199 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3200 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3201 | |
| 3202 | final long identity = Binder.clearCallingIdentity(); |
| 3203 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3204 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3205 | } finally { |
| 3206 | Binder.restoreCallingIdentity(identity); |
| 3207 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3208 | } |
| 3209 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3210 | @Override |
| 3211 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3212 | TelephonyPermissions |
| 3213 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3214 | mApp, subId, "getNetworkSelectionMode"); |
| 3215 | final long identity = Binder.clearCallingIdentity(); |
| 3216 | try { |
| 3217 | if (!isActiveSubscription(subId)) { |
| 3218 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3219 | } |
| 3220 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3221 | } finally { |
| 3222 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3223 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3224 | } |
| 3225 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3226 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3227 | public boolean isInEmergencySmsMode() { |
| 3228 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3229 | final long identity = Binder.clearCallingIdentity(); |
| 3230 | try { |
| 3231 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3232 | if (phone.isInEmergencySmsMode()) { |
| 3233 | return true; |
| 3234 | } |
| 3235 | } |
| 3236 | } finally { |
| 3237 | Binder.restoreCallingIdentity(identity); |
| 3238 | } |
| 3239 | return false; |
| 3240 | } |
| 3241 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3242 | /** |
| 3243 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3244 | * @param subId The subscription to use to check the configuration. |
| 3245 | * @param c The callback that will be used to send the result. |
| 3246 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3247 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3248 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3249 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3250 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3251 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3252 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3253 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3254 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3255 | "IMS not available on device."); |
| 3256 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3257 | final long token = Binder.clearCallingIdentity(); |
| 3258 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3259 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3260 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3261 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3262 | } catch (ImsException e) { |
| 3263 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3264 | } finally { |
| 3265 | Binder.restoreCallingIdentity(token); |
| 3266 | } |
| 3267 | } |
| 3268 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3269 | /** |
| 3270 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3271 | * @param subId The subscription to use to check the configuration. |
| 3272 | * @param c The callback that will be used to send the result. |
| 3273 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3274 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3275 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3276 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3277 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3278 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3279 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3280 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3281 | final long token = Binder.clearCallingIdentity(); |
| 3282 | try { |
| 3283 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3284 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3285 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3286 | } catch (ImsException e) { |
| 3287 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3288 | + "is inactive, ignoring unregister."); |
| 3289 | // If the subscription is no longer active, just return, since the callback |
| 3290 | // will already have been removed internally. |
| 3291 | } finally { |
| 3292 | Binder.restoreCallingIdentity(token); |
| 3293 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3294 | } |
| 3295 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3296 | /** |
| 3297 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3298 | */ |
| 3299 | @Override |
| 3300 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3301 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3302 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3303 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3304 | "IMS not available on device."); |
| 3305 | } |
| 3306 | final long token = Binder.clearCallingIdentity(); |
| 3307 | try { |
| 3308 | Phone phone = getPhone(subId); |
| 3309 | if (phone == null) { |
| 3310 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3311 | + subId + "'"); |
| 3312 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3313 | } |
| 3314 | phone.getImsRegistrationState(regState -> { |
| 3315 | try { |
| 3316 | consumer.accept((regState == null) |
| 3317 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3318 | } catch (RemoteException e) { |
| 3319 | // Ignore if the remote process is no longer available to call back. |
| 3320 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3321 | } |
| 3322 | }); |
| 3323 | } finally { |
| 3324 | Binder.restoreCallingIdentity(token); |
| 3325 | } |
| 3326 | } |
| 3327 | |
| 3328 | /** |
| 3329 | * Get the transport type for the IMS service registration state. |
| 3330 | */ |
| 3331 | @Override |
| 3332 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3333 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3334 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3335 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3336 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3337 | "IMS not available on device."); |
| 3338 | } |
| 3339 | final long token = Binder.clearCallingIdentity(); |
| 3340 | try { |
| 3341 | Phone phone = getPhone(subId); |
| 3342 | if (phone == null) { |
| 3343 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3344 | + subId + "'"); |
| 3345 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3346 | } |
| 3347 | phone.getImsRegistrationTech(regTech -> { |
| 3348 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3349 | int regTechConverted = (regTech == null) |
| 3350 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3351 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3352 | regTechConverted); |
| 3353 | try { |
| 3354 | consumer.accept(regTechConverted); |
| 3355 | } catch (RemoteException e) { |
| 3356 | // Ignore if the remote process is no longer available to call back. |
| 3357 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3358 | } |
| 3359 | }); |
| 3360 | } finally { |
| 3361 | Binder.restoreCallingIdentity(token); |
| 3362 | } |
| 3363 | } |
| 3364 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3365 | /** |
| 3366 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3367 | * @param subId The subscription to use to check the configuration. |
| 3368 | * @param c The callback that will be used to send the result. |
| 3369 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3370 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3371 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3372 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3373 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3374 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3375 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3376 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3377 | "IMS not available on device."); |
| 3378 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3379 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3380 | final long token = Binder.clearCallingIdentity(); |
| 3381 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3382 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3383 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3384 | } catch (ImsException e) { |
| 3385 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3386 | } finally { |
| 3387 | Binder.restoreCallingIdentity(token); |
| 3388 | } |
| 3389 | } |
| 3390 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3391 | /** |
| 3392 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3393 | * @param subId The subscription to use to check the configuration. |
| 3394 | * @param c The callback that will be used to send the result. |
| 3395 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3396 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3397 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3398 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3399 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3400 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3401 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3402 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3403 | |
| 3404 | final long token = Binder.clearCallingIdentity(); |
| 3405 | try { |
| 3406 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3407 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3408 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3409 | } catch (ImsException e) { |
| 3410 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3411 | + "is inactive, ignoring unregister."); |
| 3412 | // If the subscription is no longer active, just return, since the callback |
| 3413 | // will already have been removed internally. |
| 3414 | } finally { |
| 3415 | Binder.restoreCallingIdentity(token); |
| 3416 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3417 | } |
| 3418 | |
| 3419 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3420 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3421 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3422 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3423 | final long token = Binder.clearCallingIdentity(); |
| 3424 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3425 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3426 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3427 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3428 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3429 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3430 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3431 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3432 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3433 | } finally { |
| 3434 | Binder.restoreCallingIdentity(token); |
| 3435 | } |
| 3436 | } |
| 3437 | |
| 3438 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3439 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3440 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3441 | final long token = Binder.clearCallingIdentity(); |
| 3442 | try { |
| 3443 | Phone phone = getPhone(subId); |
| 3444 | if (phone == null) return false; |
| 3445 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3446 | } finally { |
| 3447 | Binder.restoreCallingIdentity(token); |
| 3448 | } |
| 3449 | } |
| 3450 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3451 | /** |
| 3452 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3453 | * subscription. |
| 3454 | * @param subId The subscription to use to check the configuration. |
| 3455 | * @param callback The callback that will be used to send the result. |
| 3456 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3457 | * @param transportType The transport type of the MmTelFeature capability. |
| 3458 | */ |
| 3459 | @Override |
| 3460 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3461 | int transportType) { |
| 3462 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3463 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3464 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3465 | "IMS not available on device."); |
| 3466 | } |
| 3467 | final long token = Binder.clearCallingIdentity(); |
| 3468 | try { |
| 3469 | int slotId = getSlotIndex(subId); |
| 3470 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3471 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3472 | + subId + "'"); |
| 3473 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3474 | } |
| 3475 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3476 | transportType, aBoolean -> { |
| 3477 | try { |
| 3478 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3479 | } catch (RemoteException e) { |
| 3480 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3481 | + "running. Ignore"); |
| 3482 | } |
| 3483 | }); |
| 3484 | } finally { |
| 3485 | Binder.restoreCallingIdentity(token); |
| 3486 | } |
| 3487 | } |
| 3488 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3489 | /** |
| 3490 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3491 | * @param subId The subscription to use to check the configuration. |
| 3492 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3493 | @Override |
| 3494 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3495 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3496 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3497 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3498 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3499 | final long token = Binder.clearCallingIdentity(); |
| 3500 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3501 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3502 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3503 | } catch (ImsException e) { |
| 3504 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3505 | } finally { |
| 3506 | Binder.restoreCallingIdentity(token); |
| 3507 | } |
| 3508 | } |
| 3509 | |
| 3510 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3511 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3512 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3513 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3514 | final long identity = Binder.clearCallingIdentity(); |
| 3515 | try { |
| 3516 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3517 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3518 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3519 | } catch (ImsException e) { |
| 3520 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3521 | } finally { |
| 3522 | Binder.restoreCallingIdentity(identity); |
| 3523 | } |
| 3524 | } |
| 3525 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3526 | /** |
| 3527 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3528 | * @param subId The subscription to use to check the configuration. |
| 3529 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3530 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3531 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3532 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3533 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3534 | final long identity = Binder.clearCallingIdentity(); |
| 3535 | try { |
| 3536 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3537 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3538 | } catch (ImsException e) { |
| 3539 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3540 | } finally { |
| 3541 | Binder.restoreCallingIdentity(identity); |
| 3542 | } |
| 3543 | } |
| 3544 | |
| 3545 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3546 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3547 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3548 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3549 | final long identity = Binder.clearCallingIdentity(); |
| 3550 | try { |
| 3551 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3552 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3553 | } catch (ImsException e) { |
| 3554 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3555 | } finally { |
| 3556 | Binder.restoreCallingIdentity(identity); |
| 3557 | } |
| 3558 | } |
| 3559 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3560 | /** |
| 3561 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3562 | * @param subId The subscription to use to check the configuration. |
| 3563 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3564 | @Override |
| 3565 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3566 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3567 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3568 | final long identity = Binder.clearCallingIdentity(); |
| 3569 | try { |
| 3570 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3571 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3572 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3573 | } catch (ImsException e) { |
| 3574 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3575 | } finally { |
| 3576 | Binder.restoreCallingIdentity(identity); |
| 3577 | } |
| 3578 | } |
| 3579 | |
| 3580 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3581 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3582 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3583 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3584 | final long identity = Binder.clearCallingIdentity(); |
| 3585 | try { |
| 3586 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3587 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3588 | } catch (ImsException e) { |
| 3589 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3590 | } finally { |
| 3591 | Binder.restoreCallingIdentity(identity); |
| 3592 | } |
| 3593 | } |
| 3594 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3595 | /** |
| 3596 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3597 | * @param subId The subscription to use to check the configuration. |
| 3598 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3599 | @Override |
| 3600 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3601 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3602 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3603 | final long identity = Binder.clearCallingIdentity(); |
| 3604 | try { |
| 3605 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3606 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3607 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3608 | } catch (ImsException e) { |
| 3609 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3610 | } finally { |
| 3611 | Binder.restoreCallingIdentity(identity); |
| 3612 | } |
| 3613 | } |
| 3614 | |
| 3615 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3616 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3617 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3618 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3619 | final long identity = Binder.clearCallingIdentity(); |
| 3620 | try { |
| 3621 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3622 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3623 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3624 | } catch (ImsException e) { |
| 3625 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3626 | } finally { |
| 3627 | Binder.restoreCallingIdentity(identity); |
| 3628 | } |
| 3629 | } |
| 3630 | |
| 3631 | @Override |
| 3632 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3633 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3634 | "setVoWiFiNonPersistent"); |
| 3635 | final long identity = Binder.clearCallingIdentity(); |
| 3636 | try { |
| 3637 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3638 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3639 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3640 | } catch (ImsException e) { |
| 3641 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3642 | } finally { |
| 3643 | Binder.restoreCallingIdentity(identity); |
| 3644 | } |
| 3645 | } |
| 3646 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3647 | /** |
| 3648 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3649 | * @param subId The subscription to use to check the configuration. |
| 3650 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3651 | @Override |
| 3652 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3653 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3654 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3655 | final long identity = Binder.clearCallingIdentity(); |
| 3656 | try { |
| 3657 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3658 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3659 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3660 | } catch (ImsException e) { |
| 3661 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3662 | } finally { |
| 3663 | Binder.restoreCallingIdentity(identity); |
| 3664 | } |
| 3665 | } |
| 3666 | |
| 3667 | @Override |
| 3668 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3669 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3670 | "setVoWiFiModeSetting"); |
| 3671 | final long identity = Binder.clearCallingIdentity(); |
| 3672 | try { |
| 3673 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3674 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3675 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3676 | } catch (ImsException e) { |
| 3677 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3678 | } finally { |
| 3679 | Binder.restoreCallingIdentity(identity); |
| 3680 | } |
| 3681 | } |
| 3682 | |
| 3683 | @Override |
| 3684 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3685 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3686 | final long identity = Binder.clearCallingIdentity(); |
| 3687 | try { |
| 3688 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3689 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3690 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3691 | } catch (ImsException e) { |
| 3692 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3693 | } finally { |
| 3694 | Binder.restoreCallingIdentity(identity); |
| 3695 | } |
| 3696 | } |
| 3697 | |
| 3698 | @Override |
| 3699 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3700 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3701 | "setVoWiFiRoamingModeSetting"); |
| 3702 | final long identity = Binder.clearCallingIdentity(); |
| 3703 | try { |
| 3704 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3705 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3706 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3707 | } catch (ImsException e) { |
| 3708 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3709 | } finally { |
| 3710 | Binder.restoreCallingIdentity(identity); |
| 3711 | } |
| 3712 | } |
| 3713 | |
| 3714 | @Override |
| 3715 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3716 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3717 | "setRttCapabilityEnabled"); |
| 3718 | final long identity = Binder.clearCallingIdentity(); |
| 3719 | try { |
| 3720 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3721 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3722 | } catch (ImsException e) { |
| 3723 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3724 | } finally { |
| 3725 | Binder.restoreCallingIdentity(identity); |
| 3726 | } |
| 3727 | } |
| 3728 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3729 | /** |
| 3730 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3731 | * @param subId The subscription to use to check the configuration. |
| 3732 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3733 | @Override |
| 3734 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3735 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3736 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3737 | final long identity = Binder.clearCallingIdentity(); |
| 3738 | try { |
| 3739 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3740 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3741 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3742 | } catch (ImsException e) { |
| 3743 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3744 | } finally { |
| 3745 | Binder.restoreCallingIdentity(identity); |
| 3746 | } |
| 3747 | } |
| 3748 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3749 | @Override |
| 3750 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3751 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3752 | final long identity = Binder.clearCallingIdentity(); |
| 3753 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3754 | if (!isImsAvailableOnDevice()) { |
| 3755 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3756 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3757 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3758 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3759 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3760 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3761 | } catch (ImsException e) { |
| 3762 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3763 | } finally { |
| 3764 | Binder.restoreCallingIdentity(identity); |
| 3765 | } |
| 3766 | } |
| 3767 | |
| 3768 | @Override |
| 3769 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3770 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3771 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3772 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3773 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3774 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3775 | try { |
| 3776 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3777 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3778 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3779 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3780 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3781 | + "is inactive, ignoring unregister."); |
| 3782 | // If the subscription is no longer active, just return, since the callback will already |
| 3783 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3784 | } finally { |
| 3785 | Binder.restoreCallingIdentity(identity); |
| 3786 | } |
| 3787 | } |
| 3788 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3789 | |
| 3790 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3791 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3792 | message); |
| 3793 | } |
| 3794 | |
| 3795 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3796 | boolean isMmtelCapability) { |
| 3797 | Phone phone = getPhone(subId); |
| 3798 | if (phone == null) { |
| 3799 | loge("phone instance null for subid " + subId); |
| 3800 | return false; |
| 3801 | } |
| 3802 | if (isMmtelCapability) { |
| 3803 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3804 | return false; |
| 3805 | } |
| 3806 | } else { |
| 3807 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3808 | return false; |
| 3809 | } |
| 3810 | } |
| 3811 | return true; |
| 3812 | } |
| 3813 | |
| 3814 | @Override |
| 3815 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3816 | boolean isProvisioned) { |
| 3817 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3818 | |
| 3819 | final long identity = Binder.clearCallingIdentity(); |
| 3820 | try { |
| 3821 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3822 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3823 | return; |
| 3824 | } |
| 3825 | |
| 3826 | // this capability requires provisioning, route to the correct API. |
| 3827 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3828 | switch (capability) { |
| 3829 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3830 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3831 | ims.setEabProvisioned(isProvisioned); |
| 3832 | break; |
| 3833 | default: { |
| 3834 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3835 | + "rcs capability '" + capability + "', which does not require " |
| 3836 | + "provisioning."); |
| 3837 | } |
| 3838 | } |
| 3839 | } finally { |
| 3840 | Binder.restoreCallingIdentity(identity); |
| 3841 | } |
| 3842 | |
| 3843 | } |
| 3844 | |
| 3845 | |
| 3846 | @Override |
| 3847 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3848 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3849 | final long identity = Binder.clearCallingIdentity(); |
| 3850 | try { |
| 3851 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3852 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3853 | return true; |
| 3854 | } |
| 3855 | |
| 3856 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3857 | switch (capability) { |
| 3858 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3859 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3860 | return ims.isEabProvisionedOnDevice(); |
| 3861 | |
| 3862 | default: { |
| 3863 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3864 | + "capability '" + capability + "', which does not require " |
| 3865 | + "provisioning."); |
| 3866 | } |
| 3867 | } |
| 3868 | |
| 3869 | } finally { |
| 3870 | Binder.restoreCallingIdentity(identity); |
| 3871 | } |
| 3872 | } |
| 3873 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3874 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3875 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3876 | boolean isProvisioned) { |
| 3877 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3878 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3879 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3880 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3881 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3882 | final long identity = Binder.clearCallingIdentity(); |
| 3883 | try { |
| 3884 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3885 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3886 | return; |
| 3887 | } |
| 3888 | |
| 3889 | // this capability requires provisioning, route to the correct API. |
| 3890 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3891 | switch (capability) { |
| 3892 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3893 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3894 | ims.setVolteProvisioned(isProvisioned); |
| 3895 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3896 | ims.setWfcProvisioned(isProvisioned); |
| 3897 | } |
| 3898 | break; |
| 3899 | } |
| 3900 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3901 | // There is currently no difference in VT provisioning type. |
| 3902 | ims.setVtProvisioned(isProvisioned); |
| 3903 | break; |
| 3904 | } |
| 3905 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3906 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3907 | // change the capability of the feature instead if needed. |
| 3908 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3909 | == isProvisioned) { |
| 3910 | // No change in provisioning. |
| 3911 | return; |
| 3912 | } |
| 3913 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3914 | try { |
| 3915 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3916 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3917 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3918 | + ", Exception" + e.getMessage()); |
| 3919 | } |
| 3920 | break; |
| 3921 | } |
| 3922 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3923 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3924 | + "MmTel capability '" + capability + "', which does not require " |
| 3925 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3926 | } |
| 3927 | } |
| 3928 | |
| 3929 | } finally { |
| 3930 | Binder.restoreCallingIdentity(identity); |
| 3931 | } |
| 3932 | } |
| 3933 | |
| 3934 | @Override |
| 3935 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3936 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3937 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3938 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3939 | } |
| 3940 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3941 | final long identity = Binder.clearCallingIdentity(); |
| 3942 | try { |
| 3943 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3944 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3945 | return true; |
| 3946 | } |
| 3947 | |
| 3948 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3949 | switch (capability) { |
| 3950 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3951 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3952 | return ims.isVolteProvisionedOnDevice(); |
| 3953 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3954 | return ims.isWfcProvisionedOnDevice(); |
| 3955 | } |
| 3956 | // This should never happen, since we are checking tech above to make sure it |
| 3957 | // is either LTE or IWLAN. |
| 3958 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3959 | + "capability."); |
| 3960 | } |
| 3961 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3962 | // There is currently no difference in VT provisioning type. |
| 3963 | return ims.isVtProvisionedOnDevice(); |
| 3964 | } |
| 3965 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3966 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3967 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3968 | } |
| 3969 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3970 | throw new IllegalArgumentException( |
| 3971 | "Tried to get provisioning for MmTel capability '" + capability |
| 3972 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3973 | } |
| 3974 | } |
| 3975 | |
| 3976 | } finally { |
| 3977 | Binder.restoreCallingIdentity(identity); |
| 3978 | } |
| 3979 | } |
| 3980 | |
| 3981 | @Override |
| 3982 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3983 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3984 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3985 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3986 | } |
| 3987 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3988 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3989 | return (provisionedBits & capability) > 0; |
| 3990 | } |
| 3991 | |
| 3992 | @Override |
| 3993 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3994 | boolean isProvisioned) { |
| 3995 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3996 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3997 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3998 | } |
| 3999 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4000 | "setProvisioningStatusForCapability"); |
| 4001 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4002 | // If the current provisioning status for capability already matches isProvisioned, |
| 4003 | // do nothing. |
| 4004 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4005 | return; |
| 4006 | } |
| 4007 | if (isProvisioned) { |
| 4008 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4009 | } else { |
| 4010 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4011 | } |
| 4012 | } |
| 4013 | |
| 4014 | /** |
| 4015 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4016 | * technology. The bitfield should mirror the bitfield defined by |
| 4017 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4018 | */ |
| 4019 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4020 | String key = getMmTelProvisioningKey(subId, tech); |
| 4021 | // Default is no capabilities are provisioned. |
| 4022 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4023 | } |
| 4024 | |
| 4025 | /** |
| 4026 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4027 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4028 | * technology specified. |
| 4029 | * |
| 4030 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4031 | */ |
| 4032 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4033 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4034 | String key = getMmTelProvisioningKey(subId, tech); |
| 4035 | editor.putInt(key, newField); |
| 4036 | editor.commit(); |
| 4037 | } |
| 4038 | |
| 4039 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4040 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4041 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4042 | } |
| 4043 | |
| 4044 | /** |
| 4045 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4046 | * carrier associated with the subscription id. |
| 4047 | */ |
| 4048 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4049 | int capability) { |
| 4050 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4051 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4052 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4053 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4054 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4055 | false); |
| 4056 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4057 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4058 | |
| 4059 | // First check to make sure that the capability requires provisioning. |
| 4060 | switch (capability) { |
| 4061 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4062 | // intentional fallthrough |
| 4063 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4064 | if (requireVoiceVtProvisioning) { |
| 4065 | // Voice and Video requires provisioning |
| 4066 | return true; |
| 4067 | } |
| 4068 | break; |
| 4069 | } |
| 4070 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4071 | if (requireUtProvisioning) { |
| 4072 | // UT requires provisioning |
| 4073 | return true; |
| 4074 | } |
| 4075 | break; |
| 4076 | } |
| 4077 | } |
| 4078 | return false; |
| 4079 | } |
| 4080 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4081 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4082 | int capability) { |
| 4083 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4084 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4085 | |
| 4086 | boolean requireRcsProvisioning = c.getBoolean( |
| 4087 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4088 | |
| 4089 | // First check to make sure that the capability requires provisioning. |
| 4090 | switch (capability) { |
| 4091 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4092 | // intentional fallthrough |
| 4093 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4094 | if (requireRcsProvisioning) { |
| 4095 | // OPTION or PRESENCE requires provisioning |
| 4096 | return true; |
| 4097 | } |
| 4098 | break; |
| 4099 | } |
| 4100 | } |
| 4101 | return false; |
| 4102 | } |
| 4103 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4104 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4105 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4106 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4107 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4108 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4109 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4110 | final long identity = Binder.clearCallingIdentity(); |
| 4111 | try { |
| 4112 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4113 | int slotId = getSlotIndex(subId); |
| 4114 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4115 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4116 | + subId + "' for key:" + key); |
| 4117 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4118 | } |
| 4119 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4120 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4121 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4122 | + subId + "' for key:" + key); |
| 4123 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4124 | } finally { |
| 4125 | Binder.restoreCallingIdentity(identity); |
| 4126 | } |
| 4127 | } |
| 4128 | |
| 4129 | @Override |
| 4130 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4131 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4132 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4133 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4134 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4135 | final long identity = Binder.clearCallingIdentity(); |
| 4136 | try { |
| 4137 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4138 | int slotId = getSlotIndex(subId); |
| 4139 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4140 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4141 | + subId + "' for key:" + key); |
| 4142 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4143 | } |
| 4144 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4145 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4146 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4147 | + subId + "' for key:" + key); |
| 4148 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4149 | } finally { |
| 4150 | Binder.restoreCallingIdentity(identity); |
| 4151 | } |
| 4152 | } |
| 4153 | |
| 4154 | @Override |
| 4155 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4156 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4157 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4158 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4159 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4160 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4161 | final long identity = Binder.clearCallingIdentity(); |
| 4162 | try { |
| 4163 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4164 | int slotId = getSlotIndex(subId); |
| 4165 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4166 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4167 | + subId + "' for key:" + key); |
| 4168 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4169 | } |
| 4170 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4171 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4172 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4173 | + "' for key:" + key); |
| 4174 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4175 | } finally { |
| 4176 | Binder.restoreCallingIdentity(identity); |
| 4177 | } |
| 4178 | } |
| 4179 | |
| 4180 | @Override |
| 4181 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4182 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4183 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4184 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4185 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4186 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4187 | final long identity = Binder.clearCallingIdentity(); |
| 4188 | try { |
| 4189 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4190 | int slotId = getSlotIndex(subId); |
| 4191 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4192 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4193 | + subId + "' for key:" + key); |
| 4194 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4195 | } |
| 4196 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4197 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4198 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4199 | + "' for key:" + key); |
| 4200 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4201 | } finally { |
| 4202 | Binder.restoreCallingIdentity(identity); |
| 4203 | } |
| 4204 | } |
| 4205 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4206 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4207 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4208 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4209 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4210 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4211 | } |
| 4212 | return slotId; |
| 4213 | } |
| 4214 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4215 | private int getSlotIndex(int subId) { |
| 4216 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4217 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4218 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4219 | } |
| 4220 | return slotId; |
| 4221 | } |
| 4222 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4223 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4224 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4225 | */ |
| 4226 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4227 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4228 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4229 | final int targetSdk = getTargetSdk(callingPackage); |
| 4230 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4231 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4232 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4233 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4234 | mApp, subId, callingPackage, callingFeatureId, |
| 4235 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4236 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4237 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4238 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4239 | final long identity = Binder.clearCallingIdentity(); |
| 4240 | try { |
| 4241 | final Phone phone = getPhone(subId); |
| 4242 | if (phone != null) { |
| 4243 | return phone.getServiceState().getDataNetworkType(); |
| 4244 | } else { |
| 4245 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4246 | } |
| 4247 | } finally { |
| 4248 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4249 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4250 | } |
| 4251 | |
| 4252 | /** |
| 4253 | * Returns the data network type |
| 4254 | */ |
| 4255 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4256 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4257 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4258 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4259 | } |
| 4260 | |
| 4261 | /** |
| 4262 | * Returns the data network type for a subId |
| 4263 | */ |
| 4264 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4265 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4266 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4267 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4268 | mApp, subId, callingPackage, callingFeatureId, |
| 4269 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4270 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4271 | } |
| 4272 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4273 | final long identity = Binder.clearCallingIdentity(); |
| 4274 | try { |
| 4275 | final Phone phone = getPhone(subId); |
| 4276 | if (phone != null) { |
| 4277 | return phone.getServiceState().getDataNetworkType(); |
| 4278 | } else { |
| 4279 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4280 | } |
| 4281 | } finally { |
| 4282 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4283 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4284 | } |
| 4285 | |
| 4286 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4287 | * Returns the Voice network type for a subId |
| 4288 | */ |
| 4289 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4290 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4291 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4292 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4293 | mApp, subId, callingPackage, callingFeatureId, |
| 4294 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4295 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4296 | } |
| 4297 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4298 | final long identity = Binder.clearCallingIdentity(); |
| 4299 | try { |
| 4300 | final Phone phone = getPhone(subId); |
| 4301 | if (phone != null) { |
| 4302 | return phone.getServiceState().getVoiceNetworkType(); |
| 4303 | } else { |
| 4304 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4305 | } |
| 4306 | } finally { |
| 4307 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4308 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4309 | } |
| 4310 | |
| 4311 | /** |
| 4312 | * @return true if a ICC card is present |
| 4313 | */ |
| 4314 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4315 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4316 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4317 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4318 | } |
| 4319 | |
| 4320 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4321 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4322 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4323 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4324 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4325 | final long identity = Binder.clearCallingIdentity(); |
| 4326 | try { |
| 4327 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4328 | if (phone != null) { |
| 4329 | return phone.getIccCard().hasIccCard(); |
| 4330 | } else { |
| 4331 | return false; |
| 4332 | } |
| 4333 | } finally { |
| 4334 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4335 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4336 | } |
| 4337 | |
| 4338 | /** |
| 4339 | * Return if the current radio is LTE on CDMA. This |
| 4340 | * is a tri-state return value as for a period of time |
| 4341 | * the mode may be unknown. |
| 4342 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4343 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4344 | * @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] | 4345 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4346 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4347 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4348 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4349 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4350 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4351 | } |
| 4352 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4353 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4354 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4355 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4356 | try { |
| 4357 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4358 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4359 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4360 | } |
| 4361 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4362 | final long identity = Binder.clearCallingIdentity(); |
| 4363 | try { |
| 4364 | final Phone phone = getPhone(subId); |
| 4365 | if (phone == null) { |
| 4366 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4367 | } else { |
| 4368 | return phone.getLteOnCdmaMode(); |
| 4369 | } |
| 4370 | } finally { |
| 4371 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4372 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4373 | } |
| 4374 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4375 | /** |
| 4376 | * {@hide} |
| 4377 | * Returns Default subId, 0 in the case of single standby. |
| 4378 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4379 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4380 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4381 | } |
| 4382 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4383 | private int getSlotForDefaultSubscription() { |
| 4384 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4385 | } |
| 4386 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4387 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4388 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4389 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4390 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4391 | private boolean isActiveSubscription(int subId) { |
| 4392 | return mSubscriptionController.isActiveSubId(subId); |
| 4393 | } |
| 4394 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4395 | /** |
| 4396 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4397 | */ |
| 4398 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4399 | final long identity = Binder.clearCallingIdentity(); |
| 4400 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4401 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4402 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4403 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4404 | } finally { |
| 4405 | Binder.restoreCallingIdentity(identity); |
| 4406 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4407 | } |
| 4408 | |
| 4409 | /** |
| 4410 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4411 | */ |
| 4412 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4413 | final long identity = Binder.clearCallingIdentity(); |
| 4414 | try { |
| 4415 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4416 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4417 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4418 | } finally { |
| 4419 | Binder.restoreCallingIdentity(identity); |
| 4420 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4421 | } |
| 4422 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4423 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4424 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4425 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4426 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4427 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4428 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4429 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4430 | if (phoneId == -1) { |
| 4431 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4432 | + " does not correspond to an active phone"); |
| 4433 | } |
| 4434 | return PhoneFactory.getPhone(phoneId); |
| 4435 | } |
| 4436 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4437 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4438 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4439 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4440 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4441 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4442 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4443 | if (DBG) { |
| 4444 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4445 | } |
| 4446 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4447 | p2); |
| 4448 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4449 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4450 | |
| 4451 | @Override |
| 4452 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4453 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4454 | enforceModifyPermission(); |
| 4455 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4456 | if (DBG) { |
| 4457 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4458 | } |
| 4459 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4460 | callingPackage, aid, p2); |
| 4461 | } |
| 4462 | |
| 4463 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4464 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4465 | final long identity = Binder.clearCallingIdentity(); |
| 4466 | try { |
| 4467 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4468 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4469 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4470 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4471 | if (bestComponent == null |
| 4472 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4473 | loge("The calling package is not allowed to access ISD-R."); |
| 4474 | throw new SecurityException( |
| 4475 | "The calling package is not allowed to access ISD-R."); |
| 4476 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4477 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4478 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4479 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4480 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4481 | null /* workSource */); |
| 4482 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4483 | return response; |
| 4484 | } finally { |
| 4485 | Binder.restoreCallingIdentity(identity); |
| 4486 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4487 | } |
| 4488 | |
| 4489 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4490 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4491 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4492 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4493 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4494 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4495 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4496 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4497 | @Override |
| 4498 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4499 | enforceModifyPermission(); |
| 4500 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4501 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4502 | channel); |
| 4503 | } |
| 4504 | |
| 4505 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4506 | final long identity = Binder.clearCallingIdentity(); |
| 4507 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4508 | if (channel < 0) { |
| 4509 | return false; |
| 4510 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4511 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4512 | null /* workSource */); |
| 4513 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4514 | return success; |
| 4515 | } finally { |
| 4516 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4517 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4518 | } |
| 4519 | |
| 4520 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4521 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4522 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4523 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4524 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4525 | if (DBG) { |
| 4526 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4527 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4528 | + p3 + " data=" + data); |
| 4529 | } |
| 4530 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4531 | command, p1, p2, p3, data); |
| 4532 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4533 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4534 | @Override |
| 4535 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4536 | int command, int p1, int p2, int p3, String data) { |
| 4537 | enforceModifyPermission(); |
| 4538 | if (DBG) { |
| 4539 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4540 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4541 | + p3 + " data=" + data); |
| 4542 | } |
| 4543 | return iccTransmitApduLogicalChannelWithPermission( |
| 4544 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4545 | data); |
| 4546 | } |
| 4547 | |
| 4548 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4549 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4550 | final long identity = Binder.clearCallingIdentity(); |
| 4551 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4552 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4553 | return ""; |
| 4554 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4555 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4556 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4557 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4558 | null /* workSource */); |
| 4559 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4560 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4561 | // Append the returned status code to the end of the response payload. |
| 4562 | String s = Integer.toHexString( |
| 4563 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4564 | if (response.payload != null) { |
| 4565 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4566 | } |
| 4567 | return s; |
| 4568 | } finally { |
| 4569 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4570 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4571 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4572 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4573 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4574 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4575 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4576 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4577 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4578 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4579 | if (DBG) { |
| 4580 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4581 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4582 | } |
| 4583 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4584 | cla, command, p1, p2, p3, data); |
| 4585 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4586 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4587 | @Override |
| 4588 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4589 | int command, int p1, int p2, int p3, String data) { |
| 4590 | enforceModifyPermission(); |
| 4591 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4592 | if (DBG) { |
| 4593 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4594 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4595 | + " data=" + data); |
| 4596 | } |
| 4597 | |
| 4598 | return iccTransmitApduBasicChannelWithPermission( |
| 4599 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4600 | p2, p3, data); |
| 4601 | } |
| 4602 | |
| 4603 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4604 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4605 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4606 | final long identity = Binder.clearCallingIdentity(); |
| 4607 | try { |
| 4608 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4609 | && TextUtils.equals(ISDR_AID, data)) { |
| 4610 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4611 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4612 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4613 | if (bestComponent == null |
| 4614 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4615 | loge("The calling package is not allowed to select ISD-R."); |
| 4616 | throw new SecurityException( |
| 4617 | "The calling package is not allowed to select ISD-R."); |
| 4618 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4619 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4620 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4621 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4622 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4623 | null /* workSource */); |
| 4624 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4625 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4626 | // Append the returned status code to the end of the response payload. |
| 4627 | String s = Integer.toHexString( |
| 4628 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4629 | if (response.payload != null) { |
| 4630 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4631 | } |
| 4632 | return s; |
| 4633 | } finally { |
| 4634 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4635 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4636 | } |
| 4637 | |
| 4638 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4639 | 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] | 4640 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4641 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4642 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4643 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4644 | final long identity = Binder.clearCallingIdentity(); |
| 4645 | try { |
| 4646 | if (DBG) { |
| 4647 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4648 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4649 | } |
| 4650 | |
| 4651 | IccIoResult response = |
| 4652 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4653 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4654 | subId); |
| 4655 | |
| 4656 | if (DBG) { |
| 4657 | log("Exchange SIM_IO [R]" + response); |
| 4658 | } |
| 4659 | |
| 4660 | byte[] result = null; |
| 4661 | int length = 2; |
| 4662 | if (response.payload != null) { |
| 4663 | length = 2 + response.payload.length; |
| 4664 | result = new byte[length]; |
| 4665 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4666 | } else { |
| 4667 | result = new byte[length]; |
| 4668 | } |
| 4669 | |
| 4670 | result[length - 1] = (byte) response.sw2; |
| 4671 | result[length - 2] = (byte) response.sw1; |
| 4672 | return result; |
| 4673 | } finally { |
| 4674 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4675 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4676 | } |
| 4677 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4678 | /** |
| 4679 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4680 | * on a particular subscription |
| 4681 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4682 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4683 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4684 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4685 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4686 | return null; |
| 4687 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4688 | |
| 4689 | final long identity = Binder.clearCallingIdentity(); |
| 4690 | try { |
| 4691 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4692 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4693 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4694 | return null; |
| 4695 | } |
| 4696 | Object response = sendRequest( |
| 4697 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4698 | if (response instanceof String[]) { |
| 4699 | return (String[]) response; |
| 4700 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4701 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4702 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4703 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4704 | } finally { |
| 4705 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4706 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4707 | } |
| 4708 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4709 | /** |
| 4710 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4711 | * subscription. |
| 4712 | * |
| 4713 | * @param subId the id of the subscription. |
| 4714 | * @param appType the uicc app type, must be USIM or SIM. |
| 4715 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4716 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4717 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4718 | * @return number of fplmns that is successfully written to the SIM. |
| 4719 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4720 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4721 | String callingFeatureId) { |
| 4722 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4723 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4724 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4725 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4726 | } |
| 4727 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4728 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4729 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4730 | } |
| 4731 | if (fplmns == null) { |
| 4732 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4733 | } |
| 4734 | for (String fplmn : fplmns) { |
| 4735 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4736 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4737 | } |
| 4738 | } |
| 4739 | final long identity = Binder.clearCallingIdentity(); |
| 4740 | try { |
| 4741 | Object response = sendRequest( |
| 4742 | CMD_SET_FORBIDDEN_PLMNS, |
| 4743 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4744 | subId); |
| 4745 | return (int) response; |
| 4746 | } finally { |
| 4747 | Binder.restoreCallingIdentity(identity); |
| 4748 | } |
| 4749 | } |
| 4750 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4751 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4752 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4753 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4754 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4755 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4756 | final long identity = Binder.clearCallingIdentity(); |
| 4757 | try { |
| 4758 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4759 | if (response.payload == null) { |
| 4760 | return ""; |
| 4761 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4762 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4763 | // Append the returned status code to the end of the response payload. |
| 4764 | String s = Integer.toHexString( |
| 4765 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4766 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4767 | return s; |
| 4768 | } finally { |
| 4769 | Binder.restoreCallingIdentity(identity); |
| 4770 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4771 | } |
| 4772 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4773 | /** |
| 4774 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4775 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4776 | * |
| 4777 | * @param itemID the ID of the item to read |
| 4778 | * @return the NV item as a String, or null on error. |
| 4779 | */ |
| 4780 | @Override |
| 4781 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4782 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4783 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4784 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4785 | |
| 4786 | final long identity = Binder.clearCallingIdentity(); |
| 4787 | try { |
| 4788 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4789 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4790 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4791 | return value; |
| 4792 | } finally { |
| 4793 | Binder.restoreCallingIdentity(identity); |
| 4794 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4795 | } |
| 4796 | |
| 4797 | /** |
| 4798 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4799 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4800 | * |
| 4801 | * @param itemID the ID of the item to read |
| 4802 | * @param itemValue the value to write, as a String |
| 4803 | * @return true on success; false on any failure |
| 4804 | */ |
| 4805 | @Override |
| 4806 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4807 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4808 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4809 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4810 | |
| 4811 | final long identity = Binder.clearCallingIdentity(); |
| 4812 | try { |
| 4813 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4814 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4815 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4816 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4817 | return success; |
| 4818 | } finally { |
| 4819 | Binder.restoreCallingIdentity(identity); |
| 4820 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4821 | } |
| 4822 | |
| 4823 | /** |
| 4824 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4825 | * Used for device configuration by some CDMA operators. |
| 4826 | * |
| 4827 | * @param preferredRoamingList byte array containing the new PRL |
| 4828 | * @return true on success; false on any failure |
| 4829 | */ |
| 4830 | @Override |
| 4831 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4832 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4833 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4834 | |
| 4835 | final long identity = Binder.clearCallingIdentity(); |
| 4836 | try { |
| 4837 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4838 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4839 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4840 | return success; |
| 4841 | } finally { |
| 4842 | Binder.restoreCallingIdentity(identity); |
| 4843 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4844 | } |
| 4845 | |
| 4846 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4847 | * 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] | 4848 | * Used for device configuration by some CDMA operators. |
| 4849 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4850 | * @param slotIndex - device slot. |
| 4851 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4852 | * @return true on success; false on any failure |
| 4853 | */ |
| 4854 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4855 | public boolean resetModemConfig(int slotIndex) { |
| 4856 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4857 | if (phone != null) { |
| 4858 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4859 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4860 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4861 | final long identity = Binder.clearCallingIdentity(); |
| 4862 | try { |
| 4863 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4864 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4865 | return success; |
| 4866 | } finally { |
| 4867 | Binder.restoreCallingIdentity(identity); |
| 4868 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4869 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4870 | return false; |
| 4871 | } |
| 4872 | |
| 4873 | /** |
| 4874 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4875 | * |
| 4876 | * @param slotIndex - device slot. |
| 4877 | * |
| 4878 | * @return true on success; false on any failure |
| 4879 | */ |
| 4880 | @Override |
| 4881 | public boolean rebootModem(int slotIndex) { |
| 4882 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4883 | if (phone != null) { |
| 4884 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4885 | mApp, phone.getSubId(), "rebootModem"); |
| 4886 | |
| 4887 | final long identity = Binder.clearCallingIdentity(); |
| 4888 | try { |
| 4889 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4890 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4891 | return success; |
| 4892 | } finally { |
| 4893 | Binder.restoreCallingIdentity(identity); |
| 4894 | } |
| 4895 | } |
| 4896 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4897 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4898 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4899 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4900 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4901 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4902 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4903 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4904 | return new String[0]; |
| 4905 | } |
| 4906 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4907 | final long identity = Binder.clearCallingIdentity(); |
| 4908 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4909 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4910 | } finally { |
| 4911 | Binder.restoreCallingIdentity(identity); |
| 4912 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4913 | } |
| 4914 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4915 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 4916 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 4917 | * {@link #disableIms(int)}. |
| 4918 | * @param slotIndex device slot. |
| 4919 | */ |
| 4920 | public void resetIms(int slotIndex) { |
| 4921 | enforceModifyPermission(); |
| 4922 | |
| 4923 | final long identity = Binder.clearCallingIdentity(); |
| 4924 | try { |
| 4925 | if (mImsResolver == null) { |
| 4926 | // may happen if the does not support IMS. |
| 4927 | return; |
| 4928 | } |
| 4929 | mImsResolver.disableIms(slotIndex); |
| 4930 | mImsResolver.enableIms(slotIndex); |
| 4931 | } finally { |
| 4932 | Binder.restoreCallingIdentity(identity); |
| 4933 | } |
| 4934 | } |
| 4935 | |
| 4936 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4937 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4938 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4939 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4940 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4941 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4942 | |
| 4943 | final long identity = Binder.clearCallingIdentity(); |
| 4944 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4945 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4946 | // may happen if the device does not support IMS. |
| 4947 | return; |
| 4948 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4949 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4950 | } finally { |
| 4951 | Binder.restoreCallingIdentity(identity); |
| 4952 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4953 | } |
| 4954 | |
| 4955 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4956 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4957 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4958 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4959 | public void disableIms(int slotId) { |
| 4960 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4961 | |
| 4962 | final long identity = Binder.clearCallingIdentity(); |
| 4963 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4964 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4965 | // may happen if the device does not support IMS. |
| 4966 | return; |
| 4967 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4968 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4969 | } finally { |
| 4970 | Binder.restoreCallingIdentity(identity); |
| 4971 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4972 | } |
| 4973 | |
| 4974 | /** |
| 4975 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4976 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4977 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4978 | */ |
| 4979 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4980 | IImsServiceFeatureCallback callback) { |
| 4981 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4982 | |
| 4983 | final long identity = Binder.clearCallingIdentity(); |
| 4984 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4985 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4986 | // may happen if the device does not support IMS. |
| 4987 | return null; |
| 4988 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4989 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4990 | } finally { |
| 4991 | Binder.restoreCallingIdentity(identity); |
| 4992 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4993 | } |
| 4994 | |
| 4995 | /** |
| 4996 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4997 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4998 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4999 | * listener for feature updates. |
| 5000 | */ |
| 5001 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 5002 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5003 | |
| 5004 | final long identity = Binder.clearCallingIdentity(); |
| 5005 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5006 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5007 | // may happen if the device does not support IMS. |
| 5008 | return null; |
| 5009 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5010 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5011 | } finally { |
| 5012 | Binder.restoreCallingIdentity(identity); |
| 5013 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5014 | } |
| 5015 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5016 | /** |
| 5017 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5018 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5019 | */ |
| 5020 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5021 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5022 | |
| 5023 | final long identity = Binder.clearCallingIdentity(); |
| 5024 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5025 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5026 | // may happen if the device does not support IMS. |
| 5027 | return null; |
| 5028 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5029 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5030 | } finally { |
| 5031 | Binder.restoreCallingIdentity(identity); |
| 5032 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5033 | } |
| 5034 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5035 | /** |
| 5036 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5037 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5038 | */ |
| 5039 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5040 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5041 | |
| 5042 | final long identity = Binder.clearCallingIdentity(); |
| 5043 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5044 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5045 | // may happen if the device does not support IMS. |
| 5046 | return null; |
| 5047 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5048 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5049 | } finally { |
| 5050 | Binder.restoreCallingIdentity(identity); |
| 5051 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5052 | } |
| 5053 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5054 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5055 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5056 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5057 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5058 | * @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] | 5059 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5060 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5061 | * @param packageName The name of the package that the current configuration will be replaced |
| 5062 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5063 | * @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] | 5064 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5065 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5066 | int[] featureTypes, String packageName) { |
| 5067 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5068 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5069 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5070 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5071 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5072 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5073 | final long identity = Binder.clearCallingIdentity(); |
| 5074 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5075 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5076 | // may happen if the device does not support IMS. |
| 5077 | return false; |
| 5078 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5079 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5080 | for (int featureType : featureTypes) { |
| 5081 | featureConfig.put(featureType, packageName); |
| 5082 | } |
| 5083 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5084 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5085 | } finally { |
| 5086 | Binder.restoreCallingIdentity(identity); |
| 5087 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5088 | } |
| 5089 | |
| 5090 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5091 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5092 | * |
| 5093 | * @param slotId The slot that the ImsService is associated with. |
| 5094 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5095 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5096 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5097 | * @return the package name of the ImsService configuration. |
| 5098 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5099 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5100 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5101 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5102 | TelephonyPermissions |
| 5103 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5104 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5105 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5106 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5107 | final long identity = Binder.clearCallingIdentity(); |
| 5108 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5109 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5110 | // may happen if the device does not support IMS. |
| 5111 | return ""; |
| 5112 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5113 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5114 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5115 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5116 | } finally { |
| 5117 | Binder.restoreCallingIdentity(identity); |
| 5118 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5119 | } |
| 5120 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5121 | /** |
| 5122 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5123 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5124 | * @param callback A callback with an integer containing the |
| 5125 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5126 | */ |
| 5127 | @Override |
| 5128 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5129 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5130 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5131 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5132 | "IMS not available on device."); |
| 5133 | } |
| 5134 | final long token = Binder.clearCallingIdentity(); |
| 5135 | try { |
| 5136 | int slotId = getSlotIndex(subId); |
| 5137 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5138 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5139 | + subId + "'"); |
| 5140 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5141 | } |
| 5142 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5143 | try { |
| 5144 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5145 | } catch (RemoteException e) { |
| 5146 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5147 | + "Ignore"); |
| 5148 | } |
| 5149 | }); |
| 5150 | } finally { |
| 5151 | Binder.restoreCallingIdentity(token); |
| 5152 | } |
| 5153 | } |
| 5154 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5155 | public void setImsRegistrationState(boolean registered) { |
| 5156 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5157 | |
| 5158 | final long identity = Binder.clearCallingIdentity(); |
| 5159 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5160 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5161 | } finally { |
| 5162 | Binder.restoreCallingIdentity(identity); |
| 5163 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5164 | } |
| 5165 | |
| 5166 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5167 | * Set the network selection mode to automatic. |
| 5168 | * |
| 5169 | */ |
| 5170 | @Override |
| 5171 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5172 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5173 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5174 | |
| 5175 | final long identity = Binder.clearCallingIdentity(); |
| 5176 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5177 | if (!isActiveSubscription(subId)) { |
| 5178 | return; |
| 5179 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5180 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5181 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5182 | } finally { |
| 5183 | Binder.restoreCallingIdentity(identity); |
| 5184 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5185 | } |
| 5186 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5187 | /** |
| 5188 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5189 | * |
| 5190 | * @param subId the id of the subscription. |
| 5191 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5192 | * the operator to attach to. |
| 5193 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5194 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5195 | * normal network selection next time. |
| 5196 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5197 | */ |
| 5198 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5199 | public boolean setNetworkSelectionModeManual( |
| 5200 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5201 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5202 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5203 | |
| 5204 | if (!isActiveSubscription(subId)) { |
| 5205 | return false; |
| 5206 | } |
| 5207 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5208 | final long identity = Binder.clearCallingIdentity(); |
| 5209 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5210 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5211 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5212 | if (DBG) { |
| 5213 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5214 | + " operator: " + operatorInfo); |
| 5215 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5216 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5217 | } finally { |
| 5218 | Binder.restoreCallingIdentity(identity); |
| 5219 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5220 | } |
| 5221 | |
| 5222 | /** |
| 5223 | * Scans for available networks. |
| 5224 | */ |
| 5225 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5226 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5227 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5228 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5229 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5230 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5231 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5232 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5233 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5234 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5235 | .setCallingPid(Binder.getCallingPid()) |
| 5236 | .setCallingUid(Binder.getCallingUid()) |
| 5237 | .setMethod("getCellNetworkScanResults") |
| 5238 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5239 | .build()); |
| 5240 | switch (locationResult) { |
| 5241 | case DENIED_HARD: |
| 5242 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5243 | case DENIED_SOFT: |
| 5244 | return null; |
| 5245 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5246 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5247 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5248 | try { |
| 5249 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5250 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5251 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5252 | } finally { |
| 5253 | Binder.restoreCallingIdentity(identity); |
| 5254 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5255 | } |
| 5256 | |
| 5257 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5258 | * Get the call forwarding info, given the call forwarding reason. |
| 5259 | */ |
| 5260 | @Override |
| 5261 | public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) { |
| 5262 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5263 | long identity = Binder.clearCallingIdentity(); |
| 5264 | try { |
| 5265 | if (DBG) { |
| 5266 | log("getCallForwarding: subId " + subId |
| 5267 | + " callForwardingReason" + callForwardingReason); |
| 5268 | } |
| 5269 | return (CallForwardingInfo) sendRequest( |
| 5270 | CMD_GET_CALL_FORWARDING, callForwardingReason, subId); |
| 5271 | } finally { |
| 5272 | Binder.restoreCallingIdentity(identity); |
| 5273 | } |
| 5274 | } |
| 5275 | |
| 5276 | /** |
| 5277 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5278 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5279 | */ |
| 5280 | @Override |
| 5281 | public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) { |
| 5282 | enforceModifyPermission(); |
| 5283 | long identity = Binder.clearCallingIdentity(); |
| 5284 | try { |
| 5285 | if (DBG) { |
| 5286 | log("setCallForwarding: subId " + subId |
| 5287 | + " callForwardingInfo" + callForwardingInfo); |
| 5288 | } |
| 5289 | return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId); |
| 5290 | } finally { |
| 5291 | Binder.restoreCallingIdentity(identity); |
| 5292 | } |
| 5293 | } |
| 5294 | |
| 5295 | /** |
| 5296 | * Get the call forwarding info, given the call forwarding reason. |
| 5297 | */ |
| 5298 | @Override |
| 5299 | public int getCallWaitingStatus(int subId) { |
| 5300 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5301 | long identity = Binder.clearCallingIdentity(); |
| 5302 | try { |
| 5303 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 5304 | return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId); |
| 5305 | } finally { |
| 5306 | Binder.restoreCallingIdentity(identity); |
| 5307 | } |
| 5308 | } |
| 5309 | |
| 5310 | /** |
| 5311 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5312 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5313 | */ |
| 5314 | @Override |
| 5315 | public boolean setCallWaitingStatus(int subId, boolean isEnable) { |
| 5316 | enforceModifyPermission(); |
| 5317 | long identity = Binder.clearCallingIdentity(); |
| 5318 | try { |
| 5319 | if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable); |
| 5320 | return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId); |
| 5321 | } finally { |
| 5322 | Binder.restoreCallingIdentity(identity); |
| 5323 | } |
| 5324 | } |
| 5325 | |
| 5326 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5327 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5328 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5329 | * @param subId id of the subscription |
| 5330 | * @param request contains the radio access networks with bands/channels to scan |
| 5331 | * @param messenger callback messenger for scan results or errors |
| 5332 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5333 | * @return the id of the requested scan which can be used to stop the scan. |
| 5334 | */ |
| 5335 | @Override |
| 5336 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5337 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5338 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5339 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5340 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5341 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5342 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5343 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5344 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5345 | .setCallingPid(Binder.getCallingPid()) |
| 5346 | .setCallingUid(Binder.getCallingUid()) |
| 5347 | .setMethod("requestNetworkScan") |
| 5348 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5349 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5350 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5351 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5352 | if (e != null) { |
| 5353 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5354 | throw e; |
| 5355 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5356 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5357 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5358 | } |
| 5359 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5360 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5361 | int callingUid = Binder.getCallingUid(); |
| 5362 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5363 | final long identity = Binder.clearCallingIdentity(); |
| 5364 | try { |
| 5365 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5366 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5367 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5368 | } finally { |
| 5369 | Binder.restoreCallingIdentity(identity); |
| 5370 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5371 | } |
| 5372 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5373 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5374 | NetworkScanRequest request, int subId) { |
| 5375 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5376 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5377 | boolean hasNetworkScanPermission = |
| 5378 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5379 | == PERMISSION_GRANTED; |
| 5380 | |
| 5381 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5382 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5383 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5384 | } |
| 5385 | |
| 5386 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5387 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5388 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5389 | return new SecurityException("Specific channels must not be" |
| 5390 | + " scanned without location access."); |
| 5391 | } |
| 5392 | } |
| 5393 | } |
| 5394 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5395 | return null; |
| 5396 | } |
| 5397 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5398 | /** |
| 5399 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5400 | * |
| 5401 | * @param subId id of the subscription |
| 5402 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5403 | */ |
| 5404 | @Override |
| 5405 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5406 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5407 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5408 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5409 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5410 | final long identity = Binder.clearCallingIdentity(); |
| 5411 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5412 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5413 | } finally { |
| 5414 | Binder.restoreCallingIdentity(identity); |
| 5415 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5416 | } |
| 5417 | |
| 5418 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5419 | * Get the calculated preferred network type. |
| 5420 | * Used for debugging incorrect network type. |
| 5421 | * |
| 5422 | * @return the preferred network type, defined in RILConstants.java. |
| 5423 | */ |
| 5424 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5425 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5426 | final Phone defaultPhone = getDefaultPhone(); |
| 5427 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5428 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5429 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5430 | } |
| 5431 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5432 | final long identity = Binder.clearCallingIdentity(); |
| 5433 | try { |
| 5434 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5435 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5436 | } finally { |
| 5437 | Binder.restoreCallingIdentity(identity); |
| 5438 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5439 | } |
| 5440 | |
| 5441 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5442 | * Get the preferred network type. |
| 5443 | * Used for device configuration by some CDMA operators. |
| 5444 | * |
| 5445 | * @return the preferred network type, defined in RILConstants.java. |
| 5446 | */ |
| 5447 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5448 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5449 | TelephonyPermissions |
| 5450 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5451 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5452 | |
| 5453 | final long identity = Binder.clearCallingIdentity(); |
| 5454 | try { |
| 5455 | if (DBG) log("getPreferredNetworkType"); |
| 5456 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5457 | int networkType = (result != null ? result[0] : -1); |
| 5458 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5459 | return networkType; |
| 5460 | } finally { |
| 5461 | Binder.restoreCallingIdentity(identity); |
| 5462 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5463 | } |
| 5464 | |
| 5465 | /** |
| 5466 | * Set the preferred network type. |
| 5467 | * Used for device configuration by some CDMA operators. |
| 5468 | * |
| 5469 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5470 | * @return true on success; false on any failure. |
| 5471 | */ |
| 5472 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5473 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5474 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5475 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5476 | |
| 5477 | final long identity = Binder.clearCallingIdentity(); |
| 5478 | try { |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5479 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5480 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5481 | return setPreferredNetworkTypesInternal(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5482 | } finally { |
| 5483 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5484 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5485 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5486 | |
| 5487 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5488 | * Get the allowed network types that store in the telephony provider. |
| 5489 | * |
| 5490 | * @param subId the id of the subscription. |
| 5491 | * @return allowedNetworkTypes the allowed network types. |
| 5492 | */ |
| 5493 | @Override |
| 5494 | public long getAllowedNetworkTypes(int subId) { |
| 5495 | TelephonyPermissions |
| 5496 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5497 | mApp, subId, "getAllowedNetworkTypes"); |
| 5498 | |
| 5499 | final long identity = Binder.clearCallingIdentity(); |
| 5500 | try { |
| 5501 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5502 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5503 | } finally { |
| 5504 | Binder.restoreCallingIdentity(identity); |
| 5505 | } |
| 5506 | } |
| 5507 | |
| 5508 | /** |
| 5509 | * Set the allowed network types. |
| 5510 | * |
| 5511 | * @param subId the id of the subscription. |
| 5512 | * @param allowedNetworkTypes the allowed network types. |
| 5513 | * @return true on success; false on any failure. |
| 5514 | */ |
| 5515 | @Override |
| 5516 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5517 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5518 | mApp, subId, "setAllowedNetworkTypes"); |
| 5519 | final long identity = Binder.clearCallingIdentity(); |
| 5520 | try { |
| 5521 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5522 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5523 | String.valueOf(allowedNetworkTypes)); |
| 5524 | return setPreferredNetworkTypesInternal(subId); |
| 5525 | } finally { |
| 5526 | Binder.restoreCallingIdentity(identity); |
| 5527 | } |
| 5528 | } |
| 5529 | |
| 5530 | private boolean setPreferredNetworkTypesInternal(int subId) { |
| 5531 | long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType( |
| 5532 | Settings.Global.getInt(mApp.getContentResolver(), |
| 5533 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5534 | RILConstants.PREFERRED_NETWORK_MODE)); |
| 5535 | long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty( |
| 5536 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5537 | int networkMode = RadioAccessFamily.getNetworkTypeFromRaf( |
| 5538 | (int) (networkTypeBitMask & allowedNetworkTypes)); |
| 5539 | |
| 5540 | if (DBG) { |
| 5541 | log("setPreferredNetworkTypesInternal: subId " + subId |
| 5542 | + " networkTypes " + networkTypeBitMask |
| 5543 | + " allowedNetworkTypes " + allowedNetworkTypes |
| 5544 | + " networkMode " + networkMode); |
| 5545 | } |
| 5546 | |
| 5547 | Boolean success = (Boolean) sendRequest( |
| 5548 | CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId); |
| 5549 | if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail")); |
| 5550 | return success; |
| 5551 | } |
| 5552 | |
| 5553 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5554 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5555 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5556 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5557 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5558 | * @hide |
| 5559 | */ |
| 5560 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5561 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5562 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5563 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5564 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5565 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5566 | if (phone != null) { |
| 5567 | return phone.hasMatchedTetherApnSetting(); |
| 5568 | } else { |
| 5569 | return false; |
| 5570 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5571 | } finally { |
| 5572 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5573 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5574 | } |
| 5575 | |
| 5576 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5577 | * Set mobile data enabled |
| 5578 | * Used by the user through settings etc to turn on/off mobile data |
| 5579 | * |
| 5580 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5581 | */ |
| 5582 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5583 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5584 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5585 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5586 | |
| 5587 | final long identity = Binder.clearCallingIdentity(); |
| 5588 | try { |
| 5589 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5590 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5591 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5592 | if (phone != null) { |
| 5593 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5594 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5595 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5596 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5597 | } |
| 5598 | } finally { |
| 5599 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5600 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5601 | } |
| 5602 | |
| 5603 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5604 | * Enable or disable always reporting signal strength changes from radio. |
| 5605 | * |
| 5606 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5607 | */ |
| 5608 | @Override |
| 5609 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5610 | enforceModifyPermission(); |
| 5611 | enforceSystemCaller(); |
| 5612 | |
| 5613 | final long identity = Binder.clearCallingIdentity(); |
| 5614 | final Phone phone = getPhone(subId); |
| 5615 | try { |
| 5616 | if (phone != null) { |
| 5617 | if (DBG) { |
| 5618 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5619 | + " isEnable=" + isEnable); |
| 5620 | } |
| 5621 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5622 | } else { |
| 5623 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5624 | + subId); |
| 5625 | } |
| 5626 | } finally { |
| 5627 | Binder.restoreCallingIdentity(identity); |
| 5628 | } |
| 5629 | } |
| 5630 | |
| 5631 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5632 | * Get the user enabled state of Mobile Data. |
| 5633 | * |
| 5634 | * TODO: remove and use isUserDataEnabled. |
| 5635 | * This can't be removed now because some vendor codes |
| 5636 | * calls through ITelephony directly while they should |
| 5637 | * use TelephonyManager. |
| 5638 | * |
| 5639 | * @return true on enabled |
| 5640 | */ |
| 5641 | @Override |
| 5642 | public boolean getDataEnabled(int subId) { |
| 5643 | return isUserDataEnabled(subId); |
| 5644 | } |
| 5645 | |
| 5646 | /** |
| 5647 | * Get whether mobile data is enabled per user setting. |
| 5648 | * |
| 5649 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5650 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5651 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5652 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5653 | * |
| 5654 | * @return {@code true} if data is enabled else {@code false} |
| 5655 | */ |
| 5656 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5657 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5658 | try { |
| 5659 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5660 | null); |
| 5661 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5662 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5663 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5664 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5665 | |
| 5666 | final long identity = Binder.clearCallingIdentity(); |
| 5667 | try { |
| 5668 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5669 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5670 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5671 | if (phone != null) { |
| 5672 | boolean retVal = phone.isUserDataEnabled(); |
| 5673 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5674 | return retVal; |
| 5675 | } else { |
| 5676 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5677 | return false; |
| 5678 | } |
| 5679 | } finally { |
| 5680 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5681 | } |
| 5682 | } |
| 5683 | |
| 5684 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5685 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5686 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5687 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5688 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5689 | * @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] | 5690 | */ |
| 5691 | @Override |
| 5692 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5693 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5694 | |
| 5695 | final long identity = Binder.clearCallingIdentity(); |
| 5696 | try { |
| 5697 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5698 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5699 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5700 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5701 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5702 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5703 | return retVal; |
| 5704 | } else { |
| 5705 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5706 | return false; |
| 5707 | } |
| 5708 | } finally { |
| 5709 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5710 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5711 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5712 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5713 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 5714 | Phone phone) { |
| 5715 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5716 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5717 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5718 | || subController == null) return privilegeFromSim; |
| 5719 | |
| 5720 | int uid = Binder.getCallingUid(); |
| 5721 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5722 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5723 | |
| 5724 | final long identity = Binder.clearCallingIdentity(); |
| 5725 | try { |
| 5726 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5727 | SubscriptionManager subManager = (SubscriptionManager) |
| 5728 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5729 | for (String pkg : packages) { |
| 5730 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5731 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5732 | } |
| 5733 | } |
| 5734 | return privilegeFromSim; |
| 5735 | } finally { |
| 5736 | Binder.restoreCallingIdentity(identity); |
| 5737 | } |
| 5738 | } |
| 5739 | |
| 5740 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5741 | String pkgName) { |
| 5742 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5743 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5744 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5745 | || subController == null) return privilegeFromSim; |
| 5746 | |
| 5747 | final long identity = Binder.clearCallingIdentity(); |
| 5748 | try { |
| 5749 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5750 | SubscriptionManager subManager = (SubscriptionManager) |
| 5751 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5752 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5753 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5754 | } finally { |
| 5755 | Binder.restoreCallingIdentity(identity); |
| 5756 | } |
| 5757 | } |
| 5758 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5759 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5760 | public int getCarrierPrivilegeStatus(int subId) { |
| 5761 | final Phone phone = getPhone(subId); |
| 5762 | if (phone == null) { |
| 5763 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5764 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5765 | } |
| 5766 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5767 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5768 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5769 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5770 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5771 | |
| 5772 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5773 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 5774 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5775 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5776 | |
| 5777 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5778 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5779 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5780 | final Phone phone = getPhone(subId); |
| 5781 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5782 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5783 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5784 | } |
| 5785 | UiccProfile profile = |
| 5786 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5787 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5788 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5789 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5790 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5791 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5792 | profile.getCarrierPrivilegeStatusForUid( |
| 5793 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5794 | } |
| 5795 | |
| 5796 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5797 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5798 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5799 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5800 | } |
| 5801 | |
| 5802 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5803 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5804 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5805 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5806 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5807 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5808 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5809 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5810 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5811 | } |
| 5812 | |
| 5813 | @Override |
| 5814 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5815 | if (TextUtils.isEmpty(pkgName)) |
| 5816 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5817 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5818 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5819 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5820 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5821 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5822 | continue; |
| 5823 | } |
| 5824 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5825 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5826 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5827 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5828 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5829 | break; |
| 5830 | } |
| 5831 | } |
| 5832 | |
| 5833 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5834 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5835 | |
| 5836 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5837 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5838 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5839 | loge("phoneId " + phoneId + " is not valid."); |
| 5840 | return null; |
| 5841 | } |
| 5842 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5843 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5844 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5845 | return null ; |
| 5846 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5847 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5848 | } |
| 5849 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5850 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5851 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5852 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5853 | List<String> privilegedPackages = new ArrayList<>(); |
| 5854 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5855 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5856 | // has UICC in that slot. |
| 5857 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5858 | if (card.hasCarrierPrivilegeRules()) { |
| 5859 | if (packages == null) { |
| 5860 | // Only check packages in user 0 for now |
| 5861 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5862 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5863 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5864 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5865 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5866 | } |
| 5867 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5868 | PackageInfo pkgInfo = packages.get(p); |
| 5869 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5870 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5871 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5872 | privilegedPackages.add(pkgInfo.packageName); |
| 5873 | } |
| 5874 | } |
| 5875 | } |
| 5876 | } |
| 5877 | return privilegedPackages; |
| 5878 | } |
| 5879 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5880 | @Override |
| 5881 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5882 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5883 | |
| 5884 | final long identity = Binder.clearCallingIdentity(); |
| 5885 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5886 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5887 | try { |
| 5888 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5889 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5890 | } |
| 5891 | } finally { |
| 5892 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5893 | } |
| 5894 | return privilegedPackages; |
| 5895 | } |
| 5896 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5897 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5898 | final Phone phone = getPhone(subId); |
| 5899 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5900 | if (card == null) { |
| 5901 | loge("getIccId: No UICC"); |
| 5902 | return null; |
| 5903 | } |
| 5904 | String iccId = card.getIccId(); |
| 5905 | if (TextUtils.isEmpty(iccId)) { |
| 5906 | loge("getIccId: ICC ID is null or empty."); |
| 5907 | return null; |
| 5908 | } |
| 5909 | return iccId; |
| 5910 | } |
| 5911 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5912 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5913 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5914 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5915 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5916 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5917 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5918 | final long identity = Binder.clearCallingIdentity(); |
| 5919 | try { |
| 5920 | final String iccId = getIccId(subId); |
| 5921 | final Phone phone = getPhone(subId); |
| 5922 | if (phone == null) { |
| 5923 | return false; |
| 5924 | } |
| 5925 | final String subscriberId = phone.getSubscriberId(); |
| 5926 | |
| 5927 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5928 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5929 | + subscriberId + " to " + number); |
| 5930 | } |
| 5931 | |
| 5932 | if (TextUtils.isEmpty(iccId)) { |
| 5933 | return false; |
| 5934 | } |
| 5935 | |
| 5936 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5937 | |
| 5938 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5939 | if (alphaTag == null) { |
| 5940 | editor.remove(alphaTagPrefKey); |
| 5941 | } else { |
| 5942 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5943 | } |
| 5944 | |
| 5945 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5946 | // track all merged IMSIs based on line number |
| 5947 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5948 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5949 | if (number == null) { |
| 5950 | editor.remove(numberPrefKey); |
| 5951 | editor.remove(subscriberPrefKey); |
| 5952 | } else { |
| 5953 | editor.putString(numberPrefKey, number); |
| 5954 | editor.putString(subscriberPrefKey, subscriberId); |
| 5955 | } |
| 5956 | |
| 5957 | editor.commit(); |
| 5958 | return true; |
| 5959 | } finally { |
| 5960 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5961 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5962 | } |
| 5963 | |
| 5964 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5965 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 5966 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5967 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5968 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5969 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5970 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5971 | return null; |
| 5972 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5973 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5974 | final long identity = Binder.clearCallingIdentity(); |
| 5975 | try { |
| 5976 | String iccId = getIccId(subId); |
| 5977 | if (iccId != null) { |
| 5978 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5979 | if (DBG_MERGE) { |
| 5980 | log("getLine1NumberForDisplay returning " |
| 5981 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5982 | } |
| 5983 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5984 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5985 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5986 | return null; |
| 5987 | } finally { |
| 5988 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5989 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5990 | } |
| 5991 | |
| 5992 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5993 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 5994 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5995 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5996 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5997 | return null; |
| 5998 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5999 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6000 | final long identity = Binder.clearCallingIdentity(); |
| 6001 | try { |
| 6002 | String iccId = getIccId(subId); |
| 6003 | if (iccId != null) { |
| 6004 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6005 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6006 | } |
| 6007 | return null; |
| 6008 | } finally { |
| 6009 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6010 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6011 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6012 | |
| 6013 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6014 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6015 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6016 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6017 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6018 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6019 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6020 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6021 | return null; |
| 6022 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6023 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6024 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6025 | // the process, where TelephonyManager was instantiated. |
| 6026 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6027 | final long identity = Binder.clearCallingIdentity(); |
| 6028 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6029 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6030 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6031 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6032 | |
| 6033 | // Figure out what subscribers are currently active |
| 6034 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6035 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6036 | // Only consider subs which match the current subId |
| 6037 | // This logic can be simplified. See b/131189269 for progress. |
| 6038 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6039 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6040 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6041 | |
| 6042 | // First pass, find a number override for an active subscriber |
| 6043 | String mergeNumber = null; |
| 6044 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6045 | for (String key : prefs.keySet()) { |
| 6046 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6047 | final String subscriberId = (String) prefs.get(key); |
| 6048 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6049 | final String iccId = key.substring( |
| 6050 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6051 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6052 | mergeNumber = (String) prefs.get(numberKey); |
| 6053 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6054 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6055 | + " for active subscriber " + subscriberId); |
| 6056 | } |
| 6057 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6058 | break; |
| 6059 | } |
| 6060 | } |
| 6061 | } |
| 6062 | } |
| 6063 | |
| 6064 | // Shortcut when no active merged subscribers |
| 6065 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6066 | return null; |
| 6067 | } |
| 6068 | |
| 6069 | // Second pass, find all subscribers under that line override |
| 6070 | final ArraySet<String> result = new ArraySet<>(); |
| 6071 | for (String key : prefs.keySet()) { |
| 6072 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6073 | final String number = (String) prefs.get(key); |
| 6074 | if (mergeNumber.equals(number)) { |
| 6075 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6076 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6077 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6078 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6079 | result.add(subscriberId); |
| 6080 | } |
| 6081 | } |
| 6082 | } |
| 6083 | } |
| 6084 | |
| 6085 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6086 | Arrays.sort(resultArray); |
| 6087 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6088 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6089 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6090 | } |
| 6091 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6092 | } finally { |
| 6093 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6094 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6095 | } |
| 6096 | |
| 6097 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6098 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 6099 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 6100 | |
| 6101 | final long identity = Binder.clearCallingIdentity(); |
| 6102 | try { |
| 6103 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6104 | TelephonyManager.class); |
| 6105 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6106 | if (subscriberId == null) { |
| 6107 | if (DBG) { |
| 6108 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 6109 | + subId); |
| 6110 | } |
| 6111 | return null; |
| 6112 | } |
| 6113 | |
| 6114 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6115 | .getSubscriptionInfo(subId); |
| 6116 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6117 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6118 | if (groupUuid == null) { |
| 6119 | return new String[]{subscriberId}; |
| 6120 | } |
| 6121 | |
| 6122 | // Get all subscriberIds from the group. |
| 6123 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6124 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6125 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 6126 | null); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6127 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6128 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6129 | if (subscriberId != null) { |
| 6130 | mergedSubscriberIds.add(subscriberId); |
| 6131 | } |
| 6132 | } |
| 6133 | |
| 6134 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6135 | } finally { |
| 6136 | Binder.restoreCallingIdentity(identity); |
| 6137 | |
| 6138 | } |
| 6139 | } |
| 6140 | |
| 6141 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6142 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6143 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6144 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6145 | |
| 6146 | final long identity = Binder.clearCallingIdentity(); |
| 6147 | try { |
| 6148 | final Phone phone = getPhone(subId); |
| 6149 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6150 | } finally { |
| 6151 | Binder.restoreCallingIdentity(identity); |
| 6152 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6153 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6154 | |
| 6155 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6156 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6157 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6158 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6159 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6160 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6161 | |
| 6162 | final long identity = Binder.clearCallingIdentity(); |
| 6163 | try { |
| 6164 | final Phone phone = getPhone(subId); |
| 6165 | if (phone == null) { |
| 6166 | return false; |
| 6167 | } |
| 6168 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6169 | cdmaNonRoamingList); |
| 6170 | } finally { |
| 6171 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6172 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6173 | } |
| 6174 | |
| 6175 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6176 | @Deprecated |
| 6177 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6178 | enforceModifyPermission(); |
| 6179 | |
| 6180 | int returnValue = 0; |
| 6181 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6182 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6183 | if(result.exception == null) { |
| 6184 | if (result.result != null) { |
| 6185 | byte[] responseData = (byte[])(result.result); |
| 6186 | if(responseData.length > oemResp.length) { |
| 6187 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6188 | responseData.length + "bytes. Buffer Size is " + |
| 6189 | oemResp.length + "bytes."); |
| 6190 | } |
| 6191 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6192 | returnValue = responseData.length; |
| 6193 | } |
| 6194 | } else { |
| 6195 | CommandException ex = (CommandException) result.exception; |
| 6196 | returnValue = ex.getCommandError().ordinal(); |
| 6197 | if(returnValue > 0) returnValue *= -1; |
| 6198 | } |
| 6199 | } catch (RuntimeException e) { |
| 6200 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6201 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6202 | if(returnValue > 0) returnValue *= -1; |
| 6203 | } |
| 6204 | |
| 6205 | return returnValue; |
| 6206 | } |
| 6207 | |
| 6208 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6209 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6210 | try { |
| 6211 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6212 | } catch (RuntimeException e) { |
| 6213 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6214 | } |
| 6215 | } |
| 6216 | |
| 6217 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6218 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6219 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6220 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6221 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6222 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6223 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6224 | final long identity = Binder.clearCallingIdentity(); |
| 6225 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6226 | TelephonyPermissions |
| 6227 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6228 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6229 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6230 | } finally { |
| 6231 | Binder.restoreCallingIdentity(identity); |
| 6232 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6233 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6234 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6235 | |
| 6236 | @Override |
| 6237 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6238 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6239 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6240 | |
| 6241 | final long identity = Binder.clearCallingIdentity(); |
| 6242 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6243 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6244 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6245 | } finally { |
| 6246 | Binder.restoreCallingIdentity(identity); |
| 6247 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6248 | } |
| 6249 | |
| 6250 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6251 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6252 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6253 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6254 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6255 | return false; |
| 6256 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6257 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6258 | final long identity = Binder.clearCallingIdentity(); |
| 6259 | try { |
| 6260 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6261 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6262 | // In the long run, we may instead need to check if there exists a connection service |
| 6263 | // which can support video calling. |
| 6264 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6265 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6266 | return imsManager.isVtEnabledByPlatform() |
| 6267 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6268 | && imsManager.isVtEnabledByUser(); |
| 6269 | } finally { |
| 6270 | Binder.restoreCallingIdentity(identity); |
| 6271 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6272 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6273 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6274 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6275 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6276 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6277 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6278 | mApp, subId, callingPackage, callingFeatureId, |
| 6279 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6280 | return false; |
| 6281 | } |
| 6282 | |
| 6283 | final long identity = Binder.clearCallingIdentity(); |
| 6284 | try { |
| 6285 | CarrierConfigManager configManager = |
| 6286 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6287 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6288 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6289 | } finally { |
| 6290 | Binder.restoreCallingIdentity(identity); |
| 6291 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6292 | } |
| 6293 | |
| 6294 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6295 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6296 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6297 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6298 | return false; |
| 6299 | } |
| 6300 | |
| 6301 | final long identity = Binder.clearCallingIdentity(); |
| 6302 | try { |
| 6303 | CarrierConfigManager configManager = |
| 6304 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6305 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6306 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6307 | } finally { |
| 6308 | Binder.restoreCallingIdentity(identity); |
| 6309 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6310 | } |
| 6311 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6312 | @Override |
| 6313 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6314 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6315 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6316 | } |
| 6317 | |
| 6318 | @Override |
| 6319 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6320 | final long identity = Binder.clearCallingIdentity(); |
| 6321 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6322 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6323 | } finally { |
| 6324 | Binder.restoreCallingIdentity(identity); |
| 6325 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6326 | } |
| 6327 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6328 | /** |
| 6329 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6330 | * support for the feature and device firmware support. |
| 6331 | * |
| 6332 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6333 | */ |
| 6334 | @Override |
| 6335 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6336 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6337 | final Phone phone = getPhone(subscriptionId); |
| 6338 | if (phone == null) { |
| 6339 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6340 | return false; |
| 6341 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6342 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6343 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6344 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6345 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6346 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6347 | return isCarrierSupported && isDeviceSupported; |
| 6348 | } finally { |
| 6349 | Binder.restoreCallingIdentity(identity); |
| 6350 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6351 | } |
| 6352 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6353 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6354 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6355 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6356 | * 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] | 6357 | */ |
| 6358 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6359 | final long identity = Binder.clearCallingIdentity(); |
| 6360 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6361 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6362 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6363 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6364 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6365 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6366 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6367 | } finally { |
| 6368 | Binder.restoreCallingIdentity(identity); |
| 6369 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6370 | } |
| 6371 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6372 | @Deprecated |
| 6373 | @Override |
| 6374 | public String getDeviceId(String callingPackage) { |
| 6375 | return getDeviceIdWithFeature(callingPackage, null); |
| 6376 | } |
| 6377 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6378 | /** |
| 6379 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6380 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6381 | * |
| 6382 | * <p>Requires Permission: |
| 6383 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6384 | */ |
| 6385 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6386 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6387 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6388 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6389 | return null; |
| 6390 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6391 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6392 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6393 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6394 | return null; |
| 6395 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6396 | |
| 6397 | final long identity = Binder.clearCallingIdentity(); |
| 6398 | try { |
| 6399 | return phone.getDeviceId(); |
| 6400 | } finally { |
| 6401 | Binder.restoreCallingIdentity(identity); |
| 6402 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6403 | } |
| 6404 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6405 | /** |
| 6406 | * {@hide} |
| 6407 | * Returns the IMS Registration Status on a particular subid |
| 6408 | * |
| 6409 | * @param subId |
| 6410 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6411 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6412 | Phone phone = getPhone(subId); |
| 6413 | if (phone != null) { |
| 6414 | return phone.isImsRegistered(); |
| 6415 | } else { |
| 6416 | return false; |
| 6417 | } |
| 6418 | } |
| 6419 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6420 | @Override |
| 6421 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6422 | final long identity = Binder.clearCallingIdentity(); |
| 6423 | try { |
| 6424 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6425 | } finally { |
| 6426 | Binder.restoreCallingIdentity(identity); |
| 6427 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6428 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6429 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6430 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6431 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6432 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6433 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6434 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6435 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6436 | } |
| 6437 | final long identity = Binder.clearCallingIdentity(); |
| 6438 | try { |
| 6439 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6440 | } finally { |
| 6441 | Binder.restoreCallingIdentity(identity); |
| 6442 | } |
| 6443 | } |
| 6444 | |
| 6445 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6446 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6447 | final long identity = Binder.clearCallingIdentity(); |
| 6448 | try { |
| 6449 | Phone phone = getPhone(subscriptionId); |
| 6450 | if (phone == null) { |
| 6451 | return null; |
| 6452 | } |
| 6453 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6454 | } finally { |
| 6455 | Binder.restoreCallingIdentity(identity); |
| 6456 | } |
| 6457 | } |
| 6458 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6459 | /** |
| 6460 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6461 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6462 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6463 | final long identity = Binder.clearCallingIdentity(); |
| 6464 | try { |
| 6465 | Phone phone = getPhone(subId); |
| 6466 | if (phone != null) { |
| 6467 | return phone.isWifiCallingEnabled(); |
| 6468 | } else { |
| 6469 | return false; |
| 6470 | } |
| 6471 | } finally { |
| 6472 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6473 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6474 | } |
| 6475 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6476 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6477 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6478 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6479 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6480 | final long identity = Binder.clearCallingIdentity(); |
| 6481 | try { |
| 6482 | Phone phone = getPhone(subId); |
| 6483 | if (phone != null) { |
| 6484 | return phone.isVideoEnabled(); |
| 6485 | } else { |
| 6486 | return false; |
| 6487 | } |
| 6488 | } finally { |
| 6489 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6490 | } |
| 6491 | } |
| 6492 | |
| 6493 | /** |
| 6494 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6495 | * defined in {@link ImsRegistrationImplBase}. |
| 6496 | */ |
| 6497 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6498 | final long identity = Binder.clearCallingIdentity(); |
| 6499 | try { |
| 6500 | Phone phone = getPhone(subId); |
| 6501 | if (phone != null) { |
| 6502 | return phone.getImsRegistrationTech(); |
| 6503 | } else { |
| 6504 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6505 | } |
| 6506 | } finally { |
| 6507 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6508 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6509 | } |
| 6510 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6511 | @Override |
| 6512 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6513 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6514 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6515 | return; |
| 6516 | } |
| 6517 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6518 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6519 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6520 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6521 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6522 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6523 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6524 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6525 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6526 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6527 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6528 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6529 | // There has been issues when Sms raw table somehow stores orphan |
| 6530 | // fragments. They lead to garbled message when new fragments come |
| 6531 | // in and combined with those stale ones. In case this happens again, |
| 6532 | // user can reset all network settings which will clean up this table. |
| 6533 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6534 | // Clean up IMS settings as well here. |
| 6535 | int slotId = getSlotIndex(subId); |
| 6536 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6537 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6538 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6539 | |
| 6540 | // Erase modem config if erase modem on network setting is enabled. |
| 6541 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6542 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6543 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6544 | sendEraseModemConfig(getDefaultPhone()); |
| 6545 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6546 | } finally { |
| 6547 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6548 | } |
| 6549 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6550 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6551 | private void cleanUpSmsRawTable(Context context) { |
| 6552 | ContentResolver resolver = context.getContentResolver(); |
| 6553 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6554 | resolver.delete(uri, null, null); |
| 6555 | } |
| 6556 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6557 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6558 | public String getSimLocaleForSubscriber(int subId) { |
| 6559 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6560 | final Phone phone = getPhone(subId); |
| 6561 | if (phone == null) { |
| 6562 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6563 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6564 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6565 | final long identity = Binder.clearCallingIdentity(); |
| 6566 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6567 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6568 | phone.getContext().getOpPackageName(), null); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6569 | if (info == null) { |
| 6570 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6571 | return null; |
| 6572 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6573 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6574 | // preferences (EF-PL and EF-LI)... |
| 6575 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6576 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6577 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6578 | if (localeFromDefaultSim != null) { |
| 6579 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6580 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6581 | + localeFromDefaultSim); |
| 6582 | return localeFromDefaultSim.toLanguageTag(); |
| 6583 | } else { |
| 6584 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6585 | } |
| 6586 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6587 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6588 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6589 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6590 | // the SIM and carrier preferences does not include a country we add the country |
| 6591 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6592 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6593 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6594 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6595 | return mccLocale.toLanguageTag(); |
| 6596 | } |
| 6597 | |
| 6598 | if (DBG) log("No locale found - returning null"); |
| 6599 | return null; |
| 6600 | } finally { |
| 6601 | Binder.restoreCallingIdentity(identity); |
| 6602 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6603 | } |
| 6604 | |
| 6605 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6606 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 6607 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6608 | } |
| 6609 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6610 | /** |
| 6611 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6612 | */ |
| 6613 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6614 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 6615 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6616 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6617 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6618 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6619 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6620 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6621 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6622 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6623 | * representing the state of the modem. |
| 6624 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6625 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6626 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6627 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6628 | */ |
| 6629 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6630 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6631 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6632 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6633 | |
| 6634 | final long identity = Binder.clearCallingIdentity(); |
| 6635 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 6636 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6637 | } finally { |
| 6638 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6639 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6640 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6641 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6642 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6643 | // less than total activity duration. |
| 6644 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6645 | if (info == null) { |
| 6646 | return false; |
| 6647 | } |
| 6648 | int activityDurationMs = |
| 6649 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6650 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6651 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6652 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6653 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6654 | } |
| 6655 | return (info.isValid() |
| 6656 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6657 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6658 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6659 | && (totalTxTimeMs <= activityDurationMs)); |
| 6660 | } |
| 6661 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6662 | /** |
| 6663 | * {@hide} |
| 6664 | * Returns the service state information on specified subscription. |
| 6665 | */ |
| 6666 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6667 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6668 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6669 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6670 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6671 | return null; |
| 6672 | } |
| 6673 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6674 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6675 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6676 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6677 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6678 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6679 | .setCallingPid(Binder.getCallingPid()) |
| 6680 | .setCallingUid(Binder.getCallingUid()) |
| 6681 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6682 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6683 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6684 | .build()); |
| 6685 | |
| 6686 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6687 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6688 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6689 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6690 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6691 | .setCallingPid(Binder.getCallingPid()) |
| 6692 | .setCallingUid(Binder.getCallingUid()) |
| 6693 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6694 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6695 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6696 | .build()); |
| 6697 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6698 | boolean hasFinePermission = |
| 6699 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6700 | boolean hasCoarsePermission = |
| 6701 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6702 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6703 | final long identity = Binder.clearCallingIdentity(); |
| 6704 | try { |
| 6705 | final Phone phone = getPhone(subId); |
| 6706 | if (phone == null) { |
| 6707 | return null; |
| 6708 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6709 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6710 | ServiceState ss = phone.getServiceState(); |
| 6711 | |
| 6712 | // Scrub out the location info in ServiceState depending on what level of access |
| 6713 | // the caller has. |
| 6714 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6715 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6716 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6717 | } finally { |
| 6718 | Binder.restoreCallingIdentity(identity); |
| 6719 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6720 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6721 | |
| 6722 | /** |
| 6723 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6724 | * |
| 6725 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6726 | * voicemail ringtone. |
| 6727 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6728 | * PhoneAccount. |
| 6729 | */ |
| 6730 | @Override |
| 6731 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6732 | final long identity = Binder.clearCallingIdentity(); |
| 6733 | try { |
| 6734 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6735 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6736 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6737 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6738 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6739 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6740 | } finally { |
| 6741 | Binder.restoreCallingIdentity(identity); |
| 6742 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6743 | } |
| 6744 | |
| 6745 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6746 | * Sets the per-account voicemail ringtone. |
| 6747 | * |
| 6748 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6749 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6750 | * |
| 6751 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6752 | * voicemail ringtone. |
| 6753 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6754 | * PhoneAccount. |
| 6755 | */ |
| 6756 | @Override |
| 6757 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6758 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6759 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6760 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6761 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6762 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6763 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6764 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6765 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6766 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6767 | |
| 6768 | final long identity = Binder.clearCallingIdentity(); |
| 6769 | try { |
| 6770 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6771 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6772 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6773 | } |
| 6774 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6775 | } finally { |
| 6776 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6777 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6778 | } |
| 6779 | |
| 6780 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6781 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6782 | * |
| 6783 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6784 | * voicemail vibration setting. |
| 6785 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6786 | */ |
| 6787 | @Override |
| 6788 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6789 | final long identity = Binder.clearCallingIdentity(); |
| 6790 | try { |
| 6791 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6792 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6793 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6794 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6795 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6796 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6797 | } finally { |
| 6798 | Binder.restoreCallingIdentity(identity); |
| 6799 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6800 | } |
| 6801 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6802 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6803 | * Sets the per-account voicemail vibration. |
| 6804 | * |
| 6805 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6806 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6807 | * |
| 6808 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6809 | * voicemail vibration setting. |
| 6810 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6811 | * specific PhoneAccount. |
| 6812 | */ |
| 6813 | @Override |
| 6814 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6815 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6816 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6817 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6818 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6819 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6820 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6821 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6822 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6823 | } |
| 6824 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6825 | final long identity = Binder.clearCallingIdentity(); |
| 6826 | try { |
| 6827 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6828 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6829 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6830 | } |
| 6831 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6832 | } finally { |
| 6833 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6834 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6835 | } |
| 6836 | |
| 6837 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6838 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6839 | * |
| 6840 | * @throws SecurityException if the caller does not have the required permission |
| 6841 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6842 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6843 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6844 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6845 | } |
| 6846 | |
| 6847 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6848 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6849 | * permission. |
| 6850 | * |
| 6851 | * @throws SecurityException if the caller does not have the required permission |
| 6852 | */ |
| 6853 | private void enforceSendSmsPermission() { |
| 6854 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6855 | } |
| 6856 | |
| 6857 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6858 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6859 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6860 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6861 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6862 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6863 | final long identity = Binder.clearCallingIdentity(); |
| 6864 | try { |
| 6865 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6866 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6867 | if (componentName == null) { |
| 6868 | throw new SecurityException( |
| 6869 | "Caller not current active visual voicemail package[null]"); |
| 6870 | } |
| 6871 | String vvmPackage = componentName.getPackageName(); |
| 6872 | if (!callingPackage.equals(vvmPackage)) { |
| 6873 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6874 | + vvmPackage + "]"); |
| 6875 | } |
| 6876 | } finally { |
| 6877 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6878 | } |
| 6879 | } |
| 6880 | |
| 6881 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6882 | * Return the application ID for the app type. |
| 6883 | * |
| 6884 | * @param subId the subscription ID that this request applies to. |
| 6885 | * @param appType the uicc app type. |
| 6886 | * @return Application ID for specificied app type, or null if no uicc. |
| 6887 | */ |
| 6888 | @Override |
| 6889 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6890 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6891 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6892 | |
| 6893 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6894 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6895 | if (phone == null) { |
| 6896 | return null; |
| 6897 | } |
| 6898 | String aid = null; |
| 6899 | try { |
| 6900 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6901 | .getApplicationByType(appType).getAid(); |
| 6902 | } catch (Exception e) { |
| 6903 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6904 | } |
| 6905 | return aid; |
| 6906 | } finally { |
| 6907 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6908 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6909 | } |
| 6910 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6911 | /** |
| 6912 | * Return the Electronic Serial Number. |
| 6913 | * |
| 6914 | * @param subId the subscription ID that this request applies to. |
| 6915 | * @return ESN or null if error. |
| 6916 | */ |
| 6917 | @Override |
| 6918 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6919 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6920 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6921 | |
| 6922 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6923 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6924 | if (phone == null) { |
| 6925 | return null; |
| 6926 | } |
| 6927 | String esn = null; |
| 6928 | try { |
| 6929 | esn = phone.getEsn(); |
| 6930 | } catch (Exception e) { |
| 6931 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6932 | } |
| 6933 | return esn; |
| 6934 | } finally { |
| 6935 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6936 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6937 | } |
| 6938 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6939 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6940 | * Return the Preferred Roaming List Version. |
| 6941 | * |
| 6942 | * @param subId the subscription ID that this request applies to. |
| 6943 | * @return PRLVersion or null if error. |
| 6944 | */ |
| 6945 | @Override |
| 6946 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6947 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6948 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6949 | |
| 6950 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6951 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6952 | if (phone == null) { |
| 6953 | return null; |
| 6954 | } |
| 6955 | String cdmaPrlVersion = null; |
| 6956 | try { |
| 6957 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6958 | } catch (Exception e) { |
| 6959 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6960 | } |
| 6961 | return cdmaPrlVersion; |
| 6962 | } finally { |
| 6963 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6964 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6965 | } |
| 6966 | |
| 6967 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6968 | * Get snapshot of Telephony histograms |
| 6969 | * @return List of Telephony histograms |
| 6970 | * @hide |
| 6971 | */ |
| 6972 | @Override |
| 6973 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6974 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6975 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6976 | |
| 6977 | final long identity = Binder.clearCallingIdentity(); |
| 6978 | try { |
| 6979 | return RIL.getTelephonyRILTimingHistograms(); |
| 6980 | } finally { |
| 6981 | Binder.restoreCallingIdentity(identity); |
| 6982 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6983 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6984 | |
| 6985 | /** |
| 6986 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6987 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6988 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6989 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6990 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6991 | * @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] | 6992 | */ |
| 6993 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6994 | @TelephonyManager.SetCarrierRestrictionResult |
| 6995 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6996 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6997 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6998 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6999 | if (carrierRestrictionRules == null) { |
| 7000 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7001 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7002 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7003 | final long identity = Binder.clearCallingIdentity(); |
| 7004 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7005 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7006 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7007 | } finally { |
| 7008 | Binder.restoreCallingIdentity(identity); |
| 7009 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7010 | } |
| 7011 | |
| 7012 | /** |
| 7013 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7014 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7015 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7016 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7017 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7018 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7019 | */ |
| 7020 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7021 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7022 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7023 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7024 | |
| 7025 | final long identity = Binder.clearCallingIdentity(); |
| 7026 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7027 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7028 | if (response instanceof CarrierRestrictionRules) { |
| 7029 | return (CarrierRestrictionRules) response; |
| 7030 | } |
| 7031 | // Response is an Exception of some kind, |
| 7032 | // which is signalled to the user as a NULL retval |
| 7033 | return null; |
| 7034 | } catch (Exception e) { |
| 7035 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7036 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7037 | } finally { |
| 7038 | Binder.restoreCallingIdentity(identity); |
| 7039 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7040 | } |
| 7041 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7042 | /** |
| 7043 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 7044 | * @param subId the subscription ID that this action applies to. |
| 7045 | * @param enabled control enable or disable metered apns. |
| 7046 | * {@hide} |
| 7047 | */ |
| 7048 | @Override |
| 7049 | public void carrierActionSetMeteredApnsEnabled(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: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 7056 | return; |
| 7057 | } |
| 7058 | try { |
| 7059 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7060 | } catch (Exception e) { |
| 7061 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled 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 | |
| 7067 | /** |
| 7068 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7069 | * @param subId the subscription ID that this action applies to. |
| 7070 | * @param enabled control enable or disable radio. |
| 7071 | * {@hide} |
| 7072 | */ |
| 7073 | @Override |
| 7074 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7075 | enforceModifyPermission(); |
| 7076 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7077 | |
| 7078 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7079 | if (phone == null) { |
| 7080 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7081 | return; |
| 7082 | } |
| 7083 | try { |
| 7084 | phone.carrierActionSetRadioEnabled(enabled); |
| 7085 | } catch (Exception e) { |
| 7086 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7087 | } finally { |
| 7088 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7089 | } |
| 7090 | } |
| 7091 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7092 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7093 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7094 | * network status based on which carrier apps could apply actions accordingly, |
| 7095 | * enable/disable default url handler for example. |
| 7096 | * |
| 7097 | * @param subId the subscription ID that this action applies to. |
| 7098 | * @param report control start/stop reporting the default network status. |
| 7099 | * {@hide} |
| 7100 | */ |
| 7101 | @Override |
| 7102 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7103 | enforceModifyPermission(); |
| 7104 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7105 | |
| 7106 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7107 | if (phone == null) { |
| 7108 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7109 | return; |
| 7110 | } |
| 7111 | try { |
| 7112 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7113 | } catch (Exception e) { |
| 7114 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7115 | } finally { |
| 7116 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7117 | } |
| 7118 | } |
| 7119 | |
| 7120 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7121 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7122 | * @param subId the subscription ID that this action applies to. |
| 7123 | * {@hide} |
| 7124 | */ |
| 7125 | @Override |
| 7126 | public void carrierActionResetAll(int subId) { |
| 7127 | enforceModifyPermission(); |
| 7128 | final Phone phone = getPhone(subId); |
| 7129 | if (phone == null) { |
| 7130 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7131 | return; |
| 7132 | } |
| 7133 | try { |
| 7134 | phone.carrierActionResetAll(); |
| 7135 | } catch (Exception e) { |
| 7136 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7137 | } |
| 7138 | } |
| 7139 | |
| 7140 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7141 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7142 | * bug report is being generated. |
| 7143 | */ |
| 7144 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7145 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7146 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7147 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7148 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7149 | + Binder.getCallingPid() |
| 7150 | + ", uid=" + Binder.getCallingUid() |
| 7151 | + "without permission " |
| 7152 | + android.Manifest.permission.DUMP); |
| 7153 | return; |
| 7154 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7155 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7156 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7157 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7158 | @Override |
| 7159 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 7160 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 7161 | throws RemoteException { |
Torbjorn Eklund | 1050cb0 | 2018-11-16 14:05:38 +0100 | [diff] [blame] | 7162 | (new TelephonyShellCommand(this, getDefaultPhone().getContext())) |
| 7163 | .exec(this, in, out, err, args, callback, resultReceiver); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7164 | } |
| 7165 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7166 | /** |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7167 | * Policy control of data connection. Usually used when data limit is passed. |
| 7168 | * @param enabled True if enabling the data, otherwise disabling. |
| 7169 | * @param subId Subscription index |
| 7170 | * {@hide} |
| 7171 | */ |
| 7172 | @Override |
| 7173 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 7174 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7175 | |
| 7176 | final long identity = Binder.clearCallingIdentity(); |
| 7177 | try { |
| 7178 | Phone phone = getPhone(subId); |
| 7179 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 7180 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7181 | } |
| 7182 | } finally { |
| 7183 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7184 | } |
| 7185 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7186 | |
| 7187 | /** |
| 7188 | * Get Client request stats |
| 7189 | * @return List of Client Request Stats |
| 7190 | * @hide |
| 7191 | */ |
| 7192 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7193 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7194 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7195 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7196 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7197 | return null; |
| 7198 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7199 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7200 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7201 | final long identity = Binder.clearCallingIdentity(); |
| 7202 | try { |
| 7203 | if (phone != null) { |
| 7204 | return phone.getClientRequestStats(); |
| 7205 | } |
| 7206 | |
| 7207 | return null; |
| 7208 | } finally { |
| 7209 | Binder.restoreCallingIdentity(identity); |
| 7210 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7211 | } |
| 7212 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7213 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7214 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7215 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7216 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7217 | |
| 7218 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7219 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7220 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7221 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7222 | * @param state State of SIM (power down, power up, pass through) |
| 7223 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7224 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7225 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7226 | * |
| 7227 | **/ |
| 7228 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7229 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7230 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7231 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7232 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7233 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7234 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7235 | final long identity = Binder.clearCallingIdentity(); |
| 7236 | try { |
| 7237 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7238 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7239 | } |
| 7240 | } finally { |
| 7241 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7242 | } |
| 7243 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7244 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7245 | private boolean isUssdApiAllowed(int subId) { |
| 7246 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7247 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7248 | if (configManager == null) { |
| 7249 | return false; |
| 7250 | } |
| 7251 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7252 | if (pb == null) { |
| 7253 | return false; |
| 7254 | } |
| 7255 | return pb.getBoolean( |
| 7256 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7257 | } |
| 7258 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7259 | /** |
| 7260 | * Check if phone is in emergency callback mode |
| 7261 | * @return true if phone is in emergency callback mode |
| 7262 | * @param subId sub id |
| 7263 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7264 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7265 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7266 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7267 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7268 | |
| 7269 | final long identity = Binder.clearCallingIdentity(); |
| 7270 | try { |
| 7271 | if (phone != null) { |
| 7272 | return phone.isInEcm(); |
| 7273 | } else { |
| 7274 | return false; |
| 7275 | } |
| 7276 | } finally { |
| 7277 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7278 | } |
| 7279 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7280 | |
| 7281 | /** |
| 7282 | * Get the current signal strength information for the given subscription. |
| 7283 | * Because this information is not updated when the device is in a low power state |
| 7284 | * it should not be relied-upon to be current. |
| 7285 | * @param subId Subscription index |
| 7286 | * @return the most recent cached signal strength info from the modem |
| 7287 | */ |
| 7288 | @Override |
| 7289 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7290 | final long identity = Binder.clearCallingIdentity(); |
| 7291 | try { |
| 7292 | Phone p = getPhone(subId); |
| 7293 | if (p == null) { |
| 7294 | return null; |
| 7295 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7296 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7297 | return p.getSignalStrength(); |
| 7298 | } finally { |
| 7299 | Binder.restoreCallingIdentity(identity); |
| 7300 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7301 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7302 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7303 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7304 | * Get the current modem radio state for the given slot. |
| 7305 | * @param slotIndex slot index. |
| 7306 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7307 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7308 | * @return the current radio power state from the modem |
| 7309 | */ |
| 7310 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7311 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7312 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7313 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7314 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7315 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7316 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7317 | } |
| 7318 | |
| 7319 | final long identity = Binder.clearCallingIdentity(); |
| 7320 | try { |
| 7321 | return phone.getRadioPowerState(); |
| 7322 | } finally { |
| 7323 | Binder.restoreCallingIdentity(identity); |
| 7324 | } |
| 7325 | } |
| 7326 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7327 | } |
| 7328 | |
| 7329 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7330 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7331 | * |
| 7332 | * <p>Requires one of the following permissions: |
| 7333 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7334 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7335 | * privileges. |
| 7336 | * |
| 7337 | * @param subId subscription id |
| 7338 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7339 | * {@code false}. |
| 7340 | */ |
| 7341 | @Override |
| 7342 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7343 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7344 | null /* message */); |
| 7345 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7346 | boolean isEnabled = false; |
| 7347 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7348 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7349 | Phone phone = getPhone(subId); |
| 7350 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7351 | } catch (Exception e) { |
| 7352 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7353 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7354 | } finally { |
| 7355 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7356 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7357 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7358 | } |
| 7359 | |
| 7360 | |
| 7361 | /** |
| 7362 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7363 | * |
| 7364 | * <p> Requires permission: |
| 7365 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7366 | * privileges. |
| 7367 | * |
| 7368 | * @param subId subscription id |
| 7369 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7370 | */ |
| 7371 | @Override |
| 7372 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7373 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7374 | mApp, subId, "setDataRoamingEnabled"); |
| 7375 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7376 | final long identity = Binder.clearCallingIdentity(); |
| 7377 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7378 | Phone phone = getPhone(subId); |
| 7379 | if (phone != null) { |
| 7380 | phone.setDataRoamingEnabled(isEnabled); |
| 7381 | } |
| 7382 | } finally { |
| 7383 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7384 | } |
| 7385 | } |
| 7386 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7387 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7388 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7389 | TelephonyPermissions |
| 7390 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7391 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7392 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7393 | boolean isAllowed = true; |
| 7394 | final long identity = Binder.clearCallingIdentity(); |
| 7395 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7396 | Phone phone = getPhone(subId); |
| 7397 | if (phone != null) { |
| 7398 | isAllowed = phone.isCspPlmnEnabled(); |
| 7399 | } |
| 7400 | } finally { |
| 7401 | Binder.restoreCallingIdentity(identity); |
| 7402 | } |
| 7403 | return isAllowed; |
| 7404 | } |
| 7405 | |
| 7406 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7407 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7408 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7409 | try { |
| 7410 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7411 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7412 | } catch (SecurityException e) { |
| 7413 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7414 | // has carrier privileges on an active UICC |
| 7415 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7416 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7417 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7418 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7419 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7420 | |
| 7421 | final long identity = Binder.clearCallingIdentity(); |
| 7422 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7423 | UiccController uiccController = UiccController.getInstance(); |
| 7424 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7425 | if (hasReadPermission) { |
| 7426 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7427 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7428 | |
| 7429 | // Remove private info if the caller doesn't have access |
| 7430 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7431 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7432 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7433 | // is available |
| 7434 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7435 | if (card == null || card.getUiccProfile() == null) { |
| 7436 | // assume no access if the card or profile is unavailable |
| 7437 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7438 | continue; |
| 7439 | } |
| 7440 | UiccProfile profile = card.getUiccProfile(); |
| 7441 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7442 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7443 | filteredInfos.add(cardInfo); |
| 7444 | } else { |
| 7445 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7446 | } |
| 7447 | } |
| 7448 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7449 | } finally { |
| 7450 | Binder.restoreCallingIdentity(identity); |
| 7451 | } |
| 7452 | } |
| 7453 | |
| 7454 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7455 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7456 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7457 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7458 | final long identity = Binder.clearCallingIdentity(); |
| 7459 | try { |
| 7460 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7461 | if (slots == null) { |
| 7462 | Rlog.i(LOG_TAG, "slots is null."); |
| 7463 | return null; |
| 7464 | } |
| 7465 | |
| 7466 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7467 | for (int i = 0; i < slots.length; i++) { |
| 7468 | UiccSlot slot = slots[i]; |
| 7469 | if (slot == null) { |
| 7470 | continue; |
| 7471 | } |
| 7472 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7473 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7474 | UiccCard card = slot.getUiccCard(); |
| 7475 | if (card != null) { |
| 7476 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7477 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7478 | cardId = slot.getEid(); |
| 7479 | if (TextUtils.isEmpty(cardId)) { |
| 7480 | cardId = slot.getIccId(); |
| 7481 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7482 | } |
| 7483 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7484 | if (cardId != null) { |
| 7485 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7486 | // if cardId is an EID, it's all digits so this is fine |
| 7487 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7488 | } |
| 7489 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7490 | int cardState = 0; |
| 7491 | switch (slot.getCardState()) { |
| 7492 | case CARDSTATE_ABSENT: |
| 7493 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7494 | break; |
| 7495 | case CARDSTATE_PRESENT: |
| 7496 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7497 | break; |
| 7498 | case CARDSTATE_ERROR: |
| 7499 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7500 | break; |
| 7501 | case CARDSTATE_RESTRICTED: |
| 7502 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7503 | break; |
| 7504 | default: |
| 7505 | break; |
| 7506 | |
| 7507 | } |
| 7508 | |
| 7509 | infos[i] = new UiccSlotInfo( |
| 7510 | slot.isActive(), |
| 7511 | slot.isEuicc(), |
| 7512 | cardId, |
| 7513 | cardState, |
| 7514 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7515 | slot.isExtendedApduSupported(), |
| 7516 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7517 | } |
| 7518 | return infos; |
| 7519 | } finally { |
| 7520 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7521 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7522 | } |
| 7523 | |
| 7524 | @Override |
| 7525 | public boolean switchSlots(int[] physicalSlots) { |
| 7526 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7527 | |
| 7528 | final long identity = Binder.clearCallingIdentity(); |
| 7529 | try { |
| 7530 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7531 | } finally { |
| 7532 | Binder.restoreCallingIdentity(identity); |
| 7533 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7534 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7535 | |
| 7536 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7537 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7538 | final long identity = Binder.clearCallingIdentity(); |
| 7539 | try { |
| 7540 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7541 | } finally { |
| 7542 | Binder.restoreCallingIdentity(identity); |
| 7543 | } |
| 7544 | } |
| 7545 | |
| 7546 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7547 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 7548 | enforceModifyPermission(); |
| 7549 | final Phone phone = getPhone(subId); |
| 7550 | if (phone == null) { |
| 7551 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 7552 | return; |
| 7553 | } |
| 7554 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7555 | final long identity = Binder.clearCallingIdentity(); |
| 7556 | try { |
| 7557 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 7558 | } finally { |
| 7559 | Binder.restoreCallingIdentity(identity); |
| 7560 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7561 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7562 | |
| 7563 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7564 | * A test API to reload the UICC profile. |
| 7565 | * |
| 7566 | * <p>Requires that the calling app has permission |
| 7567 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7568 | * @hide |
| 7569 | */ |
| 7570 | @Override |
| 7571 | public void refreshUiccProfile(int subId) { |
| 7572 | enforceModifyPermission(); |
| 7573 | |
| 7574 | final long identity = Binder.clearCallingIdentity(); |
| 7575 | try { |
| 7576 | Phone phone = getPhone(subId); |
| 7577 | if (phone == null) { |
| 7578 | return; |
| 7579 | } |
| 7580 | UiccCard uiccCard = phone.getUiccCard(); |
| 7581 | if (uiccCard == null) { |
| 7582 | return; |
| 7583 | } |
| 7584 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7585 | if (uiccProfile == null) { |
| 7586 | return; |
| 7587 | } |
| 7588 | uiccProfile.refresh(); |
| 7589 | } finally { |
| 7590 | Binder.restoreCallingIdentity(identity); |
| 7591 | } |
| 7592 | } |
| 7593 | |
| 7594 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7595 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7596 | */ |
| 7597 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7598 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7599 | } |
| 7600 | |
| 7601 | /** |
| 7602 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7603 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7604 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7605 | */ |
| 7606 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7607 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7608 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7609 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7610 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7611 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7612 | return isDataRoamingEnabled; |
| 7613 | } |
| 7614 | |
| 7615 | /** |
| 7616 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7617 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7618 | */ |
| 7619 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7620 | List<Integer> list = TelephonyProperties.default_network(); |
| 7621 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7622 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7623 | return list.get(phoneId); |
| 7624 | } |
| 7625 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7626 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7627 | |
| 7628 | @Override |
| 7629 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7630 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7631 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7632 | |
| 7633 | final long identity = Binder.clearCallingIdentity(); |
| 7634 | try { |
| 7635 | final Phone phone = getPhone(subId); |
| 7636 | if (phone == null) { |
| 7637 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7638 | return; |
| 7639 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7640 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7641 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7642 | } finally { |
| 7643 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7644 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7645 | } |
| 7646 | |
| 7647 | @Override |
| 7648 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7649 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7650 | |
| 7651 | final long identity = Binder.clearCallingIdentity(); |
| 7652 | try { |
| 7653 | final Phone phone = getPhone(subId); |
| 7654 | if (phone == null) { |
| 7655 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7656 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7657 | } |
| 7658 | return phone.getCarrierIdListVersion(); |
| 7659 | } finally { |
| 7660 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7661 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7662 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7663 | |
| 7664 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7665 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7666 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7667 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7668 | mApp, subId, callingPackage, callingFeatureId, |
| 7669 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7670 | return -1; |
| 7671 | } |
| 7672 | |
| 7673 | final long identity = Binder.clearCallingIdentity(); |
| 7674 | try { |
| 7675 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7676 | } finally { |
| 7677 | Binder.restoreCallingIdentity(identity); |
| 7678 | } |
| 7679 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7680 | |
| 7681 | @Override |
| 7682 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7683 | TelephonyPermissions |
| 7684 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7685 | mApp, subId, "getCdmaRoamingMode"); |
| 7686 | |
| 7687 | final long identity = Binder.clearCallingIdentity(); |
| 7688 | try { |
| 7689 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7690 | } finally { |
| 7691 | Binder.restoreCallingIdentity(identity); |
| 7692 | } |
| 7693 | } |
| 7694 | |
| 7695 | @Override |
| 7696 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7697 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7698 | mApp, subId, "setCdmaRoamingMode"); |
| 7699 | |
| 7700 | final long identity = Binder.clearCallingIdentity(); |
| 7701 | try { |
| 7702 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7703 | } finally { |
| 7704 | Binder.restoreCallingIdentity(identity); |
| 7705 | } |
| 7706 | } |
| 7707 | |
| 7708 | @Override |
| 7709 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7710 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7711 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7712 | |
| 7713 | final long identity = Binder.clearCallingIdentity(); |
| 7714 | try { |
| 7715 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7716 | } finally { |
| 7717 | Binder.restoreCallingIdentity(identity); |
| 7718 | } |
| 7719 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7720 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7721 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7722 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7723 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7724 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7725 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7726 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7727 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7728 | } |
| 7729 | final long identity = Binder.clearCallingIdentity(); |
| 7730 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7731 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7732 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7733 | if (phone.getEmergencyNumberTracker() != null |
| 7734 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7735 | emergencyNumberListInternal.put( |
| 7736 | phone.getSubId(), |
| 7737 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7738 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7739 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7740 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7741 | } finally { |
| 7742 | Binder.restoreCallingIdentity(identity); |
| 7743 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7744 | } |
| 7745 | |
| 7746 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7747 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7748 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7749 | if (!exactMatch) { |
| 7750 | TelephonyPermissions |
| 7751 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7752 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7753 | } |
| 7754 | final long identity = Binder.clearCallingIdentity(); |
| 7755 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7756 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7757 | if (phone.getEmergencyNumberTracker() != null |
| 7758 | && phone.getEmergencyNumberTracker() != null) { |
| 7759 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7760 | number, exactMatch)) { |
| 7761 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7762 | } |
| 7763 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7764 | } |
| 7765 | return false; |
| 7766 | } finally { |
| 7767 | Binder.restoreCallingIdentity(identity); |
| 7768 | } |
| 7769 | } |
| 7770 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7771 | /** |
| 7772 | * Update emergency number list for test mode. |
| 7773 | */ |
| 7774 | @Override |
| 7775 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7776 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7777 | "updateEmergencyNumberListTestMode"); |
| 7778 | |
| 7779 | final long identity = Binder.clearCallingIdentity(); |
| 7780 | try { |
| 7781 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7782 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7783 | if (tracker != null) { |
| 7784 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7785 | } |
| 7786 | } |
| 7787 | } finally { |
| 7788 | Binder.restoreCallingIdentity(identity); |
| 7789 | } |
| 7790 | } |
| 7791 | |
| 7792 | /** |
| 7793 | * Get the full emergency number list for test mode. |
| 7794 | */ |
| 7795 | @Override |
| 7796 | public List<String> getEmergencyNumberListTestMode() { |
| 7797 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7798 | "getEmergencyNumberListTestMode"); |
| 7799 | |
| 7800 | final long identity = Binder.clearCallingIdentity(); |
| 7801 | try { |
| 7802 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7803 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7804 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7805 | if (tracker != null) { |
| 7806 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7807 | emergencyNumbers.add(num.getNumber()); |
| 7808 | } |
| 7809 | } |
| 7810 | } |
| 7811 | return new ArrayList<>(emergencyNumbers); |
| 7812 | } finally { |
| 7813 | Binder.restoreCallingIdentity(identity); |
| 7814 | } |
| 7815 | } |
| 7816 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7817 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7818 | public int getEmergencyNumberDbVersion(int subId) { |
| 7819 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7820 | |
| 7821 | final long identity = Binder.clearCallingIdentity(); |
| 7822 | try { |
| 7823 | final Phone phone = getPhone(subId); |
| 7824 | if (phone == null) { |
| 7825 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7826 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7827 | } |
| 7828 | return phone.getEmergencyNumberDbVersion(); |
| 7829 | } finally { |
| 7830 | Binder.restoreCallingIdentity(identity); |
| 7831 | } |
| 7832 | } |
| 7833 | |
| 7834 | @Override |
| 7835 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7836 | enforceModifyPermission(); |
| 7837 | |
| 7838 | final long identity = Binder.clearCallingIdentity(); |
| 7839 | try { |
| 7840 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7841 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7842 | if (tracker != null) { |
| 7843 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7844 | } |
| 7845 | } |
| 7846 | } finally { |
| 7847 | Binder.restoreCallingIdentity(identity); |
| 7848 | } |
| 7849 | } |
| 7850 | |
| 7851 | @Override |
| 7852 | public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) { |
| 7853 | enforceActiveEmergencySessionPermission(); |
| 7854 | |
| 7855 | final long identity = Binder.clearCallingIdentity(); |
| 7856 | try { |
| 7857 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7858 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7859 | if (tracker != null) { |
| 7860 | tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath); |
| 7861 | } |
| 7862 | } |
| 7863 | } finally { |
| 7864 | Binder.restoreCallingIdentity(identity); |
| 7865 | } |
| 7866 | } |
| 7867 | |
| 7868 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7869 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7870 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7871 | Phone phone = getPhone(subId); |
| 7872 | if (phone == null) { |
| 7873 | return null; |
| 7874 | } |
| 7875 | final long identity = Binder.clearCallingIdentity(); |
| 7876 | try { |
| 7877 | UiccProfile profile = UiccController.getInstance() |
| 7878 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7879 | if (profile != null) { |
| 7880 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7881 | } |
| 7882 | } finally { |
| 7883 | Binder.restoreCallingIdentity(identity); |
| 7884 | } |
| 7885 | return null; |
| 7886 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7887 | |
| 7888 | /** |
| 7889 | * Enable or disable a modem stack. |
| 7890 | */ |
| 7891 | @Override |
| 7892 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7893 | enforceModifyPermission(); |
| 7894 | |
| 7895 | final long identity = Binder.clearCallingIdentity(); |
| 7896 | try { |
| 7897 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7898 | if (phone == null) { |
| 7899 | return false; |
| 7900 | } else { |
| 7901 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7902 | } |
| 7903 | } finally { |
| 7904 | Binder.restoreCallingIdentity(identity); |
| 7905 | } |
| 7906 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7907 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7908 | /** |
| 7909 | * Whether a modem stack is enabled or not. |
| 7910 | */ |
| 7911 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7912 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7913 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7914 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7915 | if (phone == null) return false; |
| 7916 | |
| 7917 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7918 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7919 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7920 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7921 | } |
| 7922 | |
| 7923 | final long identity = Binder.clearCallingIdentity(); |
| 7924 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7925 | try { |
| 7926 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7927 | } catch (NoSuchElementException ex) { |
| 7928 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7929 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7930 | } finally { |
| 7931 | Binder.restoreCallingIdentity(identity); |
| 7932 | } |
| 7933 | } |
| 7934 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7935 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7936 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7937 | enforceModifyPermission(); |
| 7938 | |
| 7939 | final long identity = Binder.clearCallingIdentity(); |
| 7940 | try { |
| 7941 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7942 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7943 | .commit(); |
| 7944 | } finally { |
| 7945 | Binder.restoreCallingIdentity(identity); |
| 7946 | } |
| 7947 | } |
| 7948 | |
| 7949 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7950 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7951 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7952 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7953 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 7954 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7955 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7956 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7957 | |
| 7958 | final long identity = Binder.clearCallingIdentity(); |
| 7959 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7960 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7961 | } finally { |
| 7962 | Binder.restoreCallingIdentity(identity); |
| 7963 | } |
| 7964 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7965 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7966 | @TelephonyManager.IsMultiSimSupportedResult |
| 7967 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7968 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7969 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7970 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7971 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7972 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7973 | } |
| 7974 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7975 | // supported by the modem, indicate that it is restricted. |
| 7976 | PhoneCapability staticCapability = |
| 7977 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7978 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7979 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7980 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7981 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 7982 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7983 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7984 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7985 | } |
| 7986 | // Check if support of multiple SIMs is restricted by carrier |
| 7987 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7988 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7989 | } |
| 7990 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7991 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7992 | } |
| 7993 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7994 | /** |
| 7995 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7996 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7997 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7998 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7999 | * @param numOfSims number of active sims we want to switch to |
| 8000 | */ |
| 8001 | @Override |
| 8002 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8003 | if (numOfSims == 1) { |
| 8004 | enforceModifyPermission(); |
| 8005 | } else { |
| 8006 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8007 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8008 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8009 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8010 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8011 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8012 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8013 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8014 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8015 | return; |
| 8016 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8017 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8018 | } finally { |
| 8019 | Binder.restoreCallingIdentity(identity); |
| 8020 | } |
| 8021 | } |
| 8022 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8023 | @Override |
| 8024 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8025 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8026 | Phone phone = getPhone(subId); |
| 8027 | if (phone == null) { |
| 8028 | return false; |
| 8029 | } |
| 8030 | final long identity = Binder.clearCallingIdentity(); |
| 8031 | try { |
| 8032 | UiccCard uiccCard = phone.getUiccCard(); |
| 8033 | if (uiccCard == null) { |
| 8034 | return false; |
| 8035 | } |
| 8036 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8037 | if (uiccProfile == null) { |
| 8038 | return false; |
| 8039 | } |
| 8040 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8041 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8042 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8043 | } |
| 8044 | return false; |
| 8045 | } finally { |
| 8046 | Binder.restoreCallingIdentity(identity); |
| 8047 | } |
| 8048 | } |
| 8049 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8050 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8051 | * Get whether making changes to modem configurations will trigger reboot. |
| 8052 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8053 | */ |
| 8054 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8055 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8056 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8057 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8058 | mApp, subId, callingPackage, callingFeatureId, |
| 8059 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8060 | return false; |
| 8061 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8062 | final long identity = Binder.clearCallingIdentity(); |
| 8063 | try { |
| 8064 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8065 | } finally { |
| 8066 | Binder.restoreCallingIdentity(identity); |
| 8067 | } |
| 8068 | } |
| 8069 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8070 | private void updateModemStateMetrics() { |
| 8071 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8072 | // TODO: check the state for each modem if the api is ready. |
| 8073 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8074 | } |
| 8075 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8076 | @Override |
| 8077 | public int[] getSlotsMapping() { |
| 8078 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8079 | |
| 8080 | final long identity = Binder.clearCallingIdentity(); |
| 8081 | try { |
| 8082 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8083 | // All logical slots should have a mapping to a physical slot. |
| 8084 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8085 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8086 | for (int i = 0; i < slotInfos.length; i++) { |
| 8087 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8088 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8089 | } |
| 8090 | } |
| 8091 | return logicalSlotsMapping; |
| 8092 | } finally { |
| 8093 | Binder.restoreCallingIdentity(identity); |
| 8094 | } |
| 8095 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8096 | |
| 8097 | /** |
| 8098 | * Get the IRadio HAL Version |
| 8099 | */ |
| 8100 | @Override |
| 8101 | public int getRadioHalVersion() { |
| 8102 | Phone phone = getDefaultPhone(); |
| 8103 | if (phone == null) return -1; |
| 8104 | HalVersion hv = phone.getHalVersion(); |
| 8105 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8106 | return hv.major * 100 + hv.minor; |
| 8107 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8108 | |
| 8109 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8110 | * Get the current calling package name. |
| 8111 | * @return the current calling package name |
| 8112 | */ |
| 8113 | @Override |
| 8114 | public String getCurrentPackageName() { |
| 8115 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8116 | } |
| 8117 | |
| 8118 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8119 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8120 | * corresponding network requests on a subId. |
| 8121 | * |
| 8122 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8123 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8124 | * 2) APN is un-metered for this subscription, or |
| 8125 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8126 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8127 | * |
| 8128 | * @return whether data is allowed for a apn type. |
| 8129 | * |
| 8130 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8131 | */ |
| 8132 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8133 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8134 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8135 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8136 | |
| 8137 | // Now that all security checks passes, perform the operation as ourselves. |
| 8138 | final long identity = Binder.clearCallingIdentity(); |
| 8139 | try { |
| 8140 | Phone phone = getPhone(subId); |
| 8141 | if (phone == null) return false; |
| 8142 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8143 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8144 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8145 | } finally { |
| 8146 | Binder.restoreCallingIdentity(identity); |
| 8147 | } |
| 8148 | } |
| 8149 | |
| 8150 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8151 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8152 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8153 | |
| 8154 | // Now that all security checks passes, perform the operation as ourselves. |
| 8155 | final long identity = Binder.clearCallingIdentity(); |
| 8156 | try { |
| 8157 | Phone phone = getPhone(subId); |
| 8158 | if (phone == null) return true; // By default return true. |
| 8159 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8160 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8161 | } finally { |
| 8162 | Binder.restoreCallingIdentity(identity); |
| 8163 | } |
| 8164 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8165 | |
| 8166 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8167 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8168 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8169 | enforceModifyPermission(); |
| 8170 | long token = Binder.clearCallingIdentity(); |
| 8171 | try { |
| 8172 | Phone phone = getPhone(subscriptionId); |
| 8173 | if (phone == null) { |
| 8174 | try { |
| 8175 | if (resultCallback != null) { |
| 8176 | resultCallback.accept(false); |
| 8177 | } |
| 8178 | } catch (RemoteException e) { |
| 8179 | // ignore |
| 8180 | } |
| 8181 | return; |
| 8182 | } |
| 8183 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8184 | Pair.create(specifiers, (x) -> { |
| 8185 | try { |
| 8186 | if (resultCallback != null) { |
| 8187 | resultCallback.accept(x); |
| 8188 | } |
| 8189 | } catch (RemoteException e) { |
| 8190 | // ignore |
| 8191 | } |
| 8192 | }); |
| 8193 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8194 | } finally { |
| 8195 | Binder.restoreCallingIdentity(token); |
| 8196 | } |
| 8197 | } |
| 8198 | |
| 8199 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8200 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
| 8201 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8202 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8203 | if (iccRecords == null) { |
| 8204 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8205 | return false; |
| 8206 | } |
| 8207 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8208 | } |
| 8209 | |
| 8210 | @Override |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8211 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8212 | if (callingPackage == null) { |
| 8213 | callingPackage = getCurrentPackageName(); |
| 8214 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8215 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8216 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 8217 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 8218 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8219 | } |
| 8220 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8221 | Intent intent = new Intent(); |
| 8222 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8223 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8224 | // Bring up choose default SMS subscription dialog right now |
| 8225 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8226 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8227 | mApp.startActivity(intent); |
| 8228 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8229 | |
| 8230 | @Override |
| 8231 | public String getMmsUAProfUrl(int subId) { |
| 8232 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8233 | final long identity = Binder.clearCallingIdentity(); |
| 8234 | try { |
| 8235 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8236 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 8237 | } finally { |
| 8238 | Binder.restoreCallingIdentity(identity); |
| 8239 | } |
| 8240 | } |
| 8241 | |
| 8242 | @Override |
| 8243 | public String getMmsUserAgent(int subId) { |
| 8244 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8245 | final long identity = Binder.clearCallingIdentity(); |
| 8246 | try { |
| 8247 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8248 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8249 | } finally { |
| 8250 | Binder.restoreCallingIdentity(identity); |
| 8251 | } |
| 8252 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8253 | |
| 8254 | @Override |
| 8255 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 8256 | enforceModifyPermission(); |
| 8257 | |
| 8258 | // Now that all security checks passes, perform the operation as ourselves. |
| 8259 | final long identity = Binder.clearCallingIdentity(); |
| 8260 | try { |
| 8261 | Phone phone = getPhone(subId); |
| 8262 | if (phone == null) return false; |
| 8263 | |
| 8264 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 8265 | } finally { |
| 8266 | Binder.restoreCallingIdentity(identity); |
| 8267 | } |
| 8268 | } |
| 8269 | |
| 8270 | @Override |
| 8271 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 8272 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 8273 | |
| 8274 | // Now that all security checks passes, perform the operation as ourselves. |
| 8275 | final long identity = Binder.clearCallingIdentity(); |
| 8276 | try { |
| 8277 | Phone phone = getPhone(subId); |
| 8278 | if (phone == null) return false; |
| 8279 | |
| 8280 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8281 | } finally { |
| 8282 | Binder.restoreCallingIdentity(identity); |
| 8283 | } |
| 8284 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8285 | |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8286 | @Override |
| 8287 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8288 | enforceModifyPermission(); |
| 8289 | |
| 8290 | // Now that all security checks passes, perform the operation as ourselves. |
| 8291 | final long identity = Binder.clearCallingIdentity(); |
| 8292 | try { |
| 8293 | Phone phone = getPhone(subId); |
| 8294 | if (phone == null) return false; |
| 8295 | |
| 8296 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8297 | } finally { |
| 8298 | Binder.restoreCallingIdentity(identity); |
| 8299 | } |
| 8300 | } |
| 8301 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8302 | /** |
| 8303 | * Updates whether conference event pacakge handling is enabled. |
| 8304 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8305 | * otherwise. |
| 8306 | */ |
| 8307 | @Override |
| 8308 | public void setCepEnabled(boolean isCepEnabled) { |
| 8309 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8310 | |
| 8311 | final long identity = Binder.clearCallingIdentity(); |
| 8312 | try { |
| 8313 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8314 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8315 | Phone defaultPhone = phone.getImsPhone(); |
| 8316 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8317 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8318 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8319 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8320 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8321 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8322 | + imsPhone.getMsisdn()); |
| 8323 | } |
| 8324 | } |
| 8325 | } finally { |
| 8326 | Binder.restoreCallingIdentity(identity); |
| 8327 | } |
| 8328 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8329 | |
| 8330 | /** |
| 8331 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8332 | * |
| 8333 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8334 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8335 | * before being read. |
| 8336 | */ |
| 8337 | @Override |
| 8338 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8339 | isCompressed) { |
| 8340 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8341 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8342 | try { |
| 8343 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8344 | if (configBinder == null) { |
| 8345 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8346 | } else { |
| 8347 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8348 | } |
| 8349 | } catch (RemoteException e) { |
| 8350 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8351 | } |
| 8352 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8353 | |
| 8354 | @Override |
| 8355 | public boolean isIccLockEnabled(int subId) { |
| 8356 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8357 | |
| 8358 | // Now that all security checks passes, perform the operation as ourselves. |
| 8359 | final long identity = Binder.clearCallingIdentity(); |
| 8360 | try { |
| 8361 | Phone phone = getPhone(subId); |
| 8362 | if (phone != null && phone.getIccCard() != null) { |
| 8363 | return phone.getIccCard().getIccLockEnabled(); |
| 8364 | } else { |
| 8365 | return false; |
| 8366 | } |
| 8367 | } finally { |
| 8368 | Binder.restoreCallingIdentity(identity); |
| 8369 | } |
| 8370 | } |
| 8371 | |
| 8372 | /** |
| 8373 | * Set the ICC pin lock enabled or disabled.. |
| 8374 | * |
| 8375 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8376 | * 0 or a positive integer as the attempts remaining value. |
| 8377 | * |
| 8378 | */ |
| 8379 | @Override |
| 8380 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8381 | enforceModifyPermission(); |
| 8382 | |
| 8383 | Phone phone = getPhone(subId); |
| 8384 | if (phone == null) { |
| 8385 | return 0; |
| 8386 | } |
| 8387 | // Now that all security checks passes, perform the operation as ourselves. |
| 8388 | final long identity = Binder.clearCallingIdentity(); |
| 8389 | try { |
| 8390 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8391 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8392 | return attemptsRemaining; |
| 8393 | |
| 8394 | } catch (Exception e) { |
| 8395 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8396 | } finally { |
| 8397 | Binder.restoreCallingIdentity(identity); |
| 8398 | } |
| 8399 | return 0; |
| 8400 | } |
| 8401 | |
| 8402 | /** |
| 8403 | * Change the ICC password used in ICC pin lock. |
| 8404 | * |
| 8405 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8406 | * 0 or a positive integer as the attempts remaining value. |
| 8407 | * |
| 8408 | */ |
| 8409 | @Override |
| 8410 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8411 | enforceModifyPermission(); |
| 8412 | |
| 8413 | Phone phone = getPhone(subId); |
| 8414 | if (phone == null) { |
| 8415 | return 0; |
| 8416 | } |
| 8417 | // Now that all security checks passes, perform the operation as ourselves. |
| 8418 | final long identity = Binder.clearCallingIdentity(); |
| 8419 | try { |
| 8420 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8421 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8422 | return attemptsRemaining; |
| 8423 | |
| 8424 | } catch (Exception e) { |
| 8425 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8426 | } finally { |
| 8427 | Binder.restoreCallingIdentity(identity); |
| 8428 | } |
| 8429 | return 0; |
| 8430 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8431 | } |