Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 22 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 23 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 24 | import android.Manifest.permission; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 25 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 30 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 33 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 34 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 35 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 48 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 49 | import android.os.PersistableBundle; |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 50 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 51 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 52 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.ServiceManager; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 55 | import android.os.ShellCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 57 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 58 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 59 | import android.preference.PreferenceManager; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 60 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 61 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 62 | import android.provider.Telephony; |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 63 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 65 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 66 | import android.telecom.TelecomManager; |
Chen Xu | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 67 | import android.telephony.Annotation.ApnType; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 68 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 69 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 70 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 71 | import android.telephony.CellIdentity; |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 72 | import android.telephony.CellIdentityCdma; |
| 73 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfoGsm; |
| 76 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 77 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 78 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 79 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 80 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 81 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 82 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 83 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 84 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 85 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 86 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 87 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 88 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 89 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 90 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 91 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 92 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 93 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 94 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 95 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 96 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 97 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 98 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 99 | import android.telephony.data.ApnSetting; |
| 100 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 101 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 102 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 103 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 108 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 109 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 110 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 111 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 112 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 113 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 114 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 115 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 116 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 117 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 118 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 119 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 120 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 121 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 122 | import com.android.ims.internal.IImsServiceFeatureCallback; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 123 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.HalVersion; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 158 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 160 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 170 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 172 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 173 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 174 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 175 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 176 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 177 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 178 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 179 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 180 | import java.io.FileDescriptor; |
| 181 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 182 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 183 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 184 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 185 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 186 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 187 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 188 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 189 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 190 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 191 | |
| 192 | /** |
| 193 | * Implementation of the ITelephony interface. |
| 194 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 195 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 196 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 197 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 198 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 199 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 200 | |
| 201 | // Message codes used with mMainThreadHandler |
| 202 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 203 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 204 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 205 | private static final int CMD_OPEN_CHANNEL = 9; |
| 206 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 207 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 208 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 209 | private static final int CMD_NV_READ_ITEM = 13; |
| 210 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 211 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 212 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 213 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 214 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 215 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 216 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 217 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 218 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 219 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 220 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 221 | private static final int CMD_SEND_ENVELOPE = 25; |
| 222 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 223 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 224 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 225 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 226 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 227 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 228 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 229 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 230 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 231 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 232 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 233 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 234 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 235 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 236 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 237 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 238 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 239 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 240 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 241 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 242 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 243 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 244 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 245 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 246 | private static final int CMD_SWITCH_SLOTS = 50; |
| 247 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 248 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 249 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 250 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 251 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 252 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 253 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 254 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 255 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 256 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 257 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 258 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 259 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 260 | private static final int CMD_MODEM_REBOOT = 64; |
| 261 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 262 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 263 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 264 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 265 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 266 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 267 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 268 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 269 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 270 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 271 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 272 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 273 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 274 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 275 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 276 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 277 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 278 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 279 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 280 | private static final int CMD_GET_CALL_WAITING = 87; |
| 281 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 282 | private static final int CMD_SET_CALL_WAITING = 89; |
| 283 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 284 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 285 | // Parameters of select command. |
| 286 | private static final int SELECT_COMMAND = 0xA4; |
| 287 | private static final int SELECT_P1 = 0x04; |
| 288 | private static final int SELECT_P2 = 0; |
| 289 | private static final int SELECT_P3 = 0x10; |
| 290 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 291 | /** The singleton instance. */ |
| 292 | private static PhoneInterfaceManager sInstance; |
| 293 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 294 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 295 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 296 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 297 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 298 | private AppOpsManager mAppOps; |
| 299 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 300 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 301 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 302 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 303 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 304 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 305 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 306 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 307 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 308 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 309 | // String to store multi SIM allowed |
| 310 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 311 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 312 | // The AID of ISD-R. |
| 313 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 314 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 315 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 316 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 317 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 318 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 319 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 320 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 321 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 322 | */ |
| 323 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 324 | "reset_network_erase_modem_config_enabled"; |
| 325 | |
| 326 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 327 | * A request object to use for transmitting data to an ICC. |
| 328 | */ |
| 329 | private static final class IccAPDUArgument { |
| 330 | public int channel, cla, command, p1, p2, p3; |
| 331 | public String data; |
| 332 | |
| 333 | public IccAPDUArgument(int channel, int cla, int command, |
| 334 | int p1, int p2, int p3, String data) { |
| 335 | this.channel = channel; |
| 336 | this.cla = cla; |
| 337 | this.command = command; |
| 338 | this.p1 = p1; |
| 339 | this.p2 = p2; |
| 340 | this.p3 = p3; |
| 341 | this.data = data; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 346 | * A request object to use for transmitting data to an ICC. |
| 347 | */ |
| 348 | private static final class ManualNetworkSelectionArgument { |
| 349 | public OperatorInfo operatorInfo; |
| 350 | public boolean persistSelection; |
| 351 | |
| 352 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 353 | this.operatorInfo = operatorInfo; |
| 354 | this.persistSelection = persistSelection; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 359 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 360 | * request after sending. The main thread will notify the request when it is complete. |
| 361 | */ |
| 362 | private static final class MainThreadRequest { |
| 363 | /** The argument to use for the request */ |
| 364 | public Object argument; |
| 365 | /** The result of the request that is run on the main thread */ |
| 366 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 367 | // The subscriber id that this request applies to. Defaults to |
| 368 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 369 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 370 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 371 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 372 | public Phone phone; |
| 373 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 374 | public WorkSource workSource; |
| 375 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 376 | public MainThreadRequest(Object argument) { |
| 377 | this.argument = argument; |
| 378 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 379 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 380 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 381 | this.argument = argument; |
| 382 | if (phone != null) { |
| 383 | this.phone = phone; |
| 384 | } |
| 385 | this.workSource = workSource; |
| 386 | } |
| 387 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 388 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 389 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 390 | if (subId != null) { |
| 391 | this.subId = subId; |
| 392 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 393 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 394 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 397 | private static final class IncomingThirdPartyCallArgs { |
| 398 | public final ComponentName component; |
| 399 | public final String callId; |
| 400 | public final String callerDisplayName; |
| 401 | |
| 402 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 403 | String callerDisplayName) { |
| 404 | this.component = component; |
| 405 | this.callId = callId; |
| 406 | this.callerDisplayName = callerDisplayName; |
| 407 | } |
| 408 | } |
| 409 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 410 | /** |
| 411 | * A handler that processes messages on the main thread in the phone process. Since many |
| 412 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 413 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 414 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 415 | * on, which will be notified when the operation completes and will contain the result of the |
| 416 | * request. |
| 417 | * |
| 418 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 419 | * note that request.result must be set to something non-null for the calling thread to |
| 420 | * unblock. |
| 421 | */ |
| 422 | private final class MainThreadHandler extends Handler { |
| 423 | @Override |
| 424 | public void handleMessage(Message msg) { |
| 425 | MainThreadRequest request; |
| 426 | Message onCompleted; |
| 427 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 428 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 429 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 430 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 431 | |
| 432 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 433 | case CMD_HANDLE_USSD_REQUEST: { |
| 434 | request = (MainThreadRequest) msg.obj; |
| 435 | final Phone phone = getPhoneFromRequest(request); |
| 436 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 437 | String ussdRequest = ussdObject.first; |
| 438 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 439 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 440 | if (!isUssdApiAllowed(request.subId)) { |
| 441 | // Carrier does not support use of this API, return failure. |
| 442 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 443 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 444 | Bundle returnData = new Bundle(); |
| 445 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 446 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 447 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 448 | request.result = true; |
| 449 | notifyRequester(request); |
| 450 | return; |
| 451 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 452 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 453 | try { |
| 454 | request.result = phone != null |
| 455 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 456 | } catch (CallStateException cse) { |
| 457 | request.result = false; |
| 458 | } |
| 459 | // Wake up the requesting thread |
| 460 | notifyRequester(request); |
| 461 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 464 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 465 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 466 | final Phone phone = getPhoneFromRequest(request); |
| 467 | request.result = phone != null ? |
| 468 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 469 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 470 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 471 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 472 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 473 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 474 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 475 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 476 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 477 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 478 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 479 | if (uiccCard == null) { |
| 480 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 481 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 482 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 483 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 484 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 485 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 486 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 487 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 488 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 489 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 490 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 491 | break; |
| 492 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 493 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 494 | ar = (AsyncResult) msg.obj; |
| 495 | request = (MainThreadRequest) ar.userObj; |
| 496 | if (ar.exception == null && ar.result != null) { |
| 497 | request.result = ar.result; |
| 498 | } else { |
| 499 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 500 | if (ar.result == null) { |
| 501 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 502 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 503 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 504 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 505 | } else { |
| 506 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 507 | } |
| 508 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 509 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 510 | break; |
| 511 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 512 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 513 | request = (MainThreadRequest) msg.obj; |
| 514 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 515 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 516 | if (uiccCard == null) { |
| 517 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 518 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 519 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 520 | } else { |
| 521 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 522 | request); |
| 523 | uiccCard.iccTransmitApduBasicChannel( |
| 524 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 525 | iccArgument.p3, iccArgument.data, onCompleted); |
| 526 | } |
| 527 | break; |
| 528 | |
| 529 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 530 | ar = (AsyncResult) msg.obj; |
| 531 | request = (MainThreadRequest) ar.userObj; |
| 532 | if (ar.exception == null && ar.result != null) { |
| 533 | request.result = ar.result; |
| 534 | } else { |
| 535 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 536 | if (ar.result == null) { |
| 537 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 538 | } else if (ar.exception instanceof CommandException) { |
| 539 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 540 | ar.exception); |
| 541 | } else { |
| 542 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 543 | } |
| 544 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 545 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 546 | break; |
| 547 | |
| 548 | case CMD_EXCHANGE_SIM_IO: |
| 549 | request = (MainThreadRequest) msg.obj; |
| 550 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 551 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 552 | if (uiccCard == null) { |
| 553 | loge("iccExchangeSimIO: No UICC"); |
| 554 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 555 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 556 | } else { |
| 557 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 558 | request); |
| 559 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 560 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 561 | iccArgument.data, onCompleted); |
| 562 | } |
| 563 | break; |
| 564 | |
| 565 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 566 | ar = (AsyncResult) msg.obj; |
| 567 | request = (MainThreadRequest) ar.userObj; |
| 568 | if (ar.exception == null && ar.result != null) { |
| 569 | request.result = ar.result; |
| 570 | } else { |
| 571 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 572 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 573 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 574 | break; |
| 575 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 576 | case CMD_SEND_ENVELOPE: |
| 577 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 578 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 579 | if (uiccCard == null) { |
| 580 | loge("sendEnvelopeWithStatus: No UICC"); |
| 581 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 582 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 583 | } else { |
| 584 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 585 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 586 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 587 | break; |
| 588 | |
| 589 | case EVENT_SEND_ENVELOPE_DONE: |
| 590 | ar = (AsyncResult) msg.obj; |
| 591 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 592 | if (ar.exception == null && ar.result != null) { |
| 593 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 594 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 595 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 596 | if (ar.result == null) { |
| 597 | loge("sendEnvelopeWithStatus: Empty response"); |
| 598 | } else if (ar.exception instanceof CommandException) { |
| 599 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 600 | ar.exception); |
| 601 | } else { |
| 602 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 603 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 604 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 605 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 606 | break; |
| 607 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 608 | case CMD_OPEN_CHANNEL: |
| 609 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 610 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 611 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 612 | if (uiccCard == null) { |
| 613 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 614 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 615 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 616 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 617 | } else { |
| 618 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 619 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 620 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 621 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 622 | break; |
| 623 | |
| 624 | case EVENT_OPEN_CHANNEL_DONE: |
| 625 | ar = (AsyncResult) msg.obj; |
| 626 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 627 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 628 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 629 | int[] result = (int[]) ar.result; |
| 630 | int channelId = result[0]; |
| 631 | byte[] selectResponse = null; |
| 632 | if (result.length > 1) { |
| 633 | selectResponse = new byte[result.length - 1]; |
| 634 | for (int i = 1; i < result.length; ++i) { |
| 635 | selectResponse[i - 1] = (byte) result[i]; |
| 636 | } |
| 637 | } |
| 638 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 639 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 640 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 641 | if (ar.result == null) { |
| 642 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 643 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 644 | if (ar.exception != null) { |
| 645 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 646 | } |
| 647 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 648 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 649 | if (ar.exception instanceof CommandException) { |
| 650 | CommandException.Error error = |
| 651 | ((CommandException) (ar.exception)).getCommandError(); |
| 652 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 653 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 654 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 655 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 659 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 660 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 661 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 662 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | break; |
| 664 | |
| 665 | case CMD_CLOSE_CHANNEL: |
| 666 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 667 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 668 | if (uiccCard == null) { |
| 669 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 670 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 671 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 672 | } else { |
| 673 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 674 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 675 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 676 | break; |
| 677 | |
| 678 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 679 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 680 | break; |
| 681 | |
| 682 | case CMD_NV_READ_ITEM: |
| 683 | request = (MainThreadRequest) msg.obj; |
| 684 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 685 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 686 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 687 | break; |
| 688 | |
| 689 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 690 | ar = (AsyncResult) msg.obj; |
| 691 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 692 | if (ar.exception == null && ar.result != null) { |
| 693 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 694 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 695 | request.result = ""; |
| 696 | if (ar.result == null) { |
| 697 | loge("nvReadItem: Empty response"); |
| 698 | } else if (ar.exception instanceof CommandException) { |
| 699 | loge("nvReadItem: CommandException: " + |
| 700 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 701 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 702 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 703 | } |
| 704 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 705 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 706 | break; |
| 707 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 708 | case CMD_NV_WRITE_ITEM: |
| 709 | request = (MainThreadRequest) msg.obj; |
| 710 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 711 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 712 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 713 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 714 | break; |
| 715 | |
| 716 | case EVENT_NV_WRITE_ITEM_DONE: |
| 717 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 718 | break; |
| 719 | |
| 720 | case CMD_NV_WRITE_CDMA_PRL: |
| 721 | request = (MainThreadRequest) msg.obj; |
| 722 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 723 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 724 | break; |
| 725 | |
| 726 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 727 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 728 | break; |
| 729 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 730 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 731 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 732 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 733 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 734 | break; |
| 735 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 736 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 737 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 738 | break; |
| 739 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 740 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 741 | request = (MainThreadRequest) msg.obj; |
| 742 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 743 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 744 | break; |
| 745 | |
| 746 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 747 | ar = (AsyncResult) msg.obj; |
| 748 | request = (MainThreadRequest) ar.userObj; |
| 749 | if (ar.exception == null && ar.result != null) { |
| 750 | request.result = ar.result; // Integer |
| 751 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 752 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 753 | if (ar.result == null) { |
| 754 | loge("getPreferredNetworkType: Empty response"); |
| 755 | } else if (ar.exception instanceof CommandException) { |
| 756 | loge("getPreferredNetworkType: CommandException: " + |
| 757 | ar.exception); |
| 758 | } else { |
| 759 | loge("getPreferredNetworkType: Unknown exception"); |
| 760 | } |
| 761 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 762 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 763 | break; |
| 764 | |
| 765 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 766 | request = (MainThreadRequest) msg.obj; |
| 767 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 768 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 769 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 770 | break; |
| 771 | |
| 772 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 773 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 774 | break; |
| 775 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 776 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 777 | request = (MainThreadRequest)msg.obj; |
| 778 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 779 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 780 | break; |
| 781 | |
| 782 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 783 | ar = (AsyncResult)msg.obj; |
| 784 | request = (MainThreadRequest)ar.userObj; |
| 785 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 786 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 787 | break; |
| 788 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 789 | case CMD_SET_VOICEMAIL_NUMBER: |
| 790 | request = (MainThreadRequest) msg.obj; |
| 791 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 792 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 793 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 794 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 795 | break; |
| 796 | |
| 797 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 798 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 799 | break; |
| 800 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 801 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 802 | request = (MainThreadRequest) msg.obj; |
| 803 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 804 | request); |
| 805 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 806 | break; |
| 807 | |
| 808 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 809 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 810 | break; |
| 811 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 812 | case CMD_PERFORM_NETWORK_SCAN: |
| 813 | request = (MainThreadRequest) msg.obj; |
| 814 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 815 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 816 | break; |
| 817 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 818 | case CMD_GET_CALL_FORWARDING: |
| 819 | request = (MainThreadRequest) msg.obj; |
| 820 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
| 821 | int callForwardingReason = (Integer) request.argument; |
| 822 | getPhoneFromRequest(request).getCallForwardingOption( |
| 823 | callForwardingReason, onCompleted); |
| 824 | break; |
| 825 | |
| 826 | case EVENT_GET_CALL_FORWARDING_DONE: |
| 827 | ar = (AsyncResult) msg.obj; |
| 828 | request = (MainThreadRequest) ar.userObj; |
| 829 | CallForwardingInfo callForwardingInfo = null; |
| 830 | if (ar.exception == null && ar.result != null) { |
| 831 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 832 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 833 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 834 | // any service for voice call. |
| 835 | if ((callForwardInfo.serviceClass |
| 836 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
| 837 | callForwardingInfo = new CallForwardingInfo( |
| 838 | callForwardInfo.serviceClass, callForwardInfo.reason, |
| 839 | callForwardInfo.number, |
| 840 | callForwardInfo.timeSeconds); |
| 841 | break; |
| 842 | } |
| 843 | } |
| 844 | // Didn't find a call forward info for voice call. |
| 845 | if (callForwardingInfo == null) { |
| 846 | callForwardingInfo = new CallForwardingInfo( |
| 847 | CallForwardingInfo.STATUS_UNKNOWN_ERROR, |
| 848 | 0 /* reason */, null /* number */, 0 /* timeout */); |
| 849 | } |
| 850 | } else { |
| 851 | if (ar.result == null) { |
| 852 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 853 | } |
| 854 | if (ar.exception != null) { |
| 855 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 856 | } |
| 857 | int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR; |
| 858 | if (ar.exception instanceof CommandException) { |
| 859 | CommandException.Error error = |
| 860 | ((CommandException) (ar.exception)).getCommandError(); |
| 861 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 862 | errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE; |
| 863 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 864 | errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED; |
| 865 | } |
| 866 | } |
| 867 | callForwardingInfo = new CallForwardingInfo( |
| 868 | errorCode, 0 /* reason */, null /* number */, 0 /* timeout */); |
| 869 | } |
| 870 | request.result = callForwardingInfo; |
| 871 | notifyRequester(request); |
| 872 | break; |
| 873 | |
| 874 | case CMD_SET_CALL_FORWARDING: |
| 875 | request = (MainThreadRequest) msg.obj; |
| 876 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
| 877 | CallForwardingInfo callForwardingInfoToSet = |
| 878 | (CallForwardingInfo) request.argument; |
| 879 | getPhoneFromRequest(request).setCallForwardingOption( |
| 880 | callForwardingInfoToSet.getStatus(), |
| 881 | callForwardingInfoToSet.getReason(), |
| 882 | callForwardingInfoToSet.getNumber(), |
| 883 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 884 | break; |
| 885 | |
| 886 | case EVENT_SET_CALL_FORWARDING_DONE: |
| 887 | ar = (AsyncResult) msg.obj; |
| 888 | request = (MainThreadRequest) ar.userObj; |
| 889 | if (ar.exception == null) { |
| 890 | request.result = true; |
| 891 | } else { |
| 892 | request.result = false; |
| 893 | loge("setCallForwarding exception: " + ar.exception); |
| 894 | } |
| 895 | notifyRequester(request); |
| 896 | break; |
| 897 | |
| 898 | case CMD_GET_CALL_WAITING: |
| 899 | request = (MainThreadRequest) msg.obj; |
| 900 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 901 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 902 | break; |
| 903 | |
| 904 | case EVENT_GET_CALL_WAITING_DONE: |
| 905 | ar = (AsyncResult) msg.obj; |
| 906 | request = (MainThreadRequest) ar.userObj; |
| 907 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 908 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 909 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 910 | // Service Class is a bit mask per 3gpp 27.007. |
| 911 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 912 | if (callForwardResults.length > 1 |
| 913 | && ((callForwardResults[1] |
| 914 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
| 915 | callForwardingStatus = callForwardResults[0] == 0 |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 916 | ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE |
| 917 | : TelephonyManager.CALL_WAITING_STATUS_ACTIVE; |
| 918 | } else { |
| 919 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE; |
| 920 | } |
| 921 | } else { |
| 922 | if (ar.result == null) { |
| 923 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 924 | } |
| 925 | if (ar.exception != null) { |
| 926 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 927 | } |
| 928 | if (ar.exception instanceof CommandException) { |
| 929 | CommandException.Error error = |
| 930 | ((CommandException) (ar.exception)).getCommandError(); |
| 931 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 932 | callForwardingStatus = |
| 933 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 934 | } |
| 935 | } |
| 936 | } |
| 937 | request.result = callForwardingStatus; |
| 938 | notifyRequester(request); |
| 939 | break; |
| 940 | |
| 941 | case CMD_SET_CALL_WAITING: |
| 942 | request = (MainThreadRequest) msg.obj; |
| 943 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
| 944 | boolean isEnable = (Boolean) request.argument; |
| 945 | getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted); |
| 946 | break; |
| 947 | |
| 948 | case EVENT_SET_CALL_WAITING_DONE: |
| 949 | ar = (AsyncResult) msg.obj; |
| 950 | request = (MainThreadRequest) ar.userObj; |
| 951 | if (ar.exception == null) { |
| 952 | request.result = true; |
| 953 | } else { |
| 954 | request.result = false; |
| 955 | loge("setCallWaiting exception: " + ar.exception); |
| 956 | } |
| 957 | notifyRequester(request); |
| 958 | break; |
| 959 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 960 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 961 | ar = (AsyncResult) msg.obj; |
| 962 | request = (MainThreadRequest) ar.userObj; |
| 963 | CellNetworkScanResult cellScanResult; |
| 964 | if (ar.exception == null && ar.result != null) { |
| 965 | cellScanResult = new CellNetworkScanResult( |
| 966 | CellNetworkScanResult.STATUS_SUCCESS, |
| 967 | (List<OperatorInfo>) ar.result); |
| 968 | } else { |
| 969 | if (ar.result == null) { |
| 970 | loge("getCellNetworkScanResults: Empty response"); |
| 971 | } |
| 972 | if (ar.exception != null) { |
| 973 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 974 | } |
| 975 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 976 | if (ar.exception instanceof CommandException) { |
| 977 | CommandException.Error error = |
| 978 | ((CommandException) (ar.exception)).getCommandError(); |
| 979 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 980 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 981 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 982 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 983 | } |
| 984 | } |
| 985 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 986 | } |
| 987 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 988 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 989 | break; |
| 990 | |
| 991 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 992 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 993 | ManualNetworkSelectionArgument selArg = |
| 994 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 995 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 996 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 997 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 998 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 999 | break; |
| 1000 | |
| 1001 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1002 | ar = (AsyncResult) msg.obj; |
| 1003 | request = (MainThreadRequest) ar.userObj; |
| 1004 | if (ar.exception == null) { |
| 1005 | request.result = true; |
| 1006 | } else { |
| 1007 | request.result = false; |
| 1008 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1009 | } |
| 1010 | notifyRequester(request); |
| 1011 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1012 | break; |
| 1013 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1014 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1015 | request = (MainThreadRequest) msg.obj; |
| 1016 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1017 | if (defaultPhone != null) { |
| 1018 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame^] | 1019 | } else { |
| 1020 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1021 | Bundle bundle = new Bundle(); |
| 1022 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1023 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1024 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1025 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1026 | break; |
| 1027 | |
| 1028 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1029 | ar = (AsyncResult) msg.obj; |
| 1030 | request = (MainThreadRequest) ar.userObj; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame^] | 1031 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1032 | |
| 1033 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1034 | if (ar.exception == null && ar.result != null) { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame^] | 1035 | // Update the last modem activity info and the result of the request. |
| 1036 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1037 | if (isModemActivityInfoValid(info)) { |
| 1038 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1039 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1040 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1041 | .getTransmitTimeMillis(); |
| 1042 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1043 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1044 | } |
| 1045 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1046 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1047 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1048 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1049 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1050 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1051 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1052 | info.getReceiveTimeMillis() |
| 1053 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1054 | } |
| 1055 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1056 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1057 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1058 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1059 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1060 | } else { |
| 1061 | if (ar.result == null) { |
| 1062 | loge("queryModemActivityInfo: Empty response"); |
| 1063 | } else if (ar.exception instanceof CommandException) { |
| 1064 | loge("queryModemActivityInfo: CommandException: " + |
| 1065 | ar.exception); |
| 1066 | } else { |
| 1067 | loge("queryModemActivityInfo: Unknown exception"); |
| 1068 | } |
| 1069 | } |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame^] | 1070 | Bundle bundle = new Bundle(); |
| 1071 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1072 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1073 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1074 | break; |
| 1075 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1076 | case CMD_SET_ALLOWED_CARRIERS: |
| 1077 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1078 | CarrierRestrictionRules argument = |
| 1079 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1080 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1081 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1082 | break; |
| 1083 | |
| 1084 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1085 | ar = (AsyncResult) msg.obj; |
| 1086 | request = (MainThreadRequest) ar.userObj; |
| 1087 | if (ar.exception == null && ar.result != null) { |
| 1088 | request.result = ar.result; |
| 1089 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1090 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1091 | if (ar.exception instanceof CommandException) { |
| 1092 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1093 | CommandException.Error error = |
| 1094 | ((CommandException) (ar.exception)).getCommandError(); |
| 1095 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1096 | request.result = |
| 1097 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1098 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1099 | } else { |
| 1100 | loge("setAllowedCarriers: Unknown exception"); |
| 1101 | } |
| 1102 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1103 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1104 | break; |
| 1105 | |
| 1106 | case CMD_GET_ALLOWED_CARRIERS: |
| 1107 | request = (MainThreadRequest) msg.obj; |
| 1108 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1109 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1110 | break; |
| 1111 | |
| 1112 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1113 | ar = (AsyncResult) msg.obj; |
| 1114 | request = (MainThreadRequest) ar.userObj; |
| 1115 | if (ar.exception == null && ar.result != null) { |
| 1116 | request.result = ar.result; |
| 1117 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1118 | request.result = new IllegalStateException( |
| 1119 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1120 | if (ar.result == null) { |
| 1121 | loge("getAllowedCarriers: Empty response"); |
| 1122 | } else if (ar.exception instanceof CommandException) { |
| 1123 | loge("getAllowedCarriers: CommandException: " + |
| 1124 | ar.exception); |
| 1125 | } else { |
| 1126 | loge("getAllowedCarriers: Unknown exception"); |
| 1127 | } |
| 1128 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1129 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1130 | break; |
| 1131 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1132 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1133 | ar = (AsyncResult) msg.obj; |
| 1134 | request = (MainThreadRequest) ar.userObj; |
| 1135 | if (ar.exception == null && ar.result != null) { |
| 1136 | request.result = ar.result; |
| 1137 | } else { |
| 1138 | request.result = new IllegalArgumentException( |
| 1139 | "Failed to retrieve Forbidden Plmns"); |
| 1140 | if (ar.result == null) { |
| 1141 | loge("getForbiddenPlmns: Empty response"); |
| 1142 | } else { |
| 1143 | loge("getForbiddenPlmns: Unknown exception"); |
| 1144 | } |
| 1145 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1146 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1147 | break; |
| 1148 | |
| 1149 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1150 | request = (MainThreadRequest) msg.obj; |
| 1151 | uiccCard = getUiccCardFromRequest(request); |
| 1152 | if (uiccCard == null) { |
| 1153 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1154 | request.result = new IllegalArgumentException( |
| 1155 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1156 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1157 | break; |
| 1158 | } |
| 1159 | Integer appType = (Integer) request.argument; |
| 1160 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1161 | if (uiccApp == null) { |
| 1162 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1163 | + appType); |
| 1164 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1165 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1166 | break; |
| 1167 | } else { |
| 1168 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1169 | + " specified type -- " + appType); |
| 1170 | } |
| 1171 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1172 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1173 | onCompleted); |
| 1174 | break; |
| 1175 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1176 | case CMD_SWITCH_SLOTS: |
| 1177 | request = (MainThreadRequest) msg.obj; |
| 1178 | int[] physicalSlots = (int[]) request.argument; |
| 1179 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1180 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1181 | break; |
| 1182 | |
| 1183 | case EVENT_SWITCH_SLOTS_DONE: |
| 1184 | ar = (AsyncResult) msg.obj; |
| 1185 | request = (MainThreadRequest) ar.userObj; |
| 1186 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1187 | notifyRequester(request); |
| 1188 | break; |
| 1189 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1190 | request = (MainThreadRequest) msg.obj; |
| 1191 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1192 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1193 | break; |
| 1194 | |
| 1195 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1196 | ar = (AsyncResult) msg.obj; |
| 1197 | request = (MainThreadRequest) ar.userObj; |
| 1198 | if (ar.exception != null) { |
| 1199 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1200 | } else { |
| 1201 | int mode = ((int[]) ar.result)[0]; |
| 1202 | if (mode == 0) { |
| 1203 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1204 | } else { |
| 1205 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1206 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1207 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1208 | notifyRequester(request); |
| 1209 | break; |
| 1210 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1211 | request = (MainThreadRequest) msg.obj; |
| 1212 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1213 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1214 | break; |
| 1215 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1216 | ar = (AsyncResult) msg.obj; |
| 1217 | request = (MainThreadRequest) ar.userObj; |
| 1218 | if (ar.exception != null) { |
| 1219 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1220 | } else { |
| 1221 | request.result = ((int[]) ar.result)[0]; |
| 1222 | } |
| 1223 | notifyRequester(request); |
| 1224 | break; |
| 1225 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1226 | request = (MainThreadRequest) msg.obj; |
| 1227 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1228 | int mode = (int) request.argument; |
| 1229 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1230 | break; |
| 1231 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1232 | ar = (AsyncResult) msg.obj; |
| 1233 | request = (MainThreadRequest) ar.userObj; |
| 1234 | request.result = ar.exception == null; |
| 1235 | notifyRequester(request); |
| 1236 | break; |
| 1237 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1238 | request = (MainThreadRequest) msg.obj; |
| 1239 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1240 | int subscriptionMode = (int) request.argument; |
| 1241 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1242 | break; |
| 1243 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1244 | ar = (AsyncResult) msg.obj; |
| 1245 | request = (MainThreadRequest) ar.userObj; |
| 1246 | request.result = ar.exception == null; |
| 1247 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1248 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1249 | case CMD_GET_ALL_CELL_INFO: |
| 1250 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1251 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1252 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1253 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1254 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1255 | ar = (AsyncResult) msg.obj; |
| 1256 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1257 | // If a timeout occurs, the response will be null |
| 1258 | request.result = (ar.exception == null && ar.result != null) |
| 1259 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1260 | synchronized (request) { |
| 1261 | request.notifyAll(); |
| 1262 | } |
| 1263 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1264 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1265 | request = (MainThreadRequest) msg.obj; |
| 1266 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1267 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1268 | break; |
| 1269 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1270 | ar = (AsyncResult) msg.obj; |
| 1271 | request = (MainThreadRequest) ar.userObj; |
| 1272 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1273 | try { |
| 1274 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1275 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1276 | cb.onError( |
| 1277 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1278 | ar.exception.getClass().getName(), |
| 1279 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1280 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1281 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1282 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1283 | } else { |
| 1284 | // use the result as returned |
| 1285 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1286 | } |
| 1287 | } catch (RemoteException re) { |
| 1288 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1289 | } |
| 1290 | break; |
| 1291 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1292 | request = (MainThreadRequest) msg.obj; |
| 1293 | WorkSource ws = (WorkSource) request.argument; |
| 1294 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1295 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1296 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1297 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1298 | ar = (AsyncResult) msg.obj; |
| 1299 | request = (MainThreadRequest) ar.userObj; |
| 1300 | if (ar.exception == null) { |
| 1301 | request.result = ar.result; |
| 1302 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1303 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1304 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1305 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | synchronized (request) { |
| 1309 | request.notifyAll(); |
| 1310 | } |
| 1311 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1312 | case CMD_MODEM_REBOOT: |
| 1313 | request = (MainThreadRequest) msg.obj; |
| 1314 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1315 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1316 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1317 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1318 | handleNullReturnEvent(msg, "rebootModem"); |
| 1319 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1320 | case CMD_REQUEST_ENABLE_MODEM: |
| 1321 | request = (MainThreadRequest) msg.obj; |
| 1322 | boolean enable = (boolean) request.argument; |
| 1323 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1324 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1325 | PhoneConfigurationManager.getInstance() |
| 1326 | .enablePhone(request.phone, enable, onCompleted); |
| 1327 | break; |
| 1328 | case EVENT_ENABLE_MODEM_DONE: |
| 1329 | ar = (AsyncResult) msg.obj; |
| 1330 | request = (MainThreadRequest) ar.userObj; |
| 1331 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1332 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1333 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1334 | if ((boolean) request.result) { |
| 1335 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1336 | updateModemStateMetrics(); |
| 1337 | } else { |
| 1338 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1339 | + ar.exception); |
| 1340 | } |
| 1341 | notifyRequester(request); |
| 1342 | break; |
| 1343 | case CMD_GET_MODEM_STATUS: |
| 1344 | request = (MainThreadRequest) msg.obj; |
| 1345 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1346 | PhoneConfigurationManager.getInstance() |
| 1347 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1348 | break; |
| 1349 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1350 | ar = (AsyncResult) msg.obj; |
| 1351 | request = (MainThreadRequest) ar.userObj; |
| 1352 | int id = request.phone.getPhoneId(); |
| 1353 | if (ar.exception == null && ar.result != null) { |
| 1354 | request.result = ar.result; |
| 1355 | //update the cache as modem status has changed |
| 1356 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1357 | (boolean) request.result); |
| 1358 | } else { |
| 1359 | // Return true if modem status cannot be retrieved. For most cases, |
| 1360 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1361 | // and disable modem are not supported. Modem is always on. |
| 1362 | // TODO: this should be fixed in R to support a third |
| 1363 | // status UNKNOWN b/131631629 |
| 1364 | request.result = true; |
| 1365 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1366 | + ar.exception); |
| 1367 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1368 | notifyRequester(request); |
| 1369 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1370 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1371 | ar = (AsyncResult) msg.obj; |
| 1372 | request = (MainThreadRequest) ar.userObj; |
| 1373 | if (ar.exception == null && ar.result != null) { |
| 1374 | request.result = ar.result; |
| 1375 | } else { |
| 1376 | request.result = -1; |
| 1377 | loge("Failed to set Forbidden Plmns"); |
| 1378 | if (ar.result == null) { |
| 1379 | loge("setForbidenPlmns: Empty response"); |
| 1380 | } else if (ar.exception != null) { |
| 1381 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1382 | request.result = -1; |
| 1383 | } else { |
| 1384 | loge("setForbiddenPlmns: Unknown exception"); |
| 1385 | } |
| 1386 | } |
| 1387 | notifyRequester(request); |
| 1388 | break; |
| 1389 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1390 | request = (MainThreadRequest) msg.obj; |
| 1391 | uiccCard = getUiccCardFromRequest(request); |
| 1392 | if (uiccCard == null) { |
| 1393 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1394 | request.result = -1; |
| 1395 | notifyRequester(request); |
| 1396 | break; |
| 1397 | } |
| 1398 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1399 | (Pair<Integer, List<String>>) request.argument; |
| 1400 | appType = setFplmnsArgs.first; |
| 1401 | List<String> fplmns = setFplmnsArgs.second; |
| 1402 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1403 | if (uiccApp == null) { |
| 1404 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1405 | request.result = -1; |
| 1406 | loge("Failed to get UICC App"); |
| 1407 | notifyRequester(request); |
| 1408 | } else { |
| 1409 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1410 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1411 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1412 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1413 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1414 | case CMD_ERASE_MODEM_CONFIG: |
| 1415 | request = (MainThreadRequest) msg.obj; |
| 1416 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1417 | defaultPhone.eraseModemConfig(onCompleted); |
| 1418 | break; |
| 1419 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1420 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1421 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1422 | |
| 1423 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1424 | request = (MainThreadRequest) msg.obj; |
| 1425 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1426 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1427 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1428 | changed.first, changed.second, onCompleted); |
| 1429 | break; |
| 1430 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1431 | ar = (AsyncResult) msg.obj; |
| 1432 | request = (MainThreadRequest) ar.userObj; |
| 1433 | if (ar.exception == null) { |
| 1434 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1435 | } else { |
| 1436 | request.result = msg.arg1; |
| 1437 | } |
| 1438 | notifyRequester(request); |
| 1439 | break; |
| 1440 | |
| 1441 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1442 | request = (MainThreadRequest) msg.obj; |
| 1443 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1444 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1445 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1446 | enabled.first, enabled.second, onCompleted); |
| 1447 | break; |
| 1448 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1449 | ar = (AsyncResult) msg.obj; |
| 1450 | request = (MainThreadRequest) ar.userObj; |
| 1451 | if (ar.exception == null) { |
| 1452 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1453 | } else { |
| 1454 | request.result = msg.arg1; |
| 1455 | } |
| 1456 | notifyRequester(request); |
| 1457 | break; |
| 1458 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1459 | default: |
| 1460 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1461 | break; |
| 1462 | } |
| 1463 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1464 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1465 | private void notifyRequester(MainThreadRequest request) { |
| 1466 | synchronized (request) { |
| 1467 | request.notifyAll(); |
| 1468 | } |
| 1469 | } |
| 1470 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1471 | private void handleNullReturnEvent(Message msg, String command) { |
| 1472 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1473 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1474 | if (ar.exception == null) { |
| 1475 | request.result = true; |
| 1476 | } else { |
| 1477 | request.result = false; |
| 1478 | if (ar.exception instanceof CommandException) { |
| 1479 | loge(command + ": CommandException: " + ar.exception); |
| 1480 | } else { |
| 1481 | loge(command + ": Unknown exception"); |
| 1482 | } |
| 1483 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1484 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1485 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | /** |
| 1489 | * Posts the specified command to be executed on the main thread, |
| 1490 | * waits for the request to complete, and returns the result. |
| 1491 | * @see #sendRequestAsync |
| 1492 | */ |
| 1493 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1494 | return sendRequest( |
| 1495 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | /** |
| 1499 | * Posts the specified command to be executed on the main thread, |
| 1500 | * waits for the request to complete, and returns the result. |
| 1501 | * @see #sendRequestAsync |
| 1502 | */ |
| 1503 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1504 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1505 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | /** |
| 1509 | * Posts the specified command to be executed on the main thread, |
| 1510 | * waits for the request to complete, and returns the result. |
| 1511 | * @see #sendRequestAsync |
| 1512 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1513 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1514 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | /** |
| 1518 | * Posts the specified command to be executed on the main thread, |
| 1519 | * waits for the request to complete, and returns the result. |
| 1520 | * @see #sendRequestAsync |
| 1521 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1522 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1523 | return sendRequest(command, argument, subId, null, workSource); |
| 1524 | } |
| 1525 | |
| 1526 | /** |
| 1527 | * Posts the specified command to be executed on the main thread, |
| 1528 | * waits for the request to complete, and returns the result. |
| 1529 | * @see #sendRequestAsync |
| 1530 | */ |
| 1531 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1532 | return sendRequest( |
| 1533 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1534 | } |
| 1535 | |
| 1536 | /** |
| 1537 | * Posts the specified command to be executed on the main thread, |
| 1538 | * waits for the request to complete, and returns the result. |
| 1539 | * @see #sendRequestAsync |
| 1540 | */ |
| 1541 | private Object sendRequest( |
| 1542 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1543 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1544 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1545 | } |
| 1546 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1547 | MainThreadRequest request = null; |
| 1548 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1549 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1550 | } else if (phone != null) { |
| 1551 | request = new MainThreadRequest(argument, phone, workSource); |
| 1552 | } else { |
| 1553 | request = new MainThreadRequest(argument, subId, workSource); |
| 1554 | } |
| 1555 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1556 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1557 | msg.sendToTarget(); |
| 1558 | |
| 1559 | // Wait for the request to complete |
| 1560 | synchronized (request) { |
| 1561 | while (request.result == null) { |
| 1562 | try { |
| 1563 | request.wait(); |
| 1564 | } catch (InterruptedException e) { |
| 1565 | // Do nothing, go back and wait until the request is complete |
| 1566 | } |
| 1567 | } |
| 1568 | } |
| 1569 | return request.result; |
| 1570 | } |
| 1571 | |
| 1572 | /** |
| 1573 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1574 | * Posts the specified command to be executed on the main thread, and |
| 1575 | * returns immediately. |
| 1576 | * @see #sendRequest |
| 1577 | */ |
| 1578 | private void sendRequestAsync(int command) { |
| 1579 | mMainThreadHandler.sendEmptyMessage(command); |
| 1580 | } |
| 1581 | |
| 1582 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1583 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1584 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1585 | */ |
| 1586 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1587 | sendRequestAsync(command, argument, null, null); |
| 1588 | } |
| 1589 | |
| 1590 | /** |
| 1591 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1592 | * @see {@link #sendRequest(int,Object)} |
| 1593 | */ |
| 1594 | private void sendRequestAsync( |
| 1595 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1596 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1597 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1598 | msg.sendToTarget(); |
| 1599 | } |
| 1600 | |
| 1601 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1602 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1603 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1604 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1605 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1606 | synchronized (PhoneInterfaceManager.class) { |
| 1607 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1608 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1609 | } else { |
| 1610 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1611 | } |
| 1612 | return sInstance; |
| 1613 | } |
| 1614 | } |
| 1615 | |
| 1616 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1617 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1618 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1619 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1620 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1621 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1622 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1623 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1624 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1625 | mTelephonySharedPreferences = |
| 1626 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1627 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1628 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1629 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1630 | publish(); |
| 1631 | } |
| 1632 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1633 | private Phone getDefaultPhone() { |
| 1634 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1635 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1636 | } |
| 1637 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1638 | private void publish() { |
| 1639 | if (DBG) log("publish: " + this); |
| 1640 | |
| 1641 | ServiceManager.addService("phone", this); |
| 1642 | } |
| 1643 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1644 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1645 | if (request.phone != null) { |
| 1646 | return request.phone; |
| 1647 | } else { |
| 1648 | return getPhoneFromSubId(request.subId); |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | private Phone getPhoneFromSubId(int subId) { |
| 1653 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1654 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1655 | } |
| 1656 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1657 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1658 | Phone phone = getPhoneFromRequest(request); |
| 1659 | return phone == null ? null : |
| 1660 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1661 | } |
| 1662 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1663 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1664 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1665 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1666 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1667 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1668 | private void sendEraseModemConfig(Phone phone) { |
| 1669 | if (phone != null) { |
| 1670 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1671 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1672 | final long identity = Binder.clearCallingIdentity(); |
| 1673 | try { |
| 1674 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1675 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1676 | } finally { |
| 1677 | Binder.restoreCallingIdentity(identity); |
| 1678 | } |
| 1679 | } |
| 1680 | } |
| 1681 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1682 | private boolean isImsAvailableOnDevice() { |
| 1683 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1684 | if (pm == null) { |
| 1685 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1686 | // so do not throw error and allow. |
| 1687 | return true; |
| 1688 | } |
| 1689 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1690 | } |
| 1691 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1692 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1693 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1694 | } |
| 1695 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1696 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1697 | if (DBG) log("dial: " + number); |
| 1698 | // No permission check needed here: This is just a wrapper around the |
| 1699 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1700 | // the UI before it does anything. |
| 1701 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1702 | final long identity = Binder.clearCallingIdentity(); |
| 1703 | try { |
| 1704 | String url = createTelUrl(number); |
| 1705 | if (url == null) { |
| 1706 | return; |
| 1707 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1708 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1709 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1710 | PhoneConstants.State state = mCM.getState(subId); |
| 1711 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1712 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1713 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1714 | mApp.startActivity(intent); |
| 1715 | } |
| 1716 | } finally { |
| 1717 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1722 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1723 | } |
| 1724 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1725 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1726 | if (DBG) log("call: " + number); |
| 1727 | |
| 1728 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1729 | // need to do a permission check since we're calling startActivity() |
| 1730 | // from the context of the phone app. |
| 1731 | enforceCallPermission(); |
| 1732 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1733 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1734 | != AppOpsManager.MODE_ALLOWED) { |
| 1735 | return; |
| 1736 | } |
| 1737 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1738 | final long identity = Binder.clearCallingIdentity(); |
| 1739 | try { |
| 1740 | String url = createTelUrl(number); |
| 1741 | if (url == null) { |
| 1742 | return; |
| 1743 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1744 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1745 | boolean isValid = false; |
| 1746 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1747 | if (slist != null) { |
| 1748 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1749 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1750 | isValid = true; |
| 1751 | break; |
| 1752 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1753 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1754 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1755 | if (!isValid) { |
| 1756 | return; |
| 1757 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1758 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1759 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1760 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1761 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1762 | mApp.startActivity(intent); |
| 1763 | } finally { |
| 1764 | Binder.restoreCallingIdentity(identity); |
| 1765 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1768 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1769 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1770 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1771 | } |
| 1772 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1773 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1774 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1775 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1776 | } |
| 1777 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1778 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1779 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1780 | |
| 1781 | final long identity = Binder.clearCallingIdentity(); |
| 1782 | try { |
| 1783 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1784 | checkSimPin.start(); |
| 1785 | return checkSimPin.unlockSim(null, pin); |
| 1786 | } finally { |
| 1787 | Binder.restoreCallingIdentity(identity); |
| 1788 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1791 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1792 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1793 | |
| 1794 | final long identity = Binder.clearCallingIdentity(); |
| 1795 | try { |
| 1796 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1797 | checkSimPuk.start(); |
| 1798 | return checkSimPuk.unlockSim(puk, pin); |
| 1799 | } finally { |
| 1800 | Binder.restoreCallingIdentity(identity); |
| 1801 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1805 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1806 | * a synchronous one. |
| 1807 | */ |
| 1808 | private static class UnlockSim extends Thread { |
| 1809 | |
| 1810 | private final IccCard mSimCard; |
| 1811 | |
| 1812 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1813 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1814 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1815 | |
| 1816 | // For replies from SimCard interface |
| 1817 | private Handler mHandler; |
| 1818 | |
| 1819 | // For async handler to identify request type |
| 1820 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1821 | |
| 1822 | public UnlockSim(IccCard simCard) { |
| 1823 | mSimCard = simCard; |
| 1824 | } |
| 1825 | |
| 1826 | @Override |
| 1827 | public void run() { |
| 1828 | Looper.prepare(); |
| 1829 | synchronized (UnlockSim.this) { |
| 1830 | mHandler = new Handler() { |
| 1831 | @Override |
| 1832 | public void handleMessage(Message msg) { |
| 1833 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1834 | switch (msg.what) { |
| 1835 | case SUPPLY_PIN_COMPLETE: |
| 1836 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1837 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1838 | mRetryCount = msg.arg1; |
| 1839 | if (ar.exception != null) { |
| 1840 | if (ar.exception instanceof CommandException && |
| 1841 | ((CommandException)(ar.exception)).getCommandError() |
| 1842 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1843 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1844 | } else { |
| 1845 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1846 | } |
| 1847 | } else { |
| 1848 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1849 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1850 | mDone = true; |
| 1851 | UnlockSim.this.notifyAll(); |
| 1852 | } |
| 1853 | break; |
| 1854 | } |
| 1855 | } |
| 1856 | }; |
| 1857 | UnlockSim.this.notifyAll(); |
| 1858 | } |
| 1859 | Looper.loop(); |
| 1860 | } |
| 1861 | |
| 1862 | /* |
| 1863 | * Use PIN or PUK to unlock SIM card |
| 1864 | * |
| 1865 | * If PUK is null, unlock SIM card with PIN |
| 1866 | * |
| 1867 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1868 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1869 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1870 | |
| 1871 | while (mHandler == null) { |
| 1872 | try { |
| 1873 | wait(); |
| 1874 | } catch (InterruptedException e) { |
| 1875 | Thread.currentThread().interrupt(); |
| 1876 | } |
| 1877 | } |
| 1878 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1879 | |
| 1880 | if (puk == null) { |
| 1881 | mSimCard.supplyPin(pin, callback); |
| 1882 | } else { |
| 1883 | mSimCard.supplyPuk(puk, pin, callback); |
| 1884 | } |
| 1885 | |
| 1886 | while (!mDone) { |
| 1887 | try { |
| 1888 | Log.d(LOG_TAG, "wait for done"); |
| 1889 | wait(); |
| 1890 | } catch (InterruptedException e) { |
| 1891 | // Restore the interrupted status |
| 1892 | Thread.currentThread().interrupt(); |
| 1893 | } |
| 1894 | } |
| 1895 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1896 | int[] resultArray = new int[2]; |
| 1897 | resultArray[0] = mResult; |
| 1898 | resultArray[1] = mRetryCount; |
| 1899 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1904 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1905 | |
| 1906 | } |
| 1907 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1908 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1909 | // No permission check needed here: this call is harmless, and it's |
| 1910 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1911 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1912 | final long identity = Binder.clearCallingIdentity(); |
| 1913 | try { |
| 1914 | final Phone phone = getPhone(subId); |
| 1915 | if (phone != null) { |
| 1916 | phone.updateServiceLocation(); |
| 1917 | } |
| 1918 | } finally { |
| 1919 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1920 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1921 | } |
| 1922 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1923 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1924 | @Override |
| 1925 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1926 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1927 | } |
| 1928 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1929 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1930 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1931 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1932 | callingFeatureId); |
| 1933 | } |
| 1934 | |
| 1935 | @Deprecated |
| 1936 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1937 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1938 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 1939 | } |
| 1940 | |
| 1941 | @Override |
| 1942 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1943 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1944 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1945 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1946 | return false; |
| 1947 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1948 | |
| 1949 | final long identity = Binder.clearCallingIdentity(); |
| 1950 | try { |
| 1951 | return isRadioOnForSubscriber(subId); |
| 1952 | } finally { |
| 1953 | Binder.restoreCallingIdentity(identity); |
| 1954 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1958 | final long identity = Binder.clearCallingIdentity(); |
| 1959 | try { |
| 1960 | final Phone phone = getPhone(subId); |
| 1961 | if (phone != null) { |
| 1962 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1963 | } else { |
| 1964 | return false; |
| 1965 | } |
| 1966 | } finally { |
| 1967 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1968 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1972 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1973 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1974 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1975 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1976 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1977 | |
| 1978 | final long identity = Binder.clearCallingIdentity(); |
| 1979 | try { |
| 1980 | final Phone phone = getPhone(subId); |
| 1981 | if (phone != null) { |
| 1982 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1983 | } |
| 1984 | } finally { |
| 1985 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1986 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1990 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1991 | } |
| 1992 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1993 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1994 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1995 | |
| 1996 | final long identity = Binder.clearCallingIdentity(); |
| 1997 | try { |
| 1998 | final Phone phone = getPhone(subId); |
| 1999 | if (phone == null) { |
| 2000 | return false; |
| 2001 | } |
| 2002 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2003 | toggleRadioOnOffForSubscriber(subId); |
| 2004 | } |
| 2005 | return true; |
| 2006 | } finally { |
| 2007 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2008 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2009 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2010 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2011 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2012 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2013 | /* |
| 2014 | * If any of the Radios are available, it will need to be |
| 2015 | * shutdown. So return true if any Radio is available. |
| 2016 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2017 | final long identity = Binder.clearCallingIdentity(); |
| 2018 | try { |
| 2019 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2020 | Phone phone = PhoneFactory.getPhone(i); |
| 2021 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2022 | } |
| 2023 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2024 | return false; |
| 2025 | } finally { |
| 2026 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2027 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2030 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2031 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2032 | enforceModifyPermission(); |
| 2033 | |
| 2034 | final long identity = Binder.clearCallingIdentity(); |
| 2035 | try { |
| 2036 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2037 | logv("Shutting down Phone " + i); |
| 2038 | shutdownRadioUsingPhoneId(i); |
| 2039 | } |
| 2040 | } finally { |
| 2041 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2042 | } |
| 2043 | } |
| 2044 | |
| 2045 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2046 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2047 | if (phone != null && phone.isRadioAvailable()) { |
| 2048 | phone.shutdownRadio(); |
| 2049 | } |
| 2050 | } |
| 2051 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2052 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2053 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2054 | |
| 2055 | final long identity = Binder.clearCallingIdentity(); |
| 2056 | try { |
| 2057 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2058 | if (defaultPhone != null) { |
| 2059 | defaultPhone.setRadioPower(turnOn); |
| 2060 | return true; |
| 2061 | } else { |
| 2062 | loge("There's no default phone."); |
| 2063 | return false; |
| 2064 | } |
| 2065 | } finally { |
| 2066 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2067 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2068 | } |
| 2069 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2070 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2071 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2072 | |
| 2073 | final long identity = Binder.clearCallingIdentity(); |
| 2074 | try { |
| 2075 | final Phone phone = getPhone(subId); |
| 2076 | if (phone != null) { |
| 2077 | phone.setRadioPower(turnOn); |
| 2078 | return true; |
| 2079 | } else { |
| 2080 | return false; |
| 2081 | } |
| 2082 | } finally { |
| 2083 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2084 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2087 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2088 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2089 | public boolean enableDataConnectivity() { |
| 2090 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2091 | |
| 2092 | final long identity = Binder.clearCallingIdentity(); |
| 2093 | try { |
| 2094 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2095 | final Phone phone = getPhone(subId); |
| 2096 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2097 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2098 | return true; |
| 2099 | } else { |
| 2100 | return false; |
| 2101 | } |
| 2102 | } finally { |
| 2103 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2104 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2107 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2108 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2109 | public boolean disableDataConnectivity() { |
| 2110 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2111 | |
| 2112 | final long identity = Binder.clearCallingIdentity(); |
| 2113 | try { |
| 2114 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2115 | final Phone phone = getPhone(subId); |
| 2116 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2117 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2118 | return true; |
| 2119 | } else { |
| 2120 | return false; |
| 2121 | } |
| 2122 | } finally { |
| 2123 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2124 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2125 | } |
| 2126 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2127 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2128 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2129 | final long identity = Binder.clearCallingIdentity(); |
| 2130 | try { |
| 2131 | final Phone phone = getPhone(subId); |
| 2132 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2133 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2134 | } else { |
| 2135 | return false; |
| 2136 | } |
| 2137 | } finally { |
| 2138 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2139 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2143 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2146 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2147 | enforceCallPermission(); |
| 2148 | |
| 2149 | final long identity = Binder.clearCallingIdentity(); |
| 2150 | try { |
| 2151 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2152 | return; |
| 2153 | } |
| 2154 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2155 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2156 | } finally { |
| 2157 | Binder.restoreCallingIdentity(identity); |
| 2158 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2159 | }; |
| 2160 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2161 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2162 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2163 | |
| 2164 | final long identity = Binder.clearCallingIdentity(); |
| 2165 | try { |
| 2166 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2167 | return false; |
| 2168 | } |
| 2169 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2170 | } finally { |
| 2171 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2172 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2173 | } |
| 2174 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2175 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2176 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2177 | } |
| 2178 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2179 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2180 | final long identity = Binder.clearCallingIdentity(); |
| 2181 | try { |
| 2182 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2183 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2184 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2185 | } finally { |
| 2186 | Binder.restoreCallingIdentity(identity); |
| 2187 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2188 | } |
| 2189 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2190 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2191 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2192 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2193 | } |
| 2194 | |
| 2195 | @Override |
| 2196 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2197 | final long identity = Binder.clearCallingIdentity(); |
| 2198 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2199 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2200 | if (phone != null) { |
| 2201 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2202 | } else { |
| 2203 | return PhoneConstantConversions.convertDataState( |
| 2204 | PhoneConstants.DataState.DISCONNECTED); |
| 2205 | } |
| 2206 | } finally { |
| 2207 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 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 getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2213 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2214 | } |
| 2215 | |
| 2216 | @Override |
| 2217 | public int getDataActivityForSubId(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 DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2223 | } else { |
| 2224 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2225 | } |
| 2226 | } finally { |
| 2227 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2228 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2229 | } |
| 2230 | |
| 2231 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2232 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2233 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2234 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2235 | |
| 2236 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2237 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2238 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2239 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2240 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2241 | .setCallingPid(Binder.getCallingPid()) |
| 2242 | .setCallingUid(Binder.getCallingUid()) |
| 2243 | .setMethod("getCellLocation") |
| 2244 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2245 | .build()); |
| 2246 | switch (locationResult) { |
| 2247 | case DENIED_HARD: |
| 2248 | throw new SecurityException("Not allowed to access cell location"); |
| 2249 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2250 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2251 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2252 | } |
| 2253 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2254 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2255 | final long identity = Binder.clearCallingIdentity(); |
| 2256 | try { |
| 2257 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2258 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2259 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2260 | } finally { |
| 2261 | Binder.restoreCallingIdentity(identity); |
| 2262 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2265 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2266 | public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage, |
| 2267 | String callingFeatureId) { |
Jack Yu | 7c5d91a | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2268 | if (!TextUtils.isEmpty(callingPackage)) { |
| 2269 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2270 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2271 | callingFeatureId, "getNetworkCountryIsoForPhone")) { |
Jack Yu | 7c5d91a | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2272 | return ""; |
| 2273 | } |
| 2274 | } |
| 2275 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2276 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2277 | // registered cell info, so return a NULL country instead. |
| 2278 | final long identity = Binder.clearCallingIdentity(); |
| 2279 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2280 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2281 | // Get default phone in this case. |
| 2282 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2283 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2284 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2285 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2286 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2287 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2288 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(), |
| 2289 | null)) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2290 | return ""; |
| 2291 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2292 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2293 | if (phone != null) { |
| 2294 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2295 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2296 | if (sst != null) { |
| 2297 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2298 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2299 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2300 | return lt.getCurrentCountry(); |
| 2301 | } else if (emergencyNumberTracker != null) { |
| 2302 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2303 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2304 | } |
| 2305 | } |
| 2306 | } |
| 2307 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2308 | } finally { |
| 2309 | Binder.restoreCallingIdentity(identity); |
| 2310 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2314 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2315 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2316 | } |
| 2317 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2318 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2319 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2320 | mApp.enforceCallingOrSelfPermission( |
| 2321 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2322 | |
| 2323 | final long identity = Binder.clearCallingIdentity(); |
| 2324 | try { |
| 2325 | final Phone phone = getPhone(subId); |
| 2326 | if (phone != null) { |
| 2327 | phone.enableLocationUpdates(); |
| 2328 | } |
| 2329 | } finally { |
| 2330 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2331 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | @Override |
| 2335 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2336 | disableLocationUpdatesForSubscriber(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 disableLocationUpdatesForSubscriber(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.disableLocationUpdates(); |
| 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 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2355 | /** |
| 2356 | * Returns the target SDK version number for a given package name. |
| 2357 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2358 | * This call MUST be invoked before clearing the calling UID. |
| 2359 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2360 | * @return target SDK if the package is found or INT_MAX. |
| 2361 | */ |
| 2362 | private int getTargetSdk(String packageName) { |
| 2363 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2364 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2365 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2366 | if (ai != null) return ai.targetSdkVersion; |
| 2367 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2368 | loge("Failed to get package info for pkg=" |
| 2369 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2370 | } |
| 2371 | return Integer.MAX_VALUE; |
| 2372 | } |
| 2373 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2374 | @Override |
| 2375 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2376 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2377 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2378 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2379 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2380 | throw new SecurityException( |
| 2381 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2382 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2383 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2384 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2385 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2386 | return null; |
| 2387 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2388 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2389 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2390 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2391 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2392 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2393 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2394 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2395 | for (CellInfo ci : info) { |
| 2396 | if (ci instanceof CellInfoGsm) { |
| 2397 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2398 | } else if (ci instanceof CellInfoWcdma) { |
| 2399 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2400 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2401 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2402 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2403 | } |
| 2404 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2405 | private List<CellInfo> getCachedCellInfo() { |
| 2406 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2407 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2408 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2409 | if (info != null) cellInfos.addAll(info); |
| 2410 | } |
| 2411 | return cellInfos; |
| 2412 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2413 | |
| 2414 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2415 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2416 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2417 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2418 | |
| 2419 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2420 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2421 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2422 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2423 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2424 | .setCallingPid(Binder.getCallingPid()) |
| 2425 | .setCallingUid(Binder.getCallingUid()) |
| 2426 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2427 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2428 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2429 | .build()); |
| 2430 | switch (locationResult) { |
| 2431 | case DENIED_HARD: |
| 2432 | throw new SecurityException("Not allowed to access cell info"); |
| 2433 | case DENIED_SOFT: |
| 2434 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2435 | } |
| 2436 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2437 | final int targetSdk = getTargetSdk(callingPackage); |
| 2438 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2439 | return getCachedCellInfo(); |
| 2440 | } |
| 2441 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2442 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2443 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2444 | final long identity = Binder.clearCallingIdentity(); |
| 2445 | try { |
| 2446 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2447 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2448 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2449 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2450 | if (info != null) cellInfos.addAll(info); |
| 2451 | } |
| 2452 | return cellInfos; |
| 2453 | } finally { |
| 2454 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2455 | } |
| 2456 | } |
| 2457 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2458 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2459 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2460 | String callingFeatureId) { |
| 2461 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2462 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2463 | } |
| 2464 | |
| 2465 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2466 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2467 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2468 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2469 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2472 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2473 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2474 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2475 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2476 | |
| 2477 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2478 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2479 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2480 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2481 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2482 | .setCallingPid(Binder.getCallingPid()) |
| 2483 | .setCallingUid(Binder.getCallingUid()) |
| 2484 | .setMethod("requestCellInfoUpdate") |
| 2485 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2486 | .build()); |
| 2487 | switch (locationResult) { |
| 2488 | case DENIED_HARD: |
| 2489 | throw new SecurityException("Not allowed to access cell info"); |
| 2490 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2491 | try { |
| 2492 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2493 | } catch (RemoteException re) { |
| 2494 | // Drop without consequences |
| 2495 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2496 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2497 | } |
| 2498 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2499 | |
| 2500 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2501 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2502 | |
| 2503 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2504 | } |
| 2505 | |
| 2506 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2507 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2508 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2509 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2510 | |
| 2511 | final long identity = Binder.clearCallingIdentity(); |
| 2512 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2513 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2514 | } finally { |
| 2515 | Binder.restoreCallingIdentity(identity); |
| 2516 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2517 | } |
| 2518 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2519 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2520 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2521 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2522 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2523 | return null; |
| 2524 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2525 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2526 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2527 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2528 | return null; |
| 2529 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2530 | |
| 2531 | final long identity = Binder.clearCallingIdentity(); |
| 2532 | try { |
| 2533 | return phone.getImei(); |
| 2534 | } finally { |
| 2535 | Binder.restoreCallingIdentity(identity); |
| 2536 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2540 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2541 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2542 | String tac = null; |
| 2543 | if (phone != null) { |
| 2544 | String imei = phone.getImei(); |
| 2545 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2546 | } |
| 2547 | return tac; |
| 2548 | } |
| 2549 | |
| 2550 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2551 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2552 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2553 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2554 | return null; |
| 2555 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2556 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2557 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2558 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2559 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2560 | return null; |
| 2561 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2562 | |
| 2563 | final long identity = Binder.clearCallingIdentity(); |
| 2564 | try { |
| 2565 | return phone.getMeid(); |
| 2566 | } finally { |
| 2567 | Binder.restoreCallingIdentity(identity); |
| 2568 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2569 | } |
| 2570 | |
| 2571 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2572 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2573 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2574 | String manufacturerCode = null; |
| 2575 | if (phone != null) { |
| 2576 | String meid = phone.getMeid(); |
| 2577 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2578 | } |
| 2579 | return manufacturerCode; |
| 2580 | } |
| 2581 | |
| 2582 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2583 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2584 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2585 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2586 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2587 | return null; |
| 2588 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2589 | int subId = phone.getSubId(); |
| 2590 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2591 | mApp, subId, callingPackage, callingFeatureId, |
| 2592 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2593 | return null; |
| 2594 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2595 | |
| 2596 | final long identity = Binder.clearCallingIdentity(); |
| 2597 | try { |
| 2598 | return phone.getDeviceSvn(); |
| 2599 | } finally { |
| 2600 | Binder.restoreCallingIdentity(identity); |
| 2601 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2602 | } |
| 2603 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2604 | @Override |
| 2605 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2606 | final long identity = Binder.clearCallingIdentity(); |
| 2607 | try { |
| 2608 | final Phone phone = getPhone(subId); |
| 2609 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2610 | } finally { |
| 2611 | Binder.restoreCallingIdentity(identity); |
| 2612 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2613 | } |
| 2614 | |
| 2615 | @Override |
| 2616 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2617 | final long identity = Binder.clearCallingIdentity(); |
| 2618 | try { |
| 2619 | final Phone phone = getPhone(subId); |
| 2620 | return phone == null ? null : phone.getCarrierName(); |
| 2621 | } finally { |
| 2622 | Binder.restoreCallingIdentity(identity); |
| 2623 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2624 | } |
| 2625 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2626 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2627 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2628 | final long identity = Binder.clearCallingIdentity(); |
| 2629 | try { |
| 2630 | final Phone phone = getPhone(subId); |
| 2631 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2632 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2633 | } finally { |
| 2634 | Binder.restoreCallingIdentity(identity); |
| 2635 | } |
| 2636 | } |
| 2637 | |
| 2638 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2639 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2640 | final long identity = Binder.clearCallingIdentity(); |
| 2641 | try { |
| 2642 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2643 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2644 | } finally { |
| 2645 | Binder.restoreCallingIdentity(identity); |
| 2646 | } |
| 2647 | } |
| 2648 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2649 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2650 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2651 | if (!isSubscriptionMccMnc) { |
| 2652 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2653 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2654 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2655 | if (phone == null) { |
| 2656 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2657 | } |
| 2658 | final long identity = Binder.clearCallingIdentity(); |
| 2659 | try { |
| 2660 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2661 | } finally { |
| 2662 | Binder.restoreCallingIdentity(identity); |
| 2663 | } |
| 2664 | } |
| 2665 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2666 | // |
| 2667 | // Internal helper methods. |
| 2668 | // |
| 2669 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2670 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2671 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2672 | * |
| 2673 | * @throws SecurityException if the caller does not have the required permission |
| 2674 | */ |
| 2675 | private void enforceModifyPermission() { |
| 2676 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2677 | } |
| 2678 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2679 | /** |
| 2680 | * Make sure the caller is system. |
| 2681 | * |
| 2682 | * @throws SecurityException if the caller is not system. |
| 2683 | */ |
| 2684 | private void enforceSystemCaller() { |
| 2685 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2686 | throw new SecurityException("Caller must be system"); |
| 2687 | } |
| 2688 | } |
| 2689 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2690 | private void enforceActiveEmergencySessionPermission() { |
| 2691 | mApp.enforceCallingOrSelfPermission( |
| 2692 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2693 | } |
| 2694 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2695 | /** |
| 2696 | * Make sure the caller has the CALL_PHONE permission. |
| 2697 | * |
| 2698 | * @throws SecurityException if the caller does not have the required permission |
| 2699 | */ |
| 2700 | private void enforceCallPermission() { |
| 2701 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2702 | } |
| 2703 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2704 | private void enforceSettingsPermission() { |
| 2705 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2706 | } |
| 2707 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2708 | private String createTelUrl(String number) { |
| 2709 | if (TextUtils.isEmpty(number)) { |
| 2710 | return null; |
| 2711 | } |
| 2712 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2713 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2716 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2717 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2718 | } |
| 2719 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2720 | private static void logv(String msg) { |
| 2721 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2722 | } |
| 2723 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2724 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2725 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2726 | } |
| 2727 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2728 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2729 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2730 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2731 | } |
| 2732 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2733 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2734 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2735 | final long identity = Binder.clearCallingIdentity(); |
| 2736 | try { |
| 2737 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2738 | if (phone == null) { |
| 2739 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2740 | } else { |
| 2741 | return phone.getPhoneType(); |
| 2742 | } |
| 2743 | } finally { |
| 2744 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2745 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2746 | } |
| 2747 | |
| 2748 | /** |
| 2749 | * Returns the CDMA ERI icon index to display |
| 2750 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2751 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2752 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2753 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2754 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2755 | } |
| 2756 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2757 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2758 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2759 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2760 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2761 | mApp, subId, callingPackage, callingFeatureId, |
| 2762 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2763 | return -1; |
| 2764 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2765 | |
| 2766 | final long identity = Binder.clearCallingIdentity(); |
| 2767 | try { |
| 2768 | final Phone phone = getPhone(subId); |
| 2769 | if (phone != null) { |
| 2770 | return phone.getCdmaEriIconIndex(); |
| 2771 | } else { |
| 2772 | return -1; |
| 2773 | } |
| 2774 | } finally { |
| 2775 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2776 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | /** |
| 2780 | * Returns the CDMA ERI icon mode, |
| 2781 | * 0 - ON |
| 2782 | * 1 - FLASHING |
| 2783 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2784 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2785 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2786 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2787 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2788 | } |
| 2789 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2790 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2791 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2792 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2793 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2794 | mApp, subId, callingPackage, callingFeatureId, |
| 2795 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2796 | return -1; |
| 2797 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2798 | |
| 2799 | final long identity = Binder.clearCallingIdentity(); |
| 2800 | try { |
| 2801 | final Phone phone = getPhone(subId); |
| 2802 | if (phone != null) { |
| 2803 | return phone.getCdmaEriIconMode(); |
| 2804 | } else { |
| 2805 | return -1; |
| 2806 | } |
| 2807 | } finally { |
| 2808 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2809 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2810 | } |
| 2811 | |
| 2812 | /** |
| 2813 | * Returns the CDMA ERI text, |
| 2814 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2815 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2816 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2817 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2818 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2819 | } |
| 2820 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2821 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2822 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2823 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2824 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2825 | mApp, subId, callingPackage, callingFeatureId, |
| 2826 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2827 | return null; |
| 2828 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2829 | |
| 2830 | final long identity = Binder.clearCallingIdentity(); |
| 2831 | try { |
| 2832 | final Phone phone = getPhone(subId); |
| 2833 | if (phone != null) { |
| 2834 | return phone.getCdmaEriText(); |
| 2835 | } else { |
| 2836 | return null; |
| 2837 | } |
| 2838 | } finally { |
| 2839 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2840 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2841 | } |
| 2842 | |
| 2843 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2844 | * Returns the CDMA MDN. |
| 2845 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2846 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2847 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2848 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2849 | mApp, subId, "getCdmaMdn"); |
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); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2854 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2855 | return phone.getLine1Number(); |
| 2856 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2857 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2858 | return null; |
| 2859 | } |
| 2860 | } finally { |
| 2861 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | /** |
| 2866 | * Returns the CDMA MIN. |
| 2867 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2868 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2869 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2870 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2871 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2872 | |
| 2873 | final long identity = Binder.clearCallingIdentity(); |
| 2874 | try { |
| 2875 | final Phone phone = getPhone(subId); |
| 2876 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2877 | return phone.getCdmaMin(); |
| 2878 | } else { |
| 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 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2886 | @Override |
| 2887 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2888 | INumberVerificationCallback callback, String callingPackage) { |
| 2889 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2890 | != PERMISSION_GRANTED) { |
| 2891 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2892 | } |
| 2893 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2894 | |
| 2895 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2896 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2897 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2898 | } |
| 2899 | |
| 2900 | if (range == null) { |
| 2901 | throw new NullPointerException("Range must be non-null"); |
| 2902 | } |
| 2903 | |
| 2904 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2905 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2906 | |
| 2907 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2908 | } |
| 2909 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2910 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2911 | * Returns true if CDMA provisioning needs to run. |
| 2912 | */ |
| 2913 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2914 | final long identity = Binder.clearCallingIdentity(); |
| 2915 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2916 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2917 | } finally { |
| 2918 | Binder.restoreCallingIdentity(identity); |
| 2919 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2920 | } |
| 2921 | |
| 2922 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2923 | * Sets the voice mail number of a given subId. |
| 2924 | */ |
| 2925 | @Override |
| 2926 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2927 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2928 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2929 | |
| 2930 | final long identity = Binder.clearCallingIdentity(); |
| 2931 | try { |
| 2932 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2933 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2934 | return success; |
| 2935 | } finally { |
| 2936 | Binder.restoreCallingIdentity(identity); |
| 2937 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2938 | } |
| 2939 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2940 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2941 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2942 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2943 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2944 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2945 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2946 | throw new SecurityException("caller must be system dialer"); |
| 2947 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2948 | |
| 2949 | final long identity = Binder.clearCallingIdentity(); |
| 2950 | try { |
| 2951 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2952 | if (phoneAccountHandle == null) { |
| 2953 | return null; |
| 2954 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2955 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2956 | } finally { |
| 2957 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2958 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2962 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2963 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2964 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2965 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2966 | mApp, subId, callingPackage, callingFeatureId, |
| 2967 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2968 | return null; |
| 2969 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2970 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2971 | final long identity = Binder.clearCallingIdentity(); |
| 2972 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2973 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2974 | } finally { |
| 2975 | Binder.restoreCallingIdentity(identity); |
| 2976 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2980 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2981 | VisualVoicemailSmsFilterSettings settings) { |
| 2982 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2983 | |
| 2984 | final long identity = Binder.clearCallingIdentity(); |
| 2985 | try { |
| 2986 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2987 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2988 | } finally { |
| 2989 | Binder.restoreCallingIdentity(identity); |
| 2990 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2991 | } |
| 2992 | |
| 2993 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2994 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2995 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2996 | |
| 2997 | final long identity = Binder.clearCallingIdentity(); |
| 2998 | try { |
| 2999 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3000 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3001 | } finally { |
| 3002 | Binder.restoreCallingIdentity(identity); |
| 3003 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3004 | } |
| 3005 | |
| 3006 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3007 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3008 | String callingPackage, int subId) { |
| 3009 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3010 | |
| 3011 | final long identity = Binder.clearCallingIdentity(); |
| 3012 | try { |
| 3013 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3014 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3015 | } finally { |
| 3016 | Binder.restoreCallingIdentity(identity); |
| 3017 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3018 | } |
| 3019 | |
| 3020 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3021 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3022 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3023 | |
| 3024 | final long identity = Binder.clearCallingIdentity(); |
| 3025 | try { |
| 3026 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3027 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3028 | } finally { |
| 3029 | Binder.restoreCallingIdentity(identity); |
| 3030 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3031 | } |
| 3032 | |
| 3033 | @Override |
| 3034 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 3035 | String number, int port, String text, PendingIntent sentIntent) { |
| 3036 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3037 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3038 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3039 | SmsController smsController = PhoneFactory.getSmsController(); |
| 3040 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 3041 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3042 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3043 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3044 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3045 | * Sets the voice activation state of a given subId. |
| 3046 | */ |
| 3047 | @Override |
| 3048 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3049 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3050 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3051 | |
| 3052 | final long identity = Binder.clearCallingIdentity(); |
| 3053 | try { |
| 3054 | final Phone phone = getPhone(subId); |
| 3055 | if (phone != null) { |
| 3056 | phone.setVoiceActivationState(activationState); |
| 3057 | } else { |
| 3058 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3059 | } |
| 3060 | } finally { |
| 3061 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3062 | } |
| 3063 | } |
| 3064 | |
| 3065 | /** |
| 3066 | * Sets the data activation state of a given subId. |
| 3067 | */ |
| 3068 | @Override |
| 3069 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3070 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3071 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3072 | |
| 3073 | final long identity = Binder.clearCallingIdentity(); |
| 3074 | try { |
| 3075 | final Phone phone = getPhone(subId); |
| 3076 | if (phone != null) { |
| 3077 | phone.setDataActivationState(activationState); |
| 3078 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3079 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3080 | } |
| 3081 | } finally { |
| 3082 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3083 | } |
| 3084 | } |
| 3085 | |
| 3086 | /** |
| 3087 | * Returns the voice activation state of a given subId. |
| 3088 | */ |
| 3089 | @Override |
| 3090 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3091 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3092 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3093 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3094 | final long identity = Binder.clearCallingIdentity(); |
| 3095 | try { |
| 3096 | if (phone != null) { |
| 3097 | return phone.getVoiceActivationState(); |
| 3098 | } else { |
| 3099 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3100 | } |
| 3101 | } finally { |
| 3102 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3103 | } |
| 3104 | } |
| 3105 | |
| 3106 | /** |
| 3107 | * Returns the data activation state of a given subId. |
| 3108 | */ |
| 3109 | @Override |
| 3110 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3111 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3112 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3113 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3114 | final long identity = Binder.clearCallingIdentity(); |
| 3115 | try { |
| 3116 | if (phone != null) { |
| 3117 | return phone.getDataActivationState(); |
| 3118 | } else { |
| 3119 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3120 | } |
| 3121 | } finally { |
| 3122 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3123 | } |
| 3124 | } |
| 3125 | |
| 3126 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3127 | * Returns the unread count of voicemails for a subId |
| 3128 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3129 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3130 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3131 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3132 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3133 | mApp, subId, callingPackage, callingFeatureId, |
| 3134 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3135 | return 0; |
| 3136 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3137 | final long identity = Binder.clearCallingIdentity(); |
| 3138 | try { |
| 3139 | final Phone phone = getPhone(subId); |
| 3140 | if (phone != null) { |
| 3141 | return phone.getVoiceMessageCount(); |
| 3142 | } else { |
| 3143 | return 0; |
| 3144 | } |
| 3145 | } finally { |
| 3146 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3147 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3148 | } |
| 3149 | |
| 3150 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3151 | * returns true, if the device is in a state where both voice and data |
| 3152 | * are supported simultaneously. This can change based on location or network condition. |
| 3153 | */ |
| 3154 | @Override |
| 3155 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3156 | final long identity = Binder.clearCallingIdentity(); |
| 3157 | try { |
| 3158 | final Phone phone = getPhone(subId); |
| 3159 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3160 | } finally { |
| 3161 | Binder.restoreCallingIdentity(identity); |
| 3162 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3166 | * Send the dialer code if called from the current default dialer or the caller has |
| 3167 | * carrier privilege. |
| 3168 | * @param inputCode The dialer code to send |
| 3169 | */ |
| 3170 | @Override |
| 3171 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3172 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3173 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3174 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3175 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3176 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3177 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3178 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3179 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3180 | |
| 3181 | final long identity = Binder.clearCallingIdentity(); |
| 3182 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3183 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3184 | } finally { |
| 3185 | Binder.restoreCallingIdentity(identity); |
| 3186 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3187 | } |
| 3188 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3189 | @Override |
| 3190 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3191 | TelephonyPermissions |
| 3192 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3193 | mApp, subId, "getNetworkSelectionMode"); |
| 3194 | final long identity = Binder.clearCallingIdentity(); |
| 3195 | try { |
| 3196 | if (!isActiveSubscription(subId)) { |
| 3197 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3198 | } |
| 3199 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3200 | } finally { |
| 3201 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3202 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3203 | } |
| 3204 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3205 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3206 | public boolean isInEmergencySmsMode() { |
| 3207 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3208 | final long identity = Binder.clearCallingIdentity(); |
| 3209 | try { |
| 3210 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3211 | if (phone.isInEmergencySmsMode()) { |
| 3212 | return true; |
| 3213 | } |
| 3214 | } |
| 3215 | } finally { |
| 3216 | Binder.restoreCallingIdentity(identity); |
| 3217 | } |
| 3218 | return false; |
| 3219 | } |
| 3220 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3221 | /** |
| 3222 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3223 | * @param subId The subscription to use to check the configuration. |
| 3224 | * @param c The callback that will be used to send the result. |
| 3225 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3226 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3227 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3228 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3229 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3230 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3231 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3232 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3233 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3234 | "IMS not available on device."); |
| 3235 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3236 | final long token = Binder.clearCallingIdentity(); |
| 3237 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3238 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3239 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3240 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3241 | } catch (ImsException e) { |
| 3242 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3243 | } finally { |
| 3244 | Binder.restoreCallingIdentity(token); |
| 3245 | } |
| 3246 | } |
| 3247 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3248 | /** |
| 3249 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3250 | * @param subId The subscription to use to check the configuration. |
| 3251 | * @param c The callback that will be used to send the result. |
| 3252 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3253 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3254 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3255 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3256 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3257 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3258 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3259 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3260 | final long token = Binder.clearCallingIdentity(); |
| 3261 | try { |
| 3262 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3263 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3264 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3265 | } catch (ImsException e) { |
| 3266 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3267 | + "is inactive, ignoring unregister."); |
| 3268 | // If the subscription is no longer active, just return, since the callback |
| 3269 | // will already have been removed internally. |
| 3270 | } finally { |
| 3271 | Binder.restoreCallingIdentity(token); |
| 3272 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3273 | } |
| 3274 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3275 | /** |
| 3276 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3277 | */ |
| 3278 | @Override |
| 3279 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3280 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3281 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3282 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3283 | "IMS not available on device."); |
| 3284 | } |
| 3285 | final long token = Binder.clearCallingIdentity(); |
| 3286 | try { |
| 3287 | Phone phone = getPhone(subId); |
| 3288 | if (phone == null) { |
| 3289 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3290 | + subId + "'"); |
| 3291 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3292 | } |
| 3293 | phone.getImsRegistrationState(regState -> { |
| 3294 | try { |
| 3295 | consumer.accept((regState == null) |
| 3296 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3297 | } catch (RemoteException e) { |
| 3298 | // Ignore if the remote process is no longer available to call back. |
| 3299 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3300 | } |
| 3301 | }); |
| 3302 | } finally { |
| 3303 | Binder.restoreCallingIdentity(token); |
| 3304 | } |
| 3305 | } |
| 3306 | |
| 3307 | /** |
| 3308 | * Get the transport type for the IMS service registration state. |
| 3309 | */ |
| 3310 | @Override |
| 3311 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3312 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3313 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3314 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3315 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3316 | "IMS not available on device."); |
| 3317 | } |
| 3318 | final long token = Binder.clearCallingIdentity(); |
| 3319 | try { |
| 3320 | Phone phone = getPhone(subId); |
| 3321 | if (phone == null) { |
| 3322 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3323 | + subId + "'"); |
| 3324 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3325 | } |
| 3326 | phone.getImsRegistrationTech(regTech -> { |
| 3327 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3328 | int regTechConverted = (regTech == null) |
| 3329 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3330 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3331 | regTechConverted); |
| 3332 | try { |
| 3333 | consumer.accept(regTechConverted); |
| 3334 | } catch (RemoteException e) { |
| 3335 | // Ignore if the remote process is no longer available to call back. |
| 3336 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3337 | } |
| 3338 | }); |
| 3339 | } finally { |
| 3340 | Binder.restoreCallingIdentity(token); |
| 3341 | } |
| 3342 | } |
| 3343 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3344 | /** |
| 3345 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3346 | * @param subId The subscription to use to check the configuration. |
| 3347 | * @param c The callback that will be used to send the result. |
| 3348 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3349 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3350 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3351 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3352 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3353 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3354 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3355 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3356 | "IMS not available on device."); |
| 3357 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3358 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3359 | final long token = Binder.clearCallingIdentity(); |
| 3360 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3361 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3362 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3363 | } catch (ImsException e) { |
| 3364 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3365 | } finally { |
| 3366 | Binder.restoreCallingIdentity(token); |
| 3367 | } |
| 3368 | } |
| 3369 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3370 | /** |
| 3371 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3372 | * @param subId The subscription to use to check the configuration. |
| 3373 | * @param c The callback that will be used to send the result. |
| 3374 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3375 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3376 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3377 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3378 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3379 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3380 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3381 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3382 | |
| 3383 | final long token = Binder.clearCallingIdentity(); |
| 3384 | try { |
| 3385 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3386 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3387 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3388 | } catch (ImsException e) { |
| 3389 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3390 | + "is inactive, ignoring unregister."); |
| 3391 | // If the subscription is no longer active, just return, since the callback |
| 3392 | // will already have been removed internally. |
| 3393 | } finally { |
| 3394 | Binder.restoreCallingIdentity(token); |
| 3395 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3396 | } |
| 3397 | |
| 3398 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3399 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3400 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3401 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3402 | final long token = Binder.clearCallingIdentity(); |
| 3403 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3404 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3405 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3406 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3407 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3408 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3409 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3410 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3411 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3412 | } finally { |
| 3413 | Binder.restoreCallingIdentity(token); |
| 3414 | } |
| 3415 | } |
| 3416 | |
| 3417 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3418 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3419 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3420 | final long token = Binder.clearCallingIdentity(); |
| 3421 | try { |
| 3422 | Phone phone = getPhone(subId); |
| 3423 | if (phone == null) return false; |
| 3424 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3425 | } finally { |
| 3426 | Binder.restoreCallingIdentity(token); |
| 3427 | } |
| 3428 | } |
| 3429 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3430 | /** |
| 3431 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3432 | * subscription. |
| 3433 | * @param subId The subscription to use to check the configuration. |
| 3434 | * @param callback The callback that will be used to send the result. |
| 3435 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3436 | * @param transportType The transport type of the MmTelFeature capability. |
| 3437 | */ |
| 3438 | @Override |
| 3439 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3440 | int transportType) { |
| 3441 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3442 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3443 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3444 | "IMS not available on device."); |
| 3445 | } |
| 3446 | final long token = Binder.clearCallingIdentity(); |
| 3447 | try { |
| 3448 | int slotId = getSlotIndex(subId); |
| 3449 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3450 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3451 | + subId + "'"); |
| 3452 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3453 | } |
| 3454 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3455 | transportType, aBoolean -> { |
| 3456 | try { |
| 3457 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3458 | } catch (RemoteException e) { |
| 3459 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3460 | + "running. Ignore"); |
| 3461 | } |
| 3462 | }); |
| 3463 | } finally { |
| 3464 | Binder.restoreCallingIdentity(token); |
| 3465 | } |
| 3466 | } |
| 3467 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3468 | /** |
| 3469 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3470 | * @param subId The subscription to use to check the configuration. |
| 3471 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3472 | @Override |
| 3473 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3474 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3475 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3476 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3477 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3478 | final long token = Binder.clearCallingIdentity(); |
| 3479 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3480 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3481 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3482 | } catch (ImsException e) { |
| 3483 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3484 | } finally { |
| 3485 | Binder.restoreCallingIdentity(token); |
| 3486 | } |
| 3487 | } |
| 3488 | |
| 3489 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3490 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3491 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3492 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3493 | final long identity = Binder.clearCallingIdentity(); |
| 3494 | try { |
| 3495 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3496 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3497 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3498 | } catch (ImsException e) { |
| 3499 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3500 | } finally { |
| 3501 | Binder.restoreCallingIdentity(identity); |
| 3502 | } |
| 3503 | } |
| 3504 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3505 | /** |
| 3506 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3507 | * @param subId The subscription to use to check the configuration. |
| 3508 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3509 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3510 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3511 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3512 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3513 | final long identity = Binder.clearCallingIdentity(); |
| 3514 | try { |
| 3515 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3516 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3517 | } catch (ImsException e) { |
| 3518 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3519 | } finally { |
| 3520 | Binder.restoreCallingIdentity(identity); |
| 3521 | } |
| 3522 | } |
| 3523 | |
| 3524 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3525 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3526 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3527 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3528 | final long identity = Binder.clearCallingIdentity(); |
| 3529 | try { |
| 3530 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3531 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3532 | } catch (ImsException e) { |
| 3533 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3534 | } finally { |
| 3535 | Binder.restoreCallingIdentity(identity); |
| 3536 | } |
| 3537 | } |
| 3538 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3539 | /** |
| 3540 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3541 | * @param subId The subscription to use to check the configuration. |
| 3542 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3543 | @Override |
| 3544 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3545 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3546 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3547 | final long identity = Binder.clearCallingIdentity(); |
| 3548 | try { |
| 3549 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3550 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3551 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3552 | } catch (ImsException e) { |
| 3553 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3554 | } finally { |
| 3555 | Binder.restoreCallingIdentity(identity); |
| 3556 | } |
| 3557 | } |
| 3558 | |
| 3559 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3560 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3561 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3562 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3563 | final long identity = Binder.clearCallingIdentity(); |
| 3564 | try { |
| 3565 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3566 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3567 | } catch (ImsException e) { |
| 3568 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3569 | } finally { |
| 3570 | Binder.restoreCallingIdentity(identity); |
| 3571 | } |
| 3572 | } |
| 3573 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3574 | /** |
| 3575 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3576 | * @param subId The subscription to use to check the configuration. |
| 3577 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3578 | @Override |
| 3579 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3580 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3581 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3582 | final long identity = Binder.clearCallingIdentity(); |
| 3583 | try { |
| 3584 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3585 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3586 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3587 | } catch (ImsException e) { |
| 3588 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3589 | } finally { |
| 3590 | Binder.restoreCallingIdentity(identity); |
| 3591 | } |
| 3592 | } |
| 3593 | |
| 3594 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3595 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3596 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3597 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3598 | final long identity = Binder.clearCallingIdentity(); |
| 3599 | try { |
| 3600 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3601 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3602 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3603 | } catch (ImsException e) { |
| 3604 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3605 | } finally { |
| 3606 | Binder.restoreCallingIdentity(identity); |
| 3607 | } |
| 3608 | } |
| 3609 | |
| 3610 | @Override |
| 3611 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3612 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3613 | "setVoWiFiNonPersistent"); |
| 3614 | final long identity = Binder.clearCallingIdentity(); |
| 3615 | try { |
| 3616 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3617 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3618 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3619 | } catch (ImsException e) { |
| 3620 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3621 | } finally { |
| 3622 | Binder.restoreCallingIdentity(identity); |
| 3623 | } |
| 3624 | } |
| 3625 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3626 | /** |
| 3627 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3628 | * @param subId The subscription to use to check the configuration. |
| 3629 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3630 | @Override |
| 3631 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3632 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3633 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3634 | final long identity = Binder.clearCallingIdentity(); |
| 3635 | try { |
| 3636 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3637 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3638 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3639 | } catch (ImsException e) { |
| 3640 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3641 | } finally { |
| 3642 | Binder.restoreCallingIdentity(identity); |
| 3643 | } |
| 3644 | } |
| 3645 | |
| 3646 | @Override |
| 3647 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3648 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3649 | "setVoWiFiModeSetting"); |
| 3650 | final long identity = Binder.clearCallingIdentity(); |
| 3651 | try { |
| 3652 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3653 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3654 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3655 | } catch (ImsException e) { |
| 3656 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3657 | } finally { |
| 3658 | Binder.restoreCallingIdentity(identity); |
| 3659 | } |
| 3660 | } |
| 3661 | |
| 3662 | @Override |
| 3663 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3664 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3665 | final long identity = Binder.clearCallingIdentity(); |
| 3666 | try { |
| 3667 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3668 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3669 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3670 | } catch (ImsException e) { |
| 3671 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3672 | } finally { |
| 3673 | Binder.restoreCallingIdentity(identity); |
| 3674 | } |
| 3675 | } |
| 3676 | |
| 3677 | @Override |
| 3678 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3679 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3680 | "setVoWiFiRoamingModeSetting"); |
| 3681 | final long identity = Binder.clearCallingIdentity(); |
| 3682 | try { |
| 3683 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3684 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3685 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3686 | } catch (ImsException e) { |
| 3687 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3688 | } finally { |
| 3689 | Binder.restoreCallingIdentity(identity); |
| 3690 | } |
| 3691 | } |
| 3692 | |
| 3693 | @Override |
| 3694 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3695 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3696 | "setRttCapabilityEnabled"); |
| 3697 | final long identity = Binder.clearCallingIdentity(); |
| 3698 | try { |
| 3699 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3700 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3701 | } catch (ImsException e) { |
| 3702 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3703 | } finally { |
| 3704 | Binder.restoreCallingIdentity(identity); |
| 3705 | } |
| 3706 | } |
| 3707 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3708 | /** |
| 3709 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3710 | * @param subId The subscription to use to check the configuration. |
| 3711 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3712 | @Override |
| 3713 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3714 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3715 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3716 | final long identity = Binder.clearCallingIdentity(); |
| 3717 | try { |
| 3718 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3719 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3720 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3721 | } catch (ImsException e) { |
| 3722 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3723 | } finally { |
| 3724 | Binder.restoreCallingIdentity(identity); |
| 3725 | } |
| 3726 | } |
| 3727 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3728 | @Override |
| 3729 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3730 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3731 | final long identity = Binder.clearCallingIdentity(); |
| 3732 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3733 | if (!isImsAvailableOnDevice()) { |
| 3734 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3735 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3736 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3737 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3738 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3739 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3740 | } catch (ImsException e) { |
| 3741 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3742 | } finally { |
| 3743 | Binder.restoreCallingIdentity(identity); |
| 3744 | } |
| 3745 | } |
| 3746 | |
| 3747 | @Override |
| 3748 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3749 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3750 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3751 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3752 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3753 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3754 | try { |
| 3755 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3756 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3757 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3758 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3759 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3760 | + "is inactive, ignoring unregister."); |
| 3761 | // If the subscription is no longer active, just return, since the callback will already |
| 3762 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3763 | } finally { |
| 3764 | Binder.restoreCallingIdentity(identity); |
| 3765 | } |
| 3766 | } |
| 3767 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3768 | |
| 3769 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3770 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3771 | message); |
| 3772 | } |
| 3773 | |
| 3774 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3775 | boolean isMmtelCapability) { |
| 3776 | Phone phone = getPhone(subId); |
| 3777 | if (phone == null) { |
| 3778 | loge("phone instance null for subid " + subId); |
| 3779 | return false; |
| 3780 | } |
| 3781 | if (isMmtelCapability) { |
| 3782 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3783 | return false; |
| 3784 | } |
| 3785 | } else { |
| 3786 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3787 | return false; |
| 3788 | } |
| 3789 | } |
| 3790 | return true; |
| 3791 | } |
| 3792 | |
| 3793 | @Override |
| 3794 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3795 | boolean isProvisioned) { |
| 3796 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3797 | |
| 3798 | final long identity = Binder.clearCallingIdentity(); |
| 3799 | try { |
| 3800 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3801 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3802 | return; |
| 3803 | } |
| 3804 | |
| 3805 | // this capability requires provisioning, route to the correct API. |
| 3806 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3807 | switch (capability) { |
| 3808 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3809 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3810 | ims.setEabProvisioned(isProvisioned); |
| 3811 | break; |
| 3812 | default: { |
| 3813 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3814 | + "rcs capability '" + capability + "', which does not require " |
| 3815 | + "provisioning."); |
| 3816 | } |
| 3817 | } |
| 3818 | } finally { |
| 3819 | Binder.restoreCallingIdentity(identity); |
| 3820 | } |
| 3821 | |
| 3822 | } |
| 3823 | |
| 3824 | |
| 3825 | @Override |
| 3826 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3827 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3828 | final long identity = Binder.clearCallingIdentity(); |
| 3829 | try { |
| 3830 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3831 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3832 | return true; |
| 3833 | } |
| 3834 | |
| 3835 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3836 | switch (capability) { |
| 3837 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3838 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3839 | return ims.isEabProvisionedOnDevice(); |
| 3840 | |
| 3841 | default: { |
| 3842 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3843 | + "capability '" + capability + "', which does not require " |
| 3844 | + "provisioning."); |
| 3845 | } |
| 3846 | } |
| 3847 | |
| 3848 | } finally { |
| 3849 | Binder.restoreCallingIdentity(identity); |
| 3850 | } |
| 3851 | } |
| 3852 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3853 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3854 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3855 | boolean isProvisioned) { |
| 3856 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3857 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3858 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3859 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3860 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3861 | final long identity = Binder.clearCallingIdentity(); |
| 3862 | try { |
| 3863 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3864 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3865 | return; |
| 3866 | } |
| 3867 | |
| 3868 | // this capability requires provisioning, route to the correct API. |
| 3869 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3870 | switch (capability) { |
| 3871 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3872 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3873 | ims.setVolteProvisioned(isProvisioned); |
| 3874 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3875 | ims.setWfcProvisioned(isProvisioned); |
| 3876 | } |
| 3877 | break; |
| 3878 | } |
| 3879 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3880 | // There is currently no difference in VT provisioning type. |
| 3881 | ims.setVtProvisioned(isProvisioned); |
| 3882 | break; |
| 3883 | } |
| 3884 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3885 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3886 | // change the capability of the feature instead if needed. |
| 3887 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3888 | == isProvisioned) { |
| 3889 | // No change in provisioning. |
| 3890 | return; |
| 3891 | } |
| 3892 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3893 | try { |
| 3894 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3895 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3896 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3897 | + ", Exception" + e.getMessage()); |
| 3898 | } |
| 3899 | break; |
| 3900 | } |
| 3901 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3902 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3903 | + "MmTel capability '" + capability + "', which does not require " |
| 3904 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3905 | } |
| 3906 | } |
| 3907 | |
| 3908 | } finally { |
| 3909 | Binder.restoreCallingIdentity(identity); |
| 3910 | } |
| 3911 | } |
| 3912 | |
| 3913 | @Override |
| 3914 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3915 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3916 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3917 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3918 | } |
| 3919 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3920 | final long identity = Binder.clearCallingIdentity(); |
| 3921 | try { |
| 3922 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3923 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3924 | return true; |
| 3925 | } |
| 3926 | |
| 3927 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3928 | switch (capability) { |
| 3929 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3930 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3931 | return ims.isVolteProvisionedOnDevice(); |
| 3932 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3933 | return ims.isWfcProvisionedOnDevice(); |
| 3934 | } |
| 3935 | // This should never happen, since we are checking tech above to make sure it |
| 3936 | // is either LTE or IWLAN. |
| 3937 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3938 | + "capability."); |
| 3939 | } |
| 3940 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3941 | // There is currently no difference in VT provisioning type. |
| 3942 | return ims.isVtProvisionedOnDevice(); |
| 3943 | } |
| 3944 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3945 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3946 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3947 | } |
| 3948 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3949 | throw new IllegalArgumentException( |
| 3950 | "Tried to get provisioning for MmTel capability '" + capability |
| 3951 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3952 | } |
| 3953 | } |
| 3954 | |
| 3955 | } finally { |
| 3956 | Binder.restoreCallingIdentity(identity); |
| 3957 | } |
| 3958 | } |
| 3959 | |
| 3960 | @Override |
| 3961 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3962 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3963 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3964 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3965 | } |
| 3966 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3967 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3968 | return (provisionedBits & capability) > 0; |
| 3969 | } |
| 3970 | |
| 3971 | @Override |
| 3972 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3973 | boolean isProvisioned) { |
| 3974 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3975 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3976 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3977 | } |
| 3978 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3979 | "setProvisioningStatusForCapability"); |
| 3980 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3981 | // If the current provisioning status for capability already matches isProvisioned, |
| 3982 | // do nothing. |
| 3983 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3984 | return; |
| 3985 | } |
| 3986 | if (isProvisioned) { |
| 3987 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3988 | } else { |
| 3989 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3990 | } |
| 3991 | } |
| 3992 | |
| 3993 | /** |
| 3994 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3995 | * technology. The bitfield should mirror the bitfield defined by |
| 3996 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3997 | */ |
| 3998 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3999 | String key = getMmTelProvisioningKey(subId, tech); |
| 4000 | // Default is no capabilities are provisioned. |
| 4001 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4002 | } |
| 4003 | |
| 4004 | /** |
| 4005 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4006 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4007 | * technology specified. |
| 4008 | * |
| 4009 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4010 | */ |
| 4011 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4012 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4013 | String key = getMmTelProvisioningKey(subId, tech); |
| 4014 | editor.putInt(key, newField); |
| 4015 | editor.commit(); |
| 4016 | } |
| 4017 | |
| 4018 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4019 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4020 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4021 | } |
| 4022 | |
| 4023 | /** |
| 4024 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4025 | * carrier associated with the subscription id. |
| 4026 | */ |
| 4027 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4028 | int capability) { |
| 4029 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4030 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4031 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4032 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4033 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4034 | false); |
| 4035 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4036 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4037 | |
| 4038 | // First check to make sure that the capability requires provisioning. |
| 4039 | switch (capability) { |
| 4040 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4041 | // intentional fallthrough |
| 4042 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4043 | if (requireVoiceVtProvisioning) { |
| 4044 | // Voice and Video requires provisioning |
| 4045 | return true; |
| 4046 | } |
| 4047 | break; |
| 4048 | } |
| 4049 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4050 | if (requireUtProvisioning) { |
| 4051 | // UT requires provisioning |
| 4052 | return true; |
| 4053 | } |
| 4054 | break; |
| 4055 | } |
| 4056 | } |
| 4057 | return false; |
| 4058 | } |
| 4059 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4060 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4061 | int capability) { |
| 4062 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4063 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4064 | |
| 4065 | boolean requireRcsProvisioning = c.getBoolean( |
| 4066 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4067 | |
| 4068 | // First check to make sure that the capability requires provisioning. |
| 4069 | switch (capability) { |
| 4070 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4071 | // intentional fallthrough |
| 4072 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4073 | if (requireRcsProvisioning) { |
| 4074 | // OPTION or PRESENCE requires provisioning |
| 4075 | return true; |
| 4076 | } |
| 4077 | break; |
| 4078 | } |
| 4079 | } |
| 4080 | return false; |
| 4081 | } |
| 4082 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4083 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4084 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4085 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4086 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4087 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4088 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4089 | final long identity = Binder.clearCallingIdentity(); |
| 4090 | try { |
| 4091 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4092 | int slotId = getSlotIndex(subId); |
| 4093 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4094 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4095 | + subId + "' for key:" + key); |
| 4096 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4097 | } |
| 4098 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4099 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4100 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4101 | + subId + "' for key:" + key); |
| 4102 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4103 | } finally { |
| 4104 | Binder.restoreCallingIdentity(identity); |
| 4105 | } |
| 4106 | } |
| 4107 | |
| 4108 | @Override |
| 4109 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4110 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4111 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4112 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4113 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4114 | final long identity = Binder.clearCallingIdentity(); |
| 4115 | try { |
| 4116 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4117 | int slotId = getSlotIndex(subId); |
| 4118 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4119 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4120 | + subId + "' for key:" + key); |
| 4121 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4122 | } |
| 4123 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4124 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4125 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4126 | + subId + "' for key:" + key); |
| 4127 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4128 | } finally { |
| 4129 | Binder.restoreCallingIdentity(identity); |
| 4130 | } |
| 4131 | } |
| 4132 | |
| 4133 | @Override |
| 4134 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4135 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4136 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4137 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4138 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4139 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4140 | final long identity = Binder.clearCallingIdentity(); |
| 4141 | try { |
| 4142 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4143 | int slotId = getSlotIndex(subId); |
| 4144 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4145 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4146 | + subId + "' for key:" + key); |
| 4147 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4148 | } |
| 4149 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4150 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4151 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4152 | + "' for key:" + key); |
| 4153 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4154 | } finally { |
| 4155 | Binder.restoreCallingIdentity(identity); |
| 4156 | } |
| 4157 | } |
| 4158 | |
| 4159 | @Override |
| 4160 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4161 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4162 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4163 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4164 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4165 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4166 | final long identity = Binder.clearCallingIdentity(); |
| 4167 | try { |
| 4168 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4169 | int slotId = getSlotIndex(subId); |
| 4170 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4171 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4172 | + subId + "' for key:" + key); |
| 4173 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4174 | } |
| 4175 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4176 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4177 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4178 | + "' for key:" + key); |
| 4179 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4180 | } finally { |
| 4181 | Binder.restoreCallingIdentity(identity); |
| 4182 | } |
| 4183 | } |
| 4184 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4185 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4186 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4187 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4188 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4189 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4190 | } |
| 4191 | return slotId; |
| 4192 | } |
| 4193 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4194 | private int getSlotIndex(int subId) { |
| 4195 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4196 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4197 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4198 | } |
| 4199 | return slotId; |
| 4200 | } |
| 4201 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4202 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4203 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4204 | */ |
| 4205 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4206 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4207 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4208 | final int targetSdk = getTargetSdk(callingPackage); |
| 4209 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4210 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4211 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4212 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4213 | mApp, subId, callingPackage, callingFeatureId, |
| 4214 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4215 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4216 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4217 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4218 | final long identity = Binder.clearCallingIdentity(); |
| 4219 | try { |
| 4220 | final Phone phone = getPhone(subId); |
| 4221 | if (phone != null) { |
| 4222 | return phone.getServiceState().getDataNetworkType(); |
| 4223 | } else { |
| 4224 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4225 | } |
| 4226 | } finally { |
| 4227 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4228 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4229 | } |
| 4230 | |
| 4231 | /** |
| 4232 | * Returns the data network type |
| 4233 | */ |
| 4234 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4235 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4236 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4237 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4238 | } |
| 4239 | |
| 4240 | /** |
| 4241 | * Returns the data network type for a subId |
| 4242 | */ |
| 4243 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4244 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4245 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4246 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4247 | mApp, subId, callingPackage, callingFeatureId, |
| 4248 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4249 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4250 | } |
| 4251 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4252 | final long identity = Binder.clearCallingIdentity(); |
| 4253 | try { |
| 4254 | final Phone phone = getPhone(subId); |
| 4255 | if (phone != null) { |
| 4256 | return phone.getServiceState().getDataNetworkType(); |
| 4257 | } else { |
| 4258 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4259 | } |
| 4260 | } finally { |
| 4261 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4262 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4263 | } |
| 4264 | |
| 4265 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4266 | * Returns the Voice network type for a subId |
| 4267 | */ |
| 4268 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4269 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4270 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4271 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4272 | mApp, subId, callingPackage, callingFeatureId, |
| 4273 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4274 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4275 | } |
| 4276 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4277 | final long identity = Binder.clearCallingIdentity(); |
| 4278 | try { |
| 4279 | final Phone phone = getPhone(subId); |
| 4280 | if (phone != null) { |
| 4281 | return phone.getServiceState().getVoiceNetworkType(); |
| 4282 | } else { |
| 4283 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4284 | } |
| 4285 | } finally { |
| 4286 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4287 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4288 | } |
| 4289 | |
| 4290 | /** |
| 4291 | * @return true if a ICC card is present |
| 4292 | */ |
| 4293 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4294 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4295 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4296 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4297 | } |
| 4298 | |
| 4299 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4300 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4301 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4302 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4303 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4304 | final long identity = Binder.clearCallingIdentity(); |
| 4305 | try { |
| 4306 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4307 | if (phone != null) { |
| 4308 | return phone.getIccCard().hasIccCard(); |
| 4309 | } else { |
| 4310 | return false; |
| 4311 | } |
| 4312 | } finally { |
| 4313 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4314 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4315 | } |
| 4316 | |
| 4317 | /** |
| 4318 | * Return if the current radio is LTE on CDMA. This |
| 4319 | * is a tri-state return value as for a period of time |
| 4320 | * the mode may be unknown. |
| 4321 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4322 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4323 | * @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] | 4324 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4325 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4326 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4327 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4328 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4329 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4330 | } |
| 4331 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4332 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4333 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4334 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4335 | try { |
| 4336 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4337 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4338 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4339 | } |
| 4340 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4341 | final long identity = Binder.clearCallingIdentity(); |
| 4342 | try { |
| 4343 | final Phone phone = getPhone(subId); |
| 4344 | if (phone == null) { |
| 4345 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4346 | } else { |
| 4347 | return phone.getLteOnCdmaMode(); |
| 4348 | } |
| 4349 | } finally { |
| 4350 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4351 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4352 | } |
| 4353 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4354 | /** |
| 4355 | * {@hide} |
| 4356 | * Returns Default subId, 0 in the case of single standby. |
| 4357 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4358 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4359 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4360 | } |
| 4361 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4362 | private int getSlotForDefaultSubscription() { |
| 4363 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4364 | } |
| 4365 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4366 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4367 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4368 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4369 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4370 | private boolean isActiveSubscription(int subId) { |
| 4371 | return mSubscriptionController.isActiveSubId(subId); |
| 4372 | } |
| 4373 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4374 | /** |
| 4375 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4376 | */ |
| 4377 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4378 | final long identity = Binder.clearCallingIdentity(); |
| 4379 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4380 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4381 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4382 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4383 | } finally { |
| 4384 | Binder.restoreCallingIdentity(identity); |
| 4385 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4386 | } |
| 4387 | |
| 4388 | /** |
| 4389 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4390 | */ |
| 4391 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4392 | final long identity = Binder.clearCallingIdentity(); |
| 4393 | try { |
| 4394 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4395 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4396 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4397 | } finally { |
| 4398 | Binder.restoreCallingIdentity(identity); |
| 4399 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4400 | } |
| 4401 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4402 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4403 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4404 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4405 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4406 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4407 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4408 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4409 | if (phoneId == -1) { |
| 4410 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4411 | + " does not correspond to an active phone"); |
| 4412 | } |
| 4413 | return PhoneFactory.getPhone(phoneId); |
| 4414 | } |
| 4415 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4416 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4417 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4418 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4419 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4420 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4421 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4422 | if (DBG) { |
| 4423 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4424 | } |
| 4425 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4426 | p2); |
| 4427 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4428 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4429 | |
| 4430 | @Override |
| 4431 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4432 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4433 | enforceModifyPermission(); |
| 4434 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4435 | if (DBG) { |
| 4436 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4437 | } |
| 4438 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4439 | callingPackage, aid, p2); |
| 4440 | } |
| 4441 | |
| 4442 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4443 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4444 | final long identity = Binder.clearCallingIdentity(); |
| 4445 | try { |
| 4446 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4447 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4448 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4449 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4450 | if (bestComponent == null |
| 4451 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4452 | loge("The calling package is not allowed to access ISD-R."); |
| 4453 | throw new SecurityException( |
| 4454 | "The calling package is not allowed to access ISD-R."); |
| 4455 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4456 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4457 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4458 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4459 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4460 | null /* workSource */); |
| 4461 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4462 | return response; |
| 4463 | } finally { |
| 4464 | Binder.restoreCallingIdentity(identity); |
| 4465 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4466 | } |
| 4467 | |
| 4468 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4469 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4470 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4471 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4472 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4473 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4474 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4475 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4476 | @Override |
| 4477 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4478 | enforceModifyPermission(); |
| 4479 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4480 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4481 | channel); |
| 4482 | } |
| 4483 | |
| 4484 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4485 | final long identity = Binder.clearCallingIdentity(); |
| 4486 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4487 | if (channel < 0) { |
| 4488 | return false; |
| 4489 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4490 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4491 | null /* workSource */); |
| 4492 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4493 | return success; |
| 4494 | } finally { |
| 4495 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4496 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4497 | } |
| 4498 | |
| 4499 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4500 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4501 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4502 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4503 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4504 | if (DBG) { |
| 4505 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4506 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4507 | + p3 + " data=" + data); |
| 4508 | } |
| 4509 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4510 | command, p1, p2, p3, data); |
| 4511 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4512 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4513 | @Override |
| 4514 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4515 | int command, int p1, int p2, int p3, String data) { |
| 4516 | enforceModifyPermission(); |
| 4517 | if (DBG) { |
| 4518 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4519 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4520 | + p3 + " data=" + data); |
| 4521 | } |
| 4522 | return iccTransmitApduLogicalChannelWithPermission( |
| 4523 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4524 | data); |
| 4525 | } |
| 4526 | |
| 4527 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4528 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4529 | final long identity = Binder.clearCallingIdentity(); |
| 4530 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4531 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4532 | return ""; |
| 4533 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4534 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4535 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4536 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4537 | null /* workSource */); |
| 4538 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4539 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4540 | // Append the returned status code to the end of the response payload. |
| 4541 | String s = Integer.toHexString( |
| 4542 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4543 | if (response.payload != null) { |
| 4544 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4545 | } |
| 4546 | return s; |
| 4547 | } finally { |
| 4548 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4549 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4550 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4551 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4552 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4553 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4554 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4555 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4556 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4557 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4558 | if (DBG) { |
| 4559 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4560 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4561 | } |
| 4562 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4563 | cla, command, p1, p2, p3, data); |
| 4564 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4565 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4566 | @Override |
| 4567 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4568 | int command, int p1, int p2, int p3, String data) { |
| 4569 | enforceModifyPermission(); |
| 4570 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4571 | if (DBG) { |
| 4572 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4573 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4574 | + " data=" + data); |
| 4575 | } |
| 4576 | |
| 4577 | return iccTransmitApduBasicChannelWithPermission( |
| 4578 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4579 | p2, p3, data); |
| 4580 | } |
| 4581 | |
| 4582 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4583 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4584 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4585 | final long identity = Binder.clearCallingIdentity(); |
| 4586 | try { |
| 4587 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4588 | && TextUtils.equals(ISDR_AID, data)) { |
| 4589 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4590 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4591 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4592 | if (bestComponent == null |
| 4593 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4594 | loge("The calling package is not allowed to select ISD-R."); |
| 4595 | throw new SecurityException( |
| 4596 | "The calling package is not allowed to select ISD-R."); |
| 4597 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4598 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4599 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4600 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4601 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4602 | null /* workSource */); |
| 4603 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4604 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4605 | // Append the returned status code to the end of the response payload. |
| 4606 | String s = Integer.toHexString( |
| 4607 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4608 | if (response.payload != null) { |
| 4609 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4610 | } |
| 4611 | return s; |
| 4612 | } finally { |
| 4613 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4614 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4615 | } |
| 4616 | |
| 4617 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4618 | 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] | 4619 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4620 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4621 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4622 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4623 | final long identity = Binder.clearCallingIdentity(); |
| 4624 | try { |
| 4625 | if (DBG) { |
| 4626 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4627 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4628 | } |
| 4629 | |
| 4630 | IccIoResult response = |
| 4631 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4632 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4633 | subId); |
| 4634 | |
| 4635 | if (DBG) { |
| 4636 | log("Exchange SIM_IO [R]" + response); |
| 4637 | } |
| 4638 | |
| 4639 | byte[] result = null; |
| 4640 | int length = 2; |
| 4641 | if (response.payload != null) { |
| 4642 | length = 2 + response.payload.length; |
| 4643 | result = new byte[length]; |
| 4644 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4645 | } else { |
| 4646 | result = new byte[length]; |
| 4647 | } |
| 4648 | |
| 4649 | result[length - 1] = (byte) response.sw2; |
| 4650 | result[length - 2] = (byte) response.sw1; |
| 4651 | return result; |
| 4652 | } finally { |
| 4653 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4654 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4655 | } |
| 4656 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4657 | /** |
| 4658 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4659 | * on a particular subscription |
| 4660 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4661 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4662 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4663 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4664 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4665 | return null; |
| 4666 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4667 | |
| 4668 | final long identity = Binder.clearCallingIdentity(); |
| 4669 | try { |
| 4670 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4671 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4672 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4673 | return null; |
| 4674 | } |
| 4675 | Object response = sendRequest( |
| 4676 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4677 | if (response instanceof String[]) { |
| 4678 | return (String[]) response; |
| 4679 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4680 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4681 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4682 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4683 | } finally { |
| 4684 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4685 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4686 | } |
| 4687 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4688 | /** |
| 4689 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4690 | * subscription. |
| 4691 | * |
| 4692 | * @param subId the id of the subscription. |
| 4693 | * @param appType the uicc app type, must be USIM or SIM. |
| 4694 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4695 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4696 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4697 | * @return number of fplmns that is successfully written to the SIM. |
| 4698 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4699 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4700 | String callingFeatureId) { |
| 4701 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4702 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4703 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4704 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4705 | } |
| 4706 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4707 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4708 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4709 | } |
| 4710 | if (fplmns == null) { |
| 4711 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4712 | } |
| 4713 | for (String fplmn : fplmns) { |
| 4714 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4715 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4716 | } |
| 4717 | } |
| 4718 | final long identity = Binder.clearCallingIdentity(); |
| 4719 | try { |
| 4720 | Object response = sendRequest( |
| 4721 | CMD_SET_FORBIDDEN_PLMNS, |
| 4722 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4723 | subId); |
| 4724 | return (int) response; |
| 4725 | } finally { |
| 4726 | Binder.restoreCallingIdentity(identity); |
| 4727 | } |
| 4728 | } |
| 4729 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4730 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4731 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4732 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4733 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4734 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4735 | final long identity = Binder.clearCallingIdentity(); |
| 4736 | try { |
| 4737 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4738 | if (response.payload == null) { |
| 4739 | return ""; |
| 4740 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4741 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4742 | // Append the returned status code to the end of the response payload. |
| 4743 | String s = Integer.toHexString( |
| 4744 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4745 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4746 | return s; |
| 4747 | } finally { |
| 4748 | Binder.restoreCallingIdentity(identity); |
| 4749 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4750 | } |
| 4751 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4752 | /** |
| 4753 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4754 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4755 | * |
| 4756 | * @param itemID the ID of the item to read |
| 4757 | * @return the NV item as a String, or null on error. |
| 4758 | */ |
| 4759 | @Override |
| 4760 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4761 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4762 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4763 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4764 | |
| 4765 | final long identity = Binder.clearCallingIdentity(); |
| 4766 | try { |
| 4767 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4768 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4769 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4770 | return value; |
| 4771 | } finally { |
| 4772 | Binder.restoreCallingIdentity(identity); |
| 4773 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4774 | } |
| 4775 | |
| 4776 | /** |
| 4777 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4778 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4779 | * |
| 4780 | * @param itemID the ID of the item to read |
| 4781 | * @param itemValue the value to write, as a String |
| 4782 | * @return true on success; false on any failure |
| 4783 | */ |
| 4784 | @Override |
| 4785 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4786 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4787 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4788 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4789 | |
| 4790 | final long identity = Binder.clearCallingIdentity(); |
| 4791 | try { |
| 4792 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4793 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4794 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4795 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4796 | return success; |
| 4797 | } finally { |
| 4798 | Binder.restoreCallingIdentity(identity); |
| 4799 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4800 | } |
| 4801 | |
| 4802 | /** |
| 4803 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4804 | * Used for device configuration by some CDMA operators. |
| 4805 | * |
| 4806 | * @param preferredRoamingList byte array containing the new PRL |
| 4807 | * @return true on success; false on any failure |
| 4808 | */ |
| 4809 | @Override |
| 4810 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4811 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4812 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4813 | |
| 4814 | final long identity = Binder.clearCallingIdentity(); |
| 4815 | try { |
| 4816 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4817 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4818 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4819 | return success; |
| 4820 | } finally { |
| 4821 | Binder.restoreCallingIdentity(identity); |
| 4822 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4823 | } |
| 4824 | |
| 4825 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4826 | * 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] | 4827 | * Used for device configuration by some CDMA operators. |
| 4828 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4829 | * @param slotIndex - device slot. |
| 4830 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4831 | * @return true on success; false on any failure |
| 4832 | */ |
| 4833 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4834 | public boolean resetModemConfig(int slotIndex) { |
| 4835 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4836 | if (phone != null) { |
| 4837 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4838 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4839 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4840 | final long identity = Binder.clearCallingIdentity(); |
| 4841 | try { |
| 4842 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4843 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4844 | return success; |
| 4845 | } finally { |
| 4846 | Binder.restoreCallingIdentity(identity); |
| 4847 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4848 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4849 | return false; |
| 4850 | } |
| 4851 | |
| 4852 | /** |
| 4853 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4854 | * |
| 4855 | * @param slotIndex - device slot. |
| 4856 | * |
| 4857 | * @return true on success; false on any failure |
| 4858 | */ |
| 4859 | @Override |
| 4860 | public boolean rebootModem(int slotIndex) { |
| 4861 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4862 | if (phone != null) { |
| 4863 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4864 | mApp, phone.getSubId(), "rebootModem"); |
| 4865 | |
| 4866 | final long identity = Binder.clearCallingIdentity(); |
| 4867 | try { |
| 4868 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4869 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4870 | return success; |
| 4871 | } finally { |
| 4872 | Binder.restoreCallingIdentity(identity); |
| 4873 | } |
| 4874 | } |
| 4875 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4876 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4877 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4878 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4879 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4880 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4881 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4882 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4883 | return new String[0]; |
| 4884 | } |
| 4885 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4886 | final long identity = Binder.clearCallingIdentity(); |
| 4887 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4888 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4889 | } finally { |
| 4890 | Binder.restoreCallingIdentity(identity); |
| 4891 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4892 | } |
| 4893 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4894 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 4895 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 4896 | * {@link #disableIms(int)}. |
| 4897 | * @param slotIndex device slot. |
| 4898 | */ |
| 4899 | public void resetIms(int slotIndex) { |
| 4900 | enforceModifyPermission(); |
| 4901 | |
| 4902 | final long identity = Binder.clearCallingIdentity(); |
| 4903 | try { |
| 4904 | if (mImsResolver == null) { |
| 4905 | // may happen if the does not support IMS. |
| 4906 | return; |
| 4907 | } |
| 4908 | mImsResolver.disableIms(slotIndex); |
| 4909 | mImsResolver.enableIms(slotIndex); |
| 4910 | } finally { |
| 4911 | Binder.restoreCallingIdentity(identity); |
| 4912 | } |
| 4913 | } |
| 4914 | |
| 4915 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4916 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4917 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4918 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4919 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4920 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4921 | |
| 4922 | final long identity = Binder.clearCallingIdentity(); |
| 4923 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4924 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4925 | // may happen if the device does not support IMS. |
| 4926 | return; |
| 4927 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4928 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4929 | } finally { |
| 4930 | Binder.restoreCallingIdentity(identity); |
| 4931 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4932 | } |
| 4933 | |
| 4934 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4935 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4936 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4937 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4938 | public void disableIms(int slotId) { |
| 4939 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4940 | |
| 4941 | final long identity = Binder.clearCallingIdentity(); |
| 4942 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4943 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4944 | // may happen if the device does not support IMS. |
| 4945 | return; |
| 4946 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4947 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4948 | } finally { |
| 4949 | Binder.restoreCallingIdentity(identity); |
| 4950 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4951 | } |
| 4952 | |
| 4953 | /** |
| 4954 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4955 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4956 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4957 | */ |
| 4958 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4959 | IImsServiceFeatureCallback callback) { |
| 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 null; |
| 4967 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4968 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4969 | } finally { |
| 4970 | Binder.restoreCallingIdentity(identity); |
| 4971 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4972 | } |
| 4973 | |
| 4974 | /** |
| 4975 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4976 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4977 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4978 | * listener for feature updates. |
| 4979 | */ |
| 4980 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, 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.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4990 | } finally { |
| 4991 | Binder.restoreCallingIdentity(identity); |
| 4992 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4993 | } |
| 4994 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4995 | /** |
| 4996 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4997 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4998 | */ |
| 4999 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5000 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5001 | |
| 5002 | final long identity = Binder.clearCallingIdentity(); |
| 5003 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5004 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5005 | // may happen if the device does not support IMS. |
| 5006 | return null; |
| 5007 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5008 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5009 | } finally { |
| 5010 | Binder.restoreCallingIdentity(identity); |
| 5011 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5012 | } |
| 5013 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5014 | /** |
| 5015 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5016 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5017 | */ |
| 5018 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5019 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5020 | |
| 5021 | final long identity = Binder.clearCallingIdentity(); |
| 5022 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5023 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5024 | // may happen if the device does not support IMS. |
| 5025 | return null; |
| 5026 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5027 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5028 | } finally { |
| 5029 | Binder.restoreCallingIdentity(identity); |
| 5030 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5031 | } |
| 5032 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5033 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5034 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5035 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5036 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5037 | * @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] | 5038 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5039 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5040 | * @param packageName The name of the package that the current configuration will be replaced |
| 5041 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5042 | * @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] | 5043 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5044 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5045 | int[] featureTypes, String packageName) { |
| 5046 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5047 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5048 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5049 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5050 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5051 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5052 | final long identity = Binder.clearCallingIdentity(); |
| 5053 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5054 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5055 | // may happen if the device does not support IMS. |
| 5056 | return false; |
| 5057 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5058 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5059 | for (int featureType : featureTypes) { |
| 5060 | featureConfig.put(featureType, packageName); |
| 5061 | } |
| 5062 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5063 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5064 | } finally { |
| 5065 | Binder.restoreCallingIdentity(identity); |
| 5066 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5067 | } |
| 5068 | |
| 5069 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5070 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5071 | * |
| 5072 | * @param slotId The slot that the ImsService is associated with. |
| 5073 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5074 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5075 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5076 | * @return the package name of the ImsService configuration. |
| 5077 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5078 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5079 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5080 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5081 | TelephonyPermissions |
| 5082 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5083 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5084 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5085 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5086 | final long identity = Binder.clearCallingIdentity(); |
| 5087 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5088 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5089 | // may happen if the device does not support IMS. |
| 5090 | return ""; |
| 5091 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5092 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5093 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5094 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5095 | } finally { |
| 5096 | Binder.restoreCallingIdentity(identity); |
| 5097 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5098 | } |
| 5099 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5100 | /** |
| 5101 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5102 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5103 | * @param callback A callback with an integer containing the |
| 5104 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5105 | */ |
| 5106 | @Override |
| 5107 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5108 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5109 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5110 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5111 | "IMS not available on device."); |
| 5112 | } |
| 5113 | final long token = Binder.clearCallingIdentity(); |
| 5114 | try { |
| 5115 | int slotId = getSlotIndex(subId); |
| 5116 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5117 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5118 | + subId + "'"); |
| 5119 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5120 | } |
| 5121 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5122 | try { |
| 5123 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5124 | } catch (RemoteException e) { |
| 5125 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5126 | + "Ignore"); |
| 5127 | } |
| 5128 | }); |
| 5129 | } finally { |
| 5130 | Binder.restoreCallingIdentity(token); |
| 5131 | } |
| 5132 | } |
| 5133 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5134 | public void setImsRegistrationState(boolean registered) { |
| 5135 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5136 | |
| 5137 | final long identity = Binder.clearCallingIdentity(); |
| 5138 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5139 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5140 | } finally { |
| 5141 | Binder.restoreCallingIdentity(identity); |
| 5142 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5143 | } |
| 5144 | |
| 5145 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5146 | * Set the network selection mode to automatic. |
| 5147 | * |
| 5148 | */ |
| 5149 | @Override |
| 5150 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5151 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5152 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5153 | |
| 5154 | final long identity = Binder.clearCallingIdentity(); |
| 5155 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5156 | if (!isActiveSubscription(subId)) { |
| 5157 | return; |
| 5158 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5159 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5160 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5161 | } finally { |
| 5162 | Binder.restoreCallingIdentity(identity); |
| 5163 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5164 | } |
| 5165 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5166 | /** |
| 5167 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5168 | * |
| 5169 | * @param subId the id of the subscription. |
| 5170 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5171 | * the operator to attach to. |
| 5172 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5173 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5174 | * normal network selection next time. |
| 5175 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5176 | */ |
| 5177 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5178 | public boolean setNetworkSelectionModeManual( |
| 5179 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5180 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5181 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5182 | |
| 5183 | if (!isActiveSubscription(subId)) { |
| 5184 | return false; |
| 5185 | } |
| 5186 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5187 | final long identity = Binder.clearCallingIdentity(); |
| 5188 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5189 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5190 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5191 | if (DBG) { |
| 5192 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5193 | + " operator: " + operatorInfo); |
| 5194 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5195 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5196 | } finally { |
| 5197 | Binder.restoreCallingIdentity(identity); |
| 5198 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5199 | } |
| 5200 | |
| 5201 | /** |
| 5202 | * Scans for available networks. |
| 5203 | */ |
| 5204 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5205 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5206 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5207 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5208 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5209 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5210 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5211 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5212 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5213 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5214 | .setCallingPid(Binder.getCallingPid()) |
| 5215 | .setCallingUid(Binder.getCallingUid()) |
| 5216 | .setMethod("getCellNetworkScanResults") |
| 5217 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5218 | .build()); |
| 5219 | switch (locationResult) { |
| 5220 | case DENIED_HARD: |
| 5221 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5222 | case DENIED_SOFT: |
| 5223 | return null; |
| 5224 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5225 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5226 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5227 | try { |
| 5228 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5229 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5230 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5231 | } finally { |
| 5232 | Binder.restoreCallingIdentity(identity); |
| 5233 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5234 | } |
| 5235 | |
| 5236 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5237 | * Get the call forwarding info, given the call forwarding reason. |
| 5238 | */ |
| 5239 | @Override |
| 5240 | public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) { |
| 5241 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5242 | long identity = Binder.clearCallingIdentity(); |
| 5243 | try { |
| 5244 | if (DBG) { |
| 5245 | log("getCallForwarding: subId " + subId |
| 5246 | + " callForwardingReason" + callForwardingReason); |
| 5247 | } |
| 5248 | return (CallForwardingInfo) sendRequest( |
| 5249 | CMD_GET_CALL_FORWARDING, callForwardingReason, subId); |
| 5250 | } finally { |
| 5251 | Binder.restoreCallingIdentity(identity); |
| 5252 | } |
| 5253 | } |
| 5254 | |
| 5255 | /** |
| 5256 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5257 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5258 | */ |
| 5259 | @Override |
| 5260 | public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) { |
| 5261 | enforceModifyPermission(); |
| 5262 | long identity = Binder.clearCallingIdentity(); |
| 5263 | try { |
| 5264 | if (DBG) { |
| 5265 | log("setCallForwarding: subId " + subId |
| 5266 | + " callForwardingInfo" + callForwardingInfo); |
| 5267 | } |
| 5268 | return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId); |
| 5269 | } finally { |
| 5270 | Binder.restoreCallingIdentity(identity); |
| 5271 | } |
| 5272 | } |
| 5273 | |
| 5274 | /** |
| 5275 | * Get the call forwarding info, given the call forwarding reason. |
| 5276 | */ |
| 5277 | @Override |
| 5278 | public int getCallWaitingStatus(int subId) { |
| 5279 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5280 | long identity = Binder.clearCallingIdentity(); |
| 5281 | try { |
| 5282 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 5283 | return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId); |
| 5284 | } finally { |
| 5285 | Binder.restoreCallingIdentity(identity); |
| 5286 | } |
| 5287 | } |
| 5288 | |
| 5289 | /** |
| 5290 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5291 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5292 | */ |
| 5293 | @Override |
| 5294 | public boolean setCallWaitingStatus(int subId, boolean isEnable) { |
| 5295 | enforceModifyPermission(); |
| 5296 | long identity = Binder.clearCallingIdentity(); |
| 5297 | try { |
| 5298 | if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable); |
| 5299 | return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId); |
| 5300 | } finally { |
| 5301 | Binder.restoreCallingIdentity(identity); |
| 5302 | } |
| 5303 | } |
| 5304 | |
| 5305 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5306 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5307 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5308 | * @param subId id of the subscription |
| 5309 | * @param request contains the radio access networks with bands/channels to scan |
| 5310 | * @param messenger callback messenger for scan results or errors |
| 5311 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5312 | * @return the id of the requested scan which can be used to stop the scan. |
| 5313 | */ |
| 5314 | @Override |
| 5315 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5316 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5317 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5318 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5319 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5320 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5321 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5322 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5323 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5324 | .setCallingPid(Binder.getCallingPid()) |
| 5325 | .setCallingUid(Binder.getCallingUid()) |
| 5326 | .setMethod("requestNetworkScan") |
| 5327 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5328 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5329 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5330 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5331 | if (e != null) { |
| 5332 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5333 | throw e; |
| 5334 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5335 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5336 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5337 | } |
| 5338 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5339 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5340 | int callingUid = Binder.getCallingUid(); |
| 5341 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5342 | final long identity = Binder.clearCallingIdentity(); |
| 5343 | try { |
| 5344 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5345 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5346 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5347 | } finally { |
| 5348 | Binder.restoreCallingIdentity(identity); |
| 5349 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5350 | } |
| 5351 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5352 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5353 | NetworkScanRequest request, int subId) { |
| 5354 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5355 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5356 | boolean hasNetworkScanPermission = |
| 5357 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5358 | == PERMISSION_GRANTED; |
| 5359 | |
| 5360 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5361 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5362 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5363 | } |
| 5364 | |
| 5365 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5366 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5367 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5368 | return new SecurityException("Specific channels must not be" |
| 5369 | + " scanned without location access."); |
| 5370 | } |
| 5371 | } |
| 5372 | } |
| 5373 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5374 | return null; |
| 5375 | } |
| 5376 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5377 | /** |
| 5378 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5379 | * |
| 5380 | * @param subId id of the subscription |
| 5381 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5382 | */ |
| 5383 | @Override |
| 5384 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5385 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5386 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5387 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5388 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5389 | final long identity = Binder.clearCallingIdentity(); |
| 5390 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5391 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5392 | } finally { |
| 5393 | Binder.restoreCallingIdentity(identity); |
| 5394 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5395 | } |
| 5396 | |
| 5397 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5398 | * Get the calculated preferred network type. |
| 5399 | * Used for debugging incorrect network type. |
| 5400 | * |
| 5401 | * @return the preferred network type, defined in RILConstants.java. |
| 5402 | */ |
| 5403 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5404 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5405 | final Phone defaultPhone = getDefaultPhone(); |
| 5406 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5407 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5408 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5409 | } |
| 5410 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5411 | final long identity = Binder.clearCallingIdentity(); |
| 5412 | try { |
| 5413 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5414 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5415 | } finally { |
| 5416 | Binder.restoreCallingIdentity(identity); |
| 5417 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5418 | } |
| 5419 | |
| 5420 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5421 | * Get the preferred network type. |
| 5422 | * Used for device configuration by some CDMA operators. |
| 5423 | * |
| 5424 | * @return the preferred network type, defined in RILConstants.java. |
| 5425 | */ |
| 5426 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5427 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5428 | TelephonyPermissions |
| 5429 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5430 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5431 | |
| 5432 | final long identity = Binder.clearCallingIdentity(); |
| 5433 | try { |
| 5434 | if (DBG) log("getPreferredNetworkType"); |
| 5435 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5436 | int networkType = (result != null ? result[0] : -1); |
| 5437 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5438 | return networkType; |
| 5439 | } finally { |
| 5440 | Binder.restoreCallingIdentity(identity); |
| 5441 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5442 | } |
| 5443 | |
| 5444 | /** |
| 5445 | * Set the preferred network type. |
| 5446 | * Used for device configuration by some CDMA operators. |
| 5447 | * |
| 5448 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5449 | * @return true on success; false on any failure. |
| 5450 | */ |
| 5451 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5452 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5453 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5454 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5455 | |
| 5456 | final long identity = Binder.clearCallingIdentity(); |
| 5457 | try { |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5458 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5459 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5460 | return setPreferredNetworkTypesInternal(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5461 | } finally { |
| 5462 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5463 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5464 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5465 | |
| 5466 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5467 | * Get the allowed network types that store in the telephony provider. |
| 5468 | * |
| 5469 | * @param subId the id of the subscription. |
| 5470 | * @return allowedNetworkTypes the allowed network types. |
| 5471 | */ |
| 5472 | @Override |
| 5473 | public long getAllowedNetworkTypes(int subId) { |
| 5474 | TelephonyPermissions |
| 5475 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5476 | mApp, subId, "getAllowedNetworkTypes"); |
| 5477 | |
| 5478 | final long identity = Binder.clearCallingIdentity(); |
| 5479 | try { |
| 5480 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5481 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5482 | } finally { |
| 5483 | Binder.restoreCallingIdentity(identity); |
| 5484 | } |
| 5485 | } |
| 5486 | |
| 5487 | /** |
| 5488 | * Set the allowed network types. |
| 5489 | * |
| 5490 | * @param subId the id of the subscription. |
| 5491 | * @param allowedNetworkTypes the allowed network types. |
| 5492 | * @return true on success; false on any failure. |
| 5493 | */ |
| 5494 | @Override |
| 5495 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5496 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5497 | mApp, subId, "setAllowedNetworkTypes"); |
| 5498 | final long identity = Binder.clearCallingIdentity(); |
| 5499 | try { |
| 5500 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5501 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5502 | String.valueOf(allowedNetworkTypes)); |
| 5503 | return setPreferredNetworkTypesInternal(subId); |
| 5504 | } finally { |
| 5505 | Binder.restoreCallingIdentity(identity); |
| 5506 | } |
| 5507 | } |
| 5508 | |
| 5509 | private boolean setPreferredNetworkTypesInternal(int subId) { |
| 5510 | long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType( |
| 5511 | Settings.Global.getInt(mApp.getContentResolver(), |
| 5512 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5513 | RILConstants.PREFERRED_NETWORK_MODE)); |
| 5514 | long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty( |
| 5515 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5516 | int networkMode = RadioAccessFamily.getNetworkTypeFromRaf( |
| 5517 | (int) (networkTypeBitMask & allowedNetworkTypes)); |
| 5518 | |
| 5519 | if (DBG) { |
| 5520 | log("setPreferredNetworkTypesInternal: subId " + subId |
| 5521 | + " networkTypes " + networkTypeBitMask |
| 5522 | + " allowedNetworkTypes " + allowedNetworkTypes |
| 5523 | + " networkMode " + networkMode); |
| 5524 | } |
| 5525 | |
| 5526 | Boolean success = (Boolean) sendRequest( |
| 5527 | CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId); |
| 5528 | if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail")); |
| 5529 | return success; |
| 5530 | } |
| 5531 | |
| 5532 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5533 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5534 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5535 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5536 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5537 | * @hide |
| 5538 | */ |
| 5539 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5540 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5541 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5542 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5543 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5544 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5545 | if (phone != null) { |
| 5546 | return phone.hasMatchedTetherApnSetting(); |
| 5547 | } else { |
| 5548 | return false; |
| 5549 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5550 | } finally { |
| 5551 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5552 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5553 | } |
| 5554 | |
| 5555 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5556 | * Set mobile data enabled |
| 5557 | * Used by the user through settings etc to turn on/off mobile data |
| 5558 | * |
| 5559 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5560 | */ |
| 5561 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5562 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5563 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5564 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5565 | |
| 5566 | final long identity = Binder.clearCallingIdentity(); |
| 5567 | try { |
| 5568 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5569 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5570 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5571 | if (phone != null) { |
| 5572 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5573 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5574 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5575 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5576 | } |
| 5577 | } finally { |
| 5578 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5579 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5580 | } |
| 5581 | |
| 5582 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5583 | * Enable or disable always reporting signal strength changes from radio. |
| 5584 | * |
| 5585 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5586 | */ |
| 5587 | @Override |
| 5588 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5589 | enforceModifyPermission(); |
| 5590 | enforceSystemCaller(); |
| 5591 | |
| 5592 | final long identity = Binder.clearCallingIdentity(); |
| 5593 | final Phone phone = getPhone(subId); |
| 5594 | try { |
| 5595 | if (phone != null) { |
| 5596 | if (DBG) { |
| 5597 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5598 | + " isEnable=" + isEnable); |
| 5599 | } |
| 5600 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5601 | } else { |
| 5602 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5603 | + subId); |
| 5604 | } |
| 5605 | } finally { |
| 5606 | Binder.restoreCallingIdentity(identity); |
| 5607 | } |
| 5608 | } |
| 5609 | |
| 5610 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5611 | * Get the user enabled state of Mobile Data. |
| 5612 | * |
| 5613 | * TODO: remove and use isUserDataEnabled. |
| 5614 | * This can't be removed now because some vendor codes |
| 5615 | * calls through ITelephony directly while they should |
| 5616 | * use TelephonyManager. |
| 5617 | * |
| 5618 | * @return true on enabled |
| 5619 | */ |
| 5620 | @Override |
| 5621 | public boolean getDataEnabled(int subId) { |
| 5622 | return isUserDataEnabled(subId); |
| 5623 | } |
| 5624 | |
| 5625 | /** |
| 5626 | * Get whether mobile data is enabled per user setting. |
| 5627 | * |
| 5628 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5629 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5630 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5631 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5632 | * |
| 5633 | * @return {@code true} if data is enabled else {@code false} |
| 5634 | */ |
| 5635 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5636 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5637 | try { |
| 5638 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5639 | null); |
| 5640 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5641 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5642 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5643 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5644 | |
| 5645 | final long identity = Binder.clearCallingIdentity(); |
| 5646 | try { |
| 5647 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5648 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5649 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5650 | if (phone != null) { |
| 5651 | boolean retVal = phone.isUserDataEnabled(); |
| 5652 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5653 | return retVal; |
| 5654 | } else { |
| 5655 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5656 | return false; |
| 5657 | } |
| 5658 | } finally { |
| 5659 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5660 | } |
| 5661 | } |
| 5662 | |
| 5663 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5664 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5665 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5666 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5667 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5668 | * @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] | 5669 | */ |
| 5670 | @Override |
| 5671 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5672 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5673 | |
| 5674 | final long identity = Binder.clearCallingIdentity(); |
| 5675 | try { |
| 5676 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5677 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5678 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5679 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5680 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5681 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5682 | return retVal; |
| 5683 | } else { |
| 5684 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5685 | return false; |
| 5686 | } |
| 5687 | } finally { |
| 5688 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5689 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5690 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5691 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5692 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 5693 | Phone phone) { |
| 5694 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5695 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5696 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5697 | || subController == null) return privilegeFromSim; |
| 5698 | |
| 5699 | int uid = Binder.getCallingUid(); |
| 5700 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5701 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5702 | |
| 5703 | final long identity = Binder.clearCallingIdentity(); |
| 5704 | try { |
| 5705 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5706 | SubscriptionManager subManager = (SubscriptionManager) |
| 5707 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5708 | for (String pkg : packages) { |
| 5709 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5710 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5711 | } |
| 5712 | } |
| 5713 | return privilegeFromSim; |
| 5714 | } finally { |
| 5715 | Binder.restoreCallingIdentity(identity); |
| 5716 | } |
| 5717 | } |
| 5718 | |
| 5719 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5720 | String pkgName) { |
| 5721 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5722 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5723 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5724 | || subController == null) return privilegeFromSim; |
| 5725 | |
| 5726 | final long identity = Binder.clearCallingIdentity(); |
| 5727 | try { |
| 5728 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5729 | SubscriptionManager subManager = (SubscriptionManager) |
| 5730 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5731 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5732 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5733 | } finally { |
| 5734 | Binder.restoreCallingIdentity(identity); |
| 5735 | } |
| 5736 | } |
| 5737 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5738 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5739 | public int getCarrierPrivilegeStatus(int subId) { |
| 5740 | final Phone phone = getPhone(subId); |
| 5741 | if (phone == null) { |
| 5742 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5743 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5744 | } |
| 5745 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5746 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5747 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5748 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5749 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5750 | |
| 5751 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5752 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 5753 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5754 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5755 | |
| 5756 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5757 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5758 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5759 | final Phone phone = getPhone(subId); |
| 5760 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5761 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5762 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5763 | } |
| 5764 | UiccProfile profile = |
| 5765 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5766 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5767 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5768 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5769 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5770 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5771 | profile.getCarrierPrivilegeStatusForUid( |
| 5772 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5773 | } |
| 5774 | |
| 5775 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5776 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5777 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5778 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5779 | } |
| 5780 | |
| 5781 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5782 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5783 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5784 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5785 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5786 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5787 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5788 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5789 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5790 | } |
| 5791 | |
| 5792 | @Override |
| 5793 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5794 | if (TextUtils.isEmpty(pkgName)) |
| 5795 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5796 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5797 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5798 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5799 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5800 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5801 | continue; |
| 5802 | } |
| 5803 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5804 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5805 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5806 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5807 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5808 | break; |
| 5809 | } |
| 5810 | } |
| 5811 | |
| 5812 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5813 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5814 | |
| 5815 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5816 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5817 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5818 | loge("phoneId " + phoneId + " is not valid."); |
| 5819 | return null; |
| 5820 | } |
| 5821 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5822 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5823 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5824 | return null ; |
| 5825 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5826 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5827 | } |
| 5828 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5829 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5830 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5831 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5832 | List<String> privilegedPackages = new ArrayList<>(); |
| 5833 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5834 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5835 | // has UICC in that slot. |
| 5836 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5837 | if (card.hasCarrierPrivilegeRules()) { |
| 5838 | if (packages == null) { |
| 5839 | // Only check packages in user 0 for now |
| 5840 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5841 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5842 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5843 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5844 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5845 | } |
| 5846 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5847 | PackageInfo pkgInfo = packages.get(p); |
| 5848 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5849 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5850 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5851 | privilegedPackages.add(pkgInfo.packageName); |
| 5852 | } |
| 5853 | } |
| 5854 | } |
| 5855 | } |
| 5856 | return privilegedPackages; |
| 5857 | } |
| 5858 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5859 | @Override |
| 5860 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5861 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5862 | |
| 5863 | final long identity = Binder.clearCallingIdentity(); |
| 5864 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5865 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5866 | try { |
| 5867 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5868 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5869 | } |
| 5870 | } finally { |
| 5871 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5872 | } |
| 5873 | return privilegedPackages; |
| 5874 | } |
| 5875 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5876 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5877 | final Phone phone = getPhone(subId); |
| 5878 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5879 | if (card == null) { |
| 5880 | loge("getIccId: No UICC"); |
| 5881 | return null; |
| 5882 | } |
| 5883 | String iccId = card.getIccId(); |
| 5884 | if (TextUtils.isEmpty(iccId)) { |
| 5885 | loge("getIccId: ICC ID is null or empty."); |
| 5886 | return null; |
| 5887 | } |
| 5888 | return iccId; |
| 5889 | } |
| 5890 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5891 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5892 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5893 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5894 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5895 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5896 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5897 | final long identity = Binder.clearCallingIdentity(); |
| 5898 | try { |
| 5899 | final String iccId = getIccId(subId); |
| 5900 | final Phone phone = getPhone(subId); |
| 5901 | if (phone == null) { |
| 5902 | return false; |
| 5903 | } |
| 5904 | final String subscriberId = phone.getSubscriberId(); |
| 5905 | |
| 5906 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5907 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5908 | + subscriberId + " to " + number); |
| 5909 | } |
| 5910 | |
| 5911 | if (TextUtils.isEmpty(iccId)) { |
| 5912 | return false; |
| 5913 | } |
| 5914 | |
| 5915 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5916 | |
| 5917 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5918 | if (alphaTag == null) { |
| 5919 | editor.remove(alphaTagPrefKey); |
| 5920 | } else { |
| 5921 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5922 | } |
| 5923 | |
| 5924 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5925 | // track all merged IMSIs based on line number |
| 5926 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5927 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5928 | if (number == null) { |
| 5929 | editor.remove(numberPrefKey); |
| 5930 | editor.remove(subscriberPrefKey); |
| 5931 | } else { |
| 5932 | editor.putString(numberPrefKey, number); |
| 5933 | editor.putString(subscriberPrefKey, subscriberId); |
| 5934 | } |
| 5935 | |
| 5936 | editor.commit(); |
| 5937 | return true; |
| 5938 | } finally { |
| 5939 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5940 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5941 | } |
| 5942 | |
| 5943 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5944 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 5945 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5946 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5947 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5948 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5949 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5950 | return null; |
| 5951 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5952 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5953 | final long identity = Binder.clearCallingIdentity(); |
| 5954 | try { |
| 5955 | String iccId = getIccId(subId); |
| 5956 | if (iccId != null) { |
| 5957 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5958 | if (DBG_MERGE) { |
| 5959 | log("getLine1NumberForDisplay returning " |
| 5960 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5961 | } |
| 5962 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5963 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5964 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5965 | return null; |
| 5966 | } finally { |
| 5967 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5968 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5969 | } |
| 5970 | |
| 5971 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5972 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 5973 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5974 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5975 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5976 | return null; |
| 5977 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5978 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5979 | final long identity = Binder.clearCallingIdentity(); |
| 5980 | try { |
| 5981 | String iccId = getIccId(subId); |
| 5982 | if (iccId != null) { |
| 5983 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5984 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5985 | } |
| 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 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5991 | |
| 5992 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5993 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 5994 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5995 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5996 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5997 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5998 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5999 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6000 | return null; |
| 6001 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6002 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6003 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6004 | // the process, where TelephonyManager was instantiated. |
| 6005 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6006 | final long identity = Binder.clearCallingIdentity(); |
| 6007 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6008 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6009 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6010 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6011 | |
| 6012 | // Figure out what subscribers are currently active |
| 6013 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6014 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6015 | // Only consider subs which match the current subId |
| 6016 | // This logic can be simplified. See b/131189269 for progress. |
| 6017 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6018 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6019 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6020 | |
| 6021 | // First pass, find a number override for an active subscriber |
| 6022 | String mergeNumber = null; |
| 6023 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6024 | for (String key : prefs.keySet()) { |
| 6025 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6026 | final String subscriberId = (String) prefs.get(key); |
| 6027 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6028 | final String iccId = key.substring( |
| 6029 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6030 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6031 | mergeNumber = (String) prefs.get(numberKey); |
| 6032 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6033 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6034 | + " for active subscriber " + subscriberId); |
| 6035 | } |
| 6036 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6037 | break; |
| 6038 | } |
| 6039 | } |
| 6040 | } |
| 6041 | } |
| 6042 | |
| 6043 | // Shortcut when no active merged subscribers |
| 6044 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6045 | return null; |
| 6046 | } |
| 6047 | |
| 6048 | // Second pass, find all subscribers under that line override |
| 6049 | final ArraySet<String> result = new ArraySet<>(); |
| 6050 | for (String key : prefs.keySet()) { |
| 6051 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6052 | final String number = (String) prefs.get(key); |
| 6053 | if (mergeNumber.equals(number)) { |
| 6054 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6055 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6056 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6057 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6058 | result.add(subscriberId); |
| 6059 | } |
| 6060 | } |
| 6061 | } |
| 6062 | } |
| 6063 | |
| 6064 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6065 | Arrays.sort(resultArray); |
| 6066 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6067 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6068 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6069 | } |
| 6070 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6071 | } finally { |
| 6072 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6073 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6074 | } |
| 6075 | |
| 6076 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6077 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 6078 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 6079 | |
| 6080 | final long identity = Binder.clearCallingIdentity(); |
| 6081 | try { |
| 6082 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6083 | TelephonyManager.class); |
| 6084 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6085 | if (subscriberId == null) { |
| 6086 | if (DBG) { |
| 6087 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 6088 | + subId); |
| 6089 | } |
| 6090 | return null; |
| 6091 | } |
| 6092 | |
| 6093 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6094 | .getSubscriptionInfo(subId); |
| 6095 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6096 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6097 | if (groupUuid == null) { |
| 6098 | return new String[]{subscriberId}; |
| 6099 | } |
| 6100 | |
| 6101 | // Get all subscriberIds from the group. |
| 6102 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6103 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6104 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 6105 | null); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6106 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6107 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6108 | if (subscriberId != null) { |
| 6109 | mergedSubscriberIds.add(subscriberId); |
| 6110 | } |
| 6111 | } |
| 6112 | |
| 6113 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6114 | } finally { |
| 6115 | Binder.restoreCallingIdentity(identity); |
| 6116 | |
| 6117 | } |
| 6118 | } |
| 6119 | |
| 6120 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6121 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6122 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6123 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6124 | |
| 6125 | final long identity = Binder.clearCallingIdentity(); |
| 6126 | try { |
| 6127 | final Phone phone = getPhone(subId); |
| 6128 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6129 | } finally { |
| 6130 | Binder.restoreCallingIdentity(identity); |
| 6131 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6132 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6133 | |
| 6134 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6135 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6136 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6137 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6138 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6139 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6140 | |
| 6141 | final long identity = Binder.clearCallingIdentity(); |
| 6142 | try { |
| 6143 | final Phone phone = getPhone(subId); |
| 6144 | if (phone == null) { |
| 6145 | return false; |
| 6146 | } |
| 6147 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6148 | cdmaNonRoamingList); |
| 6149 | } finally { |
| 6150 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6151 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6152 | } |
| 6153 | |
| 6154 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6155 | @Deprecated |
| 6156 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6157 | enforceModifyPermission(); |
| 6158 | |
| 6159 | int returnValue = 0; |
| 6160 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6161 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6162 | if(result.exception == null) { |
| 6163 | if (result.result != null) { |
| 6164 | byte[] responseData = (byte[])(result.result); |
| 6165 | if(responseData.length > oemResp.length) { |
| 6166 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6167 | responseData.length + "bytes. Buffer Size is " + |
| 6168 | oemResp.length + "bytes."); |
| 6169 | } |
| 6170 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6171 | returnValue = responseData.length; |
| 6172 | } |
| 6173 | } else { |
| 6174 | CommandException ex = (CommandException) result.exception; |
| 6175 | returnValue = ex.getCommandError().ordinal(); |
| 6176 | if(returnValue > 0) returnValue *= -1; |
| 6177 | } |
| 6178 | } catch (RuntimeException e) { |
| 6179 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6180 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6181 | if(returnValue > 0) returnValue *= -1; |
| 6182 | } |
| 6183 | |
| 6184 | return returnValue; |
| 6185 | } |
| 6186 | |
| 6187 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6188 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6189 | try { |
| 6190 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6191 | } catch (RuntimeException e) { |
| 6192 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6193 | } |
| 6194 | } |
| 6195 | |
| 6196 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6197 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6198 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6199 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6200 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6201 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6202 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6203 | final long identity = Binder.clearCallingIdentity(); |
| 6204 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6205 | TelephonyPermissions |
| 6206 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6207 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6208 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6209 | } finally { |
| 6210 | Binder.restoreCallingIdentity(identity); |
| 6211 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6212 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6213 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6214 | |
| 6215 | @Override |
| 6216 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6217 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6218 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6219 | |
| 6220 | final long identity = Binder.clearCallingIdentity(); |
| 6221 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6222 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6223 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6224 | } finally { |
| 6225 | Binder.restoreCallingIdentity(identity); |
| 6226 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6227 | } |
| 6228 | |
| 6229 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6230 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6231 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6232 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6233 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6234 | return false; |
| 6235 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6236 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6237 | final long identity = Binder.clearCallingIdentity(); |
| 6238 | try { |
| 6239 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6240 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6241 | // In the long run, we may instead need to check if there exists a connection service |
| 6242 | // which can support video calling. |
| 6243 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6244 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6245 | return imsManager.isVtEnabledByPlatform() |
| 6246 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6247 | && imsManager.isVtEnabledByUser(); |
| 6248 | } finally { |
| 6249 | Binder.restoreCallingIdentity(identity); |
| 6250 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6251 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6252 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6253 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6254 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6255 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6256 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6257 | mApp, subId, callingPackage, callingFeatureId, |
| 6258 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6259 | return false; |
| 6260 | } |
| 6261 | |
| 6262 | final long identity = Binder.clearCallingIdentity(); |
| 6263 | try { |
| 6264 | CarrierConfigManager configManager = |
| 6265 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6266 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6267 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6268 | } finally { |
| 6269 | Binder.restoreCallingIdentity(identity); |
| 6270 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6271 | } |
| 6272 | |
| 6273 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6274 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6275 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6276 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6277 | return false; |
| 6278 | } |
| 6279 | |
| 6280 | final long identity = Binder.clearCallingIdentity(); |
| 6281 | try { |
| 6282 | CarrierConfigManager configManager = |
| 6283 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6284 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6285 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6286 | } finally { |
| 6287 | Binder.restoreCallingIdentity(identity); |
| 6288 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6289 | } |
| 6290 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6291 | @Override |
| 6292 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6293 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6294 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6295 | } |
| 6296 | |
| 6297 | @Override |
| 6298 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6299 | final long identity = Binder.clearCallingIdentity(); |
| 6300 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6301 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6302 | } finally { |
| 6303 | Binder.restoreCallingIdentity(identity); |
| 6304 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6305 | } |
| 6306 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6307 | /** |
| 6308 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6309 | * support for the feature and device firmware support. |
| 6310 | * |
| 6311 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6312 | */ |
| 6313 | @Override |
| 6314 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6315 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6316 | final Phone phone = getPhone(subscriptionId); |
| 6317 | if (phone == null) { |
| 6318 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6319 | return false; |
| 6320 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6321 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6322 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6323 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6324 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6325 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6326 | return isCarrierSupported && isDeviceSupported; |
| 6327 | } finally { |
| 6328 | Binder.restoreCallingIdentity(identity); |
| 6329 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6330 | } |
| 6331 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6332 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6333 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6334 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6335 | * 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] | 6336 | */ |
| 6337 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6338 | final long identity = Binder.clearCallingIdentity(); |
| 6339 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6340 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6341 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6342 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6343 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6344 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6345 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6346 | } finally { |
| 6347 | Binder.restoreCallingIdentity(identity); |
| 6348 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6349 | } |
| 6350 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6351 | @Deprecated |
| 6352 | @Override |
| 6353 | public String getDeviceId(String callingPackage) { |
| 6354 | return getDeviceIdWithFeature(callingPackage, null); |
| 6355 | } |
| 6356 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6357 | /** |
| 6358 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6359 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6360 | * |
| 6361 | * <p>Requires Permission: |
| 6362 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6363 | */ |
| 6364 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6365 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6366 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6367 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6368 | return null; |
| 6369 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6370 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6371 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6372 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6373 | return null; |
| 6374 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6375 | |
| 6376 | final long identity = Binder.clearCallingIdentity(); |
| 6377 | try { |
| 6378 | return phone.getDeviceId(); |
| 6379 | } finally { |
| 6380 | Binder.restoreCallingIdentity(identity); |
| 6381 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6382 | } |
| 6383 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6384 | /** |
| 6385 | * {@hide} |
| 6386 | * Returns the IMS Registration Status on a particular subid |
| 6387 | * |
| 6388 | * @param subId |
| 6389 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6390 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6391 | Phone phone = getPhone(subId); |
| 6392 | if (phone != null) { |
| 6393 | return phone.isImsRegistered(); |
| 6394 | } else { |
| 6395 | return false; |
| 6396 | } |
| 6397 | } |
| 6398 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6399 | @Override |
| 6400 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6401 | final long identity = Binder.clearCallingIdentity(); |
| 6402 | try { |
| 6403 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6404 | } finally { |
| 6405 | Binder.restoreCallingIdentity(identity); |
| 6406 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6407 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6408 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6409 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6410 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6411 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6412 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6413 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6414 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6415 | } |
| 6416 | final long identity = Binder.clearCallingIdentity(); |
| 6417 | try { |
| 6418 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6419 | } finally { |
| 6420 | Binder.restoreCallingIdentity(identity); |
| 6421 | } |
| 6422 | } |
| 6423 | |
| 6424 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6425 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6426 | final long identity = Binder.clearCallingIdentity(); |
| 6427 | try { |
| 6428 | Phone phone = getPhone(subscriptionId); |
| 6429 | if (phone == null) { |
| 6430 | return null; |
| 6431 | } |
| 6432 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6433 | } finally { |
| 6434 | Binder.restoreCallingIdentity(identity); |
| 6435 | } |
| 6436 | } |
| 6437 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6438 | /** |
| 6439 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6440 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6441 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6442 | final long identity = Binder.clearCallingIdentity(); |
| 6443 | try { |
| 6444 | Phone phone = getPhone(subId); |
| 6445 | if (phone != null) { |
| 6446 | return phone.isWifiCallingEnabled(); |
| 6447 | } else { |
| 6448 | return false; |
| 6449 | } |
| 6450 | } finally { |
| 6451 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6452 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6453 | } |
| 6454 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6455 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6456 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6457 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6458 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6459 | final long identity = Binder.clearCallingIdentity(); |
| 6460 | try { |
| 6461 | Phone phone = getPhone(subId); |
| 6462 | if (phone != null) { |
| 6463 | return phone.isVideoEnabled(); |
| 6464 | } else { |
| 6465 | return false; |
| 6466 | } |
| 6467 | } finally { |
| 6468 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6469 | } |
| 6470 | } |
| 6471 | |
| 6472 | /** |
| 6473 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6474 | * defined in {@link ImsRegistrationImplBase}. |
| 6475 | */ |
| 6476 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6477 | final long identity = Binder.clearCallingIdentity(); |
| 6478 | try { |
| 6479 | Phone phone = getPhone(subId); |
| 6480 | if (phone != null) { |
| 6481 | return phone.getImsRegistrationTech(); |
| 6482 | } else { |
| 6483 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6484 | } |
| 6485 | } finally { |
| 6486 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6487 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6488 | } |
| 6489 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6490 | @Override |
| 6491 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6492 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6493 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6494 | return; |
| 6495 | } |
| 6496 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6497 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6498 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6499 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6500 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6501 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6502 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6503 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6504 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6505 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6506 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6507 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6508 | // There has been issues when Sms raw table somehow stores orphan |
| 6509 | // fragments. They lead to garbled message when new fragments come |
| 6510 | // in and combined with those stale ones. In case this happens again, |
| 6511 | // user can reset all network settings which will clean up this table. |
| 6512 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6513 | // Clean up IMS settings as well here. |
| 6514 | int slotId = getSlotIndex(subId); |
| 6515 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6516 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6517 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6518 | |
| 6519 | // Erase modem config if erase modem on network setting is enabled. |
| 6520 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6521 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6522 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6523 | sendEraseModemConfig(getDefaultPhone()); |
| 6524 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6525 | } finally { |
| 6526 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6527 | } |
| 6528 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6529 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6530 | private void cleanUpSmsRawTable(Context context) { |
| 6531 | ContentResolver resolver = context.getContentResolver(); |
| 6532 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6533 | resolver.delete(uri, null, null); |
| 6534 | } |
| 6535 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6536 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6537 | public String getSimLocaleForSubscriber(int subId) { |
| 6538 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6539 | final Phone phone = getPhone(subId); |
| 6540 | if (phone == null) { |
| 6541 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6542 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6543 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6544 | final long identity = Binder.clearCallingIdentity(); |
| 6545 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6546 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6547 | phone.getContext().getOpPackageName(), null); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6548 | if (info == null) { |
| 6549 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6550 | return null; |
| 6551 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6552 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6553 | // preferences (EF-PL and EF-LI)... |
| 6554 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6555 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6556 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6557 | if (localeFromDefaultSim != null) { |
| 6558 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6559 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6560 | + localeFromDefaultSim); |
| 6561 | return localeFromDefaultSim.toLanguageTag(); |
| 6562 | } else { |
| 6563 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6564 | } |
| 6565 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6566 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6567 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6568 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6569 | // the SIM and carrier preferences does not include a country we add the country |
| 6570 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6571 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6572 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6573 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6574 | return mccLocale.toLanguageTag(); |
| 6575 | } |
| 6576 | |
| 6577 | if (DBG) log("No locale found - returning null"); |
| 6578 | return null; |
| 6579 | } finally { |
| 6580 | Binder.restoreCallingIdentity(identity); |
| 6581 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6582 | } |
| 6583 | |
| 6584 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6585 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 6586 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6587 | } |
| 6588 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6589 | /** |
| 6590 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6591 | */ |
| 6592 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6593 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 6594 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6595 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6596 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6597 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6598 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6599 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6600 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6601 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6602 | * representing the state of the modem. |
| 6603 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6604 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6605 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6606 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6607 | */ |
| 6608 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6609 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6610 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6611 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6612 | |
| 6613 | final long identity = Binder.clearCallingIdentity(); |
| 6614 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame^] | 6615 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6616 | } finally { |
| 6617 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6618 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6619 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6620 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6621 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6622 | // less than total activity duration. |
| 6623 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6624 | if (info == null) { |
| 6625 | return false; |
| 6626 | } |
| 6627 | int activityDurationMs = |
| 6628 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6629 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6630 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6631 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6632 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6633 | } |
| 6634 | return (info.isValid() |
| 6635 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6636 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6637 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6638 | && (totalTxTimeMs <= activityDurationMs)); |
| 6639 | } |
| 6640 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6641 | /** |
| 6642 | * {@hide} |
| 6643 | * Returns the service state information on specified subscription. |
| 6644 | */ |
| 6645 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6646 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6647 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6648 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6649 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6650 | return null; |
| 6651 | } |
| 6652 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6653 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6654 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6655 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6656 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6657 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6658 | .setCallingPid(Binder.getCallingPid()) |
| 6659 | .setCallingUid(Binder.getCallingUid()) |
| 6660 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6661 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6662 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6663 | .build()); |
| 6664 | |
| 6665 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6666 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6667 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6668 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6669 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6670 | .setCallingPid(Binder.getCallingPid()) |
| 6671 | .setCallingUid(Binder.getCallingUid()) |
| 6672 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6673 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6674 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6675 | .build()); |
| 6676 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6677 | boolean hasFinePermission = |
| 6678 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6679 | boolean hasCoarsePermission = |
| 6680 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6681 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6682 | final long identity = Binder.clearCallingIdentity(); |
| 6683 | try { |
| 6684 | final Phone phone = getPhone(subId); |
| 6685 | if (phone == null) { |
| 6686 | return null; |
| 6687 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6688 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6689 | ServiceState ss = phone.getServiceState(); |
| 6690 | |
| 6691 | // Scrub out the location info in ServiceState depending on what level of access |
| 6692 | // the caller has. |
| 6693 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6694 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6695 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6696 | } finally { |
| 6697 | Binder.restoreCallingIdentity(identity); |
| 6698 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6699 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6700 | |
| 6701 | /** |
| 6702 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6703 | * |
| 6704 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6705 | * voicemail ringtone. |
| 6706 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6707 | * PhoneAccount. |
| 6708 | */ |
| 6709 | @Override |
| 6710 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6711 | final long identity = Binder.clearCallingIdentity(); |
| 6712 | try { |
| 6713 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6714 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6715 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6716 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6717 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6718 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6719 | } finally { |
| 6720 | Binder.restoreCallingIdentity(identity); |
| 6721 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6722 | } |
| 6723 | |
| 6724 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6725 | * Sets the per-account voicemail ringtone. |
| 6726 | * |
| 6727 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6728 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6729 | * |
| 6730 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6731 | * voicemail ringtone. |
| 6732 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6733 | * PhoneAccount. |
| 6734 | */ |
| 6735 | @Override |
| 6736 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6737 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6738 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6739 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6740 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6741 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6742 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6743 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6744 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6745 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6746 | |
| 6747 | final long identity = Binder.clearCallingIdentity(); |
| 6748 | try { |
| 6749 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6750 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6751 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6752 | } |
| 6753 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6754 | } finally { |
| 6755 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6756 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6757 | } |
| 6758 | |
| 6759 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6760 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6761 | * |
| 6762 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6763 | * voicemail vibration setting. |
| 6764 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6765 | */ |
| 6766 | @Override |
| 6767 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6768 | final long identity = Binder.clearCallingIdentity(); |
| 6769 | try { |
| 6770 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6771 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6772 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6773 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6774 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6775 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6776 | } finally { |
| 6777 | Binder.restoreCallingIdentity(identity); |
| 6778 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6779 | } |
| 6780 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6781 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6782 | * Sets the per-account voicemail vibration. |
| 6783 | * |
| 6784 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6785 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6786 | * |
| 6787 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6788 | * voicemail vibration setting. |
| 6789 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6790 | * specific PhoneAccount. |
| 6791 | */ |
| 6792 | @Override |
| 6793 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6794 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6795 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6796 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6797 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6798 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6799 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6800 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6801 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6802 | } |
| 6803 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6804 | final long identity = Binder.clearCallingIdentity(); |
| 6805 | try { |
| 6806 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6807 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6808 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6809 | } |
| 6810 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6811 | } finally { |
| 6812 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6813 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6814 | } |
| 6815 | |
| 6816 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6817 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6818 | * |
| 6819 | * @throws SecurityException if the caller does not have the required permission |
| 6820 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6821 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6822 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6823 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6824 | } |
| 6825 | |
| 6826 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6827 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6828 | * permission. |
| 6829 | * |
| 6830 | * @throws SecurityException if the caller does not have the required permission |
| 6831 | */ |
| 6832 | private void enforceSendSmsPermission() { |
| 6833 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6834 | } |
| 6835 | |
| 6836 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6837 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6838 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6839 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6840 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6841 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6842 | final long identity = Binder.clearCallingIdentity(); |
| 6843 | try { |
| 6844 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6845 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6846 | if (componentName == null) { |
| 6847 | throw new SecurityException( |
| 6848 | "Caller not current active visual voicemail package[null]"); |
| 6849 | } |
| 6850 | String vvmPackage = componentName.getPackageName(); |
| 6851 | if (!callingPackage.equals(vvmPackage)) { |
| 6852 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6853 | + vvmPackage + "]"); |
| 6854 | } |
| 6855 | } finally { |
| 6856 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6857 | } |
| 6858 | } |
| 6859 | |
| 6860 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6861 | * Return the application ID for the app type. |
| 6862 | * |
| 6863 | * @param subId the subscription ID that this request applies to. |
| 6864 | * @param appType the uicc app type. |
| 6865 | * @return Application ID for specificied app type, or null if no uicc. |
| 6866 | */ |
| 6867 | @Override |
| 6868 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6869 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6870 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6871 | |
| 6872 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6873 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6874 | if (phone == null) { |
| 6875 | return null; |
| 6876 | } |
| 6877 | String aid = null; |
| 6878 | try { |
| 6879 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6880 | .getApplicationByType(appType).getAid(); |
| 6881 | } catch (Exception e) { |
| 6882 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6883 | } |
| 6884 | return aid; |
| 6885 | } finally { |
| 6886 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6887 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6888 | } |
| 6889 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6890 | /** |
| 6891 | * Return the Electronic Serial Number. |
| 6892 | * |
| 6893 | * @param subId the subscription ID that this request applies to. |
| 6894 | * @return ESN or null if error. |
| 6895 | */ |
| 6896 | @Override |
| 6897 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6898 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6899 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6900 | |
| 6901 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6902 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6903 | if (phone == null) { |
| 6904 | return null; |
| 6905 | } |
| 6906 | String esn = null; |
| 6907 | try { |
| 6908 | esn = phone.getEsn(); |
| 6909 | } catch (Exception e) { |
| 6910 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6911 | } |
| 6912 | return esn; |
| 6913 | } finally { |
| 6914 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6915 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6916 | } |
| 6917 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6918 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6919 | * Return the Preferred Roaming List Version. |
| 6920 | * |
| 6921 | * @param subId the subscription ID that this request applies to. |
| 6922 | * @return PRLVersion or null if error. |
| 6923 | */ |
| 6924 | @Override |
| 6925 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6926 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6927 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6928 | |
| 6929 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6930 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6931 | if (phone == null) { |
| 6932 | return null; |
| 6933 | } |
| 6934 | String cdmaPrlVersion = null; |
| 6935 | try { |
| 6936 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6937 | } catch (Exception e) { |
| 6938 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6939 | } |
| 6940 | return cdmaPrlVersion; |
| 6941 | } finally { |
| 6942 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6943 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6944 | } |
| 6945 | |
| 6946 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6947 | * Get snapshot of Telephony histograms |
| 6948 | * @return List of Telephony histograms |
| 6949 | * @hide |
| 6950 | */ |
| 6951 | @Override |
| 6952 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6953 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6954 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6955 | |
| 6956 | final long identity = Binder.clearCallingIdentity(); |
| 6957 | try { |
| 6958 | return RIL.getTelephonyRILTimingHistograms(); |
| 6959 | } finally { |
| 6960 | Binder.restoreCallingIdentity(identity); |
| 6961 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6962 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6963 | |
| 6964 | /** |
| 6965 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6966 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6967 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6968 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6969 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6970 | * @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] | 6971 | */ |
| 6972 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6973 | @TelephonyManager.SetCarrierRestrictionResult |
| 6974 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6975 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6976 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6977 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6978 | if (carrierRestrictionRules == null) { |
| 6979 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6980 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6981 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6982 | final long identity = Binder.clearCallingIdentity(); |
| 6983 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6984 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6985 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6986 | } finally { |
| 6987 | Binder.restoreCallingIdentity(identity); |
| 6988 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6989 | } |
| 6990 | |
| 6991 | /** |
| 6992 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6993 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6994 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6995 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6996 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6997 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6998 | */ |
| 6999 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7000 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7001 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7002 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7003 | |
| 7004 | final long identity = Binder.clearCallingIdentity(); |
| 7005 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7006 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7007 | if (response instanceof CarrierRestrictionRules) { |
| 7008 | return (CarrierRestrictionRules) response; |
| 7009 | } |
| 7010 | // Response is an Exception of some kind, |
| 7011 | // which is signalled to the user as a NULL retval |
| 7012 | return null; |
| 7013 | } catch (Exception e) { |
| 7014 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7015 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7016 | } finally { |
| 7017 | Binder.restoreCallingIdentity(identity); |
| 7018 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7019 | } |
| 7020 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7021 | /** |
| 7022 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 7023 | * @param subId the subscription ID that this action applies to. |
| 7024 | * @param enabled control enable or disable metered apns. |
| 7025 | * {@hide} |
| 7026 | */ |
| 7027 | @Override |
| 7028 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 7029 | enforceModifyPermission(); |
| 7030 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7031 | |
| 7032 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7033 | if (phone == null) { |
| 7034 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 7035 | return; |
| 7036 | } |
| 7037 | try { |
| 7038 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7039 | } catch (Exception e) { |
| 7040 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7041 | } finally { |
| 7042 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7043 | } |
| 7044 | } |
| 7045 | |
| 7046 | /** |
| 7047 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7048 | * @param subId the subscription ID that this action applies to. |
| 7049 | * @param enabled control enable or disable radio. |
| 7050 | * {@hide} |
| 7051 | */ |
| 7052 | @Override |
| 7053 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7054 | enforceModifyPermission(); |
| 7055 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7056 | |
| 7057 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7058 | if (phone == null) { |
| 7059 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7060 | return; |
| 7061 | } |
| 7062 | try { |
| 7063 | phone.carrierActionSetRadioEnabled(enabled); |
| 7064 | } catch (Exception e) { |
| 7065 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7066 | } finally { |
| 7067 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7068 | } |
| 7069 | } |
| 7070 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7071 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7072 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7073 | * network status based on which carrier apps could apply actions accordingly, |
| 7074 | * enable/disable default url handler for example. |
| 7075 | * |
| 7076 | * @param subId the subscription ID that this action applies to. |
| 7077 | * @param report control start/stop reporting the default network status. |
| 7078 | * {@hide} |
| 7079 | */ |
| 7080 | @Override |
| 7081 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7082 | enforceModifyPermission(); |
| 7083 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7084 | |
| 7085 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7086 | if (phone == null) { |
| 7087 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7088 | return; |
| 7089 | } |
| 7090 | try { |
| 7091 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7092 | } catch (Exception e) { |
| 7093 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7094 | } finally { |
| 7095 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7096 | } |
| 7097 | } |
| 7098 | |
| 7099 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7100 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7101 | * @param subId the subscription ID that this action applies to. |
| 7102 | * {@hide} |
| 7103 | */ |
| 7104 | @Override |
| 7105 | public void carrierActionResetAll(int subId) { |
| 7106 | enforceModifyPermission(); |
| 7107 | final Phone phone = getPhone(subId); |
| 7108 | if (phone == null) { |
| 7109 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7110 | return; |
| 7111 | } |
| 7112 | try { |
| 7113 | phone.carrierActionResetAll(); |
| 7114 | } catch (Exception e) { |
| 7115 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7116 | } |
| 7117 | } |
| 7118 | |
| 7119 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7120 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7121 | * bug report is being generated. |
| 7122 | */ |
| 7123 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7124 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7125 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7126 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7127 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7128 | + Binder.getCallingPid() |
| 7129 | + ", uid=" + Binder.getCallingUid() |
| 7130 | + "without permission " |
| 7131 | + android.Manifest.permission.DUMP); |
| 7132 | return; |
| 7133 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7134 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7135 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7136 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7137 | @Override |
| 7138 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 7139 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 7140 | throws RemoteException { |
Torbjorn Eklund | 1050cb0 | 2018-11-16 14:05:38 +0100 | [diff] [blame] | 7141 | (new TelephonyShellCommand(this, getDefaultPhone().getContext())) |
| 7142 | .exec(this, in, out, err, args, callback, resultReceiver); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7143 | } |
| 7144 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7145 | /** |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7146 | * Policy control of data connection. Usually used when data limit is passed. |
| 7147 | * @param enabled True if enabling the data, otherwise disabling. |
| 7148 | * @param subId Subscription index |
| 7149 | * {@hide} |
| 7150 | */ |
| 7151 | @Override |
| 7152 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 7153 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7154 | |
| 7155 | final long identity = Binder.clearCallingIdentity(); |
| 7156 | try { |
| 7157 | Phone phone = getPhone(subId); |
| 7158 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 7159 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7160 | } |
| 7161 | } finally { |
| 7162 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7163 | } |
| 7164 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7165 | |
| 7166 | /** |
| 7167 | * Get Client request stats |
| 7168 | * @return List of Client Request Stats |
| 7169 | * @hide |
| 7170 | */ |
| 7171 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7172 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7173 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7174 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7175 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7176 | return null; |
| 7177 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7178 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7179 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7180 | final long identity = Binder.clearCallingIdentity(); |
| 7181 | try { |
| 7182 | if (phone != null) { |
| 7183 | return phone.getClientRequestStats(); |
| 7184 | } |
| 7185 | |
| 7186 | return null; |
| 7187 | } finally { |
| 7188 | Binder.restoreCallingIdentity(identity); |
| 7189 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7190 | } |
| 7191 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7192 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7193 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7194 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7195 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7196 | |
| 7197 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7198 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7199 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7200 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7201 | * @param state State of SIM (power down, power up, pass through) |
| 7202 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7203 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7204 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7205 | * |
| 7206 | **/ |
| 7207 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7208 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7209 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7210 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7211 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7212 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7213 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7214 | final long identity = Binder.clearCallingIdentity(); |
| 7215 | try { |
| 7216 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7217 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7218 | } |
| 7219 | } finally { |
| 7220 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7221 | } |
| 7222 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7223 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7224 | private boolean isUssdApiAllowed(int subId) { |
| 7225 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7226 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7227 | if (configManager == null) { |
| 7228 | return false; |
| 7229 | } |
| 7230 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7231 | if (pb == null) { |
| 7232 | return false; |
| 7233 | } |
| 7234 | return pb.getBoolean( |
| 7235 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7236 | } |
| 7237 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7238 | /** |
| 7239 | * Check if phone is in emergency callback mode |
| 7240 | * @return true if phone is in emergency callback mode |
| 7241 | * @param subId sub id |
| 7242 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7243 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7244 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7245 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7246 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7247 | |
| 7248 | final long identity = Binder.clearCallingIdentity(); |
| 7249 | try { |
| 7250 | if (phone != null) { |
| 7251 | return phone.isInEcm(); |
| 7252 | } else { |
| 7253 | return false; |
| 7254 | } |
| 7255 | } finally { |
| 7256 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7257 | } |
| 7258 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7259 | |
| 7260 | /** |
| 7261 | * Get the current signal strength information for the given subscription. |
| 7262 | * Because this information is not updated when the device is in a low power state |
| 7263 | * it should not be relied-upon to be current. |
| 7264 | * @param subId Subscription index |
| 7265 | * @return the most recent cached signal strength info from the modem |
| 7266 | */ |
| 7267 | @Override |
| 7268 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7269 | final long identity = Binder.clearCallingIdentity(); |
| 7270 | try { |
| 7271 | Phone p = getPhone(subId); |
| 7272 | if (p == null) { |
| 7273 | return null; |
| 7274 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7275 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7276 | return p.getSignalStrength(); |
| 7277 | } finally { |
| 7278 | Binder.restoreCallingIdentity(identity); |
| 7279 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7280 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7281 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7282 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7283 | * Get the current modem radio state for the given slot. |
| 7284 | * @param slotIndex slot index. |
| 7285 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7286 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7287 | * @return the current radio power state from the modem |
| 7288 | */ |
| 7289 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7290 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7291 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7292 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7293 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7294 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7295 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7296 | } |
| 7297 | |
| 7298 | final long identity = Binder.clearCallingIdentity(); |
| 7299 | try { |
| 7300 | return phone.getRadioPowerState(); |
| 7301 | } finally { |
| 7302 | Binder.restoreCallingIdentity(identity); |
| 7303 | } |
| 7304 | } |
| 7305 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7306 | } |
| 7307 | |
| 7308 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7309 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7310 | * |
| 7311 | * <p>Requires one of the following permissions: |
| 7312 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7313 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7314 | * privileges. |
| 7315 | * |
| 7316 | * @param subId subscription id |
| 7317 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7318 | * {@code false}. |
| 7319 | */ |
| 7320 | @Override |
| 7321 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7322 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7323 | null /* message */); |
| 7324 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7325 | boolean isEnabled = false; |
| 7326 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7327 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7328 | Phone phone = getPhone(subId); |
| 7329 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7330 | } catch (Exception e) { |
| 7331 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7332 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7333 | } finally { |
| 7334 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7335 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7336 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7337 | } |
| 7338 | |
| 7339 | |
| 7340 | /** |
| 7341 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7342 | * |
| 7343 | * <p> Requires permission: |
| 7344 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7345 | * privileges. |
| 7346 | * |
| 7347 | * @param subId subscription id |
| 7348 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7349 | */ |
| 7350 | @Override |
| 7351 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7352 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7353 | mApp, subId, "setDataRoamingEnabled"); |
| 7354 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7355 | final long identity = Binder.clearCallingIdentity(); |
| 7356 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7357 | Phone phone = getPhone(subId); |
| 7358 | if (phone != null) { |
| 7359 | phone.setDataRoamingEnabled(isEnabled); |
| 7360 | } |
| 7361 | } finally { |
| 7362 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7363 | } |
| 7364 | } |
| 7365 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7366 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7367 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7368 | TelephonyPermissions |
| 7369 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7370 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7371 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7372 | boolean isAllowed = true; |
| 7373 | final long identity = Binder.clearCallingIdentity(); |
| 7374 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7375 | Phone phone = getPhone(subId); |
| 7376 | if (phone != null) { |
| 7377 | isAllowed = phone.isCspPlmnEnabled(); |
| 7378 | } |
| 7379 | } finally { |
| 7380 | Binder.restoreCallingIdentity(identity); |
| 7381 | } |
| 7382 | return isAllowed; |
| 7383 | } |
| 7384 | |
| 7385 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7386 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7387 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7388 | try { |
| 7389 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7390 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7391 | } catch (SecurityException e) { |
| 7392 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7393 | // has carrier privileges on an active UICC |
| 7394 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7395 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7396 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7397 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7398 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7399 | |
| 7400 | final long identity = Binder.clearCallingIdentity(); |
| 7401 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7402 | UiccController uiccController = UiccController.getInstance(); |
| 7403 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7404 | if (hasReadPermission) { |
| 7405 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7406 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7407 | |
| 7408 | // Remove private info if the caller doesn't have access |
| 7409 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7410 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7411 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7412 | // is available |
| 7413 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7414 | if (card == null || card.getUiccProfile() == null) { |
| 7415 | // assume no access if the card or profile is unavailable |
| 7416 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7417 | continue; |
| 7418 | } |
| 7419 | UiccProfile profile = card.getUiccProfile(); |
| 7420 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7421 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7422 | filteredInfos.add(cardInfo); |
| 7423 | } else { |
| 7424 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7425 | } |
| 7426 | } |
| 7427 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7428 | } finally { |
| 7429 | Binder.restoreCallingIdentity(identity); |
| 7430 | } |
| 7431 | } |
| 7432 | |
| 7433 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7434 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7435 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7436 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7437 | final long identity = Binder.clearCallingIdentity(); |
| 7438 | try { |
| 7439 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7440 | if (slots == null) { |
| 7441 | Rlog.i(LOG_TAG, "slots is null."); |
| 7442 | return null; |
| 7443 | } |
| 7444 | |
| 7445 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7446 | for (int i = 0; i < slots.length; i++) { |
| 7447 | UiccSlot slot = slots[i]; |
| 7448 | if (slot == null) { |
| 7449 | continue; |
| 7450 | } |
| 7451 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7452 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7453 | UiccCard card = slot.getUiccCard(); |
| 7454 | if (card != null) { |
| 7455 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7456 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7457 | cardId = slot.getEid(); |
| 7458 | if (TextUtils.isEmpty(cardId)) { |
| 7459 | cardId = slot.getIccId(); |
| 7460 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7461 | } |
| 7462 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7463 | if (cardId != null) { |
| 7464 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7465 | // if cardId is an EID, it's all digits so this is fine |
| 7466 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7467 | } |
| 7468 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7469 | int cardState = 0; |
| 7470 | switch (slot.getCardState()) { |
| 7471 | case CARDSTATE_ABSENT: |
| 7472 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7473 | break; |
| 7474 | case CARDSTATE_PRESENT: |
| 7475 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7476 | break; |
| 7477 | case CARDSTATE_ERROR: |
| 7478 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7479 | break; |
| 7480 | case CARDSTATE_RESTRICTED: |
| 7481 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7482 | break; |
| 7483 | default: |
| 7484 | break; |
| 7485 | |
| 7486 | } |
| 7487 | |
| 7488 | infos[i] = new UiccSlotInfo( |
| 7489 | slot.isActive(), |
| 7490 | slot.isEuicc(), |
| 7491 | cardId, |
| 7492 | cardState, |
| 7493 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7494 | slot.isExtendedApduSupported(), |
| 7495 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7496 | } |
| 7497 | return infos; |
| 7498 | } finally { |
| 7499 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7500 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7501 | } |
| 7502 | |
| 7503 | @Override |
| 7504 | public boolean switchSlots(int[] physicalSlots) { |
| 7505 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7506 | |
| 7507 | final long identity = Binder.clearCallingIdentity(); |
| 7508 | try { |
| 7509 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7510 | } finally { |
| 7511 | Binder.restoreCallingIdentity(identity); |
| 7512 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7513 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7514 | |
| 7515 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7516 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7517 | final long identity = Binder.clearCallingIdentity(); |
| 7518 | try { |
| 7519 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7520 | } finally { |
| 7521 | Binder.restoreCallingIdentity(identity); |
| 7522 | } |
| 7523 | } |
| 7524 | |
| 7525 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7526 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 7527 | enforceModifyPermission(); |
| 7528 | final Phone phone = getPhone(subId); |
| 7529 | if (phone == null) { |
| 7530 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 7531 | return; |
| 7532 | } |
| 7533 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7534 | final long identity = Binder.clearCallingIdentity(); |
| 7535 | try { |
| 7536 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 7537 | } finally { |
| 7538 | Binder.restoreCallingIdentity(identity); |
| 7539 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7540 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7541 | |
| 7542 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7543 | * A test API to reload the UICC profile. |
| 7544 | * |
| 7545 | * <p>Requires that the calling app has permission |
| 7546 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7547 | * @hide |
| 7548 | */ |
| 7549 | @Override |
| 7550 | public void refreshUiccProfile(int subId) { |
| 7551 | enforceModifyPermission(); |
| 7552 | |
| 7553 | final long identity = Binder.clearCallingIdentity(); |
| 7554 | try { |
| 7555 | Phone phone = getPhone(subId); |
| 7556 | if (phone == null) { |
| 7557 | return; |
| 7558 | } |
| 7559 | UiccCard uiccCard = phone.getUiccCard(); |
| 7560 | if (uiccCard == null) { |
| 7561 | return; |
| 7562 | } |
| 7563 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7564 | if (uiccProfile == null) { |
| 7565 | return; |
| 7566 | } |
| 7567 | uiccProfile.refresh(); |
| 7568 | } finally { |
| 7569 | Binder.restoreCallingIdentity(identity); |
| 7570 | } |
| 7571 | } |
| 7572 | |
| 7573 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7574 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7575 | */ |
| 7576 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7577 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7578 | } |
| 7579 | |
| 7580 | /** |
| 7581 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7582 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7583 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7584 | */ |
| 7585 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7586 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7587 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7588 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7589 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7590 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7591 | return isDataRoamingEnabled; |
| 7592 | } |
| 7593 | |
| 7594 | /** |
| 7595 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7596 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7597 | */ |
| 7598 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7599 | List<Integer> list = TelephonyProperties.default_network(); |
| 7600 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7601 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7602 | return list.get(phoneId); |
| 7603 | } |
| 7604 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7605 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7606 | |
| 7607 | @Override |
| 7608 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7609 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7610 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7611 | |
| 7612 | final long identity = Binder.clearCallingIdentity(); |
| 7613 | try { |
| 7614 | final Phone phone = getPhone(subId); |
| 7615 | if (phone == null) { |
| 7616 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7617 | return; |
| 7618 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7619 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7620 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7621 | } finally { |
| 7622 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7623 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7624 | } |
| 7625 | |
| 7626 | @Override |
| 7627 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7628 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7629 | |
| 7630 | final long identity = Binder.clearCallingIdentity(); |
| 7631 | try { |
| 7632 | final Phone phone = getPhone(subId); |
| 7633 | if (phone == null) { |
| 7634 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7635 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7636 | } |
| 7637 | return phone.getCarrierIdListVersion(); |
| 7638 | } finally { |
| 7639 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7640 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7641 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7642 | |
| 7643 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7644 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7645 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7646 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7647 | mApp, subId, callingPackage, callingFeatureId, |
| 7648 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7649 | return -1; |
| 7650 | } |
| 7651 | |
| 7652 | final long identity = Binder.clearCallingIdentity(); |
| 7653 | try { |
| 7654 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7655 | } finally { |
| 7656 | Binder.restoreCallingIdentity(identity); |
| 7657 | } |
| 7658 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7659 | |
| 7660 | @Override |
| 7661 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7662 | TelephonyPermissions |
| 7663 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7664 | mApp, subId, "getCdmaRoamingMode"); |
| 7665 | |
| 7666 | final long identity = Binder.clearCallingIdentity(); |
| 7667 | try { |
| 7668 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7669 | } finally { |
| 7670 | Binder.restoreCallingIdentity(identity); |
| 7671 | } |
| 7672 | } |
| 7673 | |
| 7674 | @Override |
| 7675 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7676 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7677 | mApp, subId, "setCdmaRoamingMode"); |
| 7678 | |
| 7679 | final long identity = Binder.clearCallingIdentity(); |
| 7680 | try { |
| 7681 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7682 | } finally { |
| 7683 | Binder.restoreCallingIdentity(identity); |
| 7684 | } |
| 7685 | } |
| 7686 | |
| 7687 | @Override |
| 7688 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7689 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7690 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7691 | |
| 7692 | final long identity = Binder.clearCallingIdentity(); |
| 7693 | try { |
| 7694 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7695 | } finally { |
| 7696 | Binder.restoreCallingIdentity(identity); |
| 7697 | } |
| 7698 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7699 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7700 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7701 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7702 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7703 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7704 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7705 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7706 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7707 | } |
| 7708 | final long identity = Binder.clearCallingIdentity(); |
| 7709 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7710 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7711 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7712 | if (phone.getEmergencyNumberTracker() != null |
| 7713 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7714 | emergencyNumberListInternal.put( |
| 7715 | phone.getSubId(), |
| 7716 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7717 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7718 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7719 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7720 | } finally { |
| 7721 | Binder.restoreCallingIdentity(identity); |
| 7722 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7723 | } |
| 7724 | |
| 7725 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7726 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7727 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7728 | if (!exactMatch) { |
| 7729 | TelephonyPermissions |
| 7730 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7731 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7732 | } |
| 7733 | final long identity = Binder.clearCallingIdentity(); |
| 7734 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7735 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7736 | if (phone.getEmergencyNumberTracker() != null |
| 7737 | && phone.getEmergencyNumberTracker() != null) { |
| 7738 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7739 | number, exactMatch)) { |
| 7740 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7741 | } |
| 7742 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7743 | } |
| 7744 | return false; |
| 7745 | } finally { |
| 7746 | Binder.restoreCallingIdentity(identity); |
| 7747 | } |
| 7748 | } |
| 7749 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7750 | /** |
| 7751 | * Update emergency number list for test mode. |
| 7752 | */ |
| 7753 | @Override |
| 7754 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7755 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7756 | "updateEmergencyNumberListTestMode"); |
| 7757 | |
| 7758 | final long identity = Binder.clearCallingIdentity(); |
| 7759 | try { |
| 7760 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7761 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7762 | if (tracker != null) { |
| 7763 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7764 | } |
| 7765 | } |
| 7766 | } finally { |
| 7767 | Binder.restoreCallingIdentity(identity); |
| 7768 | } |
| 7769 | } |
| 7770 | |
| 7771 | /** |
| 7772 | * Get the full emergency number list for test mode. |
| 7773 | */ |
| 7774 | @Override |
| 7775 | public List<String> getEmergencyNumberListTestMode() { |
| 7776 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7777 | "getEmergencyNumberListTestMode"); |
| 7778 | |
| 7779 | final long identity = Binder.clearCallingIdentity(); |
| 7780 | try { |
| 7781 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7782 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7783 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7784 | if (tracker != null) { |
| 7785 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7786 | emergencyNumbers.add(num.getNumber()); |
| 7787 | } |
| 7788 | } |
| 7789 | } |
| 7790 | return new ArrayList<>(emergencyNumbers); |
| 7791 | } finally { |
| 7792 | Binder.restoreCallingIdentity(identity); |
| 7793 | } |
| 7794 | } |
| 7795 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7796 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7797 | public int getEmergencyNumberDbVersion(int subId) { |
| 7798 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7799 | |
| 7800 | final long identity = Binder.clearCallingIdentity(); |
| 7801 | try { |
| 7802 | final Phone phone = getPhone(subId); |
| 7803 | if (phone == null) { |
| 7804 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7805 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7806 | } |
| 7807 | return phone.getEmergencyNumberDbVersion(); |
| 7808 | } finally { |
| 7809 | Binder.restoreCallingIdentity(identity); |
| 7810 | } |
| 7811 | } |
| 7812 | |
| 7813 | @Override |
| 7814 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7815 | enforceModifyPermission(); |
| 7816 | |
| 7817 | final long identity = Binder.clearCallingIdentity(); |
| 7818 | try { |
| 7819 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7820 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7821 | if (tracker != null) { |
| 7822 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7823 | } |
| 7824 | } |
| 7825 | } finally { |
| 7826 | Binder.restoreCallingIdentity(identity); |
| 7827 | } |
| 7828 | } |
| 7829 | |
| 7830 | @Override |
| 7831 | public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) { |
| 7832 | enforceActiveEmergencySessionPermission(); |
| 7833 | |
| 7834 | final long identity = Binder.clearCallingIdentity(); |
| 7835 | try { |
| 7836 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7837 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7838 | if (tracker != null) { |
| 7839 | tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath); |
| 7840 | } |
| 7841 | } |
| 7842 | } finally { |
| 7843 | Binder.restoreCallingIdentity(identity); |
| 7844 | } |
| 7845 | } |
| 7846 | |
| 7847 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7848 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7849 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7850 | Phone phone = getPhone(subId); |
| 7851 | if (phone == null) { |
| 7852 | return null; |
| 7853 | } |
| 7854 | final long identity = Binder.clearCallingIdentity(); |
| 7855 | try { |
| 7856 | UiccProfile profile = UiccController.getInstance() |
| 7857 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7858 | if (profile != null) { |
| 7859 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7860 | } |
| 7861 | } finally { |
| 7862 | Binder.restoreCallingIdentity(identity); |
| 7863 | } |
| 7864 | return null; |
| 7865 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7866 | |
| 7867 | /** |
| 7868 | * Enable or disable a modem stack. |
| 7869 | */ |
| 7870 | @Override |
| 7871 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7872 | enforceModifyPermission(); |
| 7873 | |
| 7874 | final long identity = Binder.clearCallingIdentity(); |
| 7875 | try { |
| 7876 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7877 | if (phone == null) { |
| 7878 | return false; |
| 7879 | } else { |
| 7880 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7881 | } |
| 7882 | } finally { |
| 7883 | Binder.restoreCallingIdentity(identity); |
| 7884 | } |
| 7885 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7886 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7887 | /** |
| 7888 | * Whether a modem stack is enabled or not. |
| 7889 | */ |
| 7890 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7891 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7892 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7893 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7894 | if (phone == null) return false; |
| 7895 | |
| 7896 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7897 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7898 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7899 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7900 | } |
| 7901 | |
| 7902 | final long identity = Binder.clearCallingIdentity(); |
| 7903 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7904 | try { |
| 7905 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7906 | } catch (NoSuchElementException ex) { |
| 7907 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7908 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7909 | } finally { |
| 7910 | Binder.restoreCallingIdentity(identity); |
| 7911 | } |
| 7912 | } |
| 7913 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7914 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7915 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7916 | enforceModifyPermission(); |
| 7917 | |
| 7918 | final long identity = Binder.clearCallingIdentity(); |
| 7919 | try { |
| 7920 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7921 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7922 | .commit(); |
| 7923 | } finally { |
| 7924 | Binder.restoreCallingIdentity(identity); |
| 7925 | } |
| 7926 | } |
| 7927 | |
| 7928 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7929 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7930 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7931 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7932 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 7933 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7934 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7935 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7936 | |
| 7937 | final long identity = Binder.clearCallingIdentity(); |
| 7938 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7939 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7940 | } finally { |
| 7941 | Binder.restoreCallingIdentity(identity); |
| 7942 | } |
| 7943 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7944 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7945 | @TelephonyManager.IsMultiSimSupportedResult |
| 7946 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7947 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7948 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7949 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7950 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7951 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7952 | } |
| 7953 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7954 | // supported by the modem, indicate that it is restricted. |
| 7955 | PhoneCapability staticCapability = |
| 7956 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7957 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7958 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7959 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7960 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 7961 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7962 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7963 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7964 | } |
| 7965 | // Check if support of multiple SIMs is restricted by carrier |
| 7966 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7967 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7968 | } |
| 7969 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7970 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7971 | } |
| 7972 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7973 | /** |
| 7974 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7975 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7976 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7977 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7978 | * @param numOfSims number of active sims we want to switch to |
| 7979 | */ |
| 7980 | @Override |
| 7981 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7982 | if (numOfSims == 1) { |
| 7983 | enforceModifyPermission(); |
| 7984 | } else { |
| 7985 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7986 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7987 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7988 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7989 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7990 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7991 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7992 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7993 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7994 | return; |
| 7995 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7996 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7997 | } finally { |
| 7998 | Binder.restoreCallingIdentity(identity); |
| 7999 | } |
| 8000 | } |
| 8001 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8002 | @Override |
| 8003 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8004 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8005 | Phone phone = getPhone(subId); |
| 8006 | if (phone == null) { |
| 8007 | return false; |
| 8008 | } |
| 8009 | final long identity = Binder.clearCallingIdentity(); |
| 8010 | try { |
| 8011 | UiccCard uiccCard = phone.getUiccCard(); |
| 8012 | if (uiccCard == null) { |
| 8013 | return false; |
| 8014 | } |
| 8015 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8016 | if (uiccProfile == null) { |
| 8017 | return false; |
| 8018 | } |
| 8019 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8020 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8021 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8022 | } |
| 8023 | return false; |
| 8024 | } finally { |
| 8025 | Binder.restoreCallingIdentity(identity); |
| 8026 | } |
| 8027 | } |
| 8028 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8029 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8030 | * Get whether making changes to modem configurations will trigger reboot. |
| 8031 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8032 | */ |
| 8033 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8034 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8035 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8036 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8037 | mApp, subId, callingPackage, callingFeatureId, |
| 8038 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8039 | return false; |
| 8040 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8041 | final long identity = Binder.clearCallingIdentity(); |
| 8042 | try { |
| 8043 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8044 | } finally { |
| 8045 | Binder.restoreCallingIdentity(identity); |
| 8046 | } |
| 8047 | } |
| 8048 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8049 | private void updateModemStateMetrics() { |
| 8050 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8051 | // TODO: check the state for each modem if the api is ready. |
| 8052 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8053 | } |
| 8054 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8055 | @Override |
| 8056 | public int[] getSlotsMapping() { |
| 8057 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8058 | |
| 8059 | final long identity = Binder.clearCallingIdentity(); |
| 8060 | try { |
| 8061 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8062 | // All logical slots should have a mapping to a physical slot. |
| 8063 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8064 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8065 | for (int i = 0; i < slotInfos.length; i++) { |
| 8066 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8067 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8068 | } |
| 8069 | } |
| 8070 | return logicalSlotsMapping; |
| 8071 | } finally { |
| 8072 | Binder.restoreCallingIdentity(identity); |
| 8073 | } |
| 8074 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8075 | |
| 8076 | /** |
| 8077 | * Get the IRadio HAL Version |
| 8078 | */ |
| 8079 | @Override |
| 8080 | public int getRadioHalVersion() { |
| 8081 | Phone phone = getDefaultPhone(); |
| 8082 | if (phone == null) return -1; |
| 8083 | HalVersion hv = phone.getHalVersion(); |
| 8084 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8085 | return hv.major * 100 + hv.minor; |
| 8086 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8087 | |
| 8088 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8089 | * Get the current calling package name. |
| 8090 | * @return the current calling package name |
| 8091 | */ |
| 8092 | @Override |
| 8093 | public String getCurrentPackageName() { |
| 8094 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8095 | } |
| 8096 | |
| 8097 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8098 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8099 | * corresponding network requests on a subId. |
| 8100 | * |
| 8101 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8102 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8103 | * 2) APN is un-metered for this subscription, or |
| 8104 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8105 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8106 | * |
| 8107 | * @return whether data is allowed for a apn type. |
| 8108 | * |
| 8109 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8110 | */ |
| 8111 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8112 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8113 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8114 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8115 | |
| 8116 | // Now that all security checks passes, perform the operation as ourselves. |
| 8117 | final long identity = Binder.clearCallingIdentity(); |
| 8118 | try { |
| 8119 | Phone phone = getPhone(subId); |
| 8120 | if (phone == null) return false; |
| 8121 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8122 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8123 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8124 | } finally { |
| 8125 | Binder.restoreCallingIdentity(identity); |
| 8126 | } |
| 8127 | } |
| 8128 | |
| 8129 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8130 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8131 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8132 | |
| 8133 | // Now that all security checks passes, perform the operation as ourselves. |
| 8134 | final long identity = Binder.clearCallingIdentity(); |
| 8135 | try { |
| 8136 | Phone phone = getPhone(subId); |
| 8137 | if (phone == null) return true; // By default return true. |
| 8138 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8139 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8140 | } finally { |
| 8141 | Binder.restoreCallingIdentity(identity); |
| 8142 | } |
| 8143 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8144 | |
| 8145 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8146 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
| 8147 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8148 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8149 | if (iccRecords == null) { |
| 8150 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8151 | return false; |
| 8152 | } |
| 8153 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8154 | } |
| 8155 | |
| 8156 | @Override |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8157 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8158 | if (callingPackage == null) { |
| 8159 | callingPackage = getCurrentPackageName(); |
| 8160 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8161 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8162 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 8163 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 8164 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8165 | } |
| 8166 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8167 | Intent intent = new Intent(); |
| 8168 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8169 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8170 | // Bring up choose default SMS subscription dialog right now |
| 8171 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8172 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8173 | mApp.startActivity(intent); |
| 8174 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8175 | |
| 8176 | @Override |
| 8177 | public String getMmsUAProfUrl(int subId) { |
| 8178 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8179 | final long identity = Binder.clearCallingIdentity(); |
| 8180 | try { |
| 8181 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8182 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 8183 | } finally { |
| 8184 | Binder.restoreCallingIdentity(identity); |
| 8185 | } |
| 8186 | } |
| 8187 | |
| 8188 | @Override |
| 8189 | public String getMmsUserAgent(int subId) { |
| 8190 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8191 | final long identity = Binder.clearCallingIdentity(); |
| 8192 | try { |
| 8193 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8194 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8195 | } finally { |
| 8196 | Binder.restoreCallingIdentity(identity); |
| 8197 | } |
| 8198 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8199 | |
| 8200 | @Override |
| 8201 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 8202 | enforceModifyPermission(); |
| 8203 | |
| 8204 | // Now that all security checks passes, perform the operation as ourselves. |
| 8205 | final long identity = Binder.clearCallingIdentity(); |
| 8206 | try { |
| 8207 | Phone phone = getPhone(subId); |
| 8208 | if (phone == null) return false; |
| 8209 | |
| 8210 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 8211 | } finally { |
| 8212 | Binder.restoreCallingIdentity(identity); |
| 8213 | } |
| 8214 | } |
| 8215 | |
| 8216 | @Override |
| 8217 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 8218 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 8219 | |
| 8220 | // Now that all security checks passes, perform the operation as ourselves. |
| 8221 | final long identity = Binder.clearCallingIdentity(); |
| 8222 | try { |
| 8223 | Phone phone = getPhone(subId); |
| 8224 | if (phone == null) return false; |
| 8225 | |
| 8226 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8227 | } finally { |
| 8228 | Binder.restoreCallingIdentity(identity); |
| 8229 | } |
| 8230 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8231 | |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8232 | @Override |
| 8233 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8234 | enforceModifyPermission(); |
| 8235 | |
| 8236 | // Now that all security checks passes, perform the operation as ourselves. |
| 8237 | final long identity = Binder.clearCallingIdentity(); |
| 8238 | try { |
| 8239 | Phone phone = getPhone(subId); |
| 8240 | if (phone == null) return false; |
| 8241 | |
| 8242 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8243 | } finally { |
| 8244 | Binder.restoreCallingIdentity(identity); |
| 8245 | } |
| 8246 | } |
| 8247 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8248 | /** |
| 8249 | * Updates whether conference event pacakge handling is enabled. |
| 8250 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8251 | * otherwise. |
| 8252 | */ |
| 8253 | @Override |
| 8254 | public void setCepEnabled(boolean isCepEnabled) { |
| 8255 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8256 | |
| 8257 | final long identity = Binder.clearCallingIdentity(); |
| 8258 | try { |
| 8259 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8260 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8261 | Phone defaultPhone = phone.getImsPhone(); |
| 8262 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8263 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8264 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8265 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8266 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8267 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8268 | + imsPhone.getMsisdn()); |
| 8269 | } |
| 8270 | } |
| 8271 | } finally { |
| 8272 | Binder.restoreCallingIdentity(identity); |
| 8273 | } |
| 8274 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8275 | |
| 8276 | /** |
| 8277 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8278 | * |
| 8279 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8280 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8281 | * before being read. |
| 8282 | */ |
| 8283 | @Override |
| 8284 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8285 | isCompressed) { |
| 8286 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8287 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8288 | try { |
| 8289 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8290 | if (configBinder == null) { |
| 8291 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8292 | } else { |
| 8293 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8294 | } |
| 8295 | } catch (RemoteException e) { |
| 8296 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8297 | } |
| 8298 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8299 | |
| 8300 | @Override |
| 8301 | public boolean isIccLockEnabled(int subId) { |
| 8302 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8303 | |
| 8304 | // Now that all security checks passes, perform the operation as ourselves. |
| 8305 | final long identity = Binder.clearCallingIdentity(); |
| 8306 | try { |
| 8307 | Phone phone = getPhone(subId); |
| 8308 | if (phone != null && phone.getIccCard() != null) { |
| 8309 | return phone.getIccCard().getIccLockEnabled(); |
| 8310 | } else { |
| 8311 | return false; |
| 8312 | } |
| 8313 | } finally { |
| 8314 | Binder.restoreCallingIdentity(identity); |
| 8315 | } |
| 8316 | } |
| 8317 | |
| 8318 | /** |
| 8319 | * Set the ICC pin lock enabled or disabled.. |
| 8320 | * |
| 8321 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8322 | * 0 or a positive integer as the attempts remaining value. |
| 8323 | * |
| 8324 | */ |
| 8325 | @Override |
| 8326 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8327 | enforceModifyPermission(); |
| 8328 | |
| 8329 | Phone phone = getPhone(subId); |
| 8330 | if (phone == null) { |
| 8331 | return 0; |
| 8332 | } |
| 8333 | // Now that all security checks passes, perform the operation as ourselves. |
| 8334 | final long identity = Binder.clearCallingIdentity(); |
| 8335 | try { |
| 8336 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8337 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8338 | return attemptsRemaining; |
| 8339 | |
| 8340 | } catch (Exception e) { |
| 8341 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8342 | } finally { |
| 8343 | Binder.restoreCallingIdentity(identity); |
| 8344 | } |
| 8345 | return 0; |
| 8346 | } |
| 8347 | |
| 8348 | /** |
| 8349 | * Change the ICC password used in ICC pin lock. |
| 8350 | * |
| 8351 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8352 | * 0 or a positive integer as the attempts remaining value. |
| 8353 | * |
| 8354 | */ |
| 8355 | @Override |
| 8356 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8357 | enforceModifyPermission(); |
| 8358 | |
| 8359 | Phone phone = getPhone(subId); |
| 8360 | if (phone == null) { |
| 8361 | return 0; |
| 8362 | } |
| 8363 | // Now that all security checks passes, perform the operation as ourselves. |
| 8364 | final long identity = Binder.clearCallingIdentity(); |
| 8365 | try { |
| 8366 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8367 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8368 | return attemptsRemaining; |
| 8369 | |
| 8370 | } catch (Exception e) { |
| 8371 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8372 | } finally { |
| 8373 | Binder.restoreCallingIdentity(identity); |
| 8374 | } |
| 8375 | return 0; |
| 8376 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8377 | } |