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; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 38 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 39 | import android.net.Uri; |
| 40 | import android.os.AsyncResult; |
| 41 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 42 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 43 | import android.os.Bundle; |
| 44 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 45 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 46 | import android.os.Looper; |
| 47 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 48 | import android.os.Messenger; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 49 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 50 | import android.os.PersistableBundle; |
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; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 68 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 69 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 70 | import android.telephony.CellIdentity; |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 71 | import android.telephony.CellIdentityCdma; |
| 72 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 73 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfoGsm; |
| 75 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 76 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 77 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 78 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 79 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 80 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 81 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 82 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 83 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 84 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 85 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 86 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 87 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 88 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 89 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 90 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 91 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 92 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 93 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 94 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 95 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 96 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 97 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 98 | import android.telephony.data.ApnSetting; |
| 99 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 100 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 101 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 102 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 103 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 107 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 108 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 109 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 110 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 111 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 112 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 113 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 114 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 115 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 116 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 117 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 118 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 119 | import android.util.Slog; |
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; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 126 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.HalVersion; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 156 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 158 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 160 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 168 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 170 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 171 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 172 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 173 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 174 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 175 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 176 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 177 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 178 | import java.io.FileDescriptor; |
| 179 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 180 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 181 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 182 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 183 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 184 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 185 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 186 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 187 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 188 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 189 | |
| 190 | /** |
| 191 | * Implementation of the ITelephony interface. |
| 192 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 193 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 194 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 195 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 196 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 197 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 198 | |
| 199 | // Message codes used with mMainThreadHandler |
| 200 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 201 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 202 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 203 | private static final int CMD_OPEN_CHANNEL = 9; |
| 204 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 205 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 206 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 207 | private static final int CMD_NV_READ_ITEM = 13; |
| 208 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 209 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 210 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 211 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 212 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 213 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 214 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 215 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 216 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 217 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 218 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 219 | private static final int CMD_SEND_ENVELOPE = 25; |
| 220 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 221 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 222 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 223 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 224 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 225 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 226 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 227 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 228 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 229 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 230 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 231 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 232 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 233 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 234 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 235 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 236 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 237 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 238 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 239 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 240 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 241 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 242 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 243 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 244 | private static final int CMD_SWITCH_SLOTS = 50; |
| 245 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 246 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 247 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 248 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 249 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 250 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 251 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 252 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 253 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 254 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 255 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 256 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 257 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 258 | private static final int CMD_MODEM_REBOOT = 64; |
| 259 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 260 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 261 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 262 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 263 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 264 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 265 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 266 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 267 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 268 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 269 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 270 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 271 | // Parameters of select command. |
| 272 | private static final int SELECT_COMMAND = 0xA4; |
| 273 | private static final int SELECT_P1 = 0x04; |
| 274 | private static final int SELECT_P2 = 0; |
| 275 | private static final int SELECT_P3 = 0x10; |
| 276 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 277 | /** The singleton instance. */ |
| 278 | private static PhoneInterfaceManager sInstance; |
| 279 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 280 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 281 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 282 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 283 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 284 | private AppOpsManager mAppOps; |
| 285 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 286 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 287 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 288 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 289 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 290 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 291 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 292 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 293 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 294 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 295 | // String to store multi SIM allowed |
| 296 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 297 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 298 | // The AID of ISD-R. |
| 299 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 300 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 301 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 302 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 303 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 304 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 305 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 306 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 307 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 308 | */ |
| 309 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 310 | "reset_network_erase_modem_config_enabled"; |
| 311 | |
| 312 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 313 | * A request object to use for transmitting data to an ICC. |
| 314 | */ |
| 315 | private static final class IccAPDUArgument { |
| 316 | public int channel, cla, command, p1, p2, p3; |
| 317 | public String data; |
| 318 | |
| 319 | public IccAPDUArgument(int channel, int cla, int command, |
| 320 | int p1, int p2, int p3, String data) { |
| 321 | this.channel = channel; |
| 322 | this.cla = cla; |
| 323 | this.command = command; |
| 324 | this.p1 = p1; |
| 325 | this.p2 = p2; |
| 326 | this.p3 = p3; |
| 327 | this.data = data; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 332 | * A request object to use for transmitting data to an ICC. |
| 333 | */ |
| 334 | private static final class ManualNetworkSelectionArgument { |
| 335 | public OperatorInfo operatorInfo; |
| 336 | public boolean persistSelection; |
| 337 | |
| 338 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 339 | this.operatorInfo = operatorInfo; |
| 340 | this.persistSelection = persistSelection; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 345 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 346 | * request after sending. The main thread will notify the request when it is complete. |
| 347 | */ |
| 348 | private static final class MainThreadRequest { |
| 349 | /** The argument to use for the request */ |
| 350 | public Object argument; |
| 351 | /** The result of the request that is run on the main thread */ |
| 352 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 353 | // The subscriber id that this request applies to. Defaults to |
| 354 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 355 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 356 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 357 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 358 | public Phone phone; |
| 359 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 360 | public WorkSource workSource; |
| 361 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 362 | public MainThreadRequest(Object argument) { |
| 363 | this.argument = argument; |
| 364 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 365 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 366 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 367 | this.argument = argument; |
| 368 | if (phone != null) { |
| 369 | this.phone = phone; |
| 370 | } |
| 371 | this.workSource = workSource; |
| 372 | } |
| 373 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 374 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 375 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 376 | if (subId != null) { |
| 377 | this.subId = subId; |
| 378 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 379 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 380 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 383 | private static final class IncomingThirdPartyCallArgs { |
| 384 | public final ComponentName component; |
| 385 | public final String callId; |
| 386 | public final String callerDisplayName; |
| 387 | |
| 388 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 389 | String callerDisplayName) { |
| 390 | this.component = component; |
| 391 | this.callId = callId; |
| 392 | this.callerDisplayName = callerDisplayName; |
| 393 | } |
| 394 | } |
| 395 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 396 | /** |
| 397 | * A handler that processes messages on the main thread in the phone process. Since many |
| 398 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 399 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 400 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 401 | * on, which will be notified when the operation completes and will contain the result of the |
| 402 | * request. |
| 403 | * |
| 404 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 405 | * note that request.result must be set to something non-null for the calling thread to |
| 406 | * unblock. |
| 407 | */ |
| 408 | private final class MainThreadHandler extends Handler { |
| 409 | @Override |
| 410 | public void handleMessage(Message msg) { |
| 411 | MainThreadRequest request; |
| 412 | Message onCompleted; |
| 413 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 414 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 415 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 416 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 417 | |
| 418 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 419 | case CMD_HANDLE_USSD_REQUEST: { |
| 420 | request = (MainThreadRequest) msg.obj; |
| 421 | final Phone phone = getPhoneFromRequest(request); |
| 422 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 423 | String ussdRequest = ussdObject.first; |
| 424 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 425 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 426 | if (!isUssdApiAllowed(request.subId)) { |
| 427 | // Carrier does not support use of this API, return failure. |
| 428 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 429 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 430 | Bundle returnData = new Bundle(); |
| 431 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 432 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 433 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 434 | request.result = true; |
| 435 | notifyRequester(request); |
| 436 | return; |
| 437 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 438 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 439 | try { |
| 440 | request.result = phone != null |
| 441 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 442 | } catch (CallStateException cse) { |
| 443 | request.result = false; |
| 444 | } |
| 445 | // Wake up the requesting thread |
| 446 | notifyRequester(request); |
| 447 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 450 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 451 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 452 | final Phone phone = getPhoneFromRequest(request); |
| 453 | request.result = phone != null ? |
| 454 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 455 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 456 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 457 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 458 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 459 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 460 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 461 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 462 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 463 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 464 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 465 | if (uiccCard == null) { |
| 466 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 467 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 468 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 469 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 470 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 471 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 472 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 473 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 474 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 475 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 476 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 477 | break; |
| 478 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 479 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 480 | ar = (AsyncResult) msg.obj; |
| 481 | request = (MainThreadRequest) ar.userObj; |
| 482 | if (ar.exception == null && ar.result != null) { |
| 483 | request.result = ar.result; |
| 484 | } else { |
| 485 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 486 | if (ar.result == null) { |
| 487 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 488 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 489 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 490 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 491 | } else { |
| 492 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 493 | } |
| 494 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 495 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 496 | break; |
| 497 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 498 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 499 | request = (MainThreadRequest) msg.obj; |
| 500 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 501 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 502 | if (uiccCard == null) { |
| 503 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 504 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 505 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 506 | } else { |
| 507 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 508 | request); |
| 509 | uiccCard.iccTransmitApduBasicChannel( |
| 510 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 511 | iccArgument.p3, iccArgument.data, onCompleted); |
| 512 | } |
| 513 | break; |
| 514 | |
| 515 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 516 | ar = (AsyncResult) msg.obj; |
| 517 | request = (MainThreadRequest) ar.userObj; |
| 518 | if (ar.exception == null && ar.result != null) { |
| 519 | request.result = ar.result; |
| 520 | } else { |
| 521 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 522 | if (ar.result == null) { |
| 523 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 524 | } else if (ar.exception instanceof CommandException) { |
| 525 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 526 | ar.exception); |
| 527 | } else { |
| 528 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 529 | } |
| 530 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 531 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 532 | break; |
| 533 | |
| 534 | case CMD_EXCHANGE_SIM_IO: |
| 535 | request = (MainThreadRequest) msg.obj; |
| 536 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 537 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 538 | if (uiccCard == null) { |
| 539 | loge("iccExchangeSimIO: No UICC"); |
| 540 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 541 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 542 | } else { |
| 543 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 544 | request); |
| 545 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 546 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 547 | iccArgument.data, onCompleted); |
| 548 | } |
| 549 | break; |
| 550 | |
| 551 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 552 | ar = (AsyncResult) msg.obj; |
| 553 | request = (MainThreadRequest) ar.userObj; |
| 554 | if (ar.exception == null && ar.result != null) { |
| 555 | request.result = ar.result; |
| 556 | } else { |
| 557 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 558 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 559 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 560 | break; |
| 561 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 562 | case CMD_SEND_ENVELOPE: |
| 563 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 564 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 565 | if (uiccCard == null) { |
| 566 | loge("sendEnvelopeWithStatus: No UICC"); |
| 567 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 568 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 569 | } else { |
| 570 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 571 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 572 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 573 | break; |
| 574 | |
| 575 | case EVENT_SEND_ENVELOPE_DONE: |
| 576 | ar = (AsyncResult) msg.obj; |
| 577 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 578 | if (ar.exception == null && ar.result != null) { |
| 579 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 580 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 581 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 582 | if (ar.result == null) { |
| 583 | loge("sendEnvelopeWithStatus: Empty response"); |
| 584 | } else if (ar.exception instanceof CommandException) { |
| 585 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 586 | ar.exception); |
| 587 | } else { |
| 588 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 589 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 590 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 591 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 592 | break; |
| 593 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 594 | case CMD_OPEN_CHANNEL: |
| 595 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 596 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 597 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 598 | if (uiccCard == null) { |
| 599 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 600 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 601 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 602 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 603 | } else { |
| 604 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 605 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 606 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 607 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 608 | break; |
| 609 | |
| 610 | case EVENT_OPEN_CHANNEL_DONE: |
| 611 | ar = (AsyncResult) msg.obj; |
| 612 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 613 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 614 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 615 | int[] result = (int[]) ar.result; |
| 616 | int channelId = result[0]; |
| 617 | byte[] selectResponse = null; |
| 618 | if (result.length > 1) { |
| 619 | selectResponse = new byte[result.length - 1]; |
| 620 | for (int i = 1; i < result.length; ++i) { |
| 621 | selectResponse[i - 1] = (byte) result[i]; |
| 622 | } |
| 623 | } |
| 624 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 625 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 626 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 627 | if (ar.result == null) { |
| 628 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 629 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 630 | if (ar.exception != null) { |
| 631 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 632 | } |
| 633 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 634 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 635 | if (ar.exception instanceof CommandException) { |
| 636 | CommandException.Error error = |
| 637 | ((CommandException) (ar.exception)).getCommandError(); |
| 638 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 639 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 640 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 641 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 642 | } |
| 643 | } |
| 644 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 645 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 646 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 647 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 648 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 649 | break; |
| 650 | |
| 651 | case CMD_CLOSE_CHANNEL: |
| 652 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 653 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 654 | if (uiccCard == null) { |
| 655 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 656 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 657 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 658 | } else { |
| 659 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 660 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 661 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 662 | break; |
| 663 | |
| 664 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 665 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 666 | break; |
| 667 | |
| 668 | case CMD_NV_READ_ITEM: |
| 669 | request = (MainThreadRequest) msg.obj; |
| 670 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 671 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 672 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 673 | break; |
| 674 | |
| 675 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 676 | ar = (AsyncResult) msg.obj; |
| 677 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 678 | if (ar.exception == null && ar.result != null) { |
| 679 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 680 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 681 | request.result = ""; |
| 682 | if (ar.result == null) { |
| 683 | loge("nvReadItem: Empty response"); |
| 684 | } else if (ar.exception instanceof CommandException) { |
| 685 | loge("nvReadItem: CommandException: " + |
| 686 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 687 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 688 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 689 | } |
| 690 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 691 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 692 | break; |
| 693 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 694 | case CMD_NV_WRITE_ITEM: |
| 695 | request = (MainThreadRequest) msg.obj; |
| 696 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 697 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 698 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 699 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 700 | break; |
| 701 | |
| 702 | case EVENT_NV_WRITE_ITEM_DONE: |
| 703 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 704 | break; |
| 705 | |
| 706 | case CMD_NV_WRITE_CDMA_PRL: |
| 707 | request = (MainThreadRequest) msg.obj; |
| 708 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 709 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 710 | break; |
| 711 | |
| 712 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 713 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 714 | break; |
| 715 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 716 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 717 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 718 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 719 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 720 | break; |
| 721 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 722 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 723 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 724 | break; |
| 725 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 726 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 727 | request = (MainThreadRequest) msg.obj; |
| 728 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 729 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 730 | break; |
| 731 | |
| 732 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 733 | ar = (AsyncResult) msg.obj; |
| 734 | request = (MainThreadRequest) ar.userObj; |
| 735 | if (ar.exception == null && ar.result != null) { |
| 736 | request.result = ar.result; // Integer |
| 737 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 738 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 739 | if (ar.result == null) { |
| 740 | loge("getPreferredNetworkType: Empty response"); |
| 741 | } else if (ar.exception instanceof CommandException) { |
| 742 | loge("getPreferredNetworkType: CommandException: " + |
| 743 | ar.exception); |
| 744 | } else { |
| 745 | loge("getPreferredNetworkType: Unknown exception"); |
| 746 | } |
| 747 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 748 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 749 | break; |
| 750 | |
| 751 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 752 | request = (MainThreadRequest) msg.obj; |
| 753 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 754 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 755 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 756 | break; |
| 757 | |
| 758 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 759 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 760 | break; |
| 761 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 762 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 763 | request = (MainThreadRequest)msg.obj; |
| 764 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 765 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 766 | break; |
| 767 | |
| 768 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 769 | ar = (AsyncResult)msg.obj; |
| 770 | request = (MainThreadRequest)ar.userObj; |
| 771 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 772 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 773 | break; |
| 774 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 775 | case CMD_SET_VOICEMAIL_NUMBER: |
| 776 | request = (MainThreadRequest) msg.obj; |
| 777 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 778 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 779 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 780 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 781 | break; |
| 782 | |
| 783 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 784 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 785 | break; |
| 786 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 787 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 788 | request = (MainThreadRequest) msg.obj; |
| 789 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 790 | request); |
| 791 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 792 | break; |
| 793 | |
| 794 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 795 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 796 | break; |
| 797 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 798 | case CMD_PERFORM_NETWORK_SCAN: |
| 799 | request = (MainThreadRequest) msg.obj; |
| 800 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 801 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 802 | break; |
| 803 | |
| 804 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 805 | ar = (AsyncResult) msg.obj; |
| 806 | request = (MainThreadRequest) ar.userObj; |
| 807 | CellNetworkScanResult cellScanResult; |
| 808 | if (ar.exception == null && ar.result != null) { |
| 809 | cellScanResult = new CellNetworkScanResult( |
| 810 | CellNetworkScanResult.STATUS_SUCCESS, |
| 811 | (List<OperatorInfo>) ar.result); |
| 812 | } else { |
| 813 | if (ar.result == null) { |
| 814 | loge("getCellNetworkScanResults: Empty response"); |
| 815 | } |
| 816 | if (ar.exception != null) { |
| 817 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 818 | } |
| 819 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 820 | if (ar.exception instanceof CommandException) { |
| 821 | CommandException.Error error = |
| 822 | ((CommandException) (ar.exception)).getCommandError(); |
| 823 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 824 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 825 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 826 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 827 | } |
| 828 | } |
| 829 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 830 | } |
| 831 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 832 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 833 | break; |
| 834 | |
| 835 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 836 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 837 | ManualNetworkSelectionArgument selArg = |
| 838 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 839 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 840 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 841 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 842 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 843 | break; |
| 844 | |
| 845 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 846 | ar = (AsyncResult) msg.obj; |
| 847 | request = (MainThreadRequest) ar.userObj; |
| 848 | if (ar.exception == null) { |
| 849 | request.result = true; |
| 850 | } else { |
| 851 | request.result = false; |
| 852 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 853 | } |
| 854 | notifyRequester(request); |
| 855 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 856 | break; |
| 857 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 858 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 859 | request = (MainThreadRequest) msg.obj; |
| 860 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 861 | if (defaultPhone != null) { |
| 862 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 863 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 864 | break; |
| 865 | |
| 866 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 867 | ar = (AsyncResult) msg.obj; |
| 868 | request = (MainThreadRequest) ar.userObj; |
| 869 | if (ar.exception == null && ar.result != null) { |
| 870 | request.result = ar.result; |
| 871 | } else { |
| 872 | if (ar.result == null) { |
| 873 | loge("queryModemActivityInfo: Empty response"); |
| 874 | } else if (ar.exception instanceof CommandException) { |
| 875 | loge("queryModemActivityInfo: CommandException: " + |
| 876 | ar.exception); |
| 877 | } else { |
| 878 | loge("queryModemActivityInfo: Unknown exception"); |
| 879 | } |
| 880 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 881 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 882 | if (request.result == null) { |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 883 | request.result = new ModemActivityInfo(0, 0, 0, null, 0); |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 884 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 885 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 886 | break; |
| 887 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 888 | case CMD_SET_ALLOWED_CARRIERS: |
| 889 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 890 | CarrierRestrictionRules argument = |
| 891 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 892 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 893 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 894 | break; |
| 895 | |
| 896 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 897 | ar = (AsyncResult) msg.obj; |
| 898 | request = (MainThreadRequest) ar.userObj; |
| 899 | if (ar.exception == null && ar.result != null) { |
| 900 | request.result = ar.result; |
| 901 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 902 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 903 | if (ar.exception instanceof CommandException) { |
| 904 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 905 | CommandException.Error error = |
| 906 | ((CommandException) (ar.exception)).getCommandError(); |
| 907 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 908 | request.result = |
| 909 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 910 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 911 | } else { |
| 912 | loge("setAllowedCarriers: Unknown exception"); |
| 913 | } |
| 914 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 915 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 916 | break; |
| 917 | |
| 918 | case CMD_GET_ALLOWED_CARRIERS: |
| 919 | request = (MainThreadRequest) msg.obj; |
| 920 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 921 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 922 | break; |
| 923 | |
| 924 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 925 | ar = (AsyncResult) msg.obj; |
| 926 | request = (MainThreadRequest) ar.userObj; |
| 927 | if (ar.exception == null && ar.result != null) { |
| 928 | request.result = ar.result; |
| 929 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 930 | request.result = new IllegalStateException( |
| 931 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 932 | if (ar.result == null) { |
| 933 | loge("getAllowedCarriers: Empty response"); |
| 934 | } else if (ar.exception instanceof CommandException) { |
| 935 | loge("getAllowedCarriers: CommandException: " + |
| 936 | ar.exception); |
| 937 | } else { |
| 938 | loge("getAllowedCarriers: Unknown exception"); |
| 939 | } |
| 940 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 941 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 942 | break; |
| 943 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 944 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 945 | ar = (AsyncResult) msg.obj; |
| 946 | request = (MainThreadRequest) ar.userObj; |
| 947 | if (ar.exception == null && ar.result != null) { |
| 948 | request.result = ar.result; |
| 949 | } else { |
| 950 | request.result = new IllegalArgumentException( |
| 951 | "Failed to retrieve Forbidden Plmns"); |
| 952 | if (ar.result == null) { |
| 953 | loge("getForbiddenPlmns: Empty response"); |
| 954 | } else { |
| 955 | loge("getForbiddenPlmns: Unknown exception"); |
| 956 | } |
| 957 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 958 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 959 | break; |
| 960 | |
| 961 | case CMD_GET_FORBIDDEN_PLMNS: |
| 962 | request = (MainThreadRequest) msg.obj; |
| 963 | uiccCard = getUiccCardFromRequest(request); |
| 964 | if (uiccCard == null) { |
| 965 | loge("getForbiddenPlmns() UiccCard is null"); |
| 966 | request.result = new IllegalArgumentException( |
| 967 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 968 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 969 | break; |
| 970 | } |
| 971 | Integer appType = (Integer) request.argument; |
| 972 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 973 | if (uiccApp == null) { |
| 974 | loge("getForbiddenPlmns() no app with specified type -- " |
| 975 | + appType); |
| 976 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 977 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 978 | break; |
| 979 | } else { |
| 980 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 981 | + " specified type -- " + appType); |
| 982 | } |
| 983 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 984 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 985 | onCompleted); |
| 986 | break; |
| 987 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 988 | case CMD_SWITCH_SLOTS: |
| 989 | request = (MainThreadRequest) msg.obj; |
| 990 | int[] physicalSlots = (int[]) request.argument; |
| 991 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 992 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 993 | break; |
| 994 | |
| 995 | case EVENT_SWITCH_SLOTS_DONE: |
| 996 | ar = (AsyncResult) msg.obj; |
| 997 | request = (MainThreadRequest) ar.userObj; |
| 998 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 999 | notifyRequester(request); |
| 1000 | break; |
| 1001 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1002 | request = (MainThreadRequest) msg.obj; |
| 1003 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1004 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1005 | break; |
| 1006 | |
| 1007 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1008 | ar = (AsyncResult) msg.obj; |
| 1009 | request = (MainThreadRequest) ar.userObj; |
| 1010 | if (ar.exception != null) { |
| 1011 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1012 | } else { |
| 1013 | int mode = ((int[]) ar.result)[0]; |
| 1014 | if (mode == 0) { |
| 1015 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1016 | } else { |
| 1017 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1018 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1019 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1020 | notifyRequester(request); |
| 1021 | break; |
| 1022 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1023 | request = (MainThreadRequest) msg.obj; |
| 1024 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1025 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1026 | break; |
| 1027 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1028 | ar = (AsyncResult) msg.obj; |
| 1029 | request = (MainThreadRequest) ar.userObj; |
| 1030 | if (ar.exception != null) { |
| 1031 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1032 | } else { |
| 1033 | request.result = ((int[]) ar.result)[0]; |
| 1034 | } |
| 1035 | notifyRequester(request); |
| 1036 | break; |
| 1037 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1038 | request = (MainThreadRequest) msg.obj; |
| 1039 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1040 | int mode = (int) request.argument; |
| 1041 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1042 | break; |
| 1043 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1044 | ar = (AsyncResult) msg.obj; |
| 1045 | request = (MainThreadRequest) ar.userObj; |
| 1046 | request.result = ar.exception == null; |
| 1047 | notifyRequester(request); |
| 1048 | break; |
| 1049 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1050 | request = (MainThreadRequest) msg.obj; |
| 1051 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1052 | int subscriptionMode = (int) request.argument; |
| 1053 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1054 | break; |
| 1055 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1056 | ar = (AsyncResult) msg.obj; |
| 1057 | request = (MainThreadRequest) ar.userObj; |
| 1058 | request.result = ar.exception == null; |
| 1059 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1060 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1061 | case CMD_GET_ALL_CELL_INFO: |
| 1062 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1063 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1064 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1065 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1066 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1067 | ar = (AsyncResult) msg.obj; |
| 1068 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1069 | // If a timeout occurs, the response will be null |
| 1070 | request.result = (ar.exception == null && ar.result != null) |
| 1071 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1072 | synchronized (request) { |
| 1073 | request.notifyAll(); |
| 1074 | } |
| 1075 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1076 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1077 | request = (MainThreadRequest) msg.obj; |
| 1078 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1079 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1080 | break; |
| 1081 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1082 | ar = (AsyncResult) msg.obj; |
| 1083 | request = (MainThreadRequest) ar.userObj; |
| 1084 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1085 | try { |
| 1086 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1087 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1088 | cb.onError( |
| 1089 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1090 | ar.exception.getClass().getName(), |
| 1091 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1092 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1093 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1094 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1095 | } else { |
| 1096 | // use the result as returned |
| 1097 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1098 | } |
| 1099 | } catch (RemoteException re) { |
| 1100 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1101 | } |
| 1102 | break; |
| 1103 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1104 | request = (MainThreadRequest) msg.obj; |
| 1105 | WorkSource ws = (WorkSource) request.argument; |
| 1106 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1107 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1108 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1109 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1110 | ar = (AsyncResult) msg.obj; |
| 1111 | request = (MainThreadRequest) ar.userObj; |
| 1112 | if (ar.exception == null) { |
| 1113 | request.result = ar.result; |
| 1114 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1115 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1116 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1117 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | synchronized (request) { |
| 1121 | request.notifyAll(); |
| 1122 | } |
| 1123 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1124 | case CMD_MODEM_REBOOT: |
| 1125 | request = (MainThreadRequest) msg.obj; |
| 1126 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1127 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1128 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1129 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1130 | handleNullReturnEvent(msg, "rebootModem"); |
| 1131 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1132 | case CMD_REQUEST_ENABLE_MODEM: |
| 1133 | request = (MainThreadRequest) msg.obj; |
| 1134 | boolean enable = (boolean) request.argument; |
| 1135 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1136 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1137 | PhoneConfigurationManager.getInstance() |
| 1138 | .enablePhone(request.phone, enable, onCompleted); |
| 1139 | break; |
| 1140 | case EVENT_ENABLE_MODEM_DONE: |
| 1141 | ar = (AsyncResult) msg.obj; |
| 1142 | request = (MainThreadRequest) ar.userObj; |
| 1143 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1144 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1145 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1146 | if ((boolean) request.result) { |
| 1147 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1148 | updateModemStateMetrics(); |
| 1149 | } else { |
| 1150 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1151 | + ar.exception); |
| 1152 | } |
| 1153 | notifyRequester(request); |
| 1154 | break; |
| 1155 | case CMD_GET_MODEM_STATUS: |
| 1156 | request = (MainThreadRequest) msg.obj; |
| 1157 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1158 | PhoneConfigurationManager.getInstance() |
| 1159 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1160 | break; |
| 1161 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1162 | ar = (AsyncResult) msg.obj; |
| 1163 | request = (MainThreadRequest) ar.userObj; |
| 1164 | int id = request.phone.getPhoneId(); |
| 1165 | if (ar.exception == null && ar.result != null) { |
| 1166 | request.result = ar.result; |
| 1167 | //update the cache as modem status has changed |
| 1168 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1169 | (boolean) request.result); |
| 1170 | } else { |
| 1171 | // Return true if modem status cannot be retrieved. For most cases, |
| 1172 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1173 | // and disable modem are not supported. Modem is always on. |
| 1174 | // TODO: this should be fixed in R to support a third |
| 1175 | // status UNKNOWN b/131631629 |
| 1176 | request.result = true; |
| 1177 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1178 | + ar.exception); |
| 1179 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1180 | notifyRequester(request); |
| 1181 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1182 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1183 | ar = (AsyncResult) msg.obj; |
| 1184 | request = (MainThreadRequest) ar.userObj; |
| 1185 | if (ar.exception == null && ar.result != null) { |
| 1186 | request.result = ar.result; |
| 1187 | } else { |
| 1188 | request.result = -1; |
| 1189 | loge("Failed to set Forbidden Plmns"); |
| 1190 | if (ar.result == null) { |
| 1191 | loge("setForbidenPlmns: Empty response"); |
| 1192 | } else if (ar.exception != null) { |
| 1193 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1194 | request.result = -1; |
| 1195 | } else { |
| 1196 | loge("setForbiddenPlmns: Unknown exception"); |
| 1197 | } |
| 1198 | } |
| 1199 | notifyRequester(request); |
| 1200 | break; |
| 1201 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1202 | request = (MainThreadRequest) msg.obj; |
| 1203 | uiccCard = getUiccCardFromRequest(request); |
| 1204 | if (uiccCard == null) { |
| 1205 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1206 | request.result = -1; |
| 1207 | notifyRequester(request); |
| 1208 | break; |
| 1209 | } |
| 1210 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1211 | (Pair<Integer, List<String>>) request.argument; |
| 1212 | appType = setFplmnsArgs.first; |
| 1213 | List<String> fplmns = setFplmnsArgs.second; |
| 1214 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1215 | if (uiccApp == null) { |
| 1216 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1217 | request.result = -1; |
| 1218 | loge("Failed to get UICC App"); |
| 1219 | notifyRequester(request); |
| 1220 | } else { |
| 1221 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1222 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1223 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1224 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1225 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1226 | case CMD_ERASE_MODEM_CONFIG: |
| 1227 | request = (MainThreadRequest) msg.obj; |
| 1228 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1229 | defaultPhone.eraseModemConfig(onCompleted); |
| 1230 | break; |
| 1231 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1232 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1233 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1234 | default: |
| 1235 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1236 | break; |
| 1237 | } |
| 1238 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1239 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1240 | private void notifyRequester(MainThreadRequest request) { |
| 1241 | synchronized (request) { |
| 1242 | request.notifyAll(); |
| 1243 | } |
| 1244 | } |
| 1245 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1246 | private void handleNullReturnEvent(Message msg, String command) { |
| 1247 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1248 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1249 | if (ar.exception == null) { |
| 1250 | request.result = true; |
| 1251 | } else { |
| 1252 | request.result = false; |
| 1253 | if (ar.exception instanceof CommandException) { |
| 1254 | loge(command + ": CommandException: " + ar.exception); |
| 1255 | } else { |
| 1256 | loge(command + ": Unknown exception"); |
| 1257 | } |
| 1258 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1259 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1260 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | /** |
| 1264 | * Posts the specified command to be executed on the main thread, |
| 1265 | * waits for the request to complete, and returns the result. |
| 1266 | * @see #sendRequestAsync |
| 1267 | */ |
| 1268 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1269 | return sendRequest( |
| 1270 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | /** |
| 1274 | * Posts the specified command to be executed on the main thread, |
| 1275 | * waits for the request to complete, and returns the result. |
| 1276 | * @see #sendRequestAsync |
| 1277 | */ |
| 1278 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1279 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1280 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | /** |
| 1284 | * Posts the specified command to be executed on the main thread, |
| 1285 | * waits for the request to complete, and returns the result. |
| 1286 | * @see #sendRequestAsync |
| 1287 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1288 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1289 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | /** |
| 1293 | * Posts the specified command to be executed on the main thread, |
| 1294 | * waits for the request to complete, and returns the result. |
| 1295 | * @see #sendRequestAsync |
| 1296 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1297 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1298 | return sendRequest(command, argument, subId, null, workSource); |
| 1299 | } |
| 1300 | |
| 1301 | /** |
| 1302 | * Posts the specified command to be executed on the main thread, |
| 1303 | * waits for the request to complete, and returns the result. |
| 1304 | * @see #sendRequestAsync |
| 1305 | */ |
| 1306 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1307 | return sendRequest( |
| 1308 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1309 | } |
| 1310 | |
| 1311 | /** |
| 1312 | * Posts the specified command to be executed on the main thread, |
| 1313 | * waits for the request to complete, and returns the result. |
| 1314 | * @see #sendRequestAsync |
| 1315 | */ |
| 1316 | private Object sendRequest( |
| 1317 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1318 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1319 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1320 | } |
| 1321 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1322 | MainThreadRequest request = null; |
| 1323 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1324 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1325 | } else if (phone != null) { |
| 1326 | request = new MainThreadRequest(argument, phone, workSource); |
| 1327 | } else { |
| 1328 | request = new MainThreadRequest(argument, subId, workSource); |
| 1329 | } |
| 1330 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1331 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1332 | msg.sendToTarget(); |
| 1333 | |
| 1334 | // Wait for the request to complete |
| 1335 | synchronized (request) { |
| 1336 | while (request.result == null) { |
| 1337 | try { |
| 1338 | request.wait(); |
| 1339 | } catch (InterruptedException e) { |
| 1340 | // Do nothing, go back and wait until the request is complete |
| 1341 | } |
| 1342 | } |
| 1343 | } |
| 1344 | return request.result; |
| 1345 | } |
| 1346 | |
| 1347 | /** |
| 1348 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1349 | * Posts the specified command to be executed on the main thread, and |
| 1350 | * returns immediately. |
| 1351 | * @see #sendRequest |
| 1352 | */ |
| 1353 | private void sendRequestAsync(int command) { |
| 1354 | mMainThreadHandler.sendEmptyMessage(command); |
| 1355 | } |
| 1356 | |
| 1357 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1358 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1359 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1360 | */ |
| 1361 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1362 | sendRequestAsync(command, argument, null, null); |
| 1363 | } |
| 1364 | |
| 1365 | /** |
| 1366 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1367 | * @see {@link #sendRequest(int,Object)} |
| 1368 | */ |
| 1369 | private void sendRequestAsync( |
| 1370 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1371 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1372 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1373 | msg.sendToTarget(); |
| 1374 | } |
| 1375 | |
| 1376 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1377 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1378 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1379 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1380 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1381 | synchronized (PhoneInterfaceManager.class) { |
| 1382 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1383 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1384 | } else { |
| 1385 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1386 | } |
| 1387 | return sInstance; |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1392 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1393 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1394 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1395 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1396 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1397 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1398 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1399 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1400 | mTelephonySharedPreferences = |
| 1401 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1402 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1403 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1404 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1405 | publish(); |
| 1406 | } |
| 1407 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1408 | private Phone getDefaultPhone() { |
| 1409 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1410 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1411 | } |
| 1412 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1413 | private void publish() { |
| 1414 | if (DBG) log("publish: " + this); |
| 1415 | |
| 1416 | ServiceManager.addService("phone", this); |
| 1417 | } |
| 1418 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1419 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1420 | if (request.phone != null) { |
| 1421 | return request.phone; |
| 1422 | } else { |
| 1423 | return getPhoneFromSubId(request.subId); |
| 1424 | } |
| 1425 | } |
| 1426 | |
| 1427 | private Phone getPhoneFromSubId(int subId) { |
| 1428 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1429 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1430 | } |
| 1431 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1432 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1433 | Phone phone = getPhoneFromRequest(request); |
| 1434 | return phone == null ? null : |
| 1435 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1436 | } |
| 1437 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1438 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1439 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1440 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1441 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1442 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1443 | private void sendEraseModemConfig(Phone phone) { |
| 1444 | if (phone != null) { |
| 1445 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1446 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1447 | final long identity = Binder.clearCallingIdentity(); |
| 1448 | try { |
| 1449 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1450 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1451 | } finally { |
| 1452 | Binder.restoreCallingIdentity(identity); |
| 1453 | } |
| 1454 | } |
| 1455 | } |
| 1456 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1457 | private boolean isImsAvailableOnDevice() { |
| 1458 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1459 | if (pm == null) { |
| 1460 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1461 | // so do not throw error and allow. |
| 1462 | return true; |
| 1463 | } |
| 1464 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1465 | } |
| 1466 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1467 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1468 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1471 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1472 | if (DBG) log("dial: " + number); |
| 1473 | // No permission check needed here: This is just a wrapper around the |
| 1474 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1475 | // the UI before it does anything. |
| 1476 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1477 | final long identity = Binder.clearCallingIdentity(); |
| 1478 | try { |
| 1479 | String url = createTelUrl(number); |
| 1480 | if (url == null) { |
| 1481 | return; |
| 1482 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1483 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1484 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1485 | PhoneConstants.State state = mCM.getState(subId); |
| 1486 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1487 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1488 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1489 | mApp.startActivity(intent); |
| 1490 | } |
| 1491 | } finally { |
| 1492 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1497 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1500 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1501 | if (DBG) log("call: " + number); |
| 1502 | |
| 1503 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1504 | // need to do a permission check since we're calling startActivity() |
| 1505 | // from the context of the phone app. |
| 1506 | enforceCallPermission(); |
| 1507 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1508 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1509 | != AppOpsManager.MODE_ALLOWED) { |
| 1510 | return; |
| 1511 | } |
| 1512 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1513 | final long identity = Binder.clearCallingIdentity(); |
| 1514 | try { |
| 1515 | String url = createTelUrl(number); |
| 1516 | if (url == null) { |
| 1517 | return; |
| 1518 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1519 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1520 | boolean isValid = false; |
| 1521 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1522 | if (slist != null) { |
| 1523 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1524 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1525 | isValid = true; |
| 1526 | break; |
| 1527 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1528 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1529 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1530 | if (!isValid) { |
| 1531 | return; |
| 1532 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1533 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1534 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1535 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1536 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1537 | mApp.startActivity(intent); |
| 1538 | } finally { |
| 1539 | Binder.restoreCallingIdentity(identity); |
| 1540 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1541 | } |
| 1542 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1543 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1544 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1545 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1546 | } |
| 1547 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1548 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1549 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1550 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1551 | } |
| 1552 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1553 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1554 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1555 | |
| 1556 | final long identity = Binder.clearCallingIdentity(); |
| 1557 | try { |
| 1558 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1559 | checkSimPin.start(); |
| 1560 | return checkSimPin.unlockSim(null, pin); |
| 1561 | } finally { |
| 1562 | Binder.restoreCallingIdentity(identity); |
| 1563 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1564 | } |
| 1565 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1566 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1567 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1568 | |
| 1569 | final long identity = Binder.clearCallingIdentity(); |
| 1570 | try { |
| 1571 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1572 | checkSimPuk.start(); |
| 1573 | return checkSimPuk.unlockSim(puk, pin); |
| 1574 | } finally { |
| 1575 | Binder.restoreCallingIdentity(identity); |
| 1576 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1580 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1581 | * a synchronous one. |
| 1582 | */ |
| 1583 | private static class UnlockSim extends Thread { |
| 1584 | |
| 1585 | private final IccCard mSimCard; |
| 1586 | |
| 1587 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1588 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1589 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1590 | |
| 1591 | // For replies from SimCard interface |
| 1592 | private Handler mHandler; |
| 1593 | |
| 1594 | // For async handler to identify request type |
| 1595 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1596 | |
| 1597 | public UnlockSim(IccCard simCard) { |
| 1598 | mSimCard = simCard; |
| 1599 | } |
| 1600 | |
| 1601 | @Override |
| 1602 | public void run() { |
| 1603 | Looper.prepare(); |
| 1604 | synchronized (UnlockSim.this) { |
| 1605 | mHandler = new Handler() { |
| 1606 | @Override |
| 1607 | public void handleMessage(Message msg) { |
| 1608 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1609 | switch (msg.what) { |
| 1610 | case SUPPLY_PIN_COMPLETE: |
| 1611 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1612 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1613 | mRetryCount = msg.arg1; |
| 1614 | if (ar.exception != null) { |
| 1615 | if (ar.exception instanceof CommandException && |
| 1616 | ((CommandException)(ar.exception)).getCommandError() |
| 1617 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1618 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1619 | } else { |
| 1620 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1621 | } |
| 1622 | } else { |
| 1623 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1624 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1625 | mDone = true; |
| 1626 | UnlockSim.this.notifyAll(); |
| 1627 | } |
| 1628 | break; |
| 1629 | } |
| 1630 | } |
| 1631 | }; |
| 1632 | UnlockSim.this.notifyAll(); |
| 1633 | } |
| 1634 | Looper.loop(); |
| 1635 | } |
| 1636 | |
| 1637 | /* |
| 1638 | * Use PIN or PUK to unlock SIM card |
| 1639 | * |
| 1640 | * If PUK is null, unlock SIM card with PIN |
| 1641 | * |
| 1642 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1643 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1644 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1645 | |
| 1646 | while (mHandler == null) { |
| 1647 | try { |
| 1648 | wait(); |
| 1649 | } catch (InterruptedException e) { |
| 1650 | Thread.currentThread().interrupt(); |
| 1651 | } |
| 1652 | } |
| 1653 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1654 | |
| 1655 | if (puk == null) { |
| 1656 | mSimCard.supplyPin(pin, callback); |
| 1657 | } else { |
| 1658 | mSimCard.supplyPuk(puk, pin, callback); |
| 1659 | } |
| 1660 | |
| 1661 | while (!mDone) { |
| 1662 | try { |
| 1663 | Log.d(LOG_TAG, "wait for done"); |
| 1664 | wait(); |
| 1665 | } catch (InterruptedException e) { |
| 1666 | // Restore the interrupted status |
| 1667 | Thread.currentThread().interrupt(); |
| 1668 | } |
| 1669 | } |
| 1670 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1671 | int[] resultArray = new int[2]; |
| 1672 | resultArray[0] = mResult; |
| 1673 | resultArray[1] = mRetryCount; |
| 1674 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1675 | } |
| 1676 | } |
| 1677 | |
| 1678 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1679 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1680 | |
| 1681 | } |
| 1682 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1683 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1684 | // No permission check needed here: this call is harmless, and it's |
| 1685 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1686 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1687 | final long identity = Binder.clearCallingIdentity(); |
| 1688 | try { |
| 1689 | final Phone phone = getPhone(subId); |
| 1690 | if (phone != null) { |
| 1691 | phone.updateServiceLocation(); |
| 1692 | } |
| 1693 | } finally { |
| 1694 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1695 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1696 | } |
| 1697 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1698 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1699 | @Override |
| 1700 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1701 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1702 | } |
| 1703 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1704 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1705 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1706 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1707 | callingFeatureId); |
| 1708 | } |
| 1709 | |
| 1710 | @Deprecated |
| 1711 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1712 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1713 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 1714 | } |
| 1715 | |
| 1716 | @Override |
| 1717 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1718 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1719 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1720 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1721 | return false; |
| 1722 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1723 | |
| 1724 | final long identity = Binder.clearCallingIdentity(); |
| 1725 | try { |
| 1726 | return isRadioOnForSubscriber(subId); |
| 1727 | } finally { |
| 1728 | Binder.restoreCallingIdentity(identity); |
| 1729 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1733 | final long identity = Binder.clearCallingIdentity(); |
| 1734 | try { |
| 1735 | final Phone phone = getPhone(subId); |
| 1736 | if (phone != null) { |
| 1737 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1738 | } else { |
| 1739 | return false; |
| 1740 | } |
| 1741 | } finally { |
| 1742 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1743 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1747 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1748 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1749 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1750 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1751 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1752 | |
| 1753 | final long identity = Binder.clearCallingIdentity(); |
| 1754 | try { |
| 1755 | final Phone phone = getPhone(subId); |
| 1756 | if (phone != null) { |
| 1757 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1758 | } |
| 1759 | } finally { |
| 1760 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1761 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1765 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1768 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1769 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1770 | |
| 1771 | final long identity = Binder.clearCallingIdentity(); |
| 1772 | try { |
| 1773 | final Phone phone = getPhone(subId); |
| 1774 | if (phone == null) { |
| 1775 | return false; |
| 1776 | } |
| 1777 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1778 | toggleRadioOnOffForSubscriber(subId); |
| 1779 | } |
| 1780 | return true; |
| 1781 | } finally { |
| 1782 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1783 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1784 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1785 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1786 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 1787 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1788 | /* |
| 1789 | * If any of the Radios are available, it will need to be |
| 1790 | * shutdown. So return true if any Radio is available. |
| 1791 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1792 | final long identity = Binder.clearCallingIdentity(); |
| 1793 | try { |
| 1794 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1795 | Phone phone = PhoneFactory.getPhone(i); |
| 1796 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1797 | } |
| 1798 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1799 | return false; |
| 1800 | } finally { |
| 1801 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1802 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1805 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1806 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1807 | enforceModifyPermission(); |
| 1808 | |
| 1809 | final long identity = Binder.clearCallingIdentity(); |
| 1810 | try { |
| 1811 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1812 | logv("Shutting down Phone " + i); |
| 1813 | shutdownRadioUsingPhoneId(i); |
| 1814 | } |
| 1815 | } finally { |
| 1816 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1821 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1822 | if (phone != null && phone.isRadioAvailable()) { |
| 1823 | phone.shutdownRadio(); |
| 1824 | } |
| 1825 | } |
| 1826 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1827 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1828 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1829 | |
| 1830 | final long identity = Binder.clearCallingIdentity(); |
| 1831 | try { |
| 1832 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1833 | if (defaultPhone != null) { |
| 1834 | defaultPhone.setRadioPower(turnOn); |
| 1835 | return true; |
| 1836 | } else { |
| 1837 | loge("There's no default phone."); |
| 1838 | return false; |
| 1839 | } |
| 1840 | } finally { |
| 1841 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1842 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1845 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1846 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1847 | |
| 1848 | final long identity = Binder.clearCallingIdentity(); |
| 1849 | try { |
| 1850 | final Phone phone = getPhone(subId); |
| 1851 | if (phone != null) { |
| 1852 | phone.setRadioPower(turnOn); |
| 1853 | return true; |
| 1854 | } else { |
| 1855 | return false; |
| 1856 | } |
| 1857 | } finally { |
| 1858 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1859 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1862 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1863 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1864 | public boolean enableDataConnectivity() { |
| 1865 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1866 | |
| 1867 | final long identity = Binder.clearCallingIdentity(); |
| 1868 | try { |
| 1869 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1870 | final Phone phone = getPhone(subId); |
| 1871 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1872 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1873 | return true; |
| 1874 | } else { |
| 1875 | return false; |
| 1876 | } |
| 1877 | } finally { |
| 1878 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1879 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1880 | } |
| 1881 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1882 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1883 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1884 | public boolean disableDataConnectivity() { |
| 1885 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1886 | |
| 1887 | final long identity = Binder.clearCallingIdentity(); |
| 1888 | try { |
| 1889 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1890 | final Phone phone = getPhone(subId); |
| 1891 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1892 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1893 | return true; |
| 1894 | } else { |
| 1895 | return false; |
| 1896 | } |
| 1897 | } finally { |
| 1898 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1899 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1900 | } |
| 1901 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1902 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1903 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1904 | final long identity = Binder.clearCallingIdentity(); |
| 1905 | try { |
| 1906 | final Phone phone = getPhone(subId); |
| 1907 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1908 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1909 | } else { |
| 1910 | return false; |
| 1911 | } |
| 1912 | } finally { |
| 1913 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1914 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1918 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1919 | } |
| 1920 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1921 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1922 | enforceCallPermission(); |
| 1923 | |
| 1924 | final long identity = Binder.clearCallingIdentity(); |
| 1925 | try { |
| 1926 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1927 | return; |
| 1928 | } |
| 1929 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1930 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1931 | } finally { |
| 1932 | Binder.restoreCallingIdentity(identity); |
| 1933 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1934 | }; |
| 1935 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1936 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1937 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1938 | |
| 1939 | final long identity = Binder.clearCallingIdentity(); |
| 1940 | try { |
| 1941 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1942 | return false; |
| 1943 | } |
| 1944 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1945 | } finally { |
| 1946 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1947 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1950 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1951 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1954 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1955 | final long identity = Binder.clearCallingIdentity(); |
| 1956 | try { |
| 1957 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1958 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1959 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1960 | } finally { |
| 1961 | Binder.restoreCallingIdentity(identity); |
| 1962 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1965 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1966 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1967 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1968 | } |
| 1969 | |
| 1970 | @Override |
| 1971 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1972 | final long identity = Binder.clearCallingIdentity(); |
| 1973 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1974 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1975 | if (phone != null) { |
| 1976 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1977 | } else { |
| 1978 | return PhoneConstantConversions.convertDataState( |
| 1979 | PhoneConstants.DataState.DISCONNECTED); |
| 1980 | } |
| 1981 | } finally { |
| 1982 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1983 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1986 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1987 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1988 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1989 | } |
| 1990 | |
| 1991 | @Override |
| 1992 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1993 | final long identity = Binder.clearCallingIdentity(); |
| 1994 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1995 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1996 | if (phone != null) { |
| 1997 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1998 | } else { |
| 1999 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2000 | } |
| 2001 | } finally { |
| 2002 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2003 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2007 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2008 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2009 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2010 | |
| 2011 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2012 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2013 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2014 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2015 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2016 | .setCallingPid(Binder.getCallingPid()) |
| 2017 | .setCallingUid(Binder.getCallingUid()) |
| 2018 | .setMethod("getCellLocation") |
| 2019 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2020 | .build()); |
| 2021 | switch (locationResult) { |
| 2022 | case DENIED_HARD: |
| 2023 | throw new SecurityException("Not allowed to access cell location"); |
| 2024 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2025 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2026 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2027 | } |
| 2028 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2029 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2030 | final long identity = Binder.clearCallingIdentity(); |
| 2031 | try { |
| 2032 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2033 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2034 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2035 | } finally { |
| 2036 | Binder.restoreCallingIdentity(identity); |
| 2037 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2040 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2041 | public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage, |
| 2042 | String callingFeatureId) { |
Jack Yu | 7c5d91a | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2043 | if (!TextUtils.isEmpty(callingPackage)) { |
| 2044 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2045 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2046 | callingFeatureId, "getNetworkCountryIsoForPhone")) { |
Jack Yu | 7c5d91a | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2047 | return ""; |
| 2048 | } |
| 2049 | } |
| 2050 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2051 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2052 | // registered cell info, so return a NULL country instead. |
| 2053 | final long identity = Binder.clearCallingIdentity(); |
| 2054 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2055 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2056 | // Get default phone in this case. |
| 2057 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2058 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2059 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2060 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2061 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2062 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2063 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(), |
| 2064 | null)) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2065 | return ""; |
| 2066 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2067 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2068 | if (phone != null) { |
| 2069 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2070 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2071 | if (sst != null) { |
| 2072 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2073 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2074 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2075 | return lt.getCurrentCountry(); |
| 2076 | } else if (emergencyNumberTracker != null) { |
| 2077 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2078 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2079 | } |
| 2080 | } |
| 2081 | } |
| 2082 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2083 | } finally { |
| 2084 | Binder.restoreCallingIdentity(identity); |
| 2085 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2089 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2090 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2091 | } |
| 2092 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2093 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2094 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2095 | mApp.enforceCallingOrSelfPermission( |
| 2096 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2097 | |
| 2098 | final long identity = Binder.clearCallingIdentity(); |
| 2099 | try { |
| 2100 | final Phone phone = getPhone(subId); |
| 2101 | if (phone != null) { |
| 2102 | phone.enableLocationUpdates(); |
| 2103 | } |
| 2104 | } finally { |
| 2105 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2106 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | @Override |
| 2110 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2111 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2114 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2115 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2116 | mApp.enforceCallingOrSelfPermission( |
| 2117 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2118 | |
| 2119 | final long identity = Binder.clearCallingIdentity(); |
| 2120 | try { |
| 2121 | final Phone phone = getPhone(subId); |
| 2122 | if (phone != null) { |
| 2123 | phone.disableLocationUpdates(); |
| 2124 | } |
| 2125 | } finally { |
| 2126 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2127 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2128 | } |
| 2129 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2130 | /** |
| 2131 | * Returns the target SDK version number for a given package name. |
| 2132 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2133 | * This call MUST be invoked before clearing the calling UID. |
| 2134 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2135 | * @return target SDK if the package is found or INT_MAX. |
| 2136 | */ |
| 2137 | private int getTargetSdk(String packageName) { |
| 2138 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2139 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2140 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2141 | if (ai != null) return ai.targetSdkVersion; |
| 2142 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2143 | loge("Failed to get package info for pkg=" |
| 2144 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2145 | } |
| 2146 | return Integer.MAX_VALUE; |
| 2147 | } |
| 2148 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2149 | @Override |
| 2150 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2151 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2152 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2153 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2154 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2155 | throw new SecurityException( |
| 2156 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2157 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2158 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2159 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2160 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2161 | return null; |
| 2162 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2163 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2164 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2165 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2166 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2167 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2168 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2169 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2170 | for (CellInfo ci : info) { |
| 2171 | if (ci instanceof CellInfoGsm) { |
| 2172 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2173 | } else if (ci instanceof CellInfoWcdma) { |
| 2174 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2175 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2176 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2177 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2178 | } |
| 2179 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2180 | private List<CellInfo> getCachedCellInfo() { |
| 2181 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2182 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2183 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2184 | if (info != null) cellInfos.addAll(info); |
| 2185 | } |
| 2186 | return cellInfos; |
| 2187 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2188 | |
| 2189 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2190 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2191 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2192 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2193 | |
| 2194 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2195 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2196 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2197 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2198 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2199 | .setCallingPid(Binder.getCallingPid()) |
| 2200 | .setCallingUid(Binder.getCallingUid()) |
| 2201 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2202 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2203 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2204 | .build()); |
| 2205 | switch (locationResult) { |
| 2206 | case DENIED_HARD: |
| 2207 | throw new SecurityException("Not allowed to access cell info"); |
| 2208 | case DENIED_SOFT: |
| 2209 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2210 | } |
| 2211 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2212 | final int targetSdk = getTargetSdk(callingPackage); |
| 2213 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2214 | return getCachedCellInfo(); |
| 2215 | } |
| 2216 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2217 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2218 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2219 | final long identity = Binder.clearCallingIdentity(); |
| 2220 | try { |
| 2221 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2222 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2223 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2224 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2225 | if (info != null) cellInfos.addAll(info); |
| 2226 | } |
| 2227 | return cellInfos; |
| 2228 | } finally { |
| 2229 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2230 | } |
| 2231 | } |
| 2232 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2233 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2234 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2235 | String callingFeatureId) { |
| 2236 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2237 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2241 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2242 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2243 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2244 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2245 | } |
| 2246 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2247 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2248 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2249 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2250 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2251 | |
| 2252 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2253 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2254 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2255 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2256 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2257 | .setCallingPid(Binder.getCallingPid()) |
| 2258 | .setCallingUid(Binder.getCallingUid()) |
| 2259 | .setMethod("requestCellInfoUpdate") |
| 2260 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2261 | .build()); |
| 2262 | switch (locationResult) { |
| 2263 | case DENIED_HARD: |
| 2264 | throw new SecurityException("Not allowed to access cell info"); |
| 2265 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2266 | try { |
| 2267 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2268 | } catch (RemoteException re) { |
| 2269 | // Drop without consequences |
| 2270 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2271 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2272 | } |
| 2273 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2274 | |
| 2275 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2276 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2277 | |
| 2278 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2279 | } |
| 2280 | |
| 2281 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2282 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2283 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2284 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2285 | |
| 2286 | final long identity = Binder.clearCallingIdentity(); |
| 2287 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2288 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2289 | } finally { |
| 2290 | Binder.restoreCallingIdentity(identity); |
| 2291 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2292 | } |
| 2293 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2294 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2295 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2296 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2297 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2298 | return null; |
| 2299 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2300 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2301 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2302 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2303 | return null; |
| 2304 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2305 | |
| 2306 | final long identity = Binder.clearCallingIdentity(); |
| 2307 | try { |
| 2308 | return phone.getImei(); |
| 2309 | } finally { |
| 2310 | Binder.restoreCallingIdentity(identity); |
| 2311 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2315 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2316 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2317 | String tac = null; |
| 2318 | if (phone != null) { |
| 2319 | String imei = phone.getImei(); |
| 2320 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2321 | } |
| 2322 | return tac; |
| 2323 | } |
| 2324 | |
| 2325 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2326 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2327 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2328 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2329 | return null; |
| 2330 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2331 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2332 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2333 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2334 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2335 | return null; |
| 2336 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2337 | |
| 2338 | final long identity = Binder.clearCallingIdentity(); |
| 2339 | try { |
| 2340 | return phone.getMeid(); |
| 2341 | } finally { |
| 2342 | Binder.restoreCallingIdentity(identity); |
| 2343 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2347 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2348 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2349 | String manufacturerCode = null; |
| 2350 | if (phone != null) { |
| 2351 | String meid = phone.getMeid(); |
| 2352 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2353 | } |
| 2354 | return manufacturerCode; |
| 2355 | } |
| 2356 | |
| 2357 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2358 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2359 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2360 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2361 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2362 | return null; |
| 2363 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2364 | int subId = phone.getSubId(); |
| 2365 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2366 | mApp, subId, callingPackage, callingFeatureId, |
| 2367 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2368 | return null; |
| 2369 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2370 | |
| 2371 | final long identity = Binder.clearCallingIdentity(); |
| 2372 | try { |
| 2373 | return phone.getDeviceSvn(); |
| 2374 | } finally { |
| 2375 | Binder.restoreCallingIdentity(identity); |
| 2376 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2377 | } |
| 2378 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2379 | @Override |
| 2380 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2381 | final long identity = Binder.clearCallingIdentity(); |
| 2382 | try { |
| 2383 | final Phone phone = getPhone(subId); |
| 2384 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2385 | } finally { |
| 2386 | Binder.restoreCallingIdentity(identity); |
| 2387 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2388 | } |
| 2389 | |
| 2390 | @Override |
| 2391 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2392 | final long identity = Binder.clearCallingIdentity(); |
| 2393 | try { |
| 2394 | final Phone phone = getPhone(subId); |
| 2395 | return phone == null ? null : phone.getCarrierName(); |
| 2396 | } finally { |
| 2397 | Binder.restoreCallingIdentity(identity); |
| 2398 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2399 | } |
| 2400 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2401 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2402 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2403 | final long identity = Binder.clearCallingIdentity(); |
| 2404 | try { |
| 2405 | final Phone phone = getPhone(subId); |
| 2406 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2407 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2408 | } finally { |
| 2409 | Binder.restoreCallingIdentity(identity); |
| 2410 | } |
| 2411 | } |
| 2412 | |
| 2413 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2414 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2415 | final long identity = Binder.clearCallingIdentity(); |
| 2416 | try { |
| 2417 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2418 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2419 | } finally { |
| 2420 | Binder.restoreCallingIdentity(identity); |
| 2421 | } |
| 2422 | } |
| 2423 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2424 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2425 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2426 | if (!isSubscriptionMccMnc) { |
| 2427 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2428 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2429 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2430 | if (phone == null) { |
| 2431 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2432 | } |
| 2433 | final long identity = Binder.clearCallingIdentity(); |
| 2434 | try { |
| 2435 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2436 | } finally { |
| 2437 | Binder.restoreCallingIdentity(identity); |
| 2438 | } |
| 2439 | } |
| 2440 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2441 | // |
| 2442 | // Internal helper methods. |
| 2443 | // |
| 2444 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2445 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2446 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2447 | * |
| 2448 | * @throws SecurityException if the caller does not have the required permission |
| 2449 | */ |
| 2450 | private void enforceModifyPermission() { |
| 2451 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2452 | } |
| 2453 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2454 | private void enforceActiveEmergencySessionPermission() { |
| 2455 | mApp.enforceCallingOrSelfPermission( |
| 2456 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2457 | } |
| 2458 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2459 | /** |
| 2460 | * Make sure the caller has the CALL_PHONE permission. |
| 2461 | * |
| 2462 | * @throws SecurityException if the caller does not have the required permission |
| 2463 | */ |
| 2464 | private void enforceCallPermission() { |
| 2465 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2466 | } |
| 2467 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2468 | private void enforceSettingsPermission() { |
| 2469 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2472 | private String createTelUrl(String number) { |
| 2473 | if (TextUtils.isEmpty(number)) { |
| 2474 | return null; |
| 2475 | } |
| 2476 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2477 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2478 | } |
| 2479 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2480 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2481 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2482 | } |
| 2483 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2484 | private static void logv(String msg) { |
| 2485 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2486 | } |
| 2487 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2488 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2489 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2490 | } |
| 2491 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2492 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2493 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2494 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2495 | } |
| 2496 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2497 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2498 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2499 | final long identity = Binder.clearCallingIdentity(); |
| 2500 | try { |
| 2501 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2502 | if (phone == null) { |
| 2503 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2504 | } else { |
| 2505 | return phone.getPhoneType(); |
| 2506 | } |
| 2507 | } finally { |
| 2508 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2509 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | /** |
| 2513 | * Returns the CDMA ERI icon index to display |
| 2514 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2515 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2516 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2517 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2518 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2521 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2522 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2523 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2524 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2525 | mApp, subId, callingPackage, callingFeatureId, |
| 2526 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2527 | return -1; |
| 2528 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2529 | |
| 2530 | final long identity = Binder.clearCallingIdentity(); |
| 2531 | try { |
| 2532 | final Phone phone = getPhone(subId); |
| 2533 | if (phone != null) { |
| 2534 | return phone.getCdmaEriIconIndex(); |
| 2535 | } else { |
| 2536 | return -1; |
| 2537 | } |
| 2538 | } finally { |
| 2539 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2540 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2541 | } |
| 2542 | |
| 2543 | /** |
| 2544 | * Returns the CDMA ERI icon mode, |
| 2545 | * 0 - ON |
| 2546 | * 1 - FLASHING |
| 2547 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2548 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2549 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2550 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2551 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2552 | } |
| 2553 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2554 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2555 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2556 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2557 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2558 | mApp, subId, callingPackage, callingFeatureId, |
| 2559 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2560 | return -1; |
| 2561 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2562 | |
| 2563 | final long identity = Binder.clearCallingIdentity(); |
| 2564 | try { |
| 2565 | final Phone phone = getPhone(subId); |
| 2566 | if (phone != null) { |
| 2567 | return phone.getCdmaEriIconMode(); |
| 2568 | } else { |
| 2569 | return -1; |
| 2570 | } |
| 2571 | } finally { |
| 2572 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2573 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2574 | } |
| 2575 | |
| 2576 | /** |
| 2577 | * Returns the CDMA ERI text, |
| 2578 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2579 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2580 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2581 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2582 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2583 | } |
| 2584 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2585 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2586 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2587 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2588 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2589 | mApp, subId, callingPackage, callingFeatureId, |
| 2590 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2591 | return null; |
| 2592 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2593 | |
| 2594 | final long identity = Binder.clearCallingIdentity(); |
| 2595 | try { |
| 2596 | final Phone phone = getPhone(subId); |
| 2597 | if (phone != null) { |
| 2598 | return phone.getCdmaEriText(); |
| 2599 | } else { |
| 2600 | return null; |
| 2601 | } |
| 2602 | } finally { |
| 2603 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2604 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2605 | } |
| 2606 | |
| 2607 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2608 | * Returns the CDMA MDN. |
| 2609 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2610 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2611 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2612 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2613 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2614 | |
| 2615 | final long identity = Binder.clearCallingIdentity(); |
| 2616 | try { |
| 2617 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2618 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2619 | return phone.getLine1Number(); |
| 2620 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2621 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2622 | return null; |
| 2623 | } |
| 2624 | } finally { |
| 2625 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2626 | } |
| 2627 | } |
| 2628 | |
| 2629 | /** |
| 2630 | * Returns the CDMA MIN. |
| 2631 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2632 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2633 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2634 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2635 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2636 | |
| 2637 | final long identity = Binder.clearCallingIdentity(); |
| 2638 | try { |
| 2639 | final Phone phone = getPhone(subId); |
| 2640 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2641 | return phone.getCdmaMin(); |
| 2642 | } else { |
| 2643 | return null; |
| 2644 | } |
| 2645 | } finally { |
| 2646 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2647 | } |
| 2648 | } |
| 2649 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2650 | @Override |
| 2651 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2652 | INumberVerificationCallback callback, String callingPackage) { |
| 2653 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2654 | != PERMISSION_GRANTED) { |
| 2655 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2656 | } |
| 2657 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2658 | |
| 2659 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2660 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2661 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2662 | } |
| 2663 | |
| 2664 | if (range == null) { |
| 2665 | throw new NullPointerException("Range must be non-null"); |
| 2666 | } |
| 2667 | |
| 2668 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2669 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2670 | |
| 2671 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2672 | } |
| 2673 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2674 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2675 | * Returns true if CDMA provisioning needs to run. |
| 2676 | */ |
| 2677 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2678 | final long identity = Binder.clearCallingIdentity(); |
| 2679 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2680 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2681 | } finally { |
| 2682 | Binder.restoreCallingIdentity(identity); |
| 2683 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2684 | } |
| 2685 | |
| 2686 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2687 | * Sets the voice mail number of a given subId. |
| 2688 | */ |
| 2689 | @Override |
| 2690 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2691 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2692 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2693 | |
| 2694 | final long identity = Binder.clearCallingIdentity(); |
| 2695 | try { |
| 2696 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2697 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2698 | return success; |
| 2699 | } finally { |
| 2700 | Binder.restoreCallingIdentity(identity); |
| 2701 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2702 | } |
| 2703 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2704 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2705 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2706 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2707 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2708 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2709 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2710 | throw new SecurityException("caller must be system dialer"); |
| 2711 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2712 | |
| 2713 | final long identity = Binder.clearCallingIdentity(); |
| 2714 | try { |
| 2715 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2716 | if (phoneAccountHandle == null) { |
| 2717 | return null; |
| 2718 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2719 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2720 | } finally { |
| 2721 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2722 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2726 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2727 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2728 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2729 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2730 | mApp, subId, callingPackage, callingFeatureId, |
| 2731 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2732 | return null; |
| 2733 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2734 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2735 | final long identity = Binder.clearCallingIdentity(); |
| 2736 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2737 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2738 | } finally { |
| 2739 | Binder.restoreCallingIdentity(identity); |
| 2740 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2744 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2745 | VisualVoicemailSmsFilterSettings settings) { |
| 2746 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2747 | |
| 2748 | final long identity = Binder.clearCallingIdentity(); |
| 2749 | try { |
| 2750 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2751 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2752 | } finally { |
| 2753 | Binder.restoreCallingIdentity(identity); |
| 2754 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2755 | } |
| 2756 | |
| 2757 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2758 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2759 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2760 | |
| 2761 | final long identity = Binder.clearCallingIdentity(); |
| 2762 | try { |
| 2763 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2764 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2765 | } finally { |
| 2766 | Binder.restoreCallingIdentity(identity); |
| 2767 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2768 | } |
| 2769 | |
| 2770 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2771 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2772 | String callingPackage, int subId) { |
| 2773 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2774 | |
| 2775 | final long identity = Binder.clearCallingIdentity(); |
| 2776 | try { |
| 2777 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2778 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2779 | } finally { |
| 2780 | Binder.restoreCallingIdentity(identity); |
| 2781 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2782 | } |
| 2783 | |
| 2784 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2785 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2786 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2787 | |
| 2788 | final long identity = Binder.clearCallingIdentity(); |
| 2789 | try { |
| 2790 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2791 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2792 | } finally { |
| 2793 | Binder.restoreCallingIdentity(identity); |
| 2794 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2795 | } |
| 2796 | |
| 2797 | @Override |
| 2798 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2799 | String number, int port, String text, PendingIntent sentIntent) { |
| 2800 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2801 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2802 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2803 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2804 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2805 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2806 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2807 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2808 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2809 | * Sets the voice activation state of a given subId. |
| 2810 | */ |
| 2811 | @Override |
| 2812 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2813 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2814 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2815 | |
| 2816 | final long identity = Binder.clearCallingIdentity(); |
| 2817 | try { |
| 2818 | final Phone phone = getPhone(subId); |
| 2819 | if (phone != null) { |
| 2820 | phone.setVoiceActivationState(activationState); |
| 2821 | } else { |
| 2822 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2823 | } |
| 2824 | } finally { |
| 2825 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2826 | } |
| 2827 | } |
| 2828 | |
| 2829 | /** |
| 2830 | * Sets the data activation state of a given subId. |
| 2831 | */ |
| 2832 | @Override |
| 2833 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2834 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2835 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2836 | |
| 2837 | final long identity = Binder.clearCallingIdentity(); |
| 2838 | try { |
| 2839 | final Phone phone = getPhone(subId); |
| 2840 | if (phone != null) { |
| 2841 | phone.setDataActivationState(activationState); |
| 2842 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 2843 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2844 | } |
| 2845 | } finally { |
| 2846 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2847 | } |
| 2848 | } |
| 2849 | |
| 2850 | /** |
| 2851 | * Returns the voice activation state of a given subId. |
| 2852 | */ |
| 2853 | @Override |
| 2854 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2855 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2856 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2857 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2858 | final long identity = Binder.clearCallingIdentity(); |
| 2859 | try { |
| 2860 | if (phone != null) { |
| 2861 | return phone.getVoiceActivationState(); |
| 2862 | } else { |
| 2863 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2864 | } |
| 2865 | } finally { |
| 2866 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2867 | } |
| 2868 | } |
| 2869 | |
| 2870 | /** |
| 2871 | * Returns the data activation state of a given subId. |
| 2872 | */ |
| 2873 | @Override |
| 2874 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2875 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2876 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2877 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2878 | final long identity = Binder.clearCallingIdentity(); |
| 2879 | try { |
| 2880 | if (phone != null) { |
| 2881 | return phone.getDataActivationState(); |
| 2882 | } else { |
| 2883 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2884 | } |
| 2885 | } finally { |
| 2886 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2887 | } |
| 2888 | } |
| 2889 | |
| 2890 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2891 | * Returns the unread count of voicemails for a subId |
| 2892 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2893 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2894 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 2895 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2896 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2897 | mApp, subId, callingPackage, callingFeatureId, |
| 2898 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2899 | return 0; |
| 2900 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2901 | final long identity = Binder.clearCallingIdentity(); |
| 2902 | try { |
| 2903 | final Phone phone = getPhone(subId); |
| 2904 | if (phone != null) { |
| 2905 | return phone.getVoiceMessageCount(); |
| 2906 | } else { |
| 2907 | return 0; |
| 2908 | } |
| 2909 | } finally { |
| 2910 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2911 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2912 | } |
| 2913 | |
| 2914 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2915 | * returns true, if the device is in a state where both voice and data |
| 2916 | * are supported simultaneously. This can change based on location or network condition. |
| 2917 | */ |
| 2918 | @Override |
| 2919 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2920 | final long identity = Binder.clearCallingIdentity(); |
| 2921 | try { |
| 2922 | final Phone phone = getPhone(subId); |
| 2923 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2924 | } finally { |
| 2925 | Binder.restoreCallingIdentity(identity); |
| 2926 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2930 | * Send the dialer code if called from the current default dialer or the caller has |
| 2931 | * carrier privilege. |
| 2932 | * @param inputCode The dialer code to send |
| 2933 | */ |
| 2934 | @Override |
| 2935 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2936 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2937 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2938 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 2939 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2940 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2941 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2942 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2943 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2944 | |
| 2945 | final long identity = Binder.clearCallingIdentity(); |
| 2946 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2947 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2948 | } finally { |
| 2949 | Binder.restoreCallingIdentity(identity); |
| 2950 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2951 | } |
| 2952 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2953 | @Override |
| 2954 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame^] | 2955 | TelephonyPermissions |
| 2956 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 2957 | mApp, subId, "getNetworkSelectionMode"); |
| 2958 | final long identity = Binder.clearCallingIdentity(); |
| 2959 | try { |
| 2960 | if (!isActiveSubscription(subId)) { |
| 2961 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2962 | } |
| 2963 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2964 | } finally { |
| 2965 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2966 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2967 | } |
| 2968 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2969 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2970 | public boolean isInEmergencySmsMode() { |
| 2971 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2972 | final long identity = Binder.clearCallingIdentity(); |
| 2973 | try { |
| 2974 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2975 | if (phone.isInEmergencySmsMode()) { |
| 2976 | return true; |
| 2977 | } |
| 2978 | } |
| 2979 | } finally { |
| 2980 | Binder.restoreCallingIdentity(identity); |
| 2981 | } |
| 2982 | return false; |
| 2983 | } |
| 2984 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 2985 | /** |
| 2986 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 2987 | * @param subId The subscription to use to check the configuration. |
| 2988 | * @param c The callback that will be used to send the result. |
| 2989 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2990 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2991 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2992 | throws RemoteException { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 2993 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2994 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 2995 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 2996 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 2997 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 2998 | "IMS not available on device."); |
| 2999 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3000 | final long token = Binder.clearCallingIdentity(); |
| 3001 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3002 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3003 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3004 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3005 | } catch (ImsException e) { |
| 3006 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3007 | } finally { |
| 3008 | Binder.restoreCallingIdentity(token); |
| 3009 | } |
| 3010 | } |
| 3011 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3012 | /** |
| 3013 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3014 | * @param subId The subscription to use to check the configuration. |
| 3015 | * @param c The callback that will be used to send the result. |
| 3016 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3017 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3018 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3019 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3020 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3021 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3022 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3023 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3024 | final long token = Binder.clearCallingIdentity(); |
| 3025 | try { |
| 3026 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3027 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3028 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3029 | } catch (ImsException e) { |
| 3030 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3031 | + "is inactive, ignoring unregister."); |
| 3032 | // If the subscription is no longer active, just return, since the callback |
| 3033 | // will already have been removed internally. |
| 3034 | } finally { |
| 3035 | Binder.restoreCallingIdentity(token); |
| 3036 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3037 | } |
| 3038 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3039 | /** |
| 3040 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3041 | */ |
| 3042 | @Override |
| 3043 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3044 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3045 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3046 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3047 | "IMS not available on device."); |
| 3048 | } |
| 3049 | final long token = Binder.clearCallingIdentity(); |
| 3050 | try { |
| 3051 | Phone phone = getPhone(subId); |
| 3052 | if (phone == null) { |
| 3053 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3054 | + subId + "'"); |
| 3055 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3056 | } |
| 3057 | phone.getImsRegistrationState(regState -> { |
| 3058 | try { |
| 3059 | consumer.accept((regState == null) |
| 3060 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3061 | } catch (RemoteException e) { |
| 3062 | // Ignore if the remote process is no longer available to call back. |
| 3063 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3064 | } |
| 3065 | }); |
| 3066 | } finally { |
| 3067 | Binder.restoreCallingIdentity(token); |
| 3068 | } |
| 3069 | } |
| 3070 | |
| 3071 | /** |
| 3072 | * Get the transport type for the IMS service registration state. |
| 3073 | */ |
| 3074 | @Override |
| 3075 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3076 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3077 | enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType"); |
| 3078 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3079 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3080 | "IMS not available on device."); |
| 3081 | } |
| 3082 | final long token = Binder.clearCallingIdentity(); |
| 3083 | try { |
| 3084 | Phone phone = getPhone(subId); |
| 3085 | if (phone == null) { |
| 3086 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3087 | + subId + "'"); |
| 3088 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3089 | } |
| 3090 | phone.getImsRegistrationTech(regTech -> { |
| 3091 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3092 | int regTechConverted = (regTech == null) |
| 3093 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3094 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3095 | regTechConverted); |
| 3096 | try { |
| 3097 | consumer.accept(regTechConverted); |
| 3098 | } catch (RemoteException e) { |
| 3099 | // Ignore if the remote process is no longer available to call back. |
| 3100 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3101 | } |
| 3102 | }); |
| 3103 | } finally { |
| 3104 | Binder.restoreCallingIdentity(token); |
| 3105 | } |
| 3106 | } |
| 3107 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3108 | /** |
| 3109 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3110 | * @param subId The subscription to use to check the configuration. |
| 3111 | * @param c The callback that will be used to send the result. |
| 3112 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3113 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3114 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3115 | throws RemoteException { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3116 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3117 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3118 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3119 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3120 | "IMS not available on device."); |
| 3121 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3122 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3123 | final long token = Binder.clearCallingIdentity(); |
| 3124 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3125 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3126 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3127 | } catch (ImsException e) { |
| 3128 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3129 | } finally { |
| 3130 | Binder.restoreCallingIdentity(token); |
| 3131 | } |
| 3132 | } |
| 3133 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3134 | /** |
| 3135 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3136 | * @param subId The subscription to use to check the configuration. |
| 3137 | * @param c The callback that will be used to send the result. |
| 3138 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3139 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3140 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3141 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3142 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3143 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3144 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3145 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3146 | |
| 3147 | final long token = Binder.clearCallingIdentity(); |
| 3148 | try { |
| 3149 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3150 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3151 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3152 | } catch (ImsException e) { |
| 3153 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3154 | + "is inactive, ignoring unregister."); |
| 3155 | // If the subscription is no longer active, just return, since the callback |
| 3156 | // will already have been removed internally. |
| 3157 | } finally { |
| 3158 | Binder.restoreCallingIdentity(token); |
| 3159 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3163 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3164 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3165 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3166 | final long token = Binder.clearCallingIdentity(); |
| 3167 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3168 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3169 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3170 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3171 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3172 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3173 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3174 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3175 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3176 | } finally { |
| 3177 | Binder.restoreCallingIdentity(token); |
| 3178 | } |
| 3179 | } |
| 3180 | |
| 3181 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3182 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3183 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3184 | final long token = Binder.clearCallingIdentity(); |
| 3185 | try { |
| 3186 | Phone phone = getPhone(subId); |
| 3187 | if (phone == null) return false; |
| 3188 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3189 | } finally { |
| 3190 | Binder.restoreCallingIdentity(token); |
| 3191 | } |
| 3192 | } |
| 3193 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3194 | /** |
| 3195 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3196 | * subscription. |
| 3197 | * @param subId The subscription to use to check the configuration. |
| 3198 | * @param callback The callback that will be used to send the result. |
| 3199 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3200 | * @param transportType The transport type of the MmTelFeature capability. |
| 3201 | */ |
| 3202 | @Override |
| 3203 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3204 | int transportType) { |
| 3205 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3206 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3207 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3208 | "IMS not available on device."); |
| 3209 | } |
| 3210 | final long token = Binder.clearCallingIdentity(); |
| 3211 | try { |
| 3212 | int slotId = getSlotIndex(subId); |
| 3213 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3214 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3215 | + subId + "'"); |
| 3216 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3217 | } |
| 3218 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3219 | transportType, aBoolean -> { |
| 3220 | try { |
| 3221 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3222 | } catch (RemoteException e) { |
| 3223 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3224 | + "running. Ignore"); |
| 3225 | } |
| 3226 | }); |
| 3227 | } finally { |
| 3228 | Binder.restoreCallingIdentity(token); |
| 3229 | } |
| 3230 | } |
| 3231 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3232 | /** |
| 3233 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3234 | * @param subId The subscription to use to check the configuration. |
| 3235 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3236 | @Override |
| 3237 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3238 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
| 3239 | enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled"); |
| 3240 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3241 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3242 | final long token = Binder.clearCallingIdentity(); |
| 3243 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3244 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3245 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3246 | } catch (ImsException e) { |
| 3247 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3248 | } finally { |
| 3249 | Binder.restoreCallingIdentity(token); |
| 3250 | } |
| 3251 | } |
| 3252 | |
| 3253 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3254 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3255 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3256 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3257 | final long identity = Binder.clearCallingIdentity(); |
| 3258 | try { |
| 3259 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3260 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3261 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3262 | } catch (ImsException e) { |
| 3263 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3264 | } finally { |
| 3265 | Binder.restoreCallingIdentity(identity); |
| 3266 | } |
| 3267 | } |
| 3268 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3269 | /** |
| 3270 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3271 | * @param subId The subscription to use to check the configuration. |
| 3272 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3273 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3274 | public boolean isVtSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3275 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3276 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3277 | final long identity = Binder.clearCallingIdentity(); |
| 3278 | try { |
| 3279 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3280 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3281 | } catch (ImsException e) { |
| 3282 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3283 | } finally { |
| 3284 | Binder.restoreCallingIdentity(identity); |
| 3285 | } |
| 3286 | } |
| 3287 | |
| 3288 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3289 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3290 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3291 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3292 | final long identity = Binder.clearCallingIdentity(); |
| 3293 | try { |
| 3294 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3295 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3296 | } catch (ImsException e) { |
| 3297 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3298 | } finally { |
| 3299 | Binder.restoreCallingIdentity(identity); |
| 3300 | } |
| 3301 | } |
| 3302 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3303 | /** |
| 3304 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3305 | * @param subId The subscription to use to check the configuration. |
| 3306 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3307 | @Override |
| 3308 | public boolean isVoWiFiSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3309 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3310 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3311 | final long identity = Binder.clearCallingIdentity(); |
| 3312 | try { |
| 3313 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3314 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3315 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3316 | } catch (ImsException e) { |
| 3317 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3318 | } finally { |
| 3319 | Binder.restoreCallingIdentity(identity); |
| 3320 | } |
| 3321 | } |
| 3322 | |
| 3323 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3324 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3325 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3326 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3327 | final long identity = Binder.clearCallingIdentity(); |
| 3328 | try { |
| 3329 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3330 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3331 | } catch (ImsException e) { |
| 3332 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3333 | } finally { |
| 3334 | Binder.restoreCallingIdentity(identity); |
| 3335 | } |
| 3336 | } |
| 3337 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3338 | /** |
| 3339 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3340 | * @param subId The subscription to use to check the configuration. |
| 3341 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3342 | @Override |
| 3343 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3344 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3345 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3346 | final long identity = Binder.clearCallingIdentity(); |
| 3347 | try { |
| 3348 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3349 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3350 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3351 | } catch (ImsException e) { |
| 3352 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3353 | } finally { |
| 3354 | Binder.restoreCallingIdentity(identity); |
| 3355 | } |
| 3356 | } |
| 3357 | |
| 3358 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3359 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3360 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3361 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3362 | final long identity = Binder.clearCallingIdentity(); |
| 3363 | try { |
| 3364 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3365 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3366 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3367 | } catch (ImsException e) { |
| 3368 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3369 | } finally { |
| 3370 | Binder.restoreCallingIdentity(identity); |
| 3371 | } |
| 3372 | } |
| 3373 | |
| 3374 | @Override |
| 3375 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3376 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3377 | "setVoWiFiNonPersistent"); |
| 3378 | final long identity = Binder.clearCallingIdentity(); |
| 3379 | try { |
| 3380 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3381 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3382 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3383 | } catch (ImsException e) { |
| 3384 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3385 | } finally { |
| 3386 | Binder.restoreCallingIdentity(identity); |
| 3387 | } |
| 3388 | } |
| 3389 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3390 | /** |
| 3391 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3392 | * @param subId The subscription to use to check the configuration. |
| 3393 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3394 | @Override |
| 3395 | public int getVoWiFiModeSetting(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3396 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3397 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3398 | final long identity = Binder.clearCallingIdentity(); |
| 3399 | try { |
| 3400 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3401 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3402 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3403 | } catch (ImsException e) { |
| 3404 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3405 | } finally { |
| 3406 | Binder.restoreCallingIdentity(identity); |
| 3407 | } |
| 3408 | } |
| 3409 | |
| 3410 | @Override |
| 3411 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3412 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3413 | "setVoWiFiModeSetting"); |
| 3414 | final long identity = Binder.clearCallingIdentity(); |
| 3415 | try { |
| 3416 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3417 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3418 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3419 | } catch (ImsException e) { |
| 3420 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3421 | } finally { |
| 3422 | Binder.restoreCallingIdentity(identity); |
| 3423 | } |
| 3424 | } |
| 3425 | |
| 3426 | @Override |
| 3427 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3428 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3429 | final long identity = Binder.clearCallingIdentity(); |
| 3430 | try { |
| 3431 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3432 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3433 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3434 | } catch (ImsException e) { |
| 3435 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3436 | } finally { |
| 3437 | Binder.restoreCallingIdentity(identity); |
| 3438 | } |
| 3439 | } |
| 3440 | |
| 3441 | @Override |
| 3442 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3443 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3444 | "setVoWiFiRoamingModeSetting"); |
| 3445 | final long identity = Binder.clearCallingIdentity(); |
| 3446 | try { |
| 3447 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3448 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3449 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3450 | } catch (ImsException e) { |
| 3451 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3452 | } finally { |
| 3453 | Binder.restoreCallingIdentity(identity); |
| 3454 | } |
| 3455 | } |
| 3456 | |
| 3457 | @Override |
| 3458 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3459 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3460 | "setRttCapabilityEnabled"); |
| 3461 | final long identity = Binder.clearCallingIdentity(); |
| 3462 | try { |
| 3463 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3464 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 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(identity); |
| 3469 | } |
| 3470 | } |
| 3471 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3472 | /** |
| 3473 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3474 | * @param subId The subscription to use to check the configuration. |
| 3475 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3476 | @Override |
| 3477 | public boolean isTtyOverVolteEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3478 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3479 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3480 | final long identity = Binder.clearCallingIdentity(); |
| 3481 | try { |
| 3482 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3483 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3484 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3485 | } catch (ImsException e) { |
| 3486 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3487 | } finally { |
| 3488 | Binder.restoreCallingIdentity(identity); |
| 3489 | } |
| 3490 | } |
| 3491 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3492 | @Override |
| 3493 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3494 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3495 | final long identity = Binder.clearCallingIdentity(); |
| 3496 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3497 | if (!isImsAvailableOnDevice()) { |
| 3498 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3499 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3500 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3501 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3502 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3503 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3504 | } catch (ImsException e) { |
| 3505 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3506 | } finally { |
| 3507 | Binder.restoreCallingIdentity(identity); |
| 3508 | } |
| 3509 | } |
| 3510 | |
| 3511 | @Override |
| 3512 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3513 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3514 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3515 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3516 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3517 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3518 | try { |
| 3519 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3520 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3521 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3522 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3523 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3524 | + "is inactive, ignoring unregister."); |
| 3525 | // If the subscription is no longer active, just return, since the callback will already |
| 3526 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3527 | } finally { |
| 3528 | Binder.restoreCallingIdentity(identity); |
| 3529 | } |
| 3530 | } |
| 3531 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3532 | |
| 3533 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3534 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3535 | message); |
| 3536 | } |
| 3537 | |
| 3538 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3539 | boolean isMmtelCapability) { |
| 3540 | Phone phone = getPhone(subId); |
| 3541 | if (phone == null) { |
| 3542 | loge("phone instance null for subid " + subId); |
| 3543 | return false; |
| 3544 | } |
| 3545 | if (isMmtelCapability) { |
| 3546 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3547 | return false; |
| 3548 | } |
| 3549 | } else { |
| 3550 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3551 | return false; |
| 3552 | } |
| 3553 | } |
| 3554 | return true; |
| 3555 | } |
| 3556 | |
| 3557 | @Override |
| 3558 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3559 | boolean isProvisioned) { |
| 3560 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3561 | |
| 3562 | final long identity = Binder.clearCallingIdentity(); |
| 3563 | try { |
| 3564 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3565 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3566 | return; |
| 3567 | } |
| 3568 | |
| 3569 | // this capability requires provisioning, route to the correct API. |
| 3570 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3571 | switch (capability) { |
| 3572 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3573 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3574 | ims.setEabProvisioned(isProvisioned); |
| 3575 | break; |
| 3576 | default: { |
| 3577 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3578 | + "rcs capability '" + capability + "', which does not require " |
| 3579 | + "provisioning."); |
| 3580 | } |
| 3581 | } |
| 3582 | } finally { |
| 3583 | Binder.restoreCallingIdentity(identity); |
| 3584 | } |
| 3585 | |
| 3586 | } |
| 3587 | |
| 3588 | |
| 3589 | @Override |
| 3590 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3591 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3592 | final long identity = Binder.clearCallingIdentity(); |
| 3593 | try { |
| 3594 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3595 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3596 | return true; |
| 3597 | } |
| 3598 | |
| 3599 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3600 | switch (capability) { |
| 3601 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3602 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3603 | return ims.isEabProvisionedOnDevice(); |
| 3604 | |
| 3605 | default: { |
| 3606 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3607 | + "capability '" + capability + "', which does not require " |
| 3608 | + "provisioning."); |
| 3609 | } |
| 3610 | } |
| 3611 | |
| 3612 | } finally { |
| 3613 | Binder.restoreCallingIdentity(identity); |
| 3614 | } |
| 3615 | } |
| 3616 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3617 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3618 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3619 | boolean isProvisioned) { |
| 3620 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3621 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3622 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3623 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3624 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3625 | final long identity = Binder.clearCallingIdentity(); |
| 3626 | try { |
| 3627 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3628 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3629 | return; |
| 3630 | } |
| 3631 | |
| 3632 | // this capability requires provisioning, route to the correct API. |
| 3633 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3634 | switch (capability) { |
| 3635 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3636 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3637 | ims.setVolteProvisioned(isProvisioned); |
| 3638 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3639 | ims.setWfcProvisioned(isProvisioned); |
| 3640 | } |
| 3641 | break; |
| 3642 | } |
| 3643 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3644 | // There is currently no difference in VT provisioning type. |
| 3645 | ims.setVtProvisioned(isProvisioned); |
| 3646 | break; |
| 3647 | } |
| 3648 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3649 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3650 | // change the capability of the feature instead if needed. |
| 3651 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3652 | == isProvisioned) { |
| 3653 | // No change in provisioning. |
| 3654 | return; |
| 3655 | } |
| 3656 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3657 | try { |
| 3658 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3659 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3660 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3661 | + ", Exception" + e.getMessage()); |
| 3662 | } |
| 3663 | break; |
| 3664 | } |
| 3665 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3666 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3667 | + "MmTel capability '" + capability + "', which does not require " |
| 3668 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3669 | } |
| 3670 | } |
| 3671 | |
| 3672 | } finally { |
| 3673 | Binder.restoreCallingIdentity(identity); |
| 3674 | } |
| 3675 | } |
| 3676 | |
| 3677 | @Override |
| 3678 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3679 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3680 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3681 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3682 | } |
| 3683 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3684 | final long identity = Binder.clearCallingIdentity(); |
| 3685 | try { |
| 3686 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3687 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3688 | return true; |
| 3689 | } |
| 3690 | |
| 3691 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3692 | switch (capability) { |
| 3693 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3694 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3695 | return ims.isVolteProvisionedOnDevice(); |
| 3696 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3697 | return ims.isWfcProvisionedOnDevice(); |
| 3698 | } |
| 3699 | // This should never happen, since we are checking tech above to make sure it |
| 3700 | // is either LTE or IWLAN. |
| 3701 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3702 | + "capability."); |
| 3703 | } |
| 3704 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3705 | // There is currently no difference in VT provisioning type. |
| 3706 | return ims.isVtProvisionedOnDevice(); |
| 3707 | } |
| 3708 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3709 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3710 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3711 | } |
| 3712 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3713 | throw new IllegalArgumentException( |
| 3714 | "Tried to get provisioning for MmTel capability '" + capability |
| 3715 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3716 | } |
| 3717 | } |
| 3718 | |
| 3719 | } finally { |
| 3720 | Binder.restoreCallingIdentity(identity); |
| 3721 | } |
| 3722 | } |
| 3723 | |
| 3724 | @Override |
| 3725 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3726 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3727 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3728 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3729 | } |
| 3730 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3731 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3732 | return (provisionedBits & capability) > 0; |
| 3733 | } |
| 3734 | |
| 3735 | @Override |
| 3736 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3737 | boolean isProvisioned) { |
| 3738 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3739 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3740 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3741 | } |
| 3742 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3743 | "setProvisioningStatusForCapability"); |
| 3744 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3745 | // If the current provisioning status for capability already matches isProvisioned, |
| 3746 | // do nothing. |
| 3747 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3748 | return; |
| 3749 | } |
| 3750 | if (isProvisioned) { |
| 3751 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3752 | } else { |
| 3753 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3754 | } |
| 3755 | } |
| 3756 | |
| 3757 | /** |
| 3758 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3759 | * technology. The bitfield should mirror the bitfield defined by |
| 3760 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3761 | */ |
| 3762 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3763 | String key = getMmTelProvisioningKey(subId, tech); |
| 3764 | // Default is no capabilities are provisioned. |
| 3765 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3766 | } |
| 3767 | |
| 3768 | /** |
| 3769 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3770 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3771 | * technology specified. |
| 3772 | * |
| 3773 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3774 | */ |
| 3775 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3776 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3777 | String key = getMmTelProvisioningKey(subId, tech); |
| 3778 | editor.putInt(key, newField); |
| 3779 | editor.commit(); |
| 3780 | } |
| 3781 | |
| 3782 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3783 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3784 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3785 | } |
| 3786 | |
| 3787 | /** |
| 3788 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3789 | * carrier associated with the subscription id. |
| 3790 | */ |
| 3791 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3792 | int capability) { |
| 3793 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3794 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3795 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 3796 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3797 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3798 | false); |
| 3799 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3800 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3801 | |
| 3802 | // First check to make sure that the capability requires provisioning. |
| 3803 | switch (capability) { |
| 3804 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3805 | // intentional fallthrough |
| 3806 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3807 | if (requireVoiceVtProvisioning) { |
| 3808 | // Voice and Video requires provisioning |
| 3809 | return true; |
| 3810 | } |
| 3811 | break; |
| 3812 | } |
| 3813 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3814 | if (requireUtProvisioning) { |
| 3815 | // UT requires provisioning |
| 3816 | return true; |
| 3817 | } |
| 3818 | break; |
| 3819 | } |
| 3820 | } |
| 3821 | return false; |
| 3822 | } |
| 3823 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3824 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 3825 | int capability) { |
| 3826 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3827 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3828 | |
| 3829 | boolean requireRcsProvisioning = c.getBoolean( |
| 3830 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 3831 | |
| 3832 | // First check to make sure that the capability requires provisioning. |
| 3833 | switch (capability) { |
| 3834 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3835 | // intentional fallthrough |
| 3836 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 3837 | if (requireRcsProvisioning) { |
| 3838 | // OPTION or PRESENCE requires provisioning |
| 3839 | return true; |
| 3840 | } |
| 3841 | break; |
| 3842 | } |
| 3843 | } |
| 3844 | return false; |
| 3845 | } |
| 3846 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3847 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3848 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3849 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3850 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3851 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3852 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3853 | final long identity = Binder.clearCallingIdentity(); |
| 3854 | try { |
| 3855 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3856 | int slotId = getSlotIndex(subId); |
| 3857 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3858 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3859 | + subId + "' for key:" + key); |
| 3860 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3861 | } |
| 3862 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3863 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3864 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3865 | + subId + "' for key:" + key); |
| 3866 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3867 | } finally { |
| 3868 | Binder.restoreCallingIdentity(identity); |
| 3869 | } |
| 3870 | } |
| 3871 | |
| 3872 | @Override |
| 3873 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3874 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3875 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3876 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3877 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3878 | final long identity = Binder.clearCallingIdentity(); |
| 3879 | try { |
| 3880 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3881 | int slotId = getSlotIndex(subId); |
| 3882 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3883 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3884 | + subId + "' for key:" + key); |
| 3885 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3886 | } |
| 3887 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3888 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3889 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3890 | + subId + "' for key:" + key); |
| 3891 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3892 | } finally { |
| 3893 | Binder.restoreCallingIdentity(identity); |
| 3894 | } |
| 3895 | } |
| 3896 | |
| 3897 | @Override |
| 3898 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3899 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3900 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3901 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3902 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3903 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3904 | final long identity = Binder.clearCallingIdentity(); |
| 3905 | try { |
| 3906 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3907 | int slotId = getSlotIndex(subId); |
| 3908 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3909 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3910 | + subId + "' for key:" + key); |
| 3911 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3912 | } |
| 3913 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3914 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3915 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3916 | + "' for key:" + key); |
| 3917 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3918 | } finally { |
| 3919 | Binder.restoreCallingIdentity(identity); |
| 3920 | } |
| 3921 | } |
| 3922 | |
| 3923 | @Override |
| 3924 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3925 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3926 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3927 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3928 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3929 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3930 | final long identity = Binder.clearCallingIdentity(); |
| 3931 | try { |
| 3932 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3933 | int slotId = getSlotIndex(subId); |
| 3934 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3935 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3936 | + subId + "' for key:" + key); |
| 3937 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3938 | } |
| 3939 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3940 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3941 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3942 | + "' for key:" + key); |
| 3943 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3944 | } finally { |
| 3945 | Binder.restoreCallingIdentity(identity); |
| 3946 | } |
| 3947 | } |
| 3948 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3949 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3950 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3951 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3952 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 3953 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3954 | } |
| 3955 | return slotId; |
| 3956 | } |
| 3957 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3958 | private int getSlotIndex(int subId) { |
| 3959 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3960 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3961 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3962 | } |
| 3963 | return slotId; |
| 3964 | } |
| 3965 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3966 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3967 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3968 | */ |
| 3969 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3970 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 3971 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 3972 | final int targetSdk = getTargetSdk(callingPackage); |
| 3973 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3974 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 3975 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3976 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3977 | mApp, subId, callingPackage, callingFeatureId, |
| 3978 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3979 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3980 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3981 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3982 | final long identity = Binder.clearCallingIdentity(); |
| 3983 | try { |
| 3984 | final Phone phone = getPhone(subId); |
| 3985 | if (phone != null) { |
| 3986 | return phone.getServiceState().getDataNetworkType(); |
| 3987 | } else { |
| 3988 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3989 | } |
| 3990 | } finally { |
| 3991 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3992 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3993 | } |
| 3994 | |
| 3995 | /** |
| 3996 | * Returns the data network type |
| 3997 | */ |
| 3998 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3999 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4000 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4001 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4002 | } |
| 4003 | |
| 4004 | /** |
| 4005 | * Returns the data network type for a subId |
| 4006 | */ |
| 4007 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4008 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4009 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4010 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4011 | mApp, subId, callingPackage, callingFeatureId, |
| 4012 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4013 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4014 | } |
| 4015 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4016 | final long identity = Binder.clearCallingIdentity(); |
| 4017 | try { |
| 4018 | final Phone phone = getPhone(subId); |
| 4019 | if (phone != null) { |
| 4020 | return phone.getServiceState().getDataNetworkType(); |
| 4021 | } else { |
| 4022 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4023 | } |
| 4024 | } finally { |
| 4025 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4026 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4027 | } |
| 4028 | |
| 4029 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4030 | * Returns the Voice network type for a subId |
| 4031 | */ |
| 4032 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4033 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4034 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4035 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4036 | mApp, subId, callingPackage, callingFeatureId, |
| 4037 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4038 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4039 | } |
| 4040 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4041 | final long identity = Binder.clearCallingIdentity(); |
| 4042 | try { |
| 4043 | final Phone phone = getPhone(subId); |
| 4044 | if (phone != null) { |
| 4045 | return phone.getServiceState().getVoiceNetworkType(); |
| 4046 | } else { |
| 4047 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4048 | } |
| 4049 | } finally { |
| 4050 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4051 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4052 | } |
| 4053 | |
| 4054 | /** |
| 4055 | * @return true if a ICC card is present |
| 4056 | */ |
| 4057 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4058 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4059 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4060 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4061 | } |
| 4062 | |
| 4063 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4064 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4065 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4066 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4067 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4068 | final long identity = Binder.clearCallingIdentity(); |
| 4069 | try { |
| 4070 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4071 | if (phone != null) { |
| 4072 | return phone.getIccCard().hasIccCard(); |
| 4073 | } else { |
| 4074 | return false; |
| 4075 | } |
| 4076 | } finally { |
| 4077 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4078 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4079 | } |
| 4080 | |
| 4081 | /** |
| 4082 | * Return if the current radio is LTE on CDMA. This |
| 4083 | * is a tri-state return value as for a period of time |
| 4084 | * the mode may be unknown. |
| 4085 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4086 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4087 | * @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] | 4088 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4089 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4090 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4091 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4092 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4093 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4094 | } |
| 4095 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4096 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4097 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4098 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4099 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4100 | mApp, subId, callingPackage, callingFeatureId, |
| 4101 | "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4102 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4103 | } |
| 4104 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4105 | final long identity = Binder.clearCallingIdentity(); |
| 4106 | try { |
| 4107 | final Phone phone = getPhone(subId); |
| 4108 | if (phone == null) { |
| 4109 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4110 | } else { |
| 4111 | return phone.getLteOnCdmaMode(); |
| 4112 | } |
| 4113 | } finally { |
| 4114 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4115 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4116 | } |
| 4117 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4118 | /** |
| 4119 | * {@hide} |
| 4120 | * Returns Default subId, 0 in the case of single standby. |
| 4121 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4122 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4123 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4124 | } |
| 4125 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4126 | private int getSlotForDefaultSubscription() { |
| 4127 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4128 | } |
| 4129 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4130 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4131 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4132 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4133 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4134 | private boolean isActiveSubscription(int subId) { |
| 4135 | return mSubscriptionController.isActiveSubId(subId); |
| 4136 | } |
| 4137 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4138 | /** |
| 4139 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4140 | */ |
| 4141 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4142 | final long identity = Binder.clearCallingIdentity(); |
| 4143 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4144 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4145 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4146 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4147 | } finally { |
| 4148 | Binder.restoreCallingIdentity(identity); |
| 4149 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4150 | } |
| 4151 | |
| 4152 | /** |
| 4153 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4154 | */ |
| 4155 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4156 | final long identity = Binder.clearCallingIdentity(); |
| 4157 | try { |
| 4158 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4159 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4160 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4161 | } finally { |
| 4162 | Binder.restoreCallingIdentity(identity); |
| 4163 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4164 | } |
| 4165 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4166 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4167 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4168 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4169 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4170 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4171 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4172 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4173 | if (phoneId == -1) { |
| 4174 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4175 | + " does not correspond to an active phone"); |
| 4176 | } |
| 4177 | return PhoneFactory.getPhone(phoneId); |
| 4178 | } |
| 4179 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4180 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4181 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4182 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4183 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4184 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4185 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4186 | if (DBG) { |
| 4187 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4188 | } |
| 4189 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4190 | p2); |
| 4191 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4192 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4193 | |
| 4194 | @Override |
| 4195 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4196 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4197 | enforceModifyPermission(); |
| 4198 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4199 | if (DBG) { |
| 4200 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4201 | } |
| 4202 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4203 | callingPackage, aid, p2); |
| 4204 | } |
| 4205 | |
| 4206 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4207 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4208 | final long identity = Binder.clearCallingIdentity(); |
| 4209 | try { |
| 4210 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4211 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4212 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4213 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4214 | if (bestComponent == null |
| 4215 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4216 | loge("The calling package is not allowed to access ISD-R."); |
| 4217 | throw new SecurityException( |
| 4218 | "The calling package is not allowed to access ISD-R."); |
| 4219 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4220 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4221 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4222 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4223 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4224 | null /* workSource */); |
| 4225 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4226 | return response; |
| 4227 | } finally { |
| 4228 | Binder.restoreCallingIdentity(identity); |
| 4229 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4233 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4234 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4235 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4236 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4237 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4238 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4239 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4240 | @Override |
| 4241 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4242 | enforceModifyPermission(); |
| 4243 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4244 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4245 | channel); |
| 4246 | } |
| 4247 | |
| 4248 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4249 | final long identity = Binder.clearCallingIdentity(); |
| 4250 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4251 | if (channel < 0) { |
| 4252 | return false; |
| 4253 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4254 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4255 | null /* workSource */); |
| 4256 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4257 | return success; |
| 4258 | } finally { |
| 4259 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4260 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4261 | } |
| 4262 | |
| 4263 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4264 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4265 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4266 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4267 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4268 | if (DBG) { |
| 4269 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4270 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4271 | + p3 + " data=" + data); |
| 4272 | } |
| 4273 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4274 | command, p1, p2, p3, data); |
| 4275 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4276 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4277 | @Override |
| 4278 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4279 | int command, int p1, int p2, int p3, String data) { |
| 4280 | enforceModifyPermission(); |
| 4281 | if (DBG) { |
| 4282 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4283 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4284 | + p3 + " data=" + data); |
| 4285 | } |
| 4286 | return iccTransmitApduLogicalChannelWithPermission( |
| 4287 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4288 | data); |
| 4289 | } |
| 4290 | |
| 4291 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4292 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4293 | final long identity = Binder.clearCallingIdentity(); |
| 4294 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4295 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4296 | return ""; |
| 4297 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4298 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4299 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4300 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4301 | null /* workSource */); |
| 4302 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4303 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4304 | // Append the returned status code to the end of the response payload. |
| 4305 | String s = Integer.toHexString( |
| 4306 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4307 | if (response.payload != null) { |
| 4308 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4309 | } |
| 4310 | return s; |
| 4311 | } finally { |
| 4312 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4313 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4314 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4315 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4316 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4317 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4318 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4319 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4320 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4321 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4322 | if (DBG) { |
| 4323 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4324 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4325 | } |
| 4326 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4327 | cla, command, p1, p2, p3, data); |
| 4328 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4329 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4330 | @Override |
| 4331 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4332 | int command, int p1, int p2, int p3, String data) { |
| 4333 | enforceModifyPermission(); |
| 4334 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4335 | if (DBG) { |
| 4336 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4337 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4338 | + " data=" + data); |
| 4339 | } |
| 4340 | |
| 4341 | return iccTransmitApduBasicChannelWithPermission( |
| 4342 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4343 | p2, p3, data); |
| 4344 | } |
| 4345 | |
| 4346 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4347 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4348 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4349 | final long identity = Binder.clearCallingIdentity(); |
| 4350 | try { |
| 4351 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4352 | && TextUtils.equals(ISDR_AID, data)) { |
| 4353 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4354 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4355 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4356 | if (bestComponent == null |
| 4357 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4358 | loge("The calling package is not allowed to select ISD-R."); |
| 4359 | throw new SecurityException( |
| 4360 | "The calling package is not allowed to select ISD-R."); |
| 4361 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4362 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4363 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4364 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4365 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4366 | null /* workSource */); |
| 4367 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4368 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4369 | // Append the returned status code to the end of the response payload. |
| 4370 | String s = Integer.toHexString( |
| 4371 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4372 | if (response.payload != null) { |
| 4373 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4374 | } |
| 4375 | return s; |
| 4376 | } finally { |
| 4377 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4378 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4379 | } |
| 4380 | |
| 4381 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4382 | 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] | 4383 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4384 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4385 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4386 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4387 | final long identity = Binder.clearCallingIdentity(); |
| 4388 | try { |
| 4389 | if (DBG) { |
| 4390 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4391 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4392 | } |
| 4393 | |
| 4394 | IccIoResult response = |
| 4395 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4396 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4397 | subId); |
| 4398 | |
| 4399 | if (DBG) { |
| 4400 | log("Exchange SIM_IO [R]" + response); |
| 4401 | } |
| 4402 | |
| 4403 | byte[] result = null; |
| 4404 | int length = 2; |
| 4405 | if (response.payload != null) { |
| 4406 | length = 2 + response.payload.length; |
| 4407 | result = new byte[length]; |
| 4408 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4409 | } else { |
| 4410 | result = new byte[length]; |
| 4411 | } |
| 4412 | |
| 4413 | result[length - 1] = (byte) response.sw2; |
| 4414 | result[length - 2] = (byte) response.sw1; |
| 4415 | return result; |
| 4416 | } finally { |
| 4417 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4418 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4419 | } |
| 4420 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4421 | /** |
| 4422 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4423 | * on a particular subscription |
| 4424 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4425 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4426 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4427 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4428 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4429 | return null; |
| 4430 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4431 | |
| 4432 | final long identity = Binder.clearCallingIdentity(); |
| 4433 | try { |
| 4434 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4435 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4436 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4437 | return null; |
| 4438 | } |
| 4439 | Object response = sendRequest( |
| 4440 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4441 | if (response instanceof String[]) { |
| 4442 | return (String[]) response; |
| 4443 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4444 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4445 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4446 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4447 | } finally { |
| 4448 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4449 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4450 | } |
| 4451 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4452 | /** |
| 4453 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4454 | * subscription. |
| 4455 | * |
| 4456 | * @param subId the id of the subscription. |
| 4457 | * @param appType the uicc app type, must be USIM or SIM. |
| 4458 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4459 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4460 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4461 | * @return number of fplmns that is successfully written to the SIM. |
| 4462 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4463 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4464 | String callingFeatureId) { |
| 4465 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4466 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4467 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4468 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4469 | } |
| 4470 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4471 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4472 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4473 | } |
| 4474 | if (fplmns == null) { |
| 4475 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4476 | } |
| 4477 | for (String fplmn : fplmns) { |
| 4478 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4479 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4480 | } |
| 4481 | } |
| 4482 | final long identity = Binder.clearCallingIdentity(); |
| 4483 | try { |
| 4484 | Object response = sendRequest( |
| 4485 | CMD_SET_FORBIDDEN_PLMNS, |
| 4486 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4487 | subId); |
| 4488 | return (int) response; |
| 4489 | } finally { |
| 4490 | Binder.restoreCallingIdentity(identity); |
| 4491 | } |
| 4492 | } |
| 4493 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4494 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4495 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4496 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4497 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4498 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4499 | final long identity = Binder.clearCallingIdentity(); |
| 4500 | try { |
| 4501 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4502 | if (response.payload == null) { |
| 4503 | return ""; |
| 4504 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4505 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4506 | // Append the returned status code to the end of the response payload. |
| 4507 | String s = Integer.toHexString( |
| 4508 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4509 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4510 | return s; |
| 4511 | } finally { |
| 4512 | Binder.restoreCallingIdentity(identity); |
| 4513 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4514 | } |
| 4515 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4516 | /** |
| 4517 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4518 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4519 | * |
| 4520 | * @param itemID the ID of the item to read |
| 4521 | * @return the NV item as a String, or null on error. |
| 4522 | */ |
| 4523 | @Override |
| 4524 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4525 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4526 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4527 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4528 | |
| 4529 | final long identity = Binder.clearCallingIdentity(); |
| 4530 | try { |
| 4531 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4532 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4533 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4534 | return value; |
| 4535 | } finally { |
| 4536 | Binder.restoreCallingIdentity(identity); |
| 4537 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4538 | } |
| 4539 | |
| 4540 | /** |
| 4541 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4542 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4543 | * |
| 4544 | * @param itemID the ID of the item to read |
| 4545 | * @param itemValue the value to write, as a String |
| 4546 | * @return true on success; false on any failure |
| 4547 | */ |
| 4548 | @Override |
| 4549 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4550 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4551 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4552 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4553 | |
| 4554 | final long identity = Binder.clearCallingIdentity(); |
| 4555 | try { |
| 4556 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4557 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4558 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4559 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4560 | return success; |
| 4561 | } finally { |
| 4562 | Binder.restoreCallingIdentity(identity); |
| 4563 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4564 | } |
| 4565 | |
| 4566 | /** |
| 4567 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4568 | * Used for device configuration by some CDMA operators. |
| 4569 | * |
| 4570 | * @param preferredRoamingList byte array containing the new PRL |
| 4571 | * @return true on success; false on any failure |
| 4572 | */ |
| 4573 | @Override |
| 4574 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4575 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4576 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4577 | |
| 4578 | final long identity = Binder.clearCallingIdentity(); |
| 4579 | try { |
| 4580 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4581 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4582 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4583 | return success; |
| 4584 | } finally { |
| 4585 | Binder.restoreCallingIdentity(identity); |
| 4586 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4587 | } |
| 4588 | |
| 4589 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4590 | * 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] | 4591 | * Used for device configuration by some CDMA operators. |
| 4592 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4593 | * @param slotIndex - device slot. |
| 4594 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4595 | * @return true on success; false on any failure |
| 4596 | */ |
| 4597 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4598 | public boolean resetModemConfig(int slotIndex) { |
| 4599 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4600 | if (phone != null) { |
| 4601 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4602 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4603 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4604 | final long identity = Binder.clearCallingIdentity(); |
| 4605 | try { |
| 4606 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4607 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4608 | return success; |
| 4609 | } finally { |
| 4610 | Binder.restoreCallingIdentity(identity); |
| 4611 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4612 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4613 | return false; |
| 4614 | } |
| 4615 | |
| 4616 | /** |
| 4617 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4618 | * |
| 4619 | * @param slotIndex - device slot. |
| 4620 | * |
| 4621 | * @return true on success; false on any failure |
| 4622 | */ |
| 4623 | @Override |
| 4624 | public boolean rebootModem(int slotIndex) { |
| 4625 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4626 | if (phone != null) { |
| 4627 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4628 | mApp, phone.getSubId(), "rebootModem"); |
| 4629 | |
| 4630 | final long identity = Binder.clearCallingIdentity(); |
| 4631 | try { |
| 4632 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4633 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4634 | return success; |
| 4635 | } finally { |
| 4636 | Binder.restoreCallingIdentity(identity); |
| 4637 | } |
| 4638 | } |
| 4639 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4640 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4641 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4642 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4643 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4644 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4645 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4646 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4647 | return new String[0]; |
| 4648 | } |
| 4649 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4650 | final long identity = Binder.clearCallingIdentity(); |
| 4651 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4652 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4653 | } finally { |
| 4654 | Binder.restoreCallingIdentity(identity); |
| 4655 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4656 | } |
| 4657 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4658 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4659 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4660 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4661 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4662 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4663 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4664 | |
| 4665 | final long identity = Binder.clearCallingIdentity(); |
| 4666 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4667 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4668 | // may happen if the device does not support IMS. |
| 4669 | return; |
| 4670 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4671 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4672 | } finally { |
| 4673 | Binder.restoreCallingIdentity(identity); |
| 4674 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4675 | } |
| 4676 | |
| 4677 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4678 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4679 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4680 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4681 | public void disableIms(int slotId) { |
| 4682 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4683 | |
| 4684 | final long identity = Binder.clearCallingIdentity(); |
| 4685 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4686 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4687 | // may happen if the device does not support IMS. |
| 4688 | return; |
| 4689 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4690 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4691 | } finally { |
| 4692 | Binder.restoreCallingIdentity(identity); |
| 4693 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4694 | } |
| 4695 | |
| 4696 | /** |
| 4697 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4698 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4699 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4700 | */ |
| 4701 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4702 | IImsServiceFeatureCallback callback) { |
| 4703 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4704 | |
| 4705 | final long identity = Binder.clearCallingIdentity(); |
| 4706 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4707 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4708 | // may happen if the device does not support IMS. |
| 4709 | return null; |
| 4710 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4711 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4712 | } finally { |
| 4713 | Binder.restoreCallingIdentity(identity); |
| 4714 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4715 | } |
| 4716 | |
| 4717 | /** |
| 4718 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4719 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4720 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4721 | * listener for feature updates. |
| 4722 | */ |
| 4723 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4724 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4725 | |
| 4726 | final long identity = Binder.clearCallingIdentity(); |
| 4727 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4728 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4729 | // may happen if the device does not support IMS. |
| 4730 | return null; |
| 4731 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4732 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4733 | } finally { |
| 4734 | Binder.restoreCallingIdentity(identity); |
| 4735 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4736 | } |
| 4737 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4738 | /** |
| 4739 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4740 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4741 | */ |
| 4742 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4743 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4744 | |
| 4745 | final long identity = Binder.clearCallingIdentity(); |
| 4746 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4747 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4748 | // may happen if the device does not support IMS. |
| 4749 | return null; |
| 4750 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4751 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4752 | } finally { |
| 4753 | Binder.restoreCallingIdentity(identity); |
| 4754 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4755 | } |
| 4756 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4757 | /** |
| 4758 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4759 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4760 | */ |
| 4761 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4762 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4763 | |
| 4764 | final long identity = Binder.clearCallingIdentity(); |
| 4765 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4766 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4767 | // may happen if the device does not support IMS. |
| 4768 | return null; |
| 4769 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4770 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4771 | } finally { |
| 4772 | Binder.restoreCallingIdentity(identity); |
| 4773 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4774 | } |
| 4775 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4776 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4777 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4778 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4779 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 4780 | * @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] | 4781 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4782 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 4783 | * @param packageName The name of the package that the current configuration will be replaced |
| 4784 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4785 | * @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] | 4786 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4787 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 4788 | int[] featureTypes, String packageName) { |
| 4789 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 4790 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4791 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4792 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4793 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4794 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4795 | final long identity = Binder.clearCallingIdentity(); |
| 4796 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4797 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4798 | // may happen if the device does not support IMS. |
| 4799 | return false; |
| 4800 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4801 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 4802 | for (int featureType : featureTypes) { |
| 4803 | featureConfig.put(featureType, packageName); |
| 4804 | } |
| 4805 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 4806 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4807 | } finally { |
| 4808 | Binder.restoreCallingIdentity(identity); |
| 4809 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4810 | } |
| 4811 | |
| 4812 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4813 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4814 | * |
| 4815 | * @param slotId The slot that the ImsService is associated with. |
| 4816 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4817 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4818 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4819 | * @return the package name of the ImsService configuration. |
| 4820 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4821 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 4822 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4823 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4824 | TelephonyPermissions |
| 4825 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4826 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4827 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4828 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4829 | final long identity = Binder.clearCallingIdentity(); |
| 4830 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4831 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4832 | // may happen if the device does not support IMS. |
| 4833 | return ""; |
| 4834 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 4835 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4836 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 4837 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4838 | } finally { |
| 4839 | Binder.restoreCallingIdentity(identity); |
| 4840 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4841 | } |
| 4842 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4843 | /** |
| 4844 | * Get the MmTelFeature state associated with the requested subscription id. |
| 4845 | * @param subId The subscription that the MmTelFeature is associated with. |
| 4846 | * @param callback A callback with an integer containing the |
| 4847 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 4848 | */ |
| 4849 | @Override |
| 4850 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 4851 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 4852 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4853 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4854 | "IMS not available on device."); |
| 4855 | } |
| 4856 | final long token = Binder.clearCallingIdentity(); |
| 4857 | try { |
| 4858 | int slotId = getSlotIndex(subId); |
| 4859 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4860 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 4861 | + subId + "'"); |
| 4862 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4863 | } |
| 4864 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 4865 | try { |
| 4866 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 4867 | } catch (RemoteException e) { |
| 4868 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 4869 | + "Ignore"); |
| 4870 | } |
| 4871 | }); |
| 4872 | } finally { |
| 4873 | Binder.restoreCallingIdentity(token); |
| 4874 | } |
| 4875 | } |
| 4876 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4877 | public void setImsRegistrationState(boolean registered) { |
| 4878 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4879 | |
| 4880 | final long identity = Binder.clearCallingIdentity(); |
| 4881 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4882 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4883 | } finally { |
| 4884 | Binder.restoreCallingIdentity(identity); |
| 4885 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4886 | } |
| 4887 | |
| 4888 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4889 | * Set the network selection mode to automatic. |
| 4890 | * |
| 4891 | */ |
| 4892 | @Override |
| 4893 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4894 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4895 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4896 | |
| 4897 | final long identity = Binder.clearCallingIdentity(); |
| 4898 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame^] | 4899 | if (!isActiveSubscription(subId)) { |
| 4900 | return; |
| 4901 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4902 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4903 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4904 | } finally { |
| 4905 | Binder.restoreCallingIdentity(identity); |
| 4906 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4907 | } |
| 4908 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4909 | /** |
| 4910 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4911 | * |
| 4912 | * @param subId the id of the subscription. |
| 4913 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4914 | * the operator to attach to. |
| 4915 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4916 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4917 | * normal network selection next time. |
| 4918 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4919 | */ |
| 4920 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4921 | public boolean setNetworkSelectionModeManual( |
| 4922 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4923 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4924 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4925 | |
| 4926 | if (!isActiveSubscription(subId)) { |
| 4927 | return false; |
| 4928 | } |
| 4929 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4930 | final long identity = Binder.clearCallingIdentity(); |
| 4931 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4932 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4933 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4934 | if (DBG) { |
| 4935 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4936 | + " operator: " + operatorInfo); |
| 4937 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4938 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4939 | } finally { |
| 4940 | Binder.restoreCallingIdentity(identity); |
| 4941 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4942 | } |
| 4943 | |
| 4944 | /** |
| 4945 | * Scans for available networks. |
| 4946 | */ |
| 4947 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4948 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 4949 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4950 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4951 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4952 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4953 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4954 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4955 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4956 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4957 | .setCallingPid(Binder.getCallingPid()) |
| 4958 | .setCallingUid(Binder.getCallingUid()) |
| 4959 | .setMethod("getCellNetworkScanResults") |
| 4960 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4961 | .build()); |
| 4962 | switch (locationResult) { |
| 4963 | case DENIED_HARD: |
| 4964 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4965 | case DENIED_SOFT: |
| 4966 | return null; |
| 4967 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4968 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4969 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4970 | try { |
| 4971 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4972 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4973 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4974 | } finally { |
| 4975 | Binder.restoreCallingIdentity(identity); |
| 4976 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4977 | } |
| 4978 | |
| 4979 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4980 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4981 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4982 | * @param subId id of the subscription |
| 4983 | * @param request contains the radio access networks with bands/channels to scan |
| 4984 | * @param messenger callback messenger for scan results or errors |
| 4985 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4986 | * @return the id of the requested scan which can be used to stop the scan. |
| 4987 | */ |
| 4988 | @Override |
| 4989 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4990 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4991 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4992 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4993 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4994 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4995 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4996 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4997 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4998 | .setCallingPid(Binder.getCallingPid()) |
| 4999 | .setCallingUid(Binder.getCallingUid()) |
| 5000 | .setMethod("requestNetworkScan") |
| 5001 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5002 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5003 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5004 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5005 | if (e != null) { |
| 5006 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5007 | throw e; |
| 5008 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5009 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5010 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5011 | } |
| 5012 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5013 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5014 | int callingUid = Binder.getCallingUid(); |
| 5015 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5016 | final long identity = Binder.clearCallingIdentity(); |
| 5017 | try { |
| 5018 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5019 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5020 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5021 | } finally { |
| 5022 | Binder.restoreCallingIdentity(identity); |
| 5023 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5024 | } |
| 5025 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5026 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5027 | NetworkScanRequest request, int subId) { |
| 5028 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5029 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5030 | boolean hasNetworkScanPermission = |
| 5031 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5032 | == PERMISSION_GRANTED; |
| 5033 | |
| 5034 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5035 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5036 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5037 | } |
| 5038 | |
| 5039 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5040 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5041 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5042 | return new SecurityException("Specific channels must not be" |
| 5043 | + " scanned without location access."); |
| 5044 | } |
| 5045 | } |
| 5046 | } |
| 5047 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5048 | return null; |
| 5049 | } |
| 5050 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5051 | /** |
| 5052 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5053 | * |
| 5054 | * @param subId id of the subscription |
| 5055 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5056 | */ |
| 5057 | @Override |
| 5058 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5059 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5060 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5061 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5062 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5063 | final long identity = Binder.clearCallingIdentity(); |
| 5064 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5065 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5066 | } finally { |
| 5067 | Binder.restoreCallingIdentity(identity); |
| 5068 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5072 | * Get the calculated preferred network type. |
| 5073 | * Used for debugging incorrect network type. |
| 5074 | * |
| 5075 | * @return the preferred network type, defined in RILConstants.java. |
| 5076 | */ |
| 5077 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5078 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5079 | final Phone defaultPhone = getDefaultPhone(); |
| 5080 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5081 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5082 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5083 | } |
| 5084 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5085 | final long identity = Binder.clearCallingIdentity(); |
| 5086 | try { |
| 5087 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5088 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5089 | } finally { |
| 5090 | Binder.restoreCallingIdentity(identity); |
| 5091 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5092 | } |
| 5093 | |
| 5094 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5095 | * Get the preferred network type. |
| 5096 | * Used for device configuration by some CDMA operators. |
| 5097 | * |
| 5098 | * @return the preferred network type, defined in RILConstants.java. |
| 5099 | */ |
| 5100 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5101 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5102 | TelephonyPermissions |
| 5103 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5104 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5105 | |
| 5106 | final long identity = Binder.clearCallingIdentity(); |
| 5107 | try { |
| 5108 | if (DBG) log("getPreferredNetworkType"); |
| 5109 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5110 | int networkType = (result != null ? result[0] : -1); |
| 5111 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5112 | return networkType; |
| 5113 | } finally { |
| 5114 | Binder.restoreCallingIdentity(identity); |
| 5115 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5116 | } |
| 5117 | |
| 5118 | /** |
| 5119 | * Set the preferred network type. |
| 5120 | * Used for device configuration by some CDMA operators. |
| 5121 | * |
| 5122 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5123 | * @return true on success; false on any failure. |
| 5124 | */ |
| 5125 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5126 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5127 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5128 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5129 | |
| 5130 | final long identity = Binder.clearCallingIdentity(); |
| 5131 | try { |
| 5132 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 5133 | Boolean success = (Boolean) sendRequest( |
| 5134 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 5135 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5136 | if (success) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5137 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5138 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5139 | } |
| 5140 | return success; |
| 5141 | } finally { |
| 5142 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5143 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5144 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5145 | |
| 5146 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5147 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5148 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5149 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5150 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5151 | * @hide |
| 5152 | */ |
| 5153 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5154 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5155 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5156 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5157 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5158 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5159 | if (phone != null) { |
| 5160 | return phone.hasMatchedTetherApnSetting(); |
| 5161 | } else { |
| 5162 | return false; |
| 5163 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5164 | } finally { |
| 5165 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5166 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5167 | } |
| 5168 | |
| 5169 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5170 | * Set mobile data enabled |
| 5171 | * Used by the user through settings etc to turn on/off mobile data |
| 5172 | * |
| 5173 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5174 | */ |
| 5175 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5176 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5177 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5178 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5179 | |
| 5180 | final long identity = Binder.clearCallingIdentity(); |
| 5181 | try { |
| 5182 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5183 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5184 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5185 | if (phone != null) { |
| 5186 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5187 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5188 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5189 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5190 | } |
| 5191 | } finally { |
| 5192 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5193 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5194 | } |
| 5195 | |
| 5196 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5197 | * Get the user enabled state of Mobile Data. |
| 5198 | * |
| 5199 | * TODO: remove and use isUserDataEnabled. |
| 5200 | * This can't be removed now because some vendor codes |
| 5201 | * calls through ITelephony directly while they should |
| 5202 | * use TelephonyManager. |
| 5203 | * |
| 5204 | * @return true on enabled |
| 5205 | */ |
| 5206 | @Override |
| 5207 | public boolean getDataEnabled(int subId) { |
| 5208 | return isUserDataEnabled(subId); |
| 5209 | } |
| 5210 | |
| 5211 | /** |
| 5212 | * Get whether mobile data is enabled per user setting. |
| 5213 | * |
| 5214 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5215 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5216 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5217 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5218 | * |
| 5219 | * @return {@code true} if data is enabled else {@code false} |
| 5220 | */ |
| 5221 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5222 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5223 | try { |
| 5224 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5225 | null); |
| 5226 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5227 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5228 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5229 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5230 | |
| 5231 | final long identity = Binder.clearCallingIdentity(); |
| 5232 | try { |
| 5233 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5234 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5235 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5236 | if (phone != null) { |
| 5237 | boolean retVal = phone.isUserDataEnabled(); |
| 5238 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5239 | return retVal; |
| 5240 | } else { |
| 5241 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5242 | return false; |
| 5243 | } |
| 5244 | } finally { |
| 5245 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5246 | } |
| 5247 | } |
| 5248 | |
| 5249 | /** |
| 5250 | * Get whether mobile data is enabled. |
| 5251 | * |
| 5252 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 5253 | * whether mobile data is actually enabled. |
| 5254 | * |
| 5255 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 5256 | * |
| 5257 | * @return {@code true} if data is enabled else {@code false} |
| 5258 | */ |
| 5259 | @Override |
| 5260 | public boolean isDataEnabled(int subId) { |
| 5261 | try { |
| 5262 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5263 | null); |
| 5264 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5265 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5266 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5267 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5268 | |
| 5269 | final long identity = Binder.clearCallingIdentity(); |
| 5270 | try { |
| 5271 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5272 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5273 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5274 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5275 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5276 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5277 | return retVal; |
| 5278 | } else { |
| 5279 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5280 | return false; |
| 5281 | } |
| 5282 | } finally { |
| 5283 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5284 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5285 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5286 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5287 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 5288 | Phone phone) { |
| 5289 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5290 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5291 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5292 | || subController == null) return privilegeFromSim; |
| 5293 | |
| 5294 | int uid = Binder.getCallingUid(); |
| 5295 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5296 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5297 | |
| 5298 | final long identity = Binder.clearCallingIdentity(); |
| 5299 | try { |
| 5300 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5301 | SubscriptionManager subManager = (SubscriptionManager) |
| 5302 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5303 | for (String pkg : packages) { |
| 5304 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5305 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5306 | } |
| 5307 | } |
| 5308 | return privilegeFromSim; |
| 5309 | } finally { |
| 5310 | Binder.restoreCallingIdentity(identity); |
| 5311 | } |
| 5312 | } |
| 5313 | |
| 5314 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5315 | String pkgName) { |
| 5316 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5317 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5318 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5319 | || subController == null) return privilegeFromSim; |
| 5320 | |
| 5321 | final long identity = Binder.clearCallingIdentity(); |
| 5322 | try { |
| 5323 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5324 | SubscriptionManager subManager = (SubscriptionManager) |
| 5325 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5326 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5327 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5328 | } finally { |
| 5329 | Binder.restoreCallingIdentity(identity); |
| 5330 | } |
| 5331 | } |
| 5332 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5333 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5334 | public int getCarrierPrivilegeStatus(int subId) { |
| 5335 | final Phone phone = getPhone(subId); |
| 5336 | if (phone == null) { |
| 5337 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5338 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5339 | } |
| 5340 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5341 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5342 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5343 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5344 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5345 | |
| 5346 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5347 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 5348 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5349 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5350 | |
| 5351 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5352 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5353 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5354 | final Phone phone = getPhone(subId); |
| 5355 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5356 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5357 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5358 | } |
| 5359 | UiccProfile profile = |
| 5360 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5361 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5362 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5363 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5364 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5365 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5366 | profile.getCarrierPrivilegeStatusForUid( |
| 5367 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5368 | } |
| 5369 | |
| 5370 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5371 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5372 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5373 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5374 | } |
| 5375 | |
| 5376 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5377 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5378 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5379 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5380 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5381 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5382 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5383 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5384 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5385 | } |
| 5386 | |
| 5387 | @Override |
| 5388 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5389 | if (TextUtils.isEmpty(pkgName)) |
| 5390 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5391 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5392 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5393 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5394 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5395 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5396 | continue; |
| 5397 | } |
| 5398 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5399 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5400 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5401 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5402 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5403 | break; |
| 5404 | } |
| 5405 | } |
| 5406 | |
| 5407 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5408 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5409 | |
| 5410 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5411 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5412 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5413 | loge("phoneId " + phoneId + " is not valid."); |
| 5414 | return null; |
| 5415 | } |
| 5416 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5417 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5418 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5419 | return null ; |
| 5420 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5421 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5422 | } |
| 5423 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5424 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5425 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5426 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5427 | List<String> privilegedPackages = new ArrayList<>(); |
| 5428 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5429 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5430 | // has UICC in that slot. |
| 5431 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5432 | if (card.hasCarrierPrivilegeRules()) { |
| 5433 | if (packages == null) { |
| 5434 | // Only check packages in user 0 for now |
| 5435 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5436 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5437 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5438 | | PackageManager.GET_SIGNING_CERTIFICATES, |
| 5439 | UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5440 | } |
| 5441 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5442 | PackageInfo pkgInfo = packages.get(p); |
| 5443 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5444 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5445 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5446 | privilegedPackages.add(pkgInfo.packageName); |
| 5447 | } |
| 5448 | } |
| 5449 | } |
| 5450 | } |
| 5451 | return privilegedPackages; |
| 5452 | } |
| 5453 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5454 | @Override |
| 5455 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5456 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5457 | |
| 5458 | final long identity = Binder.clearCallingIdentity(); |
| 5459 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5460 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5461 | try { |
| 5462 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5463 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5464 | } |
| 5465 | } finally { |
| 5466 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5467 | } |
| 5468 | return privilegedPackages; |
| 5469 | } |
| 5470 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5471 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5472 | final Phone phone = getPhone(subId); |
| 5473 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5474 | if (card == null) { |
| 5475 | loge("getIccId: No UICC"); |
| 5476 | return null; |
| 5477 | } |
| 5478 | String iccId = card.getIccId(); |
| 5479 | if (TextUtils.isEmpty(iccId)) { |
| 5480 | loge("getIccId: ICC ID is null or empty."); |
| 5481 | return null; |
| 5482 | } |
| 5483 | return iccId; |
| 5484 | } |
| 5485 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5486 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5487 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5488 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5489 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5490 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5491 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5492 | final long identity = Binder.clearCallingIdentity(); |
| 5493 | try { |
| 5494 | final String iccId = getIccId(subId); |
| 5495 | final Phone phone = getPhone(subId); |
| 5496 | if (phone == null) { |
| 5497 | return false; |
| 5498 | } |
| 5499 | final String subscriberId = phone.getSubscriberId(); |
| 5500 | |
| 5501 | if (DBG_MERGE) { |
| 5502 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 5503 | + subscriberId + " to " + number); |
| 5504 | } |
| 5505 | |
| 5506 | if (TextUtils.isEmpty(iccId)) { |
| 5507 | return false; |
| 5508 | } |
| 5509 | |
| 5510 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5511 | |
| 5512 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5513 | if (alphaTag == null) { |
| 5514 | editor.remove(alphaTagPrefKey); |
| 5515 | } else { |
| 5516 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5517 | } |
| 5518 | |
| 5519 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5520 | // track all merged IMSIs based on line number |
| 5521 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5522 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5523 | if (number == null) { |
| 5524 | editor.remove(numberPrefKey); |
| 5525 | editor.remove(subscriberPrefKey); |
| 5526 | } else { |
| 5527 | editor.putString(numberPrefKey, number); |
| 5528 | editor.putString(subscriberPrefKey, subscriberId); |
| 5529 | } |
| 5530 | |
| 5531 | editor.commit(); |
| 5532 | return true; |
| 5533 | } finally { |
| 5534 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5535 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5536 | } |
| 5537 | |
| 5538 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5539 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 5540 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5541 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5542 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5543 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5544 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5545 | return null; |
| 5546 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5547 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5548 | final long identity = Binder.clearCallingIdentity(); |
| 5549 | try { |
| 5550 | String iccId = getIccId(subId); |
| 5551 | if (iccId != null) { |
| 5552 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5553 | if (DBG_MERGE) { |
| 5554 | log("getLine1NumberForDisplay returning " |
| 5555 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5556 | } |
| 5557 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5558 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5559 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5560 | return null; |
| 5561 | } finally { |
| 5562 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5563 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5564 | } |
| 5565 | |
| 5566 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5567 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 5568 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5569 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5570 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5571 | return null; |
| 5572 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5573 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5574 | final long identity = Binder.clearCallingIdentity(); |
| 5575 | try { |
| 5576 | String iccId = getIccId(subId); |
| 5577 | if (iccId != null) { |
| 5578 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5579 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5580 | } |
| 5581 | return null; |
| 5582 | } finally { |
| 5583 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5584 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5585 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5586 | |
| 5587 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5588 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 5589 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5590 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5591 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5592 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5593 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5594 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5595 | return null; |
| 5596 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5597 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5598 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5599 | // the process, where TelephonyManager was instantiated. |
| 5600 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5601 | final long identity = Binder.clearCallingIdentity(); |
| 5602 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5603 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5604 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5605 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5606 | |
| 5607 | // Figure out what subscribers are currently active |
| 5608 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5609 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5610 | // Only consider subs which match the current subId |
| 5611 | // This logic can be simplified. See b/131189269 for progress. |
| 5612 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5613 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5614 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5615 | |
| 5616 | // First pass, find a number override for an active subscriber |
| 5617 | String mergeNumber = null; |
| 5618 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5619 | for (String key : prefs.keySet()) { |
| 5620 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5621 | final String subscriberId = (String) prefs.get(key); |
| 5622 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5623 | final String iccId = key.substring( |
| 5624 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5625 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5626 | mergeNumber = (String) prefs.get(numberKey); |
| 5627 | if (DBG_MERGE) { |
| 5628 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5629 | + " for active subscriber " + subscriberId); |
| 5630 | } |
| 5631 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5632 | break; |
| 5633 | } |
| 5634 | } |
| 5635 | } |
| 5636 | } |
| 5637 | |
| 5638 | // Shortcut when no active merged subscribers |
| 5639 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5640 | return null; |
| 5641 | } |
| 5642 | |
| 5643 | // Second pass, find all subscribers under that line override |
| 5644 | final ArraySet<String> result = new ArraySet<>(); |
| 5645 | for (String key : prefs.keySet()) { |
| 5646 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5647 | final String number = (String) prefs.get(key); |
| 5648 | if (mergeNumber.equals(number)) { |
| 5649 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5650 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5651 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5652 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5653 | result.add(subscriberId); |
| 5654 | } |
| 5655 | } |
| 5656 | } |
| 5657 | } |
| 5658 | |
| 5659 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5660 | Arrays.sort(resultArray); |
| 5661 | if (DBG_MERGE) { |
| 5662 | Slog.d(LOG_TAG, |
| 5663 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5664 | } |
| 5665 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5666 | } finally { |
| 5667 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5668 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5669 | } |
| 5670 | |
| 5671 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5672 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 5673 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 5674 | |
| 5675 | final long identity = Binder.clearCallingIdentity(); |
| 5676 | try { |
| 5677 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 5678 | TelephonyManager.class); |
| 5679 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 5680 | if (subscriberId == null) { |
| 5681 | if (DBG) { |
| 5682 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 5683 | + subId); |
| 5684 | } |
| 5685 | return null; |
| 5686 | } |
| 5687 | |
| 5688 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 5689 | .getSubscriptionInfo(subId); |
| 5690 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 5691 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 5692 | if (groupUuid == null) { |
| 5693 | return new String[]{subscriberId}; |
| 5694 | } |
| 5695 | |
| 5696 | // Get all subscriberIds from the group. |
| 5697 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 5698 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5699 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 5700 | null); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5701 | for (SubscriptionInfo subInfo : groupInfos) { |
| 5702 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 5703 | if (subscriberId != null) { |
| 5704 | mergedSubscriberIds.add(subscriberId); |
| 5705 | } |
| 5706 | } |
| 5707 | |
| 5708 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 5709 | } finally { |
| 5710 | Binder.restoreCallingIdentity(identity); |
| 5711 | |
| 5712 | } |
| 5713 | } |
| 5714 | |
| 5715 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5716 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5717 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5718 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5719 | |
| 5720 | final long identity = Binder.clearCallingIdentity(); |
| 5721 | try { |
| 5722 | final Phone phone = getPhone(subId); |
| 5723 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5724 | } finally { |
| 5725 | Binder.restoreCallingIdentity(identity); |
| 5726 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5727 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5728 | |
| 5729 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5730 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5731 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5732 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5733 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5734 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5735 | |
| 5736 | final long identity = Binder.clearCallingIdentity(); |
| 5737 | try { |
| 5738 | final Phone phone = getPhone(subId); |
| 5739 | if (phone == null) { |
| 5740 | return false; |
| 5741 | } |
| 5742 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5743 | cdmaNonRoamingList); |
| 5744 | } finally { |
| 5745 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5746 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5747 | } |
| 5748 | |
| 5749 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5750 | @Deprecated |
| 5751 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5752 | enforceModifyPermission(); |
| 5753 | |
| 5754 | int returnValue = 0; |
| 5755 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5756 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5757 | if(result.exception == null) { |
| 5758 | if (result.result != null) { |
| 5759 | byte[] responseData = (byte[])(result.result); |
| 5760 | if(responseData.length > oemResp.length) { |
| 5761 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5762 | responseData.length + "bytes. Buffer Size is " + |
| 5763 | oemResp.length + "bytes."); |
| 5764 | } |
| 5765 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5766 | returnValue = responseData.length; |
| 5767 | } |
| 5768 | } else { |
| 5769 | CommandException ex = (CommandException) result.exception; |
| 5770 | returnValue = ex.getCommandError().ordinal(); |
| 5771 | if(returnValue > 0) returnValue *= -1; |
| 5772 | } |
| 5773 | } catch (RuntimeException e) { |
| 5774 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5775 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5776 | if(returnValue > 0) returnValue *= -1; |
| 5777 | } |
| 5778 | |
| 5779 | return returnValue; |
| 5780 | } |
| 5781 | |
| 5782 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5783 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5784 | try { |
| 5785 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5786 | } catch (RuntimeException e) { |
| 5787 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5788 | } |
| 5789 | } |
| 5790 | |
| 5791 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5792 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5793 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5794 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5795 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5796 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5797 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5798 | final long identity = Binder.clearCallingIdentity(); |
| 5799 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5800 | TelephonyPermissions |
| 5801 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5802 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5803 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5804 | } finally { |
| 5805 | Binder.restoreCallingIdentity(identity); |
| 5806 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5807 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5808 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5809 | |
| 5810 | @Override |
| 5811 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5812 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5813 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5814 | |
| 5815 | final long identity = Binder.clearCallingIdentity(); |
| 5816 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5817 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5818 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5819 | } finally { |
| 5820 | Binder.restoreCallingIdentity(identity); |
| 5821 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5822 | } |
| 5823 | |
| 5824 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5825 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5826 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5827 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5828 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5829 | return false; |
| 5830 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5831 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5832 | final long identity = Binder.clearCallingIdentity(); |
| 5833 | try { |
| 5834 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5835 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5836 | // In the long run, we may instead need to check if there exists a connection service |
| 5837 | // which can support video calling. |
| 5838 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5839 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5840 | return imsManager.isVtEnabledByPlatform() |
| 5841 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5842 | && imsManager.isVtEnabledByUser(); |
| 5843 | } finally { |
| 5844 | Binder.restoreCallingIdentity(identity); |
| 5845 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5846 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5847 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5848 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5849 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 5850 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5851 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5852 | mApp, subId, callingPackage, callingFeatureId, |
| 5853 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5854 | return false; |
| 5855 | } |
| 5856 | |
| 5857 | final long identity = Binder.clearCallingIdentity(); |
| 5858 | try { |
| 5859 | CarrierConfigManager configManager = |
| 5860 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5861 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5862 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5863 | } finally { |
| 5864 | Binder.restoreCallingIdentity(identity); |
| 5865 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5866 | } |
| 5867 | |
| 5868 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5869 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5870 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5871 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5872 | return false; |
| 5873 | } |
| 5874 | |
| 5875 | final long identity = Binder.clearCallingIdentity(); |
| 5876 | try { |
| 5877 | CarrierConfigManager configManager = |
| 5878 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5879 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5880 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5881 | } finally { |
| 5882 | Binder.restoreCallingIdentity(identity); |
| 5883 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5884 | } |
| 5885 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5886 | @Override |
| 5887 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 5888 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5889 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5890 | } |
| 5891 | |
| 5892 | @Override |
| 5893 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5894 | final long identity = Binder.clearCallingIdentity(); |
| 5895 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5896 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5897 | } finally { |
| 5898 | Binder.restoreCallingIdentity(identity); |
| 5899 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5900 | } |
| 5901 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5902 | /** |
| 5903 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5904 | * support for the feature and device firmware support. |
| 5905 | * |
| 5906 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5907 | */ |
| 5908 | @Override |
| 5909 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5910 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5911 | final Phone phone = getPhone(subscriptionId); |
| 5912 | if (phone == null) { |
| 5913 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5914 | return false; |
| 5915 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5916 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5917 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5918 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5919 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5920 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5921 | return isCarrierSupported && isDeviceSupported; |
| 5922 | } finally { |
| 5923 | Binder.restoreCallingIdentity(identity); |
| 5924 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5925 | } |
| 5926 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5927 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5928 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 5929 | * RTT setting, will return true if the device and carrier both support RTT. |
| 5930 | * 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] | 5931 | */ |
| 5932 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5933 | final long identity = Binder.clearCallingIdentity(); |
| 5934 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 5935 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 5936 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 5937 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 5938 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 5939 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 5940 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5941 | } finally { |
| 5942 | Binder.restoreCallingIdentity(identity); |
| 5943 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5944 | } |
| 5945 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5946 | @Deprecated |
| 5947 | @Override |
| 5948 | public String getDeviceId(String callingPackage) { |
| 5949 | return getDeviceIdWithFeature(callingPackage, null); |
| 5950 | } |
| 5951 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5952 | /** |
| 5953 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5954 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5955 | * |
| 5956 | * <p>Requires Permission: |
| 5957 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5958 | */ |
| 5959 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5960 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5961 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5962 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5963 | return null; |
| 5964 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5965 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 5966 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5967 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5968 | return null; |
| 5969 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5970 | |
| 5971 | final long identity = Binder.clearCallingIdentity(); |
| 5972 | try { |
| 5973 | return phone.getDeviceId(); |
| 5974 | } finally { |
| 5975 | Binder.restoreCallingIdentity(identity); |
| 5976 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5977 | } |
| 5978 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5979 | /** |
| 5980 | * {@hide} |
| 5981 | * Returns the IMS Registration Status on a particular subid |
| 5982 | * |
| 5983 | * @param subId |
| 5984 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5985 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5986 | Phone phone = getPhone(subId); |
| 5987 | if (phone != null) { |
| 5988 | return phone.isImsRegistered(); |
| 5989 | } else { |
| 5990 | return false; |
| 5991 | } |
| 5992 | } |
| 5993 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5994 | @Override |
| 5995 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5996 | final long identity = Binder.clearCallingIdentity(); |
| 5997 | try { |
| 5998 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5999 | } finally { |
| 6000 | Binder.restoreCallingIdentity(identity); |
| 6001 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6002 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6003 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6004 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6005 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6006 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6007 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6008 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6009 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6010 | } |
| 6011 | final long identity = Binder.clearCallingIdentity(); |
| 6012 | try { |
| 6013 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6014 | } finally { |
| 6015 | Binder.restoreCallingIdentity(identity); |
| 6016 | } |
| 6017 | } |
| 6018 | |
| 6019 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6020 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6021 | final long identity = Binder.clearCallingIdentity(); |
| 6022 | try { |
| 6023 | Phone phone = getPhone(subscriptionId); |
| 6024 | if (phone == null) { |
| 6025 | return null; |
| 6026 | } |
| 6027 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6028 | } finally { |
| 6029 | Binder.restoreCallingIdentity(identity); |
| 6030 | } |
| 6031 | } |
| 6032 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6033 | /** |
| 6034 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6035 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6036 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6037 | final long identity = Binder.clearCallingIdentity(); |
| 6038 | try { |
| 6039 | Phone phone = getPhone(subId); |
| 6040 | if (phone != null) { |
| 6041 | return phone.isWifiCallingEnabled(); |
| 6042 | } else { |
| 6043 | return false; |
| 6044 | } |
| 6045 | } finally { |
| 6046 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6047 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6048 | } |
| 6049 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6050 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6051 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6052 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6053 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6054 | final long identity = Binder.clearCallingIdentity(); |
| 6055 | try { |
| 6056 | Phone phone = getPhone(subId); |
| 6057 | if (phone != null) { |
| 6058 | return phone.isVideoEnabled(); |
| 6059 | } else { |
| 6060 | return false; |
| 6061 | } |
| 6062 | } finally { |
| 6063 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6064 | } |
| 6065 | } |
| 6066 | |
| 6067 | /** |
| 6068 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6069 | * defined in {@link ImsRegistrationImplBase}. |
| 6070 | */ |
| 6071 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6072 | final long identity = Binder.clearCallingIdentity(); |
| 6073 | try { |
| 6074 | Phone phone = getPhone(subId); |
| 6075 | if (phone != null) { |
| 6076 | return phone.getImsRegistrationTech(); |
| 6077 | } else { |
| 6078 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6079 | } |
| 6080 | } finally { |
| 6081 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6082 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6083 | } |
| 6084 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6085 | @Override |
| 6086 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6087 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6088 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6089 | return; |
| 6090 | } |
| 6091 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6092 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6093 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6094 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6095 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6096 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6097 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6098 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6099 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6100 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6101 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6102 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6103 | // There has been issues when Sms raw table somehow stores orphan |
| 6104 | // fragments. They lead to garbled message when new fragments come |
| 6105 | // in and combined with those stale ones. In case this happens again, |
| 6106 | // user can reset all network settings which will clean up this table. |
| 6107 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6108 | // Clean up IMS settings as well here. |
| 6109 | int slotId = getSlotIndex(subId); |
| 6110 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6111 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6112 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6113 | |
| 6114 | // Erase modem config if erase modem on network setting is enabled. |
| 6115 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6116 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6117 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6118 | sendEraseModemConfig(getDefaultPhone()); |
| 6119 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6120 | } finally { |
| 6121 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6122 | } |
| 6123 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6124 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6125 | private void cleanUpSmsRawTable(Context context) { |
| 6126 | ContentResolver resolver = context.getContentResolver(); |
| 6127 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6128 | resolver.delete(uri, null, null); |
| 6129 | } |
| 6130 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6131 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6132 | public String getSimLocaleForSubscriber(int subId) { |
| 6133 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6134 | final Phone phone = getPhone(subId); |
| 6135 | if (phone == null) { |
| 6136 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6137 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6138 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6139 | final long identity = Binder.clearCallingIdentity(); |
| 6140 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6141 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6142 | phone.getContext().getOpPackageName(), null); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6143 | if (info == null) { |
| 6144 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6145 | return null; |
| 6146 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6147 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6148 | // preferences (EF-PL and EF-LI)... |
| 6149 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6150 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6151 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6152 | if (localeFromDefaultSim != null) { |
| 6153 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6154 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6155 | + localeFromDefaultSim); |
| 6156 | return localeFromDefaultSim.toLanguageTag(); |
| 6157 | } else { |
| 6158 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6159 | } |
| 6160 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6161 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6162 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6163 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6164 | // the SIM and carrier preferences does not include a country we add the country |
| 6165 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6166 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6167 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6168 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6169 | return mccLocale.toLanguageTag(); |
| 6170 | } |
| 6171 | |
| 6172 | if (DBG) log("No locale found - returning null"); |
| 6173 | return null; |
| 6174 | } finally { |
| 6175 | Binder.restoreCallingIdentity(identity); |
| 6176 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6177 | } |
| 6178 | |
| 6179 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6180 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 6181 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6182 | } |
| 6183 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6184 | /** |
| 6185 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6186 | */ |
| 6187 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6188 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 6189 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6190 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6191 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6192 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6193 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6194 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6195 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6196 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6197 | * representing the state of the modem. |
| 6198 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6199 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6200 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6201 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6202 | */ |
| 6203 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6204 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6205 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6206 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6207 | |
| 6208 | final long identity = Binder.clearCallingIdentity(); |
| 6209 | try { |
| 6210 | ModemActivityInfo ret = null; |
| 6211 | synchronized (mLastModemActivityInfo) { |
| 6212 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 6213 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6214 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6215 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6216 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6217 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6218 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6219 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6220 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6221 | } |
| 6222 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6223 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 6224 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6225 | mLastModemActivityInfo.setIdleTimeMillis( |
| 6226 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6227 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 6228 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 6229 | info.getReceiveTimeMillis() + mLastModemActivityInfo |
| 6230 | .getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6231 | } |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6232 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6233 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 6234 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 6235 | mLastModemActivityInfo.getIdleTimeMillis(), |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6236 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 6237 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6238 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6239 | Bundle bundle = new Bundle(); |
| 6240 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 6241 | result.send(0, bundle); |
| 6242 | } finally { |
| 6243 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6244 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6245 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6246 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6247 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6248 | // less than total activity duration. |
| 6249 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6250 | if (info == null) { |
| 6251 | return false; |
| 6252 | } |
| 6253 | int activityDurationMs = |
| 6254 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6255 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6256 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6257 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6258 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6259 | } |
| 6260 | return (info.isValid() |
| 6261 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6262 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6263 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6264 | && (totalTxTimeMs <= activityDurationMs)); |
| 6265 | } |
| 6266 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6267 | /** |
| 6268 | * {@hide} |
| 6269 | * Returns the service state information on specified subscription. |
| 6270 | */ |
| 6271 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6272 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6273 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6274 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6275 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6276 | return null; |
| 6277 | } |
| 6278 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6279 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6280 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6281 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6282 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6283 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6284 | .setCallingPid(Binder.getCallingPid()) |
| 6285 | .setCallingUid(Binder.getCallingUid()) |
| 6286 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6287 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6288 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6289 | .build()); |
| 6290 | |
| 6291 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6292 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6293 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6294 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6295 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6296 | .setCallingPid(Binder.getCallingPid()) |
| 6297 | .setCallingUid(Binder.getCallingUid()) |
| 6298 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6299 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6300 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6301 | .build()); |
| 6302 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6303 | boolean hasFinePermission = |
| 6304 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6305 | boolean hasCoarsePermission = |
| 6306 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6307 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6308 | final long identity = Binder.clearCallingIdentity(); |
| 6309 | try { |
| 6310 | final Phone phone = getPhone(subId); |
| 6311 | if (phone == null) { |
| 6312 | return null; |
| 6313 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6314 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6315 | ServiceState ss = phone.getServiceState(); |
| 6316 | |
| 6317 | // Scrub out the location info in ServiceState depending on what level of access |
| 6318 | // the caller has. |
| 6319 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6320 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6321 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6322 | } finally { |
| 6323 | Binder.restoreCallingIdentity(identity); |
| 6324 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6325 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6326 | |
| 6327 | /** |
| 6328 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6329 | * |
| 6330 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6331 | * voicemail ringtone. |
| 6332 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6333 | * PhoneAccount. |
| 6334 | */ |
| 6335 | @Override |
| 6336 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6337 | final long identity = Binder.clearCallingIdentity(); |
| 6338 | try { |
| 6339 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6340 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6341 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6342 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6343 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6344 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6345 | } finally { |
| 6346 | Binder.restoreCallingIdentity(identity); |
| 6347 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6348 | } |
| 6349 | |
| 6350 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6351 | * Sets the per-account voicemail ringtone. |
| 6352 | * |
| 6353 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6354 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6355 | * |
| 6356 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6357 | * voicemail ringtone. |
| 6358 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6359 | * PhoneAccount. |
| 6360 | */ |
| 6361 | @Override |
| 6362 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6363 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6364 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6365 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6366 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6367 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6368 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6369 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6370 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6371 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6372 | |
| 6373 | final long identity = Binder.clearCallingIdentity(); |
| 6374 | try { |
| 6375 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6376 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6377 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6378 | } |
| 6379 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6380 | } finally { |
| 6381 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6382 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6383 | } |
| 6384 | |
| 6385 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6386 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6387 | * |
| 6388 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6389 | * voicemail vibration setting. |
| 6390 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6391 | */ |
| 6392 | @Override |
| 6393 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6394 | final long identity = Binder.clearCallingIdentity(); |
| 6395 | try { |
| 6396 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6397 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6398 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6399 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6400 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6401 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6402 | } finally { |
| 6403 | Binder.restoreCallingIdentity(identity); |
| 6404 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6405 | } |
| 6406 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6407 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6408 | * Sets the per-account voicemail vibration. |
| 6409 | * |
| 6410 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6411 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6412 | * |
| 6413 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6414 | * voicemail vibration setting. |
| 6415 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6416 | * specific PhoneAccount. |
| 6417 | */ |
| 6418 | @Override |
| 6419 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6420 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6421 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6422 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6423 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6424 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6425 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6426 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6427 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6428 | } |
| 6429 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6430 | final long identity = Binder.clearCallingIdentity(); |
| 6431 | try { |
| 6432 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6433 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6434 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6435 | } |
| 6436 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6437 | } finally { |
| 6438 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6439 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6440 | } |
| 6441 | |
| 6442 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6443 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6444 | * |
| 6445 | * @throws SecurityException if the caller does not have the required permission |
| 6446 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6447 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6448 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6449 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6450 | } |
| 6451 | |
| 6452 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6453 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6454 | * permission. |
| 6455 | * |
| 6456 | * @throws SecurityException if the caller does not have the required permission |
| 6457 | */ |
| 6458 | private void enforceSendSmsPermission() { |
| 6459 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6460 | } |
| 6461 | |
| 6462 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6463 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6464 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6465 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6466 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6467 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6468 | final long identity = Binder.clearCallingIdentity(); |
| 6469 | try { |
| 6470 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6471 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6472 | if (componentName == null) { |
| 6473 | throw new SecurityException( |
| 6474 | "Caller not current active visual voicemail package[null]"); |
| 6475 | } |
| 6476 | String vvmPackage = componentName.getPackageName(); |
| 6477 | if (!callingPackage.equals(vvmPackage)) { |
| 6478 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6479 | + vvmPackage + "]"); |
| 6480 | } |
| 6481 | } finally { |
| 6482 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6483 | } |
| 6484 | } |
| 6485 | |
| 6486 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6487 | * Return the application ID for the app type. |
| 6488 | * |
| 6489 | * @param subId the subscription ID that this request applies to. |
| 6490 | * @param appType the uicc app type. |
| 6491 | * @return Application ID for specificied app type, or null if no uicc. |
| 6492 | */ |
| 6493 | @Override |
| 6494 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6495 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6496 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6497 | |
| 6498 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6499 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6500 | if (phone == null) { |
| 6501 | return null; |
| 6502 | } |
| 6503 | String aid = null; |
| 6504 | try { |
| 6505 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6506 | .getApplicationByType(appType).getAid(); |
| 6507 | } catch (Exception e) { |
| 6508 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6509 | } |
| 6510 | return aid; |
| 6511 | } finally { |
| 6512 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6513 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6514 | } |
| 6515 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6516 | /** |
| 6517 | * Return the Electronic Serial Number. |
| 6518 | * |
| 6519 | * @param subId the subscription ID that this request applies to. |
| 6520 | * @return ESN or null if error. |
| 6521 | */ |
| 6522 | @Override |
| 6523 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6524 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6525 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6526 | |
| 6527 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6528 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6529 | if (phone == null) { |
| 6530 | return null; |
| 6531 | } |
| 6532 | String esn = null; |
| 6533 | try { |
| 6534 | esn = phone.getEsn(); |
| 6535 | } catch (Exception e) { |
| 6536 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6537 | } |
| 6538 | return esn; |
| 6539 | } finally { |
| 6540 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6541 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6542 | } |
| 6543 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6544 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6545 | * Return the Preferred Roaming List Version. |
| 6546 | * |
| 6547 | * @param subId the subscription ID that this request applies to. |
| 6548 | * @return PRLVersion or null if error. |
| 6549 | */ |
| 6550 | @Override |
| 6551 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6552 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6553 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6554 | |
| 6555 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6556 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6557 | if (phone == null) { |
| 6558 | return null; |
| 6559 | } |
| 6560 | String cdmaPrlVersion = null; |
| 6561 | try { |
| 6562 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6563 | } catch (Exception e) { |
| 6564 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6565 | } |
| 6566 | return cdmaPrlVersion; |
| 6567 | } finally { |
| 6568 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6569 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6570 | } |
| 6571 | |
| 6572 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6573 | * Get snapshot of Telephony histograms |
| 6574 | * @return List of Telephony histograms |
| 6575 | * @hide |
| 6576 | */ |
| 6577 | @Override |
| 6578 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6579 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6580 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6581 | |
| 6582 | final long identity = Binder.clearCallingIdentity(); |
| 6583 | try { |
| 6584 | return RIL.getTelephonyRILTimingHistograms(); |
| 6585 | } finally { |
| 6586 | Binder.restoreCallingIdentity(identity); |
| 6587 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6588 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6589 | |
| 6590 | /** |
| 6591 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6592 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6593 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6594 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6595 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6596 | * @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] | 6597 | */ |
| 6598 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6599 | @TelephonyManager.SetCarrierRestrictionResult |
| 6600 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6601 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6602 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6603 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6604 | if (carrierRestrictionRules == null) { |
| 6605 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6606 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6607 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6608 | final long identity = Binder.clearCallingIdentity(); |
| 6609 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6610 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6611 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6612 | } finally { |
| 6613 | Binder.restoreCallingIdentity(identity); |
| 6614 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6615 | } |
| 6616 | |
| 6617 | /** |
| 6618 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6619 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6620 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6621 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6622 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6623 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6624 | */ |
| 6625 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6626 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6627 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6628 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6629 | |
| 6630 | final long identity = Binder.clearCallingIdentity(); |
| 6631 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6632 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 6633 | if (response instanceof CarrierRestrictionRules) { |
| 6634 | return (CarrierRestrictionRules) response; |
| 6635 | } |
| 6636 | // Response is an Exception of some kind, |
| 6637 | // which is signalled to the user as a NULL retval |
| 6638 | return null; |
| 6639 | } catch (Exception e) { |
| 6640 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 6641 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6642 | } finally { |
| 6643 | Binder.restoreCallingIdentity(identity); |
| 6644 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6645 | } |
| 6646 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6647 | /** |
| 6648 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 6649 | * @param subId the subscription ID that this action applies to. |
| 6650 | * @param enabled control enable or disable metered apns. |
| 6651 | * {@hide} |
| 6652 | */ |
| 6653 | @Override |
| 6654 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 6655 | enforceModifyPermission(); |
| 6656 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6657 | |
| 6658 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6659 | if (phone == null) { |
| 6660 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 6661 | return; |
| 6662 | } |
| 6663 | try { |
| 6664 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 6665 | } catch (Exception e) { |
| 6666 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6667 | } finally { |
| 6668 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6669 | } |
| 6670 | } |
| 6671 | |
| 6672 | /** |
| 6673 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 6674 | * @param subId the subscription ID that this action applies to. |
| 6675 | * @param enabled control enable or disable radio. |
| 6676 | * {@hide} |
| 6677 | */ |
| 6678 | @Override |
| 6679 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 6680 | enforceModifyPermission(); |
| 6681 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6682 | |
| 6683 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6684 | if (phone == null) { |
| 6685 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 6686 | return; |
| 6687 | } |
| 6688 | try { |
| 6689 | phone.carrierActionSetRadioEnabled(enabled); |
| 6690 | } catch (Exception e) { |
| 6691 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6692 | } finally { |
| 6693 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6694 | } |
| 6695 | } |
| 6696 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6697 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6698 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6699 | * network status based on which carrier apps could apply actions accordingly, |
| 6700 | * enable/disable default url handler for example. |
| 6701 | * |
| 6702 | * @param subId the subscription ID that this action applies to. |
| 6703 | * @param report control start/stop reporting the default network status. |
| 6704 | * {@hide} |
| 6705 | */ |
| 6706 | @Override |
| 6707 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6708 | enforceModifyPermission(); |
| 6709 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6710 | |
| 6711 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6712 | if (phone == null) { |
| 6713 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6714 | return; |
| 6715 | } |
| 6716 | try { |
| 6717 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6718 | } catch (Exception e) { |
| 6719 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6720 | } finally { |
| 6721 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6722 | } |
| 6723 | } |
| 6724 | |
| 6725 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6726 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6727 | * @param subId the subscription ID that this action applies to. |
| 6728 | * {@hide} |
| 6729 | */ |
| 6730 | @Override |
| 6731 | public void carrierActionResetAll(int subId) { |
| 6732 | enforceModifyPermission(); |
| 6733 | final Phone phone = getPhone(subId); |
| 6734 | if (phone == null) { |
| 6735 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6736 | return; |
| 6737 | } |
| 6738 | try { |
| 6739 | phone.carrierActionResetAll(); |
| 6740 | } catch (Exception e) { |
| 6741 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6742 | } |
| 6743 | } |
| 6744 | |
| 6745 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6746 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6747 | * bug report is being generated. |
| 6748 | */ |
| 6749 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6750 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6751 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6752 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6753 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6754 | + Binder.getCallingPid() |
| 6755 | + ", uid=" + Binder.getCallingUid() |
| 6756 | + "without permission " |
| 6757 | + android.Manifest.permission.DUMP); |
| 6758 | return; |
| 6759 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6760 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6761 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6762 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6763 | @Override |
| 6764 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 6765 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 6766 | throws RemoteException { |
Torbjorn Eklund | 1050cb0 | 2018-11-16 14:05:38 +0100 | [diff] [blame] | 6767 | (new TelephonyShellCommand(this, getDefaultPhone().getContext())) |
| 6768 | .exec(this, in, out, err, args, callback, resultReceiver); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6769 | } |
| 6770 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6771 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6772 | * Get aggregated video call data usage since boot. |
| 6773 | * |
| 6774 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6775 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6776 | * {@hide} |
| 6777 | */ |
| 6778 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6779 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6780 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6781 | null); |
| 6782 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6783 | final long identity = Binder.clearCallingIdentity(); |
| 6784 | try { |
| 6785 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6786 | // records the delta with the corresponding network identity. |
| 6787 | // We just return the total video call data usage snapshot since boot. |
| 6788 | Phone phone = getPhone(subId); |
| 6789 | if (phone != null) { |
| 6790 | return phone.getVtDataUsage(perUidStats); |
| 6791 | } |
| 6792 | return null; |
| 6793 | } finally { |
| 6794 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6795 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6796 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6797 | |
| 6798 | /** |
| 6799 | * Policy control of data connection. Usually used when data limit is passed. |
| 6800 | * @param enabled True if enabling the data, otherwise disabling. |
| 6801 | * @param subId Subscription index |
| 6802 | * {@hide} |
| 6803 | */ |
| 6804 | @Override |
| 6805 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6806 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6807 | |
| 6808 | final long identity = Binder.clearCallingIdentity(); |
| 6809 | try { |
| 6810 | Phone phone = getPhone(subId); |
| 6811 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6812 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6813 | } |
| 6814 | } finally { |
| 6815 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6816 | } |
| 6817 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6818 | |
| 6819 | /** |
| 6820 | * Get Client request stats |
| 6821 | * @return List of Client Request Stats |
| 6822 | * @hide |
| 6823 | */ |
| 6824 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6825 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 6826 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6827 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6828 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6829 | return null; |
| 6830 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6831 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6832 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6833 | final long identity = Binder.clearCallingIdentity(); |
| 6834 | try { |
| 6835 | if (phone != null) { |
| 6836 | return phone.getClientRequestStats(); |
| 6837 | } |
| 6838 | |
| 6839 | return null; |
| 6840 | } finally { |
| 6841 | Binder.restoreCallingIdentity(identity); |
| 6842 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6843 | } |
| 6844 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6845 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6846 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6847 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6848 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6849 | |
| 6850 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6851 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6852 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6853 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6854 | * @param state State of SIM (power down, power up, pass through) |
| 6855 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6856 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6857 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6858 | * |
| 6859 | **/ |
| 6860 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6861 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6862 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6863 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6864 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6865 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6866 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6867 | final long identity = Binder.clearCallingIdentity(); |
| 6868 | try { |
| 6869 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6870 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6871 | } |
| 6872 | } finally { |
| 6873 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6874 | } |
| 6875 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6876 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6877 | private boolean isUssdApiAllowed(int subId) { |
| 6878 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6879 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6880 | if (configManager == null) { |
| 6881 | return false; |
| 6882 | } |
| 6883 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6884 | if (pb == null) { |
| 6885 | return false; |
| 6886 | } |
| 6887 | return pb.getBoolean( |
| 6888 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6889 | } |
| 6890 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6891 | /** |
| 6892 | * Check if phone is in emergency callback mode |
| 6893 | * @return true if phone is in emergency callback mode |
| 6894 | * @param subId sub id |
| 6895 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6896 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6897 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6898 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6899 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6900 | |
| 6901 | final long identity = Binder.clearCallingIdentity(); |
| 6902 | try { |
| 6903 | if (phone != null) { |
| 6904 | return phone.isInEcm(); |
| 6905 | } else { |
| 6906 | return false; |
| 6907 | } |
| 6908 | } finally { |
| 6909 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6910 | } |
| 6911 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6912 | |
| 6913 | /** |
| 6914 | * Get the current signal strength information for the given subscription. |
| 6915 | * Because this information is not updated when the device is in a low power state |
| 6916 | * it should not be relied-upon to be current. |
| 6917 | * @param subId Subscription index |
| 6918 | * @return the most recent cached signal strength info from the modem |
| 6919 | */ |
| 6920 | @Override |
| 6921 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6922 | final long identity = Binder.clearCallingIdentity(); |
| 6923 | try { |
| 6924 | Phone p = getPhone(subId); |
| 6925 | if (p == null) { |
| 6926 | return null; |
| 6927 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6928 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6929 | return p.getSignalStrength(); |
| 6930 | } finally { |
| 6931 | Binder.restoreCallingIdentity(identity); |
| 6932 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6933 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6934 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6935 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6936 | * Get the current modem radio state for the given slot. |
| 6937 | * @param slotIndex slot index. |
| 6938 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6939 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6940 | * @return the current radio power state from the modem |
| 6941 | */ |
| 6942 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6943 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6944 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6945 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6946 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 6947 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6948 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6949 | } |
| 6950 | |
| 6951 | final long identity = Binder.clearCallingIdentity(); |
| 6952 | try { |
| 6953 | return phone.getRadioPowerState(); |
| 6954 | } finally { |
| 6955 | Binder.restoreCallingIdentity(identity); |
| 6956 | } |
| 6957 | } |
| 6958 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6959 | } |
| 6960 | |
| 6961 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6962 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6963 | * |
| 6964 | * <p>Requires one of the following permissions: |
| 6965 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6966 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6967 | * privileges. |
| 6968 | * |
| 6969 | * @param subId subscription id |
| 6970 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6971 | * {@code false}. |
| 6972 | */ |
| 6973 | @Override |
| 6974 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6975 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6976 | null /* message */); |
| 6977 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6978 | boolean isEnabled = false; |
| 6979 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6980 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6981 | Phone phone = getPhone(subId); |
| 6982 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6983 | } catch (Exception e) { |
| 6984 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6985 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6986 | } finally { |
| 6987 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6988 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6989 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6990 | } |
| 6991 | |
| 6992 | |
| 6993 | /** |
| 6994 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6995 | * |
| 6996 | * <p> Requires permission: |
| 6997 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6998 | * privileges. |
| 6999 | * |
| 7000 | * @param subId subscription id |
| 7001 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7002 | */ |
| 7003 | @Override |
| 7004 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7005 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7006 | mApp, subId, "setDataRoamingEnabled"); |
| 7007 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7008 | final long identity = Binder.clearCallingIdentity(); |
| 7009 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7010 | Phone phone = getPhone(subId); |
| 7011 | if (phone != null) { |
| 7012 | phone.setDataRoamingEnabled(isEnabled); |
| 7013 | } |
| 7014 | } finally { |
| 7015 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7016 | } |
| 7017 | } |
| 7018 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7019 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7020 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7021 | TelephonyPermissions |
| 7022 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7023 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7024 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7025 | boolean isAllowed = true; |
| 7026 | final long identity = Binder.clearCallingIdentity(); |
| 7027 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7028 | Phone phone = getPhone(subId); |
| 7029 | if (phone != null) { |
| 7030 | isAllowed = phone.isCspPlmnEnabled(); |
| 7031 | } |
| 7032 | } finally { |
| 7033 | Binder.restoreCallingIdentity(identity); |
| 7034 | } |
| 7035 | return isAllowed; |
| 7036 | } |
| 7037 | |
| 7038 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7039 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7040 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7041 | try { |
| 7042 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7043 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7044 | } catch (SecurityException e) { |
| 7045 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7046 | // has carrier privileges on an active UICC |
| 7047 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7048 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7049 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7050 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7051 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7052 | |
| 7053 | final long identity = Binder.clearCallingIdentity(); |
| 7054 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7055 | UiccController uiccController = UiccController.getInstance(); |
| 7056 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7057 | if (hasReadPermission) { |
| 7058 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7059 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7060 | |
| 7061 | // Remove private info if the caller doesn't have access |
| 7062 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7063 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7064 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7065 | // is available |
| 7066 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7067 | if (card == null || card.getUiccProfile() == null) { |
| 7068 | // assume no access if the card or profile is unavailable |
| 7069 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7070 | continue; |
| 7071 | } |
| 7072 | UiccProfile profile = card.getUiccProfile(); |
| 7073 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7074 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7075 | filteredInfos.add(cardInfo); |
| 7076 | } else { |
| 7077 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7078 | } |
| 7079 | } |
| 7080 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7081 | } finally { |
| 7082 | Binder.restoreCallingIdentity(identity); |
| 7083 | } |
| 7084 | } |
| 7085 | |
| 7086 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7087 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7088 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7089 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7090 | final long identity = Binder.clearCallingIdentity(); |
| 7091 | try { |
| 7092 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7093 | if (slots == null) { |
| 7094 | Rlog.i(LOG_TAG, "slots is null."); |
| 7095 | return null; |
| 7096 | } |
| 7097 | |
| 7098 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7099 | for (int i = 0; i < slots.length; i++) { |
| 7100 | UiccSlot slot = slots[i]; |
| 7101 | if (slot == null) { |
| 7102 | continue; |
| 7103 | } |
| 7104 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7105 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7106 | UiccCard card = slot.getUiccCard(); |
| 7107 | if (card != null) { |
| 7108 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7109 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7110 | cardId = slot.getEid(); |
| 7111 | if (TextUtils.isEmpty(cardId)) { |
| 7112 | cardId = slot.getIccId(); |
| 7113 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7114 | } |
| 7115 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7116 | if (cardId != null) { |
| 7117 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7118 | // if cardId is an EID, it's all digits so this is fine |
| 7119 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7120 | } |
| 7121 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7122 | int cardState = 0; |
| 7123 | switch (slot.getCardState()) { |
| 7124 | case CARDSTATE_ABSENT: |
| 7125 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7126 | break; |
| 7127 | case CARDSTATE_PRESENT: |
| 7128 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7129 | break; |
| 7130 | case CARDSTATE_ERROR: |
| 7131 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7132 | break; |
| 7133 | case CARDSTATE_RESTRICTED: |
| 7134 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7135 | break; |
| 7136 | default: |
| 7137 | break; |
| 7138 | |
| 7139 | } |
| 7140 | |
| 7141 | infos[i] = new UiccSlotInfo( |
| 7142 | slot.isActive(), |
| 7143 | slot.isEuicc(), |
| 7144 | cardId, |
| 7145 | cardState, |
| 7146 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7147 | slot.isExtendedApduSupported(), |
| 7148 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7149 | } |
| 7150 | return infos; |
| 7151 | } finally { |
| 7152 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7153 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7154 | } |
| 7155 | |
| 7156 | @Override |
| 7157 | public boolean switchSlots(int[] physicalSlots) { |
| 7158 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7159 | |
| 7160 | final long identity = Binder.clearCallingIdentity(); |
| 7161 | try { |
| 7162 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7163 | } finally { |
| 7164 | Binder.restoreCallingIdentity(identity); |
| 7165 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7166 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7167 | |
| 7168 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7169 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7170 | final long identity = Binder.clearCallingIdentity(); |
| 7171 | try { |
| 7172 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7173 | } finally { |
| 7174 | Binder.restoreCallingIdentity(identity); |
| 7175 | } |
| 7176 | } |
| 7177 | |
| 7178 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7179 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 7180 | enforceModifyPermission(); |
| 7181 | final Phone phone = getPhone(subId); |
| 7182 | if (phone == null) { |
| 7183 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 7184 | return; |
| 7185 | } |
| 7186 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7187 | final long identity = Binder.clearCallingIdentity(); |
| 7188 | try { |
| 7189 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 7190 | } finally { |
| 7191 | Binder.restoreCallingIdentity(identity); |
| 7192 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7193 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7194 | |
| 7195 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7196 | * A test API to reload the UICC profile. |
| 7197 | * |
| 7198 | * <p>Requires that the calling app has permission |
| 7199 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7200 | * @hide |
| 7201 | */ |
| 7202 | @Override |
| 7203 | public void refreshUiccProfile(int subId) { |
| 7204 | enforceModifyPermission(); |
| 7205 | |
| 7206 | final long identity = Binder.clearCallingIdentity(); |
| 7207 | try { |
| 7208 | Phone phone = getPhone(subId); |
| 7209 | if (phone == null) { |
| 7210 | return; |
| 7211 | } |
| 7212 | UiccCard uiccCard = phone.getUiccCard(); |
| 7213 | if (uiccCard == null) { |
| 7214 | return; |
| 7215 | } |
| 7216 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7217 | if (uiccProfile == null) { |
| 7218 | return; |
| 7219 | } |
| 7220 | uiccProfile.refresh(); |
| 7221 | } finally { |
| 7222 | Binder.restoreCallingIdentity(identity); |
| 7223 | } |
| 7224 | } |
| 7225 | |
| 7226 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7227 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7228 | */ |
| 7229 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7230 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7231 | } |
| 7232 | |
| 7233 | /** |
| 7234 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7235 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7236 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7237 | */ |
| 7238 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7239 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7240 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7241 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7242 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7243 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7244 | return isDataRoamingEnabled; |
| 7245 | } |
| 7246 | |
| 7247 | /** |
| 7248 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7249 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7250 | */ |
| 7251 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7252 | List<Integer> list = TelephonyProperties.default_network(); |
| 7253 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7254 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7255 | return list.get(phoneId); |
| 7256 | } |
| 7257 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7258 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7259 | |
| 7260 | @Override |
| 7261 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7262 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7263 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7264 | |
| 7265 | final long identity = Binder.clearCallingIdentity(); |
| 7266 | try { |
| 7267 | final Phone phone = getPhone(subId); |
| 7268 | if (phone == null) { |
| 7269 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7270 | return; |
| 7271 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7272 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7273 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7274 | } finally { |
| 7275 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7276 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7277 | } |
| 7278 | |
| 7279 | @Override |
| 7280 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7281 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7282 | |
| 7283 | final long identity = Binder.clearCallingIdentity(); |
| 7284 | try { |
| 7285 | final Phone phone = getPhone(subId); |
| 7286 | if (phone == null) { |
| 7287 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7288 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7289 | } |
| 7290 | return phone.getCarrierIdListVersion(); |
| 7291 | } finally { |
| 7292 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7293 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7294 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7295 | |
| 7296 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7297 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7298 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7299 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7300 | mApp, subId, callingPackage, callingFeatureId, |
| 7301 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7302 | return -1; |
| 7303 | } |
| 7304 | |
| 7305 | final long identity = Binder.clearCallingIdentity(); |
| 7306 | try { |
| 7307 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7308 | } finally { |
| 7309 | Binder.restoreCallingIdentity(identity); |
| 7310 | } |
| 7311 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7312 | |
| 7313 | @Override |
| 7314 | public int getCdmaRoamingMode(int subId) { |
| 7315 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7316 | mApp, subId, "getCdmaRoamingMode"); |
| 7317 | |
| 7318 | final long identity = Binder.clearCallingIdentity(); |
| 7319 | try { |
| 7320 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7321 | } finally { |
| 7322 | Binder.restoreCallingIdentity(identity); |
| 7323 | } |
| 7324 | } |
| 7325 | |
| 7326 | @Override |
| 7327 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7328 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7329 | mApp, subId, "setCdmaRoamingMode"); |
| 7330 | |
| 7331 | final long identity = Binder.clearCallingIdentity(); |
| 7332 | try { |
| 7333 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7334 | } finally { |
| 7335 | Binder.restoreCallingIdentity(identity); |
| 7336 | } |
| 7337 | } |
| 7338 | |
| 7339 | @Override |
| 7340 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7341 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7342 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7343 | |
| 7344 | final long identity = Binder.clearCallingIdentity(); |
| 7345 | try { |
| 7346 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7347 | } finally { |
| 7348 | Binder.restoreCallingIdentity(identity); |
| 7349 | } |
| 7350 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7351 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7352 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7353 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7354 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7355 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7356 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7357 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7358 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7359 | } |
| 7360 | final long identity = Binder.clearCallingIdentity(); |
| 7361 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7362 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7363 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7364 | if (phone.getEmergencyNumberTracker() != null |
| 7365 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7366 | emergencyNumberListInternal.put( |
| 7367 | phone.getSubId(), |
| 7368 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7369 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7370 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7371 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7372 | } finally { |
| 7373 | Binder.restoreCallingIdentity(identity); |
| 7374 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7375 | } |
| 7376 | |
| 7377 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7378 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7379 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7380 | if (!exactMatch) { |
| 7381 | TelephonyPermissions |
| 7382 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7383 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7384 | } |
| 7385 | final long identity = Binder.clearCallingIdentity(); |
| 7386 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7387 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7388 | if (phone.getEmergencyNumberTracker() != null |
| 7389 | && phone.getEmergencyNumberTracker() != null) { |
| 7390 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7391 | number, exactMatch)) { |
| 7392 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7393 | } |
| 7394 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7395 | } |
| 7396 | return false; |
| 7397 | } finally { |
| 7398 | Binder.restoreCallingIdentity(identity); |
| 7399 | } |
| 7400 | } |
| 7401 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7402 | /** |
| 7403 | * Update emergency number list for test mode. |
| 7404 | */ |
| 7405 | @Override |
| 7406 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7407 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7408 | "updateEmergencyNumberListTestMode"); |
| 7409 | |
| 7410 | final long identity = Binder.clearCallingIdentity(); |
| 7411 | try { |
| 7412 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7413 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7414 | if (tracker != null) { |
| 7415 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7416 | } |
| 7417 | } |
| 7418 | } finally { |
| 7419 | Binder.restoreCallingIdentity(identity); |
| 7420 | } |
| 7421 | } |
| 7422 | |
| 7423 | /** |
| 7424 | * Get the full emergency number list for test mode. |
| 7425 | */ |
| 7426 | @Override |
| 7427 | public List<String> getEmergencyNumberListTestMode() { |
| 7428 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7429 | "getEmergencyNumberListTestMode"); |
| 7430 | |
| 7431 | final long identity = Binder.clearCallingIdentity(); |
| 7432 | try { |
| 7433 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7434 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7435 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7436 | if (tracker != null) { |
| 7437 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7438 | emergencyNumbers.add(num.getNumber()); |
| 7439 | } |
| 7440 | } |
| 7441 | } |
| 7442 | return new ArrayList<>(emergencyNumbers); |
| 7443 | } finally { |
| 7444 | Binder.restoreCallingIdentity(identity); |
| 7445 | } |
| 7446 | } |
| 7447 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7448 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7449 | public int getEmergencyNumberDbVersion(int subId) { |
| 7450 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7451 | |
| 7452 | final long identity = Binder.clearCallingIdentity(); |
| 7453 | try { |
| 7454 | final Phone phone = getPhone(subId); |
| 7455 | if (phone == null) { |
| 7456 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7457 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7458 | } |
| 7459 | return phone.getEmergencyNumberDbVersion(); |
| 7460 | } finally { |
| 7461 | Binder.restoreCallingIdentity(identity); |
| 7462 | } |
| 7463 | } |
| 7464 | |
| 7465 | @Override |
| 7466 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7467 | enforceModifyPermission(); |
| 7468 | |
| 7469 | final long identity = Binder.clearCallingIdentity(); |
| 7470 | try { |
| 7471 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7472 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7473 | if (tracker != null) { |
| 7474 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7475 | } |
| 7476 | } |
| 7477 | } finally { |
| 7478 | Binder.restoreCallingIdentity(identity); |
| 7479 | } |
| 7480 | } |
| 7481 | |
| 7482 | @Override |
| 7483 | public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) { |
| 7484 | enforceActiveEmergencySessionPermission(); |
| 7485 | |
| 7486 | final long identity = Binder.clearCallingIdentity(); |
| 7487 | try { |
| 7488 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7489 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7490 | if (tracker != null) { |
| 7491 | tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath); |
| 7492 | } |
| 7493 | } |
| 7494 | } finally { |
| 7495 | Binder.restoreCallingIdentity(identity); |
| 7496 | } |
| 7497 | } |
| 7498 | |
| 7499 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7500 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7501 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7502 | Phone phone = getPhone(subId); |
| 7503 | if (phone == null) { |
| 7504 | return null; |
| 7505 | } |
| 7506 | final long identity = Binder.clearCallingIdentity(); |
| 7507 | try { |
| 7508 | UiccProfile profile = UiccController.getInstance() |
| 7509 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7510 | if (profile != null) { |
| 7511 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7512 | } |
| 7513 | } finally { |
| 7514 | Binder.restoreCallingIdentity(identity); |
| 7515 | } |
| 7516 | return null; |
| 7517 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7518 | |
| 7519 | /** |
| 7520 | * Enable or disable a modem stack. |
| 7521 | */ |
| 7522 | @Override |
| 7523 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7524 | enforceModifyPermission(); |
| 7525 | |
| 7526 | final long identity = Binder.clearCallingIdentity(); |
| 7527 | try { |
| 7528 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7529 | if (phone == null) { |
| 7530 | return false; |
| 7531 | } else { |
| 7532 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7533 | } |
| 7534 | } finally { |
| 7535 | Binder.restoreCallingIdentity(identity); |
| 7536 | } |
| 7537 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7538 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7539 | /** |
| 7540 | * Whether a modem stack is enabled or not. |
| 7541 | */ |
| 7542 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7543 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7544 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7545 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7546 | if (phone == null) return false; |
| 7547 | |
| 7548 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7549 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7550 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7551 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7552 | } |
| 7553 | |
| 7554 | final long identity = Binder.clearCallingIdentity(); |
| 7555 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7556 | try { |
| 7557 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7558 | } catch (NoSuchElementException ex) { |
| 7559 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7560 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7561 | } finally { |
| 7562 | Binder.restoreCallingIdentity(identity); |
| 7563 | } |
| 7564 | } |
| 7565 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7566 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7567 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7568 | enforceModifyPermission(); |
| 7569 | |
| 7570 | final long identity = Binder.clearCallingIdentity(); |
| 7571 | try { |
| 7572 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7573 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7574 | .commit(); |
| 7575 | } finally { |
| 7576 | Binder.restoreCallingIdentity(identity); |
| 7577 | } |
| 7578 | } |
| 7579 | |
| 7580 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7581 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7582 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7583 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7584 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 7585 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7586 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7587 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7588 | |
| 7589 | final long identity = Binder.clearCallingIdentity(); |
| 7590 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7591 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7592 | } finally { |
| 7593 | Binder.restoreCallingIdentity(identity); |
| 7594 | } |
| 7595 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7596 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7597 | @TelephonyManager.IsMultiSimSupportedResult |
| 7598 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7599 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7600 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7601 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7602 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7603 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7604 | } |
| 7605 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7606 | // supported by the modem, indicate that it is restricted. |
| 7607 | PhoneCapability staticCapability = |
| 7608 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7609 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7610 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7611 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7612 | } |
| 7613 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7614 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7615 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7616 | } |
| 7617 | // Check if support of multiple SIMs is restricted by carrier |
| 7618 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7619 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7620 | } |
| 7621 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7622 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7623 | } |
| 7624 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7625 | /** |
| 7626 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7627 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7628 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7629 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7630 | * @param numOfSims number of active sims we want to switch to |
| 7631 | */ |
| 7632 | @Override |
| 7633 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7634 | if (numOfSims == 1) { |
| 7635 | enforceModifyPermission(); |
| 7636 | } else { |
| 7637 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7638 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7639 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7640 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7641 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7642 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7643 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7644 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7645 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7646 | return; |
| 7647 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7648 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7649 | } finally { |
| 7650 | Binder.restoreCallingIdentity(identity); |
| 7651 | } |
| 7652 | } |
| 7653 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 7654 | @Override |
| 7655 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 7656 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 7657 | Phone phone = getPhone(subId); |
| 7658 | if (phone == null) { |
| 7659 | return false; |
| 7660 | } |
| 7661 | final long identity = Binder.clearCallingIdentity(); |
| 7662 | try { |
| 7663 | UiccCard uiccCard = phone.getUiccCard(); |
| 7664 | if (uiccCard == null) { |
| 7665 | return false; |
| 7666 | } |
| 7667 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7668 | if (uiccProfile == null) { |
| 7669 | return false; |
| 7670 | } |
| 7671 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 7672 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 7673 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 7674 | } |
| 7675 | return false; |
| 7676 | } finally { |
| 7677 | Binder.restoreCallingIdentity(identity); |
| 7678 | } |
| 7679 | } |
| 7680 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7681 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7682 | * Get whether making changes to modem configurations will trigger reboot. |
| 7683 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7684 | */ |
| 7685 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7686 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 7687 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7688 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7689 | mApp, subId, callingPackage, callingFeatureId, |
| 7690 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7691 | return false; |
| 7692 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7693 | final long identity = Binder.clearCallingIdentity(); |
| 7694 | try { |
| 7695 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 7696 | } finally { |
| 7697 | Binder.restoreCallingIdentity(identity); |
| 7698 | } |
| 7699 | } |
| 7700 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 7701 | private void updateModemStateMetrics() { |
| 7702 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 7703 | // TODO: check the state for each modem if the api is ready. |
| 7704 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 7705 | } |
| 7706 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 7707 | @Override |
| 7708 | public int[] getSlotsMapping() { |
| 7709 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 7710 | |
| 7711 | final long identity = Binder.clearCallingIdentity(); |
| 7712 | try { |
| 7713 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 7714 | // All logical slots should have a mapping to a physical slot. |
| 7715 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 7716 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 7717 | for (int i = 0; i < slotInfos.length; i++) { |
| 7718 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 7719 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 7720 | } |
| 7721 | } |
| 7722 | return logicalSlotsMapping; |
| 7723 | } finally { |
| 7724 | Binder.restoreCallingIdentity(identity); |
| 7725 | } |
| 7726 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7727 | |
| 7728 | /** |
| 7729 | * Get the IRadio HAL Version |
| 7730 | */ |
| 7731 | @Override |
| 7732 | public int getRadioHalVersion() { |
| 7733 | Phone phone = getDefaultPhone(); |
| 7734 | if (phone == null) return -1; |
| 7735 | HalVersion hv = phone.getHalVersion(); |
| 7736 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7737 | return hv.major * 100 + hv.minor; |
| 7738 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7739 | |
| 7740 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7741 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7742 | * corresponding network requests on a subId. |
| 7743 | * |
| 7744 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7745 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7746 | * 2) APN is un-metered for this subscription, or |
| 7747 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
| 7748 | * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. |
| 7749 | * |
| 7750 | * @return whether data is allowed for a apn type. |
| 7751 | * |
| 7752 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7753 | */ |
| 7754 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7755 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 7756 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 7757 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7758 | |
| 7759 | // Now that all security checks passes, perform the operation as ourselves. |
| 7760 | final long identity = Binder.clearCallingIdentity(); |
| 7761 | try { |
| 7762 | Phone phone = getPhone(subId); |
| 7763 | if (phone == null) return false; |
| 7764 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7765 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7766 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7767 | } finally { |
| 7768 | Binder.restoreCallingIdentity(identity); |
| 7769 | } |
| 7770 | } |
| 7771 | |
| 7772 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7773 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7774 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7775 | |
| 7776 | // Now that all security checks passes, perform the operation as ourselves. |
| 7777 | final long identity = Binder.clearCallingIdentity(); |
| 7778 | try { |
| 7779 | Phone phone = getPhone(subId); |
| 7780 | if (phone == null) return true; // By default return true. |
| 7781 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7782 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7783 | } finally { |
| 7784 | Binder.restoreCallingIdentity(identity); |
| 7785 | } |
| 7786 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7787 | |
| 7788 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 7789 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
| 7790 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 7791 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 7792 | if (iccRecords == null) { |
| 7793 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 7794 | return false; |
| 7795 | } |
| 7796 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 7797 | } |
| 7798 | |
| 7799 | @Override |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7800 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
| 7801 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 7802 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 7803 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 7804 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 7805 | } |
| 7806 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 7807 | Intent intent = new Intent(); |
| 7808 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 7809 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 7810 | // Bring up choose default SMS subscription dialog right now |
| 7811 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 7812 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 7813 | mApp.startActivity(intent); |
| 7814 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 7815 | |
| 7816 | @Override |
| 7817 | public String getMmsUAProfUrl(int subId) { |
| 7818 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7819 | final long identity = Binder.clearCallingIdentity(); |
| 7820 | try { |
| 7821 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7822 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 7823 | } finally { |
| 7824 | Binder.restoreCallingIdentity(identity); |
| 7825 | } |
| 7826 | } |
| 7827 | |
| 7828 | @Override |
| 7829 | public String getMmsUserAgent(int subId) { |
| 7830 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7831 | final long identity = Binder.clearCallingIdentity(); |
| 7832 | try { |
| 7833 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7834 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 7835 | } finally { |
| 7836 | Binder.restoreCallingIdentity(identity); |
| 7837 | } |
| 7838 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 7839 | |
| 7840 | @Override |
| 7841 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 7842 | enforceModifyPermission(); |
| 7843 | |
| 7844 | // Now that all security checks passes, perform the operation as ourselves. |
| 7845 | final long identity = Binder.clearCallingIdentity(); |
| 7846 | try { |
| 7847 | Phone phone = getPhone(subId); |
| 7848 | if (phone == null) return false; |
| 7849 | |
| 7850 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 7851 | } finally { |
| 7852 | Binder.restoreCallingIdentity(identity); |
| 7853 | } |
| 7854 | } |
| 7855 | |
| 7856 | @Override |
| 7857 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 7858 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 7859 | |
| 7860 | // Now that all security checks passes, perform the operation as ourselves. |
| 7861 | final long identity = Binder.clearCallingIdentity(); |
| 7862 | try { |
| 7863 | Phone phone = getPhone(subId); |
| 7864 | if (phone == null) return false; |
| 7865 | |
| 7866 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 7867 | } finally { |
| 7868 | Binder.restoreCallingIdentity(identity); |
| 7869 | } |
| 7870 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 7871 | |
| 7872 | /** |
| 7873 | * Updates whether conference event pacakge handling is enabled. |
| 7874 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 7875 | * otherwise. |
| 7876 | */ |
| 7877 | @Override |
| 7878 | public void setCepEnabled(boolean isCepEnabled) { |
| 7879 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 7880 | |
| 7881 | final long identity = Binder.clearCallingIdentity(); |
| 7882 | try { |
| 7883 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 7884 | for (Phone phone : PhoneFactory.getPhones()) { |
| 7885 | Phone defaultPhone = phone.getImsPhone(); |
| 7886 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7887 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7888 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 7889 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 7890 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 7891 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 7892 | + imsPhone.getMsisdn()); |
| 7893 | } |
| 7894 | } |
| 7895 | } finally { |
| 7896 | Binder.restoreCallingIdentity(identity); |
| 7897 | } |
| 7898 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 7899 | |
| 7900 | /** |
| 7901 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 7902 | * |
| 7903 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 7904 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 7905 | * before being read. |
| 7906 | */ |
| 7907 | @Override |
| 7908 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 7909 | isCompressed) { |
| 7910 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7911 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 7912 | try { |
| 7913 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 7914 | if (configBinder == null) { |
| 7915 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 7916 | } else { |
| 7917 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 7918 | } |
| 7919 | } catch (RemoteException e) { |
| 7920 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 7921 | } |
| 7922 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 7923 | } |