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; |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 51 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 53 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | import android.os.ServiceManager; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 55 | import android.os.ServiceSpecificException; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 56 | import android.os.ShellCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 58 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 59 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 60 | import android.preference.PreferenceManager; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 61 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 62 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 63 | import android.provider.Telephony; |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 64 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 65 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 66 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 67 | import android.telecom.TelecomManager; |
Chen Xu | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 68 | import android.telephony.Annotation.ApnType; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 69 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 70 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 71 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 72 | import android.telephony.CellIdentity; |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 73 | import android.telephony.CellIdentityCdma; |
| 74 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 76 | import android.telephony.CellInfoGsm; |
| 77 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 78 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 79 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 80 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 81 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 82 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 83 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 84 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 85 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 86 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 87 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 88 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 89 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 90 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 91 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 92 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 93 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 94 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 95 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 96 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 97 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 98 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 99 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 100 | import android.telephony.data.ApnSetting; |
| 101 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 102 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 103 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 104 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 108 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 109 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 110 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 111 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 112 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 113 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 114 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 115 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 116 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 117 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 118 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 119 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 120 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 121 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 122 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 123 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 124 | import com.android.ims.internal.IImsServiceFeatureCallback; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 125 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 129 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.HalVersion; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 160 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 171 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 172 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 174 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 175 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 176 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 177 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 178 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 179 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 180 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 181 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 182 | import java.io.FileDescriptor; |
| 183 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 184 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 185 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 186 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 187 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 188 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 189 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 190 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 191 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 192 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 193 | |
| 194 | /** |
| 195 | * Implementation of the ITelephony interface. |
| 196 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 197 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 198 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 199 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 200 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 201 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 202 | |
| 203 | // Message codes used with mMainThreadHandler |
| 204 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 205 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 206 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 207 | private static final int CMD_OPEN_CHANNEL = 9; |
| 208 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 209 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 210 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 211 | private static final int CMD_NV_READ_ITEM = 13; |
| 212 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 213 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 214 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 215 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 216 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 217 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 218 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 219 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 220 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 221 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 222 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 223 | private static final int CMD_SEND_ENVELOPE = 25; |
| 224 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 225 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 226 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 227 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 228 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 229 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 230 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 231 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 232 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 233 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 234 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 235 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 236 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 237 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 238 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 239 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 240 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 241 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 242 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 243 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 244 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 245 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 246 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 247 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 248 | private static final int CMD_SWITCH_SLOTS = 50; |
| 249 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 250 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 251 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 252 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 253 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 254 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 255 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 256 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 257 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 258 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 259 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 260 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 261 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 262 | private static final int CMD_MODEM_REBOOT = 64; |
| 263 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 264 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 265 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 266 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 267 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 268 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 269 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 270 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 271 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 272 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 273 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 274 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 275 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 276 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 277 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 278 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 279 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 280 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 281 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 282 | private static final int CMD_GET_CALL_WAITING = 87; |
| 283 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 284 | private static final int CMD_SET_CALL_WAITING = 89; |
| 285 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 286 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 287 | // Parameters of select command. |
| 288 | private static final int SELECT_COMMAND = 0xA4; |
| 289 | private static final int SELECT_P1 = 0x04; |
| 290 | private static final int SELECT_P2 = 0; |
| 291 | private static final int SELECT_P3 = 0x10; |
| 292 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 293 | /** The singleton instance. */ |
| 294 | private static PhoneInterfaceManager sInstance; |
| 295 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 296 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 297 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 298 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 299 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 300 | private AppOpsManager mAppOps; |
| 301 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 302 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 303 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 304 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 305 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 306 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 307 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 308 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 309 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 310 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 311 | // String to store multi SIM allowed |
| 312 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 313 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 314 | // The AID of ISD-R. |
| 315 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 316 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 317 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 318 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 319 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 320 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 321 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 322 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 323 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 324 | */ |
| 325 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 326 | "reset_network_erase_modem_config_enabled"; |
| 327 | |
| 328 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 329 | * A request object to use for transmitting data to an ICC. |
| 330 | */ |
| 331 | private static final class IccAPDUArgument { |
| 332 | public int channel, cla, command, p1, p2, p3; |
| 333 | public String data; |
| 334 | |
| 335 | public IccAPDUArgument(int channel, int cla, int command, |
| 336 | int p1, int p2, int p3, String data) { |
| 337 | this.channel = channel; |
| 338 | this.cla = cla; |
| 339 | this.command = command; |
| 340 | this.p1 = p1; |
| 341 | this.p2 = p2; |
| 342 | this.p3 = p3; |
| 343 | this.data = data; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 348 | * A request object to use for transmitting data to an ICC. |
| 349 | */ |
| 350 | private static final class ManualNetworkSelectionArgument { |
| 351 | public OperatorInfo operatorInfo; |
| 352 | public boolean persistSelection; |
| 353 | |
| 354 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 355 | this.operatorInfo = operatorInfo; |
| 356 | this.persistSelection = persistSelection; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 361 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 362 | * request after sending. The main thread will notify the request when it is complete. |
| 363 | */ |
| 364 | private static final class MainThreadRequest { |
| 365 | /** The argument to use for the request */ |
| 366 | public Object argument; |
| 367 | /** The result of the request that is run on the main thread */ |
| 368 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 369 | // The subscriber id that this request applies to. Defaults to |
| 370 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 371 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 372 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 373 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 374 | public Phone phone; |
| 375 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 376 | public WorkSource workSource; |
| 377 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 378 | public MainThreadRequest(Object argument) { |
| 379 | this.argument = argument; |
| 380 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 381 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 382 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 383 | this.argument = argument; |
| 384 | if (phone != null) { |
| 385 | this.phone = phone; |
| 386 | } |
| 387 | this.workSource = workSource; |
| 388 | } |
| 389 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 390 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 391 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 392 | if (subId != null) { |
| 393 | this.subId = subId; |
| 394 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 395 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 396 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 399 | private static final class IncomingThirdPartyCallArgs { |
| 400 | public final ComponentName component; |
| 401 | public final String callId; |
| 402 | public final String callerDisplayName; |
| 403 | |
| 404 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 405 | String callerDisplayName) { |
| 406 | this.component = component; |
| 407 | this.callId = callId; |
| 408 | this.callerDisplayName = callerDisplayName; |
| 409 | } |
| 410 | } |
| 411 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 412 | /** |
| 413 | * A handler that processes messages on the main thread in the phone process. Since many |
| 414 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 415 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 416 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 417 | * on, which will be notified when the operation completes and will contain the result of the |
| 418 | * request. |
| 419 | * |
| 420 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 421 | * note that request.result must be set to something non-null for the calling thread to |
| 422 | * unblock. |
| 423 | */ |
| 424 | private final class MainThreadHandler extends Handler { |
| 425 | @Override |
| 426 | public void handleMessage(Message msg) { |
| 427 | MainThreadRequest request; |
| 428 | Message onCompleted; |
| 429 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 430 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 431 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 432 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 433 | |
| 434 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 435 | case CMD_HANDLE_USSD_REQUEST: { |
| 436 | request = (MainThreadRequest) msg.obj; |
| 437 | final Phone phone = getPhoneFromRequest(request); |
| 438 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 439 | String ussdRequest = ussdObject.first; |
| 440 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 441 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 442 | if (!isUssdApiAllowed(request.subId)) { |
| 443 | // Carrier does not support use of this API, return failure. |
| 444 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 445 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 446 | Bundle returnData = new Bundle(); |
| 447 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 448 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 449 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 450 | request.result = true; |
| 451 | notifyRequester(request); |
| 452 | return; |
| 453 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 454 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 455 | try { |
| 456 | request.result = phone != null |
| 457 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 458 | } catch (CallStateException cse) { |
| 459 | request.result = false; |
| 460 | } |
| 461 | // Wake up the requesting thread |
| 462 | notifyRequester(request); |
| 463 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 466 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 467 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 468 | final Phone phone = getPhoneFromRequest(request); |
| 469 | request.result = phone != null ? |
| 470 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 471 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 472 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 473 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 474 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 475 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 476 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 477 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 478 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 479 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 480 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 481 | if (uiccCard == null) { |
| 482 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 483 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 484 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 485 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 486 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 487 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 488 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 489 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 490 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 491 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 492 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 493 | break; |
| 494 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 495 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 496 | ar = (AsyncResult) msg.obj; |
| 497 | request = (MainThreadRequest) ar.userObj; |
| 498 | if (ar.exception == null && ar.result != null) { |
| 499 | request.result = ar.result; |
| 500 | } else { |
| 501 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 502 | if (ar.result == null) { |
| 503 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 504 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 505 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 506 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 507 | } else { |
| 508 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 509 | } |
| 510 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 511 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 512 | break; |
| 513 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 514 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 515 | request = (MainThreadRequest) msg.obj; |
| 516 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 517 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 518 | if (uiccCard == null) { |
| 519 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 520 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 521 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 522 | } else { |
| 523 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 524 | request); |
| 525 | uiccCard.iccTransmitApduBasicChannel( |
| 526 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 527 | iccArgument.p3, iccArgument.data, onCompleted); |
| 528 | } |
| 529 | break; |
| 530 | |
| 531 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 532 | ar = (AsyncResult) msg.obj; |
| 533 | request = (MainThreadRequest) ar.userObj; |
| 534 | if (ar.exception == null && ar.result != null) { |
| 535 | request.result = ar.result; |
| 536 | } else { |
| 537 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 538 | if (ar.result == null) { |
| 539 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 540 | } else if (ar.exception instanceof CommandException) { |
| 541 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 542 | ar.exception); |
| 543 | } else { |
| 544 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 545 | } |
| 546 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 547 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 548 | break; |
| 549 | |
| 550 | case CMD_EXCHANGE_SIM_IO: |
| 551 | request = (MainThreadRequest) msg.obj; |
| 552 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 553 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 554 | if (uiccCard == null) { |
| 555 | loge("iccExchangeSimIO: No UICC"); |
| 556 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 557 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 558 | } else { |
| 559 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 560 | request); |
| 561 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 562 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 563 | iccArgument.data, onCompleted); |
| 564 | } |
| 565 | break; |
| 566 | |
| 567 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 568 | ar = (AsyncResult) msg.obj; |
| 569 | request = (MainThreadRequest) ar.userObj; |
| 570 | if (ar.exception == null && ar.result != null) { |
| 571 | request.result = ar.result; |
| 572 | } else { |
| 573 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 574 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 575 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 576 | break; |
| 577 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 578 | case CMD_SEND_ENVELOPE: |
| 579 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 580 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 581 | if (uiccCard == null) { |
| 582 | loge("sendEnvelopeWithStatus: No UICC"); |
| 583 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 584 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 585 | } else { |
| 586 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 587 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 588 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 589 | break; |
| 590 | |
| 591 | case EVENT_SEND_ENVELOPE_DONE: |
| 592 | ar = (AsyncResult) msg.obj; |
| 593 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 594 | if (ar.exception == null && ar.result != null) { |
| 595 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 596 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 597 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 598 | if (ar.result == null) { |
| 599 | loge("sendEnvelopeWithStatus: Empty response"); |
| 600 | } else if (ar.exception instanceof CommandException) { |
| 601 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 602 | ar.exception); |
| 603 | } else { |
| 604 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 605 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 606 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 607 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 608 | break; |
| 609 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 610 | case CMD_OPEN_CHANNEL: |
| 611 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 612 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 613 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 614 | if (uiccCard == null) { |
| 615 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 616 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 617 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 618 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 619 | } else { |
| 620 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 621 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 622 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 623 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 624 | break; |
| 625 | |
| 626 | case EVENT_OPEN_CHANNEL_DONE: |
| 627 | ar = (AsyncResult) msg.obj; |
| 628 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 629 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 630 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 631 | int[] result = (int[]) ar.result; |
| 632 | int channelId = result[0]; |
| 633 | byte[] selectResponse = null; |
| 634 | if (result.length > 1) { |
| 635 | selectResponse = new byte[result.length - 1]; |
| 636 | for (int i = 1; i < result.length; ++i) { |
| 637 | selectResponse[i - 1] = (byte) result[i]; |
| 638 | } |
| 639 | } |
| 640 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 641 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 642 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 643 | if (ar.result == null) { |
| 644 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 645 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 646 | if (ar.exception != null) { |
| 647 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 648 | } |
| 649 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 650 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 651 | if (ar.exception instanceof CommandException) { |
| 652 | CommandException.Error error = |
| 653 | ((CommandException) (ar.exception)).getCommandError(); |
| 654 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 655 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 656 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 657 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 661 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 662 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 663 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 664 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 665 | break; |
| 666 | |
| 667 | case CMD_CLOSE_CHANNEL: |
| 668 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 669 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 670 | if (uiccCard == null) { |
| 671 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 672 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 673 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 674 | } else { |
| 675 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 676 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 677 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 678 | break; |
| 679 | |
| 680 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 681 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 682 | break; |
| 683 | |
| 684 | case CMD_NV_READ_ITEM: |
| 685 | request = (MainThreadRequest) msg.obj; |
| 686 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 687 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 688 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 689 | break; |
| 690 | |
| 691 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 692 | ar = (AsyncResult) msg.obj; |
| 693 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 694 | if (ar.exception == null && ar.result != null) { |
| 695 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 696 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 697 | request.result = ""; |
| 698 | if (ar.result == null) { |
| 699 | loge("nvReadItem: Empty response"); |
| 700 | } else if (ar.exception instanceof CommandException) { |
| 701 | loge("nvReadItem: CommandException: " + |
| 702 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 703 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 704 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 705 | } |
| 706 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 707 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 708 | break; |
| 709 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 710 | case CMD_NV_WRITE_ITEM: |
| 711 | request = (MainThreadRequest) msg.obj; |
| 712 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 713 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 714 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 715 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 716 | break; |
| 717 | |
| 718 | case EVENT_NV_WRITE_ITEM_DONE: |
| 719 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 720 | break; |
| 721 | |
| 722 | case CMD_NV_WRITE_CDMA_PRL: |
| 723 | request = (MainThreadRequest) msg.obj; |
| 724 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 725 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 726 | break; |
| 727 | |
| 728 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 729 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 730 | break; |
| 731 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 732 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 733 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 734 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 735 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 736 | break; |
| 737 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 738 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 739 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 740 | break; |
| 741 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 742 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 743 | request = (MainThreadRequest) msg.obj; |
| 744 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 745 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 746 | break; |
| 747 | |
| 748 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 749 | ar = (AsyncResult) msg.obj; |
| 750 | request = (MainThreadRequest) ar.userObj; |
| 751 | if (ar.exception == null && ar.result != null) { |
| 752 | request.result = ar.result; // Integer |
| 753 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 754 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 755 | if (ar.result == null) { |
| 756 | loge("getPreferredNetworkType: Empty response"); |
| 757 | } else if (ar.exception instanceof CommandException) { |
| 758 | loge("getPreferredNetworkType: CommandException: " + |
| 759 | ar.exception); |
| 760 | } else { |
| 761 | loge("getPreferredNetworkType: Unknown exception"); |
| 762 | } |
| 763 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 764 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 765 | break; |
| 766 | |
| 767 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 768 | request = (MainThreadRequest) msg.obj; |
| 769 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 770 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 771 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 772 | break; |
| 773 | |
| 774 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 775 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 776 | break; |
| 777 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 778 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 779 | request = (MainThreadRequest)msg.obj; |
| 780 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 781 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 782 | break; |
| 783 | |
| 784 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 785 | ar = (AsyncResult)msg.obj; |
| 786 | request = (MainThreadRequest)ar.userObj; |
| 787 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 788 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 789 | break; |
| 790 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 791 | case CMD_SET_VOICEMAIL_NUMBER: |
| 792 | request = (MainThreadRequest) msg.obj; |
| 793 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 794 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 795 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 796 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 797 | break; |
| 798 | |
| 799 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 800 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 801 | break; |
| 802 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 803 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 804 | request = (MainThreadRequest) msg.obj; |
| 805 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 806 | request); |
| 807 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 808 | break; |
| 809 | |
| 810 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 811 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 812 | break; |
| 813 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 814 | case CMD_PERFORM_NETWORK_SCAN: |
| 815 | request = (MainThreadRequest) msg.obj; |
| 816 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 817 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 818 | break; |
| 819 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 820 | case CMD_GET_CALL_FORWARDING: |
| 821 | request = (MainThreadRequest) msg.obj; |
| 822 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
| 823 | int callForwardingReason = (Integer) request.argument; |
| 824 | getPhoneFromRequest(request).getCallForwardingOption( |
| 825 | callForwardingReason, onCompleted); |
| 826 | break; |
| 827 | |
| 828 | case EVENT_GET_CALL_FORWARDING_DONE: |
| 829 | ar = (AsyncResult) msg.obj; |
| 830 | request = (MainThreadRequest) ar.userObj; |
| 831 | CallForwardingInfo callForwardingInfo = null; |
| 832 | if (ar.exception == null && ar.result != null) { |
| 833 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 834 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 835 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 836 | // any service for voice call. |
| 837 | if ((callForwardInfo.serviceClass |
| 838 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
| 839 | callForwardingInfo = new CallForwardingInfo( |
| 840 | callForwardInfo.serviceClass, callForwardInfo.reason, |
| 841 | callForwardInfo.number, |
| 842 | callForwardInfo.timeSeconds); |
| 843 | break; |
| 844 | } |
| 845 | } |
| 846 | // Didn't find a call forward info for voice call. |
| 847 | if (callForwardingInfo == null) { |
| 848 | callForwardingInfo = new CallForwardingInfo( |
| 849 | CallForwardingInfo.STATUS_UNKNOWN_ERROR, |
| 850 | 0 /* reason */, null /* number */, 0 /* timeout */); |
| 851 | } |
| 852 | } else { |
| 853 | if (ar.result == null) { |
| 854 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 855 | } |
| 856 | if (ar.exception != null) { |
| 857 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 858 | } |
| 859 | int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR; |
| 860 | if (ar.exception instanceof CommandException) { |
| 861 | CommandException.Error error = |
| 862 | ((CommandException) (ar.exception)).getCommandError(); |
| 863 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 864 | errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE; |
| 865 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 866 | errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED; |
| 867 | } |
| 868 | } |
| 869 | callForwardingInfo = new CallForwardingInfo( |
| 870 | errorCode, 0 /* reason */, null /* number */, 0 /* timeout */); |
| 871 | } |
| 872 | request.result = callForwardingInfo; |
| 873 | notifyRequester(request); |
| 874 | break; |
| 875 | |
| 876 | case CMD_SET_CALL_FORWARDING: |
| 877 | request = (MainThreadRequest) msg.obj; |
| 878 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
| 879 | CallForwardingInfo callForwardingInfoToSet = |
| 880 | (CallForwardingInfo) request.argument; |
| 881 | getPhoneFromRequest(request).setCallForwardingOption( |
| 882 | callForwardingInfoToSet.getStatus(), |
| 883 | callForwardingInfoToSet.getReason(), |
| 884 | callForwardingInfoToSet.getNumber(), |
| 885 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 886 | break; |
| 887 | |
| 888 | case EVENT_SET_CALL_FORWARDING_DONE: |
| 889 | ar = (AsyncResult) msg.obj; |
| 890 | request = (MainThreadRequest) ar.userObj; |
| 891 | if (ar.exception == null) { |
| 892 | request.result = true; |
| 893 | } else { |
| 894 | request.result = false; |
| 895 | loge("setCallForwarding exception: " + ar.exception); |
| 896 | } |
| 897 | notifyRequester(request); |
| 898 | break; |
| 899 | |
| 900 | case CMD_GET_CALL_WAITING: |
| 901 | request = (MainThreadRequest) msg.obj; |
| 902 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 903 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 904 | break; |
| 905 | |
| 906 | case EVENT_GET_CALL_WAITING_DONE: |
| 907 | ar = (AsyncResult) msg.obj; |
| 908 | request = (MainThreadRequest) ar.userObj; |
| 909 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 910 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame^] | 911 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 912 | // Service Class is a bit mask per 3gpp 27.007. |
| 913 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame^] | 914 | if (callForwardResults.length > 1 |
| 915 | && ((callForwardResults[1] |
| 916 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
| 917 | callForwardingStatus = callForwardResults[0] == 0 |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 918 | ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE |
| 919 | : TelephonyManager.CALL_WAITING_STATUS_ACTIVE; |
| 920 | } else { |
| 921 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE; |
| 922 | } |
| 923 | } else { |
| 924 | if (ar.result == null) { |
| 925 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 926 | } |
| 927 | if (ar.exception != null) { |
| 928 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 929 | } |
| 930 | if (ar.exception instanceof CommandException) { |
| 931 | CommandException.Error error = |
| 932 | ((CommandException) (ar.exception)).getCommandError(); |
| 933 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 934 | callForwardingStatus = |
| 935 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 936 | } |
| 937 | } |
| 938 | } |
| 939 | request.result = callForwardingStatus; |
| 940 | notifyRequester(request); |
| 941 | break; |
| 942 | |
| 943 | case CMD_SET_CALL_WAITING: |
| 944 | request = (MainThreadRequest) msg.obj; |
| 945 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
| 946 | boolean isEnable = (Boolean) request.argument; |
| 947 | getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted); |
| 948 | break; |
| 949 | |
| 950 | case EVENT_SET_CALL_WAITING_DONE: |
| 951 | ar = (AsyncResult) msg.obj; |
| 952 | request = (MainThreadRequest) ar.userObj; |
| 953 | if (ar.exception == null) { |
| 954 | request.result = true; |
| 955 | } else { |
| 956 | request.result = false; |
| 957 | loge("setCallWaiting exception: " + ar.exception); |
| 958 | } |
| 959 | notifyRequester(request); |
| 960 | break; |
| 961 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 962 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 963 | ar = (AsyncResult) msg.obj; |
| 964 | request = (MainThreadRequest) ar.userObj; |
| 965 | CellNetworkScanResult cellScanResult; |
| 966 | if (ar.exception == null && ar.result != null) { |
| 967 | cellScanResult = new CellNetworkScanResult( |
| 968 | CellNetworkScanResult.STATUS_SUCCESS, |
| 969 | (List<OperatorInfo>) ar.result); |
| 970 | } else { |
| 971 | if (ar.result == null) { |
| 972 | loge("getCellNetworkScanResults: Empty response"); |
| 973 | } |
| 974 | if (ar.exception != null) { |
| 975 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 976 | } |
| 977 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 978 | if (ar.exception instanceof CommandException) { |
| 979 | CommandException.Error error = |
| 980 | ((CommandException) (ar.exception)).getCommandError(); |
| 981 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 982 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 983 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 984 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 985 | } |
| 986 | } |
| 987 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 988 | } |
| 989 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 990 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 991 | break; |
| 992 | |
| 993 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 994 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 995 | ManualNetworkSelectionArgument selArg = |
| 996 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 997 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 998 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 999 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1000 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1001 | break; |
| 1002 | |
| 1003 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1004 | ar = (AsyncResult) msg.obj; |
| 1005 | request = (MainThreadRequest) ar.userObj; |
| 1006 | if (ar.exception == null) { |
| 1007 | request.result = true; |
| 1008 | } else { |
| 1009 | request.result = false; |
| 1010 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1011 | } |
| 1012 | notifyRequester(request); |
| 1013 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1014 | break; |
| 1015 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1016 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1017 | request = (MainThreadRequest) msg.obj; |
| 1018 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1019 | if (defaultPhone != null) { |
| 1020 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 1021 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1022 | break; |
| 1023 | |
| 1024 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1025 | ar = (AsyncResult) msg.obj; |
| 1026 | request = (MainThreadRequest) ar.userObj; |
| 1027 | if (ar.exception == null && ar.result != null) { |
| 1028 | request.result = ar.result; |
| 1029 | } else { |
| 1030 | if (ar.result == null) { |
| 1031 | loge("queryModemActivityInfo: Empty response"); |
| 1032 | } else if (ar.exception instanceof CommandException) { |
| 1033 | loge("queryModemActivityInfo: CommandException: " + |
| 1034 | ar.exception); |
| 1035 | } else { |
| 1036 | loge("queryModemActivityInfo: Unknown exception"); |
| 1037 | } |
| 1038 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 1039 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 1040 | if (request.result == null) { |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 1041 | request.result = new ModemActivityInfo(0, 0, 0, null, 0); |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 1042 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1043 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1044 | break; |
| 1045 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1046 | case CMD_SET_ALLOWED_CARRIERS: |
| 1047 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1048 | CarrierRestrictionRules argument = |
| 1049 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1050 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1051 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1052 | break; |
| 1053 | |
| 1054 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1055 | ar = (AsyncResult) msg.obj; |
| 1056 | request = (MainThreadRequest) ar.userObj; |
| 1057 | if (ar.exception == null && ar.result != null) { |
| 1058 | request.result = ar.result; |
| 1059 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1060 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1061 | if (ar.exception instanceof CommandException) { |
| 1062 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1063 | CommandException.Error error = |
| 1064 | ((CommandException) (ar.exception)).getCommandError(); |
| 1065 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1066 | request.result = |
| 1067 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1068 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1069 | } else { |
| 1070 | loge("setAllowedCarriers: Unknown exception"); |
| 1071 | } |
| 1072 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1073 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1074 | break; |
| 1075 | |
| 1076 | case CMD_GET_ALLOWED_CARRIERS: |
| 1077 | request = (MainThreadRequest) msg.obj; |
| 1078 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1079 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1080 | break; |
| 1081 | |
| 1082 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1083 | ar = (AsyncResult) msg.obj; |
| 1084 | request = (MainThreadRequest) ar.userObj; |
| 1085 | if (ar.exception == null && ar.result != null) { |
| 1086 | request.result = ar.result; |
| 1087 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1088 | request.result = new IllegalStateException( |
| 1089 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1090 | if (ar.result == null) { |
| 1091 | loge("getAllowedCarriers: Empty response"); |
| 1092 | } else if (ar.exception instanceof CommandException) { |
| 1093 | loge("getAllowedCarriers: CommandException: " + |
| 1094 | ar.exception); |
| 1095 | } else { |
| 1096 | loge("getAllowedCarriers: Unknown exception"); |
| 1097 | } |
| 1098 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1099 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1100 | break; |
| 1101 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1102 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1103 | ar = (AsyncResult) msg.obj; |
| 1104 | request = (MainThreadRequest) ar.userObj; |
| 1105 | if (ar.exception == null && ar.result != null) { |
| 1106 | request.result = ar.result; |
| 1107 | } else { |
| 1108 | request.result = new IllegalArgumentException( |
| 1109 | "Failed to retrieve Forbidden Plmns"); |
| 1110 | if (ar.result == null) { |
| 1111 | loge("getForbiddenPlmns: Empty response"); |
| 1112 | } else { |
| 1113 | loge("getForbiddenPlmns: Unknown exception"); |
| 1114 | } |
| 1115 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1116 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1117 | break; |
| 1118 | |
| 1119 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1120 | request = (MainThreadRequest) msg.obj; |
| 1121 | uiccCard = getUiccCardFromRequest(request); |
| 1122 | if (uiccCard == null) { |
| 1123 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1124 | request.result = new IllegalArgumentException( |
| 1125 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1126 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1127 | break; |
| 1128 | } |
| 1129 | Integer appType = (Integer) request.argument; |
| 1130 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1131 | if (uiccApp == null) { |
| 1132 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1133 | + appType); |
| 1134 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1135 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1136 | break; |
| 1137 | } else { |
| 1138 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1139 | + " specified type -- " + appType); |
| 1140 | } |
| 1141 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1142 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1143 | onCompleted); |
| 1144 | break; |
| 1145 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1146 | case CMD_SWITCH_SLOTS: |
| 1147 | request = (MainThreadRequest) msg.obj; |
| 1148 | int[] physicalSlots = (int[]) request.argument; |
| 1149 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1150 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1151 | break; |
| 1152 | |
| 1153 | case EVENT_SWITCH_SLOTS_DONE: |
| 1154 | ar = (AsyncResult) msg.obj; |
| 1155 | request = (MainThreadRequest) ar.userObj; |
| 1156 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1157 | notifyRequester(request); |
| 1158 | break; |
| 1159 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1160 | request = (MainThreadRequest) msg.obj; |
| 1161 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1162 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1163 | break; |
| 1164 | |
| 1165 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1166 | ar = (AsyncResult) msg.obj; |
| 1167 | request = (MainThreadRequest) ar.userObj; |
| 1168 | if (ar.exception != null) { |
| 1169 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1170 | } else { |
| 1171 | int mode = ((int[]) ar.result)[0]; |
| 1172 | if (mode == 0) { |
| 1173 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1174 | } else { |
| 1175 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1176 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1177 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1178 | notifyRequester(request); |
| 1179 | break; |
| 1180 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1181 | request = (MainThreadRequest) msg.obj; |
| 1182 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1183 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1184 | break; |
| 1185 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1186 | ar = (AsyncResult) msg.obj; |
| 1187 | request = (MainThreadRequest) ar.userObj; |
| 1188 | if (ar.exception != null) { |
| 1189 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1190 | } else { |
| 1191 | request.result = ((int[]) ar.result)[0]; |
| 1192 | } |
| 1193 | notifyRequester(request); |
| 1194 | break; |
| 1195 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1196 | request = (MainThreadRequest) msg.obj; |
| 1197 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1198 | int mode = (int) request.argument; |
| 1199 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1200 | break; |
| 1201 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1202 | ar = (AsyncResult) msg.obj; |
| 1203 | request = (MainThreadRequest) ar.userObj; |
| 1204 | request.result = ar.exception == null; |
| 1205 | notifyRequester(request); |
| 1206 | break; |
| 1207 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1208 | request = (MainThreadRequest) msg.obj; |
| 1209 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1210 | int subscriptionMode = (int) request.argument; |
| 1211 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1212 | break; |
| 1213 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1214 | ar = (AsyncResult) msg.obj; |
| 1215 | request = (MainThreadRequest) ar.userObj; |
| 1216 | request.result = ar.exception == null; |
| 1217 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1218 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1219 | case CMD_GET_ALL_CELL_INFO: |
| 1220 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1221 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1222 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1223 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1224 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1225 | ar = (AsyncResult) msg.obj; |
| 1226 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1227 | // If a timeout occurs, the response will be null |
| 1228 | request.result = (ar.exception == null && ar.result != null) |
| 1229 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1230 | synchronized (request) { |
| 1231 | request.notifyAll(); |
| 1232 | } |
| 1233 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1234 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1235 | request = (MainThreadRequest) msg.obj; |
| 1236 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1237 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1238 | break; |
| 1239 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1240 | ar = (AsyncResult) msg.obj; |
| 1241 | request = (MainThreadRequest) ar.userObj; |
| 1242 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1243 | try { |
| 1244 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1245 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1246 | cb.onError( |
| 1247 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1248 | ar.exception.getClass().getName(), |
| 1249 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1250 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1251 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1252 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1253 | } else { |
| 1254 | // use the result as returned |
| 1255 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1256 | } |
| 1257 | } catch (RemoteException re) { |
| 1258 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1259 | } |
| 1260 | break; |
| 1261 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1262 | request = (MainThreadRequest) msg.obj; |
| 1263 | WorkSource ws = (WorkSource) request.argument; |
| 1264 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1265 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1266 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1267 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1268 | ar = (AsyncResult) msg.obj; |
| 1269 | request = (MainThreadRequest) ar.userObj; |
| 1270 | if (ar.exception == null) { |
| 1271 | request.result = ar.result; |
| 1272 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1273 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1274 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1275 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | synchronized (request) { |
| 1279 | request.notifyAll(); |
| 1280 | } |
| 1281 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1282 | case CMD_MODEM_REBOOT: |
| 1283 | request = (MainThreadRequest) msg.obj; |
| 1284 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1285 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1286 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1287 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1288 | handleNullReturnEvent(msg, "rebootModem"); |
| 1289 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1290 | case CMD_REQUEST_ENABLE_MODEM: |
| 1291 | request = (MainThreadRequest) msg.obj; |
| 1292 | boolean enable = (boolean) request.argument; |
| 1293 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1294 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1295 | PhoneConfigurationManager.getInstance() |
| 1296 | .enablePhone(request.phone, enable, onCompleted); |
| 1297 | break; |
| 1298 | case EVENT_ENABLE_MODEM_DONE: |
| 1299 | ar = (AsyncResult) msg.obj; |
| 1300 | request = (MainThreadRequest) ar.userObj; |
| 1301 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1302 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1303 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1304 | if ((boolean) request.result) { |
| 1305 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1306 | updateModemStateMetrics(); |
| 1307 | } else { |
| 1308 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1309 | + ar.exception); |
| 1310 | } |
| 1311 | notifyRequester(request); |
| 1312 | break; |
| 1313 | case CMD_GET_MODEM_STATUS: |
| 1314 | request = (MainThreadRequest) msg.obj; |
| 1315 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1316 | PhoneConfigurationManager.getInstance() |
| 1317 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1318 | break; |
| 1319 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1320 | ar = (AsyncResult) msg.obj; |
| 1321 | request = (MainThreadRequest) ar.userObj; |
| 1322 | int id = request.phone.getPhoneId(); |
| 1323 | if (ar.exception == null && ar.result != null) { |
| 1324 | request.result = ar.result; |
| 1325 | //update the cache as modem status has changed |
| 1326 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1327 | (boolean) request.result); |
| 1328 | } else { |
| 1329 | // Return true if modem status cannot be retrieved. For most cases, |
| 1330 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1331 | // and disable modem are not supported. Modem is always on. |
| 1332 | // TODO: this should be fixed in R to support a third |
| 1333 | // status UNKNOWN b/131631629 |
| 1334 | request.result = true; |
| 1335 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1336 | + ar.exception); |
| 1337 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1338 | notifyRequester(request); |
| 1339 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1340 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1341 | ar = (AsyncResult) msg.obj; |
| 1342 | request = (MainThreadRequest) ar.userObj; |
| 1343 | if (ar.exception == null && ar.result != null) { |
| 1344 | request.result = ar.result; |
| 1345 | } else { |
| 1346 | request.result = -1; |
| 1347 | loge("Failed to set Forbidden Plmns"); |
| 1348 | if (ar.result == null) { |
| 1349 | loge("setForbidenPlmns: Empty response"); |
| 1350 | } else if (ar.exception != null) { |
| 1351 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1352 | request.result = -1; |
| 1353 | } else { |
| 1354 | loge("setForbiddenPlmns: Unknown exception"); |
| 1355 | } |
| 1356 | } |
| 1357 | notifyRequester(request); |
| 1358 | break; |
| 1359 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1360 | request = (MainThreadRequest) msg.obj; |
| 1361 | uiccCard = getUiccCardFromRequest(request); |
| 1362 | if (uiccCard == null) { |
| 1363 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1364 | request.result = -1; |
| 1365 | notifyRequester(request); |
| 1366 | break; |
| 1367 | } |
| 1368 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1369 | (Pair<Integer, List<String>>) request.argument; |
| 1370 | appType = setFplmnsArgs.first; |
| 1371 | List<String> fplmns = setFplmnsArgs.second; |
| 1372 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1373 | if (uiccApp == null) { |
| 1374 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1375 | request.result = -1; |
| 1376 | loge("Failed to get UICC App"); |
| 1377 | notifyRequester(request); |
| 1378 | } else { |
| 1379 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1380 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1381 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1382 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1383 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1384 | case CMD_ERASE_MODEM_CONFIG: |
| 1385 | request = (MainThreadRequest) msg.obj; |
| 1386 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1387 | defaultPhone.eraseModemConfig(onCompleted); |
| 1388 | break; |
| 1389 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1390 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1391 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1392 | |
| 1393 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1394 | request = (MainThreadRequest) msg.obj; |
| 1395 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1396 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1397 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1398 | changed.first, changed.second, onCompleted); |
| 1399 | break; |
| 1400 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1401 | ar = (AsyncResult) msg.obj; |
| 1402 | request = (MainThreadRequest) ar.userObj; |
| 1403 | if (ar.exception == null) { |
| 1404 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1405 | } else { |
| 1406 | request.result = msg.arg1; |
| 1407 | } |
| 1408 | notifyRequester(request); |
| 1409 | break; |
| 1410 | |
| 1411 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1412 | request = (MainThreadRequest) msg.obj; |
| 1413 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1414 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1415 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1416 | enabled.first, enabled.second, onCompleted); |
| 1417 | break; |
| 1418 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1419 | ar = (AsyncResult) msg.obj; |
| 1420 | request = (MainThreadRequest) ar.userObj; |
| 1421 | if (ar.exception == null) { |
| 1422 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1423 | } else { |
| 1424 | request.result = msg.arg1; |
| 1425 | } |
| 1426 | notifyRequester(request); |
| 1427 | break; |
| 1428 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1429 | default: |
| 1430 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1431 | break; |
| 1432 | } |
| 1433 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1434 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1435 | private void notifyRequester(MainThreadRequest request) { |
| 1436 | synchronized (request) { |
| 1437 | request.notifyAll(); |
| 1438 | } |
| 1439 | } |
| 1440 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1441 | private void handleNullReturnEvent(Message msg, String command) { |
| 1442 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1443 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1444 | if (ar.exception == null) { |
| 1445 | request.result = true; |
| 1446 | } else { |
| 1447 | request.result = false; |
| 1448 | if (ar.exception instanceof CommandException) { |
| 1449 | loge(command + ": CommandException: " + ar.exception); |
| 1450 | } else { |
| 1451 | loge(command + ": Unknown exception"); |
| 1452 | } |
| 1453 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1454 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1455 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | /** |
| 1459 | * Posts the specified command to be executed on the main thread, |
| 1460 | * waits for the request to complete, and returns the result. |
| 1461 | * @see #sendRequestAsync |
| 1462 | */ |
| 1463 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1464 | return sendRequest( |
| 1465 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | /** |
| 1469 | * Posts the specified command to be executed on the main thread, |
| 1470 | * waits for the request to complete, and returns the result. |
| 1471 | * @see #sendRequestAsync |
| 1472 | */ |
| 1473 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1474 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1475 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | /** |
| 1479 | * Posts the specified command to be executed on the main thread, |
| 1480 | * waits for the request to complete, and returns the result. |
| 1481 | * @see #sendRequestAsync |
| 1482 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1483 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1484 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | /** |
| 1488 | * Posts the specified command to be executed on the main thread, |
| 1489 | * waits for the request to complete, and returns the result. |
| 1490 | * @see #sendRequestAsync |
| 1491 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1492 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1493 | return sendRequest(command, argument, subId, null, workSource); |
| 1494 | } |
| 1495 | |
| 1496 | /** |
| 1497 | * Posts the specified command to be executed on the main thread, |
| 1498 | * waits for the request to complete, and returns the result. |
| 1499 | * @see #sendRequestAsync |
| 1500 | */ |
| 1501 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1502 | return sendRequest( |
| 1503 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1504 | } |
| 1505 | |
| 1506 | /** |
| 1507 | * Posts the specified command to be executed on the main thread, |
| 1508 | * waits for the request to complete, and returns the result. |
| 1509 | * @see #sendRequestAsync |
| 1510 | */ |
| 1511 | private Object sendRequest( |
| 1512 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1513 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1514 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1515 | } |
| 1516 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1517 | MainThreadRequest request = null; |
| 1518 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1519 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1520 | } else if (phone != null) { |
| 1521 | request = new MainThreadRequest(argument, phone, workSource); |
| 1522 | } else { |
| 1523 | request = new MainThreadRequest(argument, subId, workSource); |
| 1524 | } |
| 1525 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1526 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1527 | msg.sendToTarget(); |
| 1528 | |
| 1529 | // Wait for the request to complete |
| 1530 | synchronized (request) { |
| 1531 | while (request.result == null) { |
| 1532 | try { |
| 1533 | request.wait(); |
| 1534 | } catch (InterruptedException e) { |
| 1535 | // Do nothing, go back and wait until the request is complete |
| 1536 | } |
| 1537 | } |
| 1538 | } |
| 1539 | return request.result; |
| 1540 | } |
| 1541 | |
| 1542 | /** |
| 1543 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1544 | * Posts the specified command to be executed on the main thread, and |
| 1545 | * returns immediately. |
| 1546 | * @see #sendRequest |
| 1547 | */ |
| 1548 | private void sendRequestAsync(int command) { |
| 1549 | mMainThreadHandler.sendEmptyMessage(command); |
| 1550 | } |
| 1551 | |
| 1552 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1553 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1554 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1555 | */ |
| 1556 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1557 | sendRequestAsync(command, argument, null, null); |
| 1558 | } |
| 1559 | |
| 1560 | /** |
| 1561 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1562 | * @see {@link #sendRequest(int,Object)} |
| 1563 | */ |
| 1564 | private void sendRequestAsync( |
| 1565 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1566 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1567 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1568 | msg.sendToTarget(); |
| 1569 | } |
| 1570 | |
| 1571 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1572 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1573 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1574 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1575 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1576 | synchronized (PhoneInterfaceManager.class) { |
| 1577 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1578 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1579 | } else { |
| 1580 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1581 | } |
| 1582 | return sInstance; |
| 1583 | } |
| 1584 | } |
| 1585 | |
| 1586 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1587 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1588 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1589 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1590 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1591 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1592 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1593 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1594 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1595 | mTelephonySharedPreferences = |
| 1596 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1597 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1598 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1599 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1600 | publish(); |
| 1601 | } |
| 1602 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1603 | private Phone getDefaultPhone() { |
| 1604 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1605 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1606 | } |
| 1607 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1608 | private void publish() { |
| 1609 | if (DBG) log("publish: " + this); |
| 1610 | |
| 1611 | ServiceManager.addService("phone", this); |
| 1612 | } |
| 1613 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1614 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1615 | if (request.phone != null) { |
| 1616 | return request.phone; |
| 1617 | } else { |
| 1618 | return getPhoneFromSubId(request.subId); |
| 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | private Phone getPhoneFromSubId(int subId) { |
| 1623 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1624 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1625 | } |
| 1626 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1627 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1628 | Phone phone = getPhoneFromRequest(request); |
| 1629 | return phone == null ? null : |
| 1630 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1631 | } |
| 1632 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1633 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1634 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1635 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1636 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1637 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1638 | private void sendEraseModemConfig(Phone phone) { |
| 1639 | if (phone != null) { |
| 1640 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1641 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1642 | final long identity = Binder.clearCallingIdentity(); |
| 1643 | try { |
| 1644 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1645 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1646 | } finally { |
| 1647 | Binder.restoreCallingIdentity(identity); |
| 1648 | } |
| 1649 | } |
| 1650 | } |
| 1651 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1652 | private boolean isImsAvailableOnDevice() { |
| 1653 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1654 | if (pm == null) { |
| 1655 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1656 | // so do not throw error and allow. |
| 1657 | return true; |
| 1658 | } |
| 1659 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1660 | } |
| 1661 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1662 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1663 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1664 | } |
| 1665 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1666 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1667 | if (DBG) log("dial: " + number); |
| 1668 | // No permission check needed here: This is just a wrapper around the |
| 1669 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1670 | // the UI before it does anything. |
| 1671 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1672 | final long identity = Binder.clearCallingIdentity(); |
| 1673 | try { |
| 1674 | String url = createTelUrl(number); |
| 1675 | if (url == null) { |
| 1676 | return; |
| 1677 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1678 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1679 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1680 | PhoneConstants.State state = mCM.getState(subId); |
| 1681 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1682 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1683 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1684 | mApp.startActivity(intent); |
| 1685 | } |
| 1686 | } finally { |
| 1687 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1688 | } |
| 1689 | } |
| 1690 | |
| 1691 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1692 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1695 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1696 | if (DBG) log("call: " + number); |
| 1697 | |
| 1698 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1699 | // need to do a permission check since we're calling startActivity() |
| 1700 | // from the context of the phone app. |
| 1701 | enforceCallPermission(); |
| 1702 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1703 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1704 | != AppOpsManager.MODE_ALLOWED) { |
| 1705 | return; |
| 1706 | } |
| 1707 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1708 | final long identity = Binder.clearCallingIdentity(); |
| 1709 | try { |
| 1710 | String url = createTelUrl(number); |
| 1711 | if (url == null) { |
| 1712 | return; |
| 1713 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1714 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1715 | boolean isValid = false; |
| 1716 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1717 | if (slist != null) { |
| 1718 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1719 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1720 | isValid = true; |
| 1721 | break; |
| 1722 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1723 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1724 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1725 | if (!isValid) { |
| 1726 | return; |
| 1727 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1728 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1729 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1730 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1731 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1732 | mApp.startActivity(intent); |
| 1733 | } finally { |
| 1734 | Binder.restoreCallingIdentity(identity); |
| 1735 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1736 | } |
| 1737 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1738 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1739 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1740 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1741 | } |
| 1742 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1743 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1744 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1745 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1746 | } |
| 1747 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1748 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1749 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1750 | |
| 1751 | final long identity = Binder.clearCallingIdentity(); |
| 1752 | try { |
| 1753 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1754 | checkSimPin.start(); |
| 1755 | return checkSimPin.unlockSim(null, pin); |
| 1756 | } finally { |
| 1757 | Binder.restoreCallingIdentity(identity); |
| 1758 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1761 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1762 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1763 | |
| 1764 | final long identity = Binder.clearCallingIdentity(); |
| 1765 | try { |
| 1766 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1767 | checkSimPuk.start(); |
| 1768 | return checkSimPuk.unlockSim(puk, pin); |
| 1769 | } finally { |
| 1770 | Binder.restoreCallingIdentity(identity); |
| 1771 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1772 | } |
| 1773 | |
| 1774 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1775 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1776 | * a synchronous one. |
| 1777 | */ |
| 1778 | private static class UnlockSim extends Thread { |
| 1779 | |
| 1780 | private final IccCard mSimCard; |
| 1781 | |
| 1782 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1783 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1784 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1785 | |
| 1786 | // For replies from SimCard interface |
| 1787 | private Handler mHandler; |
| 1788 | |
| 1789 | // For async handler to identify request type |
| 1790 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1791 | |
| 1792 | public UnlockSim(IccCard simCard) { |
| 1793 | mSimCard = simCard; |
| 1794 | } |
| 1795 | |
| 1796 | @Override |
| 1797 | public void run() { |
| 1798 | Looper.prepare(); |
| 1799 | synchronized (UnlockSim.this) { |
| 1800 | mHandler = new Handler() { |
| 1801 | @Override |
| 1802 | public void handleMessage(Message msg) { |
| 1803 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1804 | switch (msg.what) { |
| 1805 | case SUPPLY_PIN_COMPLETE: |
| 1806 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1807 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1808 | mRetryCount = msg.arg1; |
| 1809 | if (ar.exception != null) { |
| 1810 | if (ar.exception instanceof CommandException && |
| 1811 | ((CommandException)(ar.exception)).getCommandError() |
| 1812 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1813 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1814 | } else { |
| 1815 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1816 | } |
| 1817 | } else { |
| 1818 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1819 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1820 | mDone = true; |
| 1821 | UnlockSim.this.notifyAll(); |
| 1822 | } |
| 1823 | break; |
| 1824 | } |
| 1825 | } |
| 1826 | }; |
| 1827 | UnlockSim.this.notifyAll(); |
| 1828 | } |
| 1829 | Looper.loop(); |
| 1830 | } |
| 1831 | |
| 1832 | /* |
| 1833 | * Use PIN or PUK to unlock SIM card |
| 1834 | * |
| 1835 | * If PUK is null, unlock SIM card with PIN |
| 1836 | * |
| 1837 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1838 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1839 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1840 | |
| 1841 | while (mHandler == null) { |
| 1842 | try { |
| 1843 | wait(); |
| 1844 | } catch (InterruptedException e) { |
| 1845 | Thread.currentThread().interrupt(); |
| 1846 | } |
| 1847 | } |
| 1848 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1849 | |
| 1850 | if (puk == null) { |
| 1851 | mSimCard.supplyPin(pin, callback); |
| 1852 | } else { |
| 1853 | mSimCard.supplyPuk(puk, pin, callback); |
| 1854 | } |
| 1855 | |
| 1856 | while (!mDone) { |
| 1857 | try { |
| 1858 | Log.d(LOG_TAG, "wait for done"); |
| 1859 | wait(); |
| 1860 | } catch (InterruptedException e) { |
| 1861 | // Restore the interrupted status |
| 1862 | Thread.currentThread().interrupt(); |
| 1863 | } |
| 1864 | } |
| 1865 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1866 | int[] resultArray = new int[2]; |
| 1867 | resultArray[0] = mResult; |
| 1868 | resultArray[1] = mRetryCount; |
| 1869 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1870 | } |
| 1871 | } |
| 1872 | |
| 1873 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1874 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1875 | |
| 1876 | } |
| 1877 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1878 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1879 | // No permission check needed here: this call is harmless, and it's |
| 1880 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1881 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1882 | final long identity = Binder.clearCallingIdentity(); |
| 1883 | try { |
| 1884 | final Phone phone = getPhone(subId); |
| 1885 | if (phone != null) { |
| 1886 | phone.updateServiceLocation(); |
| 1887 | } |
| 1888 | } finally { |
| 1889 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1890 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1891 | } |
| 1892 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1893 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1894 | @Override |
| 1895 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1896 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1897 | } |
| 1898 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1899 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1900 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1901 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1902 | callingFeatureId); |
| 1903 | } |
| 1904 | |
| 1905 | @Deprecated |
| 1906 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1907 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1908 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 1909 | } |
| 1910 | |
| 1911 | @Override |
| 1912 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1913 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1914 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1915 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1916 | return false; |
| 1917 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1918 | |
| 1919 | final long identity = Binder.clearCallingIdentity(); |
| 1920 | try { |
| 1921 | return isRadioOnForSubscriber(subId); |
| 1922 | } finally { |
| 1923 | Binder.restoreCallingIdentity(identity); |
| 1924 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
| 1927 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1928 | final long identity = Binder.clearCallingIdentity(); |
| 1929 | try { |
| 1930 | final Phone phone = getPhone(subId); |
| 1931 | if (phone != null) { |
| 1932 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1933 | } else { |
| 1934 | return false; |
| 1935 | } |
| 1936 | } finally { |
| 1937 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1938 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1942 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1943 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1944 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1945 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1946 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1947 | |
| 1948 | final long identity = Binder.clearCallingIdentity(); |
| 1949 | try { |
| 1950 | final Phone phone = getPhone(subId); |
| 1951 | if (phone != null) { |
| 1952 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1953 | } |
| 1954 | } finally { |
| 1955 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1956 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1960 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1961 | } |
| 1962 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1963 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1964 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1965 | |
| 1966 | final long identity = Binder.clearCallingIdentity(); |
| 1967 | try { |
| 1968 | final Phone phone = getPhone(subId); |
| 1969 | if (phone == null) { |
| 1970 | return false; |
| 1971 | } |
| 1972 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1973 | toggleRadioOnOffForSubscriber(subId); |
| 1974 | } |
| 1975 | return true; |
| 1976 | } finally { |
| 1977 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1978 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1979 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1980 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1981 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 1982 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1983 | /* |
| 1984 | * If any of the Radios are available, it will need to be |
| 1985 | * shutdown. So return true if any Radio is available. |
| 1986 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1987 | final long identity = Binder.clearCallingIdentity(); |
| 1988 | try { |
| 1989 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1990 | Phone phone = PhoneFactory.getPhone(i); |
| 1991 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1992 | } |
| 1993 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1994 | return false; |
| 1995 | } finally { |
| 1996 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1997 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2000 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2001 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2002 | enforceModifyPermission(); |
| 2003 | |
| 2004 | final long identity = Binder.clearCallingIdentity(); |
| 2005 | try { |
| 2006 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2007 | logv("Shutting down Phone " + i); |
| 2008 | shutdownRadioUsingPhoneId(i); |
| 2009 | } |
| 2010 | } finally { |
| 2011 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2016 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2017 | if (phone != null && phone.isRadioAvailable()) { |
| 2018 | phone.shutdownRadio(); |
| 2019 | } |
| 2020 | } |
| 2021 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2022 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2023 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2024 | |
| 2025 | final long identity = Binder.clearCallingIdentity(); |
| 2026 | try { |
| 2027 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2028 | if (defaultPhone != null) { |
| 2029 | defaultPhone.setRadioPower(turnOn); |
| 2030 | return true; |
| 2031 | } else { |
| 2032 | loge("There's no default phone."); |
| 2033 | return false; |
| 2034 | } |
| 2035 | } finally { |
| 2036 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2037 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2040 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2041 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2042 | |
| 2043 | final long identity = Binder.clearCallingIdentity(); |
| 2044 | try { |
| 2045 | final Phone phone = getPhone(subId); |
| 2046 | if (phone != null) { |
| 2047 | phone.setRadioPower(turnOn); |
| 2048 | return true; |
| 2049 | } else { |
| 2050 | return false; |
| 2051 | } |
| 2052 | } finally { |
| 2053 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2054 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2055 | } |
| 2056 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2057 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2058 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2059 | public boolean enableDataConnectivity() { |
| 2060 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2061 | |
| 2062 | final long identity = Binder.clearCallingIdentity(); |
| 2063 | try { |
| 2064 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2065 | final Phone phone = getPhone(subId); |
| 2066 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2067 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2068 | return true; |
| 2069 | } else { |
| 2070 | return false; |
| 2071 | } |
| 2072 | } finally { |
| 2073 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2074 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2075 | } |
| 2076 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2077 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2078 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2079 | public boolean disableDataConnectivity() { |
| 2080 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2081 | |
| 2082 | final long identity = Binder.clearCallingIdentity(); |
| 2083 | try { |
| 2084 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2085 | final Phone phone = getPhone(subId); |
| 2086 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2087 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2088 | return true; |
| 2089 | } else { |
| 2090 | return false; |
| 2091 | } |
| 2092 | } finally { |
| 2093 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2094 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2095 | } |
| 2096 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2097 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2098 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2099 | final long identity = Binder.clearCallingIdentity(); |
| 2100 | try { |
| 2101 | final Phone phone = getPhone(subId); |
| 2102 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2103 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2104 | } else { |
| 2105 | return false; |
| 2106 | } |
| 2107 | } finally { |
| 2108 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2109 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2113 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2114 | } |
| 2115 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2116 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2117 | enforceCallPermission(); |
| 2118 | |
| 2119 | final long identity = Binder.clearCallingIdentity(); |
| 2120 | try { |
| 2121 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2122 | return; |
| 2123 | } |
| 2124 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2125 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2126 | } finally { |
| 2127 | Binder.restoreCallingIdentity(identity); |
| 2128 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2129 | }; |
| 2130 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2131 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2132 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2133 | |
| 2134 | final long identity = Binder.clearCallingIdentity(); |
| 2135 | try { |
| 2136 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2137 | return false; |
| 2138 | } |
| 2139 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2140 | } finally { |
| 2141 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2142 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2145 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2146 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2147 | } |
| 2148 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2149 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2150 | final long identity = Binder.clearCallingIdentity(); |
| 2151 | try { |
| 2152 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2153 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2154 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2155 | } finally { |
| 2156 | Binder.restoreCallingIdentity(identity); |
| 2157 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2158 | } |
| 2159 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2160 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2161 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2162 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2163 | } |
| 2164 | |
| 2165 | @Override |
| 2166 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2167 | final long identity = Binder.clearCallingIdentity(); |
| 2168 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2169 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2170 | if (phone != null) { |
| 2171 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2172 | } else { |
| 2173 | return PhoneConstantConversions.convertDataState( |
| 2174 | PhoneConstants.DataState.DISCONNECTED); |
| 2175 | } |
| 2176 | } finally { |
| 2177 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2178 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2179 | } |
| 2180 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2181 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2182 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2183 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2184 | } |
| 2185 | |
| 2186 | @Override |
| 2187 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2188 | final long identity = Binder.clearCallingIdentity(); |
| 2189 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2190 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2191 | if (phone != null) { |
| 2192 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2193 | } else { |
| 2194 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2195 | } |
| 2196 | } finally { |
| 2197 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2198 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2202 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2203 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2204 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2205 | |
| 2206 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2207 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2208 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2209 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2210 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2211 | .setCallingPid(Binder.getCallingPid()) |
| 2212 | .setCallingUid(Binder.getCallingUid()) |
| 2213 | .setMethod("getCellLocation") |
| 2214 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2215 | .build()); |
| 2216 | switch (locationResult) { |
| 2217 | case DENIED_HARD: |
| 2218 | throw new SecurityException("Not allowed to access cell location"); |
| 2219 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2220 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2221 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2222 | } |
| 2223 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2224 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2225 | final long identity = Binder.clearCallingIdentity(); |
| 2226 | try { |
| 2227 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2228 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2229 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2230 | } finally { |
| 2231 | Binder.restoreCallingIdentity(identity); |
| 2232 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2233 | } |
| 2234 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2235 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2236 | public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage, |
| 2237 | String callingFeatureId) { |
Jack Yu | 7c5d91a | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2238 | if (!TextUtils.isEmpty(callingPackage)) { |
| 2239 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2240 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2241 | callingFeatureId, "getNetworkCountryIsoForPhone")) { |
Jack Yu | 7c5d91a | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2242 | return ""; |
| 2243 | } |
| 2244 | } |
| 2245 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2246 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2247 | // registered cell info, so return a NULL country instead. |
| 2248 | final long identity = Binder.clearCallingIdentity(); |
| 2249 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2250 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2251 | // Get default phone in this case. |
| 2252 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2253 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2254 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2255 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2256 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2257 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2258 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(), |
| 2259 | null)) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2260 | return ""; |
| 2261 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2262 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2263 | if (phone != null) { |
| 2264 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2265 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2266 | if (sst != null) { |
| 2267 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2268 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2269 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2270 | return lt.getCurrentCountry(); |
| 2271 | } else if (emergencyNumberTracker != null) { |
| 2272 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2273 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2274 | } |
| 2275 | } |
| 2276 | } |
| 2277 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2278 | } finally { |
| 2279 | Binder.restoreCallingIdentity(identity); |
| 2280 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2284 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2285 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2286 | } |
| 2287 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2288 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2289 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2290 | mApp.enforceCallingOrSelfPermission( |
| 2291 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2292 | |
| 2293 | final long identity = Binder.clearCallingIdentity(); |
| 2294 | try { |
| 2295 | final Phone phone = getPhone(subId); |
| 2296 | if (phone != null) { |
| 2297 | phone.enableLocationUpdates(); |
| 2298 | } |
| 2299 | } finally { |
| 2300 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2301 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | @Override |
| 2305 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2306 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2307 | } |
| 2308 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2309 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2310 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2311 | mApp.enforceCallingOrSelfPermission( |
| 2312 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2313 | |
| 2314 | final long identity = Binder.clearCallingIdentity(); |
| 2315 | try { |
| 2316 | final Phone phone = getPhone(subId); |
| 2317 | if (phone != null) { |
| 2318 | phone.disableLocationUpdates(); |
| 2319 | } |
| 2320 | } finally { |
| 2321 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2322 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2323 | } |
| 2324 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2325 | /** |
| 2326 | * Returns the target SDK version number for a given package name. |
| 2327 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2328 | * This call MUST be invoked before clearing the calling UID. |
| 2329 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2330 | * @return target SDK if the package is found or INT_MAX. |
| 2331 | */ |
| 2332 | private int getTargetSdk(String packageName) { |
| 2333 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2334 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2335 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2336 | if (ai != null) return ai.targetSdkVersion; |
| 2337 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2338 | loge("Failed to get package info for pkg=" |
| 2339 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2340 | } |
| 2341 | return Integer.MAX_VALUE; |
| 2342 | } |
| 2343 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2344 | @Override |
| 2345 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2346 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2347 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2348 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2349 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2350 | throw new SecurityException( |
| 2351 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2352 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2353 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2354 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2355 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2356 | return null; |
| 2357 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2358 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2359 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2360 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2361 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2362 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2363 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2364 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2365 | for (CellInfo ci : info) { |
| 2366 | if (ci instanceof CellInfoGsm) { |
| 2367 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2368 | } else if (ci instanceof CellInfoWcdma) { |
| 2369 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2370 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2371 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2372 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2373 | } |
| 2374 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2375 | private List<CellInfo> getCachedCellInfo() { |
| 2376 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2377 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2378 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2379 | if (info != null) cellInfos.addAll(info); |
| 2380 | } |
| 2381 | return cellInfos; |
| 2382 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2383 | |
| 2384 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2385 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2386 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2387 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2388 | |
| 2389 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2390 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2391 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2392 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2393 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2394 | .setCallingPid(Binder.getCallingPid()) |
| 2395 | .setCallingUid(Binder.getCallingUid()) |
| 2396 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2397 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2398 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2399 | .build()); |
| 2400 | switch (locationResult) { |
| 2401 | case DENIED_HARD: |
| 2402 | throw new SecurityException("Not allowed to access cell info"); |
| 2403 | case DENIED_SOFT: |
| 2404 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2405 | } |
| 2406 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2407 | final int targetSdk = getTargetSdk(callingPackage); |
| 2408 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2409 | return getCachedCellInfo(); |
| 2410 | } |
| 2411 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2412 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2413 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2414 | final long identity = Binder.clearCallingIdentity(); |
| 2415 | try { |
| 2416 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2417 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2418 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2419 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2420 | if (info != null) cellInfos.addAll(info); |
| 2421 | } |
| 2422 | return cellInfos; |
| 2423 | } finally { |
| 2424 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2425 | } |
| 2426 | } |
| 2427 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2428 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2429 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2430 | String callingFeatureId) { |
| 2431 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2432 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2436 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2437 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2438 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2439 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2440 | } |
| 2441 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2442 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2443 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2444 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2445 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2446 | |
| 2447 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2448 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2449 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2450 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2451 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2452 | .setCallingPid(Binder.getCallingPid()) |
| 2453 | .setCallingUid(Binder.getCallingUid()) |
| 2454 | .setMethod("requestCellInfoUpdate") |
| 2455 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2456 | .build()); |
| 2457 | switch (locationResult) { |
| 2458 | case DENIED_HARD: |
| 2459 | throw new SecurityException("Not allowed to access cell info"); |
| 2460 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2461 | try { |
| 2462 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2463 | } catch (RemoteException re) { |
| 2464 | // Drop without consequences |
| 2465 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2466 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2467 | } |
| 2468 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2469 | |
| 2470 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2471 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2472 | |
| 2473 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2474 | } |
| 2475 | |
| 2476 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2477 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2478 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2479 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2480 | |
| 2481 | final long identity = Binder.clearCallingIdentity(); |
| 2482 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2483 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2484 | } finally { |
| 2485 | Binder.restoreCallingIdentity(identity); |
| 2486 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2487 | } |
| 2488 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2489 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2490 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2491 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2492 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2493 | return null; |
| 2494 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2495 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2496 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2497 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2498 | return null; |
| 2499 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2500 | |
| 2501 | final long identity = Binder.clearCallingIdentity(); |
| 2502 | try { |
| 2503 | return phone.getImei(); |
| 2504 | } finally { |
| 2505 | Binder.restoreCallingIdentity(identity); |
| 2506 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2507 | } |
| 2508 | |
| 2509 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2510 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2511 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2512 | String tac = null; |
| 2513 | if (phone != null) { |
| 2514 | String imei = phone.getImei(); |
| 2515 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2516 | } |
| 2517 | return tac; |
| 2518 | } |
| 2519 | |
| 2520 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2521 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2522 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2523 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2524 | return null; |
| 2525 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2526 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2527 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2528 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2529 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2530 | return null; |
| 2531 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2532 | |
| 2533 | final long identity = Binder.clearCallingIdentity(); |
| 2534 | try { |
| 2535 | return phone.getMeid(); |
| 2536 | } finally { |
| 2537 | Binder.restoreCallingIdentity(identity); |
| 2538 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2542 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2543 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2544 | String manufacturerCode = null; |
| 2545 | if (phone != null) { |
| 2546 | String meid = phone.getMeid(); |
| 2547 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2548 | } |
| 2549 | return manufacturerCode; |
| 2550 | } |
| 2551 | |
| 2552 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2553 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2554 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2555 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2556 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2557 | return null; |
| 2558 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2559 | int subId = phone.getSubId(); |
| 2560 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2561 | mApp, subId, callingPackage, callingFeatureId, |
| 2562 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2563 | return null; |
| 2564 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2565 | |
| 2566 | final long identity = Binder.clearCallingIdentity(); |
| 2567 | try { |
| 2568 | return phone.getDeviceSvn(); |
| 2569 | } finally { |
| 2570 | Binder.restoreCallingIdentity(identity); |
| 2571 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2572 | } |
| 2573 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2574 | @Override |
| 2575 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2576 | final long identity = Binder.clearCallingIdentity(); |
| 2577 | try { |
| 2578 | final Phone phone = getPhone(subId); |
| 2579 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2580 | } finally { |
| 2581 | Binder.restoreCallingIdentity(identity); |
| 2582 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2583 | } |
| 2584 | |
| 2585 | @Override |
| 2586 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2587 | final long identity = Binder.clearCallingIdentity(); |
| 2588 | try { |
| 2589 | final Phone phone = getPhone(subId); |
| 2590 | return phone == null ? null : phone.getCarrierName(); |
| 2591 | } finally { |
| 2592 | Binder.restoreCallingIdentity(identity); |
| 2593 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2594 | } |
| 2595 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2596 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2597 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2598 | final long identity = Binder.clearCallingIdentity(); |
| 2599 | try { |
| 2600 | final Phone phone = getPhone(subId); |
| 2601 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2602 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2603 | } finally { |
| 2604 | Binder.restoreCallingIdentity(identity); |
| 2605 | } |
| 2606 | } |
| 2607 | |
| 2608 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2609 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2610 | final long identity = Binder.clearCallingIdentity(); |
| 2611 | try { |
| 2612 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2613 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2614 | } finally { |
| 2615 | Binder.restoreCallingIdentity(identity); |
| 2616 | } |
| 2617 | } |
| 2618 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2619 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2620 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2621 | if (!isSubscriptionMccMnc) { |
| 2622 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2623 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2624 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2625 | if (phone == null) { |
| 2626 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2627 | } |
| 2628 | final long identity = Binder.clearCallingIdentity(); |
| 2629 | try { |
| 2630 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2631 | } finally { |
| 2632 | Binder.restoreCallingIdentity(identity); |
| 2633 | } |
| 2634 | } |
| 2635 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2636 | // |
| 2637 | // Internal helper methods. |
| 2638 | // |
| 2639 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2640 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2641 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2642 | * |
| 2643 | * @throws SecurityException if the caller does not have the required permission |
| 2644 | */ |
| 2645 | private void enforceModifyPermission() { |
| 2646 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2647 | } |
| 2648 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2649 | /** |
| 2650 | * Make sure the caller is system. |
| 2651 | * |
| 2652 | * @throws SecurityException if the caller is not system. |
| 2653 | */ |
| 2654 | private void enforceSystemCaller() { |
| 2655 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2656 | throw new SecurityException("Caller must be system"); |
| 2657 | } |
| 2658 | } |
| 2659 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2660 | private void enforceActiveEmergencySessionPermission() { |
| 2661 | mApp.enforceCallingOrSelfPermission( |
| 2662 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2663 | } |
| 2664 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2665 | /** |
| 2666 | * Make sure the caller has the CALL_PHONE permission. |
| 2667 | * |
| 2668 | * @throws SecurityException if the caller does not have the required permission |
| 2669 | */ |
| 2670 | private void enforceCallPermission() { |
| 2671 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2672 | } |
| 2673 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2674 | private void enforceSettingsPermission() { |
| 2675 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2676 | } |
| 2677 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2678 | private String createTelUrl(String number) { |
| 2679 | if (TextUtils.isEmpty(number)) { |
| 2680 | return null; |
| 2681 | } |
| 2682 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2683 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2684 | } |
| 2685 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2686 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2687 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2688 | } |
| 2689 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2690 | private static void logv(String msg) { |
| 2691 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2692 | } |
| 2693 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2694 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2695 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2696 | } |
| 2697 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2698 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2699 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2700 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2701 | } |
| 2702 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2703 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2704 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2705 | final long identity = Binder.clearCallingIdentity(); |
| 2706 | try { |
| 2707 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2708 | if (phone == null) { |
| 2709 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2710 | } else { |
| 2711 | return phone.getPhoneType(); |
| 2712 | } |
| 2713 | } finally { |
| 2714 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2715 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | /** |
| 2719 | * Returns the CDMA ERI icon index to display |
| 2720 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2721 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2722 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2723 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2724 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2725 | } |
| 2726 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2727 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2728 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2729 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2730 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2731 | mApp, subId, callingPackage, callingFeatureId, |
| 2732 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2733 | return -1; |
| 2734 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2735 | |
| 2736 | final long identity = Binder.clearCallingIdentity(); |
| 2737 | try { |
| 2738 | final Phone phone = getPhone(subId); |
| 2739 | if (phone != null) { |
| 2740 | return phone.getCdmaEriIconIndex(); |
| 2741 | } else { |
| 2742 | return -1; |
| 2743 | } |
| 2744 | } finally { |
| 2745 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2746 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | /** |
| 2750 | * Returns the CDMA ERI icon mode, |
| 2751 | * 0 - ON |
| 2752 | * 1 - FLASHING |
| 2753 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2754 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2755 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2756 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2757 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2758 | } |
| 2759 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2760 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2761 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2762 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2763 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2764 | mApp, subId, callingPackage, callingFeatureId, |
| 2765 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2766 | return -1; |
| 2767 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2768 | |
| 2769 | final long identity = Binder.clearCallingIdentity(); |
| 2770 | try { |
| 2771 | final Phone phone = getPhone(subId); |
| 2772 | if (phone != null) { |
| 2773 | return phone.getCdmaEriIconMode(); |
| 2774 | } else { |
| 2775 | return -1; |
| 2776 | } |
| 2777 | } finally { |
| 2778 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2779 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2780 | } |
| 2781 | |
| 2782 | /** |
| 2783 | * Returns the CDMA ERI text, |
| 2784 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2785 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2786 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2787 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2788 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2789 | } |
| 2790 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2791 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2792 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2793 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2794 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2795 | mApp, subId, callingPackage, callingFeatureId, |
| 2796 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2797 | return null; |
| 2798 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2799 | |
| 2800 | final long identity = Binder.clearCallingIdentity(); |
| 2801 | try { |
| 2802 | final Phone phone = getPhone(subId); |
| 2803 | if (phone != null) { |
| 2804 | return phone.getCdmaEriText(); |
| 2805 | } else { |
| 2806 | return null; |
| 2807 | } |
| 2808 | } finally { |
| 2809 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2810 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2814 | * Returns the CDMA MDN. |
| 2815 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2816 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2817 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2818 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2819 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2820 | |
| 2821 | final long identity = Binder.clearCallingIdentity(); |
| 2822 | try { |
| 2823 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2824 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2825 | return phone.getLine1Number(); |
| 2826 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2827 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2828 | return null; |
| 2829 | } |
| 2830 | } finally { |
| 2831 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2832 | } |
| 2833 | } |
| 2834 | |
| 2835 | /** |
| 2836 | * Returns the CDMA MIN. |
| 2837 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2838 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2839 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2840 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2841 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2842 | |
| 2843 | final long identity = Binder.clearCallingIdentity(); |
| 2844 | try { |
| 2845 | final Phone phone = getPhone(subId); |
| 2846 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2847 | return phone.getCdmaMin(); |
| 2848 | } else { |
| 2849 | return null; |
| 2850 | } |
| 2851 | } finally { |
| 2852 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2853 | } |
| 2854 | } |
| 2855 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2856 | @Override |
| 2857 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2858 | INumberVerificationCallback callback, String callingPackage) { |
| 2859 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2860 | != PERMISSION_GRANTED) { |
| 2861 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2862 | } |
| 2863 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2864 | |
| 2865 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2866 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2867 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2868 | } |
| 2869 | |
| 2870 | if (range == null) { |
| 2871 | throw new NullPointerException("Range must be non-null"); |
| 2872 | } |
| 2873 | |
| 2874 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2875 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2876 | |
| 2877 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2878 | } |
| 2879 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2880 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2881 | * Returns true if CDMA provisioning needs to run. |
| 2882 | */ |
| 2883 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2884 | final long identity = Binder.clearCallingIdentity(); |
| 2885 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2886 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2887 | } finally { |
| 2888 | Binder.restoreCallingIdentity(identity); |
| 2889 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2890 | } |
| 2891 | |
| 2892 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2893 | * Sets the voice mail number of a given subId. |
| 2894 | */ |
| 2895 | @Override |
| 2896 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2897 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2898 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2899 | |
| 2900 | final long identity = Binder.clearCallingIdentity(); |
| 2901 | try { |
| 2902 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2903 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2904 | return success; |
| 2905 | } finally { |
| 2906 | Binder.restoreCallingIdentity(identity); |
| 2907 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2908 | } |
| 2909 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2910 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2911 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2912 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2913 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2914 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2915 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2916 | throw new SecurityException("caller must be system dialer"); |
| 2917 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2918 | |
| 2919 | final long identity = Binder.clearCallingIdentity(); |
| 2920 | try { |
| 2921 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2922 | if (phoneAccountHandle == null) { |
| 2923 | return null; |
| 2924 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2925 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2926 | } finally { |
| 2927 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2928 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2932 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2933 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2934 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2935 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2936 | mApp, subId, callingPackage, callingFeatureId, |
| 2937 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2938 | return null; |
| 2939 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2940 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2941 | final long identity = Binder.clearCallingIdentity(); |
| 2942 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2943 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2944 | } finally { |
| 2945 | Binder.restoreCallingIdentity(identity); |
| 2946 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2950 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2951 | VisualVoicemailSmsFilterSettings settings) { |
| 2952 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2953 | |
| 2954 | final long identity = Binder.clearCallingIdentity(); |
| 2955 | try { |
| 2956 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2957 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2958 | } finally { |
| 2959 | Binder.restoreCallingIdentity(identity); |
| 2960 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2961 | } |
| 2962 | |
| 2963 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2964 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2965 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2966 | |
| 2967 | final long identity = Binder.clearCallingIdentity(); |
| 2968 | try { |
| 2969 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2970 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2971 | } finally { |
| 2972 | Binder.restoreCallingIdentity(identity); |
| 2973 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2974 | } |
| 2975 | |
| 2976 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2977 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2978 | String callingPackage, int subId) { |
| 2979 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2980 | |
| 2981 | final long identity = Binder.clearCallingIdentity(); |
| 2982 | try { |
| 2983 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2984 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2985 | } finally { |
| 2986 | Binder.restoreCallingIdentity(identity); |
| 2987 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2988 | } |
| 2989 | |
| 2990 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2991 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2992 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2993 | |
| 2994 | final long identity = Binder.clearCallingIdentity(); |
| 2995 | try { |
| 2996 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2997 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2998 | } finally { |
| 2999 | Binder.restoreCallingIdentity(identity); |
| 3000 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3001 | } |
| 3002 | |
| 3003 | @Override |
| 3004 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 3005 | String number, int port, String text, PendingIntent sentIntent) { |
| 3006 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3007 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3008 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3009 | SmsController smsController = PhoneFactory.getSmsController(); |
| 3010 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 3011 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3012 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3013 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3014 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3015 | * Sets the voice activation state of a given subId. |
| 3016 | */ |
| 3017 | @Override |
| 3018 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3019 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3020 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3021 | |
| 3022 | final long identity = Binder.clearCallingIdentity(); |
| 3023 | try { |
| 3024 | final Phone phone = getPhone(subId); |
| 3025 | if (phone != null) { |
| 3026 | phone.setVoiceActivationState(activationState); |
| 3027 | } else { |
| 3028 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3029 | } |
| 3030 | } finally { |
| 3031 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3032 | } |
| 3033 | } |
| 3034 | |
| 3035 | /** |
| 3036 | * Sets the data activation state of a given subId. |
| 3037 | */ |
| 3038 | @Override |
| 3039 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3040 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3041 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3042 | |
| 3043 | final long identity = Binder.clearCallingIdentity(); |
| 3044 | try { |
| 3045 | final Phone phone = getPhone(subId); |
| 3046 | if (phone != null) { |
| 3047 | phone.setDataActivationState(activationState); |
| 3048 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3049 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3050 | } |
| 3051 | } finally { |
| 3052 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3053 | } |
| 3054 | } |
| 3055 | |
| 3056 | /** |
| 3057 | * Returns the voice activation state of a given subId. |
| 3058 | */ |
| 3059 | @Override |
| 3060 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3061 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3062 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3063 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3064 | final long identity = Binder.clearCallingIdentity(); |
| 3065 | try { |
| 3066 | if (phone != null) { |
| 3067 | return phone.getVoiceActivationState(); |
| 3068 | } else { |
| 3069 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3070 | } |
| 3071 | } finally { |
| 3072 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3073 | } |
| 3074 | } |
| 3075 | |
| 3076 | /** |
| 3077 | * Returns the data activation state of a given subId. |
| 3078 | */ |
| 3079 | @Override |
| 3080 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3081 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3082 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3083 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3084 | final long identity = Binder.clearCallingIdentity(); |
| 3085 | try { |
| 3086 | if (phone != null) { |
| 3087 | return phone.getDataActivationState(); |
| 3088 | } else { |
| 3089 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3090 | } |
| 3091 | } finally { |
| 3092 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3093 | } |
| 3094 | } |
| 3095 | |
| 3096 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3097 | * Returns the unread count of voicemails for a subId |
| 3098 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3099 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3100 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3101 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3102 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3103 | mApp, subId, callingPackage, callingFeatureId, |
| 3104 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3105 | return 0; |
| 3106 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3107 | final long identity = Binder.clearCallingIdentity(); |
| 3108 | try { |
| 3109 | final Phone phone = getPhone(subId); |
| 3110 | if (phone != null) { |
| 3111 | return phone.getVoiceMessageCount(); |
| 3112 | } else { |
| 3113 | return 0; |
| 3114 | } |
| 3115 | } finally { |
| 3116 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3117 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3118 | } |
| 3119 | |
| 3120 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3121 | * returns true, if the device is in a state where both voice and data |
| 3122 | * are supported simultaneously. This can change based on location or network condition. |
| 3123 | */ |
| 3124 | @Override |
| 3125 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3126 | final long identity = Binder.clearCallingIdentity(); |
| 3127 | try { |
| 3128 | final Phone phone = getPhone(subId); |
| 3129 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3130 | } finally { |
| 3131 | Binder.restoreCallingIdentity(identity); |
| 3132 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3133 | } |
| 3134 | |
| 3135 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3136 | * Send the dialer code if called from the current default dialer or the caller has |
| 3137 | * carrier privilege. |
| 3138 | * @param inputCode The dialer code to send |
| 3139 | */ |
| 3140 | @Override |
| 3141 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3142 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3143 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3144 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3145 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3146 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3147 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3148 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3149 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3150 | |
| 3151 | final long identity = Binder.clearCallingIdentity(); |
| 3152 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3153 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3154 | } finally { |
| 3155 | Binder.restoreCallingIdentity(identity); |
| 3156 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3157 | } |
| 3158 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3159 | @Override |
| 3160 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3161 | TelephonyPermissions |
| 3162 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3163 | mApp, subId, "getNetworkSelectionMode"); |
| 3164 | final long identity = Binder.clearCallingIdentity(); |
| 3165 | try { |
| 3166 | if (!isActiveSubscription(subId)) { |
| 3167 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3168 | } |
| 3169 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3170 | } finally { |
| 3171 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3172 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3173 | } |
| 3174 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3175 | @Override |
Sarah Chin | 5f0ecd7 | 2019-12-06 10:24:18 -0800 | [diff] [blame] | 3176 | public PhoneCapability getPhoneCapability(int subId, String callingPackage, |
| 3177 | String callingFeatureId) { |
| 3178 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3179 | mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) { |
| 3180 | return null; |
| 3181 | } |
| 3182 | final long identity = Binder.clearCallingIdentity(); |
| 3183 | try { |
| 3184 | return mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 3185 | } finally { |
| 3186 | Binder.restoreCallingIdentity(identity); |
| 3187 | } |
| 3188 | } |
| 3189 | |
| 3190 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3191 | public boolean isInEmergencySmsMode() { |
| 3192 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3193 | final long identity = Binder.clearCallingIdentity(); |
| 3194 | try { |
| 3195 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3196 | if (phone.isInEmergencySmsMode()) { |
| 3197 | return true; |
| 3198 | } |
| 3199 | } |
| 3200 | } finally { |
| 3201 | Binder.restoreCallingIdentity(identity); |
| 3202 | } |
| 3203 | return false; |
| 3204 | } |
| 3205 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3206 | /** |
| 3207 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3208 | * @param subId The subscription to use to check the configuration. |
| 3209 | * @param c The callback that will be used to send the result. |
| 3210 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3211 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3212 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3213 | throws RemoteException { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3214 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3215 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3216 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3217 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3218 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3219 | "IMS not available on device."); |
| 3220 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3221 | final long token = Binder.clearCallingIdentity(); |
| 3222 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3223 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3224 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3225 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3226 | } catch (ImsException e) { |
| 3227 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3228 | } finally { |
| 3229 | Binder.restoreCallingIdentity(token); |
| 3230 | } |
| 3231 | } |
| 3232 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3233 | /** |
| 3234 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3235 | * @param subId The subscription to use to check the configuration. |
| 3236 | * @param c The callback that will be used to send the result. |
| 3237 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3238 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3239 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3240 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3241 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3242 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3243 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3244 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3245 | final long token = Binder.clearCallingIdentity(); |
| 3246 | try { |
| 3247 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3248 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3249 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3250 | } catch (ImsException e) { |
| 3251 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3252 | + "is inactive, ignoring unregister."); |
| 3253 | // If the subscription is no longer active, just return, since the callback |
| 3254 | // will already have been removed internally. |
| 3255 | } finally { |
| 3256 | Binder.restoreCallingIdentity(token); |
| 3257 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3258 | } |
| 3259 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3260 | /** |
| 3261 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3262 | */ |
| 3263 | @Override |
| 3264 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3265 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3266 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3267 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3268 | "IMS not available on device."); |
| 3269 | } |
| 3270 | final long token = Binder.clearCallingIdentity(); |
| 3271 | try { |
| 3272 | Phone phone = getPhone(subId); |
| 3273 | if (phone == null) { |
| 3274 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3275 | + subId + "'"); |
| 3276 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3277 | } |
| 3278 | phone.getImsRegistrationState(regState -> { |
| 3279 | try { |
| 3280 | consumer.accept((regState == null) |
| 3281 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3282 | } catch (RemoteException e) { |
| 3283 | // Ignore if the remote process is no longer available to call back. |
| 3284 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3285 | } |
| 3286 | }); |
| 3287 | } finally { |
| 3288 | Binder.restoreCallingIdentity(token); |
| 3289 | } |
| 3290 | } |
| 3291 | |
| 3292 | /** |
| 3293 | * Get the transport type for the IMS service registration state. |
| 3294 | */ |
| 3295 | @Override |
| 3296 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3297 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3298 | enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType"); |
| 3299 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3300 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3301 | "IMS not available on device."); |
| 3302 | } |
| 3303 | final long token = Binder.clearCallingIdentity(); |
| 3304 | try { |
| 3305 | Phone phone = getPhone(subId); |
| 3306 | if (phone == null) { |
| 3307 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3308 | + subId + "'"); |
| 3309 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3310 | } |
| 3311 | phone.getImsRegistrationTech(regTech -> { |
| 3312 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3313 | int regTechConverted = (regTech == null) |
| 3314 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3315 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3316 | regTechConverted); |
| 3317 | try { |
| 3318 | consumer.accept(regTechConverted); |
| 3319 | } catch (RemoteException e) { |
| 3320 | // Ignore if the remote process is no longer available to call back. |
| 3321 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3322 | } |
| 3323 | }); |
| 3324 | } finally { |
| 3325 | Binder.restoreCallingIdentity(token); |
| 3326 | } |
| 3327 | } |
| 3328 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3329 | /** |
| 3330 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3331 | * @param subId The subscription to use to check the configuration. |
| 3332 | * @param c The callback that will be used to send the result. |
| 3333 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3334 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3335 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3336 | throws RemoteException { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3337 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3338 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3339 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3340 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3341 | "IMS not available on device."); |
| 3342 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3343 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3344 | final long token = Binder.clearCallingIdentity(); |
| 3345 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3346 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3347 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3348 | } catch (ImsException e) { |
| 3349 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3350 | } finally { |
| 3351 | Binder.restoreCallingIdentity(token); |
| 3352 | } |
| 3353 | } |
| 3354 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3355 | /** |
| 3356 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3357 | * @param subId The subscription to use to check the configuration. |
| 3358 | * @param c The callback that will be used to send the result. |
| 3359 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3360 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3361 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3362 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3363 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3364 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3365 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3366 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3367 | |
| 3368 | final long token = Binder.clearCallingIdentity(); |
| 3369 | try { |
| 3370 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3371 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3372 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3373 | } catch (ImsException e) { |
| 3374 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3375 | + "is inactive, ignoring unregister."); |
| 3376 | // If the subscription is no longer active, just return, since the callback |
| 3377 | // will already have been removed internally. |
| 3378 | } finally { |
| 3379 | Binder.restoreCallingIdentity(token); |
| 3380 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3381 | } |
| 3382 | |
| 3383 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3384 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3385 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3386 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3387 | final long token = Binder.clearCallingIdentity(); |
| 3388 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3389 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3390 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3391 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3392 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3393 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3394 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3395 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3396 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3397 | } finally { |
| 3398 | Binder.restoreCallingIdentity(token); |
| 3399 | } |
| 3400 | } |
| 3401 | |
| 3402 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3403 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3404 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3405 | final long token = Binder.clearCallingIdentity(); |
| 3406 | try { |
| 3407 | Phone phone = getPhone(subId); |
| 3408 | if (phone == null) return false; |
| 3409 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3410 | } finally { |
| 3411 | Binder.restoreCallingIdentity(token); |
| 3412 | } |
| 3413 | } |
| 3414 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3415 | /** |
| 3416 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3417 | * subscription. |
| 3418 | * @param subId The subscription to use to check the configuration. |
| 3419 | * @param callback The callback that will be used to send the result. |
| 3420 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3421 | * @param transportType The transport type of the MmTelFeature capability. |
| 3422 | */ |
| 3423 | @Override |
| 3424 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3425 | int transportType) { |
| 3426 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3427 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3428 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3429 | "IMS not available on device."); |
| 3430 | } |
| 3431 | final long token = Binder.clearCallingIdentity(); |
| 3432 | try { |
| 3433 | int slotId = getSlotIndex(subId); |
| 3434 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3435 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3436 | + subId + "'"); |
| 3437 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3438 | } |
| 3439 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3440 | transportType, aBoolean -> { |
| 3441 | try { |
| 3442 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3443 | } catch (RemoteException e) { |
| 3444 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3445 | + "running. Ignore"); |
| 3446 | } |
| 3447 | }); |
| 3448 | } finally { |
| 3449 | Binder.restoreCallingIdentity(token); |
| 3450 | } |
| 3451 | } |
| 3452 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3453 | /** |
| 3454 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3455 | * @param subId The subscription to use to check the configuration. |
| 3456 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3457 | @Override |
| 3458 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3459 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
| 3460 | enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled"); |
| 3461 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3462 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3463 | final long token = Binder.clearCallingIdentity(); |
| 3464 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3465 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3466 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3467 | } catch (ImsException e) { |
| 3468 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3469 | } finally { |
| 3470 | Binder.restoreCallingIdentity(token); |
| 3471 | } |
| 3472 | } |
| 3473 | |
| 3474 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3475 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3476 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3477 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3478 | final long identity = Binder.clearCallingIdentity(); |
| 3479 | try { |
| 3480 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3481 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3482 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3483 | } catch (ImsException e) { |
| 3484 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3485 | } finally { |
| 3486 | Binder.restoreCallingIdentity(identity); |
| 3487 | } |
| 3488 | } |
| 3489 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3490 | /** |
| 3491 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3492 | * @param subId The subscription to use to check the configuration. |
| 3493 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3494 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3495 | public boolean isVtSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3496 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3497 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3498 | final long identity = Binder.clearCallingIdentity(); |
| 3499 | try { |
| 3500 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3501 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3502 | } catch (ImsException e) { |
| 3503 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3504 | } finally { |
| 3505 | Binder.restoreCallingIdentity(identity); |
| 3506 | } |
| 3507 | } |
| 3508 | |
| 3509 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3510 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3511 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3512 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3513 | final long identity = Binder.clearCallingIdentity(); |
| 3514 | try { |
| 3515 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3516 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3517 | } catch (ImsException e) { |
| 3518 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3519 | } finally { |
| 3520 | Binder.restoreCallingIdentity(identity); |
| 3521 | } |
| 3522 | } |
| 3523 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3524 | /** |
| 3525 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3526 | * @param subId The subscription to use to check the configuration. |
| 3527 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3528 | @Override |
| 3529 | public boolean isVoWiFiSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3530 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3531 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3532 | final long identity = Binder.clearCallingIdentity(); |
| 3533 | try { |
| 3534 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3535 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3536 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3537 | } catch (ImsException e) { |
| 3538 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3539 | } finally { |
| 3540 | Binder.restoreCallingIdentity(identity); |
| 3541 | } |
| 3542 | } |
| 3543 | |
| 3544 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3545 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3546 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3547 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3548 | final long identity = Binder.clearCallingIdentity(); |
| 3549 | try { |
| 3550 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3551 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3552 | } catch (ImsException e) { |
| 3553 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3554 | } finally { |
| 3555 | Binder.restoreCallingIdentity(identity); |
| 3556 | } |
| 3557 | } |
| 3558 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3559 | /** |
| 3560 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3561 | * @param subId The subscription to use to check the configuration. |
| 3562 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3563 | @Override |
| 3564 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3565 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3566 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3567 | final long identity = Binder.clearCallingIdentity(); |
| 3568 | try { |
| 3569 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3570 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3571 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3572 | } catch (ImsException e) { |
| 3573 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3574 | } finally { |
| 3575 | Binder.restoreCallingIdentity(identity); |
| 3576 | } |
| 3577 | } |
| 3578 | |
| 3579 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3580 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3581 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3582 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3583 | final long identity = Binder.clearCallingIdentity(); |
| 3584 | try { |
| 3585 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3586 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3587 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3588 | } catch (ImsException e) { |
| 3589 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3590 | } finally { |
| 3591 | Binder.restoreCallingIdentity(identity); |
| 3592 | } |
| 3593 | } |
| 3594 | |
| 3595 | @Override |
| 3596 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3597 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3598 | "setVoWiFiNonPersistent"); |
| 3599 | final long identity = Binder.clearCallingIdentity(); |
| 3600 | try { |
| 3601 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3602 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3603 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3604 | } catch (ImsException e) { |
| 3605 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3606 | } finally { |
| 3607 | Binder.restoreCallingIdentity(identity); |
| 3608 | } |
| 3609 | } |
| 3610 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3611 | /** |
| 3612 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3613 | * @param subId The subscription to use to check the configuration. |
| 3614 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3615 | @Override |
| 3616 | public int getVoWiFiModeSetting(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3617 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3618 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3619 | final long identity = Binder.clearCallingIdentity(); |
| 3620 | try { |
| 3621 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3622 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3623 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3624 | } catch (ImsException e) { |
| 3625 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3626 | } finally { |
| 3627 | Binder.restoreCallingIdentity(identity); |
| 3628 | } |
| 3629 | } |
| 3630 | |
| 3631 | @Override |
| 3632 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3633 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3634 | "setVoWiFiModeSetting"); |
| 3635 | final long identity = Binder.clearCallingIdentity(); |
| 3636 | try { |
| 3637 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3638 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3639 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3640 | } catch (ImsException e) { |
| 3641 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3642 | } finally { |
| 3643 | Binder.restoreCallingIdentity(identity); |
| 3644 | } |
| 3645 | } |
| 3646 | |
| 3647 | @Override |
| 3648 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3649 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3650 | final long identity = Binder.clearCallingIdentity(); |
| 3651 | try { |
| 3652 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3653 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3654 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3655 | } catch (ImsException e) { |
| 3656 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3657 | } finally { |
| 3658 | Binder.restoreCallingIdentity(identity); |
| 3659 | } |
| 3660 | } |
| 3661 | |
| 3662 | @Override |
| 3663 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3664 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3665 | "setVoWiFiRoamingModeSetting"); |
| 3666 | final long identity = Binder.clearCallingIdentity(); |
| 3667 | try { |
| 3668 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3669 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3670 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3671 | } catch (ImsException e) { |
| 3672 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3673 | } finally { |
| 3674 | Binder.restoreCallingIdentity(identity); |
| 3675 | } |
| 3676 | } |
| 3677 | |
| 3678 | @Override |
| 3679 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3680 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3681 | "setRttCapabilityEnabled"); |
| 3682 | final long identity = Binder.clearCallingIdentity(); |
| 3683 | try { |
| 3684 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3685 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3686 | } catch (ImsException e) { |
| 3687 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3688 | } finally { |
| 3689 | Binder.restoreCallingIdentity(identity); |
| 3690 | } |
| 3691 | } |
| 3692 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3693 | /** |
| 3694 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3695 | * @param subId The subscription to use to check the configuration. |
| 3696 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3697 | @Override |
| 3698 | public boolean isTtyOverVolteEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3699 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3700 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3701 | final long identity = Binder.clearCallingIdentity(); |
| 3702 | try { |
| 3703 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3704 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3705 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3706 | } catch (ImsException e) { |
| 3707 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3708 | } finally { |
| 3709 | Binder.restoreCallingIdentity(identity); |
| 3710 | } |
| 3711 | } |
| 3712 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3713 | @Override |
| 3714 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3715 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3716 | final long identity = Binder.clearCallingIdentity(); |
| 3717 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3718 | if (!isImsAvailableOnDevice()) { |
| 3719 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3720 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3721 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3722 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3723 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3724 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3725 | } catch (ImsException e) { |
| 3726 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3727 | } finally { |
| 3728 | Binder.restoreCallingIdentity(identity); |
| 3729 | } |
| 3730 | } |
| 3731 | |
| 3732 | @Override |
| 3733 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3734 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3735 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3736 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3737 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3738 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3739 | try { |
| 3740 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3741 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3742 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3743 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3744 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3745 | + "is inactive, ignoring unregister."); |
| 3746 | // If the subscription is no longer active, just return, since the callback will already |
| 3747 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3748 | } finally { |
| 3749 | Binder.restoreCallingIdentity(identity); |
| 3750 | } |
| 3751 | } |
| 3752 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3753 | |
| 3754 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3755 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3756 | message); |
| 3757 | } |
| 3758 | |
| 3759 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3760 | boolean isMmtelCapability) { |
| 3761 | Phone phone = getPhone(subId); |
| 3762 | if (phone == null) { |
| 3763 | loge("phone instance null for subid " + subId); |
| 3764 | return false; |
| 3765 | } |
| 3766 | if (isMmtelCapability) { |
| 3767 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3768 | return false; |
| 3769 | } |
| 3770 | } else { |
| 3771 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3772 | return false; |
| 3773 | } |
| 3774 | } |
| 3775 | return true; |
| 3776 | } |
| 3777 | |
| 3778 | @Override |
| 3779 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3780 | boolean isProvisioned) { |
| 3781 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3782 | |
| 3783 | final long identity = Binder.clearCallingIdentity(); |
| 3784 | try { |
| 3785 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3786 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3787 | return; |
| 3788 | } |
| 3789 | |
| 3790 | // this capability requires provisioning, route to the correct API. |
| 3791 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3792 | switch (capability) { |
| 3793 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3794 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3795 | ims.setEabProvisioned(isProvisioned); |
| 3796 | break; |
| 3797 | default: { |
| 3798 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3799 | + "rcs capability '" + capability + "', which does not require " |
| 3800 | + "provisioning."); |
| 3801 | } |
| 3802 | } |
| 3803 | } finally { |
| 3804 | Binder.restoreCallingIdentity(identity); |
| 3805 | } |
| 3806 | |
| 3807 | } |
| 3808 | |
| 3809 | |
| 3810 | @Override |
| 3811 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3812 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3813 | final long identity = Binder.clearCallingIdentity(); |
| 3814 | try { |
| 3815 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3816 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3817 | return true; |
| 3818 | } |
| 3819 | |
| 3820 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3821 | switch (capability) { |
| 3822 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3823 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3824 | return ims.isEabProvisionedOnDevice(); |
| 3825 | |
| 3826 | default: { |
| 3827 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3828 | + "capability '" + capability + "', which does not require " |
| 3829 | + "provisioning."); |
| 3830 | } |
| 3831 | } |
| 3832 | |
| 3833 | } finally { |
| 3834 | Binder.restoreCallingIdentity(identity); |
| 3835 | } |
| 3836 | } |
| 3837 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3838 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3839 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3840 | boolean isProvisioned) { |
| 3841 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3842 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3843 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3844 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3845 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3846 | final long identity = Binder.clearCallingIdentity(); |
| 3847 | try { |
| 3848 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3849 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3850 | return; |
| 3851 | } |
| 3852 | |
| 3853 | // this capability requires provisioning, route to the correct API. |
| 3854 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3855 | switch (capability) { |
| 3856 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3857 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3858 | ims.setVolteProvisioned(isProvisioned); |
| 3859 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3860 | ims.setWfcProvisioned(isProvisioned); |
| 3861 | } |
| 3862 | break; |
| 3863 | } |
| 3864 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3865 | // There is currently no difference in VT provisioning type. |
| 3866 | ims.setVtProvisioned(isProvisioned); |
| 3867 | break; |
| 3868 | } |
| 3869 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3870 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3871 | // change the capability of the feature instead if needed. |
| 3872 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3873 | == isProvisioned) { |
| 3874 | // No change in provisioning. |
| 3875 | return; |
| 3876 | } |
| 3877 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3878 | try { |
| 3879 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3880 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3881 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3882 | + ", Exception" + e.getMessage()); |
| 3883 | } |
| 3884 | break; |
| 3885 | } |
| 3886 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3887 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3888 | + "MmTel capability '" + capability + "', which does not require " |
| 3889 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3890 | } |
| 3891 | } |
| 3892 | |
| 3893 | } finally { |
| 3894 | Binder.restoreCallingIdentity(identity); |
| 3895 | } |
| 3896 | } |
| 3897 | |
| 3898 | @Override |
| 3899 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3900 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3901 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3902 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3903 | } |
| 3904 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3905 | final long identity = Binder.clearCallingIdentity(); |
| 3906 | try { |
| 3907 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3908 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3909 | return true; |
| 3910 | } |
| 3911 | |
| 3912 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3913 | switch (capability) { |
| 3914 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3915 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3916 | return ims.isVolteProvisionedOnDevice(); |
| 3917 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3918 | return ims.isWfcProvisionedOnDevice(); |
| 3919 | } |
| 3920 | // This should never happen, since we are checking tech above to make sure it |
| 3921 | // is either LTE or IWLAN. |
| 3922 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3923 | + "capability."); |
| 3924 | } |
| 3925 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3926 | // There is currently no difference in VT provisioning type. |
| 3927 | return ims.isVtProvisionedOnDevice(); |
| 3928 | } |
| 3929 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3930 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3931 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3932 | } |
| 3933 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3934 | throw new IllegalArgumentException( |
| 3935 | "Tried to get provisioning for MmTel capability '" + capability |
| 3936 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3937 | } |
| 3938 | } |
| 3939 | |
| 3940 | } finally { |
| 3941 | Binder.restoreCallingIdentity(identity); |
| 3942 | } |
| 3943 | } |
| 3944 | |
| 3945 | @Override |
| 3946 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3947 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3948 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3949 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3950 | } |
| 3951 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3952 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3953 | return (provisionedBits & capability) > 0; |
| 3954 | } |
| 3955 | |
| 3956 | @Override |
| 3957 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3958 | boolean isProvisioned) { |
| 3959 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3960 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3961 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3962 | } |
| 3963 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3964 | "setProvisioningStatusForCapability"); |
| 3965 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3966 | // If the current provisioning status for capability already matches isProvisioned, |
| 3967 | // do nothing. |
| 3968 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3969 | return; |
| 3970 | } |
| 3971 | if (isProvisioned) { |
| 3972 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3973 | } else { |
| 3974 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3975 | } |
| 3976 | } |
| 3977 | |
| 3978 | /** |
| 3979 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3980 | * technology. The bitfield should mirror the bitfield defined by |
| 3981 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3982 | */ |
| 3983 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3984 | String key = getMmTelProvisioningKey(subId, tech); |
| 3985 | // Default is no capabilities are provisioned. |
| 3986 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3987 | } |
| 3988 | |
| 3989 | /** |
| 3990 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3991 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3992 | * technology specified. |
| 3993 | * |
| 3994 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3995 | */ |
| 3996 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3997 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3998 | String key = getMmTelProvisioningKey(subId, tech); |
| 3999 | editor.putInt(key, newField); |
| 4000 | editor.commit(); |
| 4001 | } |
| 4002 | |
| 4003 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4004 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4005 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4006 | } |
| 4007 | |
| 4008 | /** |
| 4009 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4010 | * carrier associated with the subscription id. |
| 4011 | */ |
| 4012 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4013 | int capability) { |
| 4014 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4015 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4016 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4017 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4018 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4019 | false); |
| 4020 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4021 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4022 | |
| 4023 | // First check to make sure that the capability requires provisioning. |
| 4024 | switch (capability) { |
| 4025 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4026 | // intentional fallthrough |
| 4027 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4028 | if (requireVoiceVtProvisioning) { |
| 4029 | // Voice and Video requires provisioning |
| 4030 | return true; |
| 4031 | } |
| 4032 | break; |
| 4033 | } |
| 4034 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4035 | if (requireUtProvisioning) { |
| 4036 | // UT requires provisioning |
| 4037 | return true; |
| 4038 | } |
| 4039 | break; |
| 4040 | } |
| 4041 | } |
| 4042 | return false; |
| 4043 | } |
| 4044 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4045 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4046 | int capability) { |
| 4047 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4048 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4049 | |
| 4050 | boolean requireRcsProvisioning = c.getBoolean( |
| 4051 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4052 | |
| 4053 | // First check to make sure that the capability requires provisioning. |
| 4054 | switch (capability) { |
| 4055 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4056 | // intentional fallthrough |
| 4057 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4058 | if (requireRcsProvisioning) { |
| 4059 | // OPTION or PRESENCE requires provisioning |
| 4060 | return true; |
| 4061 | } |
| 4062 | break; |
| 4063 | } |
| 4064 | } |
| 4065 | return false; |
| 4066 | } |
| 4067 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4068 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4069 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4070 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4071 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4072 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4073 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4074 | final long identity = Binder.clearCallingIdentity(); |
| 4075 | try { |
| 4076 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4077 | int slotId = getSlotIndex(subId); |
| 4078 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4079 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4080 | + subId + "' for key:" + key); |
| 4081 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4082 | } |
| 4083 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4084 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4085 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4086 | + subId + "' for key:" + key); |
| 4087 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4088 | } finally { |
| 4089 | Binder.restoreCallingIdentity(identity); |
| 4090 | } |
| 4091 | } |
| 4092 | |
| 4093 | @Override |
| 4094 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4095 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4096 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4097 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4098 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4099 | final long identity = Binder.clearCallingIdentity(); |
| 4100 | try { |
| 4101 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4102 | int slotId = getSlotIndex(subId); |
| 4103 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4104 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4105 | + subId + "' for key:" + key); |
| 4106 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4107 | } |
| 4108 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4109 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4110 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4111 | + subId + "' for key:" + key); |
| 4112 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4113 | } finally { |
| 4114 | Binder.restoreCallingIdentity(identity); |
| 4115 | } |
| 4116 | } |
| 4117 | |
| 4118 | @Override |
| 4119 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4120 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4121 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4122 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4123 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4124 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4125 | final long identity = Binder.clearCallingIdentity(); |
| 4126 | try { |
| 4127 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4128 | int slotId = getSlotIndex(subId); |
| 4129 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4130 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4131 | + subId + "' for key:" + key); |
| 4132 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4133 | } |
| 4134 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4135 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4136 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4137 | + "' for key:" + key); |
| 4138 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4139 | } finally { |
| 4140 | Binder.restoreCallingIdentity(identity); |
| 4141 | } |
| 4142 | } |
| 4143 | |
| 4144 | @Override |
| 4145 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4146 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4147 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4148 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4149 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4150 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4151 | final long identity = Binder.clearCallingIdentity(); |
| 4152 | try { |
| 4153 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4154 | int slotId = getSlotIndex(subId); |
| 4155 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4156 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4157 | + subId + "' for key:" + key); |
| 4158 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4159 | } |
| 4160 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4161 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4162 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4163 | + "' for key:" + key); |
| 4164 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4165 | } finally { |
| 4166 | Binder.restoreCallingIdentity(identity); |
| 4167 | } |
| 4168 | } |
| 4169 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4170 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4171 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4172 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4173 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4174 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4175 | } |
| 4176 | return slotId; |
| 4177 | } |
| 4178 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4179 | private int getSlotIndex(int subId) { |
| 4180 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4181 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4182 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4183 | } |
| 4184 | return slotId; |
| 4185 | } |
| 4186 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4187 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4188 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4189 | */ |
| 4190 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4191 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4192 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4193 | final int targetSdk = getTargetSdk(callingPackage); |
| 4194 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4195 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4196 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4197 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4198 | mApp, subId, callingPackage, callingFeatureId, |
| 4199 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4200 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4201 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4202 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4203 | final long identity = Binder.clearCallingIdentity(); |
| 4204 | try { |
| 4205 | final Phone phone = getPhone(subId); |
| 4206 | if (phone != null) { |
| 4207 | return phone.getServiceState().getDataNetworkType(); |
| 4208 | } else { |
| 4209 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4210 | } |
| 4211 | } finally { |
| 4212 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4213 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4214 | } |
| 4215 | |
| 4216 | /** |
| 4217 | * Returns the data network type |
| 4218 | */ |
| 4219 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4220 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4221 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4222 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | /** |
| 4226 | * Returns the data network type for a subId |
| 4227 | */ |
| 4228 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4229 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4230 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4231 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4232 | mApp, subId, callingPackage, callingFeatureId, |
| 4233 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4234 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4235 | } |
| 4236 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4237 | final long identity = Binder.clearCallingIdentity(); |
| 4238 | try { |
| 4239 | final Phone phone = getPhone(subId); |
| 4240 | if (phone != null) { |
| 4241 | return phone.getServiceState().getDataNetworkType(); |
| 4242 | } else { |
| 4243 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4244 | } |
| 4245 | } finally { |
| 4246 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4247 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4248 | } |
| 4249 | |
| 4250 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4251 | * Returns the Voice network type for a subId |
| 4252 | */ |
| 4253 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4254 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4255 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4256 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4257 | mApp, subId, callingPackage, callingFeatureId, |
| 4258 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4259 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4260 | } |
| 4261 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4262 | final long identity = Binder.clearCallingIdentity(); |
| 4263 | try { |
| 4264 | final Phone phone = getPhone(subId); |
| 4265 | if (phone != null) { |
| 4266 | return phone.getServiceState().getVoiceNetworkType(); |
| 4267 | } else { |
| 4268 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4269 | } |
| 4270 | } finally { |
| 4271 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4272 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4273 | } |
| 4274 | |
| 4275 | /** |
| 4276 | * @return true if a ICC card is present |
| 4277 | */ |
| 4278 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4279 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4280 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4281 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4282 | } |
| 4283 | |
| 4284 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4285 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4286 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4287 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4288 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4289 | final long identity = Binder.clearCallingIdentity(); |
| 4290 | try { |
| 4291 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4292 | if (phone != null) { |
| 4293 | return phone.getIccCard().hasIccCard(); |
| 4294 | } else { |
| 4295 | return false; |
| 4296 | } |
| 4297 | } finally { |
| 4298 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4299 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4300 | } |
| 4301 | |
| 4302 | /** |
| 4303 | * Return if the current radio is LTE on CDMA. This |
| 4304 | * is a tri-state return value as for a period of time |
| 4305 | * the mode may be unknown. |
| 4306 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4307 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4308 | * @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] | 4309 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4310 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4311 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4312 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4313 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4314 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4315 | } |
| 4316 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4317 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4318 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4319 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4320 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4321 | mApp, subId, callingPackage, callingFeatureId, |
| 4322 | "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4323 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4324 | } |
| 4325 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4326 | final long identity = Binder.clearCallingIdentity(); |
| 4327 | try { |
| 4328 | final Phone phone = getPhone(subId); |
| 4329 | if (phone == null) { |
| 4330 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4331 | } else { |
| 4332 | return phone.getLteOnCdmaMode(); |
| 4333 | } |
| 4334 | } finally { |
| 4335 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4336 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4337 | } |
| 4338 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4339 | /** |
| 4340 | * {@hide} |
| 4341 | * Returns Default subId, 0 in the case of single standby. |
| 4342 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4343 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4344 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4345 | } |
| 4346 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4347 | private int getSlotForDefaultSubscription() { |
| 4348 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4349 | } |
| 4350 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4351 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4352 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4353 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4354 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4355 | private boolean isActiveSubscription(int subId) { |
| 4356 | return mSubscriptionController.isActiveSubId(subId); |
| 4357 | } |
| 4358 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4359 | /** |
| 4360 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4361 | */ |
| 4362 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4363 | final long identity = Binder.clearCallingIdentity(); |
| 4364 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4365 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4366 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4367 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4368 | } finally { |
| 4369 | Binder.restoreCallingIdentity(identity); |
| 4370 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4371 | } |
| 4372 | |
| 4373 | /** |
| 4374 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4375 | */ |
| 4376 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4377 | final long identity = Binder.clearCallingIdentity(); |
| 4378 | try { |
| 4379 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4380 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4381 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4382 | } finally { |
| 4383 | Binder.restoreCallingIdentity(identity); |
| 4384 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4385 | } |
| 4386 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4387 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4388 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4389 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4390 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4391 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4392 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4393 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4394 | if (phoneId == -1) { |
| 4395 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4396 | + " does not correspond to an active phone"); |
| 4397 | } |
| 4398 | return PhoneFactory.getPhone(phoneId); |
| 4399 | } |
| 4400 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4401 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4402 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4403 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4404 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4405 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4406 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4407 | if (DBG) { |
| 4408 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4409 | } |
| 4410 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4411 | p2); |
| 4412 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4413 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4414 | |
| 4415 | @Override |
| 4416 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4417 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4418 | enforceModifyPermission(); |
| 4419 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4420 | if (DBG) { |
| 4421 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4422 | } |
| 4423 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4424 | callingPackage, aid, p2); |
| 4425 | } |
| 4426 | |
| 4427 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4428 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4429 | final long identity = Binder.clearCallingIdentity(); |
| 4430 | try { |
| 4431 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4432 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4433 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4434 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4435 | if (bestComponent == null |
| 4436 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4437 | loge("The calling package is not allowed to access ISD-R."); |
| 4438 | throw new SecurityException( |
| 4439 | "The calling package is not allowed to access ISD-R."); |
| 4440 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4441 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4442 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4443 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4444 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4445 | null /* workSource */); |
| 4446 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4447 | return response; |
| 4448 | } finally { |
| 4449 | Binder.restoreCallingIdentity(identity); |
| 4450 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4451 | } |
| 4452 | |
| 4453 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4454 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4455 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4456 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4457 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4458 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4459 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4460 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4461 | @Override |
| 4462 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4463 | enforceModifyPermission(); |
| 4464 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4465 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4466 | channel); |
| 4467 | } |
| 4468 | |
| 4469 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4470 | final long identity = Binder.clearCallingIdentity(); |
| 4471 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4472 | if (channel < 0) { |
| 4473 | return false; |
| 4474 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4475 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4476 | null /* workSource */); |
| 4477 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4478 | return success; |
| 4479 | } finally { |
| 4480 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4481 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4482 | } |
| 4483 | |
| 4484 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4485 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4486 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4487 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4488 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4489 | if (DBG) { |
| 4490 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4491 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4492 | + p3 + " data=" + data); |
| 4493 | } |
| 4494 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4495 | command, p1, p2, p3, data); |
| 4496 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4497 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4498 | @Override |
| 4499 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4500 | int command, int p1, int p2, int p3, String data) { |
| 4501 | enforceModifyPermission(); |
| 4502 | if (DBG) { |
| 4503 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4504 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4505 | + p3 + " data=" + data); |
| 4506 | } |
| 4507 | return iccTransmitApduLogicalChannelWithPermission( |
| 4508 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4509 | data); |
| 4510 | } |
| 4511 | |
| 4512 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4513 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4514 | final long identity = Binder.clearCallingIdentity(); |
| 4515 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4516 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4517 | return ""; |
| 4518 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4519 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4520 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4521 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4522 | null /* workSource */); |
| 4523 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4524 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4525 | // Append the returned status code to the end of the response payload. |
| 4526 | String s = Integer.toHexString( |
| 4527 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4528 | if (response.payload != null) { |
| 4529 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4530 | } |
| 4531 | return s; |
| 4532 | } finally { |
| 4533 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4534 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4535 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4536 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4537 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4538 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4539 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4540 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4541 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4542 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4543 | if (DBG) { |
| 4544 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4545 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4546 | } |
| 4547 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4548 | cla, command, p1, p2, p3, data); |
| 4549 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4550 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4551 | @Override |
| 4552 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4553 | int command, int p1, int p2, int p3, String data) { |
| 4554 | enforceModifyPermission(); |
| 4555 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4556 | if (DBG) { |
| 4557 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4558 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4559 | + " data=" + data); |
| 4560 | } |
| 4561 | |
| 4562 | return iccTransmitApduBasicChannelWithPermission( |
| 4563 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4564 | p2, p3, data); |
| 4565 | } |
| 4566 | |
| 4567 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4568 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4569 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4570 | final long identity = Binder.clearCallingIdentity(); |
| 4571 | try { |
| 4572 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4573 | && TextUtils.equals(ISDR_AID, data)) { |
| 4574 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4575 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4576 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4577 | if (bestComponent == null |
| 4578 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4579 | loge("The calling package is not allowed to select ISD-R."); |
| 4580 | throw new SecurityException( |
| 4581 | "The calling package is not allowed to select ISD-R."); |
| 4582 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4583 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4584 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4585 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4586 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4587 | null /* workSource */); |
| 4588 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4589 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4590 | // Append the returned status code to the end of the response payload. |
| 4591 | String s = Integer.toHexString( |
| 4592 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4593 | if (response.payload != null) { |
| 4594 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4595 | } |
| 4596 | return s; |
| 4597 | } finally { |
| 4598 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4599 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4603 | 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] | 4604 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4605 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4606 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4607 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4608 | final long identity = Binder.clearCallingIdentity(); |
| 4609 | try { |
| 4610 | if (DBG) { |
| 4611 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4612 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4613 | } |
| 4614 | |
| 4615 | IccIoResult response = |
| 4616 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4617 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4618 | subId); |
| 4619 | |
| 4620 | if (DBG) { |
| 4621 | log("Exchange SIM_IO [R]" + response); |
| 4622 | } |
| 4623 | |
| 4624 | byte[] result = null; |
| 4625 | int length = 2; |
| 4626 | if (response.payload != null) { |
| 4627 | length = 2 + response.payload.length; |
| 4628 | result = new byte[length]; |
| 4629 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4630 | } else { |
| 4631 | result = new byte[length]; |
| 4632 | } |
| 4633 | |
| 4634 | result[length - 1] = (byte) response.sw2; |
| 4635 | result[length - 2] = (byte) response.sw1; |
| 4636 | return result; |
| 4637 | } finally { |
| 4638 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4639 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4640 | } |
| 4641 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4642 | /** |
| 4643 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4644 | * on a particular subscription |
| 4645 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4646 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4647 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4648 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4649 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4650 | return null; |
| 4651 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4652 | |
| 4653 | final long identity = Binder.clearCallingIdentity(); |
| 4654 | try { |
| 4655 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4656 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4657 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4658 | return null; |
| 4659 | } |
| 4660 | Object response = sendRequest( |
| 4661 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4662 | if (response instanceof String[]) { |
| 4663 | return (String[]) response; |
| 4664 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4665 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4666 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4667 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4668 | } finally { |
| 4669 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4670 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4671 | } |
| 4672 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4673 | /** |
| 4674 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4675 | * subscription. |
| 4676 | * |
| 4677 | * @param subId the id of the subscription. |
| 4678 | * @param appType the uicc app type, must be USIM or SIM. |
| 4679 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4680 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4681 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4682 | * @return number of fplmns that is successfully written to the SIM. |
| 4683 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4684 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4685 | String callingFeatureId) { |
| 4686 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4687 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4688 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4689 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4690 | } |
| 4691 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4692 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4693 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4694 | } |
| 4695 | if (fplmns == null) { |
| 4696 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4697 | } |
| 4698 | for (String fplmn : fplmns) { |
| 4699 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4700 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4701 | } |
| 4702 | } |
| 4703 | final long identity = Binder.clearCallingIdentity(); |
| 4704 | try { |
| 4705 | Object response = sendRequest( |
| 4706 | CMD_SET_FORBIDDEN_PLMNS, |
| 4707 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4708 | subId); |
| 4709 | return (int) response; |
| 4710 | } finally { |
| 4711 | Binder.restoreCallingIdentity(identity); |
| 4712 | } |
| 4713 | } |
| 4714 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4715 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4716 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4717 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4718 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4719 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4720 | final long identity = Binder.clearCallingIdentity(); |
| 4721 | try { |
| 4722 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4723 | if (response.payload == null) { |
| 4724 | return ""; |
| 4725 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4726 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4727 | // Append the returned status code to the end of the response payload. |
| 4728 | String s = Integer.toHexString( |
| 4729 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4730 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4731 | return s; |
| 4732 | } finally { |
| 4733 | Binder.restoreCallingIdentity(identity); |
| 4734 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4735 | } |
| 4736 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4737 | /** |
| 4738 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4739 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4740 | * |
| 4741 | * @param itemID the ID of the item to read |
| 4742 | * @return the NV item as a String, or null on error. |
| 4743 | */ |
| 4744 | @Override |
| 4745 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4746 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4747 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4748 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4749 | |
| 4750 | final long identity = Binder.clearCallingIdentity(); |
| 4751 | try { |
| 4752 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4753 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4754 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4755 | return value; |
| 4756 | } finally { |
| 4757 | Binder.restoreCallingIdentity(identity); |
| 4758 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4759 | } |
| 4760 | |
| 4761 | /** |
| 4762 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4763 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4764 | * |
| 4765 | * @param itemID the ID of the item to read |
| 4766 | * @param itemValue the value to write, as a String |
| 4767 | * @return true on success; false on any failure |
| 4768 | */ |
| 4769 | @Override |
| 4770 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4771 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4772 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4773 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4774 | |
| 4775 | final long identity = Binder.clearCallingIdentity(); |
| 4776 | try { |
| 4777 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4778 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4779 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4780 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4781 | return success; |
| 4782 | } finally { |
| 4783 | Binder.restoreCallingIdentity(identity); |
| 4784 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4785 | } |
| 4786 | |
| 4787 | /** |
| 4788 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4789 | * Used for device configuration by some CDMA operators. |
| 4790 | * |
| 4791 | * @param preferredRoamingList byte array containing the new PRL |
| 4792 | * @return true on success; false on any failure |
| 4793 | */ |
| 4794 | @Override |
| 4795 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4796 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4797 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4798 | |
| 4799 | final long identity = Binder.clearCallingIdentity(); |
| 4800 | try { |
| 4801 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4802 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4803 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4804 | return success; |
| 4805 | } finally { |
| 4806 | Binder.restoreCallingIdentity(identity); |
| 4807 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4808 | } |
| 4809 | |
| 4810 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4811 | * 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] | 4812 | * Used for device configuration by some CDMA operators. |
| 4813 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4814 | * @param slotIndex - device slot. |
| 4815 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4816 | * @return true on success; false on any failure |
| 4817 | */ |
| 4818 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4819 | public boolean resetModemConfig(int slotIndex) { |
| 4820 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4821 | if (phone != null) { |
| 4822 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4823 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4824 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4825 | final long identity = Binder.clearCallingIdentity(); |
| 4826 | try { |
| 4827 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4828 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4829 | return success; |
| 4830 | } finally { |
| 4831 | Binder.restoreCallingIdentity(identity); |
| 4832 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4833 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4834 | return false; |
| 4835 | } |
| 4836 | |
| 4837 | /** |
| 4838 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4839 | * |
| 4840 | * @param slotIndex - device slot. |
| 4841 | * |
| 4842 | * @return true on success; false on any failure |
| 4843 | */ |
| 4844 | @Override |
| 4845 | public boolean rebootModem(int slotIndex) { |
| 4846 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4847 | if (phone != null) { |
| 4848 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4849 | mApp, phone.getSubId(), "rebootModem"); |
| 4850 | |
| 4851 | final long identity = Binder.clearCallingIdentity(); |
| 4852 | try { |
| 4853 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4854 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4855 | return success; |
| 4856 | } finally { |
| 4857 | Binder.restoreCallingIdentity(identity); |
| 4858 | } |
| 4859 | } |
| 4860 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4861 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4862 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4863 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4864 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4865 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4866 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4867 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4868 | return new String[0]; |
| 4869 | } |
| 4870 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4871 | final long identity = Binder.clearCallingIdentity(); |
| 4872 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4873 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4874 | } finally { |
| 4875 | Binder.restoreCallingIdentity(identity); |
| 4876 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4877 | } |
| 4878 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4879 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 4880 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 4881 | * {@link #disableIms(int)}. |
| 4882 | * @param slotIndex device slot. |
| 4883 | */ |
| 4884 | public void resetIms(int slotIndex) { |
| 4885 | enforceModifyPermission(); |
| 4886 | |
| 4887 | final long identity = Binder.clearCallingIdentity(); |
| 4888 | try { |
| 4889 | if (mImsResolver == null) { |
| 4890 | // may happen if the does not support IMS. |
| 4891 | return; |
| 4892 | } |
| 4893 | mImsResolver.disableIms(slotIndex); |
| 4894 | mImsResolver.enableIms(slotIndex); |
| 4895 | } finally { |
| 4896 | Binder.restoreCallingIdentity(identity); |
| 4897 | } |
| 4898 | } |
| 4899 | |
| 4900 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4901 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4902 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4903 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4904 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4905 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4906 | |
| 4907 | final long identity = Binder.clearCallingIdentity(); |
| 4908 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4909 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4910 | // may happen if the device does not support IMS. |
| 4911 | return; |
| 4912 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4913 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4914 | } finally { |
| 4915 | Binder.restoreCallingIdentity(identity); |
| 4916 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4917 | } |
| 4918 | |
| 4919 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4920 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4921 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4922 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4923 | public void disableIms(int slotId) { |
| 4924 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4925 | |
| 4926 | final long identity = Binder.clearCallingIdentity(); |
| 4927 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4928 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4929 | // may happen if the device does not support IMS. |
| 4930 | return; |
| 4931 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4932 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4933 | } finally { |
| 4934 | Binder.restoreCallingIdentity(identity); |
| 4935 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4936 | } |
| 4937 | |
| 4938 | /** |
| 4939 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4940 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4941 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4942 | */ |
| 4943 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4944 | IImsServiceFeatureCallback callback) { |
| 4945 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4946 | |
| 4947 | final long identity = Binder.clearCallingIdentity(); |
| 4948 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4949 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4950 | // may happen if the device does not support IMS. |
| 4951 | return null; |
| 4952 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4953 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4954 | } finally { |
| 4955 | Binder.restoreCallingIdentity(identity); |
| 4956 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4957 | } |
| 4958 | |
| 4959 | /** |
| 4960 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4961 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4962 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4963 | * listener for feature updates. |
| 4964 | */ |
| 4965 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4966 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4967 | |
| 4968 | final long identity = Binder.clearCallingIdentity(); |
| 4969 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4970 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4971 | // may happen if the device does not support IMS. |
| 4972 | return null; |
| 4973 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4974 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4975 | } finally { |
| 4976 | Binder.restoreCallingIdentity(identity); |
| 4977 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4978 | } |
| 4979 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4980 | /** |
| 4981 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4982 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4983 | */ |
| 4984 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4985 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4986 | |
| 4987 | final long identity = Binder.clearCallingIdentity(); |
| 4988 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4989 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4990 | // may happen if the device does not support IMS. |
| 4991 | return null; |
| 4992 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4993 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4994 | } finally { |
| 4995 | Binder.restoreCallingIdentity(identity); |
| 4996 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4997 | } |
| 4998 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4999 | /** |
| 5000 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5001 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5002 | */ |
| 5003 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5004 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5005 | |
| 5006 | final long identity = Binder.clearCallingIdentity(); |
| 5007 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5008 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5009 | // may happen if the device does not support IMS. |
| 5010 | return null; |
| 5011 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5012 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5013 | } finally { |
| 5014 | Binder.restoreCallingIdentity(identity); |
| 5015 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5016 | } |
| 5017 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5018 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5019 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5020 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5021 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5022 | * @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] | 5023 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5024 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5025 | * @param packageName The name of the package that the current configuration will be replaced |
| 5026 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5027 | * @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] | 5028 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5029 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5030 | int[] featureTypes, String packageName) { |
| 5031 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5032 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5033 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5034 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5035 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5036 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5037 | final long identity = Binder.clearCallingIdentity(); |
| 5038 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5039 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5040 | // may happen if the device does not support IMS. |
| 5041 | return false; |
| 5042 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5043 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5044 | for (int featureType : featureTypes) { |
| 5045 | featureConfig.put(featureType, packageName); |
| 5046 | } |
| 5047 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5048 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5049 | } finally { |
| 5050 | Binder.restoreCallingIdentity(identity); |
| 5051 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5052 | } |
| 5053 | |
| 5054 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5055 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5056 | * |
| 5057 | * @param slotId The slot that the ImsService is associated with. |
| 5058 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5059 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5060 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5061 | * @return the package name of the ImsService configuration. |
| 5062 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5063 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5064 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5065 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5066 | TelephonyPermissions |
| 5067 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5068 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5069 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5070 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5071 | final long identity = Binder.clearCallingIdentity(); |
| 5072 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5073 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5074 | // may happen if the device does not support IMS. |
| 5075 | return ""; |
| 5076 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5077 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5078 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5079 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5080 | } finally { |
| 5081 | Binder.restoreCallingIdentity(identity); |
| 5082 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5083 | } |
| 5084 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5085 | /** |
| 5086 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5087 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5088 | * @param callback A callback with an integer containing the |
| 5089 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5090 | */ |
| 5091 | @Override |
| 5092 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5093 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5094 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5095 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5096 | "IMS not available on device."); |
| 5097 | } |
| 5098 | final long token = Binder.clearCallingIdentity(); |
| 5099 | try { |
| 5100 | int slotId = getSlotIndex(subId); |
| 5101 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5102 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5103 | + subId + "'"); |
| 5104 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5105 | } |
| 5106 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5107 | try { |
| 5108 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5109 | } catch (RemoteException e) { |
| 5110 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5111 | + "Ignore"); |
| 5112 | } |
| 5113 | }); |
| 5114 | } finally { |
| 5115 | Binder.restoreCallingIdentity(token); |
| 5116 | } |
| 5117 | } |
| 5118 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5119 | public void setImsRegistrationState(boolean registered) { |
| 5120 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5121 | |
| 5122 | final long identity = Binder.clearCallingIdentity(); |
| 5123 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5124 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5125 | } finally { |
| 5126 | Binder.restoreCallingIdentity(identity); |
| 5127 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5128 | } |
| 5129 | |
| 5130 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5131 | * Set the network selection mode to automatic. |
| 5132 | * |
| 5133 | */ |
| 5134 | @Override |
| 5135 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5136 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5137 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5138 | |
| 5139 | final long identity = Binder.clearCallingIdentity(); |
| 5140 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5141 | if (!isActiveSubscription(subId)) { |
| 5142 | return; |
| 5143 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5144 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5145 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5146 | } finally { |
| 5147 | Binder.restoreCallingIdentity(identity); |
| 5148 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5149 | } |
| 5150 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5151 | /** |
| 5152 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5153 | * |
| 5154 | * @param subId the id of the subscription. |
| 5155 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5156 | * the operator to attach to. |
| 5157 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5158 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5159 | * normal network selection next time. |
| 5160 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5161 | */ |
| 5162 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5163 | public boolean setNetworkSelectionModeManual( |
| 5164 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5165 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5166 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5167 | |
| 5168 | if (!isActiveSubscription(subId)) { |
| 5169 | return false; |
| 5170 | } |
| 5171 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5172 | final long identity = Binder.clearCallingIdentity(); |
| 5173 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5174 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5175 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5176 | if (DBG) { |
| 5177 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5178 | + " operator: " + operatorInfo); |
| 5179 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5180 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5181 | } finally { |
| 5182 | Binder.restoreCallingIdentity(identity); |
| 5183 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5184 | } |
| 5185 | |
| 5186 | /** |
| 5187 | * Scans for available networks. |
| 5188 | */ |
| 5189 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5190 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5191 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5192 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5193 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5194 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5195 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5196 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5197 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5198 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5199 | .setCallingPid(Binder.getCallingPid()) |
| 5200 | .setCallingUid(Binder.getCallingUid()) |
| 5201 | .setMethod("getCellNetworkScanResults") |
| 5202 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5203 | .build()); |
| 5204 | switch (locationResult) { |
| 5205 | case DENIED_HARD: |
| 5206 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5207 | case DENIED_SOFT: |
| 5208 | return null; |
| 5209 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5210 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5211 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5212 | try { |
| 5213 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5214 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5215 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5216 | } finally { |
| 5217 | Binder.restoreCallingIdentity(identity); |
| 5218 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5219 | } |
| 5220 | |
| 5221 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5222 | * Get the call forwarding info, given the call forwarding reason. |
| 5223 | */ |
| 5224 | @Override |
| 5225 | public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) { |
| 5226 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5227 | long identity = Binder.clearCallingIdentity(); |
| 5228 | try { |
| 5229 | if (DBG) { |
| 5230 | log("getCallForwarding: subId " + subId |
| 5231 | + " callForwardingReason" + callForwardingReason); |
| 5232 | } |
| 5233 | return (CallForwardingInfo) sendRequest( |
| 5234 | CMD_GET_CALL_FORWARDING, callForwardingReason, subId); |
| 5235 | } finally { |
| 5236 | Binder.restoreCallingIdentity(identity); |
| 5237 | } |
| 5238 | } |
| 5239 | |
| 5240 | /** |
| 5241 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5242 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5243 | */ |
| 5244 | @Override |
| 5245 | public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) { |
| 5246 | enforceModifyPermission(); |
| 5247 | long identity = Binder.clearCallingIdentity(); |
| 5248 | try { |
| 5249 | if (DBG) { |
| 5250 | log("setCallForwarding: subId " + subId |
| 5251 | + " callForwardingInfo" + callForwardingInfo); |
| 5252 | } |
| 5253 | return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId); |
| 5254 | } finally { |
| 5255 | Binder.restoreCallingIdentity(identity); |
| 5256 | } |
| 5257 | } |
| 5258 | |
| 5259 | /** |
| 5260 | * Get the call forwarding info, given the call forwarding reason. |
| 5261 | */ |
| 5262 | @Override |
| 5263 | public int getCallWaitingStatus(int subId) { |
| 5264 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5265 | long identity = Binder.clearCallingIdentity(); |
| 5266 | try { |
| 5267 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 5268 | return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId); |
| 5269 | } finally { |
| 5270 | Binder.restoreCallingIdentity(identity); |
| 5271 | } |
| 5272 | } |
| 5273 | |
| 5274 | /** |
| 5275 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5276 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5277 | */ |
| 5278 | @Override |
| 5279 | public boolean setCallWaitingStatus(int subId, boolean isEnable) { |
| 5280 | enforceModifyPermission(); |
| 5281 | long identity = Binder.clearCallingIdentity(); |
| 5282 | try { |
| 5283 | if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable); |
| 5284 | return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId); |
| 5285 | } finally { |
| 5286 | Binder.restoreCallingIdentity(identity); |
| 5287 | } |
| 5288 | } |
| 5289 | |
| 5290 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5291 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5292 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5293 | * @param subId id of the subscription |
| 5294 | * @param request contains the radio access networks with bands/channels to scan |
| 5295 | * @param messenger callback messenger for scan results or errors |
| 5296 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5297 | * @return the id of the requested scan which can be used to stop the scan. |
| 5298 | */ |
| 5299 | @Override |
| 5300 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5301 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5302 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5303 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5304 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5305 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5306 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5307 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5308 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5309 | .setCallingPid(Binder.getCallingPid()) |
| 5310 | .setCallingUid(Binder.getCallingUid()) |
| 5311 | .setMethod("requestNetworkScan") |
| 5312 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5313 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5314 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5315 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5316 | if (e != null) { |
| 5317 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5318 | throw e; |
| 5319 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5320 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5321 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5322 | } |
| 5323 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5324 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5325 | int callingUid = Binder.getCallingUid(); |
| 5326 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5327 | final long identity = Binder.clearCallingIdentity(); |
| 5328 | try { |
| 5329 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5330 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5331 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5332 | } finally { |
| 5333 | Binder.restoreCallingIdentity(identity); |
| 5334 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5335 | } |
| 5336 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5337 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5338 | NetworkScanRequest request, int subId) { |
| 5339 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5340 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5341 | boolean hasNetworkScanPermission = |
| 5342 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5343 | == PERMISSION_GRANTED; |
| 5344 | |
| 5345 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5346 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5347 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5351 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5352 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5353 | return new SecurityException("Specific channels must not be" |
| 5354 | + " scanned without location access."); |
| 5355 | } |
| 5356 | } |
| 5357 | } |
| 5358 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5359 | return null; |
| 5360 | } |
| 5361 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5362 | /** |
| 5363 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5364 | * |
| 5365 | * @param subId id of the subscription |
| 5366 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5367 | */ |
| 5368 | @Override |
| 5369 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5370 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5371 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5372 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5373 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5374 | final long identity = Binder.clearCallingIdentity(); |
| 5375 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5376 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5377 | } finally { |
| 5378 | Binder.restoreCallingIdentity(identity); |
| 5379 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5383 | * Get the calculated preferred network type. |
| 5384 | * Used for debugging incorrect network type. |
| 5385 | * |
| 5386 | * @return the preferred network type, defined in RILConstants.java. |
| 5387 | */ |
| 5388 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5389 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5390 | final Phone defaultPhone = getDefaultPhone(); |
| 5391 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5392 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5393 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5394 | } |
| 5395 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5396 | final long identity = Binder.clearCallingIdentity(); |
| 5397 | try { |
| 5398 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5399 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5400 | } finally { |
| 5401 | Binder.restoreCallingIdentity(identity); |
| 5402 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5403 | } |
| 5404 | |
| 5405 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5406 | * Get the preferred network type. |
| 5407 | * Used for device configuration by some CDMA operators. |
| 5408 | * |
| 5409 | * @return the preferred network type, defined in RILConstants.java. |
| 5410 | */ |
| 5411 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5412 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5413 | TelephonyPermissions |
| 5414 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5415 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5416 | |
| 5417 | final long identity = Binder.clearCallingIdentity(); |
| 5418 | try { |
| 5419 | if (DBG) log("getPreferredNetworkType"); |
| 5420 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5421 | int networkType = (result != null ? result[0] : -1); |
| 5422 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5423 | return networkType; |
| 5424 | } finally { |
| 5425 | Binder.restoreCallingIdentity(identity); |
| 5426 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5427 | } |
| 5428 | |
| 5429 | /** |
| 5430 | * Set the preferred network type. |
| 5431 | * Used for device configuration by some CDMA operators. |
| 5432 | * |
| 5433 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5434 | * @return true on success; false on any failure. |
| 5435 | */ |
| 5436 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5437 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5438 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5439 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5440 | |
| 5441 | final long identity = Binder.clearCallingIdentity(); |
| 5442 | try { |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5443 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5444 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5445 | return setPreferredNetworkTypesInternal(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5446 | } finally { |
| 5447 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5448 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5449 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5450 | |
| 5451 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5452 | * Get the allowed network types that store in the telephony provider. |
| 5453 | * |
| 5454 | * @param subId the id of the subscription. |
| 5455 | * @return allowedNetworkTypes the allowed network types. |
| 5456 | */ |
| 5457 | @Override |
| 5458 | public long getAllowedNetworkTypes(int subId) { |
| 5459 | TelephonyPermissions |
| 5460 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5461 | mApp, subId, "getAllowedNetworkTypes"); |
| 5462 | |
| 5463 | final long identity = Binder.clearCallingIdentity(); |
| 5464 | try { |
| 5465 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5466 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5467 | } finally { |
| 5468 | Binder.restoreCallingIdentity(identity); |
| 5469 | } |
| 5470 | } |
| 5471 | |
| 5472 | /** |
| 5473 | * Set the allowed network types. |
| 5474 | * |
| 5475 | * @param subId the id of the subscription. |
| 5476 | * @param allowedNetworkTypes the allowed network types. |
| 5477 | * @return true on success; false on any failure. |
| 5478 | */ |
| 5479 | @Override |
| 5480 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5481 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5482 | mApp, subId, "setAllowedNetworkTypes"); |
| 5483 | final long identity = Binder.clearCallingIdentity(); |
| 5484 | try { |
| 5485 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5486 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5487 | String.valueOf(allowedNetworkTypes)); |
| 5488 | return setPreferredNetworkTypesInternal(subId); |
| 5489 | } finally { |
| 5490 | Binder.restoreCallingIdentity(identity); |
| 5491 | } |
| 5492 | } |
| 5493 | |
| 5494 | private boolean setPreferredNetworkTypesInternal(int subId) { |
| 5495 | long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType( |
| 5496 | Settings.Global.getInt(mApp.getContentResolver(), |
| 5497 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5498 | RILConstants.PREFERRED_NETWORK_MODE)); |
| 5499 | long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty( |
| 5500 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5501 | int networkMode = RadioAccessFamily.getNetworkTypeFromRaf( |
| 5502 | (int) (networkTypeBitMask & allowedNetworkTypes)); |
| 5503 | |
| 5504 | if (DBG) { |
| 5505 | log("setPreferredNetworkTypesInternal: subId " + subId |
| 5506 | + " networkTypes " + networkTypeBitMask |
| 5507 | + " allowedNetworkTypes " + allowedNetworkTypes |
| 5508 | + " networkMode " + networkMode); |
| 5509 | } |
| 5510 | |
| 5511 | Boolean success = (Boolean) sendRequest( |
| 5512 | CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId); |
| 5513 | if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail")); |
| 5514 | return success; |
| 5515 | } |
| 5516 | |
| 5517 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5518 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5519 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5520 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5521 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5522 | * @hide |
| 5523 | */ |
| 5524 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5525 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5526 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5527 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5528 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5529 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5530 | if (phone != null) { |
| 5531 | return phone.hasMatchedTetherApnSetting(); |
| 5532 | } else { |
| 5533 | return false; |
| 5534 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5535 | } finally { |
| 5536 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5537 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5538 | } |
| 5539 | |
| 5540 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5541 | * Set mobile data enabled |
| 5542 | * Used by the user through settings etc to turn on/off mobile data |
| 5543 | * |
| 5544 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5545 | */ |
| 5546 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5547 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5548 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5549 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5550 | |
| 5551 | final long identity = Binder.clearCallingIdentity(); |
| 5552 | try { |
| 5553 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5554 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5555 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5556 | if (phone != null) { |
| 5557 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5558 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5559 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5560 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5561 | } |
| 5562 | } finally { |
| 5563 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5564 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5565 | } |
| 5566 | |
| 5567 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5568 | * Enable or disable always reporting signal strength changes from radio. |
| 5569 | * |
| 5570 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5571 | */ |
| 5572 | @Override |
| 5573 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5574 | enforceModifyPermission(); |
| 5575 | enforceSystemCaller(); |
| 5576 | |
| 5577 | final long identity = Binder.clearCallingIdentity(); |
| 5578 | final Phone phone = getPhone(subId); |
| 5579 | try { |
| 5580 | if (phone != null) { |
| 5581 | if (DBG) { |
| 5582 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5583 | + " isEnable=" + isEnable); |
| 5584 | } |
| 5585 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5586 | } else { |
| 5587 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5588 | + subId); |
| 5589 | } |
| 5590 | } finally { |
| 5591 | Binder.restoreCallingIdentity(identity); |
| 5592 | } |
| 5593 | } |
| 5594 | |
| 5595 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5596 | * Get the user enabled state of Mobile Data. |
| 5597 | * |
| 5598 | * TODO: remove and use isUserDataEnabled. |
| 5599 | * This can't be removed now because some vendor codes |
| 5600 | * calls through ITelephony directly while they should |
| 5601 | * use TelephonyManager. |
| 5602 | * |
| 5603 | * @return true on enabled |
| 5604 | */ |
| 5605 | @Override |
| 5606 | public boolean getDataEnabled(int subId) { |
| 5607 | return isUserDataEnabled(subId); |
| 5608 | } |
| 5609 | |
| 5610 | /** |
| 5611 | * Get whether mobile data is enabled per user setting. |
| 5612 | * |
| 5613 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5614 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5615 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5616 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5617 | * |
| 5618 | * @return {@code true} if data is enabled else {@code false} |
| 5619 | */ |
| 5620 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5621 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5622 | try { |
| 5623 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5624 | null); |
| 5625 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5626 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5627 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5628 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5629 | |
| 5630 | final long identity = Binder.clearCallingIdentity(); |
| 5631 | try { |
| 5632 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5633 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5634 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5635 | if (phone != null) { |
| 5636 | boolean retVal = phone.isUserDataEnabled(); |
| 5637 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5638 | return retVal; |
| 5639 | } else { |
| 5640 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5641 | return false; |
| 5642 | } |
| 5643 | } finally { |
| 5644 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5645 | } |
| 5646 | } |
| 5647 | |
| 5648 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5649 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5650 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5651 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5652 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5653 | * @return {@code true} if the overall data connection is capable; {@code false} if not. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5654 | */ |
| 5655 | @Override |
| 5656 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5657 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5658 | |
| 5659 | final long identity = Binder.clearCallingIdentity(); |
| 5660 | try { |
| 5661 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5662 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5663 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5664 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5665 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5666 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5667 | return retVal; |
| 5668 | } else { |
| 5669 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5670 | return false; |
| 5671 | } |
| 5672 | } finally { |
| 5673 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5674 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5675 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5676 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5677 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 5678 | Phone phone) { |
| 5679 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5680 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5681 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5682 | || subController == null) return privilegeFromSim; |
| 5683 | |
| 5684 | int uid = Binder.getCallingUid(); |
| 5685 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5686 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5687 | |
| 5688 | final long identity = Binder.clearCallingIdentity(); |
| 5689 | try { |
| 5690 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5691 | SubscriptionManager subManager = (SubscriptionManager) |
| 5692 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5693 | for (String pkg : packages) { |
| 5694 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5695 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5696 | } |
| 5697 | } |
| 5698 | return privilegeFromSim; |
| 5699 | } finally { |
| 5700 | Binder.restoreCallingIdentity(identity); |
| 5701 | } |
| 5702 | } |
| 5703 | |
| 5704 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5705 | String pkgName) { |
| 5706 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5707 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5708 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5709 | || subController == null) return privilegeFromSim; |
| 5710 | |
| 5711 | final long identity = Binder.clearCallingIdentity(); |
| 5712 | try { |
| 5713 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5714 | SubscriptionManager subManager = (SubscriptionManager) |
| 5715 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5716 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5717 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5718 | } finally { |
| 5719 | Binder.restoreCallingIdentity(identity); |
| 5720 | } |
| 5721 | } |
| 5722 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5723 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5724 | public int getCarrierPrivilegeStatus(int subId) { |
| 5725 | final Phone phone = getPhone(subId); |
| 5726 | if (phone == null) { |
| 5727 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5728 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5729 | } |
| 5730 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5731 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5732 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5733 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5734 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5735 | |
| 5736 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5737 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 5738 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5739 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5740 | |
| 5741 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5742 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5743 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5744 | final Phone phone = getPhone(subId); |
| 5745 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5746 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5747 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5748 | } |
| 5749 | UiccProfile profile = |
| 5750 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5751 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5752 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5753 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5754 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5755 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5756 | profile.getCarrierPrivilegeStatusForUid( |
| 5757 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5758 | } |
| 5759 | |
| 5760 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5761 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5762 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5763 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5764 | } |
| 5765 | |
| 5766 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5767 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5768 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5769 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5770 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5771 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5772 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5773 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5774 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5775 | } |
| 5776 | |
| 5777 | @Override |
| 5778 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5779 | if (TextUtils.isEmpty(pkgName)) |
| 5780 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5781 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5782 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5783 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5784 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5785 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5786 | continue; |
| 5787 | } |
| 5788 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5789 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5790 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5791 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5792 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5793 | break; |
| 5794 | } |
| 5795 | } |
| 5796 | |
| 5797 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5798 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5799 | |
| 5800 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5801 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5802 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5803 | loge("phoneId " + phoneId + " is not valid."); |
| 5804 | return null; |
| 5805 | } |
| 5806 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5807 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5808 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5809 | return null ; |
| 5810 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5811 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5812 | } |
| 5813 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5814 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5815 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5816 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5817 | List<String> privilegedPackages = new ArrayList<>(); |
| 5818 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5819 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5820 | // has UICC in that slot. |
| 5821 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5822 | if (card.hasCarrierPrivilegeRules()) { |
| 5823 | if (packages == null) { |
| 5824 | // Only check packages in user 0 for now |
| 5825 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5826 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5827 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5828 | | PackageManager.GET_SIGNING_CERTIFICATES, |
| 5829 | UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5830 | } |
| 5831 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5832 | PackageInfo pkgInfo = packages.get(p); |
| 5833 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5834 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5835 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5836 | privilegedPackages.add(pkgInfo.packageName); |
| 5837 | } |
| 5838 | } |
| 5839 | } |
| 5840 | } |
| 5841 | return privilegedPackages; |
| 5842 | } |
| 5843 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5844 | @Override |
| 5845 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5846 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5847 | |
| 5848 | final long identity = Binder.clearCallingIdentity(); |
| 5849 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5850 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5851 | try { |
| 5852 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5853 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5854 | } |
| 5855 | } finally { |
| 5856 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5857 | } |
| 5858 | return privilegedPackages; |
| 5859 | } |
| 5860 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5861 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5862 | final Phone phone = getPhone(subId); |
| 5863 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5864 | if (card == null) { |
| 5865 | loge("getIccId: No UICC"); |
| 5866 | return null; |
| 5867 | } |
| 5868 | String iccId = card.getIccId(); |
| 5869 | if (TextUtils.isEmpty(iccId)) { |
| 5870 | loge("getIccId: ICC ID is null or empty."); |
| 5871 | return null; |
| 5872 | } |
| 5873 | return iccId; |
| 5874 | } |
| 5875 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5876 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5877 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5878 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5879 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5880 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5881 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5882 | final long identity = Binder.clearCallingIdentity(); |
| 5883 | try { |
| 5884 | final String iccId = getIccId(subId); |
| 5885 | final Phone phone = getPhone(subId); |
| 5886 | if (phone == null) { |
| 5887 | return false; |
| 5888 | } |
| 5889 | final String subscriberId = phone.getSubscriberId(); |
| 5890 | |
| 5891 | if (DBG_MERGE) { |
| 5892 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 5893 | + subscriberId + " to " + number); |
| 5894 | } |
| 5895 | |
| 5896 | if (TextUtils.isEmpty(iccId)) { |
| 5897 | return false; |
| 5898 | } |
| 5899 | |
| 5900 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5901 | |
| 5902 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5903 | if (alphaTag == null) { |
| 5904 | editor.remove(alphaTagPrefKey); |
| 5905 | } else { |
| 5906 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5907 | } |
| 5908 | |
| 5909 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5910 | // track all merged IMSIs based on line number |
| 5911 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5912 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5913 | if (number == null) { |
| 5914 | editor.remove(numberPrefKey); |
| 5915 | editor.remove(subscriberPrefKey); |
| 5916 | } else { |
| 5917 | editor.putString(numberPrefKey, number); |
| 5918 | editor.putString(subscriberPrefKey, subscriberId); |
| 5919 | } |
| 5920 | |
| 5921 | editor.commit(); |
| 5922 | return true; |
| 5923 | } finally { |
| 5924 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5925 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5926 | } |
| 5927 | |
| 5928 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5929 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 5930 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5931 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5932 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5933 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5934 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5935 | return null; |
| 5936 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5937 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5938 | final long identity = Binder.clearCallingIdentity(); |
| 5939 | try { |
| 5940 | String iccId = getIccId(subId); |
| 5941 | if (iccId != null) { |
| 5942 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5943 | if (DBG_MERGE) { |
| 5944 | log("getLine1NumberForDisplay returning " |
| 5945 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5946 | } |
| 5947 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5948 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5949 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5950 | return null; |
| 5951 | } finally { |
| 5952 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5953 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5954 | } |
| 5955 | |
| 5956 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5957 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 5958 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5959 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5960 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5961 | return null; |
| 5962 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5963 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5964 | final long identity = Binder.clearCallingIdentity(); |
| 5965 | try { |
| 5966 | String iccId = getIccId(subId); |
| 5967 | if (iccId != null) { |
| 5968 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5969 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5970 | } |
| 5971 | return null; |
| 5972 | } finally { |
| 5973 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5974 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5975 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5976 | |
| 5977 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5978 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 5979 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5980 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5981 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5982 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5983 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5984 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5985 | return null; |
| 5986 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5987 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5988 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5989 | // the process, where TelephonyManager was instantiated. |
| 5990 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5991 | final long identity = Binder.clearCallingIdentity(); |
| 5992 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5993 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5994 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5995 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5996 | |
| 5997 | // Figure out what subscribers are currently active |
| 5998 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5999 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6000 | // Only consider subs which match the current subId |
| 6001 | // This logic can be simplified. See b/131189269 for progress. |
| 6002 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6003 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6004 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6005 | |
| 6006 | // First pass, find a number override for an active subscriber |
| 6007 | String mergeNumber = null; |
| 6008 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6009 | for (String key : prefs.keySet()) { |
| 6010 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6011 | final String subscriberId = (String) prefs.get(key); |
| 6012 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6013 | final String iccId = key.substring( |
| 6014 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6015 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6016 | mergeNumber = (String) prefs.get(numberKey); |
| 6017 | if (DBG_MERGE) { |
| 6018 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 6019 | + " for active subscriber " + subscriberId); |
| 6020 | } |
| 6021 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6022 | break; |
| 6023 | } |
| 6024 | } |
| 6025 | } |
| 6026 | } |
| 6027 | |
| 6028 | // Shortcut when no active merged subscribers |
| 6029 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6030 | return null; |
| 6031 | } |
| 6032 | |
| 6033 | // Second pass, find all subscribers under that line override |
| 6034 | final ArraySet<String> result = new ArraySet<>(); |
| 6035 | for (String key : prefs.keySet()) { |
| 6036 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6037 | final String number = (String) prefs.get(key); |
| 6038 | if (mergeNumber.equals(number)) { |
| 6039 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6040 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6041 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6042 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6043 | result.add(subscriberId); |
| 6044 | } |
| 6045 | } |
| 6046 | } |
| 6047 | } |
| 6048 | |
| 6049 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6050 | Arrays.sort(resultArray); |
| 6051 | if (DBG_MERGE) { |
| 6052 | Slog.d(LOG_TAG, |
| 6053 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6054 | } |
| 6055 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6056 | } finally { |
| 6057 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6058 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6059 | } |
| 6060 | |
| 6061 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6062 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 6063 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 6064 | |
| 6065 | final long identity = Binder.clearCallingIdentity(); |
| 6066 | try { |
| 6067 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6068 | TelephonyManager.class); |
| 6069 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6070 | if (subscriberId == null) { |
| 6071 | if (DBG) { |
| 6072 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 6073 | + subId); |
| 6074 | } |
| 6075 | return null; |
| 6076 | } |
| 6077 | |
| 6078 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6079 | .getSubscriptionInfo(subId); |
| 6080 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6081 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6082 | if (groupUuid == null) { |
| 6083 | return new String[]{subscriberId}; |
| 6084 | } |
| 6085 | |
| 6086 | // Get all subscriberIds from the group. |
| 6087 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6088 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6089 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 6090 | null); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6091 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6092 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6093 | if (subscriberId != null) { |
| 6094 | mergedSubscriberIds.add(subscriberId); |
| 6095 | } |
| 6096 | } |
| 6097 | |
| 6098 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6099 | } finally { |
| 6100 | Binder.restoreCallingIdentity(identity); |
| 6101 | |
| 6102 | } |
| 6103 | } |
| 6104 | |
| 6105 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6106 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6107 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6108 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6109 | |
| 6110 | final long identity = Binder.clearCallingIdentity(); |
| 6111 | try { |
| 6112 | final Phone phone = getPhone(subId); |
| 6113 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6114 | } finally { |
| 6115 | Binder.restoreCallingIdentity(identity); |
| 6116 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6117 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6118 | |
| 6119 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6120 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6121 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6122 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6123 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6124 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6125 | |
| 6126 | final long identity = Binder.clearCallingIdentity(); |
| 6127 | try { |
| 6128 | final Phone phone = getPhone(subId); |
| 6129 | if (phone == null) { |
| 6130 | return false; |
| 6131 | } |
| 6132 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6133 | cdmaNonRoamingList); |
| 6134 | } finally { |
| 6135 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6136 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6137 | } |
| 6138 | |
| 6139 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6140 | @Deprecated |
| 6141 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6142 | enforceModifyPermission(); |
| 6143 | |
| 6144 | int returnValue = 0; |
| 6145 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6146 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6147 | if(result.exception == null) { |
| 6148 | if (result.result != null) { |
| 6149 | byte[] responseData = (byte[])(result.result); |
| 6150 | if(responseData.length > oemResp.length) { |
| 6151 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6152 | responseData.length + "bytes. Buffer Size is " + |
| 6153 | oemResp.length + "bytes."); |
| 6154 | } |
| 6155 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6156 | returnValue = responseData.length; |
| 6157 | } |
| 6158 | } else { |
| 6159 | CommandException ex = (CommandException) result.exception; |
| 6160 | returnValue = ex.getCommandError().ordinal(); |
| 6161 | if(returnValue > 0) returnValue *= -1; |
| 6162 | } |
| 6163 | } catch (RuntimeException e) { |
| 6164 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6165 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6166 | if(returnValue > 0) returnValue *= -1; |
| 6167 | } |
| 6168 | |
| 6169 | return returnValue; |
| 6170 | } |
| 6171 | |
| 6172 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6173 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6174 | try { |
| 6175 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6176 | } catch (RuntimeException e) { |
| 6177 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6178 | } |
| 6179 | } |
| 6180 | |
| 6181 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6182 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6183 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6184 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6185 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6186 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6187 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6188 | final long identity = Binder.clearCallingIdentity(); |
| 6189 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6190 | TelephonyPermissions |
| 6191 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6192 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6193 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6194 | } finally { |
| 6195 | Binder.restoreCallingIdentity(identity); |
| 6196 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6197 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6198 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6199 | |
| 6200 | @Override |
| 6201 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6202 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6203 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6204 | |
| 6205 | final long identity = Binder.clearCallingIdentity(); |
| 6206 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6207 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6208 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6209 | } finally { |
| 6210 | Binder.restoreCallingIdentity(identity); |
| 6211 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6212 | } |
| 6213 | |
| 6214 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6215 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6216 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6217 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6218 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6219 | return false; |
| 6220 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6221 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6222 | final long identity = Binder.clearCallingIdentity(); |
| 6223 | try { |
| 6224 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6225 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6226 | // In the long run, we may instead need to check if there exists a connection service |
| 6227 | // which can support video calling. |
| 6228 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6229 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6230 | return imsManager.isVtEnabledByPlatform() |
| 6231 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6232 | && imsManager.isVtEnabledByUser(); |
| 6233 | } finally { |
| 6234 | Binder.restoreCallingIdentity(identity); |
| 6235 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6236 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6237 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6238 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6239 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6240 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6241 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6242 | mApp, subId, callingPackage, callingFeatureId, |
| 6243 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6244 | return false; |
| 6245 | } |
| 6246 | |
| 6247 | final long identity = Binder.clearCallingIdentity(); |
| 6248 | try { |
| 6249 | CarrierConfigManager configManager = |
| 6250 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6251 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6252 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6253 | } finally { |
| 6254 | Binder.restoreCallingIdentity(identity); |
| 6255 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6256 | } |
| 6257 | |
| 6258 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6259 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6260 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6261 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6262 | return false; |
| 6263 | } |
| 6264 | |
| 6265 | final long identity = Binder.clearCallingIdentity(); |
| 6266 | try { |
| 6267 | CarrierConfigManager configManager = |
| 6268 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6269 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6270 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6271 | } finally { |
| 6272 | Binder.restoreCallingIdentity(identity); |
| 6273 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6274 | } |
| 6275 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6276 | @Override |
| 6277 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6278 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6279 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6280 | } |
| 6281 | |
| 6282 | @Override |
| 6283 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6284 | final long identity = Binder.clearCallingIdentity(); |
| 6285 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6286 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6287 | } finally { |
| 6288 | Binder.restoreCallingIdentity(identity); |
| 6289 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6290 | } |
| 6291 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6292 | /** |
| 6293 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6294 | * support for the feature and device firmware support. |
| 6295 | * |
| 6296 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6297 | */ |
| 6298 | @Override |
| 6299 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6300 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6301 | final Phone phone = getPhone(subscriptionId); |
| 6302 | if (phone == null) { |
| 6303 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6304 | return false; |
| 6305 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6306 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6307 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6308 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6309 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6310 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6311 | return isCarrierSupported && isDeviceSupported; |
| 6312 | } finally { |
| 6313 | Binder.restoreCallingIdentity(identity); |
| 6314 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6315 | } |
| 6316 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6317 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6318 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6319 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6320 | * 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] | 6321 | */ |
| 6322 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6323 | final long identity = Binder.clearCallingIdentity(); |
| 6324 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6325 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6326 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6327 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6328 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6329 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6330 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6331 | } finally { |
| 6332 | Binder.restoreCallingIdentity(identity); |
| 6333 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6334 | } |
| 6335 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6336 | @Deprecated |
| 6337 | @Override |
| 6338 | public String getDeviceId(String callingPackage) { |
| 6339 | return getDeviceIdWithFeature(callingPackage, null); |
| 6340 | } |
| 6341 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6342 | /** |
| 6343 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6344 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6345 | * |
| 6346 | * <p>Requires Permission: |
| 6347 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6348 | */ |
| 6349 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6350 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6351 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6352 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6353 | return null; |
| 6354 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6355 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6356 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6357 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6358 | return null; |
| 6359 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6360 | |
| 6361 | final long identity = Binder.clearCallingIdentity(); |
| 6362 | try { |
| 6363 | return phone.getDeviceId(); |
| 6364 | } finally { |
| 6365 | Binder.restoreCallingIdentity(identity); |
| 6366 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6367 | } |
| 6368 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6369 | /** |
| 6370 | * {@hide} |
| 6371 | * Returns the IMS Registration Status on a particular subid |
| 6372 | * |
| 6373 | * @param subId |
| 6374 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6375 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6376 | Phone phone = getPhone(subId); |
| 6377 | if (phone != null) { |
| 6378 | return phone.isImsRegistered(); |
| 6379 | } else { |
| 6380 | return false; |
| 6381 | } |
| 6382 | } |
| 6383 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6384 | @Override |
| 6385 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6386 | final long identity = Binder.clearCallingIdentity(); |
| 6387 | try { |
| 6388 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6389 | } finally { |
| 6390 | Binder.restoreCallingIdentity(identity); |
| 6391 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6392 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6393 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6394 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6395 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6396 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6397 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6398 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6399 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6400 | } |
| 6401 | final long identity = Binder.clearCallingIdentity(); |
| 6402 | try { |
| 6403 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6404 | } finally { |
| 6405 | Binder.restoreCallingIdentity(identity); |
| 6406 | } |
| 6407 | } |
| 6408 | |
| 6409 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6410 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6411 | final long identity = Binder.clearCallingIdentity(); |
| 6412 | try { |
| 6413 | Phone phone = getPhone(subscriptionId); |
| 6414 | if (phone == null) { |
| 6415 | return null; |
| 6416 | } |
| 6417 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6418 | } finally { |
| 6419 | Binder.restoreCallingIdentity(identity); |
| 6420 | } |
| 6421 | } |
| 6422 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6423 | /** |
| 6424 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6425 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6426 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6427 | final long identity = Binder.clearCallingIdentity(); |
| 6428 | try { |
| 6429 | Phone phone = getPhone(subId); |
| 6430 | if (phone != null) { |
| 6431 | return phone.isWifiCallingEnabled(); |
| 6432 | } else { |
| 6433 | return false; |
| 6434 | } |
| 6435 | } finally { |
| 6436 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6437 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6438 | } |
| 6439 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6440 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6441 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6442 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6443 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6444 | final long identity = Binder.clearCallingIdentity(); |
| 6445 | try { |
| 6446 | Phone phone = getPhone(subId); |
| 6447 | if (phone != null) { |
| 6448 | return phone.isVideoEnabled(); |
| 6449 | } else { |
| 6450 | return false; |
| 6451 | } |
| 6452 | } finally { |
| 6453 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6454 | } |
| 6455 | } |
| 6456 | |
| 6457 | /** |
| 6458 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6459 | * defined in {@link ImsRegistrationImplBase}. |
| 6460 | */ |
| 6461 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6462 | final long identity = Binder.clearCallingIdentity(); |
| 6463 | try { |
| 6464 | Phone phone = getPhone(subId); |
| 6465 | if (phone != null) { |
| 6466 | return phone.getImsRegistrationTech(); |
| 6467 | } else { |
| 6468 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6469 | } |
| 6470 | } finally { |
| 6471 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6472 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6473 | } |
| 6474 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6475 | @Override |
| 6476 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6477 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6478 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6479 | return; |
| 6480 | } |
| 6481 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6482 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6483 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6484 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6485 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6486 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6487 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6488 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6489 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6490 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6491 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6492 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6493 | // There has been issues when Sms raw table somehow stores orphan |
| 6494 | // fragments. They lead to garbled message when new fragments come |
| 6495 | // in and combined with those stale ones. In case this happens again, |
| 6496 | // user can reset all network settings which will clean up this table. |
| 6497 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6498 | // Clean up IMS settings as well here. |
| 6499 | int slotId = getSlotIndex(subId); |
| 6500 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6501 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6502 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6503 | |
| 6504 | // Erase modem config if erase modem on network setting is enabled. |
| 6505 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6506 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6507 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6508 | sendEraseModemConfig(getDefaultPhone()); |
| 6509 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6510 | } finally { |
| 6511 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6512 | } |
| 6513 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6514 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6515 | private void cleanUpSmsRawTable(Context context) { |
| 6516 | ContentResolver resolver = context.getContentResolver(); |
| 6517 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6518 | resolver.delete(uri, null, null); |
| 6519 | } |
| 6520 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6521 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6522 | public String getSimLocaleForSubscriber(int subId) { |
| 6523 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6524 | final Phone phone = getPhone(subId); |
| 6525 | if (phone == null) { |
| 6526 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6527 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6528 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6529 | final long identity = Binder.clearCallingIdentity(); |
| 6530 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6531 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6532 | phone.getContext().getOpPackageName(), null); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6533 | if (info == null) { |
| 6534 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6535 | return null; |
| 6536 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6537 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6538 | // preferences (EF-PL and EF-LI)... |
| 6539 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6540 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6541 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6542 | if (localeFromDefaultSim != null) { |
| 6543 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6544 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6545 | + localeFromDefaultSim); |
| 6546 | return localeFromDefaultSim.toLanguageTag(); |
| 6547 | } else { |
| 6548 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6549 | } |
| 6550 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6551 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6552 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6553 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6554 | // the SIM and carrier preferences does not include a country we add the country |
| 6555 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6556 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6557 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6558 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6559 | return mccLocale.toLanguageTag(); |
| 6560 | } |
| 6561 | |
| 6562 | if (DBG) log("No locale found - returning null"); |
| 6563 | return null; |
| 6564 | } finally { |
| 6565 | Binder.restoreCallingIdentity(identity); |
| 6566 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6567 | } |
| 6568 | |
| 6569 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6570 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 6571 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6572 | } |
| 6573 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6574 | /** |
| 6575 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6576 | */ |
| 6577 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6578 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 6579 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6580 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6581 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6582 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6583 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6584 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6585 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6586 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6587 | * representing the state of the modem. |
| 6588 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6589 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6590 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6591 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6592 | */ |
| 6593 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6594 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6595 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6596 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6597 | |
| 6598 | final long identity = Binder.clearCallingIdentity(); |
| 6599 | try { |
| 6600 | ModemActivityInfo ret = null; |
| 6601 | synchronized (mLastModemActivityInfo) { |
| 6602 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 6603 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6604 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6605 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6606 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6607 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6608 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6609 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6610 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6611 | } |
| 6612 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6613 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 6614 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6615 | mLastModemActivityInfo.setIdleTimeMillis( |
| 6616 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6617 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 6618 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 6619 | info.getReceiveTimeMillis() + mLastModemActivityInfo |
| 6620 | .getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6621 | } |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6622 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6623 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 6624 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 6625 | mLastModemActivityInfo.getIdleTimeMillis(), |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6626 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 6627 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6628 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6629 | Bundle bundle = new Bundle(); |
| 6630 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 6631 | result.send(0, bundle); |
| 6632 | } finally { |
| 6633 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6634 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6635 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6636 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6637 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6638 | // less than total activity duration. |
| 6639 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6640 | if (info == null) { |
| 6641 | return false; |
| 6642 | } |
| 6643 | int activityDurationMs = |
| 6644 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6645 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6646 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6647 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6648 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6649 | } |
| 6650 | return (info.isValid() |
| 6651 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6652 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6653 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6654 | && (totalTxTimeMs <= activityDurationMs)); |
| 6655 | } |
| 6656 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6657 | /** |
| 6658 | * {@hide} |
| 6659 | * Returns the service state information on specified subscription. |
| 6660 | */ |
| 6661 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6662 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6663 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6664 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6665 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6666 | return null; |
| 6667 | } |
| 6668 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6669 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6670 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6671 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6672 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6673 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6674 | .setCallingPid(Binder.getCallingPid()) |
| 6675 | .setCallingUid(Binder.getCallingUid()) |
| 6676 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6677 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6678 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6679 | .build()); |
| 6680 | |
| 6681 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6682 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6683 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6684 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6685 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6686 | .setCallingPid(Binder.getCallingPid()) |
| 6687 | .setCallingUid(Binder.getCallingUid()) |
| 6688 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6689 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6690 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6691 | .build()); |
| 6692 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6693 | boolean hasFinePermission = |
| 6694 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6695 | boolean hasCoarsePermission = |
| 6696 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6697 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6698 | final long identity = Binder.clearCallingIdentity(); |
| 6699 | try { |
| 6700 | final Phone phone = getPhone(subId); |
| 6701 | if (phone == null) { |
| 6702 | return null; |
| 6703 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6704 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6705 | ServiceState ss = phone.getServiceState(); |
| 6706 | |
| 6707 | // Scrub out the location info in ServiceState depending on what level of access |
| 6708 | // the caller has. |
| 6709 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6710 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6711 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6712 | } finally { |
| 6713 | Binder.restoreCallingIdentity(identity); |
| 6714 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6715 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6716 | |
| 6717 | /** |
| 6718 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6719 | * |
| 6720 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6721 | * voicemail ringtone. |
| 6722 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6723 | * PhoneAccount. |
| 6724 | */ |
| 6725 | @Override |
| 6726 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6727 | final long identity = Binder.clearCallingIdentity(); |
| 6728 | try { |
| 6729 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6730 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6731 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6732 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6733 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6734 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6735 | } finally { |
| 6736 | Binder.restoreCallingIdentity(identity); |
| 6737 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6738 | } |
| 6739 | |
| 6740 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6741 | * Sets the per-account voicemail ringtone. |
| 6742 | * |
| 6743 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6744 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6745 | * |
| 6746 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6747 | * voicemail ringtone. |
| 6748 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6749 | * PhoneAccount. |
| 6750 | */ |
| 6751 | @Override |
| 6752 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6753 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6754 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6755 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6756 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6757 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6758 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6759 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6760 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6761 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6762 | |
| 6763 | final long identity = Binder.clearCallingIdentity(); |
| 6764 | try { |
| 6765 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6766 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6767 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6768 | } |
| 6769 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6770 | } finally { |
| 6771 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6772 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6773 | } |
| 6774 | |
| 6775 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6776 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6777 | * |
| 6778 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6779 | * voicemail vibration setting. |
| 6780 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6781 | */ |
| 6782 | @Override |
| 6783 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6784 | final long identity = Binder.clearCallingIdentity(); |
| 6785 | try { |
| 6786 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6787 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6788 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6789 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6790 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6791 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6792 | } finally { |
| 6793 | Binder.restoreCallingIdentity(identity); |
| 6794 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6795 | } |
| 6796 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6797 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6798 | * Sets the per-account voicemail vibration. |
| 6799 | * |
| 6800 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6801 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6802 | * |
| 6803 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6804 | * voicemail vibration setting. |
| 6805 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6806 | * specific PhoneAccount. |
| 6807 | */ |
| 6808 | @Override |
| 6809 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6810 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6811 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6812 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6813 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6814 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6815 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6816 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6817 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6818 | } |
| 6819 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6820 | final long identity = Binder.clearCallingIdentity(); |
| 6821 | try { |
| 6822 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6823 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6824 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6825 | } |
| 6826 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6827 | } finally { |
| 6828 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6829 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6830 | } |
| 6831 | |
| 6832 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6833 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6834 | * |
| 6835 | * @throws SecurityException if the caller does not have the required permission |
| 6836 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6837 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6838 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6839 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6840 | } |
| 6841 | |
| 6842 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6843 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6844 | * permission. |
| 6845 | * |
| 6846 | * @throws SecurityException if the caller does not have the required permission |
| 6847 | */ |
| 6848 | private void enforceSendSmsPermission() { |
| 6849 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6850 | } |
| 6851 | |
| 6852 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6853 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6854 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6855 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6856 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6857 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6858 | final long identity = Binder.clearCallingIdentity(); |
| 6859 | try { |
| 6860 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6861 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6862 | if (componentName == null) { |
| 6863 | throw new SecurityException( |
| 6864 | "Caller not current active visual voicemail package[null]"); |
| 6865 | } |
| 6866 | String vvmPackage = componentName.getPackageName(); |
| 6867 | if (!callingPackage.equals(vvmPackage)) { |
| 6868 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6869 | + vvmPackage + "]"); |
| 6870 | } |
| 6871 | } finally { |
| 6872 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6873 | } |
| 6874 | } |
| 6875 | |
| 6876 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6877 | * Return the application ID for the app type. |
| 6878 | * |
| 6879 | * @param subId the subscription ID that this request applies to. |
| 6880 | * @param appType the uicc app type. |
| 6881 | * @return Application ID for specificied app type, or null if no uicc. |
| 6882 | */ |
| 6883 | @Override |
| 6884 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6885 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6886 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6887 | |
| 6888 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6889 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6890 | if (phone == null) { |
| 6891 | return null; |
| 6892 | } |
| 6893 | String aid = null; |
| 6894 | try { |
| 6895 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6896 | .getApplicationByType(appType).getAid(); |
| 6897 | } catch (Exception e) { |
| 6898 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6899 | } |
| 6900 | return aid; |
| 6901 | } finally { |
| 6902 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6903 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6904 | } |
| 6905 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6906 | /** |
| 6907 | * Return the Electronic Serial Number. |
| 6908 | * |
| 6909 | * @param subId the subscription ID that this request applies to. |
| 6910 | * @return ESN or null if error. |
| 6911 | */ |
| 6912 | @Override |
| 6913 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6914 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6915 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6916 | |
| 6917 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6918 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6919 | if (phone == null) { |
| 6920 | return null; |
| 6921 | } |
| 6922 | String esn = null; |
| 6923 | try { |
| 6924 | esn = phone.getEsn(); |
| 6925 | } catch (Exception e) { |
| 6926 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6927 | } |
| 6928 | return esn; |
| 6929 | } finally { |
| 6930 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6931 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6932 | } |
| 6933 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6934 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6935 | * Return the Preferred Roaming List Version. |
| 6936 | * |
| 6937 | * @param subId the subscription ID that this request applies to. |
| 6938 | * @return PRLVersion or null if error. |
| 6939 | */ |
| 6940 | @Override |
| 6941 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6942 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6943 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6944 | |
| 6945 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6946 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6947 | if (phone == null) { |
| 6948 | return null; |
| 6949 | } |
| 6950 | String cdmaPrlVersion = null; |
| 6951 | try { |
| 6952 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6953 | } catch (Exception e) { |
| 6954 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6955 | } |
| 6956 | return cdmaPrlVersion; |
| 6957 | } finally { |
| 6958 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6959 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6960 | } |
| 6961 | |
| 6962 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6963 | * Get snapshot of Telephony histograms |
| 6964 | * @return List of Telephony histograms |
| 6965 | * @hide |
| 6966 | */ |
| 6967 | @Override |
| 6968 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6969 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6970 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6971 | |
| 6972 | final long identity = Binder.clearCallingIdentity(); |
| 6973 | try { |
| 6974 | return RIL.getTelephonyRILTimingHistograms(); |
| 6975 | } finally { |
| 6976 | Binder.restoreCallingIdentity(identity); |
| 6977 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6978 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6979 | |
| 6980 | /** |
| 6981 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6982 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6983 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6984 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6985 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6986 | * @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] | 6987 | */ |
| 6988 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6989 | @TelephonyManager.SetCarrierRestrictionResult |
| 6990 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6991 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6992 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6993 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6994 | if (carrierRestrictionRules == null) { |
| 6995 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6996 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6997 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6998 | final long identity = Binder.clearCallingIdentity(); |
| 6999 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7000 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7001 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7002 | } finally { |
| 7003 | Binder.restoreCallingIdentity(identity); |
| 7004 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7005 | } |
| 7006 | |
| 7007 | /** |
| 7008 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7009 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7010 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7011 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7012 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7013 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7014 | */ |
| 7015 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7016 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7017 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7018 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7019 | |
| 7020 | final long identity = Binder.clearCallingIdentity(); |
| 7021 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7022 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7023 | if (response instanceof CarrierRestrictionRules) { |
| 7024 | return (CarrierRestrictionRules) response; |
| 7025 | } |
| 7026 | // Response is an Exception of some kind, |
| 7027 | // which is signalled to the user as a NULL retval |
| 7028 | return null; |
| 7029 | } catch (Exception e) { |
| 7030 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7031 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7032 | } finally { |
| 7033 | Binder.restoreCallingIdentity(identity); |
| 7034 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7035 | } |
| 7036 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7037 | /** |
| 7038 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 7039 | * @param subId the subscription ID that this action applies to. |
| 7040 | * @param enabled control enable or disable metered apns. |
| 7041 | * {@hide} |
| 7042 | */ |
| 7043 | @Override |
| 7044 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 7045 | enforceModifyPermission(); |
| 7046 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7047 | |
| 7048 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7049 | if (phone == null) { |
| 7050 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 7051 | return; |
| 7052 | } |
| 7053 | try { |
| 7054 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7055 | } catch (Exception e) { |
| 7056 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7057 | } finally { |
| 7058 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7059 | } |
| 7060 | } |
| 7061 | |
| 7062 | /** |
| 7063 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7064 | * @param subId the subscription ID that this action applies to. |
| 7065 | * @param enabled control enable or disable radio. |
| 7066 | * {@hide} |
| 7067 | */ |
| 7068 | @Override |
| 7069 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7070 | enforceModifyPermission(); |
| 7071 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7072 | |
| 7073 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7074 | if (phone == null) { |
| 7075 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7076 | return; |
| 7077 | } |
| 7078 | try { |
| 7079 | phone.carrierActionSetRadioEnabled(enabled); |
| 7080 | } catch (Exception e) { |
| 7081 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7082 | } finally { |
| 7083 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7084 | } |
| 7085 | } |
| 7086 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7087 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7088 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7089 | * network status based on which carrier apps could apply actions accordingly, |
| 7090 | * enable/disable default url handler for example. |
| 7091 | * |
| 7092 | * @param subId the subscription ID that this action applies to. |
| 7093 | * @param report control start/stop reporting the default network status. |
| 7094 | * {@hide} |
| 7095 | */ |
| 7096 | @Override |
| 7097 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7098 | enforceModifyPermission(); |
| 7099 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7100 | |
| 7101 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7102 | if (phone == null) { |
| 7103 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7104 | return; |
| 7105 | } |
| 7106 | try { |
| 7107 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7108 | } catch (Exception e) { |
| 7109 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7110 | } finally { |
| 7111 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7112 | } |
| 7113 | } |
| 7114 | |
| 7115 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7116 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7117 | * @param subId the subscription ID that this action applies to. |
| 7118 | * {@hide} |
| 7119 | */ |
| 7120 | @Override |
| 7121 | public void carrierActionResetAll(int subId) { |
| 7122 | enforceModifyPermission(); |
| 7123 | final Phone phone = getPhone(subId); |
| 7124 | if (phone == null) { |
| 7125 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7126 | return; |
| 7127 | } |
| 7128 | try { |
| 7129 | phone.carrierActionResetAll(); |
| 7130 | } catch (Exception e) { |
| 7131 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7132 | } |
| 7133 | } |
| 7134 | |
| 7135 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7136 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7137 | * bug report is being generated. |
| 7138 | */ |
| 7139 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7140 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7141 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7142 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7143 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7144 | + Binder.getCallingPid() |
| 7145 | + ", uid=" + Binder.getCallingUid() |
| 7146 | + "without permission " |
| 7147 | + android.Manifest.permission.DUMP); |
| 7148 | return; |
| 7149 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7150 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7151 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7152 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7153 | @Override |
| 7154 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 7155 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 7156 | throws RemoteException { |
Torbjorn Eklund | 1050cb0 | 2018-11-16 14:05:38 +0100 | [diff] [blame] | 7157 | (new TelephonyShellCommand(this, getDefaultPhone().getContext())) |
| 7158 | .exec(this, in, out, err, args, callback, resultReceiver); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7159 | } |
| 7160 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7161 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 7162 | * Get aggregated video call data usage since boot. |
| 7163 | * |
| 7164 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 7165 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7166 | * {@hide} |
| 7167 | */ |
| 7168 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 7169 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7170 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 7171 | null); |
| 7172 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7173 | final long identity = Binder.clearCallingIdentity(); |
| 7174 | try { |
| 7175 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 7176 | // records the delta with the corresponding network identity. |
| 7177 | // We just return the total video call data usage snapshot since boot. |
| 7178 | Phone phone = getPhone(subId); |
| 7179 | if (phone != null) { |
| 7180 | return phone.getVtDataUsage(perUidStats); |
| 7181 | } |
| 7182 | return null; |
| 7183 | } finally { |
| 7184 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7185 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7186 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7187 | |
| 7188 | /** |
| 7189 | * Policy control of data connection. Usually used when data limit is passed. |
| 7190 | * @param enabled True if enabling the data, otherwise disabling. |
| 7191 | * @param subId Subscription index |
| 7192 | * {@hide} |
| 7193 | */ |
| 7194 | @Override |
| 7195 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 7196 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7197 | |
| 7198 | final long identity = Binder.clearCallingIdentity(); |
| 7199 | try { |
| 7200 | Phone phone = getPhone(subId); |
| 7201 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 7202 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7203 | } |
| 7204 | } finally { |
| 7205 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7206 | } |
| 7207 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7208 | |
| 7209 | /** |
| 7210 | * Get Client request stats |
| 7211 | * @return List of Client Request Stats |
| 7212 | * @hide |
| 7213 | */ |
| 7214 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7215 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7216 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7217 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7218 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7219 | return null; |
| 7220 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7221 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7222 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7223 | final long identity = Binder.clearCallingIdentity(); |
| 7224 | try { |
| 7225 | if (phone != null) { |
| 7226 | return phone.getClientRequestStats(); |
| 7227 | } |
| 7228 | |
| 7229 | return null; |
| 7230 | } finally { |
| 7231 | Binder.restoreCallingIdentity(identity); |
| 7232 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7233 | } |
| 7234 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7235 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7236 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7237 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7238 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7239 | |
| 7240 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7241 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7242 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7243 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7244 | * @param state State of SIM (power down, power up, pass through) |
| 7245 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7246 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7247 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7248 | * |
| 7249 | **/ |
| 7250 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7251 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7252 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7253 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7254 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7255 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7256 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7257 | final long identity = Binder.clearCallingIdentity(); |
| 7258 | try { |
| 7259 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7260 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7261 | } |
| 7262 | } finally { |
| 7263 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7264 | } |
| 7265 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7266 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7267 | private boolean isUssdApiAllowed(int subId) { |
| 7268 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7269 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7270 | if (configManager == null) { |
| 7271 | return false; |
| 7272 | } |
| 7273 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7274 | if (pb == null) { |
| 7275 | return false; |
| 7276 | } |
| 7277 | return pb.getBoolean( |
| 7278 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7279 | } |
| 7280 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7281 | /** |
| 7282 | * Check if phone is in emergency callback mode |
| 7283 | * @return true if phone is in emergency callback mode |
| 7284 | * @param subId sub id |
| 7285 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7286 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7287 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7288 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7289 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7290 | |
| 7291 | final long identity = Binder.clearCallingIdentity(); |
| 7292 | try { |
| 7293 | if (phone != null) { |
| 7294 | return phone.isInEcm(); |
| 7295 | } else { |
| 7296 | return false; |
| 7297 | } |
| 7298 | } finally { |
| 7299 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7300 | } |
| 7301 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7302 | |
| 7303 | /** |
| 7304 | * Get the current signal strength information for the given subscription. |
| 7305 | * Because this information is not updated when the device is in a low power state |
| 7306 | * it should not be relied-upon to be current. |
| 7307 | * @param subId Subscription index |
| 7308 | * @return the most recent cached signal strength info from the modem |
| 7309 | */ |
| 7310 | @Override |
| 7311 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7312 | final long identity = Binder.clearCallingIdentity(); |
| 7313 | try { |
| 7314 | Phone p = getPhone(subId); |
| 7315 | if (p == null) { |
| 7316 | return null; |
| 7317 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7318 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7319 | return p.getSignalStrength(); |
| 7320 | } finally { |
| 7321 | Binder.restoreCallingIdentity(identity); |
| 7322 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7323 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7324 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7325 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7326 | * Get the current modem radio state for the given slot. |
| 7327 | * @param slotIndex slot index. |
| 7328 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7329 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7330 | * @return the current radio power state from the modem |
| 7331 | */ |
| 7332 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7333 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7334 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7335 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7336 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7337 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7338 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7339 | } |
| 7340 | |
| 7341 | final long identity = Binder.clearCallingIdentity(); |
| 7342 | try { |
| 7343 | return phone.getRadioPowerState(); |
| 7344 | } finally { |
| 7345 | Binder.restoreCallingIdentity(identity); |
| 7346 | } |
| 7347 | } |
| 7348 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7349 | } |
| 7350 | |
| 7351 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7352 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7353 | * |
| 7354 | * <p>Requires one of the following permissions: |
| 7355 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7356 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7357 | * privileges. |
| 7358 | * |
| 7359 | * @param subId subscription id |
| 7360 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7361 | * {@code false}. |
| 7362 | */ |
| 7363 | @Override |
| 7364 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7365 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7366 | null /* message */); |
| 7367 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7368 | boolean isEnabled = false; |
| 7369 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7370 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7371 | Phone phone = getPhone(subId); |
| 7372 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7373 | } catch (Exception e) { |
| 7374 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7375 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7376 | } finally { |
| 7377 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7378 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7379 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7380 | } |
| 7381 | |
| 7382 | |
| 7383 | /** |
| 7384 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7385 | * |
| 7386 | * <p> Requires permission: |
| 7387 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7388 | * privileges. |
| 7389 | * |
| 7390 | * @param subId subscription id |
| 7391 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7392 | */ |
| 7393 | @Override |
| 7394 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7395 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7396 | mApp, subId, "setDataRoamingEnabled"); |
| 7397 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7398 | final long identity = Binder.clearCallingIdentity(); |
| 7399 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7400 | Phone phone = getPhone(subId); |
| 7401 | if (phone != null) { |
| 7402 | phone.setDataRoamingEnabled(isEnabled); |
| 7403 | } |
| 7404 | } finally { |
| 7405 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7406 | } |
| 7407 | } |
| 7408 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7409 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7410 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7411 | TelephonyPermissions |
| 7412 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7413 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7414 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7415 | boolean isAllowed = true; |
| 7416 | final long identity = Binder.clearCallingIdentity(); |
| 7417 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7418 | Phone phone = getPhone(subId); |
| 7419 | if (phone != null) { |
| 7420 | isAllowed = phone.isCspPlmnEnabled(); |
| 7421 | } |
| 7422 | } finally { |
| 7423 | Binder.restoreCallingIdentity(identity); |
| 7424 | } |
| 7425 | return isAllowed; |
| 7426 | } |
| 7427 | |
| 7428 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7429 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7430 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7431 | try { |
| 7432 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7433 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7434 | } catch (SecurityException e) { |
| 7435 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7436 | // has carrier privileges on an active UICC |
| 7437 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7438 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7439 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7440 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7441 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7442 | |
| 7443 | final long identity = Binder.clearCallingIdentity(); |
| 7444 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7445 | UiccController uiccController = UiccController.getInstance(); |
| 7446 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7447 | if (hasReadPermission) { |
| 7448 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7449 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7450 | |
| 7451 | // Remove private info if the caller doesn't have access |
| 7452 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7453 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7454 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7455 | // is available |
| 7456 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7457 | if (card == null || card.getUiccProfile() == null) { |
| 7458 | // assume no access if the card or profile is unavailable |
| 7459 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7460 | continue; |
| 7461 | } |
| 7462 | UiccProfile profile = card.getUiccProfile(); |
| 7463 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7464 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7465 | filteredInfos.add(cardInfo); |
| 7466 | } else { |
| 7467 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7468 | } |
| 7469 | } |
| 7470 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7471 | } finally { |
| 7472 | Binder.restoreCallingIdentity(identity); |
| 7473 | } |
| 7474 | } |
| 7475 | |
| 7476 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7477 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7478 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7479 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7480 | final long identity = Binder.clearCallingIdentity(); |
| 7481 | try { |
| 7482 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7483 | if (slots == null) { |
| 7484 | Rlog.i(LOG_TAG, "slots is null."); |
| 7485 | return null; |
| 7486 | } |
| 7487 | |
| 7488 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7489 | for (int i = 0; i < slots.length; i++) { |
| 7490 | UiccSlot slot = slots[i]; |
| 7491 | if (slot == null) { |
| 7492 | continue; |
| 7493 | } |
| 7494 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7495 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7496 | UiccCard card = slot.getUiccCard(); |
| 7497 | if (card != null) { |
| 7498 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7499 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7500 | cardId = slot.getEid(); |
| 7501 | if (TextUtils.isEmpty(cardId)) { |
| 7502 | cardId = slot.getIccId(); |
| 7503 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7504 | } |
| 7505 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7506 | if (cardId != null) { |
| 7507 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7508 | // if cardId is an EID, it's all digits so this is fine |
| 7509 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7510 | } |
| 7511 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7512 | int cardState = 0; |
| 7513 | switch (slot.getCardState()) { |
| 7514 | case CARDSTATE_ABSENT: |
| 7515 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7516 | break; |
| 7517 | case CARDSTATE_PRESENT: |
| 7518 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7519 | break; |
| 7520 | case CARDSTATE_ERROR: |
| 7521 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7522 | break; |
| 7523 | case CARDSTATE_RESTRICTED: |
| 7524 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7525 | break; |
| 7526 | default: |
| 7527 | break; |
| 7528 | |
| 7529 | } |
| 7530 | |
| 7531 | infos[i] = new UiccSlotInfo( |
| 7532 | slot.isActive(), |
| 7533 | slot.isEuicc(), |
| 7534 | cardId, |
| 7535 | cardState, |
| 7536 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7537 | slot.isExtendedApduSupported(), |
| 7538 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7539 | } |
| 7540 | return infos; |
| 7541 | } finally { |
| 7542 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7543 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7544 | } |
| 7545 | |
| 7546 | @Override |
| 7547 | public boolean switchSlots(int[] physicalSlots) { |
| 7548 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7549 | |
| 7550 | final long identity = Binder.clearCallingIdentity(); |
| 7551 | try { |
| 7552 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7553 | } finally { |
| 7554 | Binder.restoreCallingIdentity(identity); |
| 7555 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7556 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7557 | |
| 7558 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7559 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7560 | final long identity = Binder.clearCallingIdentity(); |
| 7561 | try { |
| 7562 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7563 | } finally { |
| 7564 | Binder.restoreCallingIdentity(identity); |
| 7565 | } |
| 7566 | } |
| 7567 | |
| 7568 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7569 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 7570 | enforceModifyPermission(); |
| 7571 | final Phone phone = getPhone(subId); |
| 7572 | if (phone == null) { |
| 7573 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 7574 | return; |
| 7575 | } |
| 7576 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7577 | final long identity = Binder.clearCallingIdentity(); |
| 7578 | try { |
| 7579 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 7580 | } finally { |
| 7581 | Binder.restoreCallingIdentity(identity); |
| 7582 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7583 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7584 | |
| 7585 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7586 | * A test API to reload the UICC profile. |
| 7587 | * |
| 7588 | * <p>Requires that the calling app has permission |
| 7589 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7590 | * @hide |
| 7591 | */ |
| 7592 | @Override |
| 7593 | public void refreshUiccProfile(int subId) { |
| 7594 | enforceModifyPermission(); |
| 7595 | |
| 7596 | final long identity = Binder.clearCallingIdentity(); |
| 7597 | try { |
| 7598 | Phone phone = getPhone(subId); |
| 7599 | if (phone == null) { |
| 7600 | return; |
| 7601 | } |
| 7602 | UiccCard uiccCard = phone.getUiccCard(); |
| 7603 | if (uiccCard == null) { |
| 7604 | return; |
| 7605 | } |
| 7606 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7607 | if (uiccProfile == null) { |
| 7608 | return; |
| 7609 | } |
| 7610 | uiccProfile.refresh(); |
| 7611 | } finally { |
| 7612 | Binder.restoreCallingIdentity(identity); |
| 7613 | } |
| 7614 | } |
| 7615 | |
| 7616 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7617 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7618 | */ |
| 7619 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7620 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7621 | } |
| 7622 | |
| 7623 | /** |
| 7624 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7625 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7626 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7627 | */ |
| 7628 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7629 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7630 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7631 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7632 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7633 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7634 | return isDataRoamingEnabled; |
| 7635 | } |
| 7636 | |
| 7637 | /** |
| 7638 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7639 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7640 | */ |
| 7641 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7642 | List<Integer> list = TelephonyProperties.default_network(); |
| 7643 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7644 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7645 | return list.get(phoneId); |
| 7646 | } |
| 7647 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7648 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7649 | |
| 7650 | @Override |
| 7651 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7652 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7653 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7654 | |
| 7655 | final long identity = Binder.clearCallingIdentity(); |
| 7656 | try { |
| 7657 | final Phone phone = getPhone(subId); |
| 7658 | if (phone == null) { |
| 7659 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7660 | return; |
| 7661 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7662 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7663 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7664 | } finally { |
| 7665 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7666 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7667 | } |
| 7668 | |
| 7669 | @Override |
| 7670 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7671 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7672 | |
| 7673 | final long identity = Binder.clearCallingIdentity(); |
| 7674 | try { |
| 7675 | final Phone phone = getPhone(subId); |
| 7676 | if (phone == null) { |
| 7677 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7678 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7679 | } |
| 7680 | return phone.getCarrierIdListVersion(); |
| 7681 | } finally { |
| 7682 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7683 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7684 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7685 | |
| 7686 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7687 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7688 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7689 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7690 | mApp, subId, callingPackage, callingFeatureId, |
| 7691 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7692 | return -1; |
| 7693 | } |
| 7694 | |
| 7695 | final long identity = Binder.clearCallingIdentity(); |
| 7696 | try { |
| 7697 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7698 | } finally { |
| 7699 | Binder.restoreCallingIdentity(identity); |
| 7700 | } |
| 7701 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7702 | |
| 7703 | @Override |
| 7704 | public int getCdmaRoamingMode(int subId) { |
| 7705 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7706 | mApp, subId, "getCdmaRoamingMode"); |
| 7707 | |
| 7708 | final long identity = Binder.clearCallingIdentity(); |
| 7709 | try { |
| 7710 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7711 | } finally { |
| 7712 | Binder.restoreCallingIdentity(identity); |
| 7713 | } |
| 7714 | } |
| 7715 | |
| 7716 | @Override |
| 7717 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7718 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7719 | mApp, subId, "setCdmaRoamingMode"); |
| 7720 | |
| 7721 | final long identity = Binder.clearCallingIdentity(); |
| 7722 | try { |
| 7723 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7724 | } finally { |
| 7725 | Binder.restoreCallingIdentity(identity); |
| 7726 | } |
| 7727 | } |
| 7728 | |
| 7729 | @Override |
| 7730 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7731 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7732 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7733 | |
| 7734 | final long identity = Binder.clearCallingIdentity(); |
| 7735 | try { |
| 7736 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7737 | } finally { |
| 7738 | Binder.restoreCallingIdentity(identity); |
| 7739 | } |
| 7740 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7741 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7742 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7743 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7744 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7745 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7746 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7747 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7748 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7749 | } |
| 7750 | final long identity = Binder.clearCallingIdentity(); |
| 7751 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7752 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7753 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7754 | if (phone.getEmergencyNumberTracker() != null |
| 7755 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7756 | emergencyNumberListInternal.put( |
| 7757 | phone.getSubId(), |
| 7758 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7759 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7760 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7761 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7762 | } finally { |
| 7763 | Binder.restoreCallingIdentity(identity); |
| 7764 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7765 | } |
| 7766 | |
| 7767 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7768 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7769 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7770 | if (!exactMatch) { |
| 7771 | TelephonyPermissions |
| 7772 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7773 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7774 | } |
| 7775 | final long identity = Binder.clearCallingIdentity(); |
| 7776 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7777 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7778 | if (phone.getEmergencyNumberTracker() != null |
| 7779 | && phone.getEmergencyNumberTracker() != null) { |
| 7780 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7781 | number, exactMatch)) { |
| 7782 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7783 | } |
| 7784 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7785 | } |
| 7786 | return false; |
| 7787 | } finally { |
| 7788 | Binder.restoreCallingIdentity(identity); |
| 7789 | } |
| 7790 | } |
| 7791 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7792 | /** |
| 7793 | * Update emergency number list for test mode. |
| 7794 | */ |
| 7795 | @Override |
| 7796 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7797 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7798 | "updateEmergencyNumberListTestMode"); |
| 7799 | |
| 7800 | final long identity = Binder.clearCallingIdentity(); |
| 7801 | try { |
| 7802 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7803 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7804 | if (tracker != null) { |
| 7805 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7806 | } |
| 7807 | } |
| 7808 | } finally { |
| 7809 | Binder.restoreCallingIdentity(identity); |
| 7810 | } |
| 7811 | } |
| 7812 | |
| 7813 | /** |
| 7814 | * Get the full emergency number list for test mode. |
| 7815 | */ |
| 7816 | @Override |
| 7817 | public List<String> getEmergencyNumberListTestMode() { |
| 7818 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7819 | "getEmergencyNumberListTestMode"); |
| 7820 | |
| 7821 | final long identity = Binder.clearCallingIdentity(); |
| 7822 | try { |
| 7823 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7824 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7825 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7826 | if (tracker != null) { |
| 7827 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7828 | emergencyNumbers.add(num.getNumber()); |
| 7829 | } |
| 7830 | } |
| 7831 | } |
| 7832 | return new ArrayList<>(emergencyNumbers); |
| 7833 | } finally { |
| 7834 | Binder.restoreCallingIdentity(identity); |
| 7835 | } |
| 7836 | } |
| 7837 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7838 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7839 | public int getEmergencyNumberDbVersion(int subId) { |
| 7840 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7841 | |
| 7842 | final long identity = Binder.clearCallingIdentity(); |
| 7843 | try { |
| 7844 | final Phone phone = getPhone(subId); |
| 7845 | if (phone == null) { |
| 7846 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7847 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7848 | } |
| 7849 | return phone.getEmergencyNumberDbVersion(); |
| 7850 | } finally { |
| 7851 | Binder.restoreCallingIdentity(identity); |
| 7852 | } |
| 7853 | } |
| 7854 | |
| 7855 | @Override |
| 7856 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7857 | enforceModifyPermission(); |
| 7858 | |
| 7859 | final long identity = Binder.clearCallingIdentity(); |
| 7860 | try { |
| 7861 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7862 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7863 | if (tracker != null) { |
| 7864 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7865 | } |
| 7866 | } |
| 7867 | } finally { |
| 7868 | Binder.restoreCallingIdentity(identity); |
| 7869 | } |
| 7870 | } |
| 7871 | |
| 7872 | @Override |
| 7873 | public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) { |
| 7874 | enforceActiveEmergencySessionPermission(); |
| 7875 | |
| 7876 | final long identity = Binder.clearCallingIdentity(); |
| 7877 | try { |
| 7878 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7879 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7880 | if (tracker != null) { |
| 7881 | tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath); |
| 7882 | } |
| 7883 | } |
| 7884 | } finally { |
| 7885 | Binder.restoreCallingIdentity(identity); |
| 7886 | } |
| 7887 | } |
| 7888 | |
| 7889 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7890 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7891 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7892 | Phone phone = getPhone(subId); |
| 7893 | if (phone == null) { |
| 7894 | return null; |
| 7895 | } |
| 7896 | final long identity = Binder.clearCallingIdentity(); |
| 7897 | try { |
| 7898 | UiccProfile profile = UiccController.getInstance() |
| 7899 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7900 | if (profile != null) { |
| 7901 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7902 | } |
| 7903 | } finally { |
| 7904 | Binder.restoreCallingIdentity(identity); |
| 7905 | } |
| 7906 | return null; |
| 7907 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7908 | |
| 7909 | /** |
| 7910 | * Enable or disable a modem stack. |
| 7911 | */ |
| 7912 | @Override |
| 7913 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7914 | enforceModifyPermission(); |
| 7915 | |
| 7916 | final long identity = Binder.clearCallingIdentity(); |
| 7917 | try { |
| 7918 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7919 | if (phone == null) { |
| 7920 | return false; |
| 7921 | } else { |
| 7922 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7923 | } |
| 7924 | } finally { |
| 7925 | Binder.restoreCallingIdentity(identity); |
| 7926 | } |
| 7927 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7928 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7929 | /** |
| 7930 | * Whether a modem stack is enabled or not. |
| 7931 | */ |
| 7932 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7933 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7934 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7935 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7936 | if (phone == null) return false; |
| 7937 | |
| 7938 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7939 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7940 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7941 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7942 | } |
| 7943 | |
| 7944 | final long identity = Binder.clearCallingIdentity(); |
| 7945 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7946 | try { |
| 7947 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7948 | } catch (NoSuchElementException ex) { |
| 7949 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7950 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7951 | } finally { |
| 7952 | Binder.restoreCallingIdentity(identity); |
| 7953 | } |
| 7954 | } |
| 7955 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7956 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7957 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7958 | enforceModifyPermission(); |
| 7959 | |
| 7960 | final long identity = Binder.clearCallingIdentity(); |
| 7961 | try { |
| 7962 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7963 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7964 | .commit(); |
| 7965 | } finally { |
| 7966 | Binder.restoreCallingIdentity(identity); |
| 7967 | } |
| 7968 | } |
| 7969 | |
| 7970 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7971 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7972 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7973 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7974 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 7975 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7976 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7977 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7978 | |
| 7979 | final long identity = Binder.clearCallingIdentity(); |
| 7980 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7981 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7982 | } finally { |
| 7983 | Binder.restoreCallingIdentity(identity); |
| 7984 | } |
| 7985 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7986 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7987 | @TelephonyManager.IsMultiSimSupportedResult |
| 7988 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7989 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7990 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7991 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7992 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7993 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7994 | } |
| 7995 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7996 | // supported by the modem, indicate that it is restricted. |
| 7997 | PhoneCapability staticCapability = |
| 7998 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7999 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8000 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8001 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8002 | } |
Sarah Chin | 5f0ecd7 | 2019-12-06 10:24:18 -0800 | [diff] [blame] | 8003 | if (staticCapability.getLogicalModemUuids().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8004 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8005 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8006 | } |
| 8007 | // Check if support of multiple SIMs is restricted by carrier |
| 8008 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8009 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8010 | } |
| 8011 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8012 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8013 | } |
| 8014 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8015 | /** |
| 8016 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8017 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8018 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8019 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8020 | * @param numOfSims number of active sims we want to switch to |
| 8021 | */ |
| 8022 | @Override |
| 8023 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8024 | if (numOfSims == 1) { |
| 8025 | enforceModifyPermission(); |
| 8026 | } else { |
| 8027 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8028 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8029 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8030 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8031 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8032 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8033 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8034 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8035 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8036 | return; |
| 8037 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8038 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8039 | } finally { |
| 8040 | Binder.restoreCallingIdentity(identity); |
| 8041 | } |
| 8042 | } |
| 8043 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8044 | @Override |
| 8045 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8046 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8047 | Phone phone = getPhone(subId); |
| 8048 | if (phone == null) { |
| 8049 | return false; |
| 8050 | } |
| 8051 | final long identity = Binder.clearCallingIdentity(); |
| 8052 | try { |
| 8053 | UiccCard uiccCard = phone.getUiccCard(); |
| 8054 | if (uiccCard == null) { |
| 8055 | return false; |
| 8056 | } |
| 8057 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8058 | if (uiccProfile == null) { |
| 8059 | return false; |
| 8060 | } |
| 8061 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8062 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8063 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8064 | } |
| 8065 | return false; |
| 8066 | } finally { |
| 8067 | Binder.restoreCallingIdentity(identity); |
| 8068 | } |
| 8069 | } |
| 8070 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8071 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8072 | * Get whether making changes to modem configurations will trigger reboot. |
| 8073 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8074 | */ |
| 8075 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8076 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8077 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8078 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8079 | mApp, subId, callingPackage, callingFeatureId, |
| 8080 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8081 | return false; |
| 8082 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8083 | final long identity = Binder.clearCallingIdentity(); |
| 8084 | try { |
| 8085 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8086 | } finally { |
| 8087 | Binder.restoreCallingIdentity(identity); |
| 8088 | } |
| 8089 | } |
| 8090 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8091 | private void updateModemStateMetrics() { |
| 8092 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8093 | // TODO: check the state for each modem if the api is ready. |
| 8094 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8095 | } |
| 8096 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8097 | @Override |
| 8098 | public int[] getSlotsMapping() { |
| 8099 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8100 | |
| 8101 | final long identity = Binder.clearCallingIdentity(); |
| 8102 | try { |
| 8103 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8104 | // All logical slots should have a mapping to a physical slot. |
| 8105 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8106 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8107 | for (int i = 0; i < slotInfos.length; i++) { |
| 8108 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8109 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8110 | } |
| 8111 | } |
| 8112 | return logicalSlotsMapping; |
| 8113 | } finally { |
| 8114 | Binder.restoreCallingIdentity(identity); |
| 8115 | } |
| 8116 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8117 | |
| 8118 | /** |
| 8119 | * Get the IRadio HAL Version |
| 8120 | */ |
| 8121 | @Override |
| 8122 | public int getRadioHalVersion() { |
| 8123 | Phone phone = getDefaultPhone(); |
| 8124 | if (phone == null) return -1; |
| 8125 | HalVersion hv = phone.getHalVersion(); |
| 8126 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8127 | return hv.major * 100 + hv.minor; |
| 8128 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8129 | |
| 8130 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8131 | * Get the current calling package name. |
| 8132 | * @return the current calling package name |
| 8133 | */ |
| 8134 | @Override |
| 8135 | public String getCurrentPackageName() { |
| 8136 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8137 | } |
| 8138 | |
| 8139 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8140 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8141 | * corresponding network requests on a subId. |
| 8142 | * |
| 8143 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8144 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8145 | * 2) APN is un-metered for this subscription, or |
| 8146 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8147 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8148 | * |
| 8149 | * @return whether data is allowed for a apn type. |
| 8150 | * |
| 8151 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8152 | */ |
| 8153 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8154 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8155 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8156 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8157 | |
| 8158 | // Now that all security checks passes, perform the operation as ourselves. |
| 8159 | final long identity = Binder.clearCallingIdentity(); |
| 8160 | try { |
| 8161 | Phone phone = getPhone(subId); |
| 8162 | if (phone == null) return false; |
| 8163 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8164 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8165 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8166 | } finally { |
| 8167 | Binder.restoreCallingIdentity(identity); |
| 8168 | } |
| 8169 | } |
| 8170 | |
| 8171 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8172 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8173 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8174 | |
| 8175 | // Now that all security checks passes, perform the operation as ourselves. |
| 8176 | final long identity = Binder.clearCallingIdentity(); |
| 8177 | try { |
| 8178 | Phone phone = getPhone(subId); |
| 8179 | if (phone == null) return true; // By default return true. |
| 8180 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8181 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8182 | } finally { |
| 8183 | Binder.restoreCallingIdentity(identity); |
| 8184 | } |
| 8185 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8186 | |
| 8187 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8188 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
| 8189 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8190 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8191 | if (iccRecords == null) { |
| 8192 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8193 | return false; |
| 8194 | } |
| 8195 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8196 | } |
| 8197 | |
| 8198 | @Override |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8199 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8200 | if (callingPackage == null) { |
| 8201 | callingPackage = getCurrentPackageName(); |
| 8202 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8203 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8204 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 8205 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 8206 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8207 | } |
| 8208 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8209 | Intent intent = new Intent(); |
| 8210 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8211 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8212 | // Bring up choose default SMS subscription dialog right now |
| 8213 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8214 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8215 | mApp.startActivity(intent); |
| 8216 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8217 | |
| 8218 | @Override |
| 8219 | public String getMmsUAProfUrl(int subId) { |
| 8220 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8221 | final long identity = Binder.clearCallingIdentity(); |
| 8222 | try { |
| 8223 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8224 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 8225 | } finally { |
| 8226 | Binder.restoreCallingIdentity(identity); |
| 8227 | } |
| 8228 | } |
| 8229 | |
| 8230 | @Override |
| 8231 | public String getMmsUserAgent(int subId) { |
| 8232 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8233 | final long identity = Binder.clearCallingIdentity(); |
| 8234 | try { |
| 8235 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8236 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8237 | } finally { |
| 8238 | Binder.restoreCallingIdentity(identity); |
| 8239 | } |
| 8240 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8241 | |
| 8242 | @Override |
| 8243 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 8244 | enforceModifyPermission(); |
| 8245 | |
| 8246 | // Now that all security checks passes, perform the operation as ourselves. |
| 8247 | final long identity = Binder.clearCallingIdentity(); |
| 8248 | try { |
| 8249 | Phone phone = getPhone(subId); |
| 8250 | if (phone == null) return false; |
| 8251 | |
| 8252 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 8253 | } finally { |
| 8254 | Binder.restoreCallingIdentity(identity); |
| 8255 | } |
| 8256 | } |
| 8257 | |
| 8258 | @Override |
| 8259 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 8260 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 8261 | |
| 8262 | // Now that all security checks passes, perform the operation as ourselves. |
| 8263 | final long identity = Binder.clearCallingIdentity(); |
| 8264 | try { |
| 8265 | Phone phone = getPhone(subId); |
| 8266 | if (phone == null) return false; |
| 8267 | |
| 8268 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8269 | } finally { |
| 8270 | Binder.restoreCallingIdentity(identity); |
| 8271 | } |
| 8272 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8273 | |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8274 | @Override |
| 8275 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8276 | enforceModifyPermission(); |
| 8277 | |
| 8278 | // Now that all security checks passes, perform the operation as ourselves. |
| 8279 | final long identity = Binder.clearCallingIdentity(); |
| 8280 | try { |
| 8281 | Phone phone = getPhone(subId); |
| 8282 | if (phone == null) return false; |
| 8283 | |
| 8284 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8285 | } finally { |
| 8286 | Binder.restoreCallingIdentity(identity); |
| 8287 | } |
| 8288 | } |
| 8289 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8290 | /** |
| 8291 | * Updates whether conference event pacakge handling is enabled. |
| 8292 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8293 | * otherwise. |
| 8294 | */ |
| 8295 | @Override |
| 8296 | public void setCepEnabled(boolean isCepEnabled) { |
| 8297 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8298 | |
| 8299 | final long identity = Binder.clearCallingIdentity(); |
| 8300 | try { |
| 8301 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8302 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8303 | Phone defaultPhone = phone.getImsPhone(); |
| 8304 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8305 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8306 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8307 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8308 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8309 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8310 | + imsPhone.getMsisdn()); |
| 8311 | } |
| 8312 | } |
| 8313 | } finally { |
| 8314 | Binder.restoreCallingIdentity(identity); |
| 8315 | } |
| 8316 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8317 | |
| 8318 | /** |
| 8319 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8320 | * |
| 8321 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8322 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8323 | * before being read. |
| 8324 | */ |
| 8325 | @Override |
| 8326 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8327 | isCompressed) { |
| 8328 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8329 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8330 | try { |
| 8331 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8332 | if (configBinder == null) { |
| 8333 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8334 | } else { |
| 8335 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8336 | } |
| 8337 | } catch (RemoteException e) { |
| 8338 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8339 | } |
| 8340 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8341 | |
| 8342 | @Override |
| 8343 | public boolean isIccLockEnabled(int subId) { |
| 8344 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8345 | |
| 8346 | // Now that all security checks passes, perform the operation as ourselves. |
| 8347 | final long identity = Binder.clearCallingIdentity(); |
| 8348 | try { |
| 8349 | Phone phone = getPhone(subId); |
| 8350 | if (phone != null && phone.getIccCard() != null) { |
| 8351 | return phone.getIccCard().getIccLockEnabled(); |
| 8352 | } else { |
| 8353 | return false; |
| 8354 | } |
| 8355 | } finally { |
| 8356 | Binder.restoreCallingIdentity(identity); |
| 8357 | } |
| 8358 | } |
| 8359 | |
| 8360 | /** |
| 8361 | * Set the ICC pin lock enabled or disabled.. |
| 8362 | * |
| 8363 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8364 | * 0 or a positive integer as the attempts remaining value. |
| 8365 | * |
| 8366 | */ |
| 8367 | @Override |
| 8368 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8369 | enforceModifyPermission(); |
| 8370 | |
| 8371 | Phone phone = getPhone(subId); |
| 8372 | if (phone == null) { |
| 8373 | return 0; |
| 8374 | } |
| 8375 | // Now that all security checks passes, perform the operation as ourselves. |
| 8376 | final long identity = Binder.clearCallingIdentity(); |
| 8377 | try { |
| 8378 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8379 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8380 | return attemptsRemaining; |
| 8381 | |
| 8382 | } catch (Exception e) { |
| 8383 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8384 | } finally { |
| 8385 | Binder.restoreCallingIdentity(identity); |
| 8386 | } |
| 8387 | return 0; |
| 8388 | } |
| 8389 | |
| 8390 | /** |
| 8391 | * Change the ICC password used in ICC pin lock. |
| 8392 | * |
| 8393 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8394 | * 0 or a positive integer as the attempts remaining value. |
| 8395 | * |
| 8396 | */ |
| 8397 | @Override |
| 8398 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8399 | enforceModifyPermission(); |
| 8400 | |
| 8401 | Phone phone = getPhone(subId); |
| 8402 | if (phone == null) { |
| 8403 | return 0; |
| 8404 | } |
| 8405 | // Now that all security checks passes, perform the operation as ourselves. |
| 8406 | final long identity = Binder.clearCallingIdentity(); |
| 8407 | try { |
| 8408 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8409 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8410 | return attemptsRemaining; |
| 8411 | |
| 8412 | } catch (Exception e) { |
| 8413 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8414 | } finally { |
| 8415 | Binder.restoreCallingIdentity(identity); |
| 8416 | } |
| 8417 | return 0; |
| 8418 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8419 | } |