Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 22 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 23 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 24 | import android.Manifest.permission; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 25 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 30 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 33 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 34 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 35 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 48 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 49 | import android.os.PersistableBundle; |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 50 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 51 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 52 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.ServiceManager; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 55 | import android.os.ShellCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 57 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 58 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 59 | import android.preference.PreferenceManager; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 60 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 61 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 62 | import android.provider.Telephony; |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 63 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 65 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 66 | import android.telecom.TelecomManager; |
Chen Xu | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 67 | import android.telephony.Annotation.ApnType; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 68 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 69 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 70 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 71 | import android.telephony.CellIdentity; |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 72 | import android.telephony.CellIdentityCdma; |
| 73 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfoGsm; |
| 76 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 77 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 78 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 79 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 80 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 81 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 82 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 83 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 84 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 85 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 86 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 87 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 88 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 89 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 90 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 91 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 92 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 93 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 94 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 95 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 96 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 97 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 98 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 99 | import android.telephony.data.ApnSetting; |
| 100 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 101 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 102 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 103 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 108 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 109 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 110 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 111 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 112 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 113 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 114 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 115 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 116 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 117 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 118 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 119 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 120 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 121 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 122 | import com.android.ims.internal.IImsServiceFeatureCallback; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 123 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.HalVersion; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 158 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 160 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 170 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 172 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 173 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 174 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 175 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 176 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 177 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 178 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 179 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 180 | import java.io.FileDescriptor; |
| 181 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 182 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 183 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 184 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 185 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 186 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 187 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 188 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 189 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 190 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 191 | |
| 192 | /** |
| 193 | * Implementation of the ITelephony interface. |
| 194 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 195 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 196 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 197 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 198 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 199 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 200 | |
| 201 | // Message codes used with mMainThreadHandler |
| 202 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 203 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 204 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 205 | private static final int CMD_OPEN_CHANNEL = 9; |
| 206 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 207 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 208 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 209 | private static final int CMD_NV_READ_ITEM = 13; |
| 210 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 211 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 212 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 213 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 214 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 215 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 216 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 217 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 218 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 219 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 220 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 221 | private static final int CMD_SEND_ENVELOPE = 25; |
| 222 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 223 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 224 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 225 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 226 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 227 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 228 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 229 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 230 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 231 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 232 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 233 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 234 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 235 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 236 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 237 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 238 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 239 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 240 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 241 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 242 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 243 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 244 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 245 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 246 | private static final int CMD_SWITCH_SLOTS = 50; |
| 247 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 248 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 249 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 250 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 251 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 252 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 253 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 254 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 255 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 256 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 257 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 258 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 259 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 260 | private static final int CMD_MODEM_REBOOT = 64; |
| 261 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 262 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 263 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 264 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 265 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 266 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 267 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 268 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 269 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 270 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 271 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 272 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 273 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 274 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 275 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 276 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 277 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 278 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 279 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 280 | private static final int CMD_GET_CALL_WAITING = 87; |
| 281 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 282 | private static final int CMD_SET_CALL_WAITING = 89; |
| 283 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 284 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 285 | // Parameters of select command. |
| 286 | private static final int SELECT_COMMAND = 0xA4; |
| 287 | private static final int SELECT_P1 = 0x04; |
| 288 | private static final int SELECT_P2 = 0; |
| 289 | private static final int SELECT_P3 = 0x10; |
| 290 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 291 | /** The singleton instance. */ |
| 292 | private static PhoneInterfaceManager sInstance; |
| 293 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 294 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 295 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 296 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 297 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 298 | private AppOpsManager mAppOps; |
| 299 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 300 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 301 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 302 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 303 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 304 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 305 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 306 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 307 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 308 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 309 | // String to store multi SIM allowed |
| 310 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 311 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 312 | // The AID of ISD-R. |
| 313 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 314 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 315 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 316 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 317 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 318 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 319 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 320 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 321 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 322 | */ |
| 323 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 324 | "reset_network_erase_modem_config_enabled"; |
| 325 | |
| 326 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 327 | * A request object to use for transmitting data to an ICC. |
| 328 | */ |
| 329 | private static final class IccAPDUArgument { |
| 330 | public int channel, cla, command, p1, p2, p3; |
| 331 | public String data; |
| 332 | |
| 333 | public IccAPDUArgument(int channel, int cla, int command, |
| 334 | int p1, int p2, int p3, String data) { |
| 335 | this.channel = channel; |
| 336 | this.cla = cla; |
| 337 | this.command = command; |
| 338 | this.p1 = p1; |
| 339 | this.p2 = p2; |
| 340 | this.p3 = p3; |
| 341 | this.data = data; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 346 | * A request object to use for transmitting data to an ICC. |
| 347 | */ |
| 348 | private static final class ManualNetworkSelectionArgument { |
| 349 | public OperatorInfo operatorInfo; |
| 350 | public boolean persistSelection; |
| 351 | |
| 352 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 353 | this.operatorInfo = operatorInfo; |
| 354 | this.persistSelection = persistSelection; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 359 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 360 | * request after sending. The main thread will notify the request when it is complete. |
| 361 | */ |
| 362 | private static final class MainThreadRequest { |
| 363 | /** The argument to use for the request */ |
| 364 | public Object argument; |
| 365 | /** The result of the request that is run on the main thread */ |
| 366 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 367 | // The subscriber id that this request applies to. Defaults to |
| 368 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 369 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 370 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 371 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 372 | public Phone phone; |
| 373 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 374 | public WorkSource workSource; |
| 375 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 376 | public MainThreadRequest(Object argument) { |
| 377 | this.argument = argument; |
| 378 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 379 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 380 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 381 | this.argument = argument; |
| 382 | if (phone != null) { |
| 383 | this.phone = phone; |
| 384 | } |
| 385 | this.workSource = workSource; |
| 386 | } |
| 387 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 388 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 389 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 390 | if (subId != null) { |
| 391 | this.subId = subId; |
| 392 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 393 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 394 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 397 | private static final class IncomingThirdPartyCallArgs { |
| 398 | public final ComponentName component; |
| 399 | public final String callId; |
| 400 | public final String callerDisplayName; |
| 401 | |
| 402 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 403 | String callerDisplayName) { |
| 404 | this.component = component; |
| 405 | this.callId = callId; |
| 406 | this.callerDisplayName = callerDisplayName; |
| 407 | } |
| 408 | } |
| 409 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 410 | /** |
| 411 | * A handler that processes messages on the main thread in the phone process. Since many |
| 412 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 413 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 414 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 415 | * on, which will be notified when the operation completes and will contain the result of the |
| 416 | * request. |
| 417 | * |
| 418 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 419 | * note that request.result must be set to something non-null for the calling thread to |
| 420 | * unblock. |
| 421 | */ |
| 422 | private final class MainThreadHandler extends Handler { |
| 423 | @Override |
| 424 | public void handleMessage(Message msg) { |
| 425 | MainThreadRequest request; |
| 426 | Message onCompleted; |
| 427 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 428 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 429 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 430 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 431 | |
| 432 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 433 | case CMD_HANDLE_USSD_REQUEST: { |
| 434 | request = (MainThreadRequest) msg.obj; |
| 435 | final Phone phone = getPhoneFromRequest(request); |
| 436 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 437 | String ussdRequest = ussdObject.first; |
| 438 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 439 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 440 | if (!isUssdApiAllowed(request.subId)) { |
| 441 | // Carrier does not support use of this API, return failure. |
| 442 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 443 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 444 | Bundle returnData = new Bundle(); |
| 445 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 446 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 447 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 448 | request.result = true; |
| 449 | notifyRequester(request); |
| 450 | return; |
| 451 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 452 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 453 | try { |
| 454 | request.result = phone != null |
| 455 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 456 | } catch (CallStateException cse) { |
| 457 | request.result = false; |
| 458 | } |
| 459 | // Wake up the requesting thread |
| 460 | notifyRequester(request); |
| 461 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 464 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 465 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 466 | final Phone phone = getPhoneFromRequest(request); |
| 467 | request.result = phone != null ? |
| 468 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 469 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 470 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 471 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 472 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 473 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 474 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 475 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 476 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 477 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 478 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 479 | if (uiccCard == null) { |
| 480 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 481 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 482 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 483 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 484 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 485 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 486 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 487 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 488 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 489 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 490 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 491 | break; |
| 492 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 493 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 494 | ar = (AsyncResult) msg.obj; |
| 495 | request = (MainThreadRequest) ar.userObj; |
| 496 | if (ar.exception == null && ar.result != null) { |
| 497 | request.result = ar.result; |
| 498 | } else { |
| 499 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 500 | if (ar.result == null) { |
| 501 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 502 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 503 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 504 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 505 | } else { |
| 506 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 507 | } |
| 508 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 509 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 510 | break; |
| 511 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 512 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 513 | request = (MainThreadRequest) msg.obj; |
| 514 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 515 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 516 | if (uiccCard == null) { |
| 517 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 518 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 519 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 520 | } else { |
| 521 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 522 | request); |
| 523 | uiccCard.iccTransmitApduBasicChannel( |
| 524 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 525 | iccArgument.p3, iccArgument.data, onCompleted); |
| 526 | } |
| 527 | break; |
| 528 | |
| 529 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 530 | ar = (AsyncResult) msg.obj; |
| 531 | request = (MainThreadRequest) ar.userObj; |
| 532 | if (ar.exception == null && ar.result != null) { |
| 533 | request.result = ar.result; |
| 534 | } else { |
| 535 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 536 | if (ar.result == null) { |
| 537 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 538 | } else if (ar.exception instanceof CommandException) { |
| 539 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 540 | ar.exception); |
| 541 | } else { |
| 542 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 543 | } |
| 544 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 545 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 546 | break; |
| 547 | |
| 548 | case CMD_EXCHANGE_SIM_IO: |
| 549 | request = (MainThreadRequest) msg.obj; |
| 550 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 551 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 552 | if (uiccCard == null) { |
| 553 | loge("iccExchangeSimIO: No UICC"); |
| 554 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 555 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 556 | } else { |
| 557 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 558 | request); |
| 559 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 560 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 561 | iccArgument.data, onCompleted); |
| 562 | } |
| 563 | break; |
| 564 | |
| 565 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 566 | ar = (AsyncResult) msg.obj; |
| 567 | request = (MainThreadRequest) ar.userObj; |
| 568 | if (ar.exception == null && ar.result != null) { |
| 569 | request.result = ar.result; |
| 570 | } else { |
| 571 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 572 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 573 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 574 | break; |
| 575 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 576 | case CMD_SEND_ENVELOPE: |
| 577 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 578 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 579 | if (uiccCard == null) { |
| 580 | loge("sendEnvelopeWithStatus: No UICC"); |
| 581 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 582 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 583 | } else { |
| 584 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 585 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 586 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 587 | break; |
| 588 | |
| 589 | case EVENT_SEND_ENVELOPE_DONE: |
| 590 | ar = (AsyncResult) msg.obj; |
| 591 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 592 | if (ar.exception == null && ar.result != null) { |
| 593 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 594 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 595 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 596 | if (ar.result == null) { |
| 597 | loge("sendEnvelopeWithStatus: Empty response"); |
| 598 | } else if (ar.exception instanceof CommandException) { |
| 599 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 600 | ar.exception); |
| 601 | } else { |
| 602 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 603 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 604 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 605 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 606 | break; |
| 607 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 608 | case CMD_OPEN_CHANNEL: |
| 609 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 610 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 611 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 612 | if (uiccCard == null) { |
| 613 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 614 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 615 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 616 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 617 | } else { |
| 618 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 619 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 620 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 621 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 622 | break; |
| 623 | |
| 624 | case EVENT_OPEN_CHANNEL_DONE: |
| 625 | ar = (AsyncResult) msg.obj; |
| 626 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 627 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 628 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 629 | int[] result = (int[]) ar.result; |
| 630 | int channelId = result[0]; |
| 631 | byte[] selectResponse = null; |
| 632 | if (result.length > 1) { |
| 633 | selectResponse = new byte[result.length - 1]; |
| 634 | for (int i = 1; i < result.length; ++i) { |
| 635 | selectResponse[i - 1] = (byte) result[i]; |
| 636 | } |
| 637 | } |
| 638 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 639 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 640 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 641 | if (ar.result == null) { |
| 642 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 643 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 644 | if (ar.exception != null) { |
| 645 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 646 | } |
| 647 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 648 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 649 | if (ar.exception instanceof CommandException) { |
| 650 | CommandException.Error error = |
| 651 | ((CommandException) (ar.exception)).getCommandError(); |
| 652 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 653 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 654 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 655 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 659 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 660 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 661 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 662 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | break; |
| 664 | |
| 665 | case CMD_CLOSE_CHANNEL: |
| 666 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 667 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 668 | if (uiccCard == null) { |
| 669 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 670 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 671 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 672 | } else { |
| 673 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 674 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 675 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 676 | break; |
| 677 | |
| 678 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 679 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 680 | break; |
| 681 | |
| 682 | case CMD_NV_READ_ITEM: |
| 683 | request = (MainThreadRequest) msg.obj; |
| 684 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 685 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 686 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 687 | break; |
| 688 | |
| 689 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 690 | ar = (AsyncResult) msg.obj; |
| 691 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 692 | if (ar.exception == null && ar.result != null) { |
| 693 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 694 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 695 | request.result = ""; |
| 696 | if (ar.result == null) { |
| 697 | loge("nvReadItem: Empty response"); |
| 698 | } else if (ar.exception instanceof CommandException) { |
| 699 | loge("nvReadItem: CommandException: " + |
| 700 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 701 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 702 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 703 | } |
| 704 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 705 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 706 | break; |
| 707 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 708 | case CMD_NV_WRITE_ITEM: |
| 709 | request = (MainThreadRequest) msg.obj; |
| 710 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 711 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 712 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 713 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 714 | break; |
| 715 | |
| 716 | case EVENT_NV_WRITE_ITEM_DONE: |
| 717 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 718 | break; |
| 719 | |
| 720 | case CMD_NV_WRITE_CDMA_PRL: |
| 721 | request = (MainThreadRequest) msg.obj; |
| 722 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 723 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 724 | break; |
| 725 | |
| 726 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 727 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 728 | break; |
| 729 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 730 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 731 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 732 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 733 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 734 | break; |
| 735 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 736 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 737 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 738 | break; |
| 739 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 740 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 741 | request = (MainThreadRequest) msg.obj; |
| 742 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 743 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 744 | break; |
| 745 | |
| 746 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 747 | ar = (AsyncResult) msg.obj; |
| 748 | request = (MainThreadRequest) ar.userObj; |
| 749 | if (ar.exception == null && ar.result != null) { |
| 750 | request.result = ar.result; // Integer |
| 751 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 752 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 753 | if (ar.result == null) { |
| 754 | loge("getPreferredNetworkType: Empty response"); |
| 755 | } else if (ar.exception instanceof CommandException) { |
| 756 | loge("getPreferredNetworkType: CommandException: " + |
| 757 | ar.exception); |
| 758 | } else { |
| 759 | loge("getPreferredNetworkType: Unknown exception"); |
| 760 | } |
| 761 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 762 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 763 | break; |
| 764 | |
| 765 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 766 | request = (MainThreadRequest) msg.obj; |
| 767 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 768 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 769 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 770 | break; |
| 771 | |
| 772 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 773 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 774 | break; |
| 775 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 776 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 777 | request = (MainThreadRequest)msg.obj; |
| 778 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 779 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 780 | break; |
| 781 | |
| 782 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 783 | ar = (AsyncResult)msg.obj; |
| 784 | request = (MainThreadRequest)ar.userObj; |
| 785 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 786 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 787 | break; |
| 788 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 789 | case CMD_SET_VOICEMAIL_NUMBER: |
| 790 | request = (MainThreadRequest) msg.obj; |
| 791 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 792 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 793 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 794 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 795 | break; |
| 796 | |
| 797 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 798 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 799 | break; |
| 800 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 801 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 802 | request = (MainThreadRequest) msg.obj; |
| 803 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 804 | request); |
| 805 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 806 | break; |
| 807 | |
| 808 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 809 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 810 | break; |
| 811 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 812 | case CMD_PERFORM_NETWORK_SCAN: |
| 813 | request = (MainThreadRequest) msg.obj; |
| 814 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 815 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 816 | break; |
| 817 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 818 | case CMD_GET_CALL_FORWARDING: |
| 819 | request = (MainThreadRequest) msg.obj; |
| 820 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
| 821 | int callForwardingReason = (Integer) request.argument; |
| 822 | getPhoneFromRequest(request).getCallForwardingOption( |
| 823 | callForwardingReason, onCompleted); |
| 824 | break; |
| 825 | |
| 826 | case EVENT_GET_CALL_FORWARDING_DONE: |
| 827 | ar = (AsyncResult) msg.obj; |
| 828 | request = (MainThreadRequest) ar.userObj; |
| 829 | CallForwardingInfo callForwardingInfo = null; |
| 830 | if (ar.exception == null && ar.result != null) { |
| 831 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 832 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 833 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 834 | // any service for voice call. |
| 835 | if ((callForwardInfo.serviceClass |
| 836 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
| 837 | callForwardingInfo = new CallForwardingInfo( |
| 838 | callForwardInfo.serviceClass, callForwardInfo.reason, |
| 839 | callForwardInfo.number, |
| 840 | callForwardInfo.timeSeconds); |
| 841 | break; |
| 842 | } |
| 843 | } |
| 844 | // Didn't find a call forward info for voice call. |
| 845 | if (callForwardingInfo == null) { |
| 846 | callForwardingInfo = new CallForwardingInfo( |
| 847 | CallForwardingInfo.STATUS_UNKNOWN_ERROR, |
| 848 | 0 /* reason */, null /* number */, 0 /* timeout */); |
| 849 | } |
| 850 | } else { |
| 851 | if (ar.result == null) { |
| 852 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 853 | } |
| 854 | if (ar.exception != null) { |
| 855 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 856 | } |
| 857 | int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR; |
| 858 | if (ar.exception instanceof CommandException) { |
| 859 | CommandException.Error error = |
| 860 | ((CommandException) (ar.exception)).getCommandError(); |
| 861 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 862 | errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE; |
| 863 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 864 | errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED; |
| 865 | } |
| 866 | } |
| 867 | callForwardingInfo = new CallForwardingInfo( |
| 868 | errorCode, 0 /* reason */, null /* number */, 0 /* timeout */); |
| 869 | } |
| 870 | request.result = callForwardingInfo; |
| 871 | notifyRequester(request); |
| 872 | break; |
| 873 | |
| 874 | case CMD_SET_CALL_FORWARDING: |
| 875 | request = (MainThreadRequest) msg.obj; |
| 876 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
| 877 | CallForwardingInfo callForwardingInfoToSet = |
| 878 | (CallForwardingInfo) request.argument; |
| 879 | getPhoneFromRequest(request).setCallForwardingOption( |
| 880 | callForwardingInfoToSet.getStatus(), |
| 881 | callForwardingInfoToSet.getReason(), |
| 882 | callForwardingInfoToSet.getNumber(), |
| 883 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 884 | break; |
| 885 | |
| 886 | case EVENT_SET_CALL_FORWARDING_DONE: |
| 887 | ar = (AsyncResult) msg.obj; |
| 888 | request = (MainThreadRequest) ar.userObj; |
| 889 | if (ar.exception == null) { |
| 890 | request.result = true; |
| 891 | } else { |
| 892 | request.result = false; |
| 893 | loge("setCallForwarding exception: " + ar.exception); |
| 894 | } |
| 895 | notifyRequester(request); |
| 896 | break; |
| 897 | |
| 898 | case CMD_GET_CALL_WAITING: |
| 899 | request = (MainThreadRequest) msg.obj; |
| 900 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 901 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 902 | break; |
| 903 | |
| 904 | case EVENT_GET_CALL_WAITING_DONE: |
| 905 | ar = (AsyncResult) msg.obj; |
| 906 | request = (MainThreadRequest) ar.userObj; |
| 907 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 908 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 909 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 910 | // Service Class is a bit mask per 3gpp 27.007. |
| 911 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 912 | if (callForwardResults.length > 1 |
| 913 | && ((callForwardResults[1] |
| 914 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
| 915 | callForwardingStatus = callForwardResults[0] == 0 |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 916 | ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE |
| 917 | : TelephonyManager.CALL_WAITING_STATUS_ACTIVE; |
| 918 | } else { |
| 919 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE; |
| 920 | } |
| 921 | } else { |
| 922 | if (ar.result == null) { |
| 923 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 924 | } |
| 925 | if (ar.exception != null) { |
| 926 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 927 | } |
| 928 | if (ar.exception instanceof CommandException) { |
| 929 | CommandException.Error error = |
| 930 | ((CommandException) (ar.exception)).getCommandError(); |
| 931 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 932 | callForwardingStatus = |
| 933 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 934 | } |
| 935 | } |
| 936 | } |
| 937 | request.result = callForwardingStatus; |
| 938 | notifyRequester(request); |
| 939 | break; |
| 940 | |
| 941 | case CMD_SET_CALL_WAITING: |
| 942 | request = (MainThreadRequest) msg.obj; |
| 943 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
| 944 | boolean isEnable = (Boolean) request.argument; |
| 945 | getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted); |
| 946 | break; |
| 947 | |
| 948 | case EVENT_SET_CALL_WAITING_DONE: |
| 949 | ar = (AsyncResult) msg.obj; |
| 950 | request = (MainThreadRequest) ar.userObj; |
| 951 | if (ar.exception == null) { |
| 952 | request.result = true; |
| 953 | } else { |
| 954 | request.result = false; |
| 955 | loge("setCallWaiting exception: " + ar.exception); |
| 956 | } |
| 957 | notifyRequester(request); |
| 958 | break; |
| 959 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 960 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 961 | ar = (AsyncResult) msg.obj; |
| 962 | request = (MainThreadRequest) ar.userObj; |
| 963 | CellNetworkScanResult cellScanResult; |
| 964 | if (ar.exception == null && ar.result != null) { |
| 965 | cellScanResult = new CellNetworkScanResult( |
| 966 | CellNetworkScanResult.STATUS_SUCCESS, |
| 967 | (List<OperatorInfo>) ar.result); |
| 968 | } else { |
| 969 | if (ar.result == null) { |
| 970 | loge("getCellNetworkScanResults: Empty response"); |
| 971 | } |
| 972 | if (ar.exception != null) { |
| 973 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 974 | } |
| 975 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 976 | if (ar.exception instanceof CommandException) { |
| 977 | CommandException.Error error = |
| 978 | ((CommandException) (ar.exception)).getCommandError(); |
| 979 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 980 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 981 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 982 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 983 | } |
| 984 | } |
| 985 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 986 | } |
| 987 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 988 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 989 | break; |
| 990 | |
| 991 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 992 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 993 | ManualNetworkSelectionArgument selArg = |
| 994 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 995 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 996 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 997 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 998 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 999 | break; |
| 1000 | |
| 1001 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1002 | ar = (AsyncResult) msg.obj; |
| 1003 | request = (MainThreadRequest) ar.userObj; |
| 1004 | if (ar.exception == null) { |
| 1005 | request.result = true; |
| 1006 | } else { |
| 1007 | request.result = false; |
| 1008 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1009 | } |
| 1010 | notifyRequester(request); |
| 1011 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1012 | break; |
| 1013 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1014 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1015 | request = (MainThreadRequest) msg.obj; |
| 1016 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1017 | if (defaultPhone != null) { |
| 1018 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 1019 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1020 | break; |
| 1021 | |
| 1022 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1023 | ar = (AsyncResult) msg.obj; |
| 1024 | request = (MainThreadRequest) ar.userObj; |
| 1025 | if (ar.exception == null && ar.result != null) { |
| 1026 | request.result = ar.result; |
| 1027 | } else { |
| 1028 | if (ar.result == null) { |
| 1029 | loge("queryModemActivityInfo: Empty response"); |
| 1030 | } else if (ar.exception instanceof CommandException) { |
| 1031 | loge("queryModemActivityInfo: CommandException: " + |
| 1032 | ar.exception); |
| 1033 | } else { |
| 1034 | loge("queryModemActivityInfo: Unknown exception"); |
| 1035 | } |
| 1036 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 1037 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 1038 | if (request.result == null) { |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 1039 | request.result = new ModemActivityInfo(0, 0, 0, null, 0); |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 1040 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1041 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1042 | break; |
| 1043 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1044 | case CMD_SET_ALLOWED_CARRIERS: |
| 1045 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1046 | CarrierRestrictionRules argument = |
| 1047 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1048 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1049 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1050 | break; |
| 1051 | |
| 1052 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1053 | ar = (AsyncResult) msg.obj; |
| 1054 | request = (MainThreadRequest) ar.userObj; |
| 1055 | if (ar.exception == null && ar.result != null) { |
| 1056 | request.result = ar.result; |
| 1057 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1058 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1059 | if (ar.exception instanceof CommandException) { |
| 1060 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1061 | CommandException.Error error = |
| 1062 | ((CommandException) (ar.exception)).getCommandError(); |
| 1063 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1064 | request.result = |
| 1065 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1066 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1067 | } else { |
| 1068 | loge("setAllowedCarriers: Unknown exception"); |
| 1069 | } |
| 1070 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1071 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1072 | break; |
| 1073 | |
| 1074 | case CMD_GET_ALLOWED_CARRIERS: |
| 1075 | request = (MainThreadRequest) msg.obj; |
| 1076 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1077 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1078 | break; |
| 1079 | |
| 1080 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1081 | ar = (AsyncResult) msg.obj; |
| 1082 | request = (MainThreadRequest) ar.userObj; |
| 1083 | if (ar.exception == null && ar.result != null) { |
| 1084 | request.result = ar.result; |
| 1085 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1086 | request.result = new IllegalStateException( |
| 1087 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1088 | if (ar.result == null) { |
| 1089 | loge("getAllowedCarriers: Empty response"); |
| 1090 | } else if (ar.exception instanceof CommandException) { |
| 1091 | loge("getAllowedCarriers: CommandException: " + |
| 1092 | ar.exception); |
| 1093 | } else { |
| 1094 | loge("getAllowedCarriers: Unknown exception"); |
| 1095 | } |
| 1096 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1097 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1098 | break; |
| 1099 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1100 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1101 | ar = (AsyncResult) msg.obj; |
| 1102 | request = (MainThreadRequest) ar.userObj; |
| 1103 | if (ar.exception == null && ar.result != null) { |
| 1104 | request.result = ar.result; |
| 1105 | } else { |
| 1106 | request.result = new IllegalArgumentException( |
| 1107 | "Failed to retrieve Forbidden Plmns"); |
| 1108 | if (ar.result == null) { |
| 1109 | loge("getForbiddenPlmns: Empty response"); |
| 1110 | } else { |
| 1111 | loge("getForbiddenPlmns: Unknown exception"); |
| 1112 | } |
| 1113 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1114 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1115 | break; |
| 1116 | |
| 1117 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1118 | request = (MainThreadRequest) msg.obj; |
| 1119 | uiccCard = getUiccCardFromRequest(request); |
| 1120 | if (uiccCard == null) { |
| 1121 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1122 | request.result = new IllegalArgumentException( |
| 1123 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1124 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1125 | break; |
| 1126 | } |
| 1127 | Integer appType = (Integer) request.argument; |
| 1128 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1129 | if (uiccApp == null) { |
| 1130 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1131 | + appType); |
| 1132 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1133 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1134 | break; |
| 1135 | } else { |
| 1136 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1137 | + " specified type -- " + appType); |
| 1138 | } |
| 1139 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1140 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1141 | onCompleted); |
| 1142 | break; |
| 1143 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1144 | case CMD_SWITCH_SLOTS: |
| 1145 | request = (MainThreadRequest) msg.obj; |
| 1146 | int[] physicalSlots = (int[]) request.argument; |
| 1147 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1148 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1149 | break; |
| 1150 | |
| 1151 | case EVENT_SWITCH_SLOTS_DONE: |
| 1152 | ar = (AsyncResult) msg.obj; |
| 1153 | request = (MainThreadRequest) ar.userObj; |
| 1154 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1155 | notifyRequester(request); |
| 1156 | break; |
| 1157 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1158 | request = (MainThreadRequest) msg.obj; |
| 1159 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1160 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1161 | break; |
| 1162 | |
| 1163 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1164 | ar = (AsyncResult) msg.obj; |
| 1165 | request = (MainThreadRequest) ar.userObj; |
| 1166 | if (ar.exception != null) { |
| 1167 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1168 | } else { |
| 1169 | int mode = ((int[]) ar.result)[0]; |
| 1170 | if (mode == 0) { |
| 1171 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1172 | } else { |
| 1173 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1174 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1175 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1176 | notifyRequester(request); |
| 1177 | break; |
| 1178 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1179 | request = (MainThreadRequest) msg.obj; |
| 1180 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1181 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1182 | break; |
| 1183 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1184 | ar = (AsyncResult) msg.obj; |
| 1185 | request = (MainThreadRequest) ar.userObj; |
| 1186 | if (ar.exception != null) { |
| 1187 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1188 | } else { |
| 1189 | request.result = ((int[]) ar.result)[0]; |
| 1190 | } |
| 1191 | notifyRequester(request); |
| 1192 | break; |
| 1193 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1194 | request = (MainThreadRequest) msg.obj; |
| 1195 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1196 | int mode = (int) request.argument; |
| 1197 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1198 | break; |
| 1199 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1200 | ar = (AsyncResult) msg.obj; |
| 1201 | request = (MainThreadRequest) ar.userObj; |
| 1202 | request.result = ar.exception == null; |
| 1203 | notifyRequester(request); |
| 1204 | break; |
| 1205 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1206 | request = (MainThreadRequest) msg.obj; |
| 1207 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1208 | int subscriptionMode = (int) request.argument; |
| 1209 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1210 | break; |
| 1211 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1212 | ar = (AsyncResult) msg.obj; |
| 1213 | request = (MainThreadRequest) ar.userObj; |
| 1214 | request.result = ar.exception == null; |
| 1215 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1216 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1217 | case CMD_GET_ALL_CELL_INFO: |
| 1218 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1219 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1220 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1221 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1222 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1223 | ar = (AsyncResult) msg.obj; |
| 1224 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1225 | // If a timeout occurs, the response will be null |
| 1226 | request.result = (ar.exception == null && ar.result != null) |
| 1227 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1228 | synchronized (request) { |
| 1229 | request.notifyAll(); |
| 1230 | } |
| 1231 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1232 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1233 | request = (MainThreadRequest) msg.obj; |
| 1234 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1235 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1236 | break; |
| 1237 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1238 | ar = (AsyncResult) msg.obj; |
| 1239 | request = (MainThreadRequest) ar.userObj; |
| 1240 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1241 | try { |
| 1242 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1243 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1244 | cb.onError( |
| 1245 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1246 | ar.exception.getClass().getName(), |
| 1247 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1248 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1249 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1250 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1251 | } else { |
| 1252 | // use the result as returned |
| 1253 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1254 | } |
| 1255 | } catch (RemoteException re) { |
| 1256 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1257 | } |
| 1258 | break; |
| 1259 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1260 | request = (MainThreadRequest) msg.obj; |
| 1261 | WorkSource ws = (WorkSource) request.argument; |
| 1262 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1263 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1264 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1265 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1266 | ar = (AsyncResult) msg.obj; |
| 1267 | request = (MainThreadRequest) ar.userObj; |
| 1268 | if (ar.exception == null) { |
| 1269 | request.result = ar.result; |
| 1270 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1271 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1272 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1273 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | synchronized (request) { |
| 1277 | request.notifyAll(); |
| 1278 | } |
| 1279 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1280 | case CMD_MODEM_REBOOT: |
| 1281 | request = (MainThreadRequest) msg.obj; |
| 1282 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1283 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1284 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1285 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1286 | handleNullReturnEvent(msg, "rebootModem"); |
| 1287 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1288 | case CMD_REQUEST_ENABLE_MODEM: |
| 1289 | request = (MainThreadRequest) msg.obj; |
| 1290 | boolean enable = (boolean) request.argument; |
| 1291 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1292 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1293 | PhoneConfigurationManager.getInstance() |
| 1294 | .enablePhone(request.phone, enable, onCompleted); |
| 1295 | break; |
| 1296 | case EVENT_ENABLE_MODEM_DONE: |
| 1297 | ar = (AsyncResult) msg.obj; |
| 1298 | request = (MainThreadRequest) ar.userObj; |
| 1299 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1300 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1301 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1302 | if ((boolean) request.result) { |
| 1303 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1304 | updateModemStateMetrics(); |
| 1305 | } else { |
| 1306 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1307 | + ar.exception); |
| 1308 | } |
| 1309 | notifyRequester(request); |
| 1310 | break; |
| 1311 | case CMD_GET_MODEM_STATUS: |
| 1312 | request = (MainThreadRequest) msg.obj; |
| 1313 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1314 | PhoneConfigurationManager.getInstance() |
| 1315 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1316 | break; |
| 1317 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1318 | ar = (AsyncResult) msg.obj; |
| 1319 | request = (MainThreadRequest) ar.userObj; |
| 1320 | int id = request.phone.getPhoneId(); |
| 1321 | if (ar.exception == null && ar.result != null) { |
| 1322 | request.result = ar.result; |
| 1323 | //update the cache as modem status has changed |
| 1324 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1325 | (boolean) request.result); |
| 1326 | } else { |
| 1327 | // Return true if modem status cannot be retrieved. For most cases, |
| 1328 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1329 | // and disable modem are not supported. Modem is always on. |
| 1330 | // TODO: this should be fixed in R to support a third |
| 1331 | // status UNKNOWN b/131631629 |
| 1332 | request.result = true; |
| 1333 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1334 | + ar.exception); |
| 1335 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1336 | notifyRequester(request); |
| 1337 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1338 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1339 | ar = (AsyncResult) msg.obj; |
| 1340 | request = (MainThreadRequest) ar.userObj; |
| 1341 | if (ar.exception == null && ar.result != null) { |
| 1342 | request.result = ar.result; |
| 1343 | } else { |
| 1344 | request.result = -1; |
| 1345 | loge("Failed to set Forbidden Plmns"); |
| 1346 | if (ar.result == null) { |
| 1347 | loge("setForbidenPlmns: Empty response"); |
| 1348 | } else if (ar.exception != null) { |
| 1349 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1350 | request.result = -1; |
| 1351 | } else { |
| 1352 | loge("setForbiddenPlmns: Unknown exception"); |
| 1353 | } |
| 1354 | } |
| 1355 | notifyRequester(request); |
| 1356 | break; |
| 1357 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1358 | request = (MainThreadRequest) msg.obj; |
| 1359 | uiccCard = getUiccCardFromRequest(request); |
| 1360 | if (uiccCard == null) { |
| 1361 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1362 | request.result = -1; |
| 1363 | notifyRequester(request); |
| 1364 | break; |
| 1365 | } |
| 1366 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1367 | (Pair<Integer, List<String>>) request.argument; |
| 1368 | appType = setFplmnsArgs.first; |
| 1369 | List<String> fplmns = setFplmnsArgs.second; |
| 1370 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1371 | if (uiccApp == null) { |
| 1372 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1373 | request.result = -1; |
| 1374 | loge("Failed to get UICC App"); |
| 1375 | notifyRequester(request); |
| 1376 | } else { |
| 1377 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1378 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1379 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1380 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1381 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1382 | case CMD_ERASE_MODEM_CONFIG: |
| 1383 | request = (MainThreadRequest) msg.obj; |
| 1384 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1385 | defaultPhone.eraseModemConfig(onCompleted); |
| 1386 | break; |
| 1387 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1388 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1389 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1390 | |
| 1391 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1392 | request = (MainThreadRequest) msg.obj; |
| 1393 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1394 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1395 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1396 | changed.first, changed.second, onCompleted); |
| 1397 | break; |
| 1398 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1399 | ar = (AsyncResult) msg.obj; |
| 1400 | request = (MainThreadRequest) ar.userObj; |
| 1401 | if (ar.exception == null) { |
| 1402 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1403 | } else { |
| 1404 | request.result = msg.arg1; |
| 1405 | } |
| 1406 | notifyRequester(request); |
| 1407 | break; |
| 1408 | |
| 1409 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1410 | request = (MainThreadRequest) msg.obj; |
| 1411 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1412 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1413 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1414 | enabled.first, enabled.second, onCompleted); |
| 1415 | break; |
| 1416 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1417 | ar = (AsyncResult) msg.obj; |
| 1418 | request = (MainThreadRequest) ar.userObj; |
| 1419 | if (ar.exception == null) { |
| 1420 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1421 | } else { |
| 1422 | request.result = msg.arg1; |
| 1423 | } |
| 1424 | notifyRequester(request); |
| 1425 | break; |
| 1426 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1427 | default: |
| 1428 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1429 | break; |
| 1430 | } |
| 1431 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1432 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1433 | private void notifyRequester(MainThreadRequest request) { |
| 1434 | synchronized (request) { |
| 1435 | request.notifyAll(); |
| 1436 | } |
| 1437 | } |
| 1438 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1439 | private void handleNullReturnEvent(Message msg, String command) { |
| 1440 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1441 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1442 | if (ar.exception == null) { |
| 1443 | request.result = true; |
| 1444 | } else { |
| 1445 | request.result = false; |
| 1446 | if (ar.exception instanceof CommandException) { |
| 1447 | loge(command + ": CommandException: " + ar.exception); |
| 1448 | } else { |
| 1449 | loge(command + ": Unknown exception"); |
| 1450 | } |
| 1451 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1452 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1453 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | /** |
| 1457 | * Posts the specified command to be executed on the main thread, |
| 1458 | * waits for the request to complete, and returns the result. |
| 1459 | * @see #sendRequestAsync |
| 1460 | */ |
| 1461 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1462 | return sendRequest( |
| 1463 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | /** |
| 1467 | * Posts the specified command to be executed on the main thread, |
| 1468 | * waits for the request to complete, and returns the result. |
| 1469 | * @see #sendRequestAsync |
| 1470 | */ |
| 1471 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1472 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1473 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | /** |
| 1477 | * Posts the specified command to be executed on the main thread, |
| 1478 | * waits for the request to complete, and returns the result. |
| 1479 | * @see #sendRequestAsync |
| 1480 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1481 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1482 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | /** |
| 1486 | * Posts the specified command to be executed on the main thread, |
| 1487 | * waits for the request to complete, and returns the result. |
| 1488 | * @see #sendRequestAsync |
| 1489 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1490 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1491 | return sendRequest(command, argument, subId, null, workSource); |
| 1492 | } |
| 1493 | |
| 1494 | /** |
| 1495 | * Posts the specified command to be executed on the main thread, |
| 1496 | * waits for the request to complete, and returns the result. |
| 1497 | * @see #sendRequestAsync |
| 1498 | */ |
| 1499 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1500 | return sendRequest( |
| 1501 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1502 | } |
| 1503 | |
| 1504 | /** |
| 1505 | * Posts the specified command to be executed on the main thread, |
| 1506 | * waits for the request to complete, and returns the result. |
| 1507 | * @see #sendRequestAsync |
| 1508 | */ |
| 1509 | private Object sendRequest( |
| 1510 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1511 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1512 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1513 | } |
| 1514 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1515 | MainThreadRequest request = null; |
| 1516 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1517 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1518 | } else if (phone != null) { |
| 1519 | request = new MainThreadRequest(argument, phone, workSource); |
| 1520 | } else { |
| 1521 | request = new MainThreadRequest(argument, subId, workSource); |
| 1522 | } |
| 1523 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1524 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1525 | msg.sendToTarget(); |
| 1526 | |
| 1527 | // Wait for the request to complete |
| 1528 | synchronized (request) { |
| 1529 | while (request.result == null) { |
| 1530 | try { |
| 1531 | request.wait(); |
| 1532 | } catch (InterruptedException e) { |
| 1533 | // Do nothing, go back and wait until the request is complete |
| 1534 | } |
| 1535 | } |
| 1536 | } |
| 1537 | return request.result; |
| 1538 | } |
| 1539 | |
| 1540 | /** |
| 1541 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1542 | * Posts the specified command to be executed on the main thread, and |
| 1543 | * returns immediately. |
| 1544 | * @see #sendRequest |
| 1545 | */ |
| 1546 | private void sendRequestAsync(int command) { |
| 1547 | mMainThreadHandler.sendEmptyMessage(command); |
| 1548 | } |
| 1549 | |
| 1550 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1551 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1552 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1553 | */ |
| 1554 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1555 | sendRequestAsync(command, argument, null, null); |
| 1556 | } |
| 1557 | |
| 1558 | /** |
| 1559 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1560 | * @see {@link #sendRequest(int,Object)} |
| 1561 | */ |
| 1562 | private void sendRequestAsync( |
| 1563 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1564 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1565 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1566 | msg.sendToTarget(); |
| 1567 | } |
| 1568 | |
| 1569 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1570 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1571 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1572 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1573 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1574 | synchronized (PhoneInterfaceManager.class) { |
| 1575 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1576 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1577 | } else { |
| 1578 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1579 | } |
| 1580 | return sInstance; |
| 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1585 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1586 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1587 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1588 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1589 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1590 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1591 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1592 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1593 | mTelephonySharedPreferences = |
| 1594 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1595 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1596 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1597 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1598 | publish(); |
| 1599 | } |
| 1600 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1601 | private Phone getDefaultPhone() { |
| 1602 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1603 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1604 | } |
| 1605 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1606 | private void publish() { |
| 1607 | if (DBG) log("publish: " + this); |
| 1608 | |
| 1609 | ServiceManager.addService("phone", this); |
| 1610 | } |
| 1611 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1612 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1613 | if (request.phone != null) { |
| 1614 | return request.phone; |
| 1615 | } else { |
| 1616 | return getPhoneFromSubId(request.subId); |
| 1617 | } |
| 1618 | } |
| 1619 | |
| 1620 | private Phone getPhoneFromSubId(int subId) { |
| 1621 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1622 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1623 | } |
| 1624 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1625 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1626 | Phone phone = getPhoneFromRequest(request); |
| 1627 | return phone == null ? null : |
| 1628 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1629 | } |
| 1630 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1631 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1632 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1633 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1634 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1635 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1636 | private void sendEraseModemConfig(Phone phone) { |
| 1637 | if (phone != null) { |
| 1638 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1639 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1640 | final long identity = Binder.clearCallingIdentity(); |
| 1641 | try { |
| 1642 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1643 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1644 | } finally { |
| 1645 | Binder.restoreCallingIdentity(identity); |
| 1646 | } |
| 1647 | } |
| 1648 | } |
| 1649 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1650 | private boolean isImsAvailableOnDevice() { |
| 1651 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1652 | if (pm == null) { |
| 1653 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1654 | // so do not throw error and allow. |
| 1655 | return true; |
| 1656 | } |
| 1657 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1658 | } |
| 1659 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1660 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1661 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1662 | } |
| 1663 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1664 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1665 | if (DBG) log("dial: " + number); |
| 1666 | // No permission check needed here: This is just a wrapper around the |
| 1667 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1668 | // the UI before it does anything. |
| 1669 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1670 | final long identity = Binder.clearCallingIdentity(); |
| 1671 | try { |
| 1672 | String url = createTelUrl(number); |
| 1673 | if (url == null) { |
| 1674 | return; |
| 1675 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1676 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1677 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1678 | PhoneConstants.State state = mCM.getState(subId); |
| 1679 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1680 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1681 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1682 | mApp.startActivity(intent); |
| 1683 | } |
| 1684 | } finally { |
| 1685 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1686 | } |
| 1687 | } |
| 1688 | |
| 1689 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1690 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1693 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1694 | if (DBG) log("call: " + number); |
| 1695 | |
| 1696 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1697 | // need to do a permission check since we're calling startActivity() |
| 1698 | // from the context of the phone app. |
| 1699 | enforceCallPermission(); |
| 1700 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1701 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1702 | != AppOpsManager.MODE_ALLOWED) { |
| 1703 | return; |
| 1704 | } |
| 1705 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1706 | final long identity = Binder.clearCallingIdentity(); |
| 1707 | try { |
| 1708 | String url = createTelUrl(number); |
| 1709 | if (url == null) { |
| 1710 | return; |
| 1711 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1712 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1713 | boolean isValid = false; |
| 1714 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1715 | if (slist != null) { |
| 1716 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1717 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1718 | isValid = true; |
| 1719 | break; |
| 1720 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1721 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1722 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1723 | if (!isValid) { |
| 1724 | return; |
| 1725 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1726 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1727 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1728 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1729 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1730 | mApp.startActivity(intent); |
| 1731 | } finally { |
| 1732 | Binder.restoreCallingIdentity(identity); |
| 1733 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1736 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1737 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1738 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1739 | } |
| 1740 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1741 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1742 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1743 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1744 | } |
| 1745 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1746 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1747 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1748 | |
| 1749 | final long identity = Binder.clearCallingIdentity(); |
| 1750 | try { |
| 1751 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1752 | checkSimPin.start(); |
| 1753 | return checkSimPin.unlockSim(null, pin); |
| 1754 | } finally { |
| 1755 | Binder.restoreCallingIdentity(identity); |
| 1756 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1759 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1760 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1761 | |
| 1762 | final long identity = Binder.clearCallingIdentity(); |
| 1763 | try { |
| 1764 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1765 | checkSimPuk.start(); |
| 1766 | return checkSimPuk.unlockSim(puk, pin); |
| 1767 | } finally { |
| 1768 | Binder.restoreCallingIdentity(identity); |
| 1769 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1773 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1774 | * a synchronous one. |
| 1775 | */ |
| 1776 | private static class UnlockSim extends Thread { |
| 1777 | |
| 1778 | private final IccCard mSimCard; |
| 1779 | |
| 1780 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1781 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1782 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1783 | |
| 1784 | // For replies from SimCard interface |
| 1785 | private Handler mHandler; |
| 1786 | |
| 1787 | // For async handler to identify request type |
| 1788 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1789 | |
| 1790 | public UnlockSim(IccCard simCard) { |
| 1791 | mSimCard = simCard; |
| 1792 | } |
| 1793 | |
| 1794 | @Override |
| 1795 | public void run() { |
| 1796 | Looper.prepare(); |
| 1797 | synchronized (UnlockSim.this) { |
| 1798 | mHandler = new Handler() { |
| 1799 | @Override |
| 1800 | public void handleMessage(Message msg) { |
| 1801 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1802 | switch (msg.what) { |
| 1803 | case SUPPLY_PIN_COMPLETE: |
| 1804 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1805 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1806 | mRetryCount = msg.arg1; |
| 1807 | if (ar.exception != null) { |
| 1808 | if (ar.exception instanceof CommandException && |
| 1809 | ((CommandException)(ar.exception)).getCommandError() |
| 1810 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1811 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1812 | } else { |
| 1813 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1814 | } |
| 1815 | } else { |
| 1816 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1817 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1818 | mDone = true; |
| 1819 | UnlockSim.this.notifyAll(); |
| 1820 | } |
| 1821 | break; |
| 1822 | } |
| 1823 | } |
| 1824 | }; |
| 1825 | UnlockSim.this.notifyAll(); |
| 1826 | } |
| 1827 | Looper.loop(); |
| 1828 | } |
| 1829 | |
| 1830 | /* |
| 1831 | * Use PIN or PUK to unlock SIM card |
| 1832 | * |
| 1833 | * If PUK is null, unlock SIM card with PIN |
| 1834 | * |
| 1835 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1836 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1837 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1838 | |
| 1839 | while (mHandler == null) { |
| 1840 | try { |
| 1841 | wait(); |
| 1842 | } catch (InterruptedException e) { |
| 1843 | Thread.currentThread().interrupt(); |
| 1844 | } |
| 1845 | } |
| 1846 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1847 | |
| 1848 | if (puk == null) { |
| 1849 | mSimCard.supplyPin(pin, callback); |
| 1850 | } else { |
| 1851 | mSimCard.supplyPuk(puk, pin, callback); |
| 1852 | } |
| 1853 | |
| 1854 | while (!mDone) { |
| 1855 | try { |
| 1856 | Log.d(LOG_TAG, "wait for done"); |
| 1857 | wait(); |
| 1858 | } catch (InterruptedException e) { |
| 1859 | // Restore the interrupted status |
| 1860 | Thread.currentThread().interrupt(); |
| 1861 | } |
| 1862 | } |
| 1863 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1864 | int[] resultArray = new int[2]; |
| 1865 | resultArray[0] = mResult; |
| 1866 | resultArray[1] = mRetryCount; |
| 1867 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1868 | } |
| 1869 | } |
| 1870 | |
| 1871 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1872 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1873 | |
| 1874 | } |
| 1875 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1876 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1877 | // No permission check needed here: this call is harmless, and it's |
| 1878 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1879 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1880 | final long identity = Binder.clearCallingIdentity(); |
| 1881 | try { |
| 1882 | final Phone phone = getPhone(subId); |
| 1883 | if (phone != null) { |
| 1884 | phone.updateServiceLocation(); |
| 1885 | } |
| 1886 | } finally { |
| 1887 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1888 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1889 | } |
| 1890 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1891 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1892 | @Override |
| 1893 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1894 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1897 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1898 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1899 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1900 | callingFeatureId); |
| 1901 | } |
| 1902 | |
| 1903 | @Deprecated |
| 1904 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1905 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1906 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 1907 | } |
| 1908 | |
| 1909 | @Override |
| 1910 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1911 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1912 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1913 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1914 | return false; |
| 1915 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1916 | |
| 1917 | final long identity = Binder.clearCallingIdentity(); |
| 1918 | try { |
| 1919 | return isRadioOnForSubscriber(subId); |
| 1920 | } finally { |
| 1921 | Binder.restoreCallingIdentity(identity); |
| 1922 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1926 | final long identity = Binder.clearCallingIdentity(); |
| 1927 | try { |
| 1928 | final Phone phone = getPhone(subId); |
| 1929 | if (phone != null) { |
| 1930 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1931 | } else { |
| 1932 | return false; |
| 1933 | } |
| 1934 | } finally { |
| 1935 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1936 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1940 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1941 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1942 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1943 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1944 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1945 | |
| 1946 | final long identity = Binder.clearCallingIdentity(); |
| 1947 | try { |
| 1948 | final Phone phone = getPhone(subId); |
| 1949 | if (phone != null) { |
| 1950 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1951 | } |
| 1952 | } finally { |
| 1953 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1954 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1958 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1961 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1962 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1963 | |
| 1964 | final long identity = Binder.clearCallingIdentity(); |
| 1965 | try { |
| 1966 | final Phone phone = getPhone(subId); |
| 1967 | if (phone == null) { |
| 1968 | return false; |
| 1969 | } |
| 1970 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1971 | toggleRadioOnOffForSubscriber(subId); |
| 1972 | } |
| 1973 | return true; |
| 1974 | } finally { |
| 1975 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1976 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1977 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1978 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1979 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 1980 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1981 | /* |
| 1982 | * If any of the Radios are available, it will need to be |
| 1983 | * shutdown. So return true if any Radio is available. |
| 1984 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1985 | final long identity = Binder.clearCallingIdentity(); |
| 1986 | try { |
| 1987 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1988 | Phone phone = PhoneFactory.getPhone(i); |
| 1989 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1990 | } |
| 1991 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1992 | return false; |
| 1993 | } finally { |
| 1994 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1995 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1998 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1999 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2000 | enforceModifyPermission(); |
| 2001 | |
| 2002 | final long identity = Binder.clearCallingIdentity(); |
| 2003 | try { |
| 2004 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2005 | logv("Shutting down Phone " + i); |
| 2006 | shutdownRadioUsingPhoneId(i); |
| 2007 | } |
| 2008 | } finally { |
| 2009 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2010 | } |
| 2011 | } |
| 2012 | |
| 2013 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2014 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2015 | if (phone != null && phone.isRadioAvailable()) { |
| 2016 | phone.shutdownRadio(); |
| 2017 | } |
| 2018 | } |
| 2019 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2020 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2021 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2022 | |
| 2023 | final long identity = Binder.clearCallingIdentity(); |
| 2024 | try { |
| 2025 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2026 | if (defaultPhone != null) { |
| 2027 | defaultPhone.setRadioPower(turnOn); |
| 2028 | return true; |
| 2029 | } else { |
| 2030 | loge("There's no default phone."); |
| 2031 | return false; |
| 2032 | } |
| 2033 | } finally { |
| 2034 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2035 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2038 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2039 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2040 | |
| 2041 | final long identity = Binder.clearCallingIdentity(); |
| 2042 | try { |
| 2043 | final Phone phone = getPhone(subId); |
| 2044 | if (phone != null) { |
| 2045 | phone.setRadioPower(turnOn); |
| 2046 | return true; |
| 2047 | } else { |
| 2048 | return false; |
| 2049 | } |
| 2050 | } finally { |
| 2051 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2052 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2053 | } |
| 2054 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2055 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2056 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2057 | public boolean enableDataConnectivity() { |
| 2058 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2059 | |
| 2060 | final long identity = Binder.clearCallingIdentity(); |
| 2061 | try { |
| 2062 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2063 | final Phone phone = getPhone(subId); |
| 2064 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2065 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2066 | return true; |
| 2067 | } else { |
| 2068 | return false; |
| 2069 | } |
| 2070 | } finally { |
| 2071 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2072 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2073 | } |
| 2074 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2075 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2076 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2077 | public boolean disableDataConnectivity() { |
| 2078 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2079 | |
| 2080 | final long identity = Binder.clearCallingIdentity(); |
| 2081 | try { |
| 2082 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2083 | final Phone phone = getPhone(subId); |
| 2084 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2085 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2086 | return true; |
| 2087 | } else { |
| 2088 | return false; |
| 2089 | } |
| 2090 | } finally { |
| 2091 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2092 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2095 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2096 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2097 | final long identity = Binder.clearCallingIdentity(); |
| 2098 | try { |
| 2099 | final Phone phone = getPhone(subId); |
| 2100 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2101 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2102 | } else { |
| 2103 | return false; |
| 2104 | } |
| 2105 | } finally { |
| 2106 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2107 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
| 2110 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2111 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2114 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2115 | enforceCallPermission(); |
| 2116 | |
| 2117 | final long identity = Binder.clearCallingIdentity(); |
| 2118 | try { |
| 2119 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2120 | return; |
| 2121 | } |
| 2122 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2123 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2124 | } finally { |
| 2125 | Binder.restoreCallingIdentity(identity); |
| 2126 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2127 | }; |
| 2128 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2129 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2130 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2131 | |
| 2132 | final long identity = Binder.clearCallingIdentity(); |
| 2133 | try { |
| 2134 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2135 | return false; |
| 2136 | } |
| 2137 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2138 | } finally { |
| 2139 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2140 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2141 | } |
| 2142 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2143 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2144 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2145 | } |
| 2146 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2147 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2148 | final long identity = Binder.clearCallingIdentity(); |
| 2149 | try { |
| 2150 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2151 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2152 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2153 | } finally { |
| 2154 | Binder.restoreCallingIdentity(identity); |
| 2155 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2156 | } |
| 2157 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2158 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2159 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2160 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2161 | } |
| 2162 | |
| 2163 | @Override |
| 2164 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2165 | final long identity = Binder.clearCallingIdentity(); |
| 2166 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2167 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2168 | if (phone != null) { |
| 2169 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2170 | } else { |
| 2171 | return PhoneConstantConversions.convertDataState( |
| 2172 | PhoneConstants.DataState.DISCONNECTED); |
| 2173 | } |
| 2174 | } finally { |
| 2175 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2176 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2177 | } |
| 2178 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2179 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2180 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2181 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2182 | } |
| 2183 | |
| 2184 | @Override |
| 2185 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2186 | final long identity = Binder.clearCallingIdentity(); |
| 2187 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2188 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2189 | if (phone != null) { |
| 2190 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2191 | } else { |
| 2192 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2193 | } |
| 2194 | } finally { |
| 2195 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2196 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2200 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2201 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2202 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2203 | |
| 2204 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2205 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2206 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2207 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2208 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2209 | .setCallingPid(Binder.getCallingPid()) |
| 2210 | .setCallingUid(Binder.getCallingUid()) |
| 2211 | .setMethod("getCellLocation") |
| 2212 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2213 | .build()); |
| 2214 | switch (locationResult) { |
| 2215 | case DENIED_HARD: |
| 2216 | throw new SecurityException("Not allowed to access cell location"); |
| 2217 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2218 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2219 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2220 | } |
| 2221 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2222 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2223 | final long identity = Binder.clearCallingIdentity(); |
| 2224 | try { |
| 2225 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2226 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2227 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2228 | } finally { |
| 2229 | Binder.restoreCallingIdentity(identity); |
| 2230 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2231 | } |
| 2232 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2233 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2234 | public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage, |
| 2235 | String callingFeatureId) { |
Jack Yu | 7c5d91a | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2236 | if (!TextUtils.isEmpty(callingPackage)) { |
| 2237 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2238 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2239 | callingFeatureId, "getNetworkCountryIsoForPhone")) { |
Jack Yu | 7c5d91a | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2240 | return ""; |
| 2241 | } |
| 2242 | } |
| 2243 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2244 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2245 | // registered cell info, so return a NULL country instead. |
| 2246 | final long identity = Binder.clearCallingIdentity(); |
| 2247 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2248 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2249 | // Get default phone in this case. |
| 2250 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2251 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2252 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2253 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2254 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2255 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2256 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(), |
| 2257 | null)) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2258 | return ""; |
| 2259 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2260 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2261 | if (phone != null) { |
| 2262 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2263 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2264 | if (sst != null) { |
| 2265 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2266 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2267 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2268 | return lt.getCurrentCountry(); |
| 2269 | } else if (emergencyNumberTracker != null) { |
| 2270 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2271 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2272 | } |
| 2273 | } |
| 2274 | } |
| 2275 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2276 | } finally { |
| 2277 | Binder.restoreCallingIdentity(identity); |
| 2278 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2282 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2283 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2286 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2287 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2288 | mApp.enforceCallingOrSelfPermission( |
| 2289 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2290 | |
| 2291 | final long identity = Binder.clearCallingIdentity(); |
| 2292 | try { |
| 2293 | final Phone phone = getPhone(subId); |
| 2294 | if (phone != null) { |
| 2295 | phone.enableLocationUpdates(); |
| 2296 | } |
| 2297 | } finally { |
| 2298 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2299 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | @Override |
| 2303 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2304 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2307 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2308 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2309 | mApp.enforceCallingOrSelfPermission( |
| 2310 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2311 | |
| 2312 | final long identity = Binder.clearCallingIdentity(); |
| 2313 | try { |
| 2314 | final Phone phone = getPhone(subId); |
| 2315 | if (phone != null) { |
| 2316 | phone.disableLocationUpdates(); |
| 2317 | } |
| 2318 | } finally { |
| 2319 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2320 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2321 | } |
| 2322 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2323 | /** |
| 2324 | * Returns the target SDK version number for a given package name. |
| 2325 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2326 | * This call MUST be invoked before clearing the calling UID. |
| 2327 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2328 | * @return target SDK if the package is found or INT_MAX. |
| 2329 | */ |
| 2330 | private int getTargetSdk(String packageName) { |
| 2331 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2332 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2333 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2334 | if (ai != null) return ai.targetSdkVersion; |
| 2335 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2336 | loge("Failed to get package info for pkg=" |
| 2337 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2338 | } |
| 2339 | return Integer.MAX_VALUE; |
| 2340 | } |
| 2341 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2342 | @Override |
| 2343 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2344 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2345 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2346 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2347 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2348 | throw new SecurityException( |
| 2349 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2350 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2351 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2352 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2353 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2354 | return null; |
| 2355 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2356 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2357 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2358 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2359 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2360 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2361 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2362 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2363 | for (CellInfo ci : info) { |
| 2364 | if (ci instanceof CellInfoGsm) { |
| 2365 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2366 | } else if (ci instanceof CellInfoWcdma) { |
| 2367 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2368 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2369 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2370 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2371 | } |
| 2372 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2373 | private List<CellInfo> getCachedCellInfo() { |
| 2374 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2375 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2376 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2377 | if (info != null) cellInfos.addAll(info); |
| 2378 | } |
| 2379 | return cellInfos; |
| 2380 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2381 | |
| 2382 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2383 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2384 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2385 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2386 | |
| 2387 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2388 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2389 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2390 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2391 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2392 | .setCallingPid(Binder.getCallingPid()) |
| 2393 | .setCallingUid(Binder.getCallingUid()) |
| 2394 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2395 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2396 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2397 | .build()); |
| 2398 | switch (locationResult) { |
| 2399 | case DENIED_HARD: |
| 2400 | throw new SecurityException("Not allowed to access cell info"); |
| 2401 | case DENIED_SOFT: |
| 2402 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2403 | } |
| 2404 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2405 | final int targetSdk = getTargetSdk(callingPackage); |
| 2406 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2407 | return getCachedCellInfo(); |
| 2408 | } |
| 2409 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2410 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2411 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2412 | final long identity = Binder.clearCallingIdentity(); |
| 2413 | try { |
| 2414 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2415 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2416 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2417 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2418 | if (info != null) cellInfos.addAll(info); |
| 2419 | } |
| 2420 | return cellInfos; |
| 2421 | } finally { |
| 2422 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2423 | } |
| 2424 | } |
| 2425 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2426 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2427 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2428 | String callingFeatureId) { |
| 2429 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2430 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2434 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2435 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2436 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2437 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2440 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2441 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2442 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2443 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2444 | |
| 2445 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2446 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2447 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2448 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2449 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2450 | .setCallingPid(Binder.getCallingPid()) |
| 2451 | .setCallingUid(Binder.getCallingUid()) |
| 2452 | .setMethod("requestCellInfoUpdate") |
| 2453 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2454 | .build()); |
| 2455 | switch (locationResult) { |
| 2456 | case DENIED_HARD: |
| 2457 | throw new SecurityException("Not allowed to access cell info"); |
| 2458 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2459 | try { |
| 2460 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2461 | } catch (RemoteException re) { |
| 2462 | // Drop without consequences |
| 2463 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2464 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2465 | } |
| 2466 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2467 | |
| 2468 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2469 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2470 | |
| 2471 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2472 | } |
| 2473 | |
| 2474 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2475 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2476 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2477 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2478 | |
| 2479 | final long identity = Binder.clearCallingIdentity(); |
| 2480 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2481 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2482 | } finally { |
| 2483 | Binder.restoreCallingIdentity(identity); |
| 2484 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2485 | } |
| 2486 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2487 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2488 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2489 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2490 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2491 | return null; |
| 2492 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2493 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2494 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2495 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2496 | return null; |
| 2497 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2498 | |
| 2499 | final long identity = Binder.clearCallingIdentity(); |
| 2500 | try { |
| 2501 | return phone.getImei(); |
| 2502 | } finally { |
| 2503 | Binder.restoreCallingIdentity(identity); |
| 2504 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2505 | } |
| 2506 | |
| 2507 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2508 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2509 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2510 | String tac = null; |
| 2511 | if (phone != null) { |
| 2512 | String imei = phone.getImei(); |
| 2513 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2514 | } |
| 2515 | return tac; |
| 2516 | } |
| 2517 | |
| 2518 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2519 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2520 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2521 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2522 | return null; |
| 2523 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2524 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2525 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2526 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2527 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2528 | return null; |
| 2529 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2530 | |
| 2531 | final long identity = Binder.clearCallingIdentity(); |
| 2532 | try { |
| 2533 | return phone.getMeid(); |
| 2534 | } finally { |
| 2535 | Binder.restoreCallingIdentity(identity); |
| 2536 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2540 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2541 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2542 | String manufacturerCode = null; |
| 2543 | if (phone != null) { |
| 2544 | String meid = phone.getMeid(); |
| 2545 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2546 | } |
| 2547 | return manufacturerCode; |
| 2548 | } |
| 2549 | |
| 2550 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2551 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2552 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2553 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2554 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2555 | return null; |
| 2556 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2557 | int subId = phone.getSubId(); |
| 2558 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2559 | mApp, subId, callingPackage, callingFeatureId, |
| 2560 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2561 | return null; |
| 2562 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2563 | |
| 2564 | final long identity = Binder.clearCallingIdentity(); |
| 2565 | try { |
| 2566 | return phone.getDeviceSvn(); |
| 2567 | } finally { |
| 2568 | Binder.restoreCallingIdentity(identity); |
| 2569 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2570 | } |
| 2571 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2572 | @Override |
| 2573 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2574 | final long identity = Binder.clearCallingIdentity(); |
| 2575 | try { |
| 2576 | final Phone phone = getPhone(subId); |
| 2577 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2578 | } finally { |
| 2579 | Binder.restoreCallingIdentity(identity); |
| 2580 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | @Override |
| 2584 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2585 | final long identity = Binder.clearCallingIdentity(); |
| 2586 | try { |
| 2587 | final Phone phone = getPhone(subId); |
| 2588 | return phone == null ? null : phone.getCarrierName(); |
| 2589 | } finally { |
| 2590 | Binder.restoreCallingIdentity(identity); |
| 2591 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2592 | } |
| 2593 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2594 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2595 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -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 |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2600 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2601 | } finally { |
| 2602 | Binder.restoreCallingIdentity(identity); |
| 2603 | } |
| 2604 | } |
| 2605 | |
| 2606 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2607 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2608 | final long identity = Binder.clearCallingIdentity(); |
| 2609 | try { |
| 2610 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2611 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2612 | } finally { |
| 2613 | Binder.restoreCallingIdentity(identity); |
| 2614 | } |
| 2615 | } |
| 2616 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2617 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2618 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2619 | if (!isSubscriptionMccMnc) { |
| 2620 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2621 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2622 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2623 | if (phone == null) { |
| 2624 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2625 | } |
| 2626 | final long identity = Binder.clearCallingIdentity(); |
| 2627 | try { |
| 2628 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2629 | } finally { |
| 2630 | Binder.restoreCallingIdentity(identity); |
| 2631 | } |
| 2632 | } |
| 2633 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2634 | // |
| 2635 | // Internal helper methods. |
| 2636 | // |
| 2637 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2638 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2639 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2640 | * |
| 2641 | * @throws SecurityException if the caller does not have the required permission |
| 2642 | */ |
| 2643 | private void enforceModifyPermission() { |
| 2644 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2645 | } |
| 2646 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2647 | /** |
| 2648 | * Make sure the caller is system. |
| 2649 | * |
| 2650 | * @throws SecurityException if the caller is not system. |
| 2651 | */ |
| 2652 | private void enforceSystemCaller() { |
| 2653 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2654 | throw new SecurityException("Caller must be system"); |
| 2655 | } |
| 2656 | } |
| 2657 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2658 | private void enforceActiveEmergencySessionPermission() { |
| 2659 | mApp.enforceCallingOrSelfPermission( |
| 2660 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2661 | } |
| 2662 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2663 | /** |
| 2664 | * Make sure the caller has the CALL_PHONE permission. |
| 2665 | * |
| 2666 | * @throws SecurityException if the caller does not have the required permission |
| 2667 | */ |
| 2668 | private void enforceCallPermission() { |
| 2669 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2670 | } |
| 2671 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2672 | private void enforceSettingsPermission() { |
| 2673 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2674 | } |
| 2675 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2676 | private String createTelUrl(String number) { |
| 2677 | if (TextUtils.isEmpty(number)) { |
| 2678 | return null; |
| 2679 | } |
| 2680 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2681 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2682 | } |
| 2683 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2684 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2685 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2686 | } |
| 2687 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2688 | private static void logv(String msg) { |
| 2689 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2690 | } |
| 2691 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2692 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2693 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2694 | } |
| 2695 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2696 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2697 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2698 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2699 | } |
| 2700 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2701 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2702 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2703 | final long identity = Binder.clearCallingIdentity(); |
| 2704 | try { |
| 2705 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2706 | if (phone == null) { |
| 2707 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2708 | } else { |
| 2709 | return phone.getPhoneType(); |
| 2710 | } |
| 2711 | } finally { |
| 2712 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2713 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | /** |
| 2717 | * Returns the CDMA ERI icon index to display |
| 2718 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2719 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2720 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2721 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2722 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2723 | } |
| 2724 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2725 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2726 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2727 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2728 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2729 | mApp, subId, callingPackage, callingFeatureId, |
| 2730 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2731 | return -1; |
| 2732 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2733 | |
| 2734 | final long identity = Binder.clearCallingIdentity(); |
| 2735 | try { |
| 2736 | final Phone phone = getPhone(subId); |
| 2737 | if (phone != null) { |
| 2738 | return phone.getCdmaEriIconIndex(); |
| 2739 | } else { |
| 2740 | return -1; |
| 2741 | } |
| 2742 | } finally { |
| 2743 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2744 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2745 | } |
| 2746 | |
| 2747 | /** |
| 2748 | * Returns the CDMA ERI icon mode, |
| 2749 | * 0 - ON |
| 2750 | * 1 - FLASHING |
| 2751 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2752 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2753 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2754 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2755 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2756 | } |
| 2757 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2758 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2759 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2760 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2761 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2762 | mApp, subId, callingPackage, callingFeatureId, |
| 2763 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2764 | return -1; |
| 2765 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2766 | |
| 2767 | final long identity = Binder.clearCallingIdentity(); |
| 2768 | try { |
| 2769 | final Phone phone = getPhone(subId); |
| 2770 | if (phone != null) { |
| 2771 | return phone.getCdmaEriIconMode(); |
| 2772 | } else { |
| 2773 | return -1; |
| 2774 | } |
| 2775 | } finally { |
| 2776 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2777 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2778 | } |
| 2779 | |
| 2780 | /** |
| 2781 | * Returns the CDMA ERI text, |
| 2782 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2783 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2784 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2785 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2786 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2787 | } |
| 2788 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2789 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2790 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2791 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2792 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2793 | mApp, subId, callingPackage, callingFeatureId, |
| 2794 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2795 | return null; |
| 2796 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2797 | |
| 2798 | final long identity = Binder.clearCallingIdentity(); |
| 2799 | try { |
| 2800 | final Phone phone = getPhone(subId); |
| 2801 | if (phone != null) { |
| 2802 | return phone.getCdmaEriText(); |
| 2803 | } else { |
| 2804 | return null; |
| 2805 | } |
| 2806 | } finally { |
| 2807 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2808 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2809 | } |
| 2810 | |
| 2811 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2812 | * Returns the CDMA MDN. |
| 2813 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2814 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2815 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2816 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2817 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2818 | |
| 2819 | final long identity = Binder.clearCallingIdentity(); |
| 2820 | try { |
| 2821 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2822 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2823 | return phone.getLine1Number(); |
| 2824 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2825 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2826 | return null; |
| 2827 | } |
| 2828 | } finally { |
| 2829 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2830 | } |
| 2831 | } |
| 2832 | |
| 2833 | /** |
| 2834 | * Returns the CDMA MIN. |
| 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 getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2838 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2839 | mApp, subId, "getCdmaMin"); |
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); |
| 2844 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2845 | return phone.getCdmaMin(); |
| 2846 | } else { |
| 2847 | return null; |
| 2848 | } |
| 2849 | } finally { |
| 2850 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2851 | } |
| 2852 | } |
| 2853 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2854 | @Override |
| 2855 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2856 | INumberVerificationCallback callback, String callingPackage) { |
| 2857 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2858 | != PERMISSION_GRANTED) { |
| 2859 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2860 | } |
| 2861 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2862 | |
| 2863 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2864 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2865 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2866 | } |
| 2867 | |
| 2868 | if (range == null) { |
| 2869 | throw new NullPointerException("Range must be non-null"); |
| 2870 | } |
| 2871 | |
| 2872 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2873 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2874 | |
| 2875 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2876 | } |
| 2877 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2878 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2879 | * Returns true if CDMA provisioning needs to run. |
| 2880 | */ |
| 2881 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2882 | final long identity = Binder.clearCallingIdentity(); |
| 2883 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2884 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2885 | } finally { |
| 2886 | Binder.restoreCallingIdentity(identity); |
| 2887 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2891 | * Sets the voice mail number of a given subId. |
| 2892 | */ |
| 2893 | @Override |
| 2894 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2895 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2896 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2897 | |
| 2898 | final long identity = Binder.clearCallingIdentity(); |
| 2899 | try { |
| 2900 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2901 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2902 | return success; |
| 2903 | } finally { |
| 2904 | Binder.restoreCallingIdentity(identity); |
| 2905 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2906 | } |
| 2907 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2908 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2909 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2910 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2911 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2912 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2913 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2914 | throw new SecurityException("caller must be system dialer"); |
| 2915 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2916 | |
| 2917 | final long identity = Binder.clearCallingIdentity(); |
| 2918 | try { |
| 2919 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2920 | if (phoneAccountHandle == null) { |
| 2921 | return null; |
| 2922 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2923 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2924 | } finally { |
| 2925 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2926 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2930 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2931 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2932 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2933 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2934 | mApp, subId, callingPackage, callingFeatureId, |
| 2935 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2936 | return null; |
| 2937 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2938 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2939 | final long identity = Binder.clearCallingIdentity(); |
| 2940 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2941 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2942 | } finally { |
| 2943 | Binder.restoreCallingIdentity(identity); |
| 2944 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2948 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2949 | VisualVoicemailSmsFilterSettings settings) { |
| 2950 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2951 | |
| 2952 | final long identity = Binder.clearCallingIdentity(); |
| 2953 | try { |
| 2954 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2955 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2956 | } finally { |
| 2957 | Binder.restoreCallingIdentity(identity); |
| 2958 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2962 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2963 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2964 | |
| 2965 | final long identity = Binder.clearCallingIdentity(); |
| 2966 | try { |
| 2967 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2968 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2969 | } finally { |
| 2970 | Binder.restoreCallingIdentity(identity); |
| 2971 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2972 | } |
| 2973 | |
| 2974 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2975 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2976 | String callingPackage, int subId) { |
| 2977 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2978 | |
| 2979 | final long identity = Binder.clearCallingIdentity(); |
| 2980 | try { |
| 2981 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2982 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2983 | } finally { |
| 2984 | Binder.restoreCallingIdentity(identity); |
| 2985 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2989 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2990 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2991 | |
| 2992 | final long identity = Binder.clearCallingIdentity(); |
| 2993 | try { |
| 2994 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2995 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2996 | } finally { |
| 2997 | Binder.restoreCallingIdentity(identity); |
| 2998 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2999 | } |
| 3000 | |
| 3001 | @Override |
| 3002 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 3003 | String number, int port, String text, PendingIntent sentIntent) { |
| 3004 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3005 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3006 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3007 | SmsController smsController = PhoneFactory.getSmsController(); |
| 3008 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 3009 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3010 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3011 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3012 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3013 | * Sets the voice activation state of a given subId. |
| 3014 | */ |
| 3015 | @Override |
| 3016 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3017 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3018 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3019 | |
| 3020 | final long identity = Binder.clearCallingIdentity(); |
| 3021 | try { |
| 3022 | final Phone phone = getPhone(subId); |
| 3023 | if (phone != null) { |
| 3024 | phone.setVoiceActivationState(activationState); |
| 3025 | } else { |
| 3026 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3027 | } |
| 3028 | } finally { |
| 3029 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3030 | } |
| 3031 | } |
| 3032 | |
| 3033 | /** |
| 3034 | * Sets the data activation state of a given subId. |
| 3035 | */ |
| 3036 | @Override |
| 3037 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3038 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3039 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3040 | |
| 3041 | final long identity = Binder.clearCallingIdentity(); |
| 3042 | try { |
| 3043 | final Phone phone = getPhone(subId); |
| 3044 | if (phone != null) { |
| 3045 | phone.setDataActivationState(activationState); |
| 3046 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3047 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3048 | } |
| 3049 | } finally { |
| 3050 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3051 | } |
| 3052 | } |
| 3053 | |
| 3054 | /** |
| 3055 | * Returns the voice activation state of a given subId. |
| 3056 | */ |
| 3057 | @Override |
| 3058 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3059 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3060 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3061 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3062 | final long identity = Binder.clearCallingIdentity(); |
| 3063 | try { |
| 3064 | if (phone != null) { |
| 3065 | return phone.getVoiceActivationState(); |
| 3066 | } else { |
| 3067 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3068 | } |
| 3069 | } finally { |
| 3070 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3071 | } |
| 3072 | } |
| 3073 | |
| 3074 | /** |
| 3075 | * Returns the data activation state of a given subId. |
| 3076 | */ |
| 3077 | @Override |
| 3078 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3079 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3080 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3081 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3082 | final long identity = Binder.clearCallingIdentity(); |
| 3083 | try { |
| 3084 | if (phone != null) { |
| 3085 | return phone.getDataActivationState(); |
| 3086 | } else { |
| 3087 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3088 | } |
| 3089 | } finally { |
| 3090 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3091 | } |
| 3092 | } |
| 3093 | |
| 3094 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3095 | * Returns the unread count of voicemails for a subId |
| 3096 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3097 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3098 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3099 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3100 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3101 | mApp, subId, callingPackage, callingFeatureId, |
| 3102 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3103 | return 0; |
| 3104 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3105 | final long identity = Binder.clearCallingIdentity(); |
| 3106 | try { |
| 3107 | final Phone phone = getPhone(subId); |
| 3108 | if (phone != null) { |
| 3109 | return phone.getVoiceMessageCount(); |
| 3110 | } else { |
| 3111 | return 0; |
| 3112 | } |
| 3113 | } finally { |
| 3114 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3115 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3116 | } |
| 3117 | |
| 3118 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3119 | * returns true, if the device is in a state where both voice and data |
| 3120 | * are supported simultaneously. This can change based on location or network condition. |
| 3121 | */ |
| 3122 | @Override |
| 3123 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3124 | final long identity = Binder.clearCallingIdentity(); |
| 3125 | try { |
| 3126 | final Phone phone = getPhone(subId); |
| 3127 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3128 | } finally { |
| 3129 | Binder.restoreCallingIdentity(identity); |
| 3130 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3131 | } |
| 3132 | |
| 3133 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3134 | * Send the dialer code if called from the current default dialer or the caller has |
| 3135 | * carrier privilege. |
| 3136 | * @param inputCode The dialer code to send |
| 3137 | */ |
| 3138 | @Override |
| 3139 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3140 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3141 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3142 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3143 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3144 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3145 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3146 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3147 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3148 | |
| 3149 | final long identity = Binder.clearCallingIdentity(); |
| 3150 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3151 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3152 | } finally { |
| 3153 | Binder.restoreCallingIdentity(identity); |
| 3154 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3155 | } |
| 3156 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3157 | @Override |
| 3158 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3159 | TelephonyPermissions |
| 3160 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3161 | mApp, subId, "getNetworkSelectionMode"); |
| 3162 | final long identity = Binder.clearCallingIdentity(); |
| 3163 | try { |
| 3164 | if (!isActiveSubscription(subId)) { |
| 3165 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3166 | } |
| 3167 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3168 | } finally { |
| 3169 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3170 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3171 | } |
| 3172 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3173 | @Override |
Sarah Chin | 5f0ecd7 | 2019-12-06 10:24:18 -0800 | [diff] [blame] | 3174 | public PhoneCapability getPhoneCapability(int subId, String callingPackage, |
| 3175 | String callingFeatureId) { |
| 3176 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3177 | mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) { |
| 3178 | return null; |
| 3179 | } |
| 3180 | final long identity = Binder.clearCallingIdentity(); |
| 3181 | try { |
| 3182 | return mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 3183 | } finally { |
| 3184 | Binder.restoreCallingIdentity(identity); |
| 3185 | } |
| 3186 | } |
| 3187 | |
| 3188 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3189 | public boolean isInEmergencySmsMode() { |
| 3190 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3191 | final long identity = Binder.clearCallingIdentity(); |
| 3192 | try { |
| 3193 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3194 | if (phone.isInEmergencySmsMode()) { |
| 3195 | return true; |
| 3196 | } |
| 3197 | } |
| 3198 | } finally { |
| 3199 | Binder.restoreCallingIdentity(identity); |
| 3200 | } |
| 3201 | return false; |
| 3202 | } |
| 3203 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3204 | /** |
| 3205 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3206 | * @param subId The subscription to use to check the configuration. |
| 3207 | * @param c The callback that will be used to send the result. |
| 3208 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3209 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3210 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3211 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3212 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3213 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3214 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3215 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3216 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3217 | "IMS not available on device."); |
| 3218 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3219 | final long token = Binder.clearCallingIdentity(); |
| 3220 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3221 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3222 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3223 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3224 | } catch (ImsException e) { |
| 3225 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3226 | } finally { |
| 3227 | Binder.restoreCallingIdentity(token); |
| 3228 | } |
| 3229 | } |
| 3230 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3231 | /** |
| 3232 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3233 | * @param subId The subscription to use to check the configuration. |
| 3234 | * @param c The callback that will be used to send the result. |
| 3235 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3236 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3237 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3238 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3239 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3240 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3241 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3242 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3243 | final long token = Binder.clearCallingIdentity(); |
| 3244 | try { |
| 3245 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3246 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3247 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3248 | } catch (ImsException e) { |
| 3249 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3250 | + "is inactive, ignoring unregister."); |
| 3251 | // If the subscription is no longer active, just return, since the callback |
| 3252 | // will already have been removed internally. |
| 3253 | } finally { |
| 3254 | Binder.restoreCallingIdentity(token); |
| 3255 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3256 | } |
| 3257 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3258 | /** |
| 3259 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3260 | */ |
| 3261 | @Override |
| 3262 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3263 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3264 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3265 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3266 | "IMS not available on device."); |
| 3267 | } |
| 3268 | final long token = Binder.clearCallingIdentity(); |
| 3269 | try { |
| 3270 | Phone phone = getPhone(subId); |
| 3271 | if (phone == null) { |
| 3272 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3273 | + subId + "'"); |
| 3274 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3275 | } |
| 3276 | phone.getImsRegistrationState(regState -> { |
| 3277 | try { |
| 3278 | consumer.accept((regState == null) |
| 3279 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3280 | } catch (RemoteException e) { |
| 3281 | // Ignore if the remote process is no longer available to call back. |
| 3282 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3283 | } |
| 3284 | }); |
| 3285 | } finally { |
| 3286 | Binder.restoreCallingIdentity(token); |
| 3287 | } |
| 3288 | } |
| 3289 | |
| 3290 | /** |
| 3291 | * Get the transport type for the IMS service registration state. |
| 3292 | */ |
| 3293 | @Override |
| 3294 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3295 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3296 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3297 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3298 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3299 | "IMS not available on device."); |
| 3300 | } |
| 3301 | final long token = Binder.clearCallingIdentity(); |
| 3302 | try { |
| 3303 | Phone phone = getPhone(subId); |
| 3304 | if (phone == null) { |
| 3305 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3306 | + subId + "'"); |
| 3307 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3308 | } |
| 3309 | phone.getImsRegistrationTech(regTech -> { |
| 3310 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3311 | int regTechConverted = (regTech == null) |
| 3312 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3313 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3314 | regTechConverted); |
| 3315 | try { |
| 3316 | consumer.accept(regTechConverted); |
| 3317 | } catch (RemoteException e) { |
| 3318 | // Ignore if the remote process is no longer available to call back. |
| 3319 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3320 | } |
| 3321 | }); |
| 3322 | } finally { |
| 3323 | Binder.restoreCallingIdentity(token); |
| 3324 | } |
| 3325 | } |
| 3326 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3327 | /** |
| 3328 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3329 | * @param subId The subscription to use to check the configuration. |
| 3330 | * @param c The callback that will be used to send the result. |
| 3331 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3332 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3333 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3334 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3335 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3336 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3337 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3338 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3339 | "IMS not available on device."); |
| 3340 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3341 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3342 | final long token = Binder.clearCallingIdentity(); |
| 3343 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3344 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3345 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3346 | } catch (ImsException e) { |
| 3347 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3348 | } finally { |
| 3349 | Binder.restoreCallingIdentity(token); |
| 3350 | } |
| 3351 | } |
| 3352 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3353 | /** |
| 3354 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3355 | * @param subId The subscription to use to check the configuration. |
| 3356 | * @param c The callback that will be used to send the result. |
| 3357 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3358 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3359 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3360 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3361 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3362 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3363 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3364 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3365 | |
| 3366 | final long token = Binder.clearCallingIdentity(); |
| 3367 | try { |
| 3368 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3369 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3370 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3371 | } catch (ImsException e) { |
| 3372 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3373 | + "is inactive, ignoring unregister."); |
| 3374 | // If the subscription is no longer active, just return, since the callback |
| 3375 | // will already have been removed internally. |
| 3376 | } finally { |
| 3377 | Binder.restoreCallingIdentity(token); |
| 3378 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3379 | } |
| 3380 | |
| 3381 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3382 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3383 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3384 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3385 | final long token = Binder.clearCallingIdentity(); |
| 3386 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3387 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3388 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3389 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3390 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3391 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3392 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3393 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3394 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3395 | } finally { |
| 3396 | Binder.restoreCallingIdentity(token); |
| 3397 | } |
| 3398 | } |
| 3399 | |
| 3400 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3401 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3402 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3403 | final long token = Binder.clearCallingIdentity(); |
| 3404 | try { |
| 3405 | Phone phone = getPhone(subId); |
| 3406 | if (phone == null) return false; |
| 3407 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3408 | } finally { |
| 3409 | Binder.restoreCallingIdentity(token); |
| 3410 | } |
| 3411 | } |
| 3412 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3413 | /** |
| 3414 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3415 | * subscription. |
| 3416 | * @param subId The subscription to use to check the configuration. |
| 3417 | * @param callback The callback that will be used to send the result. |
| 3418 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3419 | * @param transportType The transport type of the MmTelFeature capability. |
| 3420 | */ |
| 3421 | @Override |
| 3422 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3423 | int transportType) { |
| 3424 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3425 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3426 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3427 | "IMS not available on device."); |
| 3428 | } |
| 3429 | final long token = Binder.clearCallingIdentity(); |
| 3430 | try { |
| 3431 | int slotId = getSlotIndex(subId); |
| 3432 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3433 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3434 | + subId + "'"); |
| 3435 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3436 | } |
| 3437 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3438 | transportType, aBoolean -> { |
| 3439 | try { |
| 3440 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3441 | } catch (RemoteException e) { |
| 3442 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3443 | + "running. Ignore"); |
| 3444 | } |
| 3445 | }); |
| 3446 | } finally { |
| 3447 | Binder.restoreCallingIdentity(token); |
| 3448 | } |
| 3449 | } |
| 3450 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3451 | /** |
| 3452 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3453 | * @param subId The subscription to use to check the configuration. |
| 3454 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3455 | @Override |
| 3456 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3457 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3458 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3459 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3460 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3461 | final long token = Binder.clearCallingIdentity(); |
| 3462 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3463 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3464 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3465 | } catch (ImsException e) { |
| 3466 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3467 | } finally { |
| 3468 | Binder.restoreCallingIdentity(token); |
| 3469 | } |
| 3470 | } |
| 3471 | |
| 3472 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3473 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3474 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3475 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3476 | final long identity = Binder.clearCallingIdentity(); |
| 3477 | try { |
| 3478 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3479 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3480 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3481 | } catch (ImsException e) { |
| 3482 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3483 | } finally { |
| 3484 | Binder.restoreCallingIdentity(identity); |
| 3485 | } |
| 3486 | } |
| 3487 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3488 | /** |
| 3489 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3490 | * @param subId The subscription to use to check the configuration. |
| 3491 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3492 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3493 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3494 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3495 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3496 | final long identity = Binder.clearCallingIdentity(); |
| 3497 | try { |
| 3498 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3499 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3500 | } catch (ImsException e) { |
| 3501 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3502 | } finally { |
| 3503 | Binder.restoreCallingIdentity(identity); |
| 3504 | } |
| 3505 | } |
| 3506 | |
| 3507 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3508 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3509 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3510 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3511 | final long identity = Binder.clearCallingIdentity(); |
| 3512 | try { |
| 3513 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3514 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3515 | } catch (ImsException e) { |
| 3516 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3517 | } finally { |
| 3518 | Binder.restoreCallingIdentity(identity); |
| 3519 | } |
| 3520 | } |
| 3521 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3522 | /** |
| 3523 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3524 | * @param subId The subscription to use to check the configuration. |
| 3525 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3526 | @Override |
| 3527 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3528 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3529 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3530 | final long identity = Binder.clearCallingIdentity(); |
| 3531 | try { |
| 3532 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3533 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3534 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3535 | } catch (ImsException e) { |
| 3536 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3537 | } finally { |
| 3538 | Binder.restoreCallingIdentity(identity); |
| 3539 | } |
| 3540 | } |
| 3541 | |
| 3542 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3543 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3544 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3545 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3546 | final long identity = Binder.clearCallingIdentity(); |
| 3547 | try { |
| 3548 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3549 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3550 | } catch (ImsException e) { |
| 3551 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3552 | } finally { |
| 3553 | Binder.restoreCallingIdentity(identity); |
| 3554 | } |
| 3555 | } |
| 3556 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3557 | /** |
| 3558 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3559 | * @param subId The subscription to use to check the configuration. |
| 3560 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3561 | @Override |
| 3562 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3563 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3564 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3565 | final long identity = Binder.clearCallingIdentity(); |
| 3566 | try { |
| 3567 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3568 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3569 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3570 | } catch (ImsException e) { |
| 3571 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3572 | } finally { |
| 3573 | Binder.restoreCallingIdentity(identity); |
| 3574 | } |
| 3575 | } |
| 3576 | |
| 3577 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3578 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3579 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3580 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3581 | final long identity = Binder.clearCallingIdentity(); |
| 3582 | try { |
| 3583 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3584 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3585 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3586 | } catch (ImsException e) { |
| 3587 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3588 | } finally { |
| 3589 | Binder.restoreCallingIdentity(identity); |
| 3590 | } |
| 3591 | } |
| 3592 | |
| 3593 | @Override |
| 3594 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3595 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3596 | "setVoWiFiNonPersistent"); |
| 3597 | final long identity = Binder.clearCallingIdentity(); |
| 3598 | try { |
| 3599 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3600 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3601 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3602 | } catch (ImsException e) { |
| 3603 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3604 | } finally { |
| 3605 | Binder.restoreCallingIdentity(identity); |
| 3606 | } |
| 3607 | } |
| 3608 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3609 | /** |
| 3610 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3611 | * @param subId The subscription to use to check the configuration. |
| 3612 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3613 | @Override |
| 3614 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3615 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3616 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3617 | final long identity = Binder.clearCallingIdentity(); |
| 3618 | try { |
| 3619 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3620 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3621 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3622 | } catch (ImsException e) { |
| 3623 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3624 | } finally { |
| 3625 | Binder.restoreCallingIdentity(identity); |
| 3626 | } |
| 3627 | } |
| 3628 | |
| 3629 | @Override |
| 3630 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3631 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3632 | "setVoWiFiModeSetting"); |
| 3633 | final long identity = Binder.clearCallingIdentity(); |
| 3634 | try { |
| 3635 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3636 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3637 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3638 | } catch (ImsException e) { |
| 3639 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3640 | } finally { |
| 3641 | Binder.restoreCallingIdentity(identity); |
| 3642 | } |
| 3643 | } |
| 3644 | |
| 3645 | @Override |
| 3646 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3647 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3648 | final long identity = Binder.clearCallingIdentity(); |
| 3649 | try { |
| 3650 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3651 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3652 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3653 | } catch (ImsException e) { |
| 3654 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3655 | } finally { |
| 3656 | Binder.restoreCallingIdentity(identity); |
| 3657 | } |
| 3658 | } |
| 3659 | |
| 3660 | @Override |
| 3661 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3662 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3663 | "setVoWiFiRoamingModeSetting"); |
| 3664 | final long identity = Binder.clearCallingIdentity(); |
| 3665 | try { |
| 3666 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3667 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3668 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3669 | } catch (ImsException e) { |
| 3670 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3671 | } finally { |
| 3672 | Binder.restoreCallingIdentity(identity); |
| 3673 | } |
| 3674 | } |
| 3675 | |
| 3676 | @Override |
| 3677 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3678 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3679 | "setRttCapabilityEnabled"); |
| 3680 | final long identity = Binder.clearCallingIdentity(); |
| 3681 | try { |
| 3682 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3683 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3684 | } catch (ImsException e) { |
| 3685 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3686 | } finally { |
| 3687 | Binder.restoreCallingIdentity(identity); |
| 3688 | } |
| 3689 | } |
| 3690 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3691 | /** |
| 3692 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3693 | * @param subId The subscription to use to check the configuration. |
| 3694 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3695 | @Override |
| 3696 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3697 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3698 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3699 | final long identity = Binder.clearCallingIdentity(); |
| 3700 | try { |
| 3701 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3702 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3703 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3704 | } catch (ImsException e) { |
| 3705 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3706 | } finally { |
| 3707 | Binder.restoreCallingIdentity(identity); |
| 3708 | } |
| 3709 | } |
| 3710 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3711 | @Override |
| 3712 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3713 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3714 | final long identity = Binder.clearCallingIdentity(); |
| 3715 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3716 | if (!isImsAvailableOnDevice()) { |
| 3717 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3718 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3719 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3720 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3721 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3722 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3723 | } catch (ImsException e) { |
| 3724 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3725 | } finally { |
| 3726 | Binder.restoreCallingIdentity(identity); |
| 3727 | } |
| 3728 | } |
| 3729 | |
| 3730 | @Override |
| 3731 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3732 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3733 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3734 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3735 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3736 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3737 | try { |
| 3738 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3739 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3740 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3741 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3742 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3743 | + "is inactive, ignoring unregister."); |
| 3744 | // If the subscription is no longer active, just return, since the callback will already |
| 3745 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3746 | } finally { |
| 3747 | Binder.restoreCallingIdentity(identity); |
| 3748 | } |
| 3749 | } |
| 3750 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3751 | |
| 3752 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3753 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3754 | message); |
| 3755 | } |
| 3756 | |
| 3757 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3758 | boolean isMmtelCapability) { |
| 3759 | Phone phone = getPhone(subId); |
| 3760 | if (phone == null) { |
| 3761 | loge("phone instance null for subid " + subId); |
| 3762 | return false; |
| 3763 | } |
| 3764 | if (isMmtelCapability) { |
| 3765 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3766 | return false; |
| 3767 | } |
| 3768 | } else { |
| 3769 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3770 | return false; |
| 3771 | } |
| 3772 | } |
| 3773 | return true; |
| 3774 | } |
| 3775 | |
| 3776 | @Override |
| 3777 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3778 | boolean isProvisioned) { |
| 3779 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3780 | |
| 3781 | final long identity = Binder.clearCallingIdentity(); |
| 3782 | try { |
| 3783 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3784 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3785 | return; |
| 3786 | } |
| 3787 | |
| 3788 | // this capability requires provisioning, route to the correct API. |
| 3789 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3790 | switch (capability) { |
| 3791 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3792 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3793 | ims.setEabProvisioned(isProvisioned); |
| 3794 | break; |
| 3795 | default: { |
| 3796 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3797 | + "rcs capability '" + capability + "', which does not require " |
| 3798 | + "provisioning."); |
| 3799 | } |
| 3800 | } |
| 3801 | } finally { |
| 3802 | Binder.restoreCallingIdentity(identity); |
| 3803 | } |
| 3804 | |
| 3805 | } |
| 3806 | |
| 3807 | |
| 3808 | @Override |
| 3809 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3810 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3811 | final long identity = Binder.clearCallingIdentity(); |
| 3812 | try { |
| 3813 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3814 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3815 | return true; |
| 3816 | } |
| 3817 | |
| 3818 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3819 | switch (capability) { |
| 3820 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3821 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3822 | return ims.isEabProvisionedOnDevice(); |
| 3823 | |
| 3824 | default: { |
| 3825 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3826 | + "capability '" + capability + "', which does not require " |
| 3827 | + "provisioning."); |
| 3828 | } |
| 3829 | } |
| 3830 | |
| 3831 | } finally { |
| 3832 | Binder.restoreCallingIdentity(identity); |
| 3833 | } |
| 3834 | } |
| 3835 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3836 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3837 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3838 | boolean isProvisioned) { |
| 3839 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3840 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3841 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3842 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3843 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3844 | final long identity = Binder.clearCallingIdentity(); |
| 3845 | try { |
| 3846 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3847 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3848 | return; |
| 3849 | } |
| 3850 | |
| 3851 | // this capability requires provisioning, route to the correct API. |
| 3852 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3853 | switch (capability) { |
| 3854 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3855 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3856 | ims.setVolteProvisioned(isProvisioned); |
| 3857 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3858 | ims.setWfcProvisioned(isProvisioned); |
| 3859 | } |
| 3860 | break; |
| 3861 | } |
| 3862 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3863 | // There is currently no difference in VT provisioning type. |
| 3864 | ims.setVtProvisioned(isProvisioned); |
| 3865 | break; |
| 3866 | } |
| 3867 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3868 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3869 | // change the capability of the feature instead if needed. |
| 3870 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3871 | == isProvisioned) { |
| 3872 | // No change in provisioning. |
| 3873 | return; |
| 3874 | } |
| 3875 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3876 | try { |
| 3877 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3878 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3879 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3880 | + ", Exception" + e.getMessage()); |
| 3881 | } |
| 3882 | break; |
| 3883 | } |
| 3884 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3885 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3886 | + "MmTel capability '" + capability + "', which does not require " |
| 3887 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3888 | } |
| 3889 | } |
| 3890 | |
| 3891 | } finally { |
| 3892 | Binder.restoreCallingIdentity(identity); |
| 3893 | } |
| 3894 | } |
| 3895 | |
| 3896 | @Override |
| 3897 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3898 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3899 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3900 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3901 | } |
| 3902 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3903 | final long identity = Binder.clearCallingIdentity(); |
| 3904 | try { |
| 3905 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3906 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3907 | return true; |
| 3908 | } |
| 3909 | |
| 3910 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3911 | switch (capability) { |
| 3912 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3913 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3914 | return ims.isVolteProvisionedOnDevice(); |
| 3915 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3916 | return ims.isWfcProvisionedOnDevice(); |
| 3917 | } |
| 3918 | // This should never happen, since we are checking tech above to make sure it |
| 3919 | // is either LTE or IWLAN. |
| 3920 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3921 | + "capability."); |
| 3922 | } |
| 3923 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3924 | // There is currently no difference in VT provisioning type. |
| 3925 | return ims.isVtProvisionedOnDevice(); |
| 3926 | } |
| 3927 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3928 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3929 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3930 | } |
| 3931 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3932 | throw new IllegalArgumentException( |
| 3933 | "Tried to get provisioning for MmTel capability '" + capability |
| 3934 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3935 | } |
| 3936 | } |
| 3937 | |
| 3938 | } finally { |
| 3939 | Binder.restoreCallingIdentity(identity); |
| 3940 | } |
| 3941 | } |
| 3942 | |
| 3943 | @Override |
| 3944 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3945 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3946 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3947 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3948 | } |
| 3949 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3950 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3951 | return (provisionedBits & capability) > 0; |
| 3952 | } |
| 3953 | |
| 3954 | @Override |
| 3955 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3956 | boolean isProvisioned) { |
| 3957 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3958 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3959 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3960 | } |
| 3961 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3962 | "setProvisioningStatusForCapability"); |
| 3963 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3964 | // If the current provisioning status for capability already matches isProvisioned, |
| 3965 | // do nothing. |
| 3966 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3967 | return; |
| 3968 | } |
| 3969 | if (isProvisioned) { |
| 3970 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3971 | } else { |
| 3972 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3973 | } |
| 3974 | } |
| 3975 | |
| 3976 | /** |
| 3977 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3978 | * technology. The bitfield should mirror the bitfield defined by |
| 3979 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3980 | */ |
| 3981 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3982 | String key = getMmTelProvisioningKey(subId, tech); |
| 3983 | // Default is no capabilities are provisioned. |
| 3984 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3985 | } |
| 3986 | |
| 3987 | /** |
| 3988 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3989 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3990 | * technology specified. |
| 3991 | * |
| 3992 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3993 | */ |
| 3994 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3995 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3996 | String key = getMmTelProvisioningKey(subId, tech); |
| 3997 | editor.putInt(key, newField); |
| 3998 | editor.commit(); |
| 3999 | } |
| 4000 | |
| 4001 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4002 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4003 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4004 | } |
| 4005 | |
| 4006 | /** |
| 4007 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4008 | * carrier associated with the subscription id. |
| 4009 | */ |
| 4010 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4011 | int capability) { |
| 4012 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4013 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4014 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4015 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4016 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4017 | false); |
| 4018 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4019 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4020 | |
| 4021 | // First check to make sure that the capability requires provisioning. |
| 4022 | switch (capability) { |
| 4023 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4024 | // intentional fallthrough |
| 4025 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4026 | if (requireVoiceVtProvisioning) { |
| 4027 | // Voice and Video requires provisioning |
| 4028 | return true; |
| 4029 | } |
| 4030 | break; |
| 4031 | } |
| 4032 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4033 | if (requireUtProvisioning) { |
| 4034 | // UT requires provisioning |
| 4035 | return true; |
| 4036 | } |
| 4037 | break; |
| 4038 | } |
| 4039 | } |
| 4040 | return false; |
| 4041 | } |
| 4042 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4043 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4044 | int capability) { |
| 4045 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4046 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4047 | |
| 4048 | boolean requireRcsProvisioning = c.getBoolean( |
| 4049 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4050 | |
| 4051 | // First check to make sure that the capability requires provisioning. |
| 4052 | switch (capability) { |
| 4053 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4054 | // intentional fallthrough |
| 4055 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4056 | if (requireRcsProvisioning) { |
| 4057 | // OPTION or PRESENCE requires provisioning |
| 4058 | return true; |
| 4059 | } |
| 4060 | break; |
| 4061 | } |
| 4062 | } |
| 4063 | return false; |
| 4064 | } |
| 4065 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4066 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4067 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4068 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4069 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4070 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4071 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4072 | final long identity = Binder.clearCallingIdentity(); |
| 4073 | try { |
| 4074 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4075 | int slotId = getSlotIndex(subId); |
| 4076 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4077 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4078 | + subId + "' for key:" + key); |
| 4079 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4080 | } |
| 4081 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4082 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4083 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4084 | + subId + "' for key:" + key); |
| 4085 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4086 | } finally { |
| 4087 | Binder.restoreCallingIdentity(identity); |
| 4088 | } |
| 4089 | } |
| 4090 | |
| 4091 | @Override |
| 4092 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4093 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4094 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4095 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4096 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4097 | final long identity = Binder.clearCallingIdentity(); |
| 4098 | try { |
| 4099 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4100 | int slotId = getSlotIndex(subId); |
| 4101 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4102 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4103 | + subId + "' for key:" + key); |
| 4104 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4105 | } |
| 4106 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4107 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4108 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4109 | + subId + "' for key:" + key); |
| 4110 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4111 | } finally { |
| 4112 | Binder.restoreCallingIdentity(identity); |
| 4113 | } |
| 4114 | } |
| 4115 | |
| 4116 | @Override |
| 4117 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4118 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4119 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4120 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4121 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4122 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4123 | final long identity = Binder.clearCallingIdentity(); |
| 4124 | try { |
| 4125 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4126 | int slotId = getSlotIndex(subId); |
| 4127 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4128 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4129 | + subId + "' for key:" + key); |
| 4130 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4131 | } |
| 4132 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4133 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4134 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4135 | + "' for key:" + key); |
| 4136 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4137 | } finally { |
| 4138 | Binder.restoreCallingIdentity(identity); |
| 4139 | } |
| 4140 | } |
| 4141 | |
| 4142 | @Override |
| 4143 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4144 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4145 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4146 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4147 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4148 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4149 | final long identity = Binder.clearCallingIdentity(); |
| 4150 | try { |
| 4151 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4152 | int slotId = getSlotIndex(subId); |
| 4153 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4154 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4155 | + subId + "' for key:" + key); |
| 4156 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4157 | } |
| 4158 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4159 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4160 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4161 | + "' for key:" + key); |
| 4162 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4163 | } finally { |
| 4164 | Binder.restoreCallingIdentity(identity); |
| 4165 | } |
| 4166 | } |
| 4167 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4168 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4169 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4170 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4171 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4172 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4173 | } |
| 4174 | return slotId; |
| 4175 | } |
| 4176 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4177 | private int getSlotIndex(int subId) { |
| 4178 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4179 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4180 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4181 | } |
| 4182 | return slotId; |
| 4183 | } |
| 4184 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4185 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4186 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4187 | */ |
| 4188 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4189 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4190 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4191 | final int targetSdk = getTargetSdk(callingPackage); |
| 4192 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4193 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4194 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4195 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4196 | mApp, subId, callingPackage, callingFeatureId, |
| 4197 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4198 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4199 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4200 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4201 | final long identity = Binder.clearCallingIdentity(); |
| 4202 | try { |
| 4203 | final Phone phone = getPhone(subId); |
| 4204 | if (phone != null) { |
| 4205 | return phone.getServiceState().getDataNetworkType(); |
| 4206 | } else { |
| 4207 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4208 | } |
| 4209 | } finally { |
| 4210 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4211 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4212 | } |
| 4213 | |
| 4214 | /** |
| 4215 | * Returns the data network type |
| 4216 | */ |
| 4217 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4218 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4219 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4220 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4221 | } |
| 4222 | |
| 4223 | /** |
| 4224 | * Returns the data network type for a subId |
| 4225 | */ |
| 4226 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4227 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4228 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4229 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4230 | mApp, subId, callingPackage, callingFeatureId, |
| 4231 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4232 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4233 | } |
| 4234 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4235 | final long identity = Binder.clearCallingIdentity(); |
| 4236 | try { |
| 4237 | final Phone phone = getPhone(subId); |
| 4238 | if (phone != null) { |
| 4239 | return phone.getServiceState().getDataNetworkType(); |
| 4240 | } else { |
| 4241 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4242 | } |
| 4243 | } finally { |
| 4244 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4245 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4246 | } |
| 4247 | |
| 4248 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4249 | * Returns the Voice network type for a subId |
| 4250 | */ |
| 4251 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4252 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4253 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4254 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4255 | mApp, subId, callingPackage, callingFeatureId, |
| 4256 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4257 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4258 | } |
| 4259 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4260 | final long identity = Binder.clearCallingIdentity(); |
| 4261 | try { |
| 4262 | final Phone phone = getPhone(subId); |
| 4263 | if (phone != null) { |
| 4264 | return phone.getServiceState().getVoiceNetworkType(); |
| 4265 | } else { |
| 4266 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4267 | } |
| 4268 | } finally { |
| 4269 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4270 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4271 | } |
| 4272 | |
| 4273 | /** |
| 4274 | * @return true if a ICC card is present |
| 4275 | */ |
| 4276 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4277 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4278 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4279 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4280 | } |
| 4281 | |
| 4282 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4283 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4284 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4285 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4286 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4287 | final long identity = Binder.clearCallingIdentity(); |
| 4288 | try { |
| 4289 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4290 | if (phone != null) { |
| 4291 | return phone.getIccCard().hasIccCard(); |
| 4292 | } else { |
| 4293 | return false; |
| 4294 | } |
| 4295 | } finally { |
| 4296 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4297 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4298 | } |
| 4299 | |
| 4300 | /** |
| 4301 | * Return if the current radio is LTE on CDMA. This |
| 4302 | * is a tri-state return value as for a period of time |
| 4303 | * the mode may be unknown. |
| 4304 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4305 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4306 | * @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] | 4307 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4308 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4309 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4310 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4311 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4312 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4313 | } |
| 4314 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4315 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4316 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4317 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4318 | try { |
| 4319 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4320 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4321 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4322 | } |
| 4323 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4324 | final long identity = Binder.clearCallingIdentity(); |
| 4325 | try { |
| 4326 | final Phone phone = getPhone(subId); |
| 4327 | if (phone == null) { |
| 4328 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4329 | } else { |
| 4330 | return phone.getLteOnCdmaMode(); |
| 4331 | } |
| 4332 | } finally { |
| 4333 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4334 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4335 | } |
| 4336 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4337 | /** |
| 4338 | * {@hide} |
| 4339 | * Returns Default subId, 0 in the case of single standby. |
| 4340 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4341 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4342 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4343 | } |
| 4344 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4345 | private int getSlotForDefaultSubscription() { |
| 4346 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4347 | } |
| 4348 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4349 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4350 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4351 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4352 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4353 | private boolean isActiveSubscription(int subId) { |
| 4354 | return mSubscriptionController.isActiveSubId(subId); |
| 4355 | } |
| 4356 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4357 | /** |
| 4358 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4359 | */ |
| 4360 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4361 | final long identity = Binder.clearCallingIdentity(); |
| 4362 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4363 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4364 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4365 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4366 | } finally { |
| 4367 | Binder.restoreCallingIdentity(identity); |
| 4368 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4369 | } |
| 4370 | |
| 4371 | /** |
| 4372 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4373 | */ |
| 4374 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4375 | final long identity = Binder.clearCallingIdentity(); |
| 4376 | try { |
| 4377 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4378 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4379 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4380 | } finally { |
| 4381 | Binder.restoreCallingIdentity(identity); |
| 4382 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4383 | } |
| 4384 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4385 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4386 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4387 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4388 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4389 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4390 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4391 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4392 | if (phoneId == -1) { |
| 4393 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4394 | + " does not correspond to an active phone"); |
| 4395 | } |
| 4396 | return PhoneFactory.getPhone(phoneId); |
| 4397 | } |
| 4398 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4399 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4400 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4401 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4402 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4403 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4404 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4405 | if (DBG) { |
| 4406 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4407 | } |
| 4408 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4409 | p2); |
| 4410 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4411 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4412 | |
| 4413 | @Override |
| 4414 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4415 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4416 | enforceModifyPermission(); |
| 4417 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4418 | if (DBG) { |
| 4419 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4420 | } |
| 4421 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4422 | callingPackage, aid, p2); |
| 4423 | } |
| 4424 | |
| 4425 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4426 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4427 | final long identity = Binder.clearCallingIdentity(); |
| 4428 | try { |
| 4429 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4430 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4431 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4432 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4433 | if (bestComponent == null |
| 4434 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4435 | loge("The calling package is not allowed to access ISD-R."); |
| 4436 | throw new SecurityException( |
| 4437 | "The calling package is not allowed to access ISD-R."); |
| 4438 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4439 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4440 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4441 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4442 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4443 | null /* workSource */); |
| 4444 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4445 | return response; |
| 4446 | } finally { |
| 4447 | Binder.restoreCallingIdentity(identity); |
| 4448 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4449 | } |
| 4450 | |
| 4451 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4452 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4453 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4454 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4455 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4456 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4457 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4458 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4459 | @Override |
| 4460 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4461 | enforceModifyPermission(); |
| 4462 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4463 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4464 | channel); |
| 4465 | } |
| 4466 | |
| 4467 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4468 | final long identity = Binder.clearCallingIdentity(); |
| 4469 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4470 | if (channel < 0) { |
| 4471 | return false; |
| 4472 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4473 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4474 | null /* workSource */); |
| 4475 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4476 | return success; |
| 4477 | } finally { |
| 4478 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4479 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4480 | } |
| 4481 | |
| 4482 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4483 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4484 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4485 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4486 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4487 | if (DBG) { |
| 4488 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4489 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4490 | + p3 + " data=" + data); |
| 4491 | } |
| 4492 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4493 | command, p1, p2, p3, data); |
| 4494 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4495 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4496 | @Override |
| 4497 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4498 | int command, int p1, int p2, int p3, String data) { |
| 4499 | enforceModifyPermission(); |
| 4500 | if (DBG) { |
| 4501 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4502 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4503 | + p3 + " data=" + data); |
| 4504 | } |
| 4505 | return iccTransmitApduLogicalChannelWithPermission( |
| 4506 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4507 | data); |
| 4508 | } |
| 4509 | |
| 4510 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4511 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4512 | final long identity = Binder.clearCallingIdentity(); |
| 4513 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4514 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4515 | return ""; |
| 4516 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4517 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4518 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4519 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4520 | null /* workSource */); |
| 4521 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4522 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4523 | // Append the returned status code to the end of the response payload. |
| 4524 | String s = Integer.toHexString( |
| 4525 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4526 | if (response.payload != null) { |
| 4527 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4528 | } |
| 4529 | return s; |
| 4530 | } finally { |
| 4531 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4532 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4533 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4534 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4535 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4536 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4537 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4538 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4539 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4540 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4541 | if (DBG) { |
| 4542 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4543 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4544 | } |
| 4545 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4546 | cla, command, p1, p2, p3, data); |
| 4547 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4548 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4549 | @Override |
| 4550 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4551 | int command, int p1, int p2, int p3, String data) { |
| 4552 | enforceModifyPermission(); |
| 4553 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4554 | if (DBG) { |
| 4555 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4556 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4557 | + " data=" + data); |
| 4558 | } |
| 4559 | |
| 4560 | return iccTransmitApduBasicChannelWithPermission( |
| 4561 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4562 | p2, p3, data); |
| 4563 | } |
| 4564 | |
| 4565 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4566 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4567 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4568 | final long identity = Binder.clearCallingIdentity(); |
| 4569 | try { |
| 4570 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4571 | && TextUtils.equals(ISDR_AID, data)) { |
| 4572 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4573 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4574 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4575 | if (bestComponent == null |
| 4576 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4577 | loge("The calling package is not allowed to select ISD-R."); |
| 4578 | throw new SecurityException( |
| 4579 | "The calling package is not allowed to select ISD-R."); |
| 4580 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4581 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4582 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4583 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4584 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4585 | null /* workSource */); |
| 4586 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4587 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4588 | // Append the returned status code to the end of the response payload. |
| 4589 | String s = Integer.toHexString( |
| 4590 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4591 | if (response.payload != null) { |
| 4592 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4593 | } |
| 4594 | return s; |
| 4595 | } finally { |
| 4596 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4597 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4598 | } |
| 4599 | |
| 4600 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4601 | 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] | 4602 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4603 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4604 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4605 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4606 | final long identity = Binder.clearCallingIdentity(); |
| 4607 | try { |
| 4608 | if (DBG) { |
| 4609 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4610 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4611 | } |
| 4612 | |
| 4613 | IccIoResult response = |
| 4614 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4615 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4616 | subId); |
| 4617 | |
| 4618 | if (DBG) { |
| 4619 | log("Exchange SIM_IO [R]" + response); |
| 4620 | } |
| 4621 | |
| 4622 | byte[] result = null; |
| 4623 | int length = 2; |
| 4624 | if (response.payload != null) { |
| 4625 | length = 2 + response.payload.length; |
| 4626 | result = new byte[length]; |
| 4627 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4628 | } else { |
| 4629 | result = new byte[length]; |
| 4630 | } |
| 4631 | |
| 4632 | result[length - 1] = (byte) response.sw2; |
| 4633 | result[length - 2] = (byte) response.sw1; |
| 4634 | return result; |
| 4635 | } finally { |
| 4636 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4637 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4638 | } |
| 4639 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4640 | /** |
| 4641 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4642 | * on a particular subscription |
| 4643 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4644 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4645 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4646 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4647 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4648 | return null; |
| 4649 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4650 | |
| 4651 | final long identity = Binder.clearCallingIdentity(); |
| 4652 | try { |
| 4653 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4654 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4655 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4656 | return null; |
| 4657 | } |
| 4658 | Object response = sendRequest( |
| 4659 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4660 | if (response instanceof String[]) { |
| 4661 | return (String[]) response; |
| 4662 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4663 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4664 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4665 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4666 | } finally { |
| 4667 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4668 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4669 | } |
| 4670 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4671 | /** |
| 4672 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4673 | * subscription. |
| 4674 | * |
| 4675 | * @param subId the id of the subscription. |
| 4676 | * @param appType the uicc app type, must be USIM or SIM. |
| 4677 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4678 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4679 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4680 | * @return number of fplmns that is successfully written to the SIM. |
| 4681 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4682 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4683 | String callingFeatureId) { |
| 4684 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4685 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4686 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4687 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4688 | } |
| 4689 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4690 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4691 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4692 | } |
| 4693 | if (fplmns == null) { |
| 4694 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4695 | } |
| 4696 | for (String fplmn : fplmns) { |
| 4697 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4698 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4699 | } |
| 4700 | } |
| 4701 | final long identity = Binder.clearCallingIdentity(); |
| 4702 | try { |
| 4703 | Object response = sendRequest( |
| 4704 | CMD_SET_FORBIDDEN_PLMNS, |
| 4705 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4706 | subId); |
| 4707 | return (int) response; |
| 4708 | } finally { |
| 4709 | Binder.restoreCallingIdentity(identity); |
| 4710 | } |
| 4711 | } |
| 4712 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4713 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4714 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4715 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4716 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4717 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4718 | final long identity = Binder.clearCallingIdentity(); |
| 4719 | try { |
| 4720 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4721 | if (response.payload == null) { |
| 4722 | return ""; |
| 4723 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4724 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4725 | // Append the returned status code to the end of the response payload. |
| 4726 | String s = Integer.toHexString( |
| 4727 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4728 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4729 | return s; |
| 4730 | } finally { |
| 4731 | Binder.restoreCallingIdentity(identity); |
| 4732 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4733 | } |
| 4734 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4735 | /** |
| 4736 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4737 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4738 | * |
| 4739 | * @param itemID the ID of the item to read |
| 4740 | * @return the NV item as a String, or null on error. |
| 4741 | */ |
| 4742 | @Override |
| 4743 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4744 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4745 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4746 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4747 | |
| 4748 | final long identity = Binder.clearCallingIdentity(); |
| 4749 | try { |
| 4750 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4751 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4752 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4753 | return value; |
| 4754 | } finally { |
| 4755 | Binder.restoreCallingIdentity(identity); |
| 4756 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4757 | } |
| 4758 | |
| 4759 | /** |
| 4760 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4761 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4762 | * |
| 4763 | * @param itemID the ID of the item to read |
| 4764 | * @param itemValue the value to write, as a String |
| 4765 | * @return true on success; false on any failure |
| 4766 | */ |
| 4767 | @Override |
| 4768 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4769 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4770 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4771 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4772 | |
| 4773 | final long identity = Binder.clearCallingIdentity(); |
| 4774 | try { |
| 4775 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4776 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4777 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4778 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4779 | return success; |
| 4780 | } finally { |
| 4781 | Binder.restoreCallingIdentity(identity); |
| 4782 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4783 | } |
| 4784 | |
| 4785 | /** |
| 4786 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4787 | * Used for device configuration by some CDMA operators. |
| 4788 | * |
| 4789 | * @param preferredRoamingList byte array containing the new PRL |
| 4790 | * @return true on success; false on any failure |
| 4791 | */ |
| 4792 | @Override |
| 4793 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4794 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4795 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4796 | |
| 4797 | final long identity = Binder.clearCallingIdentity(); |
| 4798 | try { |
| 4799 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4800 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4801 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4802 | return success; |
| 4803 | } finally { |
| 4804 | Binder.restoreCallingIdentity(identity); |
| 4805 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4806 | } |
| 4807 | |
| 4808 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4809 | * 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] | 4810 | * Used for device configuration by some CDMA operators. |
| 4811 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4812 | * @param slotIndex - device slot. |
| 4813 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4814 | * @return true on success; false on any failure |
| 4815 | */ |
| 4816 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4817 | public boolean resetModemConfig(int slotIndex) { |
| 4818 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4819 | if (phone != null) { |
| 4820 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4821 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4822 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4823 | final long identity = Binder.clearCallingIdentity(); |
| 4824 | try { |
| 4825 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4826 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4827 | return success; |
| 4828 | } finally { |
| 4829 | Binder.restoreCallingIdentity(identity); |
| 4830 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4831 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4832 | return false; |
| 4833 | } |
| 4834 | |
| 4835 | /** |
| 4836 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4837 | * |
| 4838 | * @param slotIndex - device slot. |
| 4839 | * |
| 4840 | * @return true on success; false on any failure |
| 4841 | */ |
| 4842 | @Override |
| 4843 | public boolean rebootModem(int slotIndex) { |
| 4844 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4845 | if (phone != null) { |
| 4846 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4847 | mApp, phone.getSubId(), "rebootModem"); |
| 4848 | |
| 4849 | final long identity = Binder.clearCallingIdentity(); |
| 4850 | try { |
| 4851 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4852 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4853 | return success; |
| 4854 | } finally { |
| 4855 | Binder.restoreCallingIdentity(identity); |
| 4856 | } |
| 4857 | } |
| 4858 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4859 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4860 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4861 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4862 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4863 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4864 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4865 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4866 | return new String[0]; |
| 4867 | } |
| 4868 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4869 | final long identity = Binder.clearCallingIdentity(); |
| 4870 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4871 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4872 | } finally { |
| 4873 | Binder.restoreCallingIdentity(identity); |
| 4874 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4875 | } |
| 4876 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4877 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 4878 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 4879 | * {@link #disableIms(int)}. |
| 4880 | * @param slotIndex device slot. |
| 4881 | */ |
| 4882 | public void resetIms(int slotIndex) { |
| 4883 | enforceModifyPermission(); |
| 4884 | |
| 4885 | final long identity = Binder.clearCallingIdentity(); |
| 4886 | try { |
| 4887 | if (mImsResolver == null) { |
| 4888 | // may happen if the does not support IMS. |
| 4889 | return; |
| 4890 | } |
| 4891 | mImsResolver.disableIms(slotIndex); |
| 4892 | mImsResolver.enableIms(slotIndex); |
| 4893 | } finally { |
| 4894 | Binder.restoreCallingIdentity(identity); |
| 4895 | } |
| 4896 | } |
| 4897 | |
| 4898 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4899 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4900 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4901 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4902 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4903 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4904 | |
| 4905 | final long identity = Binder.clearCallingIdentity(); |
| 4906 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4907 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4908 | // may happen if the device does not support IMS. |
| 4909 | return; |
| 4910 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4911 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4912 | } finally { |
| 4913 | Binder.restoreCallingIdentity(identity); |
| 4914 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4915 | } |
| 4916 | |
| 4917 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4918 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4919 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4920 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4921 | public void disableIms(int slotId) { |
| 4922 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4923 | |
| 4924 | final long identity = Binder.clearCallingIdentity(); |
| 4925 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4926 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4927 | // may happen if the device does not support IMS. |
| 4928 | return; |
| 4929 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4930 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4931 | } finally { |
| 4932 | Binder.restoreCallingIdentity(identity); |
| 4933 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4934 | } |
| 4935 | |
| 4936 | /** |
| 4937 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4938 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4939 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4940 | */ |
| 4941 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4942 | IImsServiceFeatureCallback callback) { |
| 4943 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4944 | |
| 4945 | final long identity = Binder.clearCallingIdentity(); |
| 4946 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4947 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4948 | // may happen if the device does not support IMS. |
| 4949 | return null; |
| 4950 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4951 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4952 | } finally { |
| 4953 | Binder.restoreCallingIdentity(identity); |
| 4954 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4955 | } |
| 4956 | |
| 4957 | /** |
| 4958 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4959 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4960 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4961 | * listener for feature updates. |
| 4962 | */ |
| 4963 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4964 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4965 | |
| 4966 | final long identity = Binder.clearCallingIdentity(); |
| 4967 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4968 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4969 | // may happen if the device does not support IMS. |
| 4970 | return null; |
| 4971 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4972 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4973 | } finally { |
| 4974 | Binder.restoreCallingIdentity(identity); |
| 4975 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4976 | } |
| 4977 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4978 | /** |
| 4979 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4980 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4981 | */ |
| 4982 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4983 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4984 | |
| 4985 | final long identity = Binder.clearCallingIdentity(); |
| 4986 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4987 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4988 | // may happen if the device does not support IMS. |
| 4989 | return null; |
| 4990 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4991 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4992 | } finally { |
| 4993 | Binder.restoreCallingIdentity(identity); |
| 4994 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4995 | } |
| 4996 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4997 | /** |
| 4998 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4999 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5000 | */ |
| 5001 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5002 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5003 | |
| 5004 | final long identity = Binder.clearCallingIdentity(); |
| 5005 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5006 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5007 | // may happen if the device does not support IMS. |
| 5008 | return null; |
| 5009 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5010 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5011 | } finally { |
| 5012 | Binder.restoreCallingIdentity(identity); |
| 5013 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5014 | } |
| 5015 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5016 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5017 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5018 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5019 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5020 | * @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] | 5021 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5022 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5023 | * @param packageName The name of the package that the current configuration will be replaced |
| 5024 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5025 | * @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] | 5026 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5027 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5028 | int[] featureTypes, String packageName) { |
| 5029 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5030 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5031 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5032 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5033 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5034 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5035 | final long identity = Binder.clearCallingIdentity(); |
| 5036 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5037 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5038 | // may happen if the device does not support IMS. |
| 5039 | return false; |
| 5040 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5041 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5042 | for (int featureType : featureTypes) { |
| 5043 | featureConfig.put(featureType, packageName); |
| 5044 | } |
| 5045 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5046 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5047 | } finally { |
| 5048 | Binder.restoreCallingIdentity(identity); |
| 5049 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5050 | } |
| 5051 | |
| 5052 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5053 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5054 | * |
| 5055 | * @param slotId The slot that the ImsService is associated with. |
| 5056 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5057 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5058 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5059 | * @return the package name of the ImsService configuration. |
| 5060 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5061 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5062 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5063 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5064 | TelephonyPermissions |
| 5065 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5066 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5067 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5068 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5069 | final long identity = Binder.clearCallingIdentity(); |
| 5070 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5071 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5072 | // may happen if the device does not support IMS. |
| 5073 | return ""; |
| 5074 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5075 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5076 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5077 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5078 | } finally { |
| 5079 | Binder.restoreCallingIdentity(identity); |
| 5080 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5081 | } |
| 5082 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5083 | /** |
| 5084 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5085 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5086 | * @param callback A callback with an integer containing the |
| 5087 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5088 | */ |
| 5089 | @Override |
| 5090 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5091 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5092 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5093 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5094 | "IMS not available on device."); |
| 5095 | } |
| 5096 | final long token = Binder.clearCallingIdentity(); |
| 5097 | try { |
| 5098 | int slotId = getSlotIndex(subId); |
| 5099 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5100 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5101 | + subId + "'"); |
| 5102 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5103 | } |
| 5104 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5105 | try { |
| 5106 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5107 | } catch (RemoteException e) { |
| 5108 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5109 | + "Ignore"); |
| 5110 | } |
| 5111 | }); |
| 5112 | } finally { |
| 5113 | Binder.restoreCallingIdentity(token); |
| 5114 | } |
| 5115 | } |
| 5116 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5117 | public void setImsRegistrationState(boolean registered) { |
| 5118 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5119 | |
| 5120 | final long identity = Binder.clearCallingIdentity(); |
| 5121 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5122 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5123 | } finally { |
| 5124 | Binder.restoreCallingIdentity(identity); |
| 5125 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5126 | } |
| 5127 | |
| 5128 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5129 | * Set the network selection mode to automatic. |
| 5130 | * |
| 5131 | */ |
| 5132 | @Override |
| 5133 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5134 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5135 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5136 | |
| 5137 | final long identity = Binder.clearCallingIdentity(); |
| 5138 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5139 | if (!isActiveSubscription(subId)) { |
| 5140 | return; |
| 5141 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5142 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5143 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5144 | } finally { |
| 5145 | Binder.restoreCallingIdentity(identity); |
| 5146 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5147 | } |
| 5148 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5149 | /** |
| 5150 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5151 | * |
| 5152 | * @param subId the id of the subscription. |
| 5153 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5154 | * the operator to attach to. |
| 5155 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5156 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5157 | * normal network selection next time. |
| 5158 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5159 | */ |
| 5160 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5161 | public boolean setNetworkSelectionModeManual( |
| 5162 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5163 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5164 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5165 | |
| 5166 | if (!isActiveSubscription(subId)) { |
| 5167 | return false; |
| 5168 | } |
| 5169 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5170 | final long identity = Binder.clearCallingIdentity(); |
| 5171 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5172 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5173 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5174 | if (DBG) { |
| 5175 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5176 | + " operator: " + operatorInfo); |
| 5177 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5178 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5179 | } finally { |
| 5180 | Binder.restoreCallingIdentity(identity); |
| 5181 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5182 | } |
| 5183 | |
| 5184 | /** |
| 5185 | * Scans for available networks. |
| 5186 | */ |
| 5187 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5188 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5189 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5190 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5191 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5192 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5193 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5194 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5195 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5196 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5197 | .setCallingPid(Binder.getCallingPid()) |
| 5198 | .setCallingUid(Binder.getCallingUid()) |
| 5199 | .setMethod("getCellNetworkScanResults") |
| 5200 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5201 | .build()); |
| 5202 | switch (locationResult) { |
| 5203 | case DENIED_HARD: |
| 5204 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5205 | case DENIED_SOFT: |
| 5206 | return null; |
| 5207 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5208 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5209 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5210 | try { |
| 5211 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5212 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5213 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5214 | } finally { |
| 5215 | Binder.restoreCallingIdentity(identity); |
| 5216 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5217 | } |
| 5218 | |
| 5219 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5220 | * Get the call forwarding info, given the call forwarding reason. |
| 5221 | */ |
| 5222 | @Override |
| 5223 | public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) { |
| 5224 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5225 | long identity = Binder.clearCallingIdentity(); |
| 5226 | try { |
| 5227 | if (DBG) { |
| 5228 | log("getCallForwarding: subId " + subId |
| 5229 | + " callForwardingReason" + callForwardingReason); |
| 5230 | } |
| 5231 | return (CallForwardingInfo) sendRequest( |
| 5232 | CMD_GET_CALL_FORWARDING, callForwardingReason, subId); |
| 5233 | } finally { |
| 5234 | Binder.restoreCallingIdentity(identity); |
| 5235 | } |
| 5236 | } |
| 5237 | |
| 5238 | /** |
| 5239 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5240 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5241 | */ |
| 5242 | @Override |
| 5243 | public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) { |
| 5244 | enforceModifyPermission(); |
| 5245 | long identity = Binder.clearCallingIdentity(); |
| 5246 | try { |
| 5247 | if (DBG) { |
| 5248 | log("setCallForwarding: subId " + subId |
| 5249 | + " callForwardingInfo" + callForwardingInfo); |
| 5250 | } |
| 5251 | return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId); |
| 5252 | } finally { |
| 5253 | Binder.restoreCallingIdentity(identity); |
| 5254 | } |
| 5255 | } |
| 5256 | |
| 5257 | /** |
| 5258 | * Get the call forwarding info, given the call forwarding reason. |
| 5259 | */ |
| 5260 | @Override |
| 5261 | public int getCallWaitingStatus(int subId) { |
| 5262 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5263 | long identity = Binder.clearCallingIdentity(); |
| 5264 | try { |
| 5265 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 5266 | return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId); |
| 5267 | } finally { |
| 5268 | Binder.restoreCallingIdentity(identity); |
| 5269 | } |
| 5270 | } |
| 5271 | |
| 5272 | /** |
| 5273 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5274 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5275 | */ |
| 5276 | @Override |
| 5277 | public boolean setCallWaitingStatus(int subId, boolean isEnable) { |
| 5278 | enforceModifyPermission(); |
| 5279 | long identity = Binder.clearCallingIdentity(); |
| 5280 | try { |
| 5281 | if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable); |
| 5282 | return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId); |
| 5283 | } finally { |
| 5284 | Binder.restoreCallingIdentity(identity); |
| 5285 | } |
| 5286 | } |
| 5287 | |
| 5288 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5289 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5290 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5291 | * @param subId id of the subscription |
| 5292 | * @param request contains the radio access networks with bands/channels to scan |
| 5293 | * @param messenger callback messenger for scan results or errors |
| 5294 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5295 | * @return the id of the requested scan which can be used to stop the scan. |
| 5296 | */ |
| 5297 | @Override |
| 5298 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5299 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5300 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5301 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5302 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5303 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5304 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5305 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5306 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5307 | .setCallingPid(Binder.getCallingPid()) |
| 5308 | .setCallingUid(Binder.getCallingUid()) |
| 5309 | .setMethod("requestNetworkScan") |
| 5310 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5311 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5312 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5313 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5314 | if (e != null) { |
| 5315 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5316 | throw e; |
| 5317 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5318 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5319 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5320 | } |
| 5321 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5322 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5323 | int callingUid = Binder.getCallingUid(); |
| 5324 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5325 | final long identity = Binder.clearCallingIdentity(); |
| 5326 | try { |
| 5327 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5328 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5329 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5330 | } finally { |
| 5331 | Binder.restoreCallingIdentity(identity); |
| 5332 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5333 | } |
| 5334 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5335 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5336 | NetworkScanRequest request, int subId) { |
| 5337 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5338 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5339 | boolean hasNetworkScanPermission = |
| 5340 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5341 | == PERMISSION_GRANTED; |
| 5342 | |
| 5343 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5344 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5345 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5346 | } |
| 5347 | |
| 5348 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5349 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5350 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5351 | return new SecurityException("Specific channels must not be" |
| 5352 | + " scanned without location access."); |
| 5353 | } |
| 5354 | } |
| 5355 | } |
| 5356 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5357 | return null; |
| 5358 | } |
| 5359 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5360 | /** |
| 5361 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5362 | * |
| 5363 | * @param subId id of the subscription |
| 5364 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5365 | */ |
| 5366 | @Override |
| 5367 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5368 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5369 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5370 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5371 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5372 | final long identity = Binder.clearCallingIdentity(); |
| 5373 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5374 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5375 | } finally { |
| 5376 | Binder.restoreCallingIdentity(identity); |
| 5377 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5378 | } |
| 5379 | |
| 5380 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5381 | * Get the calculated preferred network type. |
| 5382 | * Used for debugging incorrect network type. |
| 5383 | * |
| 5384 | * @return the preferred network type, defined in RILConstants.java. |
| 5385 | */ |
| 5386 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5387 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5388 | final Phone defaultPhone = getDefaultPhone(); |
| 5389 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5390 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5391 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5392 | } |
| 5393 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5394 | final long identity = Binder.clearCallingIdentity(); |
| 5395 | try { |
| 5396 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5397 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5398 | } finally { |
| 5399 | Binder.restoreCallingIdentity(identity); |
| 5400 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5401 | } |
| 5402 | |
| 5403 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5404 | * Get the preferred network type. |
| 5405 | * Used for device configuration by some CDMA operators. |
| 5406 | * |
| 5407 | * @return the preferred network type, defined in RILConstants.java. |
| 5408 | */ |
| 5409 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5410 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5411 | TelephonyPermissions |
| 5412 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5413 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5414 | |
| 5415 | final long identity = Binder.clearCallingIdentity(); |
| 5416 | try { |
| 5417 | if (DBG) log("getPreferredNetworkType"); |
| 5418 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5419 | int networkType = (result != null ? result[0] : -1); |
| 5420 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5421 | return networkType; |
| 5422 | } finally { |
| 5423 | Binder.restoreCallingIdentity(identity); |
| 5424 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5425 | } |
| 5426 | |
| 5427 | /** |
| 5428 | * Set the preferred network type. |
| 5429 | * Used for device configuration by some CDMA operators. |
| 5430 | * |
| 5431 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5432 | * @return true on success; false on any failure. |
| 5433 | */ |
| 5434 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5435 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5436 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5437 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5438 | |
| 5439 | final long identity = Binder.clearCallingIdentity(); |
| 5440 | try { |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5441 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5442 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5443 | return setPreferredNetworkTypesInternal(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5444 | } finally { |
| 5445 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5446 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5447 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5448 | |
| 5449 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5450 | * Get the allowed network types that store in the telephony provider. |
| 5451 | * |
| 5452 | * @param subId the id of the subscription. |
| 5453 | * @return allowedNetworkTypes the allowed network types. |
| 5454 | */ |
| 5455 | @Override |
| 5456 | public long getAllowedNetworkTypes(int subId) { |
| 5457 | TelephonyPermissions |
| 5458 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5459 | mApp, subId, "getAllowedNetworkTypes"); |
| 5460 | |
| 5461 | final long identity = Binder.clearCallingIdentity(); |
| 5462 | try { |
| 5463 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5464 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5465 | } finally { |
| 5466 | Binder.restoreCallingIdentity(identity); |
| 5467 | } |
| 5468 | } |
| 5469 | |
| 5470 | /** |
| 5471 | * Set the allowed network types. |
| 5472 | * |
| 5473 | * @param subId the id of the subscription. |
| 5474 | * @param allowedNetworkTypes the allowed network types. |
| 5475 | * @return true on success; false on any failure. |
| 5476 | */ |
| 5477 | @Override |
| 5478 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5479 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5480 | mApp, subId, "setAllowedNetworkTypes"); |
| 5481 | final long identity = Binder.clearCallingIdentity(); |
| 5482 | try { |
| 5483 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5484 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5485 | String.valueOf(allowedNetworkTypes)); |
| 5486 | return setPreferredNetworkTypesInternal(subId); |
| 5487 | } finally { |
| 5488 | Binder.restoreCallingIdentity(identity); |
| 5489 | } |
| 5490 | } |
| 5491 | |
| 5492 | private boolean setPreferredNetworkTypesInternal(int subId) { |
| 5493 | long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType( |
| 5494 | Settings.Global.getInt(mApp.getContentResolver(), |
| 5495 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5496 | RILConstants.PREFERRED_NETWORK_MODE)); |
| 5497 | long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty( |
| 5498 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5499 | int networkMode = RadioAccessFamily.getNetworkTypeFromRaf( |
| 5500 | (int) (networkTypeBitMask & allowedNetworkTypes)); |
| 5501 | |
| 5502 | if (DBG) { |
| 5503 | log("setPreferredNetworkTypesInternal: subId " + subId |
| 5504 | + " networkTypes " + networkTypeBitMask |
| 5505 | + " allowedNetworkTypes " + allowedNetworkTypes |
| 5506 | + " networkMode " + networkMode); |
| 5507 | } |
| 5508 | |
| 5509 | Boolean success = (Boolean) sendRequest( |
| 5510 | CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId); |
| 5511 | if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail")); |
| 5512 | return success; |
| 5513 | } |
| 5514 | |
| 5515 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5516 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5517 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5518 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5519 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5520 | * @hide |
| 5521 | */ |
| 5522 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5523 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5524 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5525 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5526 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5527 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5528 | if (phone != null) { |
| 5529 | return phone.hasMatchedTetherApnSetting(); |
| 5530 | } else { |
| 5531 | return false; |
| 5532 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5533 | } finally { |
| 5534 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5535 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5536 | } |
| 5537 | |
| 5538 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5539 | * Set mobile data enabled |
| 5540 | * Used by the user through settings etc to turn on/off mobile data |
| 5541 | * |
| 5542 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5543 | */ |
| 5544 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5545 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5546 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5547 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5548 | |
| 5549 | final long identity = Binder.clearCallingIdentity(); |
| 5550 | try { |
| 5551 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5552 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5553 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5554 | if (phone != null) { |
| 5555 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5556 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5557 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5558 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5559 | } |
| 5560 | } finally { |
| 5561 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5562 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5563 | } |
| 5564 | |
| 5565 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5566 | * Enable or disable always reporting signal strength changes from radio. |
| 5567 | * |
| 5568 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5569 | */ |
| 5570 | @Override |
| 5571 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5572 | enforceModifyPermission(); |
| 5573 | enforceSystemCaller(); |
| 5574 | |
| 5575 | final long identity = Binder.clearCallingIdentity(); |
| 5576 | final Phone phone = getPhone(subId); |
| 5577 | try { |
| 5578 | if (phone != null) { |
| 5579 | if (DBG) { |
| 5580 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5581 | + " isEnable=" + isEnable); |
| 5582 | } |
| 5583 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5584 | } else { |
| 5585 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5586 | + subId); |
| 5587 | } |
| 5588 | } finally { |
| 5589 | Binder.restoreCallingIdentity(identity); |
| 5590 | } |
| 5591 | } |
| 5592 | |
| 5593 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5594 | * Get the user enabled state of Mobile Data. |
| 5595 | * |
| 5596 | * TODO: remove and use isUserDataEnabled. |
| 5597 | * This can't be removed now because some vendor codes |
| 5598 | * calls through ITelephony directly while they should |
| 5599 | * use TelephonyManager. |
| 5600 | * |
| 5601 | * @return true on enabled |
| 5602 | */ |
| 5603 | @Override |
| 5604 | public boolean getDataEnabled(int subId) { |
| 5605 | return isUserDataEnabled(subId); |
| 5606 | } |
| 5607 | |
| 5608 | /** |
| 5609 | * Get whether mobile data is enabled per user setting. |
| 5610 | * |
| 5611 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5612 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5613 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5614 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5615 | * |
| 5616 | * @return {@code true} if data is enabled else {@code false} |
| 5617 | */ |
| 5618 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5619 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5620 | try { |
| 5621 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5622 | null); |
| 5623 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5624 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5625 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5626 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5627 | |
| 5628 | final long identity = Binder.clearCallingIdentity(); |
| 5629 | try { |
| 5630 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5631 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5632 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5633 | if (phone != null) { |
| 5634 | boolean retVal = phone.isUserDataEnabled(); |
| 5635 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5636 | return retVal; |
| 5637 | } else { |
| 5638 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5639 | return false; |
| 5640 | } |
| 5641 | } finally { |
| 5642 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5643 | } |
| 5644 | } |
| 5645 | |
| 5646 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5647 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5648 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5649 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5650 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5651 | * @return {@code true} if the overall data connection is capable; {@code false} if not. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5652 | */ |
| 5653 | @Override |
| 5654 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5655 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5656 | |
| 5657 | final long identity = Binder.clearCallingIdentity(); |
| 5658 | try { |
| 5659 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5660 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5661 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5662 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5663 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5664 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5665 | return retVal; |
| 5666 | } else { |
| 5667 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5668 | return false; |
| 5669 | } |
| 5670 | } finally { |
| 5671 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5672 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5673 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5674 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5675 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 5676 | Phone phone) { |
| 5677 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5678 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5679 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5680 | || subController == null) return privilegeFromSim; |
| 5681 | |
| 5682 | int uid = Binder.getCallingUid(); |
| 5683 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5684 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5685 | |
| 5686 | final long identity = Binder.clearCallingIdentity(); |
| 5687 | try { |
| 5688 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5689 | SubscriptionManager subManager = (SubscriptionManager) |
| 5690 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5691 | for (String pkg : packages) { |
| 5692 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5693 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5694 | } |
| 5695 | } |
| 5696 | return privilegeFromSim; |
| 5697 | } finally { |
| 5698 | Binder.restoreCallingIdentity(identity); |
| 5699 | } |
| 5700 | } |
| 5701 | |
| 5702 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5703 | String pkgName) { |
| 5704 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5705 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5706 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5707 | || subController == null) return privilegeFromSim; |
| 5708 | |
| 5709 | final long identity = Binder.clearCallingIdentity(); |
| 5710 | try { |
| 5711 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5712 | SubscriptionManager subManager = (SubscriptionManager) |
| 5713 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5714 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5715 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5716 | } finally { |
| 5717 | Binder.restoreCallingIdentity(identity); |
| 5718 | } |
| 5719 | } |
| 5720 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5721 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5722 | public int getCarrierPrivilegeStatus(int subId) { |
| 5723 | final Phone phone = getPhone(subId); |
| 5724 | if (phone == null) { |
| 5725 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5726 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5727 | } |
| 5728 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5729 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5730 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5731 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5732 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5733 | |
| 5734 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5735 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 5736 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5737 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5738 | |
| 5739 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5740 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5741 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5742 | final Phone phone = getPhone(subId); |
| 5743 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5744 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5745 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5746 | } |
| 5747 | UiccProfile profile = |
| 5748 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5749 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5750 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5751 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5752 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5753 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5754 | profile.getCarrierPrivilegeStatusForUid( |
| 5755 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5756 | } |
| 5757 | |
| 5758 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5759 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5760 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5761 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5762 | } |
| 5763 | |
| 5764 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5765 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5766 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5767 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5768 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5769 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5770 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5771 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5772 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5773 | } |
| 5774 | |
| 5775 | @Override |
| 5776 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5777 | if (TextUtils.isEmpty(pkgName)) |
| 5778 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5779 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5780 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5781 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5782 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5783 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5784 | continue; |
| 5785 | } |
| 5786 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5787 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5788 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5789 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5790 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5791 | break; |
| 5792 | } |
| 5793 | } |
| 5794 | |
| 5795 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5796 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5797 | |
| 5798 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5799 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5800 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5801 | loge("phoneId " + phoneId + " is not valid."); |
| 5802 | return null; |
| 5803 | } |
| 5804 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5805 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5806 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5807 | return null ; |
| 5808 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5809 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5810 | } |
| 5811 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5812 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5813 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5814 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5815 | List<String> privilegedPackages = new ArrayList<>(); |
| 5816 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5817 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5818 | // has UICC in that slot. |
| 5819 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5820 | if (card.hasCarrierPrivilegeRules()) { |
| 5821 | if (packages == null) { |
| 5822 | // Only check packages in user 0 for now |
| 5823 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5824 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5825 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5826 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame^] | 5827 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5828 | } |
| 5829 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5830 | PackageInfo pkgInfo = packages.get(p); |
| 5831 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5832 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5833 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5834 | privilegedPackages.add(pkgInfo.packageName); |
| 5835 | } |
| 5836 | } |
| 5837 | } |
| 5838 | } |
| 5839 | return privilegedPackages; |
| 5840 | } |
| 5841 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5842 | @Override |
| 5843 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5844 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5845 | |
| 5846 | final long identity = Binder.clearCallingIdentity(); |
| 5847 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5848 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5849 | try { |
| 5850 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5851 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5852 | } |
| 5853 | } finally { |
| 5854 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5855 | } |
| 5856 | return privilegedPackages; |
| 5857 | } |
| 5858 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5859 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5860 | final Phone phone = getPhone(subId); |
| 5861 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5862 | if (card == null) { |
| 5863 | loge("getIccId: No UICC"); |
| 5864 | return null; |
| 5865 | } |
| 5866 | String iccId = card.getIccId(); |
| 5867 | if (TextUtils.isEmpty(iccId)) { |
| 5868 | loge("getIccId: ICC ID is null or empty."); |
| 5869 | return null; |
| 5870 | } |
| 5871 | return iccId; |
| 5872 | } |
| 5873 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5874 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5875 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5876 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5877 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5878 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5879 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5880 | final long identity = Binder.clearCallingIdentity(); |
| 5881 | try { |
| 5882 | final String iccId = getIccId(subId); |
| 5883 | final Phone phone = getPhone(subId); |
| 5884 | if (phone == null) { |
| 5885 | return false; |
| 5886 | } |
| 5887 | final String subscriberId = phone.getSubscriberId(); |
| 5888 | |
| 5889 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame^] | 5890 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5891 | + subscriberId + " to " + number); |
| 5892 | } |
| 5893 | |
| 5894 | if (TextUtils.isEmpty(iccId)) { |
| 5895 | return false; |
| 5896 | } |
| 5897 | |
| 5898 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5899 | |
| 5900 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5901 | if (alphaTag == null) { |
| 5902 | editor.remove(alphaTagPrefKey); |
| 5903 | } else { |
| 5904 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5905 | } |
| 5906 | |
| 5907 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5908 | // track all merged IMSIs based on line number |
| 5909 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5910 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5911 | if (number == null) { |
| 5912 | editor.remove(numberPrefKey); |
| 5913 | editor.remove(subscriberPrefKey); |
| 5914 | } else { |
| 5915 | editor.putString(numberPrefKey, number); |
| 5916 | editor.putString(subscriberPrefKey, subscriberId); |
| 5917 | } |
| 5918 | |
| 5919 | editor.commit(); |
| 5920 | return true; |
| 5921 | } finally { |
| 5922 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5923 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5924 | } |
| 5925 | |
| 5926 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5927 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 5928 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5929 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5930 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5931 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5932 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5933 | return null; |
| 5934 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5935 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5936 | final long identity = Binder.clearCallingIdentity(); |
| 5937 | try { |
| 5938 | String iccId = getIccId(subId); |
| 5939 | if (iccId != null) { |
| 5940 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5941 | if (DBG_MERGE) { |
| 5942 | log("getLine1NumberForDisplay returning " |
| 5943 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5944 | } |
| 5945 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5946 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5947 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5948 | return null; |
| 5949 | } finally { |
| 5950 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5951 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5952 | } |
| 5953 | |
| 5954 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5955 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 5956 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5957 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5958 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5959 | return null; |
| 5960 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5961 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5962 | final long identity = Binder.clearCallingIdentity(); |
| 5963 | try { |
| 5964 | String iccId = getIccId(subId); |
| 5965 | if (iccId != null) { |
| 5966 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5967 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5968 | } |
| 5969 | return null; |
| 5970 | } finally { |
| 5971 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5972 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5973 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5974 | |
| 5975 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5976 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 5977 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5978 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5979 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5980 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5981 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5982 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5983 | return null; |
| 5984 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5985 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5986 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5987 | // the process, where TelephonyManager was instantiated. |
| 5988 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5989 | final long identity = Binder.clearCallingIdentity(); |
| 5990 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5991 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5992 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5993 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5994 | |
| 5995 | // Figure out what subscribers are currently active |
| 5996 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5997 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5998 | // Only consider subs which match the current subId |
| 5999 | // This logic can be simplified. See b/131189269 for progress. |
| 6000 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6001 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6002 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6003 | |
| 6004 | // First pass, find a number override for an active subscriber |
| 6005 | String mergeNumber = null; |
| 6006 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6007 | for (String key : prefs.keySet()) { |
| 6008 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6009 | final String subscriberId = (String) prefs.get(key); |
| 6010 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6011 | final String iccId = key.substring( |
| 6012 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6013 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6014 | mergeNumber = (String) prefs.get(numberKey); |
| 6015 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame^] | 6016 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6017 | + " for active subscriber " + subscriberId); |
| 6018 | } |
| 6019 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6020 | break; |
| 6021 | } |
| 6022 | } |
| 6023 | } |
| 6024 | } |
| 6025 | |
| 6026 | // Shortcut when no active merged subscribers |
| 6027 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6028 | return null; |
| 6029 | } |
| 6030 | |
| 6031 | // Second pass, find all subscribers under that line override |
| 6032 | final ArraySet<String> result = new ArraySet<>(); |
| 6033 | for (String key : prefs.keySet()) { |
| 6034 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6035 | final String number = (String) prefs.get(key); |
| 6036 | if (mergeNumber.equals(number)) { |
| 6037 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6038 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6039 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6040 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6041 | result.add(subscriberId); |
| 6042 | } |
| 6043 | } |
| 6044 | } |
| 6045 | } |
| 6046 | |
| 6047 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6048 | Arrays.sort(resultArray); |
| 6049 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame^] | 6050 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6051 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6052 | } |
| 6053 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6054 | } finally { |
| 6055 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6056 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6057 | } |
| 6058 | |
| 6059 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6060 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 6061 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 6062 | |
| 6063 | final long identity = Binder.clearCallingIdentity(); |
| 6064 | try { |
| 6065 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6066 | TelephonyManager.class); |
| 6067 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6068 | if (subscriberId == null) { |
| 6069 | if (DBG) { |
| 6070 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 6071 | + subId); |
| 6072 | } |
| 6073 | return null; |
| 6074 | } |
| 6075 | |
| 6076 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6077 | .getSubscriptionInfo(subId); |
| 6078 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6079 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6080 | if (groupUuid == null) { |
| 6081 | return new String[]{subscriberId}; |
| 6082 | } |
| 6083 | |
| 6084 | // Get all subscriberIds from the group. |
| 6085 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6086 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6087 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 6088 | null); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6089 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6090 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6091 | if (subscriberId != null) { |
| 6092 | mergedSubscriberIds.add(subscriberId); |
| 6093 | } |
| 6094 | } |
| 6095 | |
| 6096 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6097 | } finally { |
| 6098 | Binder.restoreCallingIdentity(identity); |
| 6099 | |
| 6100 | } |
| 6101 | } |
| 6102 | |
| 6103 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6104 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6105 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6106 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6107 | |
| 6108 | final long identity = Binder.clearCallingIdentity(); |
| 6109 | try { |
| 6110 | final Phone phone = getPhone(subId); |
| 6111 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6112 | } finally { |
| 6113 | Binder.restoreCallingIdentity(identity); |
| 6114 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6115 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6116 | |
| 6117 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6118 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6119 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6120 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6121 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6122 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6123 | |
| 6124 | final long identity = Binder.clearCallingIdentity(); |
| 6125 | try { |
| 6126 | final Phone phone = getPhone(subId); |
| 6127 | if (phone == null) { |
| 6128 | return false; |
| 6129 | } |
| 6130 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6131 | cdmaNonRoamingList); |
| 6132 | } finally { |
| 6133 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6134 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6135 | } |
| 6136 | |
| 6137 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6138 | @Deprecated |
| 6139 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6140 | enforceModifyPermission(); |
| 6141 | |
| 6142 | int returnValue = 0; |
| 6143 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6144 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6145 | if(result.exception == null) { |
| 6146 | if (result.result != null) { |
| 6147 | byte[] responseData = (byte[])(result.result); |
| 6148 | if(responseData.length > oemResp.length) { |
| 6149 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6150 | responseData.length + "bytes. Buffer Size is " + |
| 6151 | oemResp.length + "bytes."); |
| 6152 | } |
| 6153 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6154 | returnValue = responseData.length; |
| 6155 | } |
| 6156 | } else { |
| 6157 | CommandException ex = (CommandException) result.exception; |
| 6158 | returnValue = ex.getCommandError().ordinal(); |
| 6159 | if(returnValue > 0) returnValue *= -1; |
| 6160 | } |
| 6161 | } catch (RuntimeException e) { |
| 6162 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6163 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6164 | if(returnValue > 0) returnValue *= -1; |
| 6165 | } |
| 6166 | |
| 6167 | return returnValue; |
| 6168 | } |
| 6169 | |
| 6170 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6171 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6172 | try { |
| 6173 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6174 | } catch (RuntimeException e) { |
| 6175 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6176 | } |
| 6177 | } |
| 6178 | |
| 6179 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6180 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6181 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6182 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6183 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6184 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6185 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6186 | final long identity = Binder.clearCallingIdentity(); |
| 6187 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6188 | TelephonyPermissions |
| 6189 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6190 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6191 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6192 | } finally { |
| 6193 | Binder.restoreCallingIdentity(identity); |
| 6194 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6195 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6196 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6197 | |
| 6198 | @Override |
| 6199 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6200 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6201 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6202 | |
| 6203 | final long identity = Binder.clearCallingIdentity(); |
| 6204 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6205 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6206 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6207 | } finally { |
| 6208 | Binder.restoreCallingIdentity(identity); |
| 6209 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6210 | } |
| 6211 | |
| 6212 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6213 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6214 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6215 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6216 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6217 | return false; |
| 6218 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6219 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6220 | final long identity = Binder.clearCallingIdentity(); |
| 6221 | try { |
| 6222 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6223 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6224 | // In the long run, we may instead need to check if there exists a connection service |
| 6225 | // which can support video calling. |
| 6226 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6227 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6228 | return imsManager.isVtEnabledByPlatform() |
| 6229 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6230 | && imsManager.isVtEnabledByUser(); |
| 6231 | } finally { |
| 6232 | Binder.restoreCallingIdentity(identity); |
| 6233 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6234 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6235 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6236 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6237 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6238 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6239 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6240 | mApp, subId, callingPackage, callingFeatureId, |
| 6241 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6242 | return false; |
| 6243 | } |
| 6244 | |
| 6245 | final long identity = Binder.clearCallingIdentity(); |
| 6246 | try { |
| 6247 | CarrierConfigManager configManager = |
| 6248 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6249 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6250 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6251 | } finally { |
| 6252 | Binder.restoreCallingIdentity(identity); |
| 6253 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6254 | } |
| 6255 | |
| 6256 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6257 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6258 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6259 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6260 | return false; |
| 6261 | } |
| 6262 | |
| 6263 | final long identity = Binder.clearCallingIdentity(); |
| 6264 | try { |
| 6265 | CarrierConfigManager configManager = |
| 6266 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6267 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6268 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6269 | } finally { |
| 6270 | Binder.restoreCallingIdentity(identity); |
| 6271 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6272 | } |
| 6273 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6274 | @Override |
| 6275 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6276 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6277 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6278 | } |
| 6279 | |
| 6280 | @Override |
| 6281 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6282 | final long identity = Binder.clearCallingIdentity(); |
| 6283 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6284 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6285 | } finally { |
| 6286 | Binder.restoreCallingIdentity(identity); |
| 6287 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6288 | } |
| 6289 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6290 | /** |
| 6291 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6292 | * support for the feature and device firmware support. |
| 6293 | * |
| 6294 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6295 | */ |
| 6296 | @Override |
| 6297 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6298 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6299 | final Phone phone = getPhone(subscriptionId); |
| 6300 | if (phone == null) { |
| 6301 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6302 | return false; |
| 6303 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6304 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6305 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6306 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6307 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6308 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6309 | return isCarrierSupported && isDeviceSupported; |
| 6310 | } finally { |
| 6311 | Binder.restoreCallingIdentity(identity); |
| 6312 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6313 | } |
| 6314 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6315 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6316 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6317 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6318 | * 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] | 6319 | */ |
| 6320 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6321 | final long identity = Binder.clearCallingIdentity(); |
| 6322 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6323 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6324 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6325 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6326 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6327 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6328 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6329 | } finally { |
| 6330 | Binder.restoreCallingIdentity(identity); |
| 6331 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6332 | } |
| 6333 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6334 | @Deprecated |
| 6335 | @Override |
| 6336 | public String getDeviceId(String callingPackage) { |
| 6337 | return getDeviceIdWithFeature(callingPackage, null); |
| 6338 | } |
| 6339 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6340 | /** |
| 6341 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6342 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6343 | * |
| 6344 | * <p>Requires Permission: |
| 6345 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6346 | */ |
| 6347 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6348 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6349 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6350 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6351 | return null; |
| 6352 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6353 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6354 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6355 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6356 | return null; |
| 6357 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6358 | |
| 6359 | final long identity = Binder.clearCallingIdentity(); |
| 6360 | try { |
| 6361 | return phone.getDeviceId(); |
| 6362 | } finally { |
| 6363 | Binder.restoreCallingIdentity(identity); |
| 6364 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6365 | } |
| 6366 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6367 | /** |
| 6368 | * {@hide} |
| 6369 | * Returns the IMS Registration Status on a particular subid |
| 6370 | * |
| 6371 | * @param subId |
| 6372 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6373 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6374 | Phone phone = getPhone(subId); |
| 6375 | if (phone != null) { |
| 6376 | return phone.isImsRegistered(); |
| 6377 | } else { |
| 6378 | return false; |
| 6379 | } |
| 6380 | } |
| 6381 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6382 | @Override |
| 6383 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6384 | final long identity = Binder.clearCallingIdentity(); |
| 6385 | try { |
| 6386 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6387 | } finally { |
| 6388 | Binder.restoreCallingIdentity(identity); |
| 6389 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6390 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6391 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6392 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6393 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6394 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6395 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6396 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6397 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6398 | } |
| 6399 | final long identity = Binder.clearCallingIdentity(); |
| 6400 | try { |
| 6401 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6402 | } finally { |
| 6403 | Binder.restoreCallingIdentity(identity); |
| 6404 | } |
| 6405 | } |
| 6406 | |
| 6407 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6408 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6409 | final long identity = Binder.clearCallingIdentity(); |
| 6410 | try { |
| 6411 | Phone phone = getPhone(subscriptionId); |
| 6412 | if (phone == null) { |
| 6413 | return null; |
| 6414 | } |
| 6415 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6416 | } finally { |
| 6417 | Binder.restoreCallingIdentity(identity); |
| 6418 | } |
| 6419 | } |
| 6420 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6421 | /** |
| 6422 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6423 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6424 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6425 | final long identity = Binder.clearCallingIdentity(); |
| 6426 | try { |
| 6427 | Phone phone = getPhone(subId); |
| 6428 | if (phone != null) { |
| 6429 | return phone.isWifiCallingEnabled(); |
| 6430 | } else { |
| 6431 | return false; |
| 6432 | } |
| 6433 | } finally { |
| 6434 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6435 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6436 | } |
| 6437 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6438 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6439 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6440 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6441 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6442 | final long identity = Binder.clearCallingIdentity(); |
| 6443 | try { |
| 6444 | Phone phone = getPhone(subId); |
| 6445 | if (phone != null) { |
| 6446 | return phone.isVideoEnabled(); |
| 6447 | } else { |
| 6448 | return false; |
| 6449 | } |
| 6450 | } finally { |
| 6451 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6452 | } |
| 6453 | } |
| 6454 | |
| 6455 | /** |
| 6456 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6457 | * defined in {@link ImsRegistrationImplBase}. |
| 6458 | */ |
| 6459 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6460 | final long identity = Binder.clearCallingIdentity(); |
| 6461 | try { |
| 6462 | Phone phone = getPhone(subId); |
| 6463 | if (phone != null) { |
| 6464 | return phone.getImsRegistrationTech(); |
| 6465 | } else { |
| 6466 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6467 | } |
| 6468 | } finally { |
| 6469 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6470 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6471 | } |
| 6472 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6473 | @Override |
| 6474 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6475 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6476 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6477 | return; |
| 6478 | } |
| 6479 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6480 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6481 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6482 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6483 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6484 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6485 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6486 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6487 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6488 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6489 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6490 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6491 | // There has been issues when Sms raw table somehow stores orphan |
| 6492 | // fragments. They lead to garbled message when new fragments come |
| 6493 | // in and combined with those stale ones. In case this happens again, |
| 6494 | // user can reset all network settings which will clean up this table. |
| 6495 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6496 | // Clean up IMS settings as well here. |
| 6497 | int slotId = getSlotIndex(subId); |
| 6498 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6499 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6500 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6501 | |
| 6502 | // Erase modem config if erase modem on network setting is enabled. |
| 6503 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6504 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6505 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6506 | sendEraseModemConfig(getDefaultPhone()); |
| 6507 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6508 | } finally { |
| 6509 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6510 | } |
| 6511 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6512 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6513 | private void cleanUpSmsRawTable(Context context) { |
| 6514 | ContentResolver resolver = context.getContentResolver(); |
| 6515 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6516 | resolver.delete(uri, null, null); |
| 6517 | } |
| 6518 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6519 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6520 | public String getSimLocaleForSubscriber(int subId) { |
| 6521 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6522 | final Phone phone = getPhone(subId); |
| 6523 | if (phone == null) { |
| 6524 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6525 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6526 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6527 | final long identity = Binder.clearCallingIdentity(); |
| 6528 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6529 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6530 | phone.getContext().getOpPackageName(), null); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6531 | if (info == null) { |
| 6532 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6533 | return null; |
| 6534 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6535 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6536 | // preferences (EF-PL and EF-LI)... |
| 6537 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6538 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6539 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6540 | if (localeFromDefaultSim != null) { |
| 6541 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6542 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6543 | + localeFromDefaultSim); |
| 6544 | return localeFromDefaultSim.toLanguageTag(); |
| 6545 | } else { |
| 6546 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6547 | } |
| 6548 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6549 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6550 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6551 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6552 | // the SIM and carrier preferences does not include a country we add the country |
| 6553 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6554 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6555 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6556 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6557 | return mccLocale.toLanguageTag(); |
| 6558 | } |
| 6559 | |
| 6560 | if (DBG) log("No locale found - returning null"); |
| 6561 | return null; |
| 6562 | } finally { |
| 6563 | Binder.restoreCallingIdentity(identity); |
| 6564 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6565 | } |
| 6566 | |
| 6567 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6568 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 6569 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6570 | } |
| 6571 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6572 | /** |
| 6573 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6574 | */ |
| 6575 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6576 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 6577 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6578 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6579 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6580 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6581 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6582 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6583 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6584 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6585 | * representing the state of the modem. |
| 6586 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6587 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6588 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6589 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6590 | */ |
| 6591 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6592 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6593 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6594 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6595 | |
| 6596 | final long identity = Binder.clearCallingIdentity(); |
| 6597 | try { |
| 6598 | ModemActivityInfo ret = null; |
| 6599 | synchronized (mLastModemActivityInfo) { |
| 6600 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 6601 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6602 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6603 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6604 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6605 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6606 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6607 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6608 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6609 | } |
| 6610 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6611 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 6612 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6613 | mLastModemActivityInfo.setIdleTimeMillis( |
| 6614 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6615 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 6616 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 6617 | info.getReceiveTimeMillis() + mLastModemActivityInfo |
| 6618 | .getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6619 | } |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6620 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6621 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 6622 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 6623 | mLastModemActivityInfo.getIdleTimeMillis(), |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6624 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 6625 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6626 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6627 | Bundle bundle = new Bundle(); |
| 6628 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 6629 | result.send(0, bundle); |
| 6630 | } finally { |
| 6631 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6632 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6633 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6634 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6635 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6636 | // less than total activity duration. |
| 6637 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6638 | if (info == null) { |
| 6639 | return false; |
| 6640 | } |
| 6641 | int activityDurationMs = |
| 6642 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6643 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6644 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6645 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6646 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6647 | } |
| 6648 | return (info.isValid() |
| 6649 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6650 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6651 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6652 | && (totalTxTimeMs <= activityDurationMs)); |
| 6653 | } |
| 6654 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6655 | /** |
| 6656 | * {@hide} |
| 6657 | * Returns the service state information on specified subscription. |
| 6658 | */ |
| 6659 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6660 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6661 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6662 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6663 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6664 | return null; |
| 6665 | } |
| 6666 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6667 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6668 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6669 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6670 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6671 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6672 | .setCallingPid(Binder.getCallingPid()) |
| 6673 | .setCallingUid(Binder.getCallingUid()) |
| 6674 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6675 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6676 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6677 | .build()); |
| 6678 | |
| 6679 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6680 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6681 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6682 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6683 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6684 | .setCallingPid(Binder.getCallingPid()) |
| 6685 | .setCallingUid(Binder.getCallingUid()) |
| 6686 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6687 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6688 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6689 | .build()); |
| 6690 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6691 | boolean hasFinePermission = |
| 6692 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6693 | boolean hasCoarsePermission = |
| 6694 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6695 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6696 | final long identity = Binder.clearCallingIdentity(); |
| 6697 | try { |
| 6698 | final Phone phone = getPhone(subId); |
| 6699 | if (phone == null) { |
| 6700 | return null; |
| 6701 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6702 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6703 | ServiceState ss = phone.getServiceState(); |
| 6704 | |
| 6705 | // Scrub out the location info in ServiceState depending on what level of access |
| 6706 | // the caller has. |
| 6707 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6708 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6709 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6710 | } finally { |
| 6711 | Binder.restoreCallingIdentity(identity); |
| 6712 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6713 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6714 | |
| 6715 | /** |
| 6716 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6717 | * |
| 6718 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6719 | * voicemail ringtone. |
| 6720 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6721 | * PhoneAccount. |
| 6722 | */ |
| 6723 | @Override |
| 6724 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6725 | final long identity = Binder.clearCallingIdentity(); |
| 6726 | try { |
| 6727 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6728 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6729 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6730 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6731 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6732 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6733 | } finally { |
| 6734 | Binder.restoreCallingIdentity(identity); |
| 6735 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6736 | } |
| 6737 | |
| 6738 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6739 | * Sets the per-account voicemail ringtone. |
| 6740 | * |
| 6741 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6742 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6743 | * |
| 6744 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6745 | * voicemail ringtone. |
| 6746 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6747 | * PhoneAccount. |
| 6748 | */ |
| 6749 | @Override |
| 6750 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6751 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6752 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6753 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6754 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6755 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6756 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6757 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6758 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6759 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6760 | |
| 6761 | final long identity = Binder.clearCallingIdentity(); |
| 6762 | try { |
| 6763 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6764 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6765 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6766 | } |
| 6767 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6768 | } finally { |
| 6769 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6770 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6771 | } |
| 6772 | |
| 6773 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6774 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6775 | * |
| 6776 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6777 | * voicemail vibration setting. |
| 6778 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6779 | */ |
| 6780 | @Override |
| 6781 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6782 | final long identity = Binder.clearCallingIdentity(); |
| 6783 | try { |
| 6784 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6785 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6786 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6787 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6788 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6789 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6790 | } finally { |
| 6791 | Binder.restoreCallingIdentity(identity); |
| 6792 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6793 | } |
| 6794 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6795 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6796 | * Sets the per-account voicemail vibration. |
| 6797 | * |
| 6798 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6799 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6800 | * |
| 6801 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6802 | * voicemail vibration setting. |
| 6803 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6804 | * specific PhoneAccount. |
| 6805 | */ |
| 6806 | @Override |
| 6807 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6808 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6809 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6810 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6811 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6812 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6813 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6814 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6815 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6816 | } |
| 6817 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6818 | final long identity = Binder.clearCallingIdentity(); |
| 6819 | try { |
| 6820 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6821 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6822 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6823 | } |
| 6824 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6825 | } finally { |
| 6826 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6827 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6828 | } |
| 6829 | |
| 6830 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6831 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6832 | * |
| 6833 | * @throws SecurityException if the caller does not have the required permission |
| 6834 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6835 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6836 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6837 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6838 | } |
| 6839 | |
| 6840 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6841 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6842 | * permission. |
| 6843 | * |
| 6844 | * @throws SecurityException if the caller does not have the required permission |
| 6845 | */ |
| 6846 | private void enforceSendSmsPermission() { |
| 6847 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6848 | } |
| 6849 | |
| 6850 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6851 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6852 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6853 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6854 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6855 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6856 | final long identity = Binder.clearCallingIdentity(); |
| 6857 | try { |
| 6858 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6859 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6860 | if (componentName == null) { |
| 6861 | throw new SecurityException( |
| 6862 | "Caller not current active visual voicemail package[null]"); |
| 6863 | } |
| 6864 | String vvmPackage = componentName.getPackageName(); |
| 6865 | if (!callingPackage.equals(vvmPackage)) { |
| 6866 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6867 | + vvmPackage + "]"); |
| 6868 | } |
| 6869 | } finally { |
| 6870 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6871 | } |
| 6872 | } |
| 6873 | |
| 6874 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6875 | * Return the application ID for the app type. |
| 6876 | * |
| 6877 | * @param subId the subscription ID that this request applies to. |
| 6878 | * @param appType the uicc app type. |
| 6879 | * @return Application ID for specificied app type, or null if no uicc. |
| 6880 | */ |
| 6881 | @Override |
| 6882 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6883 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6884 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6885 | |
| 6886 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6887 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6888 | if (phone == null) { |
| 6889 | return null; |
| 6890 | } |
| 6891 | String aid = null; |
| 6892 | try { |
| 6893 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6894 | .getApplicationByType(appType).getAid(); |
| 6895 | } catch (Exception e) { |
| 6896 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6897 | } |
| 6898 | return aid; |
| 6899 | } finally { |
| 6900 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6901 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6902 | } |
| 6903 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6904 | /** |
| 6905 | * Return the Electronic Serial Number. |
| 6906 | * |
| 6907 | * @param subId the subscription ID that this request applies to. |
| 6908 | * @return ESN or null if error. |
| 6909 | */ |
| 6910 | @Override |
| 6911 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6912 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6913 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6914 | |
| 6915 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6916 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6917 | if (phone == null) { |
| 6918 | return null; |
| 6919 | } |
| 6920 | String esn = null; |
| 6921 | try { |
| 6922 | esn = phone.getEsn(); |
| 6923 | } catch (Exception e) { |
| 6924 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6925 | } |
| 6926 | return esn; |
| 6927 | } finally { |
| 6928 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6929 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6930 | } |
| 6931 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6932 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6933 | * Return the Preferred Roaming List Version. |
| 6934 | * |
| 6935 | * @param subId the subscription ID that this request applies to. |
| 6936 | * @return PRLVersion or null if error. |
| 6937 | */ |
| 6938 | @Override |
| 6939 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6940 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6941 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6942 | |
| 6943 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6944 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6945 | if (phone == null) { |
| 6946 | return null; |
| 6947 | } |
| 6948 | String cdmaPrlVersion = null; |
| 6949 | try { |
| 6950 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6951 | } catch (Exception e) { |
| 6952 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6953 | } |
| 6954 | return cdmaPrlVersion; |
| 6955 | } finally { |
| 6956 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6957 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6958 | } |
| 6959 | |
| 6960 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6961 | * Get snapshot of Telephony histograms |
| 6962 | * @return List of Telephony histograms |
| 6963 | * @hide |
| 6964 | */ |
| 6965 | @Override |
| 6966 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6967 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6968 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6969 | |
| 6970 | final long identity = Binder.clearCallingIdentity(); |
| 6971 | try { |
| 6972 | return RIL.getTelephonyRILTimingHistograms(); |
| 6973 | } finally { |
| 6974 | Binder.restoreCallingIdentity(identity); |
| 6975 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6976 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6977 | |
| 6978 | /** |
| 6979 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6980 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6981 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6982 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6983 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6984 | * @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] | 6985 | */ |
| 6986 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6987 | @TelephonyManager.SetCarrierRestrictionResult |
| 6988 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6989 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6990 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6991 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6992 | if (carrierRestrictionRules == null) { |
| 6993 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6994 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6995 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6996 | final long identity = Binder.clearCallingIdentity(); |
| 6997 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6998 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6999 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7000 | } finally { |
| 7001 | Binder.restoreCallingIdentity(identity); |
| 7002 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7003 | } |
| 7004 | |
| 7005 | /** |
| 7006 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7007 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7008 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7009 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7010 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7011 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7012 | */ |
| 7013 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7014 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7015 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7016 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7017 | |
| 7018 | final long identity = Binder.clearCallingIdentity(); |
| 7019 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7020 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7021 | if (response instanceof CarrierRestrictionRules) { |
| 7022 | return (CarrierRestrictionRules) response; |
| 7023 | } |
| 7024 | // Response is an Exception of some kind, |
| 7025 | // which is signalled to the user as a NULL retval |
| 7026 | return null; |
| 7027 | } catch (Exception e) { |
| 7028 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7029 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7030 | } finally { |
| 7031 | Binder.restoreCallingIdentity(identity); |
| 7032 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7033 | } |
| 7034 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7035 | /** |
| 7036 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 7037 | * @param subId the subscription ID that this action applies to. |
| 7038 | * @param enabled control enable or disable metered apns. |
| 7039 | * {@hide} |
| 7040 | */ |
| 7041 | @Override |
| 7042 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 7043 | enforceModifyPermission(); |
| 7044 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7045 | |
| 7046 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7047 | if (phone == null) { |
| 7048 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 7049 | return; |
| 7050 | } |
| 7051 | try { |
| 7052 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7053 | } catch (Exception e) { |
| 7054 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7055 | } finally { |
| 7056 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7057 | } |
| 7058 | } |
| 7059 | |
| 7060 | /** |
| 7061 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7062 | * @param subId the subscription ID that this action applies to. |
| 7063 | * @param enabled control enable or disable radio. |
| 7064 | * {@hide} |
| 7065 | */ |
| 7066 | @Override |
| 7067 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7068 | enforceModifyPermission(); |
| 7069 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7070 | |
| 7071 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7072 | if (phone == null) { |
| 7073 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7074 | return; |
| 7075 | } |
| 7076 | try { |
| 7077 | phone.carrierActionSetRadioEnabled(enabled); |
| 7078 | } catch (Exception e) { |
| 7079 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7080 | } finally { |
| 7081 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7082 | } |
| 7083 | } |
| 7084 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7085 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7086 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7087 | * network status based on which carrier apps could apply actions accordingly, |
| 7088 | * enable/disable default url handler for example. |
| 7089 | * |
| 7090 | * @param subId the subscription ID that this action applies to. |
| 7091 | * @param report control start/stop reporting the default network status. |
| 7092 | * {@hide} |
| 7093 | */ |
| 7094 | @Override |
| 7095 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7096 | enforceModifyPermission(); |
| 7097 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7098 | |
| 7099 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7100 | if (phone == null) { |
| 7101 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7102 | return; |
| 7103 | } |
| 7104 | try { |
| 7105 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7106 | } catch (Exception e) { |
| 7107 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7108 | } finally { |
| 7109 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7110 | } |
| 7111 | } |
| 7112 | |
| 7113 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7114 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7115 | * @param subId the subscription ID that this action applies to. |
| 7116 | * {@hide} |
| 7117 | */ |
| 7118 | @Override |
| 7119 | public void carrierActionResetAll(int subId) { |
| 7120 | enforceModifyPermission(); |
| 7121 | final Phone phone = getPhone(subId); |
| 7122 | if (phone == null) { |
| 7123 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7124 | return; |
| 7125 | } |
| 7126 | try { |
| 7127 | phone.carrierActionResetAll(); |
| 7128 | } catch (Exception e) { |
| 7129 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7130 | } |
| 7131 | } |
| 7132 | |
| 7133 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7134 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7135 | * bug report is being generated. |
| 7136 | */ |
| 7137 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7138 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7139 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7140 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7141 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7142 | + Binder.getCallingPid() |
| 7143 | + ", uid=" + Binder.getCallingUid() |
| 7144 | + "without permission " |
| 7145 | + android.Manifest.permission.DUMP); |
| 7146 | return; |
| 7147 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7148 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7149 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7150 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7151 | @Override |
| 7152 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 7153 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 7154 | throws RemoteException { |
Torbjorn Eklund | 1050cb0 | 2018-11-16 14:05:38 +0100 | [diff] [blame] | 7155 | (new TelephonyShellCommand(this, getDefaultPhone().getContext())) |
| 7156 | .exec(this, in, out, err, args, callback, resultReceiver); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7157 | } |
| 7158 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7159 | /** |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7160 | * Policy control of data connection. Usually used when data limit is passed. |
| 7161 | * @param enabled True if enabling the data, otherwise disabling. |
| 7162 | * @param subId Subscription index |
| 7163 | * {@hide} |
| 7164 | */ |
| 7165 | @Override |
| 7166 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 7167 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7168 | |
| 7169 | final long identity = Binder.clearCallingIdentity(); |
| 7170 | try { |
| 7171 | Phone phone = getPhone(subId); |
| 7172 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 7173 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7174 | } |
| 7175 | } finally { |
| 7176 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7177 | } |
| 7178 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7179 | |
| 7180 | /** |
| 7181 | * Get Client request stats |
| 7182 | * @return List of Client Request Stats |
| 7183 | * @hide |
| 7184 | */ |
| 7185 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7186 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7187 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7188 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7189 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7190 | return null; |
| 7191 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7192 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7193 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7194 | final long identity = Binder.clearCallingIdentity(); |
| 7195 | try { |
| 7196 | if (phone != null) { |
| 7197 | return phone.getClientRequestStats(); |
| 7198 | } |
| 7199 | |
| 7200 | return null; |
| 7201 | } finally { |
| 7202 | Binder.restoreCallingIdentity(identity); |
| 7203 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7204 | } |
| 7205 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7206 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7207 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7208 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7209 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7210 | |
| 7211 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7212 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7213 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7214 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7215 | * @param state State of SIM (power down, power up, pass through) |
| 7216 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7217 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7218 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7219 | * |
| 7220 | **/ |
| 7221 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7222 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7223 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7224 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7225 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7226 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7227 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7228 | final long identity = Binder.clearCallingIdentity(); |
| 7229 | try { |
| 7230 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7231 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7232 | } |
| 7233 | } finally { |
| 7234 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7235 | } |
| 7236 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7237 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7238 | private boolean isUssdApiAllowed(int subId) { |
| 7239 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7240 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7241 | if (configManager == null) { |
| 7242 | return false; |
| 7243 | } |
| 7244 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7245 | if (pb == null) { |
| 7246 | return false; |
| 7247 | } |
| 7248 | return pb.getBoolean( |
| 7249 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7250 | } |
| 7251 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7252 | /** |
| 7253 | * Check if phone is in emergency callback mode |
| 7254 | * @return true if phone is in emergency callback mode |
| 7255 | * @param subId sub id |
| 7256 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7257 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7258 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7259 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7260 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7261 | |
| 7262 | final long identity = Binder.clearCallingIdentity(); |
| 7263 | try { |
| 7264 | if (phone != null) { |
| 7265 | return phone.isInEcm(); |
| 7266 | } else { |
| 7267 | return false; |
| 7268 | } |
| 7269 | } finally { |
| 7270 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7271 | } |
| 7272 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7273 | |
| 7274 | /** |
| 7275 | * Get the current signal strength information for the given subscription. |
| 7276 | * Because this information is not updated when the device is in a low power state |
| 7277 | * it should not be relied-upon to be current. |
| 7278 | * @param subId Subscription index |
| 7279 | * @return the most recent cached signal strength info from the modem |
| 7280 | */ |
| 7281 | @Override |
| 7282 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7283 | final long identity = Binder.clearCallingIdentity(); |
| 7284 | try { |
| 7285 | Phone p = getPhone(subId); |
| 7286 | if (p == null) { |
| 7287 | return null; |
| 7288 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7289 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7290 | return p.getSignalStrength(); |
| 7291 | } finally { |
| 7292 | Binder.restoreCallingIdentity(identity); |
| 7293 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7294 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7295 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7296 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7297 | * Get the current modem radio state for the given slot. |
| 7298 | * @param slotIndex slot index. |
| 7299 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7300 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7301 | * @return the current radio power state from the modem |
| 7302 | */ |
| 7303 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7304 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7305 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7306 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7307 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7308 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7309 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7310 | } |
| 7311 | |
| 7312 | final long identity = Binder.clearCallingIdentity(); |
| 7313 | try { |
| 7314 | return phone.getRadioPowerState(); |
| 7315 | } finally { |
| 7316 | Binder.restoreCallingIdentity(identity); |
| 7317 | } |
| 7318 | } |
| 7319 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7320 | } |
| 7321 | |
| 7322 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7323 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7324 | * |
| 7325 | * <p>Requires one of the following permissions: |
| 7326 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7327 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7328 | * privileges. |
| 7329 | * |
| 7330 | * @param subId subscription id |
| 7331 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7332 | * {@code false}. |
| 7333 | */ |
| 7334 | @Override |
| 7335 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7336 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7337 | null /* message */); |
| 7338 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7339 | boolean isEnabled = false; |
| 7340 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7341 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7342 | Phone phone = getPhone(subId); |
| 7343 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7344 | } catch (Exception e) { |
| 7345 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7346 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7347 | } finally { |
| 7348 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7349 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7350 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7351 | } |
| 7352 | |
| 7353 | |
| 7354 | /** |
| 7355 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7356 | * |
| 7357 | * <p> Requires permission: |
| 7358 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7359 | * privileges. |
| 7360 | * |
| 7361 | * @param subId subscription id |
| 7362 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7363 | */ |
| 7364 | @Override |
| 7365 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7366 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7367 | mApp, subId, "setDataRoamingEnabled"); |
| 7368 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7369 | final long identity = Binder.clearCallingIdentity(); |
| 7370 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7371 | Phone phone = getPhone(subId); |
| 7372 | if (phone != null) { |
| 7373 | phone.setDataRoamingEnabled(isEnabled); |
| 7374 | } |
| 7375 | } finally { |
| 7376 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7377 | } |
| 7378 | } |
| 7379 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7380 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7381 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7382 | TelephonyPermissions |
| 7383 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7384 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7385 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7386 | boolean isAllowed = true; |
| 7387 | final long identity = Binder.clearCallingIdentity(); |
| 7388 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7389 | Phone phone = getPhone(subId); |
| 7390 | if (phone != null) { |
| 7391 | isAllowed = phone.isCspPlmnEnabled(); |
| 7392 | } |
| 7393 | } finally { |
| 7394 | Binder.restoreCallingIdentity(identity); |
| 7395 | } |
| 7396 | return isAllowed; |
| 7397 | } |
| 7398 | |
| 7399 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7400 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7401 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7402 | try { |
| 7403 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7404 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7405 | } catch (SecurityException e) { |
| 7406 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7407 | // has carrier privileges on an active UICC |
| 7408 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7409 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7410 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7411 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7412 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7413 | |
| 7414 | final long identity = Binder.clearCallingIdentity(); |
| 7415 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7416 | UiccController uiccController = UiccController.getInstance(); |
| 7417 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7418 | if (hasReadPermission) { |
| 7419 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7420 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7421 | |
| 7422 | // Remove private info if the caller doesn't have access |
| 7423 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7424 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7425 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7426 | // is available |
| 7427 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7428 | if (card == null || card.getUiccProfile() == null) { |
| 7429 | // assume no access if the card or profile is unavailable |
| 7430 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7431 | continue; |
| 7432 | } |
| 7433 | UiccProfile profile = card.getUiccProfile(); |
| 7434 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7435 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7436 | filteredInfos.add(cardInfo); |
| 7437 | } else { |
| 7438 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7439 | } |
| 7440 | } |
| 7441 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7442 | } finally { |
| 7443 | Binder.restoreCallingIdentity(identity); |
| 7444 | } |
| 7445 | } |
| 7446 | |
| 7447 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7448 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7449 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7450 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7451 | final long identity = Binder.clearCallingIdentity(); |
| 7452 | try { |
| 7453 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7454 | if (slots == null) { |
| 7455 | Rlog.i(LOG_TAG, "slots is null."); |
| 7456 | return null; |
| 7457 | } |
| 7458 | |
| 7459 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7460 | for (int i = 0; i < slots.length; i++) { |
| 7461 | UiccSlot slot = slots[i]; |
| 7462 | if (slot == null) { |
| 7463 | continue; |
| 7464 | } |
| 7465 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7466 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7467 | UiccCard card = slot.getUiccCard(); |
| 7468 | if (card != null) { |
| 7469 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7470 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7471 | cardId = slot.getEid(); |
| 7472 | if (TextUtils.isEmpty(cardId)) { |
| 7473 | cardId = slot.getIccId(); |
| 7474 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7475 | } |
| 7476 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7477 | if (cardId != null) { |
| 7478 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7479 | // if cardId is an EID, it's all digits so this is fine |
| 7480 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7481 | } |
| 7482 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7483 | int cardState = 0; |
| 7484 | switch (slot.getCardState()) { |
| 7485 | case CARDSTATE_ABSENT: |
| 7486 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7487 | break; |
| 7488 | case CARDSTATE_PRESENT: |
| 7489 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7490 | break; |
| 7491 | case CARDSTATE_ERROR: |
| 7492 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7493 | break; |
| 7494 | case CARDSTATE_RESTRICTED: |
| 7495 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7496 | break; |
| 7497 | default: |
| 7498 | break; |
| 7499 | |
| 7500 | } |
| 7501 | |
| 7502 | infos[i] = new UiccSlotInfo( |
| 7503 | slot.isActive(), |
| 7504 | slot.isEuicc(), |
| 7505 | cardId, |
| 7506 | cardState, |
| 7507 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7508 | slot.isExtendedApduSupported(), |
| 7509 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7510 | } |
| 7511 | return infos; |
| 7512 | } finally { |
| 7513 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7514 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7515 | } |
| 7516 | |
| 7517 | @Override |
| 7518 | public boolean switchSlots(int[] physicalSlots) { |
| 7519 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7520 | |
| 7521 | final long identity = Binder.clearCallingIdentity(); |
| 7522 | try { |
| 7523 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7524 | } finally { |
| 7525 | Binder.restoreCallingIdentity(identity); |
| 7526 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7527 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7528 | |
| 7529 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7530 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7531 | final long identity = Binder.clearCallingIdentity(); |
| 7532 | try { |
| 7533 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7534 | } finally { |
| 7535 | Binder.restoreCallingIdentity(identity); |
| 7536 | } |
| 7537 | } |
| 7538 | |
| 7539 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7540 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 7541 | enforceModifyPermission(); |
| 7542 | final Phone phone = getPhone(subId); |
| 7543 | if (phone == null) { |
| 7544 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 7545 | return; |
| 7546 | } |
| 7547 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7548 | final long identity = Binder.clearCallingIdentity(); |
| 7549 | try { |
| 7550 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 7551 | } finally { |
| 7552 | Binder.restoreCallingIdentity(identity); |
| 7553 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7554 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7555 | |
| 7556 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7557 | * A test API to reload the UICC profile. |
| 7558 | * |
| 7559 | * <p>Requires that the calling app has permission |
| 7560 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7561 | * @hide |
| 7562 | */ |
| 7563 | @Override |
| 7564 | public void refreshUiccProfile(int subId) { |
| 7565 | enforceModifyPermission(); |
| 7566 | |
| 7567 | final long identity = Binder.clearCallingIdentity(); |
| 7568 | try { |
| 7569 | Phone phone = getPhone(subId); |
| 7570 | if (phone == null) { |
| 7571 | return; |
| 7572 | } |
| 7573 | UiccCard uiccCard = phone.getUiccCard(); |
| 7574 | if (uiccCard == null) { |
| 7575 | return; |
| 7576 | } |
| 7577 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7578 | if (uiccProfile == null) { |
| 7579 | return; |
| 7580 | } |
| 7581 | uiccProfile.refresh(); |
| 7582 | } finally { |
| 7583 | Binder.restoreCallingIdentity(identity); |
| 7584 | } |
| 7585 | } |
| 7586 | |
| 7587 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7588 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7589 | */ |
| 7590 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7591 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7592 | } |
| 7593 | |
| 7594 | /** |
| 7595 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7596 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7597 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7598 | */ |
| 7599 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7600 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7601 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7602 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7603 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7604 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7605 | return isDataRoamingEnabled; |
| 7606 | } |
| 7607 | |
| 7608 | /** |
| 7609 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7610 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7611 | */ |
| 7612 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7613 | List<Integer> list = TelephonyProperties.default_network(); |
| 7614 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7615 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7616 | return list.get(phoneId); |
| 7617 | } |
| 7618 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7619 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7620 | |
| 7621 | @Override |
| 7622 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7623 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7624 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7625 | |
| 7626 | final long identity = Binder.clearCallingIdentity(); |
| 7627 | try { |
| 7628 | final Phone phone = getPhone(subId); |
| 7629 | if (phone == null) { |
| 7630 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7631 | return; |
| 7632 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7633 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7634 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7635 | } finally { |
| 7636 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7637 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7638 | } |
| 7639 | |
| 7640 | @Override |
| 7641 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7642 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7643 | |
| 7644 | final long identity = Binder.clearCallingIdentity(); |
| 7645 | try { |
| 7646 | final Phone phone = getPhone(subId); |
| 7647 | if (phone == null) { |
| 7648 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7649 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7650 | } |
| 7651 | return phone.getCarrierIdListVersion(); |
| 7652 | } finally { |
| 7653 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7654 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7655 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7656 | |
| 7657 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7658 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7659 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7660 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7661 | mApp, subId, callingPackage, callingFeatureId, |
| 7662 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7663 | return -1; |
| 7664 | } |
| 7665 | |
| 7666 | final long identity = Binder.clearCallingIdentity(); |
| 7667 | try { |
| 7668 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7669 | } finally { |
| 7670 | Binder.restoreCallingIdentity(identity); |
| 7671 | } |
| 7672 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7673 | |
| 7674 | @Override |
| 7675 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7676 | TelephonyPermissions |
| 7677 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7678 | mApp, subId, "getCdmaRoamingMode"); |
| 7679 | |
| 7680 | final long identity = Binder.clearCallingIdentity(); |
| 7681 | try { |
| 7682 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7683 | } finally { |
| 7684 | Binder.restoreCallingIdentity(identity); |
| 7685 | } |
| 7686 | } |
| 7687 | |
| 7688 | @Override |
| 7689 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7690 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7691 | mApp, subId, "setCdmaRoamingMode"); |
| 7692 | |
| 7693 | final long identity = Binder.clearCallingIdentity(); |
| 7694 | try { |
| 7695 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7696 | } finally { |
| 7697 | Binder.restoreCallingIdentity(identity); |
| 7698 | } |
| 7699 | } |
| 7700 | |
| 7701 | @Override |
| 7702 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7703 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7704 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7705 | |
| 7706 | final long identity = Binder.clearCallingIdentity(); |
| 7707 | try { |
| 7708 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7709 | } finally { |
| 7710 | Binder.restoreCallingIdentity(identity); |
| 7711 | } |
| 7712 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7713 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7714 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7715 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7716 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7717 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7718 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7719 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7720 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7721 | } |
| 7722 | final long identity = Binder.clearCallingIdentity(); |
| 7723 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7724 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7725 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7726 | if (phone.getEmergencyNumberTracker() != null |
| 7727 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7728 | emergencyNumberListInternal.put( |
| 7729 | phone.getSubId(), |
| 7730 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7731 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7732 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7733 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7734 | } finally { |
| 7735 | Binder.restoreCallingIdentity(identity); |
| 7736 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7737 | } |
| 7738 | |
| 7739 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7740 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7741 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7742 | if (!exactMatch) { |
| 7743 | TelephonyPermissions |
| 7744 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7745 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7746 | } |
| 7747 | final long identity = Binder.clearCallingIdentity(); |
| 7748 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7749 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7750 | if (phone.getEmergencyNumberTracker() != null |
| 7751 | && phone.getEmergencyNumberTracker() != null) { |
| 7752 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7753 | number, exactMatch)) { |
| 7754 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7755 | } |
| 7756 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7757 | } |
| 7758 | return false; |
| 7759 | } finally { |
| 7760 | Binder.restoreCallingIdentity(identity); |
| 7761 | } |
| 7762 | } |
| 7763 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7764 | /** |
| 7765 | * Update emergency number list for test mode. |
| 7766 | */ |
| 7767 | @Override |
| 7768 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7769 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7770 | "updateEmergencyNumberListTestMode"); |
| 7771 | |
| 7772 | final long identity = Binder.clearCallingIdentity(); |
| 7773 | try { |
| 7774 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7775 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7776 | if (tracker != null) { |
| 7777 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7778 | } |
| 7779 | } |
| 7780 | } finally { |
| 7781 | Binder.restoreCallingIdentity(identity); |
| 7782 | } |
| 7783 | } |
| 7784 | |
| 7785 | /** |
| 7786 | * Get the full emergency number list for test mode. |
| 7787 | */ |
| 7788 | @Override |
| 7789 | public List<String> getEmergencyNumberListTestMode() { |
| 7790 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7791 | "getEmergencyNumberListTestMode"); |
| 7792 | |
| 7793 | final long identity = Binder.clearCallingIdentity(); |
| 7794 | try { |
| 7795 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7796 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7797 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7798 | if (tracker != null) { |
| 7799 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7800 | emergencyNumbers.add(num.getNumber()); |
| 7801 | } |
| 7802 | } |
| 7803 | } |
| 7804 | return new ArrayList<>(emergencyNumbers); |
| 7805 | } finally { |
| 7806 | Binder.restoreCallingIdentity(identity); |
| 7807 | } |
| 7808 | } |
| 7809 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7810 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7811 | public int getEmergencyNumberDbVersion(int subId) { |
| 7812 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7813 | |
| 7814 | final long identity = Binder.clearCallingIdentity(); |
| 7815 | try { |
| 7816 | final Phone phone = getPhone(subId); |
| 7817 | if (phone == null) { |
| 7818 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7819 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7820 | } |
| 7821 | return phone.getEmergencyNumberDbVersion(); |
| 7822 | } finally { |
| 7823 | Binder.restoreCallingIdentity(identity); |
| 7824 | } |
| 7825 | } |
| 7826 | |
| 7827 | @Override |
| 7828 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7829 | enforceModifyPermission(); |
| 7830 | |
| 7831 | final long identity = Binder.clearCallingIdentity(); |
| 7832 | try { |
| 7833 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7834 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7835 | if (tracker != null) { |
| 7836 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7837 | } |
| 7838 | } |
| 7839 | } finally { |
| 7840 | Binder.restoreCallingIdentity(identity); |
| 7841 | } |
| 7842 | } |
| 7843 | |
| 7844 | @Override |
| 7845 | public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) { |
| 7846 | enforceActiveEmergencySessionPermission(); |
| 7847 | |
| 7848 | final long identity = Binder.clearCallingIdentity(); |
| 7849 | try { |
| 7850 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7851 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7852 | if (tracker != null) { |
| 7853 | tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath); |
| 7854 | } |
| 7855 | } |
| 7856 | } finally { |
| 7857 | Binder.restoreCallingIdentity(identity); |
| 7858 | } |
| 7859 | } |
| 7860 | |
| 7861 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7862 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7863 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7864 | Phone phone = getPhone(subId); |
| 7865 | if (phone == null) { |
| 7866 | return null; |
| 7867 | } |
| 7868 | final long identity = Binder.clearCallingIdentity(); |
| 7869 | try { |
| 7870 | UiccProfile profile = UiccController.getInstance() |
| 7871 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7872 | if (profile != null) { |
| 7873 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7874 | } |
| 7875 | } finally { |
| 7876 | Binder.restoreCallingIdentity(identity); |
| 7877 | } |
| 7878 | return null; |
| 7879 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7880 | |
| 7881 | /** |
| 7882 | * Enable or disable a modem stack. |
| 7883 | */ |
| 7884 | @Override |
| 7885 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7886 | enforceModifyPermission(); |
| 7887 | |
| 7888 | final long identity = Binder.clearCallingIdentity(); |
| 7889 | try { |
| 7890 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7891 | if (phone == null) { |
| 7892 | return false; |
| 7893 | } else { |
| 7894 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7895 | } |
| 7896 | } finally { |
| 7897 | Binder.restoreCallingIdentity(identity); |
| 7898 | } |
| 7899 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7900 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7901 | /** |
| 7902 | * Whether a modem stack is enabled or not. |
| 7903 | */ |
| 7904 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7905 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7906 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7907 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7908 | if (phone == null) return false; |
| 7909 | |
| 7910 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7911 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7912 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7913 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7914 | } |
| 7915 | |
| 7916 | final long identity = Binder.clearCallingIdentity(); |
| 7917 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7918 | try { |
| 7919 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7920 | } catch (NoSuchElementException ex) { |
| 7921 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7922 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7923 | } finally { |
| 7924 | Binder.restoreCallingIdentity(identity); |
| 7925 | } |
| 7926 | } |
| 7927 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7928 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7929 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7930 | enforceModifyPermission(); |
| 7931 | |
| 7932 | final long identity = Binder.clearCallingIdentity(); |
| 7933 | try { |
| 7934 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7935 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7936 | .commit(); |
| 7937 | } finally { |
| 7938 | Binder.restoreCallingIdentity(identity); |
| 7939 | } |
| 7940 | } |
| 7941 | |
| 7942 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7943 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7944 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7945 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7946 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 7947 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7948 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7949 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7950 | |
| 7951 | final long identity = Binder.clearCallingIdentity(); |
| 7952 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7953 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7954 | } finally { |
| 7955 | Binder.restoreCallingIdentity(identity); |
| 7956 | } |
| 7957 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7958 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7959 | @TelephonyManager.IsMultiSimSupportedResult |
| 7960 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7961 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7962 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7963 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7964 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7965 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7966 | } |
| 7967 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7968 | // supported by the modem, indicate that it is restricted. |
| 7969 | PhoneCapability staticCapability = |
| 7970 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7971 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7972 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7973 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7974 | } |
Sarah Chin | 5f0ecd7 | 2019-12-06 10:24:18 -0800 | [diff] [blame] | 7975 | if (staticCapability.getLogicalModemUuids().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7976 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7977 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7978 | } |
| 7979 | // Check if support of multiple SIMs is restricted by carrier |
| 7980 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7981 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7982 | } |
| 7983 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7984 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7985 | } |
| 7986 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7987 | /** |
| 7988 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7989 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7990 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7991 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7992 | * @param numOfSims number of active sims we want to switch to |
| 7993 | */ |
| 7994 | @Override |
| 7995 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7996 | if (numOfSims == 1) { |
| 7997 | enforceModifyPermission(); |
| 7998 | } else { |
| 7999 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8000 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8001 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8002 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8003 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8004 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8005 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8006 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8007 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8008 | return; |
| 8009 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8010 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8011 | } finally { |
| 8012 | Binder.restoreCallingIdentity(identity); |
| 8013 | } |
| 8014 | } |
| 8015 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8016 | @Override |
| 8017 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8018 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8019 | Phone phone = getPhone(subId); |
| 8020 | if (phone == null) { |
| 8021 | return false; |
| 8022 | } |
| 8023 | final long identity = Binder.clearCallingIdentity(); |
| 8024 | try { |
| 8025 | UiccCard uiccCard = phone.getUiccCard(); |
| 8026 | if (uiccCard == null) { |
| 8027 | return false; |
| 8028 | } |
| 8029 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8030 | if (uiccProfile == null) { |
| 8031 | return false; |
| 8032 | } |
| 8033 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8034 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8035 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8036 | } |
| 8037 | return false; |
| 8038 | } finally { |
| 8039 | Binder.restoreCallingIdentity(identity); |
| 8040 | } |
| 8041 | } |
| 8042 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8043 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8044 | * Get whether making changes to modem configurations will trigger reboot. |
| 8045 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8046 | */ |
| 8047 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8048 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8049 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8050 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8051 | mApp, subId, callingPackage, callingFeatureId, |
| 8052 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8053 | return false; |
| 8054 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8055 | final long identity = Binder.clearCallingIdentity(); |
| 8056 | try { |
| 8057 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8058 | } finally { |
| 8059 | Binder.restoreCallingIdentity(identity); |
| 8060 | } |
| 8061 | } |
| 8062 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8063 | private void updateModemStateMetrics() { |
| 8064 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8065 | // TODO: check the state for each modem if the api is ready. |
| 8066 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8067 | } |
| 8068 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8069 | @Override |
| 8070 | public int[] getSlotsMapping() { |
| 8071 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8072 | |
| 8073 | final long identity = Binder.clearCallingIdentity(); |
| 8074 | try { |
| 8075 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8076 | // All logical slots should have a mapping to a physical slot. |
| 8077 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8078 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8079 | for (int i = 0; i < slotInfos.length; i++) { |
| 8080 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8081 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8082 | } |
| 8083 | } |
| 8084 | return logicalSlotsMapping; |
| 8085 | } finally { |
| 8086 | Binder.restoreCallingIdentity(identity); |
| 8087 | } |
| 8088 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8089 | |
| 8090 | /** |
| 8091 | * Get the IRadio HAL Version |
| 8092 | */ |
| 8093 | @Override |
| 8094 | public int getRadioHalVersion() { |
| 8095 | Phone phone = getDefaultPhone(); |
| 8096 | if (phone == null) return -1; |
| 8097 | HalVersion hv = phone.getHalVersion(); |
| 8098 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8099 | return hv.major * 100 + hv.minor; |
| 8100 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8101 | |
| 8102 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8103 | * Get the current calling package name. |
| 8104 | * @return the current calling package name |
| 8105 | */ |
| 8106 | @Override |
| 8107 | public String getCurrentPackageName() { |
| 8108 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8109 | } |
| 8110 | |
| 8111 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8112 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8113 | * corresponding network requests on a subId. |
| 8114 | * |
| 8115 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8116 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8117 | * 2) APN is un-metered for this subscription, or |
| 8118 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8119 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8120 | * |
| 8121 | * @return whether data is allowed for a apn type. |
| 8122 | * |
| 8123 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8124 | */ |
| 8125 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8126 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8127 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8128 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8129 | |
| 8130 | // Now that all security checks passes, perform the operation as ourselves. |
| 8131 | final long identity = Binder.clearCallingIdentity(); |
| 8132 | try { |
| 8133 | Phone phone = getPhone(subId); |
| 8134 | if (phone == null) return false; |
| 8135 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8136 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8137 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8138 | } finally { |
| 8139 | Binder.restoreCallingIdentity(identity); |
| 8140 | } |
| 8141 | } |
| 8142 | |
| 8143 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8144 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8145 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8146 | |
| 8147 | // Now that all security checks passes, perform the operation as ourselves. |
| 8148 | final long identity = Binder.clearCallingIdentity(); |
| 8149 | try { |
| 8150 | Phone phone = getPhone(subId); |
| 8151 | if (phone == null) return true; // By default return true. |
| 8152 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8153 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8154 | } finally { |
| 8155 | Binder.restoreCallingIdentity(identity); |
| 8156 | } |
| 8157 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8158 | |
| 8159 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8160 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
| 8161 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8162 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8163 | if (iccRecords == null) { |
| 8164 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8165 | return false; |
| 8166 | } |
| 8167 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8168 | } |
| 8169 | |
| 8170 | @Override |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8171 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8172 | if (callingPackage == null) { |
| 8173 | callingPackage = getCurrentPackageName(); |
| 8174 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8175 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8176 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 8177 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 8178 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8179 | } |
| 8180 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8181 | Intent intent = new Intent(); |
| 8182 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8183 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8184 | // Bring up choose default SMS subscription dialog right now |
| 8185 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8186 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8187 | mApp.startActivity(intent); |
| 8188 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8189 | |
| 8190 | @Override |
| 8191 | public String getMmsUAProfUrl(int subId) { |
| 8192 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8193 | final long identity = Binder.clearCallingIdentity(); |
| 8194 | try { |
| 8195 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8196 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 8197 | } finally { |
| 8198 | Binder.restoreCallingIdentity(identity); |
| 8199 | } |
| 8200 | } |
| 8201 | |
| 8202 | @Override |
| 8203 | public String getMmsUserAgent(int subId) { |
| 8204 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8205 | final long identity = Binder.clearCallingIdentity(); |
| 8206 | try { |
| 8207 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8208 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8209 | } finally { |
| 8210 | Binder.restoreCallingIdentity(identity); |
| 8211 | } |
| 8212 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8213 | |
| 8214 | @Override |
| 8215 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 8216 | enforceModifyPermission(); |
| 8217 | |
| 8218 | // Now that all security checks passes, perform the operation as ourselves. |
| 8219 | final long identity = Binder.clearCallingIdentity(); |
| 8220 | try { |
| 8221 | Phone phone = getPhone(subId); |
| 8222 | if (phone == null) return false; |
| 8223 | |
| 8224 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 8225 | } finally { |
| 8226 | Binder.restoreCallingIdentity(identity); |
| 8227 | } |
| 8228 | } |
| 8229 | |
| 8230 | @Override |
| 8231 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 8232 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 8233 | |
| 8234 | // Now that all security checks passes, perform the operation as ourselves. |
| 8235 | final long identity = Binder.clearCallingIdentity(); |
| 8236 | try { |
| 8237 | Phone phone = getPhone(subId); |
| 8238 | if (phone == null) return false; |
| 8239 | |
| 8240 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8241 | } finally { |
| 8242 | Binder.restoreCallingIdentity(identity); |
| 8243 | } |
| 8244 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8245 | |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8246 | @Override |
| 8247 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8248 | enforceModifyPermission(); |
| 8249 | |
| 8250 | // Now that all security checks passes, perform the operation as ourselves. |
| 8251 | final long identity = Binder.clearCallingIdentity(); |
| 8252 | try { |
| 8253 | Phone phone = getPhone(subId); |
| 8254 | if (phone == null) return false; |
| 8255 | |
| 8256 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8257 | } finally { |
| 8258 | Binder.restoreCallingIdentity(identity); |
| 8259 | } |
| 8260 | } |
| 8261 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8262 | /** |
| 8263 | * Updates whether conference event pacakge handling is enabled. |
| 8264 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8265 | * otherwise. |
| 8266 | */ |
| 8267 | @Override |
| 8268 | public void setCepEnabled(boolean isCepEnabled) { |
| 8269 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8270 | |
| 8271 | final long identity = Binder.clearCallingIdentity(); |
| 8272 | try { |
| 8273 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8274 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8275 | Phone defaultPhone = phone.getImsPhone(); |
| 8276 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8277 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8278 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8279 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8280 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8281 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8282 | + imsPhone.getMsisdn()); |
| 8283 | } |
| 8284 | } |
| 8285 | } finally { |
| 8286 | Binder.restoreCallingIdentity(identity); |
| 8287 | } |
| 8288 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8289 | |
| 8290 | /** |
| 8291 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8292 | * |
| 8293 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8294 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8295 | * before being read. |
| 8296 | */ |
| 8297 | @Override |
| 8298 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8299 | isCompressed) { |
| 8300 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8301 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8302 | try { |
| 8303 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8304 | if (configBinder == null) { |
| 8305 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8306 | } else { |
| 8307 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8308 | } |
| 8309 | } catch (RemoteException e) { |
| 8310 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8311 | } |
| 8312 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8313 | |
| 8314 | @Override |
| 8315 | public boolean isIccLockEnabled(int subId) { |
| 8316 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8317 | |
| 8318 | // Now that all security checks passes, perform the operation as ourselves. |
| 8319 | final long identity = Binder.clearCallingIdentity(); |
| 8320 | try { |
| 8321 | Phone phone = getPhone(subId); |
| 8322 | if (phone != null && phone.getIccCard() != null) { |
| 8323 | return phone.getIccCard().getIccLockEnabled(); |
| 8324 | } else { |
| 8325 | return false; |
| 8326 | } |
| 8327 | } finally { |
| 8328 | Binder.restoreCallingIdentity(identity); |
| 8329 | } |
| 8330 | } |
| 8331 | |
| 8332 | /** |
| 8333 | * Set the ICC pin lock enabled or disabled.. |
| 8334 | * |
| 8335 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8336 | * 0 or a positive integer as the attempts remaining value. |
| 8337 | * |
| 8338 | */ |
| 8339 | @Override |
| 8340 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8341 | enforceModifyPermission(); |
| 8342 | |
| 8343 | Phone phone = getPhone(subId); |
| 8344 | if (phone == null) { |
| 8345 | return 0; |
| 8346 | } |
| 8347 | // Now that all security checks passes, perform the operation as ourselves. |
| 8348 | final long identity = Binder.clearCallingIdentity(); |
| 8349 | try { |
| 8350 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8351 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8352 | return attemptsRemaining; |
| 8353 | |
| 8354 | } catch (Exception e) { |
| 8355 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8356 | } finally { |
| 8357 | Binder.restoreCallingIdentity(identity); |
| 8358 | } |
| 8359 | return 0; |
| 8360 | } |
| 8361 | |
| 8362 | /** |
| 8363 | * Change the ICC password used in ICC pin lock. |
| 8364 | * |
| 8365 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8366 | * 0 or a positive integer as the attempts remaining value. |
| 8367 | * |
| 8368 | */ |
| 8369 | @Override |
| 8370 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8371 | enforceModifyPermission(); |
| 8372 | |
| 8373 | Phone phone = getPhone(subId); |
| 8374 | if (phone == null) { |
| 8375 | return 0; |
| 8376 | } |
| 8377 | // Now that all security checks passes, perform the operation as ourselves. |
| 8378 | final long identity = Binder.clearCallingIdentity(); |
| 8379 | try { |
| 8380 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8381 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8382 | return attemptsRemaining; |
| 8383 | |
| 8384 | } catch (Exception e) { |
| 8385 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8386 | } finally { |
| 8387 | Binder.restoreCallingIdentity(identity); |
| 8388 | } |
| 8389 | return 0; |
| 8390 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8391 | } |