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; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 120 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 121 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 122 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 123 | import com.android.ims.internal.IImsServiceFeatureCallback; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 124 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 128 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 131 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame^] | 134 | import com.android.internal.telephony.IBooleanConsumer; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 160 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 171 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 172 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 174 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 175 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 176 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 177 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 178 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 179 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 180 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 181 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 182 | import java.io.FileDescriptor; |
| 183 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 184 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 185 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 186 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 187 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 188 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 189 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 190 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 191 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 192 | import java.util.Set; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame^] | 193 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 194 | |
| 195 | /** |
| 196 | * Implementation of the ITelephony interface. |
| 197 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 198 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 199 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 200 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 201 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 202 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 203 | |
| 204 | // Message codes used with mMainThreadHandler |
| 205 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 206 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 207 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 208 | private static final int CMD_OPEN_CHANNEL = 9; |
| 209 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 210 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 211 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 212 | private static final int CMD_NV_READ_ITEM = 13; |
| 213 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 214 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 215 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 216 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 217 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 218 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 219 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 220 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 221 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 222 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 223 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 224 | private static final int CMD_SEND_ENVELOPE = 25; |
| 225 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 226 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 227 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 228 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 229 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 230 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 231 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 232 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 233 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 234 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 235 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 236 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 237 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 238 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 239 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 240 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 241 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 242 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 243 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 244 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 245 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 246 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 247 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 248 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 249 | private static final int CMD_SWITCH_SLOTS = 50; |
| 250 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 251 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 252 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 253 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 254 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 255 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 256 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 257 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 258 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 259 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 260 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 261 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 262 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 263 | private static final int CMD_MODEM_REBOOT = 64; |
| 264 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 265 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 266 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 267 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 268 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 269 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 270 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 271 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 272 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 273 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 274 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 275 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 276 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 277 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 278 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame^] | 279 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 280 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 281 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 282 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 283 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 284 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 285 | private static final int CMD_GET_CALL_WAITING = 87; |
| 286 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 287 | private static final int CMD_SET_CALL_WAITING = 89; |
| 288 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 289 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 290 | // Parameters of select command. |
| 291 | private static final int SELECT_COMMAND = 0xA4; |
| 292 | private static final int SELECT_P1 = 0x04; |
| 293 | private static final int SELECT_P2 = 0; |
| 294 | private static final int SELECT_P3 = 0x10; |
| 295 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 296 | /** The singleton instance. */ |
| 297 | private static PhoneInterfaceManager sInstance; |
| 298 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 299 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 300 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 301 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 302 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 303 | private AppOpsManager mAppOps; |
| 304 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 305 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 306 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 307 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 308 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 309 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 310 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 311 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 312 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 313 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 314 | // String to store multi SIM allowed |
| 315 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 316 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 317 | // The AID of ISD-R. |
| 318 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 319 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 320 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 321 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 322 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 323 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 324 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 325 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 326 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 327 | */ |
| 328 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 329 | "reset_network_erase_modem_config_enabled"; |
| 330 | |
| 331 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 332 | * A request object to use for transmitting data to an ICC. |
| 333 | */ |
| 334 | private static final class IccAPDUArgument { |
| 335 | public int channel, cla, command, p1, p2, p3; |
| 336 | public String data; |
| 337 | |
| 338 | public IccAPDUArgument(int channel, int cla, int command, |
| 339 | int p1, int p2, int p3, String data) { |
| 340 | this.channel = channel; |
| 341 | this.cla = cla; |
| 342 | this.command = command; |
| 343 | this.p1 = p1; |
| 344 | this.p2 = p2; |
| 345 | this.p3 = p3; |
| 346 | this.data = data; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 351 | * A request object to use for transmitting data to an ICC. |
| 352 | */ |
| 353 | private static final class ManualNetworkSelectionArgument { |
| 354 | public OperatorInfo operatorInfo; |
| 355 | public boolean persistSelection; |
| 356 | |
| 357 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 358 | this.operatorInfo = operatorInfo; |
| 359 | this.persistSelection = persistSelection; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 364 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 365 | * request after sending. The main thread will notify the request when it is complete. |
| 366 | */ |
| 367 | private static final class MainThreadRequest { |
| 368 | /** The argument to use for the request */ |
| 369 | public Object argument; |
| 370 | /** The result of the request that is run on the main thread */ |
| 371 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 372 | // The subscriber id that this request applies to. Defaults to |
| 373 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 374 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 375 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 376 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 377 | public Phone phone; |
| 378 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 379 | public WorkSource workSource; |
| 380 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 381 | public MainThreadRequest(Object argument) { |
| 382 | this.argument = argument; |
| 383 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 384 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 385 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 386 | this.argument = argument; |
| 387 | if (phone != null) { |
| 388 | this.phone = phone; |
| 389 | } |
| 390 | this.workSource = workSource; |
| 391 | } |
| 392 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 393 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 394 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 395 | if (subId != null) { |
| 396 | this.subId = subId; |
| 397 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 398 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 399 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 402 | private static final class IncomingThirdPartyCallArgs { |
| 403 | public final ComponentName component; |
| 404 | public final String callId; |
| 405 | public final String callerDisplayName; |
| 406 | |
| 407 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 408 | String callerDisplayName) { |
| 409 | this.component = component; |
| 410 | this.callId = callId; |
| 411 | this.callerDisplayName = callerDisplayName; |
| 412 | } |
| 413 | } |
| 414 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 415 | /** |
| 416 | * A handler that processes messages on the main thread in the phone process. Since many |
| 417 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 418 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 419 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 420 | * on, which will be notified when the operation completes and will contain the result of the |
| 421 | * request. |
| 422 | * |
| 423 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 424 | * note that request.result must be set to something non-null for the calling thread to |
| 425 | * unblock. |
| 426 | */ |
| 427 | private final class MainThreadHandler extends Handler { |
| 428 | @Override |
| 429 | public void handleMessage(Message msg) { |
| 430 | MainThreadRequest request; |
| 431 | Message onCompleted; |
| 432 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 433 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 434 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 435 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 436 | |
| 437 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 438 | case CMD_HANDLE_USSD_REQUEST: { |
| 439 | request = (MainThreadRequest) msg.obj; |
| 440 | final Phone phone = getPhoneFromRequest(request); |
| 441 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 442 | String ussdRequest = ussdObject.first; |
| 443 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 444 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 445 | if (!isUssdApiAllowed(request.subId)) { |
| 446 | // Carrier does not support use of this API, return failure. |
| 447 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 448 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 449 | Bundle returnData = new Bundle(); |
| 450 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 451 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 452 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 453 | request.result = true; |
| 454 | notifyRequester(request); |
| 455 | return; |
| 456 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 457 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 458 | try { |
| 459 | request.result = phone != null |
| 460 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 461 | } catch (CallStateException cse) { |
| 462 | request.result = false; |
| 463 | } |
| 464 | // Wake up the requesting thread |
| 465 | notifyRequester(request); |
| 466 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 469 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 470 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 471 | final Phone phone = getPhoneFromRequest(request); |
| 472 | request.result = phone != null ? |
| 473 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 474 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 475 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 476 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 477 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 478 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 479 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 480 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 481 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 482 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 483 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 484 | if (uiccCard == null) { |
| 485 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 486 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 487 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 488 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 489 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 490 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 491 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 492 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 493 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 494 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 495 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 496 | break; |
| 497 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 498 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 499 | ar = (AsyncResult) msg.obj; |
| 500 | request = (MainThreadRequest) ar.userObj; |
| 501 | if (ar.exception == null && ar.result != null) { |
| 502 | request.result = ar.result; |
| 503 | } else { |
| 504 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 505 | if (ar.result == null) { |
| 506 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 507 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 508 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 509 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 510 | } else { |
| 511 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 512 | } |
| 513 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 514 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 515 | break; |
| 516 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 517 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 518 | request = (MainThreadRequest) msg.obj; |
| 519 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 520 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 521 | if (uiccCard == null) { |
| 522 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 523 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 524 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 525 | } else { |
| 526 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 527 | request); |
| 528 | uiccCard.iccTransmitApduBasicChannel( |
| 529 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 530 | iccArgument.p3, iccArgument.data, onCompleted); |
| 531 | } |
| 532 | break; |
| 533 | |
| 534 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 535 | ar = (AsyncResult) msg.obj; |
| 536 | request = (MainThreadRequest) ar.userObj; |
| 537 | if (ar.exception == null && ar.result != null) { |
| 538 | request.result = ar.result; |
| 539 | } else { |
| 540 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 541 | if (ar.result == null) { |
| 542 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 543 | } else if (ar.exception instanceof CommandException) { |
| 544 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 545 | ar.exception); |
| 546 | } else { |
| 547 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 548 | } |
| 549 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 550 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 551 | break; |
| 552 | |
| 553 | case CMD_EXCHANGE_SIM_IO: |
| 554 | request = (MainThreadRequest) msg.obj; |
| 555 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 556 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 557 | if (uiccCard == null) { |
| 558 | loge("iccExchangeSimIO: No UICC"); |
| 559 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 560 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 561 | } else { |
| 562 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 563 | request); |
| 564 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 565 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 566 | iccArgument.data, onCompleted); |
| 567 | } |
| 568 | break; |
| 569 | |
| 570 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 571 | ar = (AsyncResult) msg.obj; |
| 572 | request = (MainThreadRequest) ar.userObj; |
| 573 | if (ar.exception == null && ar.result != null) { |
| 574 | request.result = ar.result; |
| 575 | } else { |
| 576 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 577 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 578 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 579 | break; |
| 580 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 581 | case CMD_SEND_ENVELOPE: |
| 582 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 583 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 584 | if (uiccCard == null) { |
| 585 | loge("sendEnvelopeWithStatus: No UICC"); |
| 586 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 587 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 588 | } else { |
| 589 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 590 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 591 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 592 | break; |
| 593 | |
| 594 | case EVENT_SEND_ENVELOPE_DONE: |
| 595 | ar = (AsyncResult) msg.obj; |
| 596 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 597 | if (ar.exception == null && ar.result != null) { |
| 598 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 599 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 600 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 601 | if (ar.result == null) { |
| 602 | loge("sendEnvelopeWithStatus: Empty response"); |
| 603 | } else if (ar.exception instanceof CommandException) { |
| 604 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 605 | ar.exception); |
| 606 | } else { |
| 607 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 608 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 609 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 610 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 611 | break; |
| 612 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 613 | case CMD_OPEN_CHANNEL: |
| 614 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 615 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 616 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 617 | if (uiccCard == null) { |
| 618 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 619 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 620 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 621 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 622 | } else { |
| 623 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 624 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 625 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 626 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 627 | break; |
| 628 | |
| 629 | case EVENT_OPEN_CHANNEL_DONE: |
| 630 | ar = (AsyncResult) msg.obj; |
| 631 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 632 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 633 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 634 | int[] result = (int[]) ar.result; |
| 635 | int channelId = result[0]; |
| 636 | byte[] selectResponse = null; |
| 637 | if (result.length > 1) { |
| 638 | selectResponse = new byte[result.length - 1]; |
| 639 | for (int i = 1; i < result.length; ++i) { |
| 640 | selectResponse[i - 1] = (byte) result[i]; |
| 641 | } |
| 642 | } |
| 643 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 644 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 645 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 646 | if (ar.result == null) { |
| 647 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 648 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 649 | if (ar.exception != null) { |
| 650 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 651 | } |
| 652 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 653 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 654 | if (ar.exception instanceof CommandException) { |
| 655 | CommandException.Error error = |
| 656 | ((CommandException) (ar.exception)).getCommandError(); |
| 657 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 658 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 659 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 660 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 661 | } |
| 662 | } |
| 663 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 664 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 665 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 666 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 667 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 668 | break; |
| 669 | |
| 670 | case CMD_CLOSE_CHANNEL: |
| 671 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 672 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 673 | if (uiccCard == null) { |
| 674 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 675 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 676 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 677 | } else { |
| 678 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 679 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 680 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 681 | break; |
| 682 | |
| 683 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 684 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 685 | break; |
| 686 | |
| 687 | case CMD_NV_READ_ITEM: |
| 688 | request = (MainThreadRequest) msg.obj; |
| 689 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 690 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 691 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 692 | break; |
| 693 | |
| 694 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 695 | ar = (AsyncResult) msg.obj; |
| 696 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 697 | if (ar.exception == null && ar.result != null) { |
| 698 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 699 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 700 | request.result = ""; |
| 701 | if (ar.result == null) { |
| 702 | loge("nvReadItem: Empty response"); |
| 703 | } else if (ar.exception instanceof CommandException) { |
| 704 | loge("nvReadItem: CommandException: " + |
| 705 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 706 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 707 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 708 | } |
| 709 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 710 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 711 | break; |
| 712 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 713 | case CMD_NV_WRITE_ITEM: |
| 714 | request = (MainThreadRequest) msg.obj; |
| 715 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 716 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 717 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 718 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 719 | break; |
| 720 | |
| 721 | case EVENT_NV_WRITE_ITEM_DONE: |
| 722 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 723 | break; |
| 724 | |
| 725 | case CMD_NV_WRITE_CDMA_PRL: |
| 726 | request = (MainThreadRequest) msg.obj; |
| 727 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 728 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 729 | break; |
| 730 | |
| 731 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 732 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 733 | break; |
| 734 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 735 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 736 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 737 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 738 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 739 | break; |
| 740 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 741 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 742 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 743 | break; |
| 744 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 745 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 746 | request = (MainThreadRequest) msg.obj; |
| 747 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 748 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 749 | break; |
| 750 | |
| 751 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 752 | ar = (AsyncResult) msg.obj; |
| 753 | request = (MainThreadRequest) ar.userObj; |
| 754 | if (ar.exception == null && ar.result != null) { |
| 755 | request.result = ar.result; // Integer |
| 756 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 757 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 758 | if (ar.result == null) { |
| 759 | loge("getPreferredNetworkType: Empty response"); |
| 760 | } else if (ar.exception instanceof CommandException) { |
| 761 | loge("getPreferredNetworkType: CommandException: " + |
| 762 | ar.exception); |
| 763 | } else { |
| 764 | loge("getPreferredNetworkType: Unknown exception"); |
| 765 | } |
| 766 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 767 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 768 | break; |
| 769 | |
| 770 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 771 | request = (MainThreadRequest) msg.obj; |
| 772 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 773 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 774 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 775 | break; |
| 776 | |
| 777 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 778 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 779 | break; |
| 780 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 781 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 782 | request = (MainThreadRequest)msg.obj; |
| 783 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 784 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 785 | break; |
| 786 | |
| 787 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 788 | ar = (AsyncResult)msg.obj; |
| 789 | request = (MainThreadRequest)ar.userObj; |
| 790 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 791 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 792 | break; |
| 793 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 794 | case CMD_SET_VOICEMAIL_NUMBER: |
| 795 | request = (MainThreadRequest) msg.obj; |
| 796 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 797 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 798 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 799 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 800 | break; |
| 801 | |
| 802 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 803 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 804 | break; |
| 805 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 806 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 807 | request = (MainThreadRequest) msg.obj; |
| 808 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 809 | request); |
| 810 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 811 | break; |
| 812 | |
| 813 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 814 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 815 | break; |
| 816 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 817 | case CMD_PERFORM_NETWORK_SCAN: |
| 818 | request = (MainThreadRequest) msg.obj; |
| 819 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 820 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 821 | break; |
| 822 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 823 | case CMD_GET_CALL_FORWARDING: |
| 824 | request = (MainThreadRequest) msg.obj; |
| 825 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
| 826 | int callForwardingReason = (Integer) request.argument; |
| 827 | getPhoneFromRequest(request).getCallForwardingOption( |
| 828 | callForwardingReason, onCompleted); |
| 829 | break; |
| 830 | |
| 831 | case EVENT_GET_CALL_FORWARDING_DONE: |
| 832 | ar = (AsyncResult) msg.obj; |
| 833 | request = (MainThreadRequest) ar.userObj; |
| 834 | CallForwardingInfo callForwardingInfo = null; |
| 835 | if (ar.exception == null && ar.result != null) { |
| 836 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 837 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 838 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 839 | // any service for voice call. |
| 840 | if ((callForwardInfo.serviceClass |
| 841 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
| 842 | callForwardingInfo = new CallForwardingInfo( |
| 843 | callForwardInfo.serviceClass, callForwardInfo.reason, |
| 844 | callForwardInfo.number, |
| 845 | callForwardInfo.timeSeconds); |
| 846 | break; |
| 847 | } |
| 848 | } |
| 849 | // Didn't find a call forward info for voice call. |
| 850 | if (callForwardingInfo == null) { |
| 851 | callForwardingInfo = new CallForwardingInfo( |
| 852 | CallForwardingInfo.STATUS_UNKNOWN_ERROR, |
| 853 | 0 /* reason */, null /* number */, 0 /* timeout */); |
| 854 | } |
| 855 | } else { |
| 856 | if (ar.result == null) { |
| 857 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 858 | } |
| 859 | if (ar.exception != null) { |
| 860 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 861 | } |
| 862 | int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR; |
| 863 | if (ar.exception instanceof CommandException) { |
| 864 | CommandException.Error error = |
| 865 | ((CommandException) (ar.exception)).getCommandError(); |
| 866 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 867 | errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE; |
| 868 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 869 | errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED; |
| 870 | } |
| 871 | } |
| 872 | callForwardingInfo = new CallForwardingInfo( |
| 873 | errorCode, 0 /* reason */, null /* number */, 0 /* timeout */); |
| 874 | } |
| 875 | request.result = callForwardingInfo; |
| 876 | notifyRequester(request); |
| 877 | break; |
| 878 | |
| 879 | case CMD_SET_CALL_FORWARDING: |
| 880 | request = (MainThreadRequest) msg.obj; |
| 881 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
| 882 | CallForwardingInfo callForwardingInfoToSet = |
| 883 | (CallForwardingInfo) request.argument; |
| 884 | getPhoneFromRequest(request).setCallForwardingOption( |
| 885 | callForwardingInfoToSet.getStatus(), |
| 886 | callForwardingInfoToSet.getReason(), |
| 887 | callForwardingInfoToSet.getNumber(), |
| 888 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 889 | break; |
| 890 | |
| 891 | case EVENT_SET_CALL_FORWARDING_DONE: |
| 892 | ar = (AsyncResult) msg.obj; |
| 893 | request = (MainThreadRequest) ar.userObj; |
| 894 | if (ar.exception == null) { |
| 895 | request.result = true; |
| 896 | } else { |
| 897 | request.result = false; |
| 898 | loge("setCallForwarding exception: " + ar.exception); |
| 899 | } |
| 900 | notifyRequester(request); |
| 901 | break; |
| 902 | |
| 903 | case CMD_GET_CALL_WAITING: |
| 904 | request = (MainThreadRequest) msg.obj; |
| 905 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 906 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 907 | break; |
| 908 | |
| 909 | case EVENT_GET_CALL_WAITING_DONE: |
| 910 | ar = (AsyncResult) msg.obj; |
| 911 | request = (MainThreadRequest) ar.userObj; |
| 912 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 913 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 914 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 915 | // Service Class is a bit mask per 3gpp 27.007. |
| 916 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 917 | if (callForwardResults.length > 1 |
| 918 | && ((callForwardResults[1] |
| 919 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
| 920 | callForwardingStatus = callForwardResults[0] == 0 |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 921 | ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE |
| 922 | : TelephonyManager.CALL_WAITING_STATUS_ACTIVE; |
| 923 | } else { |
| 924 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE; |
| 925 | } |
| 926 | } else { |
| 927 | if (ar.result == null) { |
| 928 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 929 | } |
| 930 | if (ar.exception != null) { |
| 931 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 932 | } |
| 933 | if (ar.exception instanceof CommandException) { |
| 934 | CommandException.Error error = |
| 935 | ((CommandException) (ar.exception)).getCommandError(); |
| 936 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 937 | callForwardingStatus = |
| 938 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 939 | } |
| 940 | } |
| 941 | } |
| 942 | request.result = callForwardingStatus; |
| 943 | notifyRequester(request); |
| 944 | break; |
| 945 | |
| 946 | case CMD_SET_CALL_WAITING: |
| 947 | request = (MainThreadRequest) msg.obj; |
| 948 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
| 949 | boolean isEnable = (Boolean) request.argument; |
| 950 | getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted); |
| 951 | break; |
| 952 | |
| 953 | case EVENT_SET_CALL_WAITING_DONE: |
| 954 | ar = (AsyncResult) msg.obj; |
| 955 | request = (MainThreadRequest) ar.userObj; |
| 956 | if (ar.exception == null) { |
| 957 | request.result = true; |
| 958 | } else { |
| 959 | request.result = false; |
| 960 | loge("setCallWaiting exception: " + ar.exception); |
| 961 | } |
| 962 | notifyRequester(request); |
| 963 | break; |
| 964 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 965 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 966 | ar = (AsyncResult) msg.obj; |
| 967 | request = (MainThreadRequest) ar.userObj; |
| 968 | CellNetworkScanResult cellScanResult; |
| 969 | if (ar.exception == null && ar.result != null) { |
| 970 | cellScanResult = new CellNetworkScanResult( |
| 971 | CellNetworkScanResult.STATUS_SUCCESS, |
| 972 | (List<OperatorInfo>) ar.result); |
| 973 | } else { |
| 974 | if (ar.result == null) { |
| 975 | loge("getCellNetworkScanResults: Empty response"); |
| 976 | } |
| 977 | if (ar.exception != null) { |
| 978 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 979 | } |
| 980 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 981 | if (ar.exception instanceof CommandException) { |
| 982 | CommandException.Error error = |
| 983 | ((CommandException) (ar.exception)).getCommandError(); |
| 984 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 985 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 986 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 987 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 988 | } |
| 989 | } |
| 990 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 991 | } |
| 992 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 993 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 994 | break; |
| 995 | |
| 996 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 997 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 998 | ManualNetworkSelectionArgument selArg = |
| 999 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1000 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1001 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1002 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1003 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1004 | break; |
| 1005 | |
| 1006 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1007 | ar = (AsyncResult) msg.obj; |
| 1008 | request = (MainThreadRequest) ar.userObj; |
| 1009 | if (ar.exception == null) { |
| 1010 | request.result = true; |
| 1011 | } else { |
| 1012 | request.result = false; |
| 1013 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1014 | } |
| 1015 | notifyRequester(request); |
| 1016 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1017 | break; |
| 1018 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1019 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1020 | request = (MainThreadRequest) msg.obj; |
| 1021 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1022 | if (defaultPhone != null) { |
| 1023 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 1024 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1025 | break; |
| 1026 | |
| 1027 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1028 | ar = (AsyncResult) msg.obj; |
| 1029 | request = (MainThreadRequest) ar.userObj; |
| 1030 | if (ar.exception == null && ar.result != null) { |
| 1031 | request.result = ar.result; |
| 1032 | } else { |
| 1033 | if (ar.result == null) { |
| 1034 | loge("queryModemActivityInfo: Empty response"); |
| 1035 | } else if (ar.exception instanceof CommandException) { |
| 1036 | loge("queryModemActivityInfo: CommandException: " + |
| 1037 | ar.exception); |
| 1038 | } else { |
| 1039 | loge("queryModemActivityInfo: Unknown exception"); |
| 1040 | } |
| 1041 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 1042 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 1043 | if (request.result == null) { |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 1044 | request.result = new ModemActivityInfo(0, 0, 0, null, 0); |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 1045 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1046 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1047 | break; |
| 1048 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1049 | case CMD_SET_ALLOWED_CARRIERS: |
| 1050 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1051 | CarrierRestrictionRules argument = |
| 1052 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1053 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1054 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1055 | break; |
| 1056 | |
| 1057 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1058 | ar = (AsyncResult) msg.obj; |
| 1059 | request = (MainThreadRequest) ar.userObj; |
| 1060 | if (ar.exception == null && ar.result != null) { |
| 1061 | request.result = ar.result; |
| 1062 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1063 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1064 | if (ar.exception instanceof CommandException) { |
| 1065 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1066 | CommandException.Error error = |
| 1067 | ((CommandException) (ar.exception)).getCommandError(); |
| 1068 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1069 | request.result = |
| 1070 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1071 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1072 | } else { |
| 1073 | loge("setAllowedCarriers: Unknown exception"); |
| 1074 | } |
| 1075 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1076 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1077 | break; |
| 1078 | |
| 1079 | case CMD_GET_ALLOWED_CARRIERS: |
| 1080 | request = (MainThreadRequest) msg.obj; |
| 1081 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1082 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1083 | break; |
| 1084 | |
| 1085 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1086 | ar = (AsyncResult) msg.obj; |
| 1087 | request = (MainThreadRequest) ar.userObj; |
| 1088 | if (ar.exception == null && ar.result != null) { |
| 1089 | request.result = ar.result; |
| 1090 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1091 | request.result = new IllegalStateException( |
| 1092 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1093 | if (ar.result == null) { |
| 1094 | loge("getAllowedCarriers: Empty response"); |
| 1095 | } else if (ar.exception instanceof CommandException) { |
| 1096 | loge("getAllowedCarriers: CommandException: " + |
| 1097 | ar.exception); |
| 1098 | } else { |
| 1099 | loge("getAllowedCarriers: Unknown exception"); |
| 1100 | } |
| 1101 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1102 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1103 | break; |
| 1104 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1105 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1106 | ar = (AsyncResult) msg.obj; |
| 1107 | request = (MainThreadRequest) ar.userObj; |
| 1108 | if (ar.exception == null && ar.result != null) { |
| 1109 | request.result = ar.result; |
| 1110 | } else { |
| 1111 | request.result = new IllegalArgumentException( |
| 1112 | "Failed to retrieve Forbidden Plmns"); |
| 1113 | if (ar.result == null) { |
| 1114 | loge("getForbiddenPlmns: Empty response"); |
| 1115 | } else { |
| 1116 | loge("getForbiddenPlmns: Unknown exception"); |
| 1117 | } |
| 1118 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1119 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1120 | break; |
| 1121 | |
| 1122 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1123 | request = (MainThreadRequest) msg.obj; |
| 1124 | uiccCard = getUiccCardFromRequest(request); |
| 1125 | if (uiccCard == null) { |
| 1126 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1127 | request.result = new IllegalArgumentException( |
| 1128 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1129 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1130 | break; |
| 1131 | } |
| 1132 | Integer appType = (Integer) request.argument; |
| 1133 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1134 | if (uiccApp == null) { |
| 1135 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1136 | + appType); |
| 1137 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1138 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1139 | break; |
| 1140 | } else { |
| 1141 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1142 | + " specified type -- " + appType); |
| 1143 | } |
| 1144 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1145 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1146 | onCompleted); |
| 1147 | break; |
| 1148 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1149 | case CMD_SWITCH_SLOTS: |
| 1150 | request = (MainThreadRequest) msg.obj; |
| 1151 | int[] physicalSlots = (int[]) request.argument; |
| 1152 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1153 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1154 | break; |
| 1155 | |
| 1156 | case EVENT_SWITCH_SLOTS_DONE: |
| 1157 | ar = (AsyncResult) msg.obj; |
| 1158 | request = (MainThreadRequest) ar.userObj; |
| 1159 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1160 | notifyRequester(request); |
| 1161 | break; |
| 1162 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1163 | request = (MainThreadRequest) msg.obj; |
| 1164 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1165 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1166 | break; |
| 1167 | |
| 1168 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1169 | ar = (AsyncResult) msg.obj; |
| 1170 | request = (MainThreadRequest) ar.userObj; |
| 1171 | if (ar.exception != null) { |
| 1172 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1173 | } else { |
| 1174 | int mode = ((int[]) ar.result)[0]; |
| 1175 | if (mode == 0) { |
| 1176 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1177 | } else { |
| 1178 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1179 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1180 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1181 | notifyRequester(request); |
| 1182 | break; |
| 1183 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1184 | request = (MainThreadRequest) msg.obj; |
| 1185 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1186 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1187 | break; |
| 1188 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1189 | ar = (AsyncResult) msg.obj; |
| 1190 | request = (MainThreadRequest) ar.userObj; |
| 1191 | if (ar.exception != null) { |
| 1192 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1193 | } else { |
| 1194 | request.result = ((int[]) ar.result)[0]; |
| 1195 | } |
| 1196 | notifyRequester(request); |
| 1197 | break; |
| 1198 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1199 | request = (MainThreadRequest) msg.obj; |
| 1200 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1201 | int mode = (int) request.argument; |
| 1202 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1203 | break; |
| 1204 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1205 | ar = (AsyncResult) msg.obj; |
| 1206 | request = (MainThreadRequest) ar.userObj; |
| 1207 | request.result = ar.exception == null; |
| 1208 | notifyRequester(request); |
| 1209 | break; |
| 1210 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1211 | request = (MainThreadRequest) msg.obj; |
| 1212 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1213 | int subscriptionMode = (int) request.argument; |
| 1214 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1215 | break; |
| 1216 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1217 | ar = (AsyncResult) msg.obj; |
| 1218 | request = (MainThreadRequest) ar.userObj; |
| 1219 | request.result = ar.exception == null; |
| 1220 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1221 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1222 | case CMD_GET_ALL_CELL_INFO: |
| 1223 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1224 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1225 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1226 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1227 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1228 | ar = (AsyncResult) msg.obj; |
| 1229 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1230 | // If a timeout occurs, the response will be null |
| 1231 | request.result = (ar.exception == null && ar.result != null) |
| 1232 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1233 | synchronized (request) { |
| 1234 | request.notifyAll(); |
| 1235 | } |
| 1236 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1237 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1238 | request = (MainThreadRequest) msg.obj; |
| 1239 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1240 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1241 | break; |
| 1242 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1243 | ar = (AsyncResult) msg.obj; |
| 1244 | request = (MainThreadRequest) ar.userObj; |
| 1245 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1246 | try { |
| 1247 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1248 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1249 | cb.onError( |
| 1250 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1251 | ar.exception.getClass().getName(), |
| 1252 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1253 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1254 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1255 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1256 | } else { |
| 1257 | // use the result as returned |
| 1258 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1259 | } |
| 1260 | } catch (RemoteException re) { |
| 1261 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1262 | } |
| 1263 | break; |
| 1264 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1265 | request = (MainThreadRequest) msg.obj; |
| 1266 | WorkSource ws = (WorkSource) request.argument; |
| 1267 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1268 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1269 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1270 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1271 | ar = (AsyncResult) msg.obj; |
| 1272 | request = (MainThreadRequest) ar.userObj; |
| 1273 | if (ar.exception == null) { |
| 1274 | request.result = ar.result; |
| 1275 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1276 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1277 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1278 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | synchronized (request) { |
| 1282 | request.notifyAll(); |
| 1283 | } |
| 1284 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1285 | case CMD_MODEM_REBOOT: |
| 1286 | request = (MainThreadRequest) msg.obj; |
| 1287 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1288 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1289 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1290 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1291 | handleNullReturnEvent(msg, "rebootModem"); |
| 1292 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1293 | case CMD_REQUEST_ENABLE_MODEM: |
| 1294 | request = (MainThreadRequest) msg.obj; |
| 1295 | boolean enable = (boolean) request.argument; |
| 1296 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1297 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1298 | PhoneConfigurationManager.getInstance() |
| 1299 | .enablePhone(request.phone, enable, onCompleted); |
| 1300 | break; |
| 1301 | case EVENT_ENABLE_MODEM_DONE: |
| 1302 | ar = (AsyncResult) msg.obj; |
| 1303 | request = (MainThreadRequest) ar.userObj; |
| 1304 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1305 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1306 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1307 | if ((boolean) request.result) { |
| 1308 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1309 | updateModemStateMetrics(); |
| 1310 | } else { |
| 1311 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1312 | + ar.exception); |
| 1313 | } |
| 1314 | notifyRequester(request); |
| 1315 | break; |
| 1316 | case CMD_GET_MODEM_STATUS: |
| 1317 | request = (MainThreadRequest) msg.obj; |
| 1318 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1319 | PhoneConfigurationManager.getInstance() |
| 1320 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1321 | break; |
| 1322 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1323 | ar = (AsyncResult) msg.obj; |
| 1324 | request = (MainThreadRequest) ar.userObj; |
| 1325 | int id = request.phone.getPhoneId(); |
| 1326 | if (ar.exception == null && ar.result != null) { |
| 1327 | request.result = ar.result; |
| 1328 | //update the cache as modem status has changed |
| 1329 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1330 | (boolean) request.result); |
| 1331 | } else { |
| 1332 | // Return true if modem status cannot be retrieved. For most cases, |
| 1333 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1334 | // and disable modem are not supported. Modem is always on. |
| 1335 | // TODO: this should be fixed in R to support a third |
| 1336 | // status UNKNOWN b/131631629 |
| 1337 | request.result = true; |
| 1338 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1339 | + ar.exception); |
| 1340 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1341 | notifyRequester(request); |
| 1342 | break; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame^] | 1343 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1344 | request = (MainThreadRequest) msg.obj; |
| 1345 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1346 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1347 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1348 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1349 | break; |
| 1350 | } |
| 1351 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1352 | ar = (AsyncResult) msg.obj; |
| 1353 | request = (MainThreadRequest) ar.userObj; |
| 1354 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1355 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1356 | args.second.accept(ar.exception == null); |
| 1357 | notifyRequester(request); |
| 1358 | break; |
| 1359 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1360 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1361 | ar = (AsyncResult) msg.obj; |
| 1362 | request = (MainThreadRequest) ar.userObj; |
| 1363 | if (ar.exception == null && ar.result != null) { |
| 1364 | request.result = ar.result; |
| 1365 | } else { |
| 1366 | request.result = -1; |
| 1367 | loge("Failed to set Forbidden Plmns"); |
| 1368 | if (ar.result == null) { |
| 1369 | loge("setForbidenPlmns: Empty response"); |
| 1370 | } else if (ar.exception != null) { |
| 1371 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1372 | request.result = -1; |
| 1373 | } else { |
| 1374 | loge("setForbiddenPlmns: Unknown exception"); |
| 1375 | } |
| 1376 | } |
| 1377 | notifyRequester(request); |
| 1378 | break; |
| 1379 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1380 | request = (MainThreadRequest) msg.obj; |
| 1381 | uiccCard = getUiccCardFromRequest(request); |
| 1382 | if (uiccCard == null) { |
| 1383 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1384 | request.result = -1; |
| 1385 | notifyRequester(request); |
| 1386 | break; |
| 1387 | } |
| 1388 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1389 | (Pair<Integer, List<String>>) request.argument; |
| 1390 | appType = setFplmnsArgs.first; |
| 1391 | List<String> fplmns = setFplmnsArgs.second; |
| 1392 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1393 | if (uiccApp == null) { |
| 1394 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1395 | request.result = -1; |
| 1396 | loge("Failed to get UICC App"); |
| 1397 | notifyRequester(request); |
| 1398 | } else { |
| 1399 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1400 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1401 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1402 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1403 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1404 | case CMD_ERASE_MODEM_CONFIG: |
| 1405 | request = (MainThreadRequest) msg.obj; |
| 1406 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1407 | defaultPhone.eraseModemConfig(onCompleted); |
| 1408 | break; |
| 1409 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1410 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1411 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1412 | |
| 1413 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1414 | request = (MainThreadRequest) msg.obj; |
| 1415 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1416 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1417 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1418 | changed.first, changed.second, onCompleted); |
| 1419 | break; |
| 1420 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1421 | ar = (AsyncResult) msg.obj; |
| 1422 | request = (MainThreadRequest) ar.userObj; |
| 1423 | if (ar.exception == null) { |
| 1424 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1425 | } else { |
| 1426 | request.result = msg.arg1; |
| 1427 | } |
| 1428 | notifyRequester(request); |
| 1429 | break; |
| 1430 | |
| 1431 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1432 | request = (MainThreadRequest) msg.obj; |
| 1433 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1434 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1435 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1436 | enabled.first, enabled.second, onCompleted); |
| 1437 | break; |
| 1438 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1439 | ar = (AsyncResult) msg.obj; |
| 1440 | request = (MainThreadRequest) ar.userObj; |
| 1441 | if (ar.exception == null) { |
| 1442 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1443 | } else { |
| 1444 | request.result = msg.arg1; |
| 1445 | } |
| 1446 | notifyRequester(request); |
| 1447 | break; |
| 1448 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1449 | default: |
| 1450 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1451 | break; |
| 1452 | } |
| 1453 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1454 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1455 | private void notifyRequester(MainThreadRequest request) { |
| 1456 | synchronized (request) { |
| 1457 | request.notifyAll(); |
| 1458 | } |
| 1459 | } |
| 1460 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1461 | private void handleNullReturnEvent(Message msg, String command) { |
| 1462 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1463 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1464 | if (ar.exception == null) { |
| 1465 | request.result = true; |
| 1466 | } else { |
| 1467 | request.result = false; |
| 1468 | if (ar.exception instanceof CommandException) { |
| 1469 | loge(command + ": CommandException: " + ar.exception); |
| 1470 | } else { |
| 1471 | loge(command + ": Unknown exception"); |
| 1472 | } |
| 1473 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1474 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1475 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | /** |
| 1479 | * Posts the specified command to be executed on the main thread, |
| 1480 | * waits for the request to complete, and returns the result. |
| 1481 | * @see #sendRequestAsync |
| 1482 | */ |
| 1483 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1484 | return sendRequest( |
| 1485 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -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, WorkSource workSource) { |
| 1494 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1495 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -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 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1503 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1504 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | /** |
| 1508 | * Posts the specified command to be executed on the main thread, |
| 1509 | * waits for the request to complete, and returns the result. |
| 1510 | * @see #sendRequestAsync |
| 1511 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1512 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1513 | return sendRequest(command, argument, subId, null, workSource); |
| 1514 | } |
| 1515 | |
| 1516 | /** |
| 1517 | * Posts the specified command to be executed on the main thread, |
| 1518 | * waits for the request to complete, and returns the result. |
| 1519 | * @see #sendRequestAsync |
| 1520 | */ |
| 1521 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1522 | return sendRequest( |
| 1523 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, 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( |
| 1532 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1533 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1534 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1535 | } |
| 1536 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1537 | MainThreadRequest request = null; |
| 1538 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1539 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1540 | } else if (phone != null) { |
| 1541 | request = new MainThreadRequest(argument, phone, workSource); |
| 1542 | } else { |
| 1543 | request = new MainThreadRequest(argument, subId, workSource); |
| 1544 | } |
| 1545 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1546 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1547 | msg.sendToTarget(); |
| 1548 | |
| 1549 | // Wait for the request to complete |
| 1550 | synchronized (request) { |
| 1551 | while (request.result == null) { |
| 1552 | try { |
| 1553 | request.wait(); |
| 1554 | } catch (InterruptedException e) { |
| 1555 | // Do nothing, go back and wait until the request is complete |
| 1556 | } |
| 1557 | } |
| 1558 | } |
| 1559 | return request.result; |
| 1560 | } |
| 1561 | |
| 1562 | /** |
| 1563 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1564 | * Posts the specified command to be executed on the main thread, and |
| 1565 | * returns immediately. |
| 1566 | * @see #sendRequest |
| 1567 | */ |
| 1568 | private void sendRequestAsync(int command) { |
| 1569 | mMainThreadHandler.sendEmptyMessage(command); |
| 1570 | } |
| 1571 | |
| 1572 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1573 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1574 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1575 | */ |
| 1576 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1577 | sendRequestAsync(command, argument, null, null); |
| 1578 | } |
| 1579 | |
| 1580 | /** |
| 1581 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1582 | * @see {@link #sendRequest(int,Object)} |
| 1583 | */ |
| 1584 | private void sendRequestAsync( |
| 1585 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1586 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1587 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1588 | msg.sendToTarget(); |
| 1589 | } |
| 1590 | |
| 1591 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1592 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1593 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1594 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1595 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1596 | synchronized (PhoneInterfaceManager.class) { |
| 1597 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1598 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1599 | } else { |
| 1600 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1601 | } |
| 1602 | return sInstance; |
| 1603 | } |
| 1604 | } |
| 1605 | |
| 1606 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1607 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1608 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1609 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1610 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1611 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1612 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1613 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1614 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1615 | mTelephonySharedPreferences = |
| 1616 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1617 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1618 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1619 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1620 | publish(); |
| 1621 | } |
| 1622 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1623 | private Phone getDefaultPhone() { |
| 1624 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1625 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1626 | } |
| 1627 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1628 | private void publish() { |
| 1629 | if (DBG) log("publish: " + this); |
| 1630 | |
| 1631 | ServiceManager.addService("phone", this); |
| 1632 | } |
| 1633 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1634 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1635 | if (request.phone != null) { |
| 1636 | return request.phone; |
| 1637 | } else { |
| 1638 | return getPhoneFromSubId(request.subId); |
| 1639 | } |
| 1640 | } |
| 1641 | |
| 1642 | private Phone getPhoneFromSubId(int subId) { |
| 1643 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1644 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1645 | } |
| 1646 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1647 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1648 | Phone phone = getPhoneFromRequest(request); |
| 1649 | return phone == null ? null : |
| 1650 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1651 | } |
| 1652 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1653 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1654 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1655 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1656 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1657 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1658 | private void sendEraseModemConfig(Phone phone) { |
| 1659 | if (phone != null) { |
| 1660 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1661 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1662 | final long identity = Binder.clearCallingIdentity(); |
| 1663 | try { |
| 1664 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1665 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1666 | } finally { |
| 1667 | Binder.restoreCallingIdentity(identity); |
| 1668 | } |
| 1669 | } |
| 1670 | } |
| 1671 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1672 | private boolean isImsAvailableOnDevice() { |
| 1673 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1674 | if (pm == null) { |
| 1675 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1676 | // so do not throw error and allow. |
| 1677 | return true; |
| 1678 | } |
| 1679 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1680 | } |
| 1681 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1682 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1683 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1684 | } |
| 1685 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1686 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1687 | if (DBG) log("dial: " + number); |
| 1688 | // No permission check needed here: This is just a wrapper around the |
| 1689 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1690 | // the UI before it does anything. |
| 1691 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1692 | final long identity = Binder.clearCallingIdentity(); |
| 1693 | try { |
| 1694 | String url = createTelUrl(number); |
| 1695 | if (url == null) { |
| 1696 | return; |
| 1697 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1698 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1699 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1700 | PhoneConstants.State state = mCM.getState(subId); |
| 1701 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1702 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1703 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1704 | mApp.startActivity(intent); |
| 1705 | } |
| 1706 | } finally { |
| 1707 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1712 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1713 | } |
| 1714 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1715 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1716 | if (DBG) log("call: " + number); |
| 1717 | |
| 1718 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1719 | // need to do a permission check since we're calling startActivity() |
| 1720 | // from the context of the phone app. |
| 1721 | enforceCallPermission(); |
| 1722 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1723 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1724 | != AppOpsManager.MODE_ALLOWED) { |
| 1725 | return; |
| 1726 | } |
| 1727 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1728 | final long identity = Binder.clearCallingIdentity(); |
| 1729 | try { |
| 1730 | String url = createTelUrl(number); |
| 1731 | if (url == null) { |
| 1732 | return; |
| 1733 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1734 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1735 | boolean isValid = false; |
| 1736 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1737 | if (slist != null) { |
| 1738 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1739 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1740 | isValid = true; |
| 1741 | break; |
| 1742 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1743 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1744 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1745 | if (!isValid) { |
| 1746 | return; |
| 1747 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1748 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1749 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1750 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1751 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1752 | mApp.startActivity(intent); |
| 1753 | } finally { |
| 1754 | Binder.restoreCallingIdentity(identity); |
| 1755 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1758 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1759 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1760 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1761 | } |
| 1762 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1763 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1764 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1765 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1766 | } |
| 1767 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1768 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1769 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1770 | |
| 1771 | final long identity = Binder.clearCallingIdentity(); |
| 1772 | try { |
| 1773 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1774 | checkSimPin.start(); |
| 1775 | return checkSimPin.unlockSim(null, pin); |
| 1776 | } finally { |
| 1777 | Binder.restoreCallingIdentity(identity); |
| 1778 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1781 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1782 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1783 | |
| 1784 | final long identity = Binder.clearCallingIdentity(); |
| 1785 | try { |
| 1786 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1787 | checkSimPuk.start(); |
| 1788 | return checkSimPuk.unlockSim(puk, pin); |
| 1789 | } finally { |
| 1790 | Binder.restoreCallingIdentity(identity); |
| 1791 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1795 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1796 | * a synchronous one. |
| 1797 | */ |
| 1798 | private static class UnlockSim extends Thread { |
| 1799 | |
| 1800 | private final IccCard mSimCard; |
| 1801 | |
| 1802 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1803 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1804 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1805 | |
| 1806 | // For replies from SimCard interface |
| 1807 | private Handler mHandler; |
| 1808 | |
| 1809 | // For async handler to identify request type |
| 1810 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1811 | |
| 1812 | public UnlockSim(IccCard simCard) { |
| 1813 | mSimCard = simCard; |
| 1814 | } |
| 1815 | |
| 1816 | @Override |
| 1817 | public void run() { |
| 1818 | Looper.prepare(); |
| 1819 | synchronized (UnlockSim.this) { |
| 1820 | mHandler = new Handler() { |
| 1821 | @Override |
| 1822 | public void handleMessage(Message msg) { |
| 1823 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1824 | switch (msg.what) { |
| 1825 | case SUPPLY_PIN_COMPLETE: |
| 1826 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1827 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1828 | mRetryCount = msg.arg1; |
| 1829 | if (ar.exception != null) { |
| 1830 | if (ar.exception instanceof CommandException && |
| 1831 | ((CommandException)(ar.exception)).getCommandError() |
| 1832 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1833 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1834 | } else { |
| 1835 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1836 | } |
| 1837 | } else { |
| 1838 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1839 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1840 | mDone = true; |
| 1841 | UnlockSim.this.notifyAll(); |
| 1842 | } |
| 1843 | break; |
| 1844 | } |
| 1845 | } |
| 1846 | }; |
| 1847 | UnlockSim.this.notifyAll(); |
| 1848 | } |
| 1849 | Looper.loop(); |
| 1850 | } |
| 1851 | |
| 1852 | /* |
| 1853 | * Use PIN or PUK to unlock SIM card |
| 1854 | * |
| 1855 | * If PUK is null, unlock SIM card with PIN |
| 1856 | * |
| 1857 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1858 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1859 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1860 | |
| 1861 | while (mHandler == null) { |
| 1862 | try { |
| 1863 | wait(); |
| 1864 | } catch (InterruptedException e) { |
| 1865 | Thread.currentThread().interrupt(); |
| 1866 | } |
| 1867 | } |
| 1868 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1869 | |
| 1870 | if (puk == null) { |
| 1871 | mSimCard.supplyPin(pin, callback); |
| 1872 | } else { |
| 1873 | mSimCard.supplyPuk(puk, pin, callback); |
| 1874 | } |
| 1875 | |
| 1876 | while (!mDone) { |
| 1877 | try { |
| 1878 | Log.d(LOG_TAG, "wait for done"); |
| 1879 | wait(); |
| 1880 | } catch (InterruptedException e) { |
| 1881 | // Restore the interrupted status |
| 1882 | Thread.currentThread().interrupt(); |
| 1883 | } |
| 1884 | } |
| 1885 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1886 | int[] resultArray = new int[2]; |
| 1887 | resultArray[0] = mResult; |
| 1888 | resultArray[1] = mRetryCount; |
| 1889 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1894 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1895 | |
| 1896 | } |
| 1897 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1898 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1899 | // No permission check needed here: this call is harmless, and it's |
| 1900 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1901 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1902 | final long identity = Binder.clearCallingIdentity(); |
| 1903 | try { |
| 1904 | final Phone phone = getPhone(subId); |
| 1905 | if (phone != null) { |
| 1906 | phone.updateServiceLocation(); |
| 1907 | } |
| 1908 | } finally { |
| 1909 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1910 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1911 | } |
| 1912 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1913 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1914 | @Override |
| 1915 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1916 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1917 | } |
| 1918 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1919 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1920 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1921 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1922 | callingFeatureId); |
| 1923 | } |
| 1924 | |
| 1925 | @Deprecated |
| 1926 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1927 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1928 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 1929 | } |
| 1930 | |
| 1931 | @Override |
| 1932 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1933 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1934 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1935 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1936 | return false; |
| 1937 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1938 | |
| 1939 | final long identity = Binder.clearCallingIdentity(); |
| 1940 | try { |
| 1941 | return isRadioOnForSubscriber(subId); |
| 1942 | } finally { |
| 1943 | Binder.restoreCallingIdentity(identity); |
| 1944 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1945 | } |
| 1946 | |
| 1947 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1948 | final long identity = Binder.clearCallingIdentity(); |
| 1949 | try { |
| 1950 | final Phone phone = getPhone(subId); |
| 1951 | if (phone != null) { |
| 1952 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1953 | } else { |
| 1954 | return false; |
| 1955 | } |
| 1956 | } finally { |
| 1957 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1958 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1962 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1963 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1964 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1965 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1966 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1967 | |
| 1968 | final long identity = Binder.clearCallingIdentity(); |
| 1969 | try { |
| 1970 | final Phone phone = getPhone(subId); |
| 1971 | if (phone != null) { |
| 1972 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1973 | } |
| 1974 | } finally { |
| 1975 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1976 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1980 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1981 | } |
| 1982 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1983 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1984 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1985 | |
| 1986 | final long identity = Binder.clearCallingIdentity(); |
| 1987 | try { |
| 1988 | final Phone phone = getPhone(subId); |
| 1989 | if (phone == null) { |
| 1990 | return false; |
| 1991 | } |
| 1992 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1993 | toggleRadioOnOffForSubscriber(subId); |
| 1994 | } |
| 1995 | return true; |
| 1996 | } finally { |
| 1997 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1998 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1999 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2000 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2001 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2002 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2003 | /* |
| 2004 | * If any of the Radios are available, it will need to be |
| 2005 | * shutdown. So return true if any Radio is available. |
| 2006 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2007 | final long identity = Binder.clearCallingIdentity(); |
| 2008 | try { |
| 2009 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2010 | Phone phone = PhoneFactory.getPhone(i); |
| 2011 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2012 | } |
| 2013 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2014 | return false; |
| 2015 | } finally { |
| 2016 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2017 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2020 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2021 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2022 | enforceModifyPermission(); |
| 2023 | |
| 2024 | final long identity = Binder.clearCallingIdentity(); |
| 2025 | try { |
| 2026 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2027 | logv("Shutting down Phone " + i); |
| 2028 | shutdownRadioUsingPhoneId(i); |
| 2029 | } |
| 2030 | } finally { |
| 2031 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2032 | } |
| 2033 | } |
| 2034 | |
| 2035 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2036 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2037 | if (phone != null && phone.isRadioAvailable()) { |
| 2038 | phone.shutdownRadio(); |
| 2039 | } |
| 2040 | } |
| 2041 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2042 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2043 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2044 | |
| 2045 | final long identity = Binder.clearCallingIdentity(); |
| 2046 | try { |
| 2047 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2048 | if (defaultPhone != null) { |
| 2049 | defaultPhone.setRadioPower(turnOn); |
| 2050 | return true; |
| 2051 | } else { |
| 2052 | loge("There's no default phone."); |
| 2053 | return false; |
| 2054 | } |
| 2055 | } finally { |
| 2056 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2057 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2058 | } |
| 2059 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2060 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2061 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2062 | |
| 2063 | final long identity = Binder.clearCallingIdentity(); |
| 2064 | try { |
| 2065 | final Phone phone = getPhone(subId); |
| 2066 | if (phone != null) { |
| 2067 | phone.setRadioPower(turnOn); |
| 2068 | return true; |
| 2069 | } else { |
| 2070 | return false; |
| 2071 | } |
| 2072 | } finally { |
| 2073 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2074 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2075 | } |
| 2076 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2077 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2078 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2079 | public boolean enableDataConnectivity() { |
| 2080 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2081 | |
| 2082 | final long identity = Binder.clearCallingIdentity(); |
| 2083 | try { |
| 2084 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2085 | final Phone phone = getPhone(subId); |
| 2086 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2087 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2088 | return true; |
| 2089 | } else { |
| 2090 | return false; |
| 2091 | } |
| 2092 | } finally { |
| 2093 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2094 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2095 | } |
| 2096 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2097 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2098 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2099 | public boolean disableDataConnectivity() { |
| 2100 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2101 | |
| 2102 | final long identity = Binder.clearCallingIdentity(); |
| 2103 | try { |
| 2104 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2105 | final Phone phone = getPhone(subId); |
| 2106 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2107 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2108 | return true; |
| 2109 | } else { |
| 2110 | return false; |
| 2111 | } |
| 2112 | } finally { |
| 2113 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2114 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2115 | } |
| 2116 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2117 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2118 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2119 | final long identity = Binder.clearCallingIdentity(); |
| 2120 | try { |
| 2121 | final Phone phone = getPhone(subId); |
| 2122 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2123 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2124 | } else { |
| 2125 | return false; |
| 2126 | } |
| 2127 | } finally { |
| 2128 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2129 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2133 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2134 | } |
| 2135 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2136 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2137 | enforceCallPermission(); |
| 2138 | |
| 2139 | final long identity = Binder.clearCallingIdentity(); |
| 2140 | try { |
| 2141 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2142 | return; |
| 2143 | } |
| 2144 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2145 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2146 | } finally { |
| 2147 | Binder.restoreCallingIdentity(identity); |
| 2148 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2149 | }; |
| 2150 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2151 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2152 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2153 | |
| 2154 | final long identity = Binder.clearCallingIdentity(); |
| 2155 | try { |
| 2156 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2157 | return false; |
| 2158 | } |
| 2159 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2160 | } finally { |
| 2161 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2162 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2163 | } |
| 2164 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2165 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2166 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2167 | } |
| 2168 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2169 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2170 | final long identity = Binder.clearCallingIdentity(); |
| 2171 | try { |
| 2172 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2173 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2174 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2175 | } finally { |
| 2176 | Binder.restoreCallingIdentity(identity); |
| 2177 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2178 | } |
| 2179 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2180 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2181 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2182 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2183 | } |
| 2184 | |
| 2185 | @Override |
| 2186 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2187 | final long identity = Binder.clearCallingIdentity(); |
| 2188 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2189 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2190 | if (phone != null) { |
| 2191 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2192 | } else { |
| 2193 | return PhoneConstantConversions.convertDataState( |
| 2194 | PhoneConstants.DataState.DISCONNECTED); |
| 2195 | } |
| 2196 | } finally { |
| 2197 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2198 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2199 | } |
| 2200 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2201 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2202 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2203 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2204 | } |
| 2205 | |
| 2206 | @Override |
| 2207 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2208 | final long identity = Binder.clearCallingIdentity(); |
| 2209 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2210 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2211 | if (phone != null) { |
| 2212 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2213 | } else { |
| 2214 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2215 | } |
| 2216 | } finally { |
| 2217 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2218 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2222 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2223 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2224 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2225 | |
| 2226 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2227 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2228 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2229 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2230 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2231 | .setCallingPid(Binder.getCallingPid()) |
| 2232 | .setCallingUid(Binder.getCallingUid()) |
| 2233 | .setMethod("getCellLocation") |
| 2234 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2235 | .build()); |
| 2236 | switch (locationResult) { |
| 2237 | case DENIED_HARD: |
| 2238 | throw new SecurityException("Not allowed to access cell location"); |
| 2239 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2240 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2241 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2242 | } |
| 2243 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2244 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2245 | final long identity = Binder.clearCallingIdentity(); |
| 2246 | try { |
| 2247 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2248 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2249 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2250 | } finally { |
| 2251 | Binder.restoreCallingIdentity(identity); |
| 2252 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2255 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2256 | public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage, |
| 2257 | String callingFeatureId) { |
Jack Yu | 7c5d91a | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2258 | if (!TextUtils.isEmpty(callingPackage)) { |
| 2259 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2260 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2261 | callingFeatureId, "getNetworkCountryIsoForPhone")) { |
Jack Yu | 7c5d91a | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2262 | return ""; |
| 2263 | } |
| 2264 | } |
| 2265 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2266 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2267 | // registered cell info, so return a NULL country instead. |
| 2268 | final long identity = Binder.clearCallingIdentity(); |
| 2269 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2270 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2271 | // Get default phone in this case. |
| 2272 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2273 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2274 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2275 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2276 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2277 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2278 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(), |
| 2279 | null)) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2280 | return ""; |
| 2281 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2282 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2283 | if (phone != null) { |
| 2284 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2285 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2286 | if (sst != null) { |
| 2287 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2288 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2289 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2290 | return lt.getCurrentCountry(); |
| 2291 | } else if (emergencyNumberTracker != null) { |
| 2292 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2293 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2294 | } |
| 2295 | } |
| 2296 | } |
| 2297 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2298 | } finally { |
| 2299 | Binder.restoreCallingIdentity(identity); |
| 2300 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2304 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2305 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2306 | } |
| 2307 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2308 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2309 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2310 | mApp.enforceCallingOrSelfPermission( |
| 2311 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2312 | |
| 2313 | final long identity = Binder.clearCallingIdentity(); |
| 2314 | try { |
| 2315 | final Phone phone = getPhone(subId); |
| 2316 | if (phone != null) { |
| 2317 | phone.enableLocationUpdates(); |
| 2318 | } |
| 2319 | } finally { |
| 2320 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2321 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2322 | } |
| 2323 | |
| 2324 | @Override |
| 2325 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2326 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2327 | } |
| 2328 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2329 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2330 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2331 | mApp.enforceCallingOrSelfPermission( |
| 2332 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2333 | |
| 2334 | final long identity = Binder.clearCallingIdentity(); |
| 2335 | try { |
| 2336 | final Phone phone = getPhone(subId); |
| 2337 | if (phone != null) { |
| 2338 | phone.disableLocationUpdates(); |
| 2339 | } |
| 2340 | } finally { |
| 2341 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2342 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2343 | } |
| 2344 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2345 | /** |
| 2346 | * Returns the target SDK version number for a given package name. |
| 2347 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2348 | * This call MUST be invoked before clearing the calling UID. |
| 2349 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2350 | * @return target SDK if the package is found or INT_MAX. |
| 2351 | */ |
| 2352 | private int getTargetSdk(String packageName) { |
| 2353 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2354 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2355 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2356 | if (ai != null) return ai.targetSdkVersion; |
| 2357 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2358 | loge("Failed to get package info for pkg=" |
| 2359 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2360 | } |
| 2361 | return Integer.MAX_VALUE; |
| 2362 | } |
| 2363 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2364 | @Override |
| 2365 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2366 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2367 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2368 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2369 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2370 | throw new SecurityException( |
| 2371 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2372 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2373 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2374 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2375 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2376 | return null; |
| 2377 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2378 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2379 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2380 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2381 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2382 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2383 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2384 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2385 | for (CellInfo ci : info) { |
| 2386 | if (ci instanceof CellInfoGsm) { |
| 2387 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2388 | } else if (ci instanceof CellInfoWcdma) { |
| 2389 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2390 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2391 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2392 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2393 | } |
| 2394 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2395 | private List<CellInfo> getCachedCellInfo() { |
| 2396 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2397 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2398 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2399 | if (info != null) cellInfos.addAll(info); |
| 2400 | } |
| 2401 | return cellInfos; |
| 2402 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2403 | |
| 2404 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2405 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2406 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2407 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2408 | |
| 2409 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2410 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2411 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2412 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2413 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2414 | .setCallingPid(Binder.getCallingPid()) |
| 2415 | .setCallingUid(Binder.getCallingUid()) |
| 2416 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2417 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2418 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2419 | .build()); |
| 2420 | switch (locationResult) { |
| 2421 | case DENIED_HARD: |
| 2422 | throw new SecurityException("Not allowed to access cell info"); |
| 2423 | case DENIED_SOFT: |
| 2424 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2425 | } |
| 2426 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2427 | final int targetSdk = getTargetSdk(callingPackage); |
| 2428 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2429 | return getCachedCellInfo(); |
| 2430 | } |
| 2431 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2432 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2433 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2434 | final long identity = Binder.clearCallingIdentity(); |
| 2435 | try { |
| 2436 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2437 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2438 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2439 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2440 | if (info != null) cellInfos.addAll(info); |
| 2441 | } |
| 2442 | return cellInfos; |
| 2443 | } finally { |
| 2444 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2445 | } |
| 2446 | } |
| 2447 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2448 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2449 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2450 | String callingFeatureId) { |
| 2451 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2452 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2453 | } |
| 2454 | |
| 2455 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2456 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2457 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2458 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2459 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2462 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2463 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2464 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2465 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2466 | |
| 2467 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2468 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2469 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2470 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2471 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2472 | .setCallingPid(Binder.getCallingPid()) |
| 2473 | .setCallingUid(Binder.getCallingUid()) |
| 2474 | .setMethod("requestCellInfoUpdate") |
| 2475 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2476 | .build()); |
| 2477 | switch (locationResult) { |
| 2478 | case DENIED_HARD: |
| 2479 | throw new SecurityException("Not allowed to access cell info"); |
| 2480 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2481 | try { |
| 2482 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2483 | } catch (RemoteException re) { |
| 2484 | // Drop without consequences |
| 2485 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2486 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2487 | } |
| 2488 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2489 | |
| 2490 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2491 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2492 | |
| 2493 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2494 | } |
| 2495 | |
| 2496 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2497 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2498 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2499 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2500 | |
| 2501 | final long identity = Binder.clearCallingIdentity(); |
| 2502 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2503 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2504 | } finally { |
| 2505 | Binder.restoreCallingIdentity(identity); |
| 2506 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2507 | } |
| 2508 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2509 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2510 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2511 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2512 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2513 | return null; |
| 2514 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2515 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2516 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2517 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2518 | return null; |
| 2519 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2520 | |
| 2521 | final long identity = Binder.clearCallingIdentity(); |
| 2522 | try { |
| 2523 | return phone.getImei(); |
| 2524 | } finally { |
| 2525 | Binder.restoreCallingIdentity(identity); |
| 2526 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2527 | } |
| 2528 | |
| 2529 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2530 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2531 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2532 | String tac = null; |
| 2533 | if (phone != null) { |
| 2534 | String imei = phone.getImei(); |
| 2535 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2536 | } |
| 2537 | return tac; |
| 2538 | } |
| 2539 | |
| 2540 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2541 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2542 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2543 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2544 | return null; |
| 2545 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2546 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2547 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2548 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2549 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2550 | return null; |
| 2551 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2552 | |
| 2553 | final long identity = Binder.clearCallingIdentity(); |
| 2554 | try { |
| 2555 | return phone.getMeid(); |
| 2556 | } finally { |
| 2557 | Binder.restoreCallingIdentity(identity); |
| 2558 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2562 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2563 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2564 | String manufacturerCode = null; |
| 2565 | if (phone != null) { |
| 2566 | String meid = phone.getMeid(); |
| 2567 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2568 | } |
| 2569 | return manufacturerCode; |
| 2570 | } |
| 2571 | |
| 2572 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2573 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2574 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2575 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2576 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2577 | return null; |
| 2578 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2579 | int subId = phone.getSubId(); |
| 2580 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2581 | mApp, subId, callingPackage, callingFeatureId, |
| 2582 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2583 | return null; |
| 2584 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2585 | |
| 2586 | final long identity = Binder.clearCallingIdentity(); |
| 2587 | try { |
| 2588 | return phone.getDeviceSvn(); |
| 2589 | } finally { |
| 2590 | Binder.restoreCallingIdentity(identity); |
| 2591 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2592 | } |
| 2593 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2594 | @Override |
| 2595 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2596 | final long identity = Binder.clearCallingIdentity(); |
| 2597 | try { |
| 2598 | final Phone phone = getPhone(subId); |
| 2599 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2600 | } finally { |
| 2601 | Binder.restoreCallingIdentity(identity); |
| 2602 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2603 | } |
| 2604 | |
| 2605 | @Override |
| 2606 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2607 | final long identity = Binder.clearCallingIdentity(); |
| 2608 | try { |
| 2609 | final Phone phone = getPhone(subId); |
| 2610 | return phone == null ? null : phone.getCarrierName(); |
| 2611 | } finally { |
| 2612 | Binder.restoreCallingIdentity(identity); |
| 2613 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2614 | } |
| 2615 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2616 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2617 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2618 | final long identity = Binder.clearCallingIdentity(); |
| 2619 | try { |
| 2620 | final Phone phone = getPhone(subId); |
| 2621 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2622 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2623 | } finally { |
| 2624 | Binder.restoreCallingIdentity(identity); |
| 2625 | } |
| 2626 | } |
| 2627 | |
| 2628 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2629 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2630 | final long identity = Binder.clearCallingIdentity(); |
| 2631 | try { |
| 2632 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2633 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2634 | } finally { |
| 2635 | Binder.restoreCallingIdentity(identity); |
| 2636 | } |
| 2637 | } |
| 2638 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2639 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2640 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2641 | if (!isSubscriptionMccMnc) { |
| 2642 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2643 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2644 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2645 | if (phone == null) { |
| 2646 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2647 | } |
| 2648 | final long identity = Binder.clearCallingIdentity(); |
| 2649 | try { |
| 2650 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2651 | } finally { |
| 2652 | Binder.restoreCallingIdentity(identity); |
| 2653 | } |
| 2654 | } |
| 2655 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2656 | // |
| 2657 | // Internal helper methods. |
| 2658 | // |
| 2659 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2660 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2661 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2662 | * |
| 2663 | * @throws SecurityException if the caller does not have the required permission |
| 2664 | */ |
| 2665 | private void enforceModifyPermission() { |
| 2666 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2667 | } |
| 2668 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2669 | /** |
| 2670 | * Make sure the caller is system. |
| 2671 | * |
| 2672 | * @throws SecurityException if the caller is not system. |
| 2673 | */ |
| 2674 | private void enforceSystemCaller() { |
| 2675 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2676 | throw new SecurityException("Caller must be system"); |
| 2677 | } |
| 2678 | } |
| 2679 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2680 | private void enforceActiveEmergencySessionPermission() { |
| 2681 | mApp.enforceCallingOrSelfPermission( |
| 2682 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2683 | } |
| 2684 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2685 | /** |
| 2686 | * Make sure the caller has the CALL_PHONE permission. |
| 2687 | * |
| 2688 | * @throws SecurityException if the caller does not have the required permission |
| 2689 | */ |
| 2690 | private void enforceCallPermission() { |
| 2691 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2692 | } |
| 2693 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2694 | private void enforceSettingsPermission() { |
| 2695 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2696 | } |
| 2697 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2698 | private String createTelUrl(String number) { |
| 2699 | if (TextUtils.isEmpty(number)) { |
| 2700 | return null; |
| 2701 | } |
| 2702 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2703 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2704 | } |
| 2705 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2706 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2707 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2708 | } |
| 2709 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2710 | private static void logv(String msg) { |
| 2711 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2712 | } |
| 2713 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2714 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2715 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2716 | } |
| 2717 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2718 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2719 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2720 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2721 | } |
| 2722 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2723 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2724 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2725 | final long identity = Binder.clearCallingIdentity(); |
| 2726 | try { |
| 2727 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2728 | if (phone == null) { |
| 2729 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2730 | } else { |
| 2731 | return phone.getPhoneType(); |
| 2732 | } |
| 2733 | } finally { |
| 2734 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2735 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | /** |
| 2739 | * Returns the CDMA ERI icon index to display |
| 2740 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2741 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2742 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2743 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2744 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2745 | } |
| 2746 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2747 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2748 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2749 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2750 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2751 | mApp, subId, callingPackage, callingFeatureId, |
| 2752 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2753 | return -1; |
| 2754 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2755 | |
| 2756 | final long identity = Binder.clearCallingIdentity(); |
| 2757 | try { |
| 2758 | final Phone phone = getPhone(subId); |
| 2759 | if (phone != null) { |
| 2760 | return phone.getCdmaEriIconIndex(); |
| 2761 | } else { |
| 2762 | return -1; |
| 2763 | } |
| 2764 | } finally { |
| 2765 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2766 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | /** |
| 2770 | * Returns the CDMA ERI icon mode, |
| 2771 | * 0 - ON |
| 2772 | * 1 - FLASHING |
| 2773 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2774 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2775 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2776 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2777 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2778 | } |
| 2779 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2780 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2781 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2782 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2783 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2784 | mApp, subId, callingPackage, callingFeatureId, |
| 2785 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2786 | return -1; |
| 2787 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2788 | |
| 2789 | final long identity = Binder.clearCallingIdentity(); |
| 2790 | try { |
| 2791 | final Phone phone = getPhone(subId); |
| 2792 | if (phone != null) { |
| 2793 | return phone.getCdmaEriIconMode(); |
| 2794 | } else { |
| 2795 | return -1; |
| 2796 | } |
| 2797 | } finally { |
| 2798 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2799 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2800 | } |
| 2801 | |
| 2802 | /** |
| 2803 | * Returns the CDMA ERI text, |
| 2804 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2805 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2806 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2807 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2808 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2809 | } |
| 2810 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2811 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2812 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2813 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2814 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2815 | mApp, subId, callingPackage, callingFeatureId, |
| 2816 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2817 | return null; |
| 2818 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2819 | |
| 2820 | final long identity = Binder.clearCallingIdentity(); |
| 2821 | try { |
| 2822 | final Phone phone = getPhone(subId); |
| 2823 | if (phone != null) { |
| 2824 | return phone.getCdmaEriText(); |
| 2825 | } else { |
| 2826 | return null; |
| 2827 | } |
| 2828 | } finally { |
| 2829 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2830 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2831 | } |
| 2832 | |
| 2833 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2834 | * Returns the CDMA MDN. |
| 2835 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2836 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2837 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2838 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2839 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2840 | |
| 2841 | final long identity = Binder.clearCallingIdentity(); |
| 2842 | try { |
| 2843 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2844 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2845 | return phone.getLine1Number(); |
| 2846 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2847 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2848 | return null; |
| 2849 | } |
| 2850 | } finally { |
| 2851 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2852 | } |
| 2853 | } |
| 2854 | |
| 2855 | /** |
| 2856 | * Returns the CDMA MIN. |
| 2857 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2858 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2859 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2860 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2861 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2862 | |
| 2863 | final long identity = Binder.clearCallingIdentity(); |
| 2864 | try { |
| 2865 | final Phone phone = getPhone(subId); |
| 2866 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2867 | return phone.getCdmaMin(); |
| 2868 | } else { |
| 2869 | return null; |
| 2870 | } |
| 2871 | } finally { |
| 2872 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2873 | } |
| 2874 | } |
| 2875 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2876 | @Override |
| 2877 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2878 | INumberVerificationCallback callback, String callingPackage) { |
| 2879 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2880 | != PERMISSION_GRANTED) { |
| 2881 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2882 | } |
| 2883 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2884 | |
| 2885 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2886 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2887 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2888 | } |
| 2889 | |
| 2890 | if (range == null) { |
| 2891 | throw new NullPointerException("Range must be non-null"); |
| 2892 | } |
| 2893 | |
| 2894 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2895 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2896 | |
| 2897 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2898 | } |
| 2899 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2900 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2901 | * Returns true if CDMA provisioning needs to run. |
| 2902 | */ |
| 2903 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2904 | final long identity = Binder.clearCallingIdentity(); |
| 2905 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2906 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2907 | } finally { |
| 2908 | Binder.restoreCallingIdentity(identity); |
| 2909 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2913 | * Sets the voice mail number of a given subId. |
| 2914 | */ |
| 2915 | @Override |
| 2916 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2917 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2918 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2919 | |
| 2920 | final long identity = Binder.clearCallingIdentity(); |
| 2921 | try { |
| 2922 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2923 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2924 | return success; |
| 2925 | } finally { |
| 2926 | Binder.restoreCallingIdentity(identity); |
| 2927 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2928 | } |
| 2929 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2930 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2931 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2932 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2933 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2934 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2935 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2936 | throw new SecurityException("caller must be system dialer"); |
| 2937 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2938 | |
| 2939 | final long identity = Binder.clearCallingIdentity(); |
| 2940 | try { |
| 2941 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2942 | if (phoneAccountHandle == null) { |
| 2943 | return null; |
| 2944 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2945 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2946 | } finally { |
| 2947 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2948 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2949 | } |
| 2950 | |
| 2951 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2952 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2953 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2954 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2955 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2956 | mApp, subId, callingPackage, callingFeatureId, |
| 2957 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2958 | return null; |
| 2959 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2960 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2961 | final long identity = Binder.clearCallingIdentity(); |
| 2962 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2963 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2964 | } finally { |
| 2965 | Binder.restoreCallingIdentity(identity); |
| 2966 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2970 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2971 | VisualVoicemailSmsFilterSettings settings) { |
| 2972 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2973 | |
| 2974 | final long identity = Binder.clearCallingIdentity(); |
| 2975 | try { |
| 2976 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2977 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2978 | } finally { |
| 2979 | Binder.restoreCallingIdentity(identity); |
| 2980 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2981 | } |
| 2982 | |
| 2983 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2984 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2985 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2986 | |
| 2987 | final long identity = Binder.clearCallingIdentity(); |
| 2988 | try { |
| 2989 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2990 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2991 | } finally { |
| 2992 | Binder.restoreCallingIdentity(identity); |
| 2993 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2994 | } |
| 2995 | |
| 2996 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2997 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2998 | String callingPackage, int subId) { |
| 2999 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3000 | |
| 3001 | final long identity = Binder.clearCallingIdentity(); |
| 3002 | try { |
| 3003 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3004 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3005 | } finally { |
| 3006 | Binder.restoreCallingIdentity(identity); |
| 3007 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3008 | } |
| 3009 | |
| 3010 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3011 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3012 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3013 | |
| 3014 | final long identity = Binder.clearCallingIdentity(); |
| 3015 | try { |
| 3016 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3017 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3018 | } finally { |
| 3019 | Binder.restoreCallingIdentity(identity); |
| 3020 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3021 | } |
| 3022 | |
| 3023 | @Override |
| 3024 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 3025 | String number, int port, String text, PendingIntent sentIntent) { |
| 3026 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3027 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3028 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3029 | SmsController smsController = PhoneFactory.getSmsController(); |
| 3030 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 3031 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3032 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3033 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3034 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3035 | * Sets the voice activation state of a given subId. |
| 3036 | */ |
| 3037 | @Override |
| 3038 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3039 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3040 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3041 | |
| 3042 | final long identity = Binder.clearCallingIdentity(); |
| 3043 | try { |
| 3044 | final Phone phone = getPhone(subId); |
| 3045 | if (phone != null) { |
| 3046 | phone.setVoiceActivationState(activationState); |
| 3047 | } else { |
| 3048 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3049 | } |
| 3050 | } finally { |
| 3051 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3052 | } |
| 3053 | } |
| 3054 | |
| 3055 | /** |
| 3056 | * Sets the data activation state of a given subId. |
| 3057 | */ |
| 3058 | @Override |
| 3059 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3060 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3061 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3062 | |
| 3063 | final long identity = Binder.clearCallingIdentity(); |
| 3064 | try { |
| 3065 | final Phone phone = getPhone(subId); |
| 3066 | if (phone != null) { |
| 3067 | phone.setDataActivationState(activationState); |
| 3068 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3069 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3070 | } |
| 3071 | } finally { |
| 3072 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3073 | } |
| 3074 | } |
| 3075 | |
| 3076 | /** |
| 3077 | * Returns the voice activation state of a given subId. |
| 3078 | */ |
| 3079 | @Override |
| 3080 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3081 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3082 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3083 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3084 | final long identity = Binder.clearCallingIdentity(); |
| 3085 | try { |
| 3086 | if (phone != null) { |
| 3087 | return phone.getVoiceActivationState(); |
| 3088 | } else { |
| 3089 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3090 | } |
| 3091 | } finally { |
| 3092 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3093 | } |
| 3094 | } |
| 3095 | |
| 3096 | /** |
| 3097 | * Returns the data activation state of a given subId. |
| 3098 | */ |
| 3099 | @Override |
| 3100 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3101 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3102 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3103 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3104 | final long identity = Binder.clearCallingIdentity(); |
| 3105 | try { |
| 3106 | if (phone != null) { |
| 3107 | return phone.getDataActivationState(); |
| 3108 | } else { |
| 3109 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3110 | } |
| 3111 | } finally { |
| 3112 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3113 | } |
| 3114 | } |
| 3115 | |
| 3116 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3117 | * Returns the unread count of voicemails for a subId |
| 3118 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3119 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3120 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3121 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3122 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3123 | mApp, subId, callingPackage, callingFeatureId, |
| 3124 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3125 | return 0; |
| 3126 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3127 | final long identity = Binder.clearCallingIdentity(); |
| 3128 | try { |
| 3129 | final Phone phone = getPhone(subId); |
| 3130 | if (phone != null) { |
| 3131 | return phone.getVoiceMessageCount(); |
| 3132 | } else { |
| 3133 | return 0; |
| 3134 | } |
| 3135 | } finally { |
| 3136 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3137 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3138 | } |
| 3139 | |
| 3140 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3141 | * returns true, if the device is in a state where both voice and data |
| 3142 | * are supported simultaneously. This can change based on location or network condition. |
| 3143 | */ |
| 3144 | @Override |
| 3145 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3146 | final long identity = Binder.clearCallingIdentity(); |
| 3147 | try { |
| 3148 | final Phone phone = getPhone(subId); |
| 3149 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3150 | } finally { |
| 3151 | Binder.restoreCallingIdentity(identity); |
| 3152 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3153 | } |
| 3154 | |
| 3155 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3156 | * Send the dialer code if called from the current default dialer or the caller has |
| 3157 | * carrier privilege. |
| 3158 | * @param inputCode The dialer code to send |
| 3159 | */ |
| 3160 | @Override |
| 3161 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3162 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3163 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3164 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3165 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3166 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3167 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3168 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3169 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3170 | |
| 3171 | final long identity = Binder.clearCallingIdentity(); |
| 3172 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3173 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3174 | } finally { |
| 3175 | Binder.restoreCallingIdentity(identity); |
| 3176 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3177 | } |
| 3178 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3179 | @Override |
| 3180 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3181 | TelephonyPermissions |
| 3182 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3183 | mApp, subId, "getNetworkSelectionMode"); |
| 3184 | final long identity = Binder.clearCallingIdentity(); |
| 3185 | try { |
| 3186 | if (!isActiveSubscription(subId)) { |
| 3187 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3188 | } |
| 3189 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3190 | } finally { |
| 3191 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3192 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3193 | } |
| 3194 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3195 | @Override |
Sarah Chin | 5f0ecd7 | 2019-12-06 10:24:18 -0800 | [diff] [blame] | 3196 | public PhoneCapability getPhoneCapability(int subId, String callingPackage, |
| 3197 | String callingFeatureId) { |
| 3198 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3199 | mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) { |
| 3200 | return null; |
| 3201 | } |
| 3202 | final long identity = Binder.clearCallingIdentity(); |
| 3203 | try { |
| 3204 | return mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 3205 | } finally { |
| 3206 | Binder.restoreCallingIdentity(identity); |
| 3207 | } |
| 3208 | } |
| 3209 | |
| 3210 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3211 | public boolean isInEmergencySmsMode() { |
| 3212 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3213 | final long identity = Binder.clearCallingIdentity(); |
| 3214 | try { |
| 3215 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3216 | if (phone.isInEmergencySmsMode()) { |
| 3217 | return true; |
| 3218 | } |
| 3219 | } |
| 3220 | } finally { |
| 3221 | Binder.restoreCallingIdentity(identity); |
| 3222 | } |
| 3223 | return false; |
| 3224 | } |
| 3225 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3226 | /** |
| 3227 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3228 | * @param subId The subscription to use to check the configuration. |
| 3229 | * @param c The callback that will be used to send the result. |
| 3230 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3231 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3232 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3233 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3234 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3235 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3236 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3237 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3238 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3239 | "IMS not available on device."); |
| 3240 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3241 | final long token = Binder.clearCallingIdentity(); |
| 3242 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3243 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3244 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3245 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3246 | } catch (ImsException e) { |
| 3247 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3248 | } finally { |
| 3249 | Binder.restoreCallingIdentity(token); |
| 3250 | } |
| 3251 | } |
| 3252 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3253 | /** |
| 3254 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3255 | * @param subId The subscription to use to check the configuration. |
| 3256 | * @param c The callback that will be used to send the result. |
| 3257 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3258 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3259 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3260 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3261 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3262 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3263 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3264 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3265 | final long token = Binder.clearCallingIdentity(); |
| 3266 | try { |
| 3267 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3268 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3269 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3270 | } catch (ImsException e) { |
| 3271 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3272 | + "is inactive, ignoring unregister."); |
| 3273 | // If the subscription is no longer active, just return, since the callback |
| 3274 | // will already have been removed internally. |
| 3275 | } finally { |
| 3276 | Binder.restoreCallingIdentity(token); |
| 3277 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3278 | } |
| 3279 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3280 | /** |
| 3281 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3282 | */ |
| 3283 | @Override |
| 3284 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3285 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3286 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3287 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3288 | "IMS not available on device."); |
| 3289 | } |
| 3290 | final long token = Binder.clearCallingIdentity(); |
| 3291 | try { |
| 3292 | Phone phone = getPhone(subId); |
| 3293 | if (phone == null) { |
| 3294 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3295 | + subId + "'"); |
| 3296 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3297 | } |
| 3298 | phone.getImsRegistrationState(regState -> { |
| 3299 | try { |
| 3300 | consumer.accept((regState == null) |
| 3301 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3302 | } catch (RemoteException e) { |
| 3303 | // Ignore if the remote process is no longer available to call back. |
| 3304 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3305 | } |
| 3306 | }); |
| 3307 | } finally { |
| 3308 | Binder.restoreCallingIdentity(token); |
| 3309 | } |
| 3310 | } |
| 3311 | |
| 3312 | /** |
| 3313 | * Get the transport type for the IMS service registration state. |
| 3314 | */ |
| 3315 | @Override |
| 3316 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3317 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3318 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3319 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3320 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3321 | "IMS not available on device."); |
| 3322 | } |
| 3323 | final long token = Binder.clearCallingIdentity(); |
| 3324 | try { |
| 3325 | Phone phone = getPhone(subId); |
| 3326 | if (phone == null) { |
| 3327 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3328 | + subId + "'"); |
| 3329 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3330 | } |
| 3331 | phone.getImsRegistrationTech(regTech -> { |
| 3332 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3333 | int regTechConverted = (regTech == null) |
| 3334 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3335 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3336 | regTechConverted); |
| 3337 | try { |
| 3338 | consumer.accept(regTechConverted); |
| 3339 | } catch (RemoteException e) { |
| 3340 | // Ignore if the remote process is no longer available to call back. |
| 3341 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3342 | } |
| 3343 | }); |
| 3344 | } finally { |
| 3345 | Binder.restoreCallingIdentity(token); |
| 3346 | } |
| 3347 | } |
| 3348 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3349 | /** |
| 3350 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3351 | * @param subId The subscription to use to check the configuration. |
| 3352 | * @param c The callback that will be used to send the result. |
| 3353 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3354 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3355 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3356 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3357 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3358 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3359 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3360 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3361 | "IMS not available on device."); |
| 3362 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3363 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3364 | final long token = Binder.clearCallingIdentity(); |
| 3365 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3366 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3367 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3368 | } catch (ImsException e) { |
| 3369 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3370 | } finally { |
| 3371 | Binder.restoreCallingIdentity(token); |
| 3372 | } |
| 3373 | } |
| 3374 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3375 | /** |
| 3376 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3377 | * @param subId The subscription to use to check the configuration. |
| 3378 | * @param c The callback that will be used to send the result. |
| 3379 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3380 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3381 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3382 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3383 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3384 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3385 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3386 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3387 | |
| 3388 | final long token = Binder.clearCallingIdentity(); |
| 3389 | try { |
| 3390 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3391 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3392 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3393 | } catch (ImsException e) { |
| 3394 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3395 | + "is inactive, ignoring unregister."); |
| 3396 | // If the subscription is no longer active, just return, since the callback |
| 3397 | // will already have been removed internally. |
| 3398 | } finally { |
| 3399 | Binder.restoreCallingIdentity(token); |
| 3400 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3401 | } |
| 3402 | |
| 3403 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3404 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3405 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3406 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3407 | final long token = Binder.clearCallingIdentity(); |
| 3408 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3409 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3410 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3411 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3412 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3413 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3414 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3415 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3416 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3417 | } finally { |
| 3418 | Binder.restoreCallingIdentity(token); |
| 3419 | } |
| 3420 | } |
| 3421 | |
| 3422 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3423 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3424 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3425 | final long token = Binder.clearCallingIdentity(); |
| 3426 | try { |
| 3427 | Phone phone = getPhone(subId); |
| 3428 | if (phone == null) return false; |
| 3429 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3430 | } finally { |
| 3431 | Binder.restoreCallingIdentity(token); |
| 3432 | } |
| 3433 | } |
| 3434 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3435 | /** |
| 3436 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3437 | * subscription. |
| 3438 | * @param subId The subscription to use to check the configuration. |
| 3439 | * @param callback The callback that will be used to send the result. |
| 3440 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3441 | * @param transportType The transport type of the MmTelFeature capability. |
| 3442 | */ |
| 3443 | @Override |
| 3444 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3445 | int transportType) { |
| 3446 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3447 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3448 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3449 | "IMS not available on device."); |
| 3450 | } |
| 3451 | final long token = Binder.clearCallingIdentity(); |
| 3452 | try { |
| 3453 | int slotId = getSlotIndex(subId); |
| 3454 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3455 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3456 | + subId + "'"); |
| 3457 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3458 | } |
| 3459 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3460 | transportType, aBoolean -> { |
| 3461 | try { |
| 3462 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3463 | } catch (RemoteException e) { |
| 3464 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3465 | + "running. Ignore"); |
| 3466 | } |
| 3467 | }); |
| 3468 | } finally { |
| 3469 | Binder.restoreCallingIdentity(token); |
| 3470 | } |
| 3471 | } |
| 3472 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3473 | /** |
| 3474 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3475 | * @param subId The subscription to use to check the configuration. |
| 3476 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3477 | @Override |
| 3478 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3479 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3480 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3481 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3482 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3483 | final long token = Binder.clearCallingIdentity(); |
| 3484 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3485 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3486 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3487 | } catch (ImsException e) { |
| 3488 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3489 | } finally { |
| 3490 | Binder.restoreCallingIdentity(token); |
| 3491 | } |
| 3492 | } |
| 3493 | |
| 3494 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3495 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3496 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3497 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3498 | final long identity = Binder.clearCallingIdentity(); |
| 3499 | try { |
| 3500 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3501 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3502 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3503 | } catch (ImsException e) { |
| 3504 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3505 | } finally { |
| 3506 | Binder.restoreCallingIdentity(identity); |
| 3507 | } |
| 3508 | } |
| 3509 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3510 | /** |
| 3511 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3512 | * @param subId The subscription to use to check the configuration. |
| 3513 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3514 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3515 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3516 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3517 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3518 | final long identity = Binder.clearCallingIdentity(); |
| 3519 | try { |
| 3520 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3521 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3522 | } catch (ImsException e) { |
| 3523 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3524 | } finally { |
| 3525 | Binder.restoreCallingIdentity(identity); |
| 3526 | } |
| 3527 | } |
| 3528 | |
| 3529 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3530 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3531 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3532 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3533 | final long identity = Binder.clearCallingIdentity(); |
| 3534 | try { |
| 3535 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3536 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3537 | } catch (ImsException e) { |
| 3538 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3539 | } finally { |
| 3540 | Binder.restoreCallingIdentity(identity); |
| 3541 | } |
| 3542 | } |
| 3543 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3544 | /** |
| 3545 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3546 | * @param subId The subscription to use to check the configuration. |
| 3547 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3548 | @Override |
| 3549 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3550 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3551 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3552 | final long identity = Binder.clearCallingIdentity(); |
| 3553 | try { |
| 3554 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3555 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3556 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3557 | } catch (ImsException e) { |
| 3558 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3559 | } finally { |
| 3560 | Binder.restoreCallingIdentity(identity); |
| 3561 | } |
| 3562 | } |
| 3563 | |
| 3564 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3565 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3566 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3567 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3568 | final long identity = Binder.clearCallingIdentity(); |
| 3569 | try { |
| 3570 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3571 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3572 | } catch (ImsException e) { |
| 3573 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3574 | } finally { |
| 3575 | Binder.restoreCallingIdentity(identity); |
| 3576 | } |
| 3577 | } |
| 3578 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3579 | /** |
| 3580 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3581 | * @param subId The subscription to use to check the configuration. |
| 3582 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3583 | @Override |
| 3584 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3585 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3586 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3587 | final long identity = Binder.clearCallingIdentity(); |
| 3588 | try { |
| 3589 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3590 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3591 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3592 | } catch (ImsException e) { |
| 3593 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3594 | } finally { |
| 3595 | Binder.restoreCallingIdentity(identity); |
| 3596 | } |
| 3597 | } |
| 3598 | |
| 3599 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3600 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3601 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3602 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3603 | final long identity = Binder.clearCallingIdentity(); |
| 3604 | try { |
| 3605 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3606 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3607 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3608 | } catch (ImsException e) { |
| 3609 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3610 | } finally { |
| 3611 | Binder.restoreCallingIdentity(identity); |
| 3612 | } |
| 3613 | } |
| 3614 | |
| 3615 | @Override |
| 3616 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3617 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3618 | "setVoWiFiNonPersistent"); |
| 3619 | final long identity = Binder.clearCallingIdentity(); |
| 3620 | try { |
| 3621 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3622 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3623 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3624 | } catch (ImsException e) { |
| 3625 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3626 | } finally { |
| 3627 | Binder.restoreCallingIdentity(identity); |
| 3628 | } |
| 3629 | } |
| 3630 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3631 | /** |
| 3632 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3633 | * @param subId The subscription to use to check the configuration. |
| 3634 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3635 | @Override |
| 3636 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3637 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3638 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3639 | final long identity = Binder.clearCallingIdentity(); |
| 3640 | try { |
| 3641 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3642 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3643 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3644 | } catch (ImsException e) { |
| 3645 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3646 | } finally { |
| 3647 | Binder.restoreCallingIdentity(identity); |
| 3648 | } |
| 3649 | } |
| 3650 | |
| 3651 | @Override |
| 3652 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3653 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3654 | "setVoWiFiModeSetting"); |
| 3655 | final long identity = Binder.clearCallingIdentity(); |
| 3656 | try { |
| 3657 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3658 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3659 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3660 | } catch (ImsException e) { |
| 3661 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3662 | } finally { |
| 3663 | Binder.restoreCallingIdentity(identity); |
| 3664 | } |
| 3665 | } |
| 3666 | |
| 3667 | @Override |
| 3668 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3669 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3670 | final long identity = Binder.clearCallingIdentity(); |
| 3671 | try { |
| 3672 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3673 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3674 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3675 | } catch (ImsException e) { |
| 3676 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3677 | } finally { |
| 3678 | Binder.restoreCallingIdentity(identity); |
| 3679 | } |
| 3680 | } |
| 3681 | |
| 3682 | @Override |
| 3683 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3684 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3685 | "setVoWiFiRoamingModeSetting"); |
| 3686 | final long identity = Binder.clearCallingIdentity(); |
| 3687 | try { |
| 3688 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3689 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3690 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3691 | } catch (ImsException e) { |
| 3692 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3693 | } finally { |
| 3694 | Binder.restoreCallingIdentity(identity); |
| 3695 | } |
| 3696 | } |
| 3697 | |
| 3698 | @Override |
| 3699 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3700 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3701 | "setRttCapabilityEnabled"); |
| 3702 | final long identity = Binder.clearCallingIdentity(); |
| 3703 | try { |
| 3704 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3705 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3706 | } catch (ImsException e) { |
| 3707 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3708 | } finally { |
| 3709 | Binder.restoreCallingIdentity(identity); |
| 3710 | } |
| 3711 | } |
| 3712 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3713 | /** |
| 3714 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3715 | * @param subId The subscription to use to check the configuration. |
| 3716 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3717 | @Override |
| 3718 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3719 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3720 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3721 | final long identity = Binder.clearCallingIdentity(); |
| 3722 | try { |
| 3723 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3724 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3725 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3726 | } catch (ImsException e) { |
| 3727 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3728 | } finally { |
| 3729 | Binder.restoreCallingIdentity(identity); |
| 3730 | } |
| 3731 | } |
| 3732 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3733 | @Override |
| 3734 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3735 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3736 | final long identity = Binder.clearCallingIdentity(); |
| 3737 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3738 | if (!isImsAvailableOnDevice()) { |
| 3739 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3740 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3741 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3742 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3743 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3744 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3745 | } catch (ImsException e) { |
| 3746 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3747 | } finally { |
| 3748 | Binder.restoreCallingIdentity(identity); |
| 3749 | } |
| 3750 | } |
| 3751 | |
| 3752 | @Override |
| 3753 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3754 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3755 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3756 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3757 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3758 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3759 | try { |
| 3760 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3761 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3762 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3763 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3764 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3765 | + "is inactive, ignoring unregister."); |
| 3766 | // If the subscription is no longer active, just return, since the callback will already |
| 3767 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3768 | } finally { |
| 3769 | Binder.restoreCallingIdentity(identity); |
| 3770 | } |
| 3771 | } |
| 3772 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3773 | |
| 3774 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3775 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3776 | message); |
| 3777 | } |
| 3778 | |
| 3779 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3780 | boolean isMmtelCapability) { |
| 3781 | Phone phone = getPhone(subId); |
| 3782 | if (phone == null) { |
| 3783 | loge("phone instance null for subid " + subId); |
| 3784 | return false; |
| 3785 | } |
| 3786 | if (isMmtelCapability) { |
| 3787 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3788 | return false; |
| 3789 | } |
| 3790 | } else { |
| 3791 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3792 | return false; |
| 3793 | } |
| 3794 | } |
| 3795 | return true; |
| 3796 | } |
| 3797 | |
| 3798 | @Override |
| 3799 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3800 | boolean isProvisioned) { |
| 3801 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3802 | |
| 3803 | final long identity = Binder.clearCallingIdentity(); |
| 3804 | try { |
| 3805 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3806 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3807 | return; |
| 3808 | } |
| 3809 | |
| 3810 | // this capability requires provisioning, route to the correct API. |
| 3811 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3812 | switch (capability) { |
| 3813 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3814 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3815 | ims.setEabProvisioned(isProvisioned); |
| 3816 | break; |
| 3817 | default: { |
| 3818 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3819 | + "rcs capability '" + capability + "', which does not require " |
| 3820 | + "provisioning."); |
| 3821 | } |
| 3822 | } |
| 3823 | } finally { |
| 3824 | Binder.restoreCallingIdentity(identity); |
| 3825 | } |
| 3826 | |
| 3827 | } |
| 3828 | |
| 3829 | |
| 3830 | @Override |
| 3831 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3832 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3833 | final long identity = Binder.clearCallingIdentity(); |
| 3834 | try { |
| 3835 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3836 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3837 | return true; |
| 3838 | } |
| 3839 | |
| 3840 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3841 | switch (capability) { |
| 3842 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3843 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3844 | return ims.isEabProvisionedOnDevice(); |
| 3845 | |
| 3846 | default: { |
| 3847 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3848 | + "capability '" + capability + "', which does not require " |
| 3849 | + "provisioning."); |
| 3850 | } |
| 3851 | } |
| 3852 | |
| 3853 | } finally { |
| 3854 | Binder.restoreCallingIdentity(identity); |
| 3855 | } |
| 3856 | } |
| 3857 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3858 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3859 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3860 | boolean isProvisioned) { |
| 3861 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3862 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3863 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3864 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3865 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3866 | final long identity = Binder.clearCallingIdentity(); |
| 3867 | try { |
| 3868 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3869 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3870 | return; |
| 3871 | } |
| 3872 | |
| 3873 | // this capability requires provisioning, route to the correct API. |
| 3874 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3875 | switch (capability) { |
| 3876 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3877 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3878 | ims.setVolteProvisioned(isProvisioned); |
| 3879 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3880 | ims.setWfcProvisioned(isProvisioned); |
| 3881 | } |
| 3882 | break; |
| 3883 | } |
| 3884 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3885 | // There is currently no difference in VT provisioning type. |
| 3886 | ims.setVtProvisioned(isProvisioned); |
| 3887 | break; |
| 3888 | } |
| 3889 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3890 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3891 | // change the capability of the feature instead if needed. |
| 3892 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3893 | == isProvisioned) { |
| 3894 | // No change in provisioning. |
| 3895 | return; |
| 3896 | } |
| 3897 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3898 | try { |
| 3899 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3900 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3901 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3902 | + ", Exception" + e.getMessage()); |
| 3903 | } |
| 3904 | break; |
| 3905 | } |
| 3906 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3907 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3908 | + "MmTel capability '" + capability + "', which does not require " |
| 3909 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3910 | } |
| 3911 | } |
| 3912 | |
| 3913 | } finally { |
| 3914 | Binder.restoreCallingIdentity(identity); |
| 3915 | } |
| 3916 | } |
| 3917 | |
| 3918 | @Override |
| 3919 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3920 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3921 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3922 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3923 | } |
| 3924 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3925 | final long identity = Binder.clearCallingIdentity(); |
| 3926 | try { |
| 3927 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3928 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3929 | return true; |
| 3930 | } |
| 3931 | |
| 3932 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3933 | switch (capability) { |
| 3934 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3935 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3936 | return ims.isVolteProvisionedOnDevice(); |
| 3937 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3938 | return ims.isWfcProvisionedOnDevice(); |
| 3939 | } |
| 3940 | // This should never happen, since we are checking tech above to make sure it |
| 3941 | // is either LTE or IWLAN. |
| 3942 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3943 | + "capability."); |
| 3944 | } |
| 3945 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3946 | // There is currently no difference in VT provisioning type. |
| 3947 | return ims.isVtProvisionedOnDevice(); |
| 3948 | } |
| 3949 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3950 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3951 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3952 | } |
| 3953 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3954 | throw new IllegalArgumentException( |
| 3955 | "Tried to get provisioning for MmTel capability '" + capability |
| 3956 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3957 | } |
| 3958 | } |
| 3959 | |
| 3960 | } finally { |
| 3961 | Binder.restoreCallingIdentity(identity); |
| 3962 | } |
| 3963 | } |
| 3964 | |
| 3965 | @Override |
| 3966 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3967 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3968 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3969 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3970 | } |
| 3971 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3972 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3973 | return (provisionedBits & capability) > 0; |
| 3974 | } |
| 3975 | |
| 3976 | @Override |
| 3977 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3978 | boolean isProvisioned) { |
| 3979 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3980 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3981 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3982 | } |
| 3983 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3984 | "setProvisioningStatusForCapability"); |
| 3985 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3986 | // If the current provisioning status for capability already matches isProvisioned, |
| 3987 | // do nothing. |
| 3988 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3989 | return; |
| 3990 | } |
| 3991 | if (isProvisioned) { |
| 3992 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3993 | } else { |
| 3994 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3995 | } |
| 3996 | } |
| 3997 | |
| 3998 | /** |
| 3999 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4000 | * technology. The bitfield should mirror the bitfield defined by |
| 4001 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4002 | */ |
| 4003 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4004 | String key = getMmTelProvisioningKey(subId, tech); |
| 4005 | // Default is no capabilities are provisioned. |
| 4006 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4007 | } |
| 4008 | |
| 4009 | /** |
| 4010 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4011 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4012 | * technology specified. |
| 4013 | * |
| 4014 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4015 | */ |
| 4016 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4017 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4018 | String key = getMmTelProvisioningKey(subId, tech); |
| 4019 | editor.putInt(key, newField); |
| 4020 | editor.commit(); |
| 4021 | } |
| 4022 | |
| 4023 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4024 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4025 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4026 | } |
| 4027 | |
| 4028 | /** |
| 4029 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4030 | * carrier associated with the subscription id. |
| 4031 | */ |
| 4032 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4033 | int capability) { |
| 4034 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4035 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4036 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4037 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4038 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4039 | false); |
| 4040 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4041 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4042 | |
| 4043 | // First check to make sure that the capability requires provisioning. |
| 4044 | switch (capability) { |
| 4045 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4046 | // intentional fallthrough |
| 4047 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4048 | if (requireVoiceVtProvisioning) { |
| 4049 | // Voice and Video requires provisioning |
| 4050 | return true; |
| 4051 | } |
| 4052 | break; |
| 4053 | } |
| 4054 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4055 | if (requireUtProvisioning) { |
| 4056 | // UT requires provisioning |
| 4057 | return true; |
| 4058 | } |
| 4059 | break; |
| 4060 | } |
| 4061 | } |
| 4062 | return false; |
| 4063 | } |
| 4064 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4065 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4066 | int capability) { |
| 4067 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4068 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4069 | |
| 4070 | boolean requireRcsProvisioning = c.getBoolean( |
| 4071 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4072 | |
| 4073 | // First check to make sure that the capability requires provisioning. |
| 4074 | switch (capability) { |
| 4075 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4076 | // intentional fallthrough |
| 4077 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4078 | if (requireRcsProvisioning) { |
| 4079 | // OPTION or PRESENCE requires provisioning |
| 4080 | return true; |
| 4081 | } |
| 4082 | break; |
| 4083 | } |
| 4084 | } |
| 4085 | return false; |
| 4086 | } |
| 4087 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4088 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4089 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4090 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4091 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4092 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4093 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4094 | final long identity = Binder.clearCallingIdentity(); |
| 4095 | try { |
| 4096 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4097 | int slotId = getSlotIndex(subId); |
| 4098 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4099 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4100 | + subId + "' for key:" + key); |
| 4101 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4102 | } |
| 4103 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4104 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4105 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4106 | + subId + "' for key:" + key); |
| 4107 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4108 | } finally { |
| 4109 | Binder.restoreCallingIdentity(identity); |
| 4110 | } |
| 4111 | } |
| 4112 | |
| 4113 | @Override |
| 4114 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4115 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4116 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4117 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4118 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4119 | final long identity = Binder.clearCallingIdentity(); |
| 4120 | try { |
| 4121 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4122 | int slotId = getSlotIndex(subId); |
| 4123 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4124 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4125 | + subId + "' for key:" + key); |
| 4126 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4127 | } |
| 4128 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4129 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4130 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4131 | + subId + "' for key:" + key); |
| 4132 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4133 | } finally { |
| 4134 | Binder.restoreCallingIdentity(identity); |
| 4135 | } |
| 4136 | } |
| 4137 | |
| 4138 | @Override |
| 4139 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4140 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4141 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4142 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4143 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4144 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4145 | final long identity = Binder.clearCallingIdentity(); |
| 4146 | try { |
| 4147 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4148 | int slotId = getSlotIndex(subId); |
| 4149 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4150 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4151 | + subId + "' for key:" + key); |
| 4152 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4153 | } |
| 4154 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4155 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4156 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4157 | + "' for key:" + key); |
| 4158 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4159 | } finally { |
| 4160 | Binder.restoreCallingIdentity(identity); |
| 4161 | } |
| 4162 | } |
| 4163 | |
| 4164 | @Override |
| 4165 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4166 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4167 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4168 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4169 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4170 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4171 | final long identity = Binder.clearCallingIdentity(); |
| 4172 | try { |
| 4173 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4174 | int slotId = getSlotIndex(subId); |
| 4175 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4176 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4177 | + subId + "' for key:" + key); |
| 4178 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4179 | } |
| 4180 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4181 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4182 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4183 | + "' for key:" + key); |
| 4184 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4185 | } finally { |
| 4186 | Binder.restoreCallingIdentity(identity); |
| 4187 | } |
| 4188 | } |
| 4189 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4190 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4191 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4192 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4193 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4194 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4195 | } |
| 4196 | return slotId; |
| 4197 | } |
| 4198 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4199 | private int getSlotIndex(int subId) { |
| 4200 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4201 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4202 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4203 | } |
| 4204 | return slotId; |
| 4205 | } |
| 4206 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4207 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4208 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4209 | */ |
| 4210 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4211 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4212 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4213 | final int targetSdk = getTargetSdk(callingPackage); |
| 4214 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4215 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4216 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4217 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4218 | mApp, subId, callingPackage, callingFeatureId, |
| 4219 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4220 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4221 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4222 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4223 | final long identity = Binder.clearCallingIdentity(); |
| 4224 | try { |
| 4225 | final Phone phone = getPhone(subId); |
| 4226 | if (phone != null) { |
| 4227 | return phone.getServiceState().getDataNetworkType(); |
| 4228 | } else { |
| 4229 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4230 | } |
| 4231 | } finally { |
| 4232 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4233 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4234 | } |
| 4235 | |
| 4236 | /** |
| 4237 | * Returns the data network type |
| 4238 | */ |
| 4239 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4240 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4241 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4242 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4243 | } |
| 4244 | |
| 4245 | /** |
| 4246 | * Returns the data network type for a subId |
| 4247 | */ |
| 4248 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4249 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4250 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4251 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4252 | mApp, subId, callingPackage, callingFeatureId, |
| 4253 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4254 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4255 | } |
| 4256 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4257 | final long identity = Binder.clearCallingIdentity(); |
| 4258 | try { |
| 4259 | final Phone phone = getPhone(subId); |
| 4260 | if (phone != null) { |
| 4261 | return phone.getServiceState().getDataNetworkType(); |
| 4262 | } else { |
| 4263 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4264 | } |
| 4265 | } finally { |
| 4266 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4267 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4268 | } |
| 4269 | |
| 4270 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4271 | * Returns the Voice network type for a subId |
| 4272 | */ |
| 4273 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4274 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4275 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4276 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4277 | mApp, subId, callingPackage, callingFeatureId, |
| 4278 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4279 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4280 | } |
| 4281 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4282 | final long identity = Binder.clearCallingIdentity(); |
| 4283 | try { |
| 4284 | final Phone phone = getPhone(subId); |
| 4285 | if (phone != null) { |
| 4286 | return phone.getServiceState().getVoiceNetworkType(); |
| 4287 | } else { |
| 4288 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4289 | } |
| 4290 | } finally { |
| 4291 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4292 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4293 | } |
| 4294 | |
| 4295 | /** |
| 4296 | * @return true if a ICC card is present |
| 4297 | */ |
| 4298 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4299 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4300 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4301 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4305 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4306 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4307 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4308 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4309 | final long identity = Binder.clearCallingIdentity(); |
| 4310 | try { |
| 4311 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4312 | if (phone != null) { |
| 4313 | return phone.getIccCard().hasIccCard(); |
| 4314 | } else { |
| 4315 | return false; |
| 4316 | } |
| 4317 | } finally { |
| 4318 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4319 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4320 | } |
| 4321 | |
| 4322 | /** |
| 4323 | * Return if the current radio is LTE on CDMA. This |
| 4324 | * is a tri-state return value as for a period of time |
| 4325 | * the mode may be unknown. |
| 4326 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4327 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4328 | * @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] | 4329 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4330 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4331 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4332 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4333 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4334 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4335 | } |
| 4336 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4337 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4338 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4339 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4340 | try { |
| 4341 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4342 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4343 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4344 | } |
| 4345 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4346 | final long identity = Binder.clearCallingIdentity(); |
| 4347 | try { |
| 4348 | final Phone phone = getPhone(subId); |
| 4349 | if (phone == null) { |
| 4350 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4351 | } else { |
| 4352 | return phone.getLteOnCdmaMode(); |
| 4353 | } |
| 4354 | } finally { |
| 4355 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4356 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4357 | } |
| 4358 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4359 | /** |
| 4360 | * {@hide} |
| 4361 | * Returns Default subId, 0 in the case of single standby. |
| 4362 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4363 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4364 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4365 | } |
| 4366 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4367 | private int getSlotForDefaultSubscription() { |
| 4368 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4369 | } |
| 4370 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4371 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4372 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4373 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4374 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4375 | private boolean isActiveSubscription(int subId) { |
| 4376 | return mSubscriptionController.isActiveSubId(subId); |
| 4377 | } |
| 4378 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4379 | /** |
| 4380 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4381 | */ |
| 4382 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4383 | final long identity = Binder.clearCallingIdentity(); |
| 4384 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4385 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4386 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4387 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4388 | } finally { |
| 4389 | Binder.restoreCallingIdentity(identity); |
| 4390 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4391 | } |
| 4392 | |
| 4393 | /** |
| 4394 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4395 | */ |
| 4396 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4397 | final long identity = Binder.clearCallingIdentity(); |
| 4398 | try { |
| 4399 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4400 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4401 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4402 | } finally { |
| 4403 | Binder.restoreCallingIdentity(identity); |
| 4404 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4405 | } |
| 4406 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4407 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4408 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4409 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4410 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4411 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4412 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4413 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4414 | if (phoneId == -1) { |
| 4415 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4416 | + " does not correspond to an active phone"); |
| 4417 | } |
| 4418 | return PhoneFactory.getPhone(phoneId); |
| 4419 | } |
| 4420 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4421 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4422 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4423 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4424 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4425 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4426 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4427 | if (DBG) { |
| 4428 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4429 | } |
| 4430 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4431 | p2); |
| 4432 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4433 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4434 | |
| 4435 | @Override |
| 4436 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4437 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4438 | enforceModifyPermission(); |
| 4439 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4440 | if (DBG) { |
| 4441 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4442 | } |
| 4443 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4444 | callingPackage, aid, p2); |
| 4445 | } |
| 4446 | |
| 4447 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4448 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4449 | final long identity = Binder.clearCallingIdentity(); |
| 4450 | try { |
| 4451 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4452 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4453 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4454 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4455 | if (bestComponent == null |
| 4456 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4457 | loge("The calling package is not allowed to access ISD-R."); |
| 4458 | throw new SecurityException( |
| 4459 | "The calling package is not allowed to access ISD-R."); |
| 4460 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4461 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4462 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4463 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4464 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4465 | null /* workSource */); |
| 4466 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4467 | return response; |
| 4468 | } finally { |
| 4469 | Binder.restoreCallingIdentity(identity); |
| 4470 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4471 | } |
| 4472 | |
| 4473 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4474 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4475 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4476 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4477 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4478 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4479 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4480 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4481 | @Override |
| 4482 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4483 | enforceModifyPermission(); |
| 4484 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4485 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4486 | channel); |
| 4487 | } |
| 4488 | |
| 4489 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4490 | final long identity = Binder.clearCallingIdentity(); |
| 4491 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4492 | if (channel < 0) { |
| 4493 | return false; |
| 4494 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4495 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4496 | null /* workSource */); |
| 4497 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4498 | return success; |
| 4499 | } finally { |
| 4500 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4501 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4502 | } |
| 4503 | |
| 4504 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4505 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4506 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4507 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4508 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4509 | if (DBG) { |
| 4510 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4511 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4512 | + p3 + " data=" + data); |
| 4513 | } |
| 4514 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4515 | command, p1, p2, p3, data); |
| 4516 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4517 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4518 | @Override |
| 4519 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4520 | int command, int p1, int p2, int p3, String data) { |
| 4521 | enforceModifyPermission(); |
| 4522 | if (DBG) { |
| 4523 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4524 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4525 | + p3 + " data=" + data); |
| 4526 | } |
| 4527 | return iccTransmitApduLogicalChannelWithPermission( |
| 4528 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4529 | data); |
| 4530 | } |
| 4531 | |
| 4532 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4533 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4534 | final long identity = Binder.clearCallingIdentity(); |
| 4535 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4536 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4537 | return ""; |
| 4538 | } |
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 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4541 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4542 | null /* workSource */); |
| 4543 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4544 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4545 | // Append the returned status code to the end of the response payload. |
| 4546 | String s = Integer.toHexString( |
| 4547 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4548 | if (response.payload != null) { |
| 4549 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4550 | } |
| 4551 | return s; |
| 4552 | } finally { |
| 4553 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4554 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4555 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4556 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4557 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4558 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4559 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4560 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4561 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4562 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4563 | if (DBG) { |
| 4564 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4565 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4566 | } |
| 4567 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4568 | cla, command, p1, p2, p3, data); |
| 4569 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4570 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4571 | @Override |
| 4572 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4573 | int command, int p1, int p2, int p3, String data) { |
| 4574 | enforceModifyPermission(); |
| 4575 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4576 | if (DBG) { |
| 4577 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4578 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4579 | + " data=" + data); |
| 4580 | } |
| 4581 | |
| 4582 | return iccTransmitApduBasicChannelWithPermission( |
| 4583 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4584 | p2, p3, data); |
| 4585 | } |
| 4586 | |
| 4587 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4588 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4589 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4590 | final long identity = Binder.clearCallingIdentity(); |
| 4591 | try { |
| 4592 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4593 | && TextUtils.equals(ISDR_AID, data)) { |
| 4594 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4595 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4596 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4597 | if (bestComponent == null |
| 4598 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4599 | loge("The calling package is not allowed to select ISD-R."); |
| 4600 | throw new SecurityException( |
| 4601 | "The calling package is not allowed to select ISD-R."); |
| 4602 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4603 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4604 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4605 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4606 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4607 | null /* workSource */); |
| 4608 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4609 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4610 | // Append the returned status code to the end of the response payload. |
| 4611 | String s = Integer.toHexString( |
| 4612 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4613 | if (response.payload != null) { |
| 4614 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4615 | } |
| 4616 | return s; |
| 4617 | } finally { |
| 4618 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4619 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4620 | } |
| 4621 | |
| 4622 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4623 | 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] | 4624 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4625 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4626 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4627 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4628 | final long identity = Binder.clearCallingIdentity(); |
| 4629 | try { |
| 4630 | if (DBG) { |
| 4631 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4632 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4633 | } |
| 4634 | |
| 4635 | IccIoResult response = |
| 4636 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4637 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4638 | subId); |
| 4639 | |
| 4640 | if (DBG) { |
| 4641 | log("Exchange SIM_IO [R]" + response); |
| 4642 | } |
| 4643 | |
| 4644 | byte[] result = null; |
| 4645 | int length = 2; |
| 4646 | if (response.payload != null) { |
| 4647 | length = 2 + response.payload.length; |
| 4648 | result = new byte[length]; |
| 4649 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4650 | } else { |
| 4651 | result = new byte[length]; |
| 4652 | } |
| 4653 | |
| 4654 | result[length - 1] = (byte) response.sw2; |
| 4655 | result[length - 2] = (byte) response.sw1; |
| 4656 | return result; |
| 4657 | } finally { |
| 4658 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4659 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4660 | } |
| 4661 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4662 | /** |
| 4663 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4664 | * on a particular subscription |
| 4665 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4666 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4667 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4668 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4669 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4670 | return null; |
| 4671 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4672 | |
| 4673 | final long identity = Binder.clearCallingIdentity(); |
| 4674 | try { |
| 4675 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4676 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4677 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4678 | return null; |
| 4679 | } |
| 4680 | Object response = sendRequest( |
| 4681 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4682 | if (response instanceof String[]) { |
| 4683 | return (String[]) response; |
| 4684 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4685 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4686 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4687 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4688 | } finally { |
| 4689 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4690 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4691 | } |
| 4692 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4693 | /** |
| 4694 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4695 | * subscription. |
| 4696 | * |
| 4697 | * @param subId the id of the subscription. |
| 4698 | * @param appType the uicc app type, must be USIM or SIM. |
| 4699 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4700 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4701 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4702 | * @return number of fplmns that is successfully written to the SIM. |
| 4703 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4704 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4705 | String callingFeatureId) { |
| 4706 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4707 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4708 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4709 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4710 | } |
| 4711 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4712 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4713 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4714 | } |
| 4715 | if (fplmns == null) { |
| 4716 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4717 | } |
| 4718 | for (String fplmn : fplmns) { |
| 4719 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4720 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4721 | } |
| 4722 | } |
| 4723 | final long identity = Binder.clearCallingIdentity(); |
| 4724 | try { |
| 4725 | Object response = sendRequest( |
| 4726 | CMD_SET_FORBIDDEN_PLMNS, |
| 4727 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4728 | subId); |
| 4729 | return (int) response; |
| 4730 | } finally { |
| 4731 | Binder.restoreCallingIdentity(identity); |
| 4732 | } |
| 4733 | } |
| 4734 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4735 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4736 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4737 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4738 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4739 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4740 | final long identity = Binder.clearCallingIdentity(); |
| 4741 | try { |
| 4742 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4743 | if (response.payload == null) { |
| 4744 | return ""; |
| 4745 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4746 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4747 | // Append the returned status code to the end of the response payload. |
| 4748 | String s = Integer.toHexString( |
| 4749 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4750 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4751 | return s; |
| 4752 | } finally { |
| 4753 | Binder.restoreCallingIdentity(identity); |
| 4754 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4755 | } |
| 4756 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4757 | /** |
| 4758 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4759 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4760 | * |
| 4761 | * @param itemID the ID of the item to read |
| 4762 | * @return the NV item as a String, or null on error. |
| 4763 | */ |
| 4764 | @Override |
| 4765 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4766 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4767 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4768 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4769 | |
| 4770 | final long identity = Binder.clearCallingIdentity(); |
| 4771 | try { |
| 4772 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4773 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4774 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4775 | return value; |
| 4776 | } finally { |
| 4777 | Binder.restoreCallingIdentity(identity); |
| 4778 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4779 | } |
| 4780 | |
| 4781 | /** |
| 4782 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4783 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4784 | * |
| 4785 | * @param itemID the ID of the item to read |
| 4786 | * @param itemValue the value to write, as a String |
| 4787 | * @return true on success; false on any failure |
| 4788 | */ |
| 4789 | @Override |
| 4790 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4791 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4792 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4793 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4794 | |
| 4795 | final long identity = Binder.clearCallingIdentity(); |
| 4796 | try { |
| 4797 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4798 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4799 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4800 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4801 | return success; |
| 4802 | } finally { |
| 4803 | Binder.restoreCallingIdentity(identity); |
| 4804 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4805 | } |
| 4806 | |
| 4807 | /** |
| 4808 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4809 | * Used for device configuration by some CDMA operators. |
| 4810 | * |
| 4811 | * @param preferredRoamingList byte array containing the new PRL |
| 4812 | * @return true on success; false on any failure |
| 4813 | */ |
| 4814 | @Override |
| 4815 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4816 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4817 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4818 | |
| 4819 | final long identity = Binder.clearCallingIdentity(); |
| 4820 | try { |
| 4821 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4822 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4823 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4824 | return success; |
| 4825 | } finally { |
| 4826 | Binder.restoreCallingIdentity(identity); |
| 4827 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4828 | } |
| 4829 | |
| 4830 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4831 | * 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] | 4832 | * Used for device configuration by some CDMA operators. |
| 4833 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4834 | * @param slotIndex - device slot. |
| 4835 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4836 | * @return true on success; false on any failure |
| 4837 | */ |
| 4838 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4839 | public boolean resetModemConfig(int slotIndex) { |
| 4840 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4841 | if (phone != null) { |
| 4842 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4843 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4844 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4845 | final long identity = Binder.clearCallingIdentity(); |
| 4846 | try { |
| 4847 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4848 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4849 | return success; |
| 4850 | } finally { |
| 4851 | Binder.restoreCallingIdentity(identity); |
| 4852 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4853 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4854 | return false; |
| 4855 | } |
| 4856 | |
| 4857 | /** |
| 4858 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4859 | * |
| 4860 | * @param slotIndex - device slot. |
| 4861 | * |
| 4862 | * @return true on success; false on any failure |
| 4863 | */ |
| 4864 | @Override |
| 4865 | public boolean rebootModem(int slotIndex) { |
| 4866 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4867 | if (phone != null) { |
| 4868 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4869 | mApp, phone.getSubId(), "rebootModem"); |
| 4870 | |
| 4871 | final long identity = Binder.clearCallingIdentity(); |
| 4872 | try { |
| 4873 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4874 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4875 | return success; |
| 4876 | } finally { |
| 4877 | Binder.restoreCallingIdentity(identity); |
| 4878 | } |
| 4879 | } |
| 4880 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4881 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4882 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4883 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4884 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4885 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4886 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4887 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4888 | return new String[0]; |
| 4889 | } |
| 4890 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4891 | final long identity = Binder.clearCallingIdentity(); |
| 4892 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4893 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4894 | } finally { |
| 4895 | Binder.restoreCallingIdentity(identity); |
| 4896 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4897 | } |
| 4898 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4899 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 4900 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 4901 | * {@link #disableIms(int)}. |
| 4902 | * @param slotIndex device slot. |
| 4903 | */ |
| 4904 | public void resetIms(int slotIndex) { |
| 4905 | enforceModifyPermission(); |
| 4906 | |
| 4907 | final long identity = Binder.clearCallingIdentity(); |
| 4908 | try { |
| 4909 | if (mImsResolver == null) { |
| 4910 | // may happen if the does not support IMS. |
| 4911 | return; |
| 4912 | } |
| 4913 | mImsResolver.disableIms(slotIndex); |
| 4914 | mImsResolver.enableIms(slotIndex); |
| 4915 | } finally { |
| 4916 | Binder.restoreCallingIdentity(identity); |
| 4917 | } |
| 4918 | } |
| 4919 | |
| 4920 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4921 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4922 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4923 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4924 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4925 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4926 | |
| 4927 | final long identity = Binder.clearCallingIdentity(); |
| 4928 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4929 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4930 | // may happen if the device does not support IMS. |
| 4931 | return; |
| 4932 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4933 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4934 | } finally { |
| 4935 | Binder.restoreCallingIdentity(identity); |
| 4936 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4937 | } |
| 4938 | |
| 4939 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4940 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4941 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4942 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4943 | public void disableIms(int slotId) { |
| 4944 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4945 | |
| 4946 | final long identity = Binder.clearCallingIdentity(); |
| 4947 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4948 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4949 | // may happen if the device does not support IMS. |
| 4950 | return; |
| 4951 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4952 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4953 | } finally { |
| 4954 | Binder.restoreCallingIdentity(identity); |
| 4955 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4956 | } |
| 4957 | |
| 4958 | /** |
| 4959 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4960 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4961 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4962 | */ |
| 4963 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4964 | IImsServiceFeatureCallback callback) { |
| 4965 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4966 | |
| 4967 | final long identity = Binder.clearCallingIdentity(); |
| 4968 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4969 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4970 | // may happen if the device does not support IMS. |
| 4971 | return null; |
| 4972 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4973 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4974 | } finally { |
| 4975 | Binder.restoreCallingIdentity(identity); |
| 4976 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4977 | } |
| 4978 | |
| 4979 | /** |
| 4980 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4981 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4982 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4983 | * listener for feature updates. |
| 4984 | */ |
| 4985 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4986 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4987 | |
| 4988 | final long identity = Binder.clearCallingIdentity(); |
| 4989 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4990 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4991 | // may happen if the device does not support IMS. |
| 4992 | return null; |
| 4993 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4994 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4995 | } finally { |
| 4996 | Binder.restoreCallingIdentity(identity); |
| 4997 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4998 | } |
| 4999 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5000 | /** |
| 5001 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5002 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5003 | */ |
| 5004 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5005 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5006 | |
| 5007 | final long identity = Binder.clearCallingIdentity(); |
| 5008 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5009 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5010 | // may happen if the device does not support IMS. |
| 5011 | return null; |
| 5012 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5013 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5014 | } finally { |
| 5015 | Binder.restoreCallingIdentity(identity); |
| 5016 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5017 | } |
| 5018 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5019 | /** |
| 5020 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5021 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5022 | */ |
| 5023 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5024 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5025 | |
| 5026 | final long identity = Binder.clearCallingIdentity(); |
| 5027 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5028 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5029 | // may happen if the device does not support IMS. |
| 5030 | return null; |
| 5031 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5032 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5033 | } finally { |
| 5034 | Binder.restoreCallingIdentity(identity); |
| 5035 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5036 | } |
| 5037 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5038 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5039 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5040 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5041 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5042 | * @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] | 5043 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5044 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5045 | * @param packageName The name of the package that the current configuration will be replaced |
| 5046 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5047 | * @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] | 5048 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5049 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5050 | int[] featureTypes, String packageName) { |
| 5051 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5052 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5053 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5054 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5055 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5056 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5057 | final long identity = Binder.clearCallingIdentity(); |
| 5058 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5059 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5060 | // may happen if the device does not support IMS. |
| 5061 | return false; |
| 5062 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5063 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5064 | for (int featureType : featureTypes) { |
| 5065 | featureConfig.put(featureType, packageName); |
| 5066 | } |
| 5067 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5068 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5069 | } finally { |
| 5070 | Binder.restoreCallingIdentity(identity); |
| 5071 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5072 | } |
| 5073 | |
| 5074 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5075 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5076 | * |
| 5077 | * @param slotId The slot that the ImsService is associated with. |
| 5078 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5079 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5080 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5081 | * @return the package name of the ImsService configuration. |
| 5082 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5083 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5084 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5085 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5086 | TelephonyPermissions |
| 5087 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5088 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5089 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5090 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5091 | final long identity = Binder.clearCallingIdentity(); |
| 5092 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5093 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5094 | // may happen if the device does not support IMS. |
| 5095 | return ""; |
| 5096 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5097 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5098 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5099 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5100 | } finally { |
| 5101 | Binder.restoreCallingIdentity(identity); |
| 5102 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5103 | } |
| 5104 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5105 | /** |
| 5106 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5107 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5108 | * @param callback A callback with an integer containing the |
| 5109 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5110 | */ |
| 5111 | @Override |
| 5112 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5113 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5114 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5115 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5116 | "IMS not available on device."); |
| 5117 | } |
| 5118 | final long token = Binder.clearCallingIdentity(); |
| 5119 | try { |
| 5120 | int slotId = getSlotIndex(subId); |
| 5121 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5122 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5123 | + subId + "'"); |
| 5124 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5125 | } |
| 5126 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5127 | try { |
| 5128 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5129 | } catch (RemoteException e) { |
| 5130 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5131 | + "Ignore"); |
| 5132 | } |
| 5133 | }); |
| 5134 | } finally { |
| 5135 | Binder.restoreCallingIdentity(token); |
| 5136 | } |
| 5137 | } |
| 5138 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5139 | public void setImsRegistrationState(boolean registered) { |
| 5140 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5141 | |
| 5142 | final long identity = Binder.clearCallingIdentity(); |
| 5143 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5144 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5145 | } finally { |
| 5146 | Binder.restoreCallingIdentity(identity); |
| 5147 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5148 | } |
| 5149 | |
| 5150 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5151 | * Set the network selection mode to automatic. |
| 5152 | * |
| 5153 | */ |
| 5154 | @Override |
| 5155 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5156 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5157 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5158 | |
| 5159 | final long identity = Binder.clearCallingIdentity(); |
| 5160 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5161 | if (!isActiveSubscription(subId)) { |
| 5162 | return; |
| 5163 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5164 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5165 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5166 | } finally { |
| 5167 | Binder.restoreCallingIdentity(identity); |
| 5168 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5169 | } |
| 5170 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5171 | /** |
| 5172 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5173 | * |
| 5174 | * @param subId the id of the subscription. |
| 5175 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5176 | * the operator to attach to. |
| 5177 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5178 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5179 | * normal network selection next time. |
| 5180 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5181 | */ |
| 5182 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5183 | public boolean setNetworkSelectionModeManual( |
| 5184 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5185 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5186 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5187 | |
| 5188 | if (!isActiveSubscription(subId)) { |
| 5189 | return false; |
| 5190 | } |
| 5191 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5192 | final long identity = Binder.clearCallingIdentity(); |
| 5193 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5194 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5195 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5196 | if (DBG) { |
| 5197 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5198 | + " operator: " + operatorInfo); |
| 5199 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5200 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5201 | } finally { |
| 5202 | Binder.restoreCallingIdentity(identity); |
| 5203 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5204 | } |
| 5205 | |
| 5206 | /** |
| 5207 | * Scans for available networks. |
| 5208 | */ |
| 5209 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5210 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5211 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5212 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5213 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5214 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5215 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5216 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5217 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5218 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5219 | .setCallingPid(Binder.getCallingPid()) |
| 5220 | .setCallingUid(Binder.getCallingUid()) |
| 5221 | .setMethod("getCellNetworkScanResults") |
| 5222 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5223 | .build()); |
| 5224 | switch (locationResult) { |
| 5225 | case DENIED_HARD: |
| 5226 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5227 | case DENIED_SOFT: |
| 5228 | return null; |
| 5229 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5230 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5231 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5232 | try { |
| 5233 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5234 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5235 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5236 | } finally { |
| 5237 | Binder.restoreCallingIdentity(identity); |
| 5238 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5239 | } |
| 5240 | |
| 5241 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5242 | * Get the call forwarding info, given the call forwarding reason. |
| 5243 | */ |
| 5244 | @Override |
| 5245 | public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) { |
| 5246 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5247 | long identity = Binder.clearCallingIdentity(); |
| 5248 | try { |
| 5249 | if (DBG) { |
| 5250 | log("getCallForwarding: subId " + subId |
| 5251 | + " callForwardingReason" + callForwardingReason); |
| 5252 | } |
| 5253 | return (CallForwardingInfo) sendRequest( |
| 5254 | CMD_GET_CALL_FORWARDING, callForwardingReason, subId); |
| 5255 | } finally { |
| 5256 | Binder.restoreCallingIdentity(identity); |
| 5257 | } |
| 5258 | } |
| 5259 | |
| 5260 | /** |
| 5261 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5262 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5263 | */ |
| 5264 | @Override |
| 5265 | public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) { |
| 5266 | enforceModifyPermission(); |
| 5267 | long identity = Binder.clearCallingIdentity(); |
| 5268 | try { |
| 5269 | if (DBG) { |
| 5270 | log("setCallForwarding: subId " + subId |
| 5271 | + " callForwardingInfo" + callForwardingInfo); |
| 5272 | } |
| 5273 | return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId); |
| 5274 | } finally { |
| 5275 | Binder.restoreCallingIdentity(identity); |
| 5276 | } |
| 5277 | } |
| 5278 | |
| 5279 | /** |
| 5280 | * Get the call forwarding info, given the call forwarding reason. |
| 5281 | */ |
| 5282 | @Override |
| 5283 | public int getCallWaitingStatus(int subId) { |
| 5284 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5285 | long identity = Binder.clearCallingIdentity(); |
| 5286 | try { |
| 5287 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 5288 | return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId); |
| 5289 | } finally { |
| 5290 | Binder.restoreCallingIdentity(identity); |
| 5291 | } |
| 5292 | } |
| 5293 | |
| 5294 | /** |
| 5295 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5296 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5297 | */ |
| 5298 | @Override |
| 5299 | public boolean setCallWaitingStatus(int subId, boolean isEnable) { |
| 5300 | enforceModifyPermission(); |
| 5301 | long identity = Binder.clearCallingIdentity(); |
| 5302 | try { |
| 5303 | if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable); |
| 5304 | return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId); |
| 5305 | } finally { |
| 5306 | Binder.restoreCallingIdentity(identity); |
| 5307 | } |
| 5308 | } |
| 5309 | |
| 5310 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5311 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5312 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5313 | * @param subId id of the subscription |
| 5314 | * @param request contains the radio access networks with bands/channels to scan |
| 5315 | * @param messenger callback messenger for scan results or errors |
| 5316 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5317 | * @return the id of the requested scan which can be used to stop the scan. |
| 5318 | */ |
| 5319 | @Override |
| 5320 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5321 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5322 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5323 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5324 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5325 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5326 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5327 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5328 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5329 | .setCallingPid(Binder.getCallingPid()) |
| 5330 | .setCallingUid(Binder.getCallingUid()) |
| 5331 | .setMethod("requestNetworkScan") |
| 5332 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5333 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5334 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5335 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5336 | if (e != null) { |
| 5337 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5338 | throw e; |
| 5339 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5340 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5341 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5342 | } |
| 5343 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5344 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5345 | int callingUid = Binder.getCallingUid(); |
| 5346 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5347 | final long identity = Binder.clearCallingIdentity(); |
| 5348 | try { |
| 5349 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5350 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5351 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5352 | } finally { |
| 5353 | Binder.restoreCallingIdentity(identity); |
| 5354 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5355 | } |
| 5356 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5357 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5358 | NetworkScanRequest request, int subId) { |
| 5359 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5360 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5361 | boolean hasNetworkScanPermission = |
| 5362 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5363 | == PERMISSION_GRANTED; |
| 5364 | |
| 5365 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5366 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5367 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5368 | } |
| 5369 | |
| 5370 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5371 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5372 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5373 | return new SecurityException("Specific channels must not be" |
| 5374 | + " scanned without location access."); |
| 5375 | } |
| 5376 | } |
| 5377 | } |
| 5378 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5379 | return null; |
| 5380 | } |
| 5381 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5382 | /** |
| 5383 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5384 | * |
| 5385 | * @param subId id of the subscription |
| 5386 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5387 | */ |
| 5388 | @Override |
| 5389 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5390 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5391 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5392 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5393 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5394 | final long identity = Binder.clearCallingIdentity(); |
| 5395 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5396 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5397 | } finally { |
| 5398 | Binder.restoreCallingIdentity(identity); |
| 5399 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5400 | } |
| 5401 | |
| 5402 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5403 | * Get the calculated preferred network type. |
| 5404 | * Used for debugging incorrect network type. |
| 5405 | * |
| 5406 | * @return the preferred network type, defined in RILConstants.java. |
| 5407 | */ |
| 5408 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5409 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5410 | final Phone defaultPhone = getDefaultPhone(); |
| 5411 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5412 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5413 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5414 | } |
| 5415 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5416 | final long identity = Binder.clearCallingIdentity(); |
| 5417 | try { |
| 5418 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5419 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5420 | } finally { |
| 5421 | Binder.restoreCallingIdentity(identity); |
| 5422 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5423 | } |
| 5424 | |
| 5425 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5426 | * Get the preferred network type. |
| 5427 | * Used for device configuration by some CDMA operators. |
| 5428 | * |
| 5429 | * @return the preferred network type, defined in RILConstants.java. |
| 5430 | */ |
| 5431 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5432 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5433 | TelephonyPermissions |
| 5434 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5435 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5436 | |
| 5437 | final long identity = Binder.clearCallingIdentity(); |
| 5438 | try { |
| 5439 | if (DBG) log("getPreferredNetworkType"); |
| 5440 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5441 | int networkType = (result != null ? result[0] : -1); |
| 5442 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5443 | return networkType; |
| 5444 | } finally { |
| 5445 | Binder.restoreCallingIdentity(identity); |
| 5446 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5447 | } |
| 5448 | |
| 5449 | /** |
| 5450 | * Set the preferred network type. |
| 5451 | * Used for device configuration by some CDMA operators. |
| 5452 | * |
| 5453 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5454 | * @return true on success; false on any failure. |
| 5455 | */ |
| 5456 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5457 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5458 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5459 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5460 | |
| 5461 | final long identity = Binder.clearCallingIdentity(); |
| 5462 | try { |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5463 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5464 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5465 | return setPreferredNetworkTypesInternal(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5466 | } finally { |
| 5467 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5468 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5469 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5470 | |
| 5471 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5472 | * Get the allowed network types that store in the telephony provider. |
| 5473 | * |
| 5474 | * @param subId the id of the subscription. |
| 5475 | * @return allowedNetworkTypes the allowed network types. |
| 5476 | */ |
| 5477 | @Override |
| 5478 | public long getAllowedNetworkTypes(int subId) { |
| 5479 | TelephonyPermissions |
| 5480 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5481 | mApp, subId, "getAllowedNetworkTypes"); |
| 5482 | |
| 5483 | final long identity = Binder.clearCallingIdentity(); |
| 5484 | try { |
| 5485 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5486 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5487 | } finally { |
| 5488 | Binder.restoreCallingIdentity(identity); |
| 5489 | } |
| 5490 | } |
| 5491 | |
| 5492 | /** |
| 5493 | * Set the allowed network types. |
| 5494 | * |
| 5495 | * @param subId the id of the subscription. |
| 5496 | * @param allowedNetworkTypes the allowed network types. |
| 5497 | * @return true on success; false on any failure. |
| 5498 | */ |
| 5499 | @Override |
| 5500 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5501 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5502 | mApp, subId, "setAllowedNetworkTypes"); |
| 5503 | final long identity = Binder.clearCallingIdentity(); |
| 5504 | try { |
| 5505 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5506 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5507 | String.valueOf(allowedNetworkTypes)); |
| 5508 | return setPreferredNetworkTypesInternal(subId); |
| 5509 | } finally { |
| 5510 | Binder.restoreCallingIdentity(identity); |
| 5511 | } |
| 5512 | } |
| 5513 | |
| 5514 | private boolean setPreferredNetworkTypesInternal(int subId) { |
| 5515 | long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType( |
| 5516 | Settings.Global.getInt(mApp.getContentResolver(), |
| 5517 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5518 | RILConstants.PREFERRED_NETWORK_MODE)); |
| 5519 | long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty( |
| 5520 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5521 | int networkMode = RadioAccessFamily.getNetworkTypeFromRaf( |
| 5522 | (int) (networkTypeBitMask & allowedNetworkTypes)); |
| 5523 | |
| 5524 | if (DBG) { |
| 5525 | log("setPreferredNetworkTypesInternal: subId " + subId |
| 5526 | + " networkTypes " + networkTypeBitMask |
| 5527 | + " allowedNetworkTypes " + allowedNetworkTypes |
| 5528 | + " networkMode " + networkMode); |
| 5529 | } |
| 5530 | |
| 5531 | Boolean success = (Boolean) sendRequest( |
| 5532 | CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId); |
| 5533 | if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail")); |
| 5534 | return success; |
| 5535 | } |
| 5536 | |
| 5537 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5538 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5539 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5540 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5541 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5542 | * @hide |
| 5543 | */ |
| 5544 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5545 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5546 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5547 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5548 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5549 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5550 | if (phone != null) { |
| 5551 | return phone.hasMatchedTetherApnSetting(); |
| 5552 | } else { |
| 5553 | return false; |
| 5554 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5555 | } finally { |
| 5556 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5557 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5558 | } |
| 5559 | |
| 5560 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5561 | * Set mobile data enabled |
| 5562 | * Used by the user through settings etc to turn on/off mobile data |
| 5563 | * |
| 5564 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5565 | */ |
| 5566 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5567 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5568 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5569 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5570 | |
| 5571 | final long identity = Binder.clearCallingIdentity(); |
| 5572 | try { |
| 5573 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5574 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5575 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5576 | if (phone != null) { |
| 5577 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5578 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5579 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5580 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5581 | } |
| 5582 | } finally { |
| 5583 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5584 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5585 | } |
| 5586 | |
| 5587 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5588 | * Enable or disable always reporting signal strength changes from radio. |
| 5589 | * |
| 5590 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5591 | */ |
| 5592 | @Override |
| 5593 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5594 | enforceModifyPermission(); |
| 5595 | enforceSystemCaller(); |
| 5596 | |
| 5597 | final long identity = Binder.clearCallingIdentity(); |
| 5598 | final Phone phone = getPhone(subId); |
| 5599 | try { |
| 5600 | if (phone != null) { |
| 5601 | if (DBG) { |
| 5602 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5603 | + " isEnable=" + isEnable); |
| 5604 | } |
| 5605 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5606 | } else { |
| 5607 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5608 | + subId); |
| 5609 | } |
| 5610 | } finally { |
| 5611 | Binder.restoreCallingIdentity(identity); |
| 5612 | } |
| 5613 | } |
| 5614 | |
| 5615 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5616 | * Get the user enabled state of Mobile Data. |
| 5617 | * |
| 5618 | * TODO: remove and use isUserDataEnabled. |
| 5619 | * This can't be removed now because some vendor codes |
| 5620 | * calls through ITelephony directly while they should |
| 5621 | * use TelephonyManager. |
| 5622 | * |
| 5623 | * @return true on enabled |
| 5624 | */ |
| 5625 | @Override |
| 5626 | public boolean getDataEnabled(int subId) { |
| 5627 | return isUserDataEnabled(subId); |
| 5628 | } |
| 5629 | |
| 5630 | /** |
| 5631 | * Get whether mobile data is enabled per user setting. |
| 5632 | * |
| 5633 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5634 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5635 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5636 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5637 | * |
| 5638 | * @return {@code true} if data is enabled else {@code false} |
| 5639 | */ |
| 5640 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5641 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5642 | try { |
| 5643 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5644 | null); |
| 5645 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5646 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5647 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5648 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5649 | |
| 5650 | final long identity = Binder.clearCallingIdentity(); |
| 5651 | try { |
| 5652 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5653 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5654 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5655 | if (phone != null) { |
| 5656 | boolean retVal = phone.isUserDataEnabled(); |
| 5657 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5658 | return retVal; |
| 5659 | } else { |
| 5660 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5661 | return false; |
| 5662 | } |
| 5663 | } finally { |
| 5664 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5665 | } |
| 5666 | } |
| 5667 | |
| 5668 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5669 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5670 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5671 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5672 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5673 | * @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] | 5674 | */ |
| 5675 | @Override |
| 5676 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5677 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5678 | |
| 5679 | final long identity = Binder.clearCallingIdentity(); |
| 5680 | try { |
| 5681 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5682 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5683 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5684 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5685 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5686 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5687 | return retVal; |
| 5688 | } else { |
| 5689 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5690 | return false; |
| 5691 | } |
| 5692 | } finally { |
| 5693 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5694 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5695 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5696 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5697 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 5698 | Phone phone) { |
| 5699 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5700 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5701 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5702 | || subController == null) return privilegeFromSim; |
| 5703 | |
| 5704 | int uid = Binder.getCallingUid(); |
| 5705 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5706 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5707 | |
| 5708 | final long identity = Binder.clearCallingIdentity(); |
| 5709 | try { |
| 5710 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5711 | SubscriptionManager subManager = (SubscriptionManager) |
| 5712 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5713 | for (String pkg : packages) { |
| 5714 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5715 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5716 | } |
| 5717 | } |
| 5718 | return privilegeFromSim; |
| 5719 | } finally { |
| 5720 | Binder.restoreCallingIdentity(identity); |
| 5721 | } |
| 5722 | } |
| 5723 | |
| 5724 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5725 | String pkgName) { |
| 5726 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5727 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5728 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5729 | || subController == null) return privilegeFromSim; |
| 5730 | |
| 5731 | final long identity = Binder.clearCallingIdentity(); |
| 5732 | try { |
| 5733 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5734 | SubscriptionManager subManager = (SubscriptionManager) |
| 5735 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5736 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5737 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5738 | } finally { |
| 5739 | Binder.restoreCallingIdentity(identity); |
| 5740 | } |
| 5741 | } |
| 5742 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5743 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5744 | public int getCarrierPrivilegeStatus(int subId) { |
| 5745 | final Phone phone = getPhone(subId); |
| 5746 | if (phone == null) { |
| 5747 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5748 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5749 | } |
| 5750 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5751 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5752 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5753 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5754 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5755 | |
| 5756 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5757 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 5758 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5759 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5760 | |
| 5761 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5762 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5763 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5764 | final Phone phone = getPhone(subId); |
| 5765 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5766 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5767 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5768 | } |
| 5769 | UiccProfile profile = |
| 5770 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5771 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5772 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5773 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5774 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5775 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5776 | profile.getCarrierPrivilegeStatusForUid( |
| 5777 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5778 | } |
| 5779 | |
| 5780 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5781 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5782 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5783 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5784 | } |
| 5785 | |
| 5786 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5787 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5788 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5789 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5790 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5791 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5792 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5793 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5794 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5795 | } |
| 5796 | |
| 5797 | @Override |
| 5798 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5799 | if (TextUtils.isEmpty(pkgName)) |
| 5800 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5801 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5802 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5803 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5804 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5805 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5806 | continue; |
| 5807 | } |
| 5808 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5809 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5810 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5811 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5812 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5813 | break; |
| 5814 | } |
| 5815 | } |
| 5816 | |
| 5817 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5818 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5819 | |
| 5820 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5821 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5822 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5823 | loge("phoneId " + phoneId + " is not valid."); |
| 5824 | return null; |
| 5825 | } |
| 5826 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5827 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5828 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5829 | return null ; |
| 5830 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5831 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5832 | } |
| 5833 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5834 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5835 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5836 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5837 | List<String> privilegedPackages = new ArrayList<>(); |
| 5838 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5839 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5840 | // has UICC in that slot. |
| 5841 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5842 | if (card.hasCarrierPrivilegeRules()) { |
| 5843 | if (packages == null) { |
| 5844 | // Only check packages in user 0 for now |
| 5845 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5846 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5847 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5848 | | PackageManager.GET_SIGNING_CERTIFICATES, |
| 5849 | UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5850 | } |
| 5851 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5852 | PackageInfo pkgInfo = packages.get(p); |
| 5853 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5854 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5855 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5856 | privilegedPackages.add(pkgInfo.packageName); |
| 5857 | } |
| 5858 | } |
| 5859 | } |
| 5860 | } |
| 5861 | return privilegedPackages; |
| 5862 | } |
| 5863 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5864 | @Override |
| 5865 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5866 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5867 | |
| 5868 | final long identity = Binder.clearCallingIdentity(); |
| 5869 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5870 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5871 | try { |
| 5872 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5873 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5874 | } |
| 5875 | } finally { |
| 5876 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5877 | } |
| 5878 | return privilegedPackages; |
| 5879 | } |
| 5880 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5881 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5882 | final Phone phone = getPhone(subId); |
| 5883 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5884 | if (card == null) { |
| 5885 | loge("getIccId: No UICC"); |
| 5886 | return null; |
| 5887 | } |
| 5888 | String iccId = card.getIccId(); |
| 5889 | if (TextUtils.isEmpty(iccId)) { |
| 5890 | loge("getIccId: ICC ID is null or empty."); |
| 5891 | return null; |
| 5892 | } |
| 5893 | return iccId; |
| 5894 | } |
| 5895 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5896 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5897 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5898 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5899 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5900 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5901 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5902 | final long identity = Binder.clearCallingIdentity(); |
| 5903 | try { |
| 5904 | final String iccId = getIccId(subId); |
| 5905 | final Phone phone = getPhone(subId); |
| 5906 | if (phone == null) { |
| 5907 | return false; |
| 5908 | } |
| 5909 | final String subscriberId = phone.getSubscriberId(); |
| 5910 | |
| 5911 | if (DBG_MERGE) { |
| 5912 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 5913 | + subscriberId + " to " + number); |
| 5914 | } |
| 5915 | |
| 5916 | if (TextUtils.isEmpty(iccId)) { |
| 5917 | return false; |
| 5918 | } |
| 5919 | |
| 5920 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5921 | |
| 5922 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5923 | if (alphaTag == null) { |
| 5924 | editor.remove(alphaTagPrefKey); |
| 5925 | } else { |
| 5926 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5927 | } |
| 5928 | |
| 5929 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5930 | // track all merged IMSIs based on line number |
| 5931 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5932 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5933 | if (number == null) { |
| 5934 | editor.remove(numberPrefKey); |
| 5935 | editor.remove(subscriberPrefKey); |
| 5936 | } else { |
| 5937 | editor.putString(numberPrefKey, number); |
| 5938 | editor.putString(subscriberPrefKey, subscriberId); |
| 5939 | } |
| 5940 | |
| 5941 | editor.commit(); |
| 5942 | return true; |
| 5943 | } finally { |
| 5944 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5945 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5946 | } |
| 5947 | |
| 5948 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5949 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 5950 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5951 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5952 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5953 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5954 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5955 | return null; |
| 5956 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5957 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5958 | final long identity = Binder.clearCallingIdentity(); |
| 5959 | try { |
| 5960 | String iccId = getIccId(subId); |
| 5961 | if (iccId != null) { |
| 5962 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5963 | if (DBG_MERGE) { |
| 5964 | log("getLine1NumberForDisplay returning " |
| 5965 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5966 | } |
| 5967 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5968 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5969 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5970 | return null; |
| 5971 | } finally { |
| 5972 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5973 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5974 | } |
| 5975 | |
| 5976 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5977 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 5978 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5979 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5980 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5981 | return null; |
| 5982 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5983 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5984 | final long identity = Binder.clearCallingIdentity(); |
| 5985 | try { |
| 5986 | String iccId = getIccId(subId); |
| 5987 | if (iccId != null) { |
| 5988 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5989 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5990 | } |
| 5991 | return null; |
| 5992 | } finally { |
| 5993 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5994 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5995 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5996 | |
| 5997 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5998 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 5999 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6000 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6001 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6002 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6003 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6004 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6005 | return null; |
| 6006 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6007 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6008 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6009 | // the process, where TelephonyManager was instantiated. |
| 6010 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6011 | final long identity = Binder.clearCallingIdentity(); |
| 6012 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6013 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6014 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6015 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6016 | |
| 6017 | // Figure out what subscribers are currently active |
| 6018 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6019 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6020 | // Only consider subs which match the current subId |
| 6021 | // This logic can be simplified. See b/131189269 for progress. |
| 6022 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6023 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6024 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6025 | |
| 6026 | // First pass, find a number override for an active subscriber |
| 6027 | String mergeNumber = null; |
| 6028 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6029 | for (String key : prefs.keySet()) { |
| 6030 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6031 | final String subscriberId = (String) prefs.get(key); |
| 6032 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6033 | final String iccId = key.substring( |
| 6034 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6035 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6036 | mergeNumber = (String) prefs.get(numberKey); |
| 6037 | if (DBG_MERGE) { |
| 6038 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 6039 | + " for active subscriber " + subscriberId); |
| 6040 | } |
| 6041 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6042 | break; |
| 6043 | } |
| 6044 | } |
| 6045 | } |
| 6046 | } |
| 6047 | |
| 6048 | // Shortcut when no active merged subscribers |
| 6049 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6050 | return null; |
| 6051 | } |
| 6052 | |
| 6053 | // Second pass, find all subscribers under that line override |
| 6054 | final ArraySet<String> result = new ArraySet<>(); |
| 6055 | for (String key : prefs.keySet()) { |
| 6056 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6057 | final String number = (String) prefs.get(key); |
| 6058 | if (mergeNumber.equals(number)) { |
| 6059 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6060 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6061 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6062 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6063 | result.add(subscriberId); |
| 6064 | } |
| 6065 | } |
| 6066 | } |
| 6067 | } |
| 6068 | |
| 6069 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6070 | Arrays.sort(resultArray); |
| 6071 | if (DBG_MERGE) { |
| 6072 | Slog.d(LOG_TAG, |
| 6073 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6074 | } |
| 6075 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6076 | } finally { |
| 6077 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6078 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6079 | } |
| 6080 | |
| 6081 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6082 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 6083 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 6084 | |
| 6085 | final long identity = Binder.clearCallingIdentity(); |
| 6086 | try { |
| 6087 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6088 | TelephonyManager.class); |
| 6089 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6090 | if (subscriberId == null) { |
| 6091 | if (DBG) { |
| 6092 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 6093 | + subId); |
| 6094 | } |
| 6095 | return null; |
| 6096 | } |
| 6097 | |
| 6098 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6099 | .getSubscriptionInfo(subId); |
| 6100 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6101 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6102 | if (groupUuid == null) { |
| 6103 | return new String[]{subscriberId}; |
| 6104 | } |
| 6105 | |
| 6106 | // Get all subscriberIds from the group. |
| 6107 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6108 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6109 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 6110 | null); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6111 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6112 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6113 | if (subscriberId != null) { |
| 6114 | mergedSubscriberIds.add(subscriberId); |
| 6115 | } |
| 6116 | } |
| 6117 | |
| 6118 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6119 | } finally { |
| 6120 | Binder.restoreCallingIdentity(identity); |
| 6121 | |
| 6122 | } |
| 6123 | } |
| 6124 | |
| 6125 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6126 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6127 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6128 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6129 | |
| 6130 | final long identity = Binder.clearCallingIdentity(); |
| 6131 | try { |
| 6132 | final Phone phone = getPhone(subId); |
| 6133 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6134 | } finally { |
| 6135 | Binder.restoreCallingIdentity(identity); |
| 6136 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6137 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6138 | |
| 6139 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6140 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6141 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6142 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6143 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6144 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6145 | |
| 6146 | final long identity = Binder.clearCallingIdentity(); |
| 6147 | try { |
| 6148 | final Phone phone = getPhone(subId); |
| 6149 | if (phone == null) { |
| 6150 | return false; |
| 6151 | } |
| 6152 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6153 | cdmaNonRoamingList); |
| 6154 | } finally { |
| 6155 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6156 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6157 | } |
| 6158 | |
| 6159 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6160 | @Deprecated |
| 6161 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6162 | enforceModifyPermission(); |
| 6163 | |
| 6164 | int returnValue = 0; |
| 6165 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6166 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6167 | if(result.exception == null) { |
| 6168 | if (result.result != null) { |
| 6169 | byte[] responseData = (byte[])(result.result); |
| 6170 | if(responseData.length > oemResp.length) { |
| 6171 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6172 | responseData.length + "bytes. Buffer Size is " + |
| 6173 | oemResp.length + "bytes."); |
| 6174 | } |
| 6175 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6176 | returnValue = responseData.length; |
| 6177 | } |
| 6178 | } else { |
| 6179 | CommandException ex = (CommandException) result.exception; |
| 6180 | returnValue = ex.getCommandError().ordinal(); |
| 6181 | if(returnValue > 0) returnValue *= -1; |
| 6182 | } |
| 6183 | } catch (RuntimeException e) { |
| 6184 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6185 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6186 | if(returnValue > 0) returnValue *= -1; |
| 6187 | } |
| 6188 | |
| 6189 | return returnValue; |
| 6190 | } |
| 6191 | |
| 6192 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6193 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6194 | try { |
| 6195 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6196 | } catch (RuntimeException e) { |
| 6197 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6198 | } |
| 6199 | } |
| 6200 | |
| 6201 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6202 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6203 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6204 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6205 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6206 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6207 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6208 | final long identity = Binder.clearCallingIdentity(); |
| 6209 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6210 | TelephonyPermissions |
| 6211 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6212 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6213 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6214 | } finally { |
| 6215 | Binder.restoreCallingIdentity(identity); |
| 6216 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6217 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6218 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6219 | |
| 6220 | @Override |
| 6221 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6222 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6223 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6224 | |
| 6225 | final long identity = Binder.clearCallingIdentity(); |
| 6226 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6227 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6228 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6229 | } finally { |
| 6230 | Binder.restoreCallingIdentity(identity); |
| 6231 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6232 | } |
| 6233 | |
| 6234 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6235 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6236 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6237 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6238 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6239 | return false; |
| 6240 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6241 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6242 | final long identity = Binder.clearCallingIdentity(); |
| 6243 | try { |
| 6244 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6245 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6246 | // In the long run, we may instead need to check if there exists a connection service |
| 6247 | // which can support video calling. |
| 6248 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6249 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6250 | return imsManager.isVtEnabledByPlatform() |
| 6251 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6252 | && imsManager.isVtEnabledByUser(); |
| 6253 | } finally { |
| 6254 | Binder.restoreCallingIdentity(identity); |
| 6255 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6256 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6257 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6258 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6259 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6260 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6261 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6262 | mApp, subId, callingPackage, callingFeatureId, |
| 6263 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6264 | return false; |
| 6265 | } |
| 6266 | |
| 6267 | final long identity = Binder.clearCallingIdentity(); |
| 6268 | try { |
| 6269 | CarrierConfigManager configManager = |
| 6270 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6271 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6272 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6273 | } finally { |
| 6274 | Binder.restoreCallingIdentity(identity); |
| 6275 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6276 | } |
| 6277 | |
| 6278 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6279 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6280 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6281 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6282 | return false; |
| 6283 | } |
| 6284 | |
| 6285 | final long identity = Binder.clearCallingIdentity(); |
| 6286 | try { |
| 6287 | CarrierConfigManager configManager = |
| 6288 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6289 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6290 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6291 | } finally { |
| 6292 | Binder.restoreCallingIdentity(identity); |
| 6293 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6294 | } |
| 6295 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6296 | @Override |
| 6297 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6298 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6299 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6300 | } |
| 6301 | |
| 6302 | @Override |
| 6303 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6304 | final long identity = Binder.clearCallingIdentity(); |
| 6305 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6306 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6307 | } finally { |
| 6308 | Binder.restoreCallingIdentity(identity); |
| 6309 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6310 | } |
| 6311 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6312 | /** |
| 6313 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6314 | * support for the feature and device firmware support. |
| 6315 | * |
| 6316 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6317 | */ |
| 6318 | @Override |
| 6319 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6320 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6321 | final Phone phone = getPhone(subscriptionId); |
| 6322 | if (phone == null) { |
| 6323 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6324 | return false; |
| 6325 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6326 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6327 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6328 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6329 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6330 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6331 | return isCarrierSupported && isDeviceSupported; |
| 6332 | } finally { |
| 6333 | Binder.restoreCallingIdentity(identity); |
| 6334 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6335 | } |
| 6336 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6337 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6338 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6339 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6340 | * 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] | 6341 | */ |
| 6342 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6343 | final long identity = Binder.clearCallingIdentity(); |
| 6344 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6345 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6346 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6347 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6348 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6349 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6350 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6351 | } finally { |
| 6352 | Binder.restoreCallingIdentity(identity); |
| 6353 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6354 | } |
| 6355 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6356 | @Deprecated |
| 6357 | @Override |
| 6358 | public String getDeviceId(String callingPackage) { |
| 6359 | return getDeviceIdWithFeature(callingPackage, null); |
| 6360 | } |
| 6361 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6362 | /** |
| 6363 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6364 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6365 | * |
| 6366 | * <p>Requires Permission: |
| 6367 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6368 | */ |
| 6369 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6370 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6371 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6372 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6373 | return null; |
| 6374 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6375 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6376 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6377 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6378 | return null; |
| 6379 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6380 | |
| 6381 | final long identity = Binder.clearCallingIdentity(); |
| 6382 | try { |
| 6383 | return phone.getDeviceId(); |
| 6384 | } finally { |
| 6385 | Binder.restoreCallingIdentity(identity); |
| 6386 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6387 | } |
| 6388 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6389 | /** |
| 6390 | * {@hide} |
| 6391 | * Returns the IMS Registration Status on a particular subid |
| 6392 | * |
| 6393 | * @param subId |
| 6394 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6395 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6396 | Phone phone = getPhone(subId); |
| 6397 | if (phone != null) { |
| 6398 | return phone.isImsRegistered(); |
| 6399 | } else { |
| 6400 | return false; |
| 6401 | } |
| 6402 | } |
| 6403 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6404 | @Override |
| 6405 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6406 | final long identity = Binder.clearCallingIdentity(); |
| 6407 | try { |
| 6408 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6409 | } finally { |
| 6410 | Binder.restoreCallingIdentity(identity); |
| 6411 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6412 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6413 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6414 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6415 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6416 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6417 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6418 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6419 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6420 | } |
| 6421 | final long identity = Binder.clearCallingIdentity(); |
| 6422 | try { |
| 6423 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6424 | } finally { |
| 6425 | Binder.restoreCallingIdentity(identity); |
| 6426 | } |
| 6427 | } |
| 6428 | |
| 6429 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6430 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6431 | final long identity = Binder.clearCallingIdentity(); |
| 6432 | try { |
| 6433 | Phone phone = getPhone(subscriptionId); |
| 6434 | if (phone == null) { |
| 6435 | return null; |
| 6436 | } |
| 6437 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6438 | } finally { |
| 6439 | Binder.restoreCallingIdentity(identity); |
| 6440 | } |
| 6441 | } |
| 6442 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6443 | /** |
| 6444 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6445 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6446 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6447 | final long identity = Binder.clearCallingIdentity(); |
| 6448 | try { |
| 6449 | Phone phone = getPhone(subId); |
| 6450 | if (phone != null) { |
| 6451 | return phone.isWifiCallingEnabled(); |
| 6452 | } else { |
| 6453 | return false; |
| 6454 | } |
| 6455 | } finally { |
| 6456 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6457 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6458 | } |
| 6459 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6460 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6461 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6462 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6463 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6464 | final long identity = Binder.clearCallingIdentity(); |
| 6465 | try { |
| 6466 | Phone phone = getPhone(subId); |
| 6467 | if (phone != null) { |
| 6468 | return phone.isVideoEnabled(); |
| 6469 | } else { |
| 6470 | return false; |
| 6471 | } |
| 6472 | } finally { |
| 6473 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6474 | } |
| 6475 | } |
| 6476 | |
| 6477 | /** |
| 6478 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6479 | * defined in {@link ImsRegistrationImplBase}. |
| 6480 | */ |
| 6481 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6482 | final long identity = Binder.clearCallingIdentity(); |
| 6483 | try { |
| 6484 | Phone phone = getPhone(subId); |
| 6485 | if (phone != null) { |
| 6486 | return phone.getImsRegistrationTech(); |
| 6487 | } else { |
| 6488 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6489 | } |
| 6490 | } finally { |
| 6491 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6492 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6493 | } |
| 6494 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6495 | @Override |
| 6496 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6497 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6498 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6499 | return; |
| 6500 | } |
| 6501 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6502 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6503 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6504 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6505 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6506 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6507 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6508 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6509 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6510 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6511 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6512 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6513 | // There has been issues when Sms raw table somehow stores orphan |
| 6514 | // fragments. They lead to garbled message when new fragments come |
| 6515 | // in and combined with those stale ones. In case this happens again, |
| 6516 | // user can reset all network settings which will clean up this table. |
| 6517 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6518 | // Clean up IMS settings as well here. |
| 6519 | int slotId = getSlotIndex(subId); |
| 6520 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6521 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6522 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6523 | |
| 6524 | // Erase modem config if erase modem on network setting is enabled. |
| 6525 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6526 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6527 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6528 | sendEraseModemConfig(getDefaultPhone()); |
| 6529 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6530 | } finally { |
| 6531 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6532 | } |
| 6533 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6534 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6535 | private void cleanUpSmsRawTable(Context context) { |
| 6536 | ContentResolver resolver = context.getContentResolver(); |
| 6537 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6538 | resolver.delete(uri, null, null); |
| 6539 | } |
| 6540 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6541 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6542 | public String getSimLocaleForSubscriber(int subId) { |
| 6543 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6544 | final Phone phone = getPhone(subId); |
| 6545 | if (phone == null) { |
| 6546 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6547 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6548 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6549 | final long identity = Binder.clearCallingIdentity(); |
| 6550 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6551 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6552 | phone.getContext().getOpPackageName(), null); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6553 | if (info == null) { |
| 6554 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6555 | return null; |
| 6556 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6557 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6558 | // preferences (EF-PL and EF-LI)... |
| 6559 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6560 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6561 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6562 | if (localeFromDefaultSim != null) { |
| 6563 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6564 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6565 | + localeFromDefaultSim); |
| 6566 | return localeFromDefaultSim.toLanguageTag(); |
| 6567 | } else { |
| 6568 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6569 | } |
| 6570 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6571 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6572 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6573 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6574 | // the SIM and carrier preferences does not include a country we add the country |
| 6575 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6576 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6577 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6578 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6579 | return mccLocale.toLanguageTag(); |
| 6580 | } |
| 6581 | |
| 6582 | if (DBG) log("No locale found - returning null"); |
| 6583 | return null; |
| 6584 | } finally { |
| 6585 | Binder.restoreCallingIdentity(identity); |
| 6586 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6587 | } |
| 6588 | |
| 6589 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6590 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 6591 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6592 | } |
| 6593 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6594 | /** |
| 6595 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6596 | */ |
| 6597 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6598 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 6599 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6600 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6601 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6602 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6603 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6604 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6605 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6606 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6607 | * representing the state of the modem. |
| 6608 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6609 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6610 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6611 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6612 | */ |
| 6613 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6614 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6615 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6616 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6617 | |
| 6618 | final long identity = Binder.clearCallingIdentity(); |
| 6619 | try { |
| 6620 | ModemActivityInfo ret = null; |
| 6621 | synchronized (mLastModemActivityInfo) { |
| 6622 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 6623 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6624 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6625 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6626 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6627 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6628 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6629 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6630 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6631 | } |
| 6632 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6633 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 6634 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6635 | mLastModemActivityInfo.setIdleTimeMillis( |
| 6636 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6637 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 6638 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 6639 | info.getReceiveTimeMillis() + mLastModemActivityInfo |
| 6640 | .getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6641 | } |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6642 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6643 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 6644 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 6645 | mLastModemActivityInfo.getIdleTimeMillis(), |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6646 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 6647 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6648 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6649 | Bundle bundle = new Bundle(); |
| 6650 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 6651 | result.send(0, bundle); |
| 6652 | } finally { |
| 6653 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6654 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6655 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6656 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6657 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6658 | // less than total activity duration. |
| 6659 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6660 | if (info == null) { |
| 6661 | return false; |
| 6662 | } |
| 6663 | int activityDurationMs = |
| 6664 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6665 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6666 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6667 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6668 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6669 | } |
| 6670 | return (info.isValid() |
| 6671 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6672 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6673 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6674 | && (totalTxTimeMs <= activityDurationMs)); |
| 6675 | } |
| 6676 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6677 | /** |
| 6678 | * {@hide} |
| 6679 | * Returns the service state information on specified subscription. |
| 6680 | */ |
| 6681 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6682 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6683 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6684 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6685 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6686 | return null; |
| 6687 | } |
| 6688 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6689 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6690 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6691 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6692 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6693 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6694 | .setCallingPid(Binder.getCallingPid()) |
| 6695 | .setCallingUid(Binder.getCallingUid()) |
| 6696 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6697 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6698 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6699 | .build()); |
| 6700 | |
| 6701 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6702 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6703 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6704 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6705 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6706 | .setCallingPid(Binder.getCallingPid()) |
| 6707 | .setCallingUid(Binder.getCallingUid()) |
| 6708 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6709 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6710 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6711 | .build()); |
| 6712 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6713 | boolean hasFinePermission = |
| 6714 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6715 | boolean hasCoarsePermission = |
| 6716 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6717 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6718 | final long identity = Binder.clearCallingIdentity(); |
| 6719 | try { |
| 6720 | final Phone phone = getPhone(subId); |
| 6721 | if (phone == null) { |
| 6722 | return null; |
| 6723 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6724 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6725 | ServiceState ss = phone.getServiceState(); |
| 6726 | |
| 6727 | // Scrub out the location info in ServiceState depending on what level of access |
| 6728 | // the caller has. |
| 6729 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6730 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6731 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6732 | } finally { |
| 6733 | Binder.restoreCallingIdentity(identity); |
| 6734 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6735 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6736 | |
| 6737 | /** |
| 6738 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6739 | * |
| 6740 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6741 | * voicemail ringtone. |
| 6742 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6743 | * PhoneAccount. |
| 6744 | */ |
| 6745 | @Override |
| 6746 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6747 | final long identity = Binder.clearCallingIdentity(); |
| 6748 | try { |
| 6749 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6750 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6751 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6752 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6753 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6754 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6755 | } finally { |
| 6756 | Binder.restoreCallingIdentity(identity); |
| 6757 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6758 | } |
| 6759 | |
| 6760 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6761 | * Sets the per-account voicemail ringtone. |
| 6762 | * |
| 6763 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6764 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6765 | * |
| 6766 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6767 | * voicemail ringtone. |
| 6768 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6769 | * PhoneAccount. |
| 6770 | */ |
| 6771 | @Override |
| 6772 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6773 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6774 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6775 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6776 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6777 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6778 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6779 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6780 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6781 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6782 | |
| 6783 | final long identity = Binder.clearCallingIdentity(); |
| 6784 | try { |
| 6785 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6786 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6787 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6788 | } |
| 6789 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6790 | } finally { |
| 6791 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6792 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6793 | } |
| 6794 | |
| 6795 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6796 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6797 | * |
| 6798 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6799 | * voicemail vibration setting. |
| 6800 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6801 | */ |
| 6802 | @Override |
| 6803 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
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(accountHandle); |
| 6807 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6808 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6809 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6810 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6811 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6812 | } finally { |
| 6813 | Binder.restoreCallingIdentity(identity); |
| 6814 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6815 | } |
| 6816 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6817 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6818 | * Sets the per-account voicemail vibration. |
| 6819 | * |
| 6820 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6821 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6822 | * |
| 6823 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6824 | * voicemail vibration setting. |
| 6825 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6826 | * specific PhoneAccount. |
| 6827 | */ |
| 6828 | @Override |
| 6829 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6830 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6831 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6832 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6833 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6834 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6835 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6836 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6837 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6838 | } |
| 6839 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6840 | final long identity = Binder.clearCallingIdentity(); |
| 6841 | try { |
| 6842 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6843 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6844 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6845 | } |
| 6846 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6847 | } finally { |
| 6848 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6849 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6850 | } |
| 6851 | |
| 6852 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6853 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6854 | * |
| 6855 | * @throws SecurityException if the caller does not have the required permission |
| 6856 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6857 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6858 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6859 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6860 | } |
| 6861 | |
| 6862 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6863 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6864 | * permission. |
| 6865 | * |
| 6866 | * @throws SecurityException if the caller does not have the required permission |
| 6867 | */ |
| 6868 | private void enforceSendSmsPermission() { |
| 6869 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6870 | } |
| 6871 | |
| 6872 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6873 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6874 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6875 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6876 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6877 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6878 | final long identity = Binder.clearCallingIdentity(); |
| 6879 | try { |
| 6880 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6881 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6882 | if (componentName == null) { |
| 6883 | throw new SecurityException( |
| 6884 | "Caller not current active visual voicemail package[null]"); |
| 6885 | } |
| 6886 | String vvmPackage = componentName.getPackageName(); |
| 6887 | if (!callingPackage.equals(vvmPackage)) { |
| 6888 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6889 | + vvmPackage + "]"); |
| 6890 | } |
| 6891 | } finally { |
| 6892 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6893 | } |
| 6894 | } |
| 6895 | |
| 6896 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6897 | * Return the application ID for the app type. |
| 6898 | * |
| 6899 | * @param subId the subscription ID that this request applies to. |
| 6900 | * @param appType the uicc app type. |
| 6901 | * @return Application ID for specificied app type, or null if no uicc. |
| 6902 | */ |
| 6903 | @Override |
| 6904 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6905 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6906 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6907 | |
| 6908 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6909 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6910 | if (phone == null) { |
| 6911 | return null; |
| 6912 | } |
| 6913 | String aid = null; |
| 6914 | try { |
| 6915 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6916 | .getApplicationByType(appType).getAid(); |
| 6917 | } catch (Exception e) { |
| 6918 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6919 | } |
| 6920 | return aid; |
| 6921 | } finally { |
| 6922 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6923 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6924 | } |
| 6925 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6926 | /** |
| 6927 | * Return the Electronic Serial Number. |
| 6928 | * |
| 6929 | * @param subId the subscription ID that this request applies to. |
| 6930 | * @return ESN or null if error. |
| 6931 | */ |
| 6932 | @Override |
| 6933 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6934 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6935 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6936 | |
| 6937 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6938 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6939 | if (phone == null) { |
| 6940 | return null; |
| 6941 | } |
| 6942 | String esn = null; |
| 6943 | try { |
| 6944 | esn = phone.getEsn(); |
| 6945 | } catch (Exception e) { |
| 6946 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6947 | } |
| 6948 | return esn; |
| 6949 | } finally { |
| 6950 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6951 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6952 | } |
| 6953 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6954 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6955 | * Return the Preferred Roaming List Version. |
| 6956 | * |
| 6957 | * @param subId the subscription ID that this request applies to. |
| 6958 | * @return PRLVersion or null if error. |
| 6959 | */ |
| 6960 | @Override |
| 6961 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6962 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6963 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6964 | |
| 6965 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6966 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6967 | if (phone == null) { |
| 6968 | return null; |
| 6969 | } |
| 6970 | String cdmaPrlVersion = null; |
| 6971 | try { |
| 6972 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6973 | } catch (Exception e) { |
| 6974 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6975 | } |
| 6976 | return cdmaPrlVersion; |
| 6977 | } finally { |
| 6978 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6979 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6980 | } |
| 6981 | |
| 6982 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6983 | * Get snapshot of Telephony histograms |
| 6984 | * @return List of Telephony histograms |
| 6985 | * @hide |
| 6986 | */ |
| 6987 | @Override |
| 6988 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6989 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6990 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6991 | |
| 6992 | final long identity = Binder.clearCallingIdentity(); |
| 6993 | try { |
| 6994 | return RIL.getTelephonyRILTimingHistograms(); |
| 6995 | } finally { |
| 6996 | Binder.restoreCallingIdentity(identity); |
| 6997 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6998 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6999 | |
| 7000 | /** |
| 7001 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7002 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7003 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7004 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7005 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7006 | * @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] | 7007 | */ |
| 7008 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7009 | @TelephonyManager.SetCarrierRestrictionResult |
| 7010 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7011 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7012 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7013 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7014 | if (carrierRestrictionRules == null) { |
| 7015 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7016 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7017 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7018 | final long identity = Binder.clearCallingIdentity(); |
| 7019 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7020 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7021 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7022 | } finally { |
| 7023 | Binder.restoreCallingIdentity(identity); |
| 7024 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7025 | } |
| 7026 | |
| 7027 | /** |
| 7028 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7029 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7030 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7031 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7032 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7033 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7034 | */ |
| 7035 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7036 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7037 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7038 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7039 | |
| 7040 | final long identity = Binder.clearCallingIdentity(); |
| 7041 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7042 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7043 | if (response instanceof CarrierRestrictionRules) { |
| 7044 | return (CarrierRestrictionRules) response; |
| 7045 | } |
| 7046 | // Response is an Exception of some kind, |
| 7047 | // which is signalled to the user as a NULL retval |
| 7048 | return null; |
| 7049 | } catch (Exception e) { |
| 7050 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7051 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7052 | } finally { |
| 7053 | Binder.restoreCallingIdentity(identity); |
| 7054 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7055 | } |
| 7056 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7057 | /** |
| 7058 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 7059 | * @param subId the subscription ID that this action applies to. |
| 7060 | * @param enabled control enable or disable metered apns. |
| 7061 | * {@hide} |
| 7062 | */ |
| 7063 | @Override |
| 7064 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 7065 | enforceModifyPermission(); |
| 7066 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7067 | |
| 7068 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7069 | if (phone == null) { |
| 7070 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 7071 | return; |
| 7072 | } |
| 7073 | try { |
| 7074 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7075 | } catch (Exception e) { |
| 7076 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7077 | } finally { |
| 7078 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7079 | } |
| 7080 | } |
| 7081 | |
| 7082 | /** |
| 7083 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7084 | * @param subId the subscription ID that this action applies to. |
| 7085 | * @param enabled control enable or disable radio. |
| 7086 | * {@hide} |
| 7087 | */ |
| 7088 | @Override |
| 7089 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7090 | enforceModifyPermission(); |
| 7091 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7092 | |
| 7093 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7094 | if (phone == null) { |
| 7095 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7096 | return; |
| 7097 | } |
| 7098 | try { |
| 7099 | phone.carrierActionSetRadioEnabled(enabled); |
| 7100 | } catch (Exception e) { |
| 7101 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7102 | } finally { |
| 7103 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7104 | } |
| 7105 | } |
| 7106 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7107 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7108 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7109 | * network status based on which carrier apps could apply actions accordingly, |
| 7110 | * enable/disable default url handler for example. |
| 7111 | * |
| 7112 | * @param subId the subscription ID that this action applies to. |
| 7113 | * @param report control start/stop reporting the default network status. |
| 7114 | * {@hide} |
| 7115 | */ |
| 7116 | @Override |
| 7117 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7118 | enforceModifyPermission(); |
| 7119 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7120 | |
| 7121 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7122 | if (phone == null) { |
| 7123 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7124 | return; |
| 7125 | } |
| 7126 | try { |
| 7127 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7128 | } catch (Exception e) { |
| 7129 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7130 | } finally { |
| 7131 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7132 | } |
| 7133 | } |
| 7134 | |
| 7135 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7136 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7137 | * @param subId the subscription ID that this action applies to. |
| 7138 | * {@hide} |
| 7139 | */ |
| 7140 | @Override |
| 7141 | public void carrierActionResetAll(int subId) { |
| 7142 | enforceModifyPermission(); |
| 7143 | final Phone phone = getPhone(subId); |
| 7144 | if (phone == null) { |
| 7145 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7146 | return; |
| 7147 | } |
| 7148 | try { |
| 7149 | phone.carrierActionResetAll(); |
| 7150 | } catch (Exception e) { |
| 7151 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7152 | } |
| 7153 | } |
| 7154 | |
| 7155 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7156 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7157 | * bug report is being generated. |
| 7158 | */ |
| 7159 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7160 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7161 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7162 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7163 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7164 | + Binder.getCallingPid() |
| 7165 | + ", uid=" + Binder.getCallingUid() |
| 7166 | + "without permission " |
| 7167 | + android.Manifest.permission.DUMP); |
| 7168 | return; |
| 7169 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7170 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7171 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7172 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7173 | @Override |
| 7174 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 7175 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 7176 | throws RemoteException { |
Torbjorn Eklund | 1050cb0 | 2018-11-16 14:05:38 +0100 | [diff] [blame] | 7177 | (new TelephonyShellCommand(this, getDefaultPhone().getContext())) |
| 7178 | .exec(this, in, out, err, args, callback, resultReceiver); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7179 | } |
| 7180 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7181 | /** |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7182 | * Policy control of data connection. Usually used when data limit is passed. |
| 7183 | * @param enabled True if enabling the data, otherwise disabling. |
| 7184 | * @param subId Subscription index |
| 7185 | * {@hide} |
| 7186 | */ |
| 7187 | @Override |
| 7188 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 7189 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7190 | |
| 7191 | final long identity = Binder.clearCallingIdentity(); |
| 7192 | try { |
| 7193 | Phone phone = getPhone(subId); |
| 7194 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 7195 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7196 | } |
| 7197 | } finally { |
| 7198 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7199 | } |
| 7200 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7201 | |
| 7202 | /** |
| 7203 | * Get Client request stats |
| 7204 | * @return List of Client Request Stats |
| 7205 | * @hide |
| 7206 | */ |
| 7207 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7208 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7209 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7210 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7211 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7212 | return null; |
| 7213 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7214 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7215 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7216 | final long identity = Binder.clearCallingIdentity(); |
| 7217 | try { |
| 7218 | if (phone != null) { |
| 7219 | return phone.getClientRequestStats(); |
| 7220 | } |
| 7221 | |
| 7222 | return null; |
| 7223 | } finally { |
| 7224 | Binder.restoreCallingIdentity(identity); |
| 7225 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7226 | } |
| 7227 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7228 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7229 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7230 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7231 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7232 | |
| 7233 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7234 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7235 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7236 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7237 | * @param state State of SIM (power down, power up, pass through) |
| 7238 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7239 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7240 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7241 | * |
| 7242 | **/ |
| 7243 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7244 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7245 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7246 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7247 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7248 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7249 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7250 | final long identity = Binder.clearCallingIdentity(); |
| 7251 | try { |
| 7252 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7253 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7254 | } |
| 7255 | } finally { |
| 7256 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7257 | } |
| 7258 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7259 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7260 | private boolean isUssdApiAllowed(int subId) { |
| 7261 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7262 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7263 | if (configManager == null) { |
| 7264 | return false; |
| 7265 | } |
| 7266 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7267 | if (pb == null) { |
| 7268 | return false; |
| 7269 | } |
| 7270 | return pb.getBoolean( |
| 7271 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7272 | } |
| 7273 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7274 | /** |
| 7275 | * Check if phone is in emergency callback mode |
| 7276 | * @return true if phone is in emergency callback mode |
| 7277 | * @param subId sub id |
| 7278 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7279 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7280 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7281 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7282 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7283 | |
| 7284 | final long identity = Binder.clearCallingIdentity(); |
| 7285 | try { |
| 7286 | if (phone != null) { |
| 7287 | return phone.isInEcm(); |
| 7288 | } else { |
| 7289 | return false; |
| 7290 | } |
| 7291 | } finally { |
| 7292 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7293 | } |
| 7294 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7295 | |
| 7296 | /** |
| 7297 | * Get the current signal strength information for the given subscription. |
| 7298 | * Because this information is not updated when the device is in a low power state |
| 7299 | * it should not be relied-upon to be current. |
| 7300 | * @param subId Subscription index |
| 7301 | * @return the most recent cached signal strength info from the modem |
| 7302 | */ |
| 7303 | @Override |
| 7304 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7305 | final long identity = Binder.clearCallingIdentity(); |
| 7306 | try { |
| 7307 | Phone p = getPhone(subId); |
| 7308 | if (p == null) { |
| 7309 | return null; |
| 7310 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7311 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7312 | return p.getSignalStrength(); |
| 7313 | } finally { |
| 7314 | Binder.restoreCallingIdentity(identity); |
| 7315 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7316 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7317 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7318 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7319 | * Get the current modem radio state for the given slot. |
| 7320 | * @param slotIndex slot index. |
| 7321 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7322 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7323 | * @return the current radio power state from the modem |
| 7324 | */ |
| 7325 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7326 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7327 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7328 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7329 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7330 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7331 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7332 | } |
| 7333 | |
| 7334 | final long identity = Binder.clearCallingIdentity(); |
| 7335 | try { |
| 7336 | return phone.getRadioPowerState(); |
| 7337 | } finally { |
| 7338 | Binder.restoreCallingIdentity(identity); |
| 7339 | } |
| 7340 | } |
| 7341 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7342 | } |
| 7343 | |
| 7344 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7345 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7346 | * |
| 7347 | * <p>Requires one of the following permissions: |
| 7348 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7349 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7350 | * privileges. |
| 7351 | * |
| 7352 | * @param subId subscription id |
| 7353 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7354 | * {@code false}. |
| 7355 | */ |
| 7356 | @Override |
| 7357 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7358 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7359 | null /* message */); |
| 7360 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7361 | boolean isEnabled = false; |
| 7362 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7363 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7364 | Phone phone = getPhone(subId); |
| 7365 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7366 | } catch (Exception e) { |
| 7367 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7368 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7369 | } finally { |
| 7370 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7371 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7372 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7373 | } |
| 7374 | |
| 7375 | |
| 7376 | /** |
| 7377 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7378 | * |
| 7379 | * <p> Requires permission: |
| 7380 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7381 | * privileges. |
| 7382 | * |
| 7383 | * @param subId subscription id |
| 7384 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7385 | */ |
| 7386 | @Override |
| 7387 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7388 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7389 | mApp, subId, "setDataRoamingEnabled"); |
| 7390 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7391 | final long identity = Binder.clearCallingIdentity(); |
| 7392 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7393 | Phone phone = getPhone(subId); |
| 7394 | if (phone != null) { |
| 7395 | phone.setDataRoamingEnabled(isEnabled); |
| 7396 | } |
| 7397 | } finally { |
| 7398 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7399 | } |
| 7400 | } |
| 7401 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7402 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7403 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7404 | TelephonyPermissions |
| 7405 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7406 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7407 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7408 | boolean isAllowed = true; |
| 7409 | final long identity = Binder.clearCallingIdentity(); |
| 7410 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7411 | Phone phone = getPhone(subId); |
| 7412 | if (phone != null) { |
| 7413 | isAllowed = phone.isCspPlmnEnabled(); |
| 7414 | } |
| 7415 | } finally { |
| 7416 | Binder.restoreCallingIdentity(identity); |
| 7417 | } |
| 7418 | return isAllowed; |
| 7419 | } |
| 7420 | |
| 7421 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7422 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7423 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7424 | try { |
| 7425 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7426 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7427 | } catch (SecurityException e) { |
| 7428 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7429 | // has carrier privileges on an active UICC |
| 7430 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7431 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7432 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7433 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7434 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7435 | |
| 7436 | final long identity = Binder.clearCallingIdentity(); |
| 7437 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7438 | UiccController uiccController = UiccController.getInstance(); |
| 7439 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7440 | if (hasReadPermission) { |
| 7441 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7442 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7443 | |
| 7444 | // Remove private info if the caller doesn't have access |
| 7445 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7446 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7447 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7448 | // is available |
| 7449 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7450 | if (card == null || card.getUiccProfile() == null) { |
| 7451 | // assume no access if the card or profile is unavailable |
| 7452 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7453 | continue; |
| 7454 | } |
| 7455 | UiccProfile profile = card.getUiccProfile(); |
| 7456 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7457 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7458 | filteredInfos.add(cardInfo); |
| 7459 | } else { |
| 7460 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7461 | } |
| 7462 | } |
| 7463 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7464 | } finally { |
| 7465 | Binder.restoreCallingIdentity(identity); |
| 7466 | } |
| 7467 | } |
| 7468 | |
| 7469 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7470 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7471 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7472 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7473 | final long identity = Binder.clearCallingIdentity(); |
| 7474 | try { |
| 7475 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7476 | if (slots == null) { |
| 7477 | Rlog.i(LOG_TAG, "slots is null."); |
| 7478 | return null; |
| 7479 | } |
| 7480 | |
| 7481 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7482 | for (int i = 0; i < slots.length; i++) { |
| 7483 | UiccSlot slot = slots[i]; |
| 7484 | if (slot == null) { |
| 7485 | continue; |
| 7486 | } |
| 7487 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7488 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7489 | UiccCard card = slot.getUiccCard(); |
| 7490 | if (card != null) { |
| 7491 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7492 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7493 | cardId = slot.getEid(); |
| 7494 | if (TextUtils.isEmpty(cardId)) { |
| 7495 | cardId = slot.getIccId(); |
| 7496 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7497 | } |
| 7498 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7499 | if (cardId != null) { |
| 7500 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7501 | // if cardId is an EID, it's all digits so this is fine |
| 7502 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7503 | } |
| 7504 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7505 | int cardState = 0; |
| 7506 | switch (slot.getCardState()) { |
| 7507 | case CARDSTATE_ABSENT: |
| 7508 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7509 | break; |
| 7510 | case CARDSTATE_PRESENT: |
| 7511 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7512 | break; |
| 7513 | case CARDSTATE_ERROR: |
| 7514 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7515 | break; |
| 7516 | case CARDSTATE_RESTRICTED: |
| 7517 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7518 | break; |
| 7519 | default: |
| 7520 | break; |
| 7521 | |
| 7522 | } |
| 7523 | |
| 7524 | infos[i] = new UiccSlotInfo( |
| 7525 | slot.isActive(), |
| 7526 | slot.isEuicc(), |
| 7527 | cardId, |
| 7528 | cardState, |
| 7529 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7530 | slot.isExtendedApduSupported(), |
| 7531 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7532 | } |
| 7533 | return infos; |
| 7534 | } finally { |
| 7535 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7536 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7537 | } |
| 7538 | |
| 7539 | @Override |
| 7540 | public boolean switchSlots(int[] physicalSlots) { |
| 7541 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7542 | |
| 7543 | final long identity = Binder.clearCallingIdentity(); |
| 7544 | try { |
| 7545 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7546 | } finally { |
| 7547 | Binder.restoreCallingIdentity(identity); |
| 7548 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7549 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7550 | |
| 7551 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7552 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7553 | final long identity = Binder.clearCallingIdentity(); |
| 7554 | try { |
| 7555 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7556 | } finally { |
| 7557 | Binder.restoreCallingIdentity(identity); |
| 7558 | } |
| 7559 | } |
| 7560 | |
| 7561 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7562 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 7563 | enforceModifyPermission(); |
| 7564 | final Phone phone = getPhone(subId); |
| 7565 | if (phone == null) { |
| 7566 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 7567 | return; |
| 7568 | } |
| 7569 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7570 | final long identity = Binder.clearCallingIdentity(); |
| 7571 | try { |
| 7572 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 7573 | } finally { |
| 7574 | Binder.restoreCallingIdentity(identity); |
| 7575 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7576 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7577 | |
| 7578 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7579 | * A test API to reload the UICC profile. |
| 7580 | * |
| 7581 | * <p>Requires that the calling app has permission |
| 7582 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7583 | * @hide |
| 7584 | */ |
| 7585 | @Override |
| 7586 | public void refreshUiccProfile(int subId) { |
| 7587 | enforceModifyPermission(); |
| 7588 | |
| 7589 | final long identity = Binder.clearCallingIdentity(); |
| 7590 | try { |
| 7591 | Phone phone = getPhone(subId); |
| 7592 | if (phone == null) { |
| 7593 | return; |
| 7594 | } |
| 7595 | UiccCard uiccCard = phone.getUiccCard(); |
| 7596 | if (uiccCard == null) { |
| 7597 | return; |
| 7598 | } |
| 7599 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7600 | if (uiccProfile == null) { |
| 7601 | return; |
| 7602 | } |
| 7603 | uiccProfile.refresh(); |
| 7604 | } finally { |
| 7605 | Binder.restoreCallingIdentity(identity); |
| 7606 | } |
| 7607 | } |
| 7608 | |
| 7609 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7610 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7611 | */ |
| 7612 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7613 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7614 | } |
| 7615 | |
| 7616 | /** |
| 7617 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7618 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7619 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7620 | */ |
| 7621 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7622 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7623 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7624 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7625 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7626 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7627 | return isDataRoamingEnabled; |
| 7628 | } |
| 7629 | |
| 7630 | /** |
| 7631 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7632 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7633 | */ |
| 7634 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7635 | List<Integer> list = TelephonyProperties.default_network(); |
| 7636 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7637 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7638 | return list.get(phoneId); |
| 7639 | } |
| 7640 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7641 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7642 | |
| 7643 | @Override |
| 7644 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7645 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7646 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7647 | |
| 7648 | final long identity = Binder.clearCallingIdentity(); |
| 7649 | try { |
| 7650 | final Phone phone = getPhone(subId); |
| 7651 | if (phone == null) { |
| 7652 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7653 | return; |
| 7654 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7655 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7656 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7657 | } finally { |
| 7658 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7659 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7660 | } |
| 7661 | |
| 7662 | @Override |
| 7663 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7664 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7665 | |
| 7666 | final long identity = Binder.clearCallingIdentity(); |
| 7667 | try { |
| 7668 | final Phone phone = getPhone(subId); |
| 7669 | if (phone == null) { |
| 7670 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7671 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7672 | } |
| 7673 | return phone.getCarrierIdListVersion(); |
| 7674 | } finally { |
| 7675 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7676 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7677 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7678 | |
| 7679 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7680 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7681 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7682 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7683 | mApp, subId, callingPackage, callingFeatureId, |
| 7684 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7685 | return -1; |
| 7686 | } |
| 7687 | |
| 7688 | final long identity = Binder.clearCallingIdentity(); |
| 7689 | try { |
| 7690 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7691 | } finally { |
| 7692 | Binder.restoreCallingIdentity(identity); |
| 7693 | } |
| 7694 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7695 | |
| 7696 | @Override |
| 7697 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7698 | TelephonyPermissions |
| 7699 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7700 | mApp, subId, "getCdmaRoamingMode"); |
| 7701 | |
| 7702 | final long identity = Binder.clearCallingIdentity(); |
| 7703 | try { |
| 7704 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7705 | } finally { |
| 7706 | Binder.restoreCallingIdentity(identity); |
| 7707 | } |
| 7708 | } |
| 7709 | |
| 7710 | @Override |
| 7711 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7712 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7713 | mApp, subId, "setCdmaRoamingMode"); |
| 7714 | |
| 7715 | final long identity = Binder.clearCallingIdentity(); |
| 7716 | try { |
| 7717 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7718 | } finally { |
| 7719 | Binder.restoreCallingIdentity(identity); |
| 7720 | } |
| 7721 | } |
| 7722 | |
| 7723 | @Override |
| 7724 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7725 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7726 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7727 | |
| 7728 | final long identity = Binder.clearCallingIdentity(); |
| 7729 | try { |
| 7730 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7731 | } finally { |
| 7732 | Binder.restoreCallingIdentity(identity); |
| 7733 | } |
| 7734 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7735 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7736 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7737 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7738 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7739 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7740 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7741 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7742 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7743 | } |
| 7744 | final long identity = Binder.clearCallingIdentity(); |
| 7745 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7746 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7747 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7748 | if (phone.getEmergencyNumberTracker() != null |
| 7749 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7750 | emergencyNumberListInternal.put( |
| 7751 | phone.getSubId(), |
| 7752 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7753 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7754 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7755 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7756 | } finally { |
| 7757 | Binder.restoreCallingIdentity(identity); |
| 7758 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7759 | } |
| 7760 | |
| 7761 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7762 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7763 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7764 | if (!exactMatch) { |
| 7765 | TelephonyPermissions |
| 7766 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7767 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7768 | } |
| 7769 | final long identity = Binder.clearCallingIdentity(); |
| 7770 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7771 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7772 | if (phone.getEmergencyNumberTracker() != null |
| 7773 | && phone.getEmergencyNumberTracker() != null) { |
| 7774 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7775 | number, exactMatch)) { |
| 7776 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7777 | } |
| 7778 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7779 | } |
| 7780 | return false; |
| 7781 | } finally { |
| 7782 | Binder.restoreCallingIdentity(identity); |
| 7783 | } |
| 7784 | } |
| 7785 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7786 | /** |
| 7787 | * Update emergency number list for test mode. |
| 7788 | */ |
| 7789 | @Override |
| 7790 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7791 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7792 | "updateEmergencyNumberListTestMode"); |
| 7793 | |
| 7794 | final long identity = Binder.clearCallingIdentity(); |
| 7795 | try { |
| 7796 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7797 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7798 | if (tracker != null) { |
| 7799 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7800 | } |
| 7801 | } |
| 7802 | } finally { |
| 7803 | Binder.restoreCallingIdentity(identity); |
| 7804 | } |
| 7805 | } |
| 7806 | |
| 7807 | /** |
| 7808 | * Get the full emergency number list for test mode. |
| 7809 | */ |
| 7810 | @Override |
| 7811 | public List<String> getEmergencyNumberListTestMode() { |
| 7812 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7813 | "getEmergencyNumberListTestMode"); |
| 7814 | |
| 7815 | final long identity = Binder.clearCallingIdentity(); |
| 7816 | try { |
| 7817 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7818 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7819 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7820 | if (tracker != null) { |
| 7821 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7822 | emergencyNumbers.add(num.getNumber()); |
| 7823 | } |
| 7824 | } |
| 7825 | } |
| 7826 | return new ArrayList<>(emergencyNumbers); |
| 7827 | } finally { |
| 7828 | Binder.restoreCallingIdentity(identity); |
| 7829 | } |
| 7830 | } |
| 7831 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7832 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7833 | public int getEmergencyNumberDbVersion(int subId) { |
| 7834 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7835 | |
| 7836 | final long identity = Binder.clearCallingIdentity(); |
| 7837 | try { |
| 7838 | final Phone phone = getPhone(subId); |
| 7839 | if (phone == null) { |
| 7840 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7841 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7842 | } |
| 7843 | return phone.getEmergencyNumberDbVersion(); |
| 7844 | } finally { |
| 7845 | Binder.restoreCallingIdentity(identity); |
| 7846 | } |
| 7847 | } |
| 7848 | |
| 7849 | @Override |
| 7850 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7851 | enforceModifyPermission(); |
| 7852 | |
| 7853 | final long identity = Binder.clearCallingIdentity(); |
| 7854 | try { |
| 7855 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7856 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7857 | if (tracker != null) { |
| 7858 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7859 | } |
| 7860 | } |
| 7861 | } finally { |
| 7862 | Binder.restoreCallingIdentity(identity); |
| 7863 | } |
| 7864 | } |
| 7865 | |
| 7866 | @Override |
| 7867 | public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) { |
| 7868 | enforceActiveEmergencySessionPermission(); |
| 7869 | |
| 7870 | final long identity = Binder.clearCallingIdentity(); |
| 7871 | try { |
| 7872 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7873 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7874 | if (tracker != null) { |
| 7875 | tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath); |
| 7876 | } |
| 7877 | } |
| 7878 | } finally { |
| 7879 | Binder.restoreCallingIdentity(identity); |
| 7880 | } |
| 7881 | } |
| 7882 | |
| 7883 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7884 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7885 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7886 | Phone phone = getPhone(subId); |
| 7887 | if (phone == null) { |
| 7888 | return null; |
| 7889 | } |
| 7890 | final long identity = Binder.clearCallingIdentity(); |
| 7891 | try { |
| 7892 | UiccProfile profile = UiccController.getInstance() |
| 7893 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7894 | if (profile != null) { |
| 7895 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7896 | } |
| 7897 | } finally { |
| 7898 | Binder.restoreCallingIdentity(identity); |
| 7899 | } |
| 7900 | return null; |
| 7901 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7902 | |
| 7903 | /** |
| 7904 | * Enable or disable a modem stack. |
| 7905 | */ |
| 7906 | @Override |
| 7907 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7908 | enforceModifyPermission(); |
| 7909 | |
| 7910 | final long identity = Binder.clearCallingIdentity(); |
| 7911 | try { |
| 7912 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7913 | if (phone == null) { |
| 7914 | return false; |
| 7915 | } else { |
| 7916 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7917 | } |
| 7918 | } finally { |
| 7919 | Binder.restoreCallingIdentity(identity); |
| 7920 | } |
| 7921 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7922 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7923 | /** |
| 7924 | * Whether a modem stack is enabled or not. |
| 7925 | */ |
| 7926 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7927 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7928 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7929 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7930 | if (phone == null) return false; |
| 7931 | |
| 7932 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7933 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7934 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7935 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7936 | } |
| 7937 | |
| 7938 | final long identity = Binder.clearCallingIdentity(); |
| 7939 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7940 | try { |
| 7941 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7942 | } catch (NoSuchElementException ex) { |
| 7943 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7944 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7945 | } finally { |
| 7946 | Binder.restoreCallingIdentity(identity); |
| 7947 | } |
| 7948 | } |
| 7949 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7950 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7951 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7952 | enforceModifyPermission(); |
| 7953 | |
| 7954 | final long identity = Binder.clearCallingIdentity(); |
| 7955 | try { |
| 7956 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7957 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7958 | .commit(); |
| 7959 | } finally { |
| 7960 | Binder.restoreCallingIdentity(identity); |
| 7961 | } |
| 7962 | } |
| 7963 | |
| 7964 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7965 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7966 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7967 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7968 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 7969 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7970 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7971 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7972 | |
| 7973 | final long identity = Binder.clearCallingIdentity(); |
| 7974 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7975 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7976 | } finally { |
| 7977 | Binder.restoreCallingIdentity(identity); |
| 7978 | } |
| 7979 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7980 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7981 | @TelephonyManager.IsMultiSimSupportedResult |
| 7982 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7983 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7984 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7985 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7986 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7987 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7988 | } |
| 7989 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7990 | // supported by the modem, indicate that it is restricted. |
| 7991 | PhoneCapability staticCapability = |
| 7992 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7993 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7994 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7995 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7996 | } |
Sarah Chin | 5f0ecd7 | 2019-12-06 10:24:18 -0800 | [diff] [blame] | 7997 | if (staticCapability.getLogicalModemUuids().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7998 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7999 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8000 | } |
| 8001 | // Check if support of multiple SIMs is restricted by carrier |
| 8002 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8003 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8004 | } |
| 8005 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8006 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8007 | } |
| 8008 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8009 | /** |
| 8010 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8011 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8012 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8013 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8014 | * @param numOfSims number of active sims we want to switch to |
| 8015 | */ |
| 8016 | @Override |
| 8017 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8018 | if (numOfSims == 1) { |
| 8019 | enforceModifyPermission(); |
| 8020 | } else { |
| 8021 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8022 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8023 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8024 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8025 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8026 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8027 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8028 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8029 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8030 | return; |
| 8031 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8032 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8033 | } finally { |
| 8034 | Binder.restoreCallingIdentity(identity); |
| 8035 | } |
| 8036 | } |
| 8037 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8038 | @Override |
| 8039 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8040 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8041 | Phone phone = getPhone(subId); |
| 8042 | if (phone == null) { |
| 8043 | return false; |
| 8044 | } |
| 8045 | final long identity = Binder.clearCallingIdentity(); |
| 8046 | try { |
| 8047 | UiccCard uiccCard = phone.getUiccCard(); |
| 8048 | if (uiccCard == null) { |
| 8049 | return false; |
| 8050 | } |
| 8051 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8052 | if (uiccProfile == null) { |
| 8053 | return false; |
| 8054 | } |
| 8055 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8056 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8057 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8058 | } |
| 8059 | return false; |
| 8060 | } finally { |
| 8061 | Binder.restoreCallingIdentity(identity); |
| 8062 | } |
| 8063 | } |
| 8064 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8065 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8066 | * Get whether making changes to modem configurations will trigger reboot. |
| 8067 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8068 | */ |
| 8069 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8070 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8071 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8072 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8073 | mApp, subId, callingPackage, callingFeatureId, |
| 8074 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8075 | return false; |
| 8076 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8077 | final long identity = Binder.clearCallingIdentity(); |
| 8078 | try { |
| 8079 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8080 | } finally { |
| 8081 | Binder.restoreCallingIdentity(identity); |
| 8082 | } |
| 8083 | } |
| 8084 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8085 | private void updateModemStateMetrics() { |
| 8086 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8087 | // TODO: check the state for each modem if the api is ready. |
| 8088 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8089 | } |
| 8090 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8091 | @Override |
| 8092 | public int[] getSlotsMapping() { |
| 8093 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8094 | |
| 8095 | final long identity = Binder.clearCallingIdentity(); |
| 8096 | try { |
| 8097 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8098 | // All logical slots should have a mapping to a physical slot. |
| 8099 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8100 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8101 | for (int i = 0; i < slotInfos.length; i++) { |
| 8102 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8103 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8104 | } |
| 8105 | } |
| 8106 | return logicalSlotsMapping; |
| 8107 | } finally { |
| 8108 | Binder.restoreCallingIdentity(identity); |
| 8109 | } |
| 8110 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8111 | |
| 8112 | /** |
| 8113 | * Get the IRadio HAL Version |
| 8114 | */ |
| 8115 | @Override |
| 8116 | public int getRadioHalVersion() { |
| 8117 | Phone phone = getDefaultPhone(); |
| 8118 | if (phone == null) return -1; |
| 8119 | HalVersion hv = phone.getHalVersion(); |
| 8120 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8121 | return hv.major * 100 + hv.minor; |
| 8122 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8123 | |
| 8124 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8125 | * Get the current calling package name. |
| 8126 | * @return the current calling package name |
| 8127 | */ |
| 8128 | @Override |
| 8129 | public String getCurrentPackageName() { |
| 8130 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8131 | } |
| 8132 | |
| 8133 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8134 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8135 | * corresponding network requests on a subId. |
| 8136 | * |
| 8137 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8138 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8139 | * 2) APN is un-metered for this subscription, or |
| 8140 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8141 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8142 | * |
| 8143 | * @return whether data is allowed for a apn type. |
| 8144 | * |
| 8145 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8146 | */ |
| 8147 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8148 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8149 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8150 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8151 | |
| 8152 | // Now that all security checks passes, perform the operation as ourselves. |
| 8153 | final long identity = Binder.clearCallingIdentity(); |
| 8154 | try { |
| 8155 | Phone phone = getPhone(subId); |
| 8156 | if (phone == null) return false; |
| 8157 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8158 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8159 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8160 | } finally { |
| 8161 | Binder.restoreCallingIdentity(identity); |
| 8162 | } |
| 8163 | } |
| 8164 | |
| 8165 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8166 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8167 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8168 | |
| 8169 | // Now that all security checks passes, perform the operation as ourselves. |
| 8170 | final long identity = Binder.clearCallingIdentity(); |
| 8171 | try { |
| 8172 | Phone phone = getPhone(subId); |
| 8173 | if (phone == null) return true; // By default return true. |
| 8174 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8175 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8176 | } finally { |
| 8177 | Binder.restoreCallingIdentity(identity); |
| 8178 | } |
| 8179 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8180 | |
| 8181 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame^] | 8182 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8183 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8184 | enforceModifyPermission(); |
| 8185 | long token = Binder.clearCallingIdentity(); |
| 8186 | try { |
| 8187 | Phone phone = getPhone(subscriptionId); |
| 8188 | if (phone == null) { |
| 8189 | try { |
| 8190 | if (resultCallback != null) { |
| 8191 | resultCallback.accept(false); |
| 8192 | } |
| 8193 | } catch (RemoteException e) { |
| 8194 | // ignore |
| 8195 | } |
| 8196 | return; |
| 8197 | } |
| 8198 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8199 | Pair.create(specifiers, (x) -> { |
| 8200 | try { |
| 8201 | if (resultCallback != null) { |
| 8202 | resultCallback.accept(x); |
| 8203 | } |
| 8204 | } catch (RemoteException e) { |
| 8205 | // ignore |
| 8206 | } |
| 8207 | }); |
| 8208 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8209 | } finally { |
| 8210 | Binder.restoreCallingIdentity(token); |
| 8211 | } |
| 8212 | } |
| 8213 | |
| 8214 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8215 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
| 8216 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8217 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8218 | if (iccRecords == null) { |
| 8219 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8220 | return false; |
| 8221 | } |
| 8222 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8223 | } |
| 8224 | |
| 8225 | @Override |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8226 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8227 | if (callingPackage == null) { |
| 8228 | callingPackage = getCurrentPackageName(); |
| 8229 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8230 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8231 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 8232 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 8233 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8234 | } |
| 8235 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8236 | Intent intent = new Intent(); |
| 8237 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8238 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8239 | // Bring up choose default SMS subscription dialog right now |
| 8240 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8241 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8242 | mApp.startActivity(intent); |
| 8243 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8244 | |
| 8245 | @Override |
| 8246 | public String getMmsUAProfUrl(int subId) { |
| 8247 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8248 | final long identity = Binder.clearCallingIdentity(); |
| 8249 | try { |
| 8250 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8251 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 8252 | } finally { |
| 8253 | Binder.restoreCallingIdentity(identity); |
| 8254 | } |
| 8255 | } |
| 8256 | |
| 8257 | @Override |
| 8258 | public String getMmsUserAgent(int subId) { |
| 8259 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8260 | final long identity = Binder.clearCallingIdentity(); |
| 8261 | try { |
| 8262 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8263 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8264 | } finally { |
| 8265 | Binder.restoreCallingIdentity(identity); |
| 8266 | } |
| 8267 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8268 | |
| 8269 | @Override |
| 8270 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 8271 | enforceModifyPermission(); |
| 8272 | |
| 8273 | // Now that all security checks passes, perform the operation as ourselves. |
| 8274 | final long identity = Binder.clearCallingIdentity(); |
| 8275 | try { |
| 8276 | Phone phone = getPhone(subId); |
| 8277 | if (phone == null) return false; |
| 8278 | |
| 8279 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 8280 | } finally { |
| 8281 | Binder.restoreCallingIdentity(identity); |
| 8282 | } |
| 8283 | } |
| 8284 | |
| 8285 | @Override |
| 8286 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 8287 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 8288 | |
| 8289 | // Now that all security checks passes, perform the operation as ourselves. |
| 8290 | final long identity = Binder.clearCallingIdentity(); |
| 8291 | try { |
| 8292 | Phone phone = getPhone(subId); |
| 8293 | if (phone == null) return false; |
| 8294 | |
| 8295 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8296 | } finally { |
| 8297 | Binder.restoreCallingIdentity(identity); |
| 8298 | } |
| 8299 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8300 | |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8301 | @Override |
| 8302 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8303 | enforceModifyPermission(); |
| 8304 | |
| 8305 | // Now that all security checks passes, perform the operation as ourselves. |
| 8306 | final long identity = Binder.clearCallingIdentity(); |
| 8307 | try { |
| 8308 | Phone phone = getPhone(subId); |
| 8309 | if (phone == null) return false; |
| 8310 | |
| 8311 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8312 | } finally { |
| 8313 | Binder.restoreCallingIdentity(identity); |
| 8314 | } |
| 8315 | } |
| 8316 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8317 | /** |
| 8318 | * Updates whether conference event pacakge handling is enabled. |
| 8319 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8320 | * otherwise. |
| 8321 | */ |
| 8322 | @Override |
| 8323 | public void setCepEnabled(boolean isCepEnabled) { |
| 8324 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8325 | |
| 8326 | final long identity = Binder.clearCallingIdentity(); |
| 8327 | try { |
| 8328 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8329 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8330 | Phone defaultPhone = phone.getImsPhone(); |
| 8331 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8332 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8333 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8334 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8335 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8336 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8337 | + imsPhone.getMsisdn()); |
| 8338 | } |
| 8339 | } |
| 8340 | } finally { |
| 8341 | Binder.restoreCallingIdentity(identity); |
| 8342 | } |
| 8343 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8344 | |
| 8345 | /** |
| 8346 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8347 | * |
| 8348 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8349 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8350 | * before being read. |
| 8351 | */ |
| 8352 | @Override |
| 8353 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8354 | isCompressed) { |
| 8355 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8356 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8357 | try { |
| 8358 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8359 | if (configBinder == null) { |
| 8360 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8361 | } else { |
| 8362 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8363 | } |
| 8364 | } catch (RemoteException e) { |
| 8365 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8366 | } |
| 8367 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8368 | |
| 8369 | @Override |
| 8370 | public boolean isIccLockEnabled(int subId) { |
| 8371 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8372 | |
| 8373 | // Now that all security checks passes, perform the operation as ourselves. |
| 8374 | final long identity = Binder.clearCallingIdentity(); |
| 8375 | try { |
| 8376 | Phone phone = getPhone(subId); |
| 8377 | if (phone != null && phone.getIccCard() != null) { |
| 8378 | return phone.getIccCard().getIccLockEnabled(); |
| 8379 | } else { |
| 8380 | return false; |
| 8381 | } |
| 8382 | } finally { |
| 8383 | Binder.restoreCallingIdentity(identity); |
| 8384 | } |
| 8385 | } |
| 8386 | |
| 8387 | /** |
| 8388 | * Set the ICC pin lock enabled or disabled.. |
| 8389 | * |
| 8390 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8391 | * 0 or a positive integer as the attempts remaining value. |
| 8392 | * |
| 8393 | */ |
| 8394 | @Override |
| 8395 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8396 | enforceModifyPermission(); |
| 8397 | |
| 8398 | Phone phone = getPhone(subId); |
| 8399 | if (phone == null) { |
| 8400 | return 0; |
| 8401 | } |
| 8402 | // Now that all security checks passes, perform the operation as ourselves. |
| 8403 | final long identity = Binder.clearCallingIdentity(); |
| 8404 | try { |
| 8405 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8406 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8407 | return attemptsRemaining; |
| 8408 | |
| 8409 | } catch (Exception e) { |
| 8410 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8411 | } finally { |
| 8412 | Binder.restoreCallingIdentity(identity); |
| 8413 | } |
| 8414 | return 0; |
| 8415 | } |
| 8416 | |
| 8417 | /** |
| 8418 | * Change the ICC password used in ICC pin lock. |
| 8419 | * |
| 8420 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8421 | * 0 or a positive integer as the attempts remaining value. |
| 8422 | * |
| 8423 | */ |
| 8424 | @Override |
| 8425 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8426 | enforceModifyPermission(); |
| 8427 | |
| 8428 | Phone phone = getPhone(subId); |
| 8429 | if (phone == null) { |
| 8430 | return 0; |
| 8431 | } |
| 8432 | // Now that all security checks passes, perform the operation as ourselves. |
| 8433 | final long identity = Binder.clearCallingIdentity(); |
| 8434 | try { |
| 8435 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8436 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8437 | return attemptsRemaining; |
| 8438 | |
| 8439 | } catch (Exception e) { |
| 8440 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8441 | } finally { |
| 8442 | Binder.restoreCallingIdentity(identity); |
| 8443 | } |
| 8444 | return 0; |
| 8445 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8446 | } |