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; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -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; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 49 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 50 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 51 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 52 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 53 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 54 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 55 | import android.os.ServiceSpecificException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 57 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 58 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 59 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 60 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 61 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 62 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 63 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 65 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 66 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 67 | import android.telephony.Annotation.ApnType; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 68 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 69 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 70 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 71 | import android.telephony.CellIdentityCdma; |
| 72 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 73 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfoGsm; |
| 75 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 76 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 77 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 78 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 79 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 80 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 81 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 82 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 83 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 84 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 85 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 86 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 87 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 88 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 89 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 90 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 91 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 92 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 93 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 94 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 95 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 96 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 97 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 98 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 99 | import android.telephony.data.ApnSetting; |
| 100 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 101 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 102 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 103 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 108 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 109 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 110 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 111 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 112 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 113 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 114 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 115 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 116 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 117 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 118 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 119 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 120 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 121 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 122 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 123 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 131 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.IBooleanConsumer; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 158 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 170 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 172 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 173 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 174 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 175 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 176 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 177 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 178 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 179 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 180 | import java.io.FileDescriptor; |
| 181 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 182 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 183 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 184 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 185 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 186 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 187 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 188 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 189 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 190 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 191 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 192 | import java.util.function.Consumer; |
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 | 2737e88 | 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 | d63128d | 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 | e02881a | 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; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 278 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 279 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 280 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 281 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 282 | // Parameters of select command. |
| 283 | private static final int SELECT_COMMAND = 0xA4; |
| 284 | private static final int SELECT_P1 = 0x04; |
| 285 | private static final int SELECT_P2 = 0; |
| 286 | private static final int SELECT_P3 = 0x10; |
| 287 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 288 | /** The singleton instance. */ |
| 289 | private static PhoneInterfaceManager sInstance; |
| 290 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 291 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 292 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 293 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 294 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 295 | private AppOpsManager mAppOps; |
| 296 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 297 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 298 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 299 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 300 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 301 | /** User Activity */ |
| 302 | private AtomicBoolean mNotifyUserActivity; |
| 303 | private static final String ACTION_USER_ACTIVITY_NOTIFICATION = |
| 304 | "android.intent.action.USER_ACTIVITY_NOTIFICATION"; |
| 305 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 306 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 307 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 308 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 309 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 310 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 311 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 312 | // String to store multi SIM allowed |
| 313 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 314 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 315 | // The AID of ISD-R. |
| 316 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 317 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 318 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 319 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 320 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 321 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 322 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 323 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 324 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 325 | */ |
| 326 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 327 | "reset_network_erase_modem_config_enabled"; |
| 328 | |
| 329 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 330 | * A request object to use for transmitting data to an ICC. |
| 331 | */ |
| 332 | private static final class IccAPDUArgument { |
| 333 | public int channel, cla, command, p1, p2, p3; |
| 334 | public String data; |
| 335 | |
| 336 | public IccAPDUArgument(int channel, int cla, int command, |
| 337 | int p1, int p2, int p3, String data) { |
| 338 | this.channel = channel; |
| 339 | this.cla = cla; |
| 340 | this.command = command; |
| 341 | this.p1 = p1; |
| 342 | this.p2 = p2; |
| 343 | this.p3 = p3; |
| 344 | this.data = data; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 349 | * A request object to use for transmitting data to an ICC. |
| 350 | */ |
| 351 | private static final class ManualNetworkSelectionArgument { |
| 352 | public OperatorInfo operatorInfo; |
| 353 | public boolean persistSelection; |
| 354 | |
| 355 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 356 | this.operatorInfo = operatorInfo; |
| 357 | this.persistSelection = persistSelection; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 362 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 363 | * request after sending. The main thread will notify the request when it is complete. |
| 364 | */ |
| 365 | private static final class MainThreadRequest { |
| 366 | /** The argument to use for the request */ |
| 367 | public Object argument; |
| 368 | /** The result of the request that is run on the main thread */ |
| 369 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 370 | // The subscriber id that this request applies to. Defaults to |
| 371 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 372 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 373 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 374 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 375 | public Phone phone; |
| 376 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 377 | public WorkSource workSource; |
| 378 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 379 | public MainThreadRequest(Object argument) { |
| 380 | this.argument = argument; |
| 381 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 382 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 383 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 384 | this.argument = argument; |
| 385 | if (phone != null) { |
| 386 | this.phone = phone; |
| 387 | } |
| 388 | this.workSource = workSource; |
| 389 | } |
| 390 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 391 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 392 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 393 | if (subId != null) { |
| 394 | this.subId = subId; |
| 395 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 396 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 397 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 400 | private static final class IncomingThirdPartyCallArgs { |
| 401 | public final ComponentName component; |
| 402 | public final String callId; |
| 403 | public final String callerDisplayName; |
| 404 | |
| 405 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 406 | String callerDisplayName) { |
| 407 | this.component = component; |
| 408 | this.callId = callId; |
| 409 | this.callerDisplayName = callerDisplayName; |
| 410 | } |
| 411 | } |
| 412 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 413 | /** |
| 414 | * A handler that processes messages on the main thread in the phone process. Since many |
| 415 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 416 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 417 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 418 | * on, which will be notified when the operation completes and will contain the result of the |
| 419 | * request. |
| 420 | * |
| 421 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 422 | * note that request.result must be set to something non-null for the calling thread to |
| 423 | * unblock. |
| 424 | */ |
| 425 | private final class MainThreadHandler extends Handler { |
| 426 | @Override |
| 427 | public void handleMessage(Message msg) { |
| 428 | MainThreadRequest request; |
| 429 | Message onCompleted; |
| 430 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 431 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 432 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 433 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 434 | |
| 435 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 436 | case CMD_HANDLE_USSD_REQUEST: { |
| 437 | request = (MainThreadRequest) msg.obj; |
| 438 | final Phone phone = getPhoneFromRequest(request); |
| 439 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 440 | String ussdRequest = ussdObject.first; |
| 441 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 442 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 443 | if (!isUssdApiAllowed(request.subId)) { |
| 444 | // Carrier does not support use of this API, return failure. |
| 445 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 446 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 447 | Bundle returnData = new Bundle(); |
| 448 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 449 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 450 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 451 | request.result = true; |
| 452 | notifyRequester(request); |
| 453 | return; |
| 454 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 455 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 456 | try { |
| 457 | request.result = phone != null |
| 458 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 459 | } catch (CallStateException cse) { |
| 460 | request.result = false; |
| 461 | } |
| 462 | // Wake up the requesting thread |
| 463 | notifyRequester(request); |
| 464 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 467 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 468 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 469 | final Phone phone = getPhoneFromRequest(request); |
| 470 | request.result = phone != null ? |
| 471 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 472 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 473 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 474 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 475 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 476 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 477 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 478 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 479 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 480 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 481 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 482 | if (uiccCard == null) { |
| 483 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 484 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 485 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 486 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 487 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 488 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 489 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 490 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 491 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 492 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 493 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 494 | break; |
| 495 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 496 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 497 | ar = (AsyncResult) msg.obj; |
| 498 | request = (MainThreadRequest) ar.userObj; |
| 499 | if (ar.exception == null && ar.result != null) { |
| 500 | request.result = ar.result; |
| 501 | } else { |
| 502 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 503 | if (ar.result == null) { |
| 504 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 505 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 506 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 507 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 508 | } else { |
| 509 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 510 | } |
| 511 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 512 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 513 | break; |
| 514 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 515 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 516 | request = (MainThreadRequest) msg.obj; |
| 517 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 518 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 519 | if (uiccCard == null) { |
| 520 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 521 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 522 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 523 | } else { |
| 524 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 525 | request); |
| 526 | uiccCard.iccTransmitApduBasicChannel( |
| 527 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 528 | iccArgument.p3, iccArgument.data, onCompleted); |
| 529 | } |
| 530 | break; |
| 531 | |
| 532 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 533 | ar = (AsyncResult) msg.obj; |
| 534 | request = (MainThreadRequest) ar.userObj; |
| 535 | if (ar.exception == null && ar.result != null) { |
| 536 | request.result = ar.result; |
| 537 | } else { |
| 538 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 539 | if (ar.result == null) { |
| 540 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 541 | } else if (ar.exception instanceof CommandException) { |
| 542 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 543 | ar.exception); |
| 544 | } else { |
| 545 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 546 | } |
| 547 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 548 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 549 | break; |
| 550 | |
| 551 | case CMD_EXCHANGE_SIM_IO: |
| 552 | request = (MainThreadRequest) msg.obj; |
| 553 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 554 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 555 | if (uiccCard == null) { |
| 556 | loge("iccExchangeSimIO: No UICC"); |
| 557 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 558 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 559 | } else { |
| 560 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 561 | request); |
| 562 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 563 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 564 | iccArgument.data, onCompleted); |
| 565 | } |
| 566 | break; |
| 567 | |
| 568 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 569 | ar = (AsyncResult) msg.obj; |
| 570 | request = (MainThreadRequest) ar.userObj; |
| 571 | if (ar.exception == null && ar.result != null) { |
| 572 | request.result = ar.result; |
| 573 | } else { |
| 574 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 575 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 576 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 577 | break; |
| 578 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 579 | case CMD_SEND_ENVELOPE: |
| 580 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 581 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 582 | if (uiccCard == null) { |
| 583 | loge("sendEnvelopeWithStatus: No UICC"); |
| 584 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 585 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 586 | } else { |
| 587 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 588 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 589 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 590 | break; |
| 591 | |
| 592 | case EVENT_SEND_ENVELOPE_DONE: |
| 593 | ar = (AsyncResult) msg.obj; |
| 594 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 595 | if (ar.exception == null && ar.result != null) { |
| 596 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 597 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 598 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 599 | if (ar.result == null) { |
| 600 | loge("sendEnvelopeWithStatus: Empty response"); |
| 601 | } else if (ar.exception instanceof CommandException) { |
| 602 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 603 | ar.exception); |
| 604 | } else { |
| 605 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 606 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 607 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 608 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 609 | break; |
| 610 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 611 | case CMD_OPEN_CHANNEL: |
| 612 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 613 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 614 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 615 | if (uiccCard == null) { |
| 616 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 617 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 618 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 619 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 620 | } else { |
| 621 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 622 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 623 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 624 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 625 | break; |
| 626 | |
| 627 | case EVENT_OPEN_CHANNEL_DONE: |
| 628 | ar = (AsyncResult) msg.obj; |
| 629 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 630 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 631 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 632 | int[] result = (int[]) ar.result; |
| 633 | int channelId = result[0]; |
| 634 | byte[] selectResponse = null; |
| 635 | if (result.length > 1) { |
| 636 | selectResponse = new byte[result.length - 1]; |
| 637 | for (int i = 1; i < result.length; ++i) { |
| 638 | selectResponse[i - 1] = (byte) result[i]; |
| 639 | } |
| 640 | } |
| 641 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 642 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 643 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 644 | if (ar.result == null) { |
| 645 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 646 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 647 | if (ar.exception != null) { |
| 648 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 649 | } |
| 650 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 651 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 652 | if (ar.exception instanceof CommandException) { |
| 653 | CommandException.Error error = |
| 654 | ((CommandException) (ar.exception)).getCommandError(); |
| 655 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 656 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 657 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 658 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 659 | } |
| 660 | } |
| 661 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 662 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 664 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 665 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 666 | break; |
| 667 | |
| 668 | case CMD_CLOSE_CHANNEL: |
| 669 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 670 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 671 | if (uiccCard == null) { |
| 672 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 673 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 674 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 675 | } else { |
| 676 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 677 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 678 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 679 | break; |
| 680 | |
| 681 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 682 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 683 | break; |
| 684 | |
| 685 | case CMD_NV_READ_ITEM: |
| 686 | request = (MainThreadRequest) msg.obj; |
| 687 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 688 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 689 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 690 | break; |
| 691 | |
| 692 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 693 | ar = (AsyncResult) msg.obj; |
| 694 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 695 | if (ar.exception == null && ar.result != null) { |
| 696 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 697 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 698 | request.result = ""; |
| 699 | if (ar.result == null) { |
| 700 | loge("nvReadItem: Empty response"); |
| 701 | } else if (ar.exception instanceof CommandException) { |
| 702 | loge("nvReadItem: CommandException: " + |
| 703 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 704 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 705 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 706 | } |
| 707 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 708 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 709 | break; |
| 710 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 711 | case CMD_NV_WRITE_ITEM: |
| 712 | request = (MainThreadRequest) msg.obj; |
| 713 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 714 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 715 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 716 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 717 | break; |
| 718 | |
| 719 | case EVENT_NV_WRITE_ITEM_DONE: |
| 720 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 721 | break; |
| 722 | |
| 723 | case CMD_NV_WRITE_CDMA_PRL: |
| 724 | request = (MainThreadRequest) msg.obj; |
| 725 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 726 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 727 | break; |
| 728 | |
| 729 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 730 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 731 | break; |
| 732 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 733 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 734 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 735 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 736 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 737 | break; |
| 738 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 739 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 740 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 741 | break; |
| 742 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 743 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 744 | request = (MainThreadRequest) msg.obj; |
| 745 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 746 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 747 | break; |
| 748 | |
| 749 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 750 | ar = (AsyncResult) msg.obj; |
| 751 | request = (MainThreadRequest) ar.userObj; |
| 752 | if (ar.exception == null && ar.result != null) { |
| 753 | request.result = ar.result; // Integer |
| 754 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 755 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 756 | if (ar.result == null) { |
| 757 | loge("getPreferredNetworkType: Empty response"); |
| 758 | } else if (ar.exception instanceof CommandException) { |
| 759 | loge("getPreferredNetworkType: CommandException: " + |
| 760 | ar.exception); |
| 761 | } else { |
| 762 | loge("getPreferredNetworkType: Unknown exception"); |
| 763 | } |
| 764 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 765 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 766 | break; |
| 767 | |
| 768 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 769 | request = (MainThreadRequest) msg.obj; |
| 770 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 771 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 772 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 773 | break; |
| 774 | |
| 775 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 776 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 777 | break; |
| 778 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 779 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 780 | request = (MainThreadRequest)msg.obj; |
| 781 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 782 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 783 | break; |
| 784 | |
| 785 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 786 | ar = (AsyncResult)msg.obj; |
| 787 | request = (MainThreadRequest)ar.userObj; |
| 788 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 789 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 790 | break; |
| 791 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 792 | case CMD_SET_VOICEMAIL_NUMBER: |
| 793 | request = (MainThreadRequest) msg.obj; |
| 794 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 795 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 796 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 797 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 798 | break; |
| 799 | |
| 800 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 801 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 802 | break; |
| 803 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 804 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 805 | request = (MainThreadRequest) msg.obj; |
| 806 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 807 | request); |
| 808 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 809 | break; |
| 810 | |
| 811 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 812 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 813 | break; |
| 814 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 815 | case CMD_PERFORM_NETWORK_SCAN: |
| 816 | request = (MainThreadRequest) msg.obj; |
| 817 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 818 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 819 | break; |
| 820 | |
| 821 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 822 | ar = (AsyncResult) msg.obj; |
| 823 | request = (MainThreadRequest) ar.userObj; |
| 824 | CellNetworkScanResult cellScanResult; |
| 825 | if (ar.exception == null && ar.result != null) { |
| 826 | cellScanResult = new CellNetworkScanResult( |
| 827 | CellNetworkScanResult.STATUS_SUCCESS, |
| 828 | (List<OperatorInfo>) ar.result); |
| 829 | } else { |
| 830 | if (ar.result == null) { |
| 831 | loge("getCellNetworkScanResults: Empty response"); |
| 832 | } |
| 833 | if (ar.exception != null) { |
| 834 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 835 | } |
| 836 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 837 | if (ar.exception instanceof CommandException) { |
| 838 | CommandException.Error error = |
| 839 | ((CommandException) (ar.exception)).getCommandError(); |
| 840 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 841 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 842 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 843 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 844 | } |
| 845 | } |
| 846 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 847 | } |
| 848 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 849 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 850 | break; |
| 851 | |
| 852 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 853 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 854 | ManualNetworkSelectionArgument selArg = |
| 855 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 856 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 857 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 858 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 859 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 860 | break; |
| 861 | |
| 862 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 863 | ar = (AsyncResult) msg.obj; |
| 864 | request = (MainThreadRequest) ar.userObj; |
| 865 | if (ar.exception == null) { |
| 866 | request.result = true; |
| 867 | } else { |
| 868 | request.result = false; |
| 869 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 870 | } |
| 871 | notifyRequester(request); |
| 872 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 873 | break; |
| 874 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 875 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 876 | request = (MainThreadRequest) msg.obj; |
| 877 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 878 | if (defaultPhone != null) { |
| 879 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 880 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 881 | break; |
| 882 | |
| 883 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 884 | ar = (AsyncResult) msg.obj; |
| 885 | request = (MainThreadRequest) ar.userObj; |
| 886 | if (ar.exception == null && ar.result != null) { |
| 887 | request.result = ar.result; |
| 888 | } else { |
| 889 | if (ar.result == null) { |
| 890 | loge("queryModemActivityInfo: Empty response"); |
| 891 | } else if (ar.exception instanceof CommandException) { |
| 892 | loge("queryModemActivityInfo: CommandException: " + |
| 893 | ar.exception); |
| 894 | } else { |
| 895 | loge("queryModemActivityInfo: Unknown exception"); |
| 896 | } |
| 897 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 898 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 899 | if (request.result == null) { |
Peter Collingbourne | c00e902 | 2019-11-26 09:56:26 -0800 | [diff] [blame] | 900 | request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 901 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 902 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 903 | break; |
| 904 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 905 | case CMD_SET_ALLOWED_CARRIERS: |
| 906 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 907 | CarrierRestrictionRules argument = |
| 908 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 909 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 910 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 911 | break; |
| 912 | |
| 913 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 914 | ar = (AsyncResult) msg.obj; |
| 915 | request = (MainThreadRequest) ar.userObj; |
| 916 | if (ar.exception == null && ar.result != null) { |
| 917 | request.result = ar.result; |
| 918 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 919 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 920 | if (ar.exception instanceof CommandException) { |
| 921 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 922 | CommandException.Error error = |
| 923 | ((CommandException) (ar.exception)).getCommandError(); |
| 924 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 925 | request.result = |
| 926 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 927 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 928 | } else { |
| 929 | loge("setAllowedCarriers: Unknown exception"); |
| 930 | } |
| 931 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 932 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 933 | break; |
| 934 | |
| 935 | case CMD_GET_ALLOWED_CARRIERS: |
| 936 | request = (MainThreadRequest) msg.obj; |
| 937 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 938 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 939 | break; |
| 940 | |
| 941 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 942 | ar = (AsyncResult) msg.obj; |
| 943 | request = (MainThreadRequest) ar.userObj; |
| 944 | if (ar.exception == null && ar.result != null) { |
| 945 | request.result = ar.result; |
| 946 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 947 | request.result = new IllegalStateException( |
| 948 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 949 | if (ar.result == null) { |
| 950 | loge("getAllowedCarriers: Empty response"); |
| 951 | } else if (ar.exception instanceof CommandException) { |
| 952 | loge("getAllowedCarriers: CommandException: " + |
| 953 | ar.exception); |
| 954 | } else { |
| 955 | loge("getAllowedCarriers: Unknown exception"); |
| 956 | } |
| 957 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 958 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 959 | break; |
| 960 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 961 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 962 | ar = (AsyncResult) msg.obj; |
| 963 | request = (MainThreadRequest) ar.userObj; |
| 964 | if (ar.exception == null && ar.result != null) { |
| 965 | request.result = ar.result; |
| 966 | } else { |
| 967 | request.result = new IllegalArgumentException( |
| 968 | "Failed to retrieve Forbidden Plmns"); |
| 969 | if (ar.result == null) { |
| 970 | loge("getForbiddenPlmns: Empty response"); |
| 971 | } else { |
| 972 | loge("getForbiddenPlmns: Unknown exception"); |
| 973 | } |
| 974 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 975 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 976 | break; |
| 977 | |
| 978 | case CMD_GET_FORBIDDEN_PLMNS: |
| 979 | request = (MainThreadRequest) msg.obj; |
| 980 | uiccCard = getUiccCardFromRequest(request); |
| 981 | if (uiccCard == null) { |
| 982 | loge("getForbiddenPlmns() UiccCard is null"); |
| 983 | request.result = new IllegalArgumentException( |
| 984 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 985 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 986 | break; |
| 987 | } |
| 988 | Integer appType = (Integer) request.argument; |
| 989 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 990 | if (uiccApp == null) { |
| 991 | loge("getForbiddenPlmns() no app with specified type -- " |
| 992 | + appType); |
| 993 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 994 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 995 | break; |
| 996 | } else { |
| 997 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 998 | + " specified type -- " + appType); |
| 999 | } |
| 1000 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1001 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1002 | onCompleted); |
| 1003 | break; |
| 1004 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1005 | case CMD_SWITCH_SLOTS: |
| 1006 | request = (MainThreadRequest) msg.obj; |
| 1007 | int[] physicalSlots = (int[]) request.argument; |
| 1008 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1009 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1010 | break; |
| 1011 | |
| 1012 | case EVENT_SWITCH_SLOTS_DONE: |
| 1013 | ar = (AsyncResult) msg.obj; |
| 1014 | request = (MainThreadRequest) ar.userObj; |
| 1015 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1016 | notifyRequester(request); |
| 1017 | break; |
| 1018 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1019 | request = (MainThreadRequest) msg.obj; |
| 1020 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1021 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1022 | break; |
| 1023 | |
| 1024 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1025 | ar = (AsyncResult) msg.obj; |
| 1026 | request = (MainThreadRequest) ar.userObj; |
| 1027 | if (ar.exception != null) { |
| 1028 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1029 | } else { |
| 1030 | int mode = ((int[]) ar.result)[0]; |
| 1031 | if (mode == 0) { |
| 1032 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1033 | } else { |
| 1034 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1035 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1036 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1037 | notifyRequester(request); |
| 1038 | break; |
| 1039 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1040 | request = (MainThreadRequest) msg.obj; |
| 1041 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1042 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1043 | break; |
| 1044 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1045 | ar = (AsyncResult) msg.obj; |
| 1046 | request = (MainThreadRequest) ar.userObj; |
| 1047 | if (ar.exception != null) { |
| 1048 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1049 | } else { |
| 1050 | request.result = ((int[]) ar.result)[0]; |
| 1051 | } |
| 1052 | notifyRequester(request); |
| 1053 | break; |
| 1054 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1055 | request = (MainThreadRequest) msg.obj; |
| 1056 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1057 | int mode = (int) request.argument; |
| 1058 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1059 | break; |
| 1060 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1061 | ar = (AsyncResult) msg.obj; |
| 1062 | request = (MainThreadRequest) ar.userObj; |
| 1063 | request.result = ar.exception == null; |
| 1064 | notifyRequester(request); |
| 1065 | break; |
| 1066 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1067 | request = (MainThreadRequest) msg.obj; |
| 1068 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1069 | int subscriptionMode = (int) request.argument; |
| 1070 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1071 | break; |
| 1072 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1073 | ar = (AsyncResult) msg.obj; |
| 1074 | request = (MainThreadRequest) ar.userObj; |
| 1075 | request.result = ar.exception == null; |
| 1076 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1077 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1078 | case CMD_GET_ALL_CELL_INFO: |
| 1079 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1080 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1081 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1082 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1083 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1084 | ar = (AsyncResult) msg.obj; |
| 1085 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1086 | // If a timeout occurs, the response will be null |
| 1087 | request.result = (ar.exception == null && ar.result != null) |
| 1088 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1089 | synchronized (request) { |
| 1090 | request.notifyAll(); |
| 1091 | } |
| 1092 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1093 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1094 | request = (MainThreadRequest) msg.obj; |
| 1095 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1096 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1097 | break; |
| 1098 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1099 | ar = (AsyncResult) msg.obj; |
| 1100 | request = (MainThreadRequest) ar.userObj; |
| 1101 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1102 | try { |
| 1103 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1104 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1105 | cb.onError( |
| 1106 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1107 | ar.exception.getClass().getName(), |
| 1108 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1109 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1110 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1111 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1112 | } else { |
| 1113 | // use the result as returned |
| 1114 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1115 | } |
| 1116 | } catch (RemoteException re) { |
| 1117 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1118 | } |
| 1119 | break; |
| 1120 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1121 | request = (MainThreadRequest) msg.obj; |
| 1122 | WorkSource ws = (WorkSource) request.argument; |
| 1123 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1124 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1125 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1126 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1127 | ar = (AsyncResult) msg.obj; |
| 1128 | request = (MainThreadRequest) ar.userObj; |
| 1129 | if (ar.exception == null) { |
| 1130 | request.result = ar.result; |
| 1131 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1132 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1133 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1134 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | synchronized (request) { |
| 1138 | request.notifyAll(); |
| 1139 | } |
| 1140 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1141 | case CMD_MODEM_REBOOT: |
| 1142 | request = (MainThreadRequest) msg.obj; |
| 1143 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1144 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1145 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1146 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1147 | handleNullReturnEvent(msg, "rebootModem"); |
| 1148 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1149 | case CMD_REQUEST_ENABLE_MODEM: |
| 1150 | request = (MainThreadRequest) msg.obj; |
| 1151 | boolean enable = (boolean) request.argument; |
| 1152 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1153 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1154 | PhoneConfigurationManager.getInstance() |
| 1155 | .enablePhone(request.phone, enable, onCompleted); |
| 1156 | break; |
| 1157 | case EVENT_ENABLE_MODEM_DONE: |
| 1158 | ar = (AsyncResult) msg.obj; |
| 1159 | request = (MainThreadRequest) ar.userObj; |
| 1160 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1161 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1162 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1163 | if ((boolean) request.result) { |
| 1164 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1165 | updateModemStateMetrics(); |
| 1166 | } else { |
| 1167 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1168 | + ar.exception); |
| 1169 | } |
| 1170 | notifyRequester(request); |
| 1171 | break; |
| 1172 | case CMD_GET_MODEM_STATUS: |
| 1173 | request = (MainThreadRequest) msg.obj; |
| 1174 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1175 | PhoneConfigurationManager.getInstance() |
| 1176 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1177 | break; |
| 1178 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1179 | ar = (AsyncResult) msg.obj; |
| 1180 | request = (MainThreadRequest) ar.userObj; |
| 1181 | int id = request.phone.getPhoneId(); |
| 1182 | if (ar.exception == null && ar.result != null) { |
| 1183 | request.result = ar.result; |
| 1184 | //update the cache as modem status has changed |
| 1185 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1186 | (boolean) request.result); |
| 1187 | } else { |
| 1188 | // Return true if modem status cannot be retrieved. For most cases, |
| 1189 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1190 | // and disable modem are not supported. Modem is always on. |
| 1191 | // TODO: this should be fixed in R to support a third |
| 1192 | // status UNKNOWN b/131631629 |
| 1193 | request.result = true; |
| 1194 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1195 | + ar.exception); |
| 1196 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1197 | notifyRequester(request); |
| 1198 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1199 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1200 | request = (MainThreadRequest) msg.obj; |
| 1201 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1202 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1203 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1204 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1205 | break; |
| 1206 | } |
| 1207 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1208 | ar = (AsyncResult) msg.obj; |
| 1209 | request = (MainThreadRequest) ar.userObj; |
| 1210 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1211 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1212 | args.second.accept(ar.exception == null); |
| 1213 | notifyRequester(request); |
| 1214 | break; |
| 1215 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1216 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1217 | ar = (AsyncResult) msg.obj; |
| 1218 | request = (MainThreadRequest) ar.userObj; |
| 1219 | if (ar.exception == null && ar.result != null) { |
| 1220 | request.result = ar.result; |
| 1221 | } else { |
| 1222 | request.result = -1; |
| 1223 | loge("Failed to set Forbidden Plmns"); |
| 1224 | if (ar.result == null) { |
| 1225 | loge("setForbidenPlmns: Empty response"); |
| 1226 | } else if (ar.exception != null) { |
| 1227 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1228 | request.result = -1; |
| 1229 | } else { |
| 1230 | loge("setForbiddenPlmns: Unknown exception"); |
| 1231 | } |
| 1232 | } |
| 1233 | notifyRequester(request); |
| 1234 | break; |
| 1235 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1236 | request = (MainThreadRequest) msg.obj; |
| 1237 | uiccCard = getUiccCardFromRequest(request); |
| 1238 | if (uiccCard == null) { |
| 1239 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1240 | request.result = -1; |
| 1241 | notifyRequester(request); |
| 1242 | break; |
| 1243 | } |
| 1244 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1245 | (Pair<Integer, List<String>>) request.argument; |
| 1246 | appType = setFplmnsArgs.first; |
| 1247 | List<String> fplmns = setFplmnsArgs.second; |
| 1248 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1249 | if (uiccApp == null) { |
| 1250 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1251 | request.result = -1; |
| 1252 | loge("Failed to get UICC App"); |
| 1253 | notifyRequester(request); |
| 1254 | } else { |
| 1255 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1256 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1257 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1258 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1259 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1260 | case CMD_ERASE_MODEM_CONFIG: |
| 1261 | request = (MainThreadRequest) msg.obj; |
| 1262 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1263 | defaultPhone.eraseModemConfig(onCompleted); |
| 1264 | break; |
| 1265 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1266 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1267 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1268 | |
| 1269 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1270 | request = (MainThreadRequest) msg.obj; |
| 1271 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1272 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1273 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1274 | changed.first, changed.second, onCompleted); |
| 1275 | break; |
| 1276 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1277 | ar = (AsyncResult) msg.obj; |
| 1278 | request = (MainThreadRequest) ar.userObj; |
| 1279 | if (ar.exception == null) { |
| 1280 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1281 | } else { |
| 1282 | request.result = msg.arg1; |
| 1283 | } |
| 1284 | notifyRequester(request); |
| 1285 | break; |
| 1286 | |
| 1287 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1288 | request = (MainThreadRequest) msg.obj; |
| 1289 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1290 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1291 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1292 | enabled.first, enabled.second, onCompleted); |
| 1293 | break; |
| 1294 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1295 | ar = (AsyncResult) msg.obj; |
| 1296 | request = (MainThreadRequest) ar.userObj; |
| 1297 | if (ar.exception == null) { |
| 1298 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1299 | } else { |
| 1300 | request.result = msg.arg1; |
| 1301 | } |
| 1302 | notifyRequester(request); |
| 1303 | break; |
| 1304 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1305 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1306 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
| 1307 | Intent intent = new Intent(ACTION_USER_ACTIVITY_NOTIFICATION); |
| 1308 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1309 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1310 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1311 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1312 | default: |
| 1313 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1314 | break; |
| 1315 | } |
| 1316 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1317 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1318 | private void notifyRequester(MainThreadRequest request) { |
| 1319 | synchronized (request) { |
| 1320 | request.notifyAll(); |
| 1321 | } |
| 1322 | } |
| 1323 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1324 | private void handleNullReturnEvent(Message msg, String command) { |
| 1325 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1326 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1327 | if (ar.exception == null) { |
| 1328 | request.result = true; |
| 1329 | } else { |
| 1330 | request.result = false; |
| 1331 | if (ar.exception instanceof CommandException) { |
| 1332 | loge(command + ": CommandException: " + ar.exception); |
| 1333 | } else { |
| 1334 | loge(command + ": Unknown exception"); |
| 1335 | } |
| 1336 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1337 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1338 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | /** |
| 1342 | * Posts the specified command to be executed on the main thread, |
| 1343 | * waits for the request to complete, and returns the result. |
| 1344 | * @see #sendRequestAsync |
| 1345 | */ |
| 1346 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1347 | return sendRequest( |
| 1348 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | /** |
| 1352 | * Posts the specified command to be executed on the main thread, |
| 1353 | * waits for the request to complete, and returns the result. |
| 1354 | * @see #sendRequestAsync |
| 1355 | */ |
| 1356 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1357 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1358 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | /** |
| 1362 | * Posts the specified command to be executed on the main thread, |
| 1363 | * waits for the request to complete, and returns the result. |
| 1364 | * @see #sendRequestAsync |
| 1365 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1366 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1367 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | /** |
| 1371 | * Posts the specified command to be executed on the main thread, |
| 1372 | * waits for the request to complete, and returns the result. |
| 1373 | * @see #sendRequestAsync |
| 1374 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1375 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1376 | return sendRequest(command, argument, subId, null, workSource); |
| 1377 | } |
| 1378 | |
| 1379 | /** |
| 1380 | * Posts the specified command to be executed on the main thread, |
| 1381 | * waits for the request to complete, and returns the result. |
| 1382 | * @see #sendRequestAsync |
| 1383 | */ |
| 1384 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1385 | return sendRequest( |
| 1386 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1387 | } |
| 1388 | |
| 1389 | /** |
| 1390 | * Posts the specified command to be executed on the main thread, |
| 1391 | * waits for the request to complete, and returns the result. |
| 1392 | * @see #sendRequestAsync |
| 1393 | */ |
| 1394 | private Object sendRequest( |
| 1395 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1396 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1397 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1398 | } |
| 1399 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1400 | MainThreadRequest request = null; |
| 1401 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1402 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1403 | } else if (phone != null) { |
| 1404 | request = new MainThreadRequest(argument, phone, workSource); |
| 1405 | } else { |
| 1406 | request = new MainThreadRequest(argument, subId, workSource); |
| 1407 | } |
| 1408 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1409 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1410 | msg.sendToTarget(); |
| 1411 | |
| 1412 | // Wait for the request to complete |
| 1413 | synchronized (request) { |
| 1414 | while (request.result == null) { |
| 1415 | try { |
| 1416 | request.wait(); |
| 1417 | } catch (InterruptedException e) { |
| 1418 | // Do nothing, go back and wait until the request is complete |
| 1419 | } |
| 1420 | } |
| 1421 | } |
| 1422 | return request.result; |
| 1423 | } |
| 1424 | |
| 1425 | /** |
| 1426 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1427 | * Posts the specified command to be executed on the main thread, and |
| 1428 | * returns immediately. |
| 1429 | * @see #sendRequest |
| 1430 | */ |
| 1431 | private void sendRequestAsync(int command) { |
| 1432 | mMainThreadHandler.sendEmptyMessage(command); |
| 1433 | } |
| 1434 | |
| 1435 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1436 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1437 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1438 | */ |
| 1439 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1440 | sendRequestAsync(command, argument, null, null); |
| 1441 | } |
| 1442 | |
| 1443 | /** |
| 1444 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1445 | * @see {@link #sendRequest(int,Object)} |
| 1446 | */ |
| 1447 | private void sendRequestAsync( |
| 1448 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1449 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1450 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1451 | msg.sendToTarget(); |
| 1452 | } |
| 1453 | |
| 1454 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1455 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1456 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1457 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1458 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1459 | synchronized (PhoneInterfaceManager.class) { |
| 1460 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1461 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1462 | } else { |
| 1463 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1464 | } |
| 1465 | return sInstance; |
| 1466 | } |
| 1467 | } |
| 1468 | |
| 1469 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1470 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1471 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1472 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1473 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1474 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1475 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1476 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1477 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1478 | mTelephonySharedPreferences = |
| 1479 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1480 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1481 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1482 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1483 | publish(); |
| 1484 | } |
| 1485 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1486 | private Phone getDefaultPhone() { |
| 1487 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1488 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1489 | } |
| 1490 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1491 | private void publish() { |
| 1492 | if (DBG) log("publish: " + this); |
| 1493 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1494 | TelephonyFrameworkInitializer |
| 1495 | .getTelephonyServiceManager() |
| 1496 | .getTelephonyServiceRegisterer() |
| 1497 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1500 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1501 | if (request.phone != null) { |
| 1502 | return request.phone; |
| 1503 | } else { |
| 1504 | return getPhoneFromSubId(request.subId); |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | private Phone getPhoneFromSubId(int subId) { |
| 1509 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1510 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1511 | } |
| 1512 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1513 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1514 | Phone phone = getPhoneFromRequest(request); |
| 1515 | return phone == null ? null : |
| 1516 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1517 | } |
| 1518 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1519 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1520 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1521 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1522 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1523 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1524 | private void sendEraseModemConfig(Phone phone) { |
| 1525 | if (phone != null) { |
| 1526 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1527 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1528 | final long identity = Binder.clearCallingIdentity(); |
| 1529 | try { |
| 1530 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1531 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1532 | } finally { |
| 1533 | Binder.restoreCallingIdentity(identity); |
| 1534 | } |
| 1535 | } |
| 1536 | } |
| 1537 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1538 | private boolean isImsAvailableOnDevice() { |
| 1539 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1540 | if (pm == null) { |
| 1541 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1542 | // so do not throw error and allow. |
| 1543 | return true; |
| 1544 | } |
| 1545 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1546 | } |
| 1547 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1548 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1549 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1552 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1553 | if (DBG) log("dial: " + number); |
| 1554 | // No permission check needed here: This is just a wrapper around the |
| 1555 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1556 | // the UI before it does anything. |
| 1557 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1558 | final long identity = Binder.clearCallingIdentity(); |
| 1559 | try { |
| 1560 | String url = createTelUrl(number); |
| 1561 | if (url == null) { |
| 1562 | return; |
| 1563 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1564 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1565 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1566 | PhoneConstants.State state = mCM.getState(subId); |
| 1567 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1568 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1569 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1570 | mApp.startActivity(intent); |
| 1571 | } |
| 1572 | } finally { |
| 1573 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1578 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1581 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1582 | if (DBG) log("call: " + number); |
| 1583 | |
| 1584 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1585 | // need to do a permission check since we're calling startActivity() |
| 1586 | // from the context of the phone app. |
| 1587 | enforceCallPermission(); |
| 1588 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1589 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1590 | != AppOpsManager.MODE_ALLOWED) { |
| 1591 | return; |
| 1592 | } |
| 1593 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1594 | final long identity = Binder.clearCallingIdentity(); |
| 1595 | try { |
| 1596 | String url = createTelUrl(number); |
| 1597 | if (url == null) { |
| 1598 | return; |
| 1599 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1600 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1601 | boolean isValid = false; |
| 1602 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1603 | if (slist != null) { |
| 1604 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1605 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1606 | isValid = true; |
| 1607 | break; |
| 1608 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1609 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1610 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1611 | if (!isValid) { |
| 1612 | return; |
| 1613 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1614 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1615 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1616 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1617 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1618 | mApp.startActivity(intent); |
| 1619 | } finally { |
| 1620 | Binder.restoreCallingIdentity(identity); |
| 1621 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1622 | } |
| 1623 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1624 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1625 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1626 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1627 | } |
| 1628 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1629 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1630 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1631 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1632 | } |
| 1633 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1634 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1635 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1636 | |
| 1637 | final long identity = Binder.clearCallingIdentity(); |
| 1638 | try { |
| 1639 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1640 | checkSimPin.start(); |
| 1641 | return checkSimPin.unlockSim(null, pin); |
| 1642 | } finally { |
| 1643 | Binder.restoreCallingIdentity(identity); |
| 1644 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1645 | } |
| 1646 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1647 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1648 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1649 | |
| 1650 | final long identity = Binder.clearCallingIdentity(); |
| 1651 | try { |
| 1652 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1653 | checkSimPuk.start(); |
| 1654 | return checkSimPuk.unlockSim(puk, pin); |
| 1655 | } finally { |
| 1656 | Binder.restoreCallingIdentity(identity); |
| 1657 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1661 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1662 | * a synchronous one. |
| 1663 | */ |
| 1664 | private static class UnlockSim extends Thread { |
| 1665 | |
| 1666 | private final IccCard mSimCard; |
| 1667 | |
| 1668 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1669 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1670 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1671 | |
| 1672 | // For replies from SimCard interface |
| 1673 | private Handler mHandler; |
| 1674 | |
| 1675 | // For async handler to identify request type |
| 1676 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1677 | |
| 1678 | public UnlockSim(IccCard simCard) { |
| 1679 | mSimCard = simCard; |
| 1680 | } |
| 1681 | |
| 1682 | @Override |
| 1683 | public void run() { |
| 1684 | Looper.prepare(); |
| 1685 | synchronized (UnlockSim.this) { |
| 1686 | mHandler = new Handler() { |
| 1687 | @Override |
| 1688 | public void handleMessage(Message msg) { |
| 1689 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1690 | switch (msg.what) { |
| 1691 | case SUPPLY_PIN_COMPLETE: |
| 1692 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1693 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1694 | mRetryCount = msg.arg1; |
| 1695 | if (ar.exception != null) { |
| 1696 | if (ar.exception instanceof CommandException && |
| 1697 | ((CommandException)(ar.exception)).getCommandError() |
| 1698 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1699 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1700 | } else { |
| 1701 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1702 | } |
| 1703 | } else { |
| 1704 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1705 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1706 | mDone = true; |
| 1707 | UnlockSim.this.notifyAll(); |
| 1708 | } |
| 1709 | break; |
| 1710 | } |
| 1711 | } |
| 1712 | }; |
| 1713 | UnlockSim.this.notifyAll(); |
| 1714 | } |
| 1715 | Looper.loop(); |
| 1716 | } |
| 1717 | |
| 1718 | /* |
| 1719 | * Use PIN or PUK to unlock SIM card |
| 1720 | * |
| 1721 | * If PUK is null, unlock SIM card with PIN |
| 1722 | * |
| 1723 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1724 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1725 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1726 | |
| 1727 | while (mHandler == null) { |
| 1728 | try { |
| 1729 | wait(); |
| 1730 | } catch (InterruptedException e) { |
| 1731 | Thread.currentThread().interrupt(); |
| 1732 | } |
| 1733 | } |
| 1734 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1735 | |
| 1736 | if (puk == null) { |
| 1737 | mSimCard.supplyPin(pin, callback); |
| 1738 | } else { |
| 1739 | mSimCard.supplyPuk(puk, pin, callback); |
| 1740 | } |
| 1741 | |
| 1742 | while (!mDone) { |
| 1743 | try { |
| 1744 | Log.d(LOG_TAG, "wait for done"); |
| 1745 | wait(); |
| 1746 | } catch (InterruptedException e) { |
| 1747 | // Restore the interrupted status |
| 1748 | Thread.currentThread().interrupt(); |
| 1749 | } |
| 1750 | } |
| 1751 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1752 | int[] resultArray = new int[2]; |
| 1753 | resultArray[0] = mResult; |
| 1754 | resultArray[1] = mRetryCount; |
| 1755 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1756 | } |
| 1757 | } |
| 1758 | |
| 1759 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1760 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1761 | |
| 1762 | } |
| 1763 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1764 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1765 | // No permission check needed here: this call is harmless, and it's |
| 1766 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1767 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1768 | final long identity = Binder.clearCallingIdentity(); |
| 1769 | try { |
| 1770 | final Phone phone = getPhone(subId); |
| 1771 | if (phone != null) { |
| 1772 | phone.updateServiceLocation(); |
| 1773 | } |
| 1774 | } finally { |
| 1775 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1776 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1779 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1780 | @Override |
| 1781 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1782 | return isRadioOnWithFeature(callingPackage, null); |
| 1783 | } |
| 1784 | |
| 1785 | |
| 1786 | @Override |
| 1787 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1788 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1789 | callingFeatureId); |
| 1790 | } |
| 1791 | |
| 1792 | @Deprecated |
| 1793 | @Override |
| 1794 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 1795 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1796 | } |
| 1797 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1798 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1799 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1800 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1801 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1802 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1803 | return false; |
| 1804 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1805 | |
| 1806 | final long identity = Binder.clearCallingIdentity(); |
| 1807 | try { |
| 1808 | return isRadioOnForSubscriber(subId); |
| 1809 | } finally { |
| 1810 | Binder.restoreCallingIdentity(identity); |
| 1811 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1815 | final long identity = Binder.clearCallingIdentity(); |
| 1816 | try { |
| 1817 | final Phone phone = getPhone(subId); |
| 1818 | if (phone != null) { |
| 1819 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1820 | } else { |
| 1821 | return false; |
| 1822 | } |
| 1823 | } finally { |
| 1824 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1825 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1829 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1830 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1831 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1832 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1833 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1834 | |
| 1835 | final long identity = Binder.clearCallingIdentity(); |
| 1836 | try { |
| 1837 | final Phone phone = getPhone(subId); |
| 1838 | if (phone != null) { |
| 1839 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1840 | } |
| 1841 | } finally { |
| 1842 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1843 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1847 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1848 | } |
| 1849 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1850 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1851 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1852 | |
| 1853 | final long identity = Binder.clearCallingIdentity(); |
| 1854 | try { |
| 1855 | final Phone phone = getPhone(subId); |
| 1856 | if (phone == null) { |
| 1857 | return false; |
| 1858 | } |
| 1859 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1860 | toggleRadioOnOffForSubscriber(subId); |
| 1861 | } |
| 1862 | return true; |
| 1863 | } finally { |
| 1864 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1865 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1866 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1867 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1868 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 1869 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1870 | /* |
| 1871 | * If any of the Radios are available, it will need to be |
| 1872 | * shutdown. So return true if any Radio is available. |
| 1873 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1874 | final long identity = Binder.clearCallingIdentity(); |
| 1875 | try { |
| 1876 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1877 | Phone phone = PhoneFactory.getPhone(i); |
| 1878 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1879 | } |
| 1880 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1881 | return false; |
| 1882 | } finally { |
| 1883 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1884 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1885 | } |
| 1886 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1887 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1888 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1889 | enforceModifyPermission(); |
| 1890 | |
| 1891 | final long identity = Binder.clearCallingIdentity(); |
| 1892 | try { |
| 1893 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1894 | logv("Shutting down Phone " + i); |
| 1895 | shutdownRadioUsingPhoneId(i); |
| 1896 | } |
| 1897 | } finally { |
| 1898 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1903 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1904 | if (phone != null && phone.isRadioAvailable()) { |
| 1905 | phone.shutdownRadio(); |
| 1906 | } |
| 1907 | } |
| 1908 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1909 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1910 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1911 | |
| 1912 | final long identity = Binder.clearCallingIdentity(); |
| 1913 | try { |
| 1914 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1915 | if (defaultPhone != null) { |
| 1916 | defaultPhone.setRadioPower(turnOn); |
| 1917 | return true; |
| 1918 | } else { |
| 1919 | loge("There's no default phone."); |
| 1920 | return false; |
| 1921 | } |
| 1922 | } finally { |
| 1923 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1924 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1927 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1928 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1929 | |
| 1930 | final long identity = Binder.clearCallingIdentity(); |
| 1931 | try { |
| 1932 | final Phone phone = getPhone(subId); |
| 1933 | if (phone != null) { |
| 1934 | phone.setRadioPower(turnOn); |
| 1935 | return true; |
| 1936 | } else { |
| 1937 | return false; |
| 1938 | } |
| 1939 | } finally { |
| 1940 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1941 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1942 | } |
| 1943 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1944 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1945 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1946 | public boolean enableDataConnectivity() { |
| 1947 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1948 | |
| 1949 | final long identity = Binder.clearCallingIdentity(); |
| 1950 | try { |
| 1951 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1952 | final Phone phone = getPhone(subId); |
| 1953 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1954 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1955 | return true; |
| 1956 | } else { |
| 1957 | return false; |
| 1958 | } |
| 1959 | } finally { |
| 1960 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1961 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1964 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1965 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1966 | public boolean disableDataConnectivity() { |
| 1967 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1968 | |
| 1969 | final long identity = Binder.clearCallingIdentity(); |
| 1970 | try { |
| 1971 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1972 | final Phone phone = getPhone(subId); |
| 1973 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1974 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1975 | return true; |
| 1976 | } else { |
| 1977 | return false; |
| 1978 | } |
| 1979 | } finally { |
| 1980 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1981 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1982 | } |
| 1983 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1984 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1985 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1986 | final long identity = Binder.clearCallingIdentity(); |
| 1987 | try { |
| 1988 | final Phone phone = getPhone(subId); |
| 1989 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1990 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1991 | } else { |
| 1992 | return false; |
| 1993 | } |
| 1994 | } finally { |
| 1995 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1996 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
| 1999 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2000 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2001 | } |
| 2002 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2003 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2004 | enforceCallPermission(); |
| 2005 | |
| 2006 | final long identity = Binder.clearCallingIdentity(); |
| 2007 | try { |
| 2008 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2009 | return; |
| 2010 | } |
| 2011 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2012 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2013 | } finally { |
| 2014 | Binder.restoreCallingIdentity(identity); |
| 2015 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2016 | }; |
| 2017 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2018 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2019 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2020 | |
| 2021 | final long identity = Binder.clearCallingIdentity(); |
| 2022 | try { |
| 2023 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2024 | return false; |
| 2025 | } |
| 2026 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2027 | } finally { |
| 2028 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2029 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2030 | } |
| 2031 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2032 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2033 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2034 | } |
| 2035 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2036 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2037 | final long identity = Binder.clearCallingIdentity(); |
| 2038 | try { |
| 2039 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2040 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2041 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2042 | } finally { |
| 2043 | Binder.restoreCallingIdentity(identity); |
| 2044 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2045 | } |
| 2046 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2047 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2048 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2049 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2050 | } |
| 2051 | |
| 2052 | @Override |
| 2053 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2054 | final long identity = Binder.clearCallingIdentity(); |
| 2055 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2056 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2057 | if (phone != null) { |
| 2058 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2059 | } else { |
| 2060 | return PhoneConstantConversions.convertDataState( |
| 2061 | PhoneConstants.DataState.DISCONNECTED); |
| 2062 | } |
| 2063 | } finally { |
| 2064 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2065 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2068 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2069 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2070 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2071 | } |
| 2072 | |
| 2073 | @Override |
| 2074 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2075 | final long identity = Binder.clearCallingIdentity(); |
| 2076 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2077 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2078 | if (phone != null) { |
| 2079 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2080 | } else { |
| 2081 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2082 | } |
| 2083 | } finally { |
| 2084 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2085 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2089 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2090 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2091 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2092 | |
| 2093 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2094 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2095 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2096 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2097 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2098 | .setCallingPid(Binder.getCallingPid()) |
| 2099 | .setCallingUid(Binder.getCallingUid()) |
| 2100 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame^] | 2101 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2102 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2103 | .build()); |
| 2104 | switch (locationResult) { |
| 2105 | case DENIED_HARD: |
| 2106 | throw new SecurityException("Not allowed to access cell location"); |
| 2107 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2108 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2109 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2112 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2113 | final long identity = Binder.clearCallingIdentity(); |
| 2114 | try { |
| 2115 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2116 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2117 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2118 | } finally { |
| 2119 | Binder.restoreCallingIdentity(identity); |
| 2120 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2121 | } |
| 2122 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2123 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2124 | public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage, |
| 2125 | String callingFeatureId) { |
Jack Yu | 1e81ccd | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2126 | if (!TextUtils.isEmpty(callingPackage)) { |
| 2127 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2128 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2129 | callingFeatureId, "getNetworkCountryIsoForPhone")) { |
Jack Yu | 1e81ccd | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2130 | return ""; |
| 2131 | } |
| 2132 | } |
| 2133 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2134 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2135 | // registered cell info, so return a NULL country instead. |
| 2136 | final long identity = Binder.clearCallingIdentity(); |
| 2137 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2138 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2139 | // Get default phone in this case. |
| 2140 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2141 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2142 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2143 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2144 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2145 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2146 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(), |
| 2147 | mApp.getFeatureId())) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2148 | return ""; |
| 2149 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2150 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2151 | if (phone != null) { |
| 2152 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2153 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2154 | if (sst != null) { |
| 2155 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2156 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2157 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2158 | return lt.getCurrentCountry(); |
| 2159 | } else if (emergencyNumberTracker != null) { |
| 2160 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2161 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2162 | } |
| 2163 | } |
| 2164 | } |
| 2165 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2166 | } finally { |
| 2167 | Binder.restoreCallingIdentity(identity); |
| 2168 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2169 | } |
| 2170 | |
| 2171 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2172 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2173 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2174 | } |
| 2175 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2176 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2177 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2178 | mApp.enforceCallingOrSelfPermission( |
| 2179 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2180 | |
| 2181 | final long identity = Binder.clearCallingIdentity(); |
| 2182 | try { |
| 2183 | final Phone phone = getPhone(subId); |
| 2184 | if (phone != null) { |
| 2185 | phone.enableLocationUpdates(); |
| 2186 | } |
| 2187 | } finally { |
| 2188 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2189 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | @Override |
| 2193 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2194 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2195 | } |
| 2196 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2197 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2198 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2199 | mApp.enforceCallingOrSelfPermission( |
| 2200 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2201 | |
| 2202 | final long identity = Binder.clearCallingIdentity(); |
| 2203 | try { |
| 2204 | final Phone phone = getPhone(subId); |
| 2205 | if (phone != null) { |
| 2206 | phone.disableLocationUpdates(); |
| 2207 | } |
| 2208 | } finally { |
| 2209 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2210 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2211 | } |
| 2212 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2213 | /** |
| 2214 | * Returns the target SDK version number for a given package name. |
| 2215 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2216 | * This call MUST be invoked before clearing the calling UID. |
| 2217 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2218 | * @return target SDK if the package is found or INT_MAX. |
| 2219 | */ |
| 2220 | private int getTargetSdk(String packageName) { |
| 2221 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2222 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2223 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2224 | if (ai != null) return ai.targetSdkVersion; |
| 2225 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2226 | loge("Failed to get package info for pkg=" |
| 2227 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2228 | } |
| 2229 | return Integer.MAX_VALUE; |
| 2230 | } |
| 2231 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2232 | @Override |
| 2233 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2234 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2235 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2236 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2237 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2238 | throw new SecurityException( |
| 2239 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2240 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2241 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2242 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2243 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2244 | return null; |
| 2245 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2246 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2247 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2248 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2249 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2250 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2251 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2252 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2253 | for (CellInfo ci : info) { |
| 2254 | if (ci instanceof CellInfoGsm) { |
| 2255 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2256 | } else if (ci instanceof CellInfoWcdma) { |
| 2257 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2258 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2259 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2260 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2263 | private List<CellInfo> getCachedCellInfo() { |
| 2264 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2265 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2266 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2267 | if (info != null) cellInfos.addAll(info); |
| 2268 | } |
| 2269 | return cellInfos; |
| 2270 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2271 | |
| 2272 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2273 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2274 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2275 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2276 | |
| 2277 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2278 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2279 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2280 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2281 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2282 | .setCallingPid(Binder.getCallingPid()) |
| 2283 | .setCallingUid(Binder.getCallingUid()) |
| 2284 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2285 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2286 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2287 | .build()); |
| 2288 | switch (locationResult) { |
| 2289 | case DENIED_HARD: |
| 2290 | throw new SecurityException("Not allowed to access cell info"); |
| 2291 | case DENIED_SOFT: |
| 2292 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2293 | } |
| 2294 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2295 | final int targetSdk = getTargetSdk(callingPackage); |
| 2296 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2297 | return getCachedCellInfo(); |
| 2298 | } |
| 2299 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2300 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2301 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2302 | final long identity = Binder.clearCallingIdentity(); |
| 2303 | try { |
| 2304 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2305 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2306 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2307 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2308 | if (info != null) cellInfos.addAll(info); |
| 2309 | } |
| 2310 | return cellInfos; |
| 2311 | } finally { |
| 2312 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2313 | } |
| 2314 | } |
| 2315 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2316 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2317 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2318 | String callingFeatureId) { |
| 2319 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2320 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2324 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2325 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2326 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2327 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2328 | } |
| 2329 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2330 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2331 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2332 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2333 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2334 | |
| 2335 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2336 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2337 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2338 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2339 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2340 | .setCallingPid(Binder.getCallingPid()) |
| 2341 | .setCallingUid(Binder.getCallingUid()) |
| 2342 | .setMethod("requestCellInfoUpdate") |
| 2343 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2344 | .build()); |
| 2345 | switch (locationResult) { |
| 2346 | case DENIED_HARD: |
| 2347 | throw new SecurityException("Not allowed to access cell info"); |
| 2348 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2349 | try { |
| 2350 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2351 | } catch (RemoteException re) { |
| 2352 | // Drop without consequences |
| 2353 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2354 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2355 | } |
| 2356 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2357 | |
| 2358 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2359 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2360 | |
| 2361 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2362 | } |
| 2363 | |
| 2364 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2365 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2366 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2367 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2368 | |
| 2369 | final long identity = Binder.clearCallingIdentity(); |
| 2370 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2371 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2372 | } finally { |
| 2373 | Binder.restoreCallingIdentity(identity); |
| 2374 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2375 | } |
| 2376 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2377 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2378 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2379 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2380 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2381 | return null; |
| 2382 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2383 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2384 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2385 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2386 | return null; |
| 2387 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2388 | |
| 2389 | final long identity = Binder.clearCallingIdentity(); |
| 2390 | try { |
| 2391 | return phone.getImei(); |
| 2392 | } finally { |
| 2393 | Binder.restoreCallingIdentity(identity); |
| 2394 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2398 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2399 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2400 | String tac = null; |
| 2401 | if (phone != null) { |
| 2402 | String imei = phone.getImei(); |
| 2403 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2404 | } |
| 2405 | return tac; |
| 2406 | } |
| 2407 | |
| 2408 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2409 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2410 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2411 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2412 | return null; |
| 2413 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2414 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2415 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2416 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2417 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2418 | return null; |
| 2419 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2420 | |
| 2421 | final long identity = Binder.clearCallingIdentity(); |
| 2422 | try { |
| 2423 | return phone.getMeid(); |
| 2424 | } finally { |
| 2425 | Binder.restoreCallingIdentity(identity); |
| 2426 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2430 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2431 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2432 | String manufacturerCode = null; |
| 2433 | if (phone != null) { |
| 2434 | String meid = phone.getMeid(); |
| 2435 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2436 | } |
| 2437 | return manufacturerCode; |
| 2438 | } |
| 2439 | |
| 2440 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2441 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2442 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2443 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2444 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2445 | return null; |
| 2446 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2447 | int subId = phone.getSubId(); |
| 2448 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2449 | mApp, subId, callingPackage, callingFeatureId, |
| 2450 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2451 | return null; |
| 2452 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2453 | |
| 2454 | final long identity = Binder.clearCallingIdentity(); |
| 2455 | try { |
| 2456 | return phone.getDeviceSvn(); |
| 2457 | } finally { |
| 2458 | Binder.restoreCallingIdentity(identity); |
| 2459 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2462 | @Override |
| 2463 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2464 | final long identity = Binder.clearCallingIdentity(); |
| 2465 | try { |
| 2466 | final Phone phone = getPhone(subId); |
| 2467 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2468 | } finally { |
| 2469 | Binder.restoreCallingIdentity(identity); |
| 2470 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2471 | } |
| 2472 | |
| 2473 | @Override |
| 2474 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2475 | final long identity = Binder.clearCallingIdentity(); |
| 2476 | try { |
| 2477 | final Phone phone = getPhone(subId); |
| 2478 | return phone == null ? null : phone.getCarrierName(); |
| 2479 | } finally { |
| 2480 | Binder.restoreCallingIdentity(identity); |
| 2481 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2482 | } |
| 2483 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2484 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2485 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2486 | final long identity = Binder.clearCallingIdentity(); |
| 2487 | try { |
| 2488 | final Phone phone = getPhone(subId); |
| 2489 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2490 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2491 | } finally { |
| 2492 | Binder.restoreCallingIdentity(identity); |
| 2493 | } |
| 2494 | } |
| 2495 | |
| 2496 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2497 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2498 | final long identity = Binder.clearCallingIdentity(); |
| 2499 | try { |
| 2500 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2501 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2502 | } finally { |
| 2503 | Binder.restoreCallingIdentity(identity); |
| 2504 | } |
| 2505 | } |
| 2506 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2507 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2508 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2509 | if (!isSubscriptionMccMnc) { |
| 2510 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2511 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2512 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2513 | if (phone == null) { |
| 2514 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2515 | } |
| 2516 | final long identity = Binder.clearCallingIdentity(); |
| 2517 | try { |
| 2518 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2519 | } finally { |
| 2520 | Binder.restoreCallingIdentity(identity); |
| 2521 | } |
| 2522 | } |
| 2523 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2524 | // |
| 2525 | // Internal helper methods. |
| 2526 | // |
| 2527 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2528 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2529 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2530 | * |
| 2531 | * @throws SecurityException if the caller does not have the required permission |
| 2532 | */ |
| 2533 | private void enforceModifyPermission() { |
| 2534 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2535 | } |
| 2536 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2537 | /** |
| 2538 | * Make sure the caller is system. |
| 2539 | * |
| 2540 | * @throws SecurityException if the caller is not system. |
| 2541 | */ |
| 2542 | private void enforceSystemCaller() { |
| 2543 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2544 | throw new SecurityException("Caller must be system"); |
| 2545 | } |
| 2546 | } |
| 2547 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2548 | private void enforceActiveEmergencySessionPermission() { |
| 2549 | mApp.enforceCallingOrSelfPermission( |
| 2550 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2551 | } |
| 2552 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2553 | /** |
| 2554 | * Make sure the caller has the CALL_PHONE permission. |
| 2555 | * |
| 2556 | * @throws SecurityException if the caller does not have the required permission |
| 2557 | */ |
| 2558 | private void enforceCallPermission() { |
| 2559 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2560 | } |
| 2561 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2562 | private void enforceSettingsPermission() { |
| 2563 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2564 | } |
| 2565 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2566 | private String createTelUrl(String number) { |
| 2567 | if (TextUtils.isEmpty(number)) { |
| 2568 | return null; |
| 2569 | } |
| 2570 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2571 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2572 | } |
| 2573 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2574 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2575 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2576 | } |
| 2577 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2578 | private static void logv(String msg) { |
| 2579 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2580 | } |
| 2581 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2582 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2583 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2584 | } |
| 2585 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2586 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2587 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2588 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2589 | } |
| 2590 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2591 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2592 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2593 | final long identity = Binder.clearCallingIdentity(); |
| 2594 | try { |
| 2595 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2596 | if (phone == null) { |
| 2597 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2598 | } else { |
| 2599 | return phone.getPhoneType(); |
| 2600 | } |
| 2601 | } finally { |
| 2602 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2603 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | /** |
| 2607 | * Returns the CDMA ERI icon index to display |
| 2608 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2609 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2610 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2611 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2612 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2613 | } |
| 2614 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2615 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2616 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2617 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2618 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2619 | mApp, subId, callingPackage, callingFeatureId, |
| 2620 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2621 | return -1; |
| 2622 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2623 | |
| 2624 | final long identity = Binder.clearCallingIdentity(); |
| 2625 | try { |
| 2626 | final Phone phone = getPhone(subId); |
| 2627 | if (phone != null) { |
| 2628 | return phone.getCdmaEriIconIndex(); |
| 2629 | } else { |
| 2630 | return -1; |
| 2631 | } |
| 2632 | } finally { |
| 2633 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2634 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | /** |
| 2638 | * Returns the CDMA ERI icon mode, |
| 2639 | * 0 - ON |
| 2640 | * 1 - FLASHING |
| 2641 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2642 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2643 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2644 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2645 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2646 | } |
| 2647 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2648 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2649 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2650 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2651 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2652 | mApp, subId, callingPackage, callingFeatureId, |
| 2653 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2654 | return -1; |
| 2655 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2656 | |
| 2657 | final long identity = Binder.clearCallingIdentity(); |
| 2658 | try { |
| 2659 | final Phone phone = getPhone(subId); |
| 2660 | if (phone != null) { |
| 2661 | return phone.getCdmaEriIconMode(); |
| 2662 | } else { |
| 2663 | return -1; |
| 2664 | } |
| 2665 | } finally { |
| 2666 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2667 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2668 | } |
| 2669 | |
| 2670 | /** |
| 2671 | * Returns the CDMA ERI text, |
| 2672 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2673 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2674 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2675 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2676 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2677 | } |
| 2678 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2679 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2680 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2681 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2682 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2683 | mApp, subId, callingPackage, callingFeatureId, |
| 2684 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2685 | return null; |
| 2686 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2687 | |
| 2688 | final long identity = Binder.clearCallingIdentity(); |
| 2689 | try { |
| 2690 | final Phone phone = getPhone(subId); |
| 2691 | if (phone != null) { |
| 2692 | return phone.getCdmaEriText(); |
| 2693 | } else { |
| 2694 | return null; |
| 2695 | } |
| 2696 | } finally { |
| 2697 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2698 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2699 | } |
| 2700 | |
| 2701 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2702 | * Returns the CDMA MDN. |
| 2703 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2704 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2705 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2706 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2707 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2708 | |
| 2709 | final long identity = Binder.clearCallingIdentity(); |
| 2710 | try { |
| 2711 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2712 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2713 | return phone.getLine1Number(); |
| 2714 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2715 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2716 | return null; |
| 2717 | } |
| 2718 | } finally { |
| 2719 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2720 | } |
| 2721 | } |
| 2722 | |
| 2723 | /** |
| 2724 | * Returns the CDMA MIN. |
| 2725 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2726 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2727 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2728 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2729 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2730 | |
| 2731 | final long identity = Binder.clearCallingIdentity(); |
| 2732 | try { |
| 2733 | final Phone phone = getPhone(subId); |
| 2734 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2735 | return phone.getCdmaMin(); |
| 2736 | } else { |
| 2737 | return null; |
| 2738 | } |
| 2739 | } finally { |
| 2740 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2741 | } |
| 2742 | } |
| 2743 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2744 | @Override |
| 2745 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2746 | INumberVerificationCallback callback, String callingPackage) { |
| 2747 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2748 | != PERMISSION_GRANTED) { |
| 2749 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2750 | } |
| 2751 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2752 | |
| 2753 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2754 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2755 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2756 | } |
| 2757 | |
| 2758 | if (range == null) { |
| 2759 | throw new NullPointerException("Range must be non-null"); |
| 2760 | } |
| 2761 | |
| 2762 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2763 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2764 | |
| 2765 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2766 | } |
| 2767 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2768 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2769 | * Returns true if CDMA provisioning needs to run. |
| 2770 | */ |
| 2771 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2772 | final long identity = Binder.clearCallingIdentity(); |
| 2773 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2774 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2775 | } finally { |
| 2776 | Binder.restoreCallingIdentity(identity); |
| 2777 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2778 | } |
| 2779 | |
| 2780 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2781 | * Sets the voice mail number of a given subId. |
| 2782 | */ |
| 2783 | @Override |
| 2784 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2785 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2786 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2787 | |
| 2788 | final long identity = Binder.clearCallingIdentity(); |
| 2789 | try { |
| 2790 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2791 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2792 | return success; |
| 2793 | } finally { |
| 2794 | Binder.restoreCallingIdentity(identity); |
| 2795 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2796 | } |
| 2797 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2798 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2799 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2800 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2801 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2802 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2803 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2804 | throw new SecurityException("caller must be system dialer"); |
| 2805 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2806 | |
| 2807 | final long identity = Binder.clearCallingIdentity(); |
| 2808 | try { |
| 2809 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2810 | if (phoneAccountHandle == null) { |
| 2811 | return null; |
| 2812 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2813 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2814 | } finally { |
| 2815 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2816 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2817 | } |
| 2818 | |
| 2819 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2820 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2821 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2822 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2823 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2824 | mApp, subId, callingPackage, callingFeatureId, |
| 2825 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2826 | return null; |
| 2827 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2828 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2829 | final long identity = Binder.clearCallingIdentity(); |
| 2830 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2831 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2832 | } finally { |
| 2833 | Binder.restoreCallingIdentity(identity); |
| 2834 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2838 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2839 | VisualVoicemailSmsFilterSettings settings) { |
| 2840 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2841 | |
| 2842 | final long identity = Binder.clearCallingIdentity(); |
| 2843 | try { |
| 2844 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2845 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2846 | } finally { |
| 2847 | Binder.restoreCallingIdentity(identity); |
| 2848 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2852 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2853 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2854 | |
| 2855 | final long identity = Binder.clearCallingIdentity(); |
| 2856 | try { |
| 2857 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2858 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2859 | } finally { |
| 2860 | Binder.restoreCallingIdentity(identity); |
| 2861 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2862 | } |
| 2863 | |
| 2864 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2865 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2866 | String callingPackage, int subId) { |
| 2867 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2868 | |
| 2869 | final long identity = Binder.clearCallingIdentity(); |
| 2870 | try { |
| 2871 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2872 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2873 | } finally { |
| 2874 | Binder.restoreCallingIdentity(identity); |
| 2875 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2876 | } |
| 2877 | |
| 2878 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2879 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2880 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2881 | |
| 2882 | final long identity = Binder.clearCallingIdentity(); |
| 2883 | try { |
| 2884 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2885 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2886 | } finally { |
| 2887 | Binder.restoreCallingIdentity(identity); |
| 2888 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2889 | } |
| 2890 | |
| 2891 | @Override |
| 2892 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2893 | String number, int port, String text, PendingIntent sentIntent) { |
| 2894 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2895 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2896 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2897 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2898 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2899 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2900 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2901 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2902 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2903 | * Sets the voice activation state of a given subId. |
| 2904 | */ |
| 2905 | @Override |
| 2906 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2907 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2908 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2909 | |
| 2910 | final long identity = Binder.clearCallingIdentity(); |
| 2911 | try { |
| 2912 | final Phone phone = getPhone(subId); |
| 2913 | if (phone != null) { |
| 2914 | phone.setVoiceActivationState(activationState); |
| 2915 | } else { |
| 2916 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2917 | } |
| 2918 | } finally { |
| 2919 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2920 | } |
| 2921 | } |
| 2922 | |
| 2923 | /** |
| 2924 | * Sets the data activation state of a given subId. |
| 2925 | */ |
| 2926 | @Override |
| 2927 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2928 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2929 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2930 | |
| 2931 | final long identity = Binder.clearCallingIdentity(); |
| 2932 | try { |
| 2933 | final Phone phone = getPhone(subId); |
| 2934 | if (phone != null) { |
| 2935 | phone.setDataActivationState(activationState); |
| 2936 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 2937 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2938 | } |
| 2939 | } finally { |
| 2940 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2941 | } |
| 2942 | } |
| 2943 | |
| 2944 | /** |
| 2945 | * Returns the voice activation state of a given subId. |
| 2946 | */ |
| 2947 | @Override |
| 2948 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2949 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2950 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2951 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2952 | final long identity = Binder.clearCallingIdentity(); |
| 2953 | try { |
| 2954 | if (phone != null) { |
| 2955 | return phone.getVoiceActivationState(); |
| 2956 | } else { |
| 2957 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2958 | } |
| 2959 | } finally { |
| 2960 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2961 | } |
| 2962 | } |
| 2963 | |
| 2964 | /** |
| 2965 | * Returns the data activation state of a given subId. |
| 2966 | */ |
| 2967 | @Override |
| 2968 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2969 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2970 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2971 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2972 | final long identity = Binder.clearCallingIdentity(); |
| 2973 | try { |
| 2974 | if (phone != null) { |
| 2975 | return phone.getDataActivationState(); |
| 2976 | } else { |
| 2977 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2978 | } |
| 2979 | } finally { |
| 2980 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2981 | } |
| 2982 | } |
| 2983 | |
| 2984 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2985 | * Returns the unread count of voicemails for a subId |
| 2986 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2987 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2988 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 2989 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2990 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2991 | mApp, subId, callingPackage, callingFeatureId, |
| 2992 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2993 | return 0; |
| 2994 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2995 | final long identity = Binder.clearCallingIdentity(); |
| 2996 | try { |
| 2997 | final Phone phone = getPhone(subId); |
| 2998 | if (phone != null) { |
| 2999 | return phone.getVoiceMessageCount(); |
| 3000 | } else { |
| 3001 | return 0; |
| 3002 | } |
| 3003 | } finally { |
| 3004 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3005 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3006 | } |
| 3007 | |
| 3008 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3009 | * returns true, if the device is in a state where both voice and data |
| 3010 | * are supported simultaneously. This can change based on location or network condition. |
| 3011 | */ |
| 3012 | @Override |
| 3013 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3014 | final long identity = Binder.clearCallingIdentity(); |
| 3015 | try { |
| 3016 | final Phone phone = getPhone(subId); |
| 3017 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3018 | } finally { |
| 3019 | Binder.restoreCallingIdentity(identity); |
| 3020 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3021 | } |
| 3022 | |
| 3023 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3024 | * Send the dialer code if called from the current default dialer or the caller has |
| 3025 | * carrier privilege. |
| 3026 | * @param inputCode The dialer code to send |
| 3027 | */ |
| 3028 | @Override |
| 3029 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3030 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3031 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3032 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3033 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3034 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3035 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3036 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3037 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3038 | |
| 3039 | final long identity = Binder.clearCallingIdentity(); |
| 3040 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3041 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3042 | } finally { |
| 3043 | Binder.restoreCallingIdentity(identity); |
| 3044 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3045 | } |
| 3046 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3047 | @Override |
| 3048 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3049 | TelephonyPermissions |
| 3050 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3051 | mApp, subId, "getNetworkSelectionMode"); |
| 3052 | final long identity = Binder.clearCallingIdentity(); |
| 3053 | try { |
| 3054 | if (!isActiveSubscription(subId)) { |
| 3055 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3056 | } |
| 3057 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3058 | } finally { |
| 3059 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3060 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3061 | } |
| 3062 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3063 | @Override |
Sarah Chin | 0605abf | 2019-12-06 10:24:18 -0800 | [diff] [blame] | 3064 | public PhoneCapability getPhoneCapability(int subId, String callingPackage, |
| 3065 | String callingFeatureId) { |
| 3066 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3067 | mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) { |
| 3068 | return null; |
| 3069 | } |
| 3070 | final long identity = Binder.clearCallingIdentity(); |
| 3071 | try { |
| 3072 | return mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 3073 | } finally { |
| 3074 | Binder.restoreCallingIdentity(identity); |
| 3075 | } |
| 3076 | } |
| 3077 | |
| 3078 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3079 | public boolean isInEmergencySmsMode() { |
| 3080 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3081 | final long identity = Binder.clearCallingIdentity(); |
| 3082 | try { |
| 3083 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3084 | if (phone.isInEmergencySmsMode()) { |
| 3085 | return true; |
| 3086 | } |
| 3087 | } |
| 3088 | } finally { |
| 3089 | Binder.restoreCallingIdentity(identity); |
| 3090 | } |
| 3091 | return false; |
| 3092 | } |
| 3093 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3094 | /** |
| 3095 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3096 | * @param subId The subscription to use to check the configuration. |
| 3097 | * @param c The callback that will be used to send the result. |
| 3098 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3099 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3100 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3101 | throws RemoteException { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3102 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3103 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3104 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3105 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3106 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3107 | "IMS not available on device."); |
| 3108 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3109 | final long token = Binder.clearCallingIdentity(); |
| 3110 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3111 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3112 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3113 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3114 | } catch (ImsException e) { |
| 3115 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3116 | } finally { |
| 3117 | Binder.restoreCallingIdentity(token); |
| 3118 | } |
| 3119 | } |
| 3120 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3121 | /** |
| 3122 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3123 | * @param subId The subscription to use to check the configuration. |
| 3124 | * @param c The callback that will be used to send the result. |
| 3125 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3126 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3127 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3128 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3129 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3130 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3131 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3132 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3133 | final long token = Binder.clearCallingIdentity(); |
| 3134 | try { |
| 3135 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3136 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3137 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3138 | } catch (ImsException e) { |
| 3139 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3140 | + "is inactive, ignoring unregister."); |
| 3141 | // If the subscription is no longer active, just return, since the callback |
| 3142 | // will already have been removed internally. |
| 3143 | } finally { |
| 3144 | Binder.restoreCallingIdentity(token); |
| 3145 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3146 | } |
| 3147 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3148 | /** |
| 3149 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3150 | */ |
| 3151 | @Override |
| 3152 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3153 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3154 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3155 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3156 | "IMS not available on device."); |
| 3157 | } |
| 3158 | final long token = Binder.clearCallingIdentity(); |
| 3159 | try { |
| 3160 | Phone phone = getPhone(subId); |
| 3161 | if (phone == null) { |
| 3162 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3163 | + subId + "'"); |
| 3164 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3165 | } |
| 3166 | phone.getImsRegistrationState(regState -> { |
| 3167 | try { |
| 3168 | consumer.accept((regState == null) |
| 3169 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3170 | } catch (RemoteException e) { |
| 3171 | // Ignore if the remote process is no longer available to call back. |
| 3172 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3173 | } |
| 3174 | }); |
| 3175 | } finally { |
| 3176 | Binder.restoreCallingIdentity(token); |
| 3177 | } |
| 3178 | } |
| 3179 | |
| 3180 | /** |
| 3181 | * Get the transport type for the IMS service registration state. |
| 3182 | */ |
| 3183 | @Override |
| 3184 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3185 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3186 | enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType"); |
| 3187 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3188 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3189 | "IMS not available on device."); |
| 3190 | } |
| 3191 | final long token = Binder.clearCallingIdentity(); |
| 3192 | try { |
| 3193 | Phone phone = getPhone(subId); |
| 3194 | if (phone == null) { |
| 3195 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3196 | + subId + "'"); |
| 3197 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3198 | } |
| 3199 | phone.getImsRegistrationTech(regTech -> { |
| 3200 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3201 | int regTechConverted = (regTech == null) |
| 3202 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3203 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3204 | regTechConverted); |
| 3205 | try { |
| 3206 | consumer.accept(regTechConverted); |
| 3207 | } catch (RemoteException e) { |
| 3208 | // Ignore if the remote process is no longer available to call back. |
| 3209 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3210 | } |
| 3211 | }); |
| 3212 | } finally { |
| 3213 | Binder.restoreCallingIdentity(token); |
| 3214 | } |
| 3215 | } |
| 3216 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3217 | /** |
| 3218 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3219 | * @param subId The subscription to use to check the configuration. |
| 3220 | * @param c The callback that will be used to send the result. |
| 3221 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3222 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3223 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3224 | throws RemoteException { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3225 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3226 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3227 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3228 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3229 | "IMS not available on device."); |
| 3230 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3231 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3232 | final long token = Binder.clearCallingIdentity(); |
| 3233 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3234 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3235 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3236 | } catch (ImsException e) { |
| 3237 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3238 | } finally { |
| 3239 | Binder.restoreCallingIdentity(token); |
| 3240 | } |
| 3241 | } |
| 3242 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3243 | /** |
| 3244 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3245 | * @param subId The subscription to use to check the configuration. |
| 3246 | * @param c The callback that will be used to send the result. |
| 3247 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3248 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3249 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3250 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3251 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3252 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3253 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3254 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3255 | |
| 3256 | final long token = Binder.clearCallingIdentity(); |
| 3257 | try { |
| 3258 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3259 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3260 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3261 | } catch (ImsException e) { |
| 3262 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3263 | + "is inactive, ignoring unregister."); |
| 3264 | // If the subscription is no longer active, just return, since the callback |
| 3265 | // will already have been removed internally. |
| 3266 | } finally { |
| 3267 | Binder.restoreCallingIdentity(token); |
| 3268 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3269 | } |
| 3270 | |
| 3271 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3272 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3273 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3274 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3275 | final long token = Binder.clearCallingIdentity(); |
| 3276 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3277 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3278 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3279 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3280 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3281 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3282 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3283 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3284 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3285 | } finally { |
| 3286 | Binder.restoreCallingIdentity(token); |
| 3287 | } |
| 3288 | } |
| 3289 | |
| 3290 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3291 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3292 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3293 | final long token = Binder.clearCallingIdentity(); |
| 3294 | try { |
| 3295 | Phone phone = getPhone(subId); |
| 3296 | if (phone == null) return false; |
| 3297 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3298 | } finally { |
| 3299 | Binder.restoreCallingIdentity(token); |
| 3300 | } |
| 3301 | } |
| 3302 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3303 | /** |
| 3304 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3305 | * subscription. |
| 3306 | * @param subId The subscription to use to check the configuration. |
| 3307 | * @param callback The callback that will be used to send the result. |
| 3308 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3309 | * @param transportType The transport type of the MmTelFeature capability. |
| 3310 | */ |
| 3311 | @Override |
| 3312 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3313 | int transportType) { |
| 3314 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3315 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3316 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3317 | "IMS not available on device."); |
| 3318 | } |
| 3319 | final long token = Binder.clearCallingIdentity(); |
| 3320 | try { |
| 3321 | int slotId = getSlotIndex(subId); |
| 3322 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3323 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3324 | + subId + "'"); |
| 3325 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3326 | } |
| 3327 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3328 | transportType, aBoolean -> { |
| 3329 | try { |
| 3330 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3331 | } catch (RemoteException e) { |
| 3332 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3333 | + "running. Ignore"); |
| 3334 | } |
| 3335 | }); |
| 3336 | } finally { |
| 3337 | Binder.restoreCallingIdentity(token); |
| 3338 | } |
| 3339 | } |
| 3340 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3341 | /** |
| 3342 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3343 | * @param subId The subscription to use to check the configuration. |
| 3344 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3345 | @Override |
| 3346 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3347 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
| 3348 | enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled"); |
| 3349 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3350 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3351 | final long token = Binder.clearCallingIdentity(); |
| 3352 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3353 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3354 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3355 | } catch (ImsException e) { |
| 3356 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3357 | } finally { |
| 3358 | Binder.restoreCallingIdentity(token); |
| 3359 | } |
| 3360 | } |
| 3361 | |
| 3362 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3363 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3364 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3365 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3366 | final long identity = Binder.clearCallingIdentity(); |
| 3367 | try { |
| 3368 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3369 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3370 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3371 | } catch (ImsException e) { |
| 3372 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3373 | } finally { |
| 3374 | Binder.restoreCallingIdentity(identity); |
| 3375 | } |
| 3376 | } |
| 3377 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3378 | /** |
| 3379 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3380 | * @param subId The subscription to use to check the configuration. |
| 3381 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3382 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3383 | public boolean isVtSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3384 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3385 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3386 | final long identity = Binder.clearCallingIdentity(); |
| 3387 | try { |
| 3388 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3389 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3390 | } catch (ImsException e) { |
| 3391 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3392 | } finally { |
| 3393 | Binder.restoreCallingIdentity(identity); |
| 3394 | } |
| 3395 | } |
| 3396 | |
| 3397 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3398 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3399 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3400 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3401 | final long identity = Binder.clearCallingIdentity(); |
| 3402 | try { |
| 3403 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3404 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3405 | } catch (ImsException e) { |
| 3406 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3407 | } finally { |
| 3408 | Binder.restoreCallingIdentity(identity); |
| 3409 | } |
| 3410 | } |
| 3411 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3412 | /** |
| 3413 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3414 | * @param subId The subscription to use to check the configuration. |
| 3415 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3416 | @Override |
| 3417 | public boolean isVoWiFiSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3418 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3419 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3420 | final long identity = Binder.clearCallingIdentity(); |
| 3421 | try { |
| 3422 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3423 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3424 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3425 | } catch (ImsException e) { |
| 3426 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3427 | } finally { |
| 3428 | Binder.restoreCallingIdentity(identity); |
| 3429 | } |
| 3430 | } |
| 3431 | |
| 3432 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3433 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3434 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3435 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3436 | final long identity = Binder.clearCallingIdentity(); |
| 3437 | try { |
| 3438 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3439 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3440 | } catch (ImsException e) { |
| 3441 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3442 | } finally { |
| 3443 | Binder.restoreCallingIdentity(identity); |
| 3444 | } |
| 3445 | } |
| 3446 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3447 | /** |
| 3448 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3449 | * @param subId The subscription to use to check the configuration. |
| 3450 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3451 | @Override |
| 3452 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3453 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3454 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3455 | final long identity = Binder.clearCallingIdentity(); |
| 3456 | try { |
| 3457 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3458 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3459 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3460 | } catch (ImsException e) { |
| 3461 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3462 | } finally { |
| 3463 | Binder.restoreCallingIdentity(identity); |
| 3464 | } |
| 3465 | } |
| 3466 | |
| 3467 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3468 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3469 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3470 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3471 | final long identity = Binder.clearCallingIdentity(); |
| 3472 | try { |
| 3473 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3474 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3475 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3476 | } catch (ImsException e) { |
| 3477 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3478 | } finally { |
| 3479 | Binder.restoreCallingIdentity(identity); |
| 3480 | } |
| 3481 | } |
| 3482 | |
| 3483 | @Override |
| 3484 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3485 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3486 | "setVoWiFiNonPersistent"); |
| 3487 | final long identity = Binder.clearCallingIdentity(); |
| 3488 | try { |
| 3489 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3490 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3491 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3492 | } catch (ImsException e) { |
| 3493 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3494 | } finally { |
| 3495 | Binder.restoreCallingIdentity(identity); |
| 3496 | } |
| 3497 | } |
| 3498 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3499 | /** |
| 3500 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3501 | * @param subId The subscription to use to check the configuration. |
| 3502 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3503 | @Override |
| 3504 | public int getVoWiFiModeSetting(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3505 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3506 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3507 | final long identity = Binder.clearCallingIdentity(); |
| 3508 | try { |
| 3509 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3510 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3511 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3512 | } catch (ImsException e) { |
| 3513 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3514 | } finally { |
| 3515 | Binder.restoreCallingIdentity(identity); |
| 3516 | } |
| 3517 | } |
| 3518 | |
| 3519 | @Override |
| 3520 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3521 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3522 | "setVoWiFiModeSetting"); |
| 3523 | final long identity = Binder.clearCallingIdentity(); |
| 3524 | try { |
| 3525 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3526 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3527 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3528 | } catch (ImsException e) { |
| 3529 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3530 | } finally { |
| 3531 | Binder.restoreCallingIdentity(identity); |
| 3532 | } |
| 3533 | } |
| 3534 | |
| 3535 | @Override |
| 3536 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3537 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3538 | final long identity = Binder.clearCallingIdentity(); |
| 3539 | try { |
| 3540 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3541 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3542 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3543 | } catch (ImsException e) { |
| 3544 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3545 | } finally { |
| 3546 | Binder.restoreCallingIdentity(identity); |
| 3547 | } |
| 3548 | } |
| 3549 | |
| 3550 | @Override |
| 3551 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3552 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3553 | "setVoWiFiRoamingModeSetting"); |
| 3554 | final long identity = Binder.clearCallingIdentity(); |
| 3555 | try { |
| 3556 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3557 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3558 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3559 | } catch (ImsException e) { |
| 3560 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3561 | } finally { |
| 3562 | Binder.restoreCallingIdentity(identity); |
| 3563 | } |
| 3564 | } |
| 3565 | |
| 3566 | @Override |
| 3567 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3568 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3569 | "setRttCapabilityEnabled"); |
| 3570 | final long identity = Binder.clearCallingIdentity(); |
| 3571 | try { |
| 3572 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3573 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3574 | } catch (ImsException e) { |
| 3575 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3576 | } finally { |
| 3577 | Binder.restoreCallingIdentity(identity); |
| 3578 | } |
| 3579 | } |
| 3580 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3581 | /** |
| 3582 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3583 | * @param subId The subscription to use to check the configuration. |
| 3584 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3585 | @Override |
| 3586 | public boolean isTtyOverVolteEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3587 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3588 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3589 | final long identity = Binder.clearCallingIdentity(); |
| 3590 | try { |
| 3591 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3592 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3593 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3594 | } catch (ImsException e) { |
| 3595 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3596 | } finally { |
| 3597 | Binder.restoreCallingIdentity(identity); |
| 3598 | } |
| 3599 | } |
| 3600 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3601 | @Override |
| 3602 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3603 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3604 | final long identity = Binder.clearCallingIdentity(); |
| 3605 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3606 | if (!isImsAvailableOnDevice()) { |
| 3607 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3608 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3609 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3610 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3611 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3612 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3613 | } catch (ImsException e) { |
| 3614 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3615 | } finally { |
| 3616 | Binder.restoreCallingIdentity(identity); |
| 3617 | } |
| 3618 | } |
| 3619 | |
| 3620 | @Override |
| 3621 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3622 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3623 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3624 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3625 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3626 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3627 | try { |
| 3628 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3629 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3630 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3631 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3632 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3633 | + "is inactive, ignoring unregister."); |
| 3634 | // If the subscription is no longer active, just return, since the callback will already |
| 3635 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3636 | } finally { |
| 3637 | Binder.restoreCallingIdentity(identity); |
| 3638 | } |
| 3639 | } |
| 3640 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3641 | |
| 3642 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3643 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3644 | message); |
| 3645 | } |
| 3646 | |
| 3647 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3648 | boolean isMmtelCapability) { |
| 3649 | Phone phone = getPhone(subId); |
| 3650 | if (phone == null) { |
| 3651 | loge("phone instance null for subid " + subId); |
| 3652 | return false; |
| 3653 | } |
| 3654 | if (isMmtelCapability) { |
| 3655 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3656 | return false; |
| 3657 | } |
| 3658 | } else { |
| 3659 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3660 | return false; |
| 3661 | } |
| 3662 | } |
| 3663 | return true; |
| 3664 | } |
| 3665 | |
| 3666 | @Override |
| 3667 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3668 | boolean isProvisioned) { |
| 3669 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3670 | |
| 3671 | final long identity = Binder.clearCallingIdentity(); |
| 3672 | try { |
| 3673 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3674 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3675 | return; |
| 3676 | } |
| 3677 | |
| 3678 | // this capability requires provisioning, route to the correct API. |
| 3679 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3680 | switch (capability) { |
| 3681 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3682 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3683 | ims.setEabProvisioned(isProvisioned); |
| 3684 | break; |
| 3685 | default: { |
| 3686 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3687 | + "rcs capability '" + capability + "', which does not require " |
| 3688 | + "provisioning."); |
| 3689 | } |
| 3690 | } |
| 3691 | } finally { |
| 3692 | Binder.restoreCallingIdentity(identity); |
| 3693 | } |
| 3694 | |
| 3695 | } |
| 3696 | |
| 3697 | |
| 3698 | @Override |
| 3699 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3700 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3701 | final long identity = Binder.clearCallingIdentity(); |
| 3702 | try { |
| 3703 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3704 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3705 | return true; |
| 3706 | } |
| 3707 | |
| 3708 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3709 | switch (capability) { |
| 3710 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3711 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3712 | return ims.isEabProvisionedOnDevice(); |
| 3713 | |
| 3714 | default: { |
| 3715 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3716 | + "capability '" + capability + "', which does not require " |
| 3717 | + "provisioning."); |
| 3718 | } |
| 3719 | } |
| 3720 | |
| 3721 | } finally { |
| 3722 | Binder.restoreCallingIdentity(identity); |
| 3723 | } |
| 3724 | } |
| 3725 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3726 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3727 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3728 | boolean isProvisioned) { |
| 3729 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3730 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3731 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3732 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3733 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3734 | final long identity = Binder.clearCallingIdentity(); |
| 3735 | try { |
| 3736 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3737 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3738 | return; |
| 3739 | } |
| 3740 | |
| 3741 | // this capability requires provisioning, route to the correct API. |
| 3742 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3743 | switch (capability) { |
| 3744 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3745 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3746 | ims.setVolteProvisioned(isProvisioned); |
| 3747 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3748 | ims.setWfcProvisioned(isProvisioned); |
| 3749 | } |
| 3750 | break; |
| 3751 | } |
| 3752 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3753 | // There is currently no difference in VT provisioning type. |
| 3754 | ims.setVtProvisioned(isProvisioned); |
| 3755 | break; |
| 3756 | } |
| 3757 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3758 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3759 | // change the capability of the feature instead if needed. |
| 3760 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3761 | == isProvisioned) { |
| 3762 | // No change in provisioning. |
| 3763 | return; |
| 3764 | } |
| 3765 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3766 | try { |
| 3767 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3768 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3769 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3770 | + ", Exception" + e.getMessage()); |
| 3771 | } |
| 3772 | break; |
| 3773 | } |
| 3774 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3775 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3776 | + "MmTel capability '" + capability + "', which does not require " |
| 3777 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3778 | } |
| 3779 | } |
| 3780 | |
| 3781 | } finally { |
| 3782 | Binder.restoreCallingIdentity(identity); |
| 3783 | } |
| 3784 | } |
| 3785 | |
| 3786 | @Override |
| 3787 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3788 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3789 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3790 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3791 | } |
| 3792 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3793 | final long identity = Binder.clearCallingIdentity(); |
| 3794 | try { |
| 3795 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3796 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3797 | return true; |
| 3798 | } |
| 3799 | |
| 3800 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3801 | switch (capability) { |
| 3802 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3803 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3804 | return ims.isVolteProvisionedOnDevice(); |
| 3805 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3806 | return ims.isWfcProvisionedOnDevice(); |
| 3807 | } |
| 3808 | // This should never happen, since we are checking tech above to make sure it |
| 3809 | // is either LTE or IWLAN. |
| 3810 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3811 | + "capability."); |
| 3812 | } |
| 3813 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3814 | // There is currently no difference in VT provisioning type. |
| 3815 | return ims.isVtProvisionedOnDevice(); |
| 3816 | } |
| 3817 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3818 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3819 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3820 | } |
| 3821 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3822 | throw new IllegalArgumentException( |
| 3823 | "Tried to get provisioning for MmTel capability '" + capability |
| 3824 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3825 | } |
| 3826 | } |
| 3827 | |
| 3828 | } finally { |
| 3829 | Binder.restoreCallingIdentity(identity); |
| 3830 | } |
| 3831 | } |
| 3832 | |
| 3833 | @Override |
| 3834 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3835 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3836 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3837 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3838 | } |
| 3839 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3840 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3841 | return (provisionedBits & capability) > 0; |
| 3842 | } |
| 3843 | |
| 3844 | @Override |
| 3845 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3846 | boolean isProvisioned) { |
| 3847 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3848 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3849 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3850 | } |
| 3851 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3852 | "setProvisioningStatusForCapability"); |
| 3853 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3854 | // If the current provisioning status for capability already matches isProvisioned, |
| 3855 | // do nothing. |
| 3856 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3857 | return; |
| 3858 | } |
| 3859 | if (isProvisioned) { |
| 3860 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3861 | } else { |
| 3862 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3863 | } |
| 3864 | } |
| 3865 | |
| 3866 | /** |
| 3867 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3868 | * technology. The bitfield should mirror the bitfield defined by |
| 3869 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3870 | */ |
| 3871 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3872 | String key = getMmTelProvisioningKey(subId, tech); |
| 3873 | // Default is no capabilities are provisioned. |
| 3874 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3875 | } |
| 3876 | |
| 3877 | /** |
| 3878 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3879 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3880 | * technology specified. |
| 3881 | * |
| 3882 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3883 | */ |
| 3884 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3885 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3886 | String key = getMmTelProvisioningKey(subId, tech); |
| 3887 | editor.putInt(key, newField); |
| 3888 | editor.commit(); |
| 3889 | } |
| 3890 | |
| 3891 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3892 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3893 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3894 | } |
| 3895 | |
| 3896 | /** |
| 3897 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3898 | * carrier associated with the subscription id. |
| 3899 | */ |
| 3900 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3901 | int capability) { |
| 3902 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3903 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3904 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 3905 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3906 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3907 | false); |
| 3908 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3909 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3910 | |
| 3911 | // First check to make sure that the capability requires provisioning. |
| 3912 | switch (capability) { |
| 3913 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3914 | // intentional fallthrough |
| 3915 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3916 | if (requireVoiceVtProvisioning) { |
| 3917 | // Voice and Video requires provisioning |
| 3918 | return true; |
| 3919 | } |
| 3920 | break; |
| 3921 | } |
| 3922 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3923 | if (requireUtProvisioning) { |
| 3924 | // UT requires provisioning |
| 3925 | return true; |
| 3926 | } |
| 3927 | break; |
| 3928 | } |
| 3929 | } |
| 3930 | return false; |
| 3931 | } |
| 3932 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3933 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 3934 | int capability) { |
| 3935 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3936 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3937 | |
| 3938 | boolean requireRcsProvisioning = c.getBoolean( |
| 3939 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 3940 | |
| 3941 | // First check to make sure that the capability requires provisioning. |
| 3942 | switch (capability) { |
| 3943 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3944 | // intentional fallthrough |
| 3945 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 3946 | if (requireRcsProvisioning) { |
| 3947 | // OPTION or PRESENCE requires provisioning |
| 3948 | return true; |
| 3949 | } |
| 3950 | break; |
| 3951 | } |
| 3952 | } |
| 3953 | return false; |
| 3954 | } |
| 3955 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3956 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3957 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3958 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3959 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3960 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3961 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3962 | final long identity = Binder.clearCallingIdentity(); |
| 3963 | try { |
| 3964 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3965 | int slotId = getSlotIndex(subId); |
| 3966 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3967 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3968 | + subId + "' for key:" + key); |
| 3969 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3970 | } |
| 3971 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3972 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3973 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3974 | + subId + "' for key:" + key); |
| 3975 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3976 | } finally { |
| 3977 | Binder.restoreCallingIdentity(identity); |
| 3978 | } |
| 3979 | } |
| 3980 | |
| 3981 | @Override |
| 3982 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3983 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3984 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3985 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3986 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3987 | final long identity = Binder.clearCallingIdentity(); |
| 3988 | try { |
| 3989 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3990 | int slotId = getSlotIndex(subId); |
| 3991 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3992 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3993 | + subId + "' for key:" + key); |
| 3994 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3995 | } |
| 3996 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3997 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3998 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3999 | + subId + "' for key:" + key); |
| 4000 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4001 | } finally { |
| 4002 | Binder.restoreCallingIdentity(identity); |
| 4003 | } |
| 4004 | } |
| 4005 | |
| 4006 | @Override |
| 4007 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4008 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4009 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4010 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4011 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4012 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4013 | final long identity = Binder.clearCallingIdentity(); |
| 4014 | try { |
| 4015 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4016 | int slotId = getSlotIndex(subId); |
| 4017 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4018 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4019 | + subId + "' for key:" + key); |
| 4020 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4021 | } |
| 4022 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4023 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4024 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4025 | + "' for key:" + key); |
| 4026 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4027 | } finally { |
| 4028 | Binder.restoreCallingIdentity(identity); |
| 4029 | } |
| 4030 | } |
| 4031 | |
| 4032 | @Override |
| 4033 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4034 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4035 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4036 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4037 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4038 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4039 | final long identity = Binder.clearCallingIdentity(); |
| 4040 | try { |
| 4041 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4042 | int slotId = getSlotIndex(subId); |
| 4043 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4044 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4045 | + subId + "' for key:" + key); |
| 4046 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4047 | } |
| 4048 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4049 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4050 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4051 | + "' for key:" + key); |
| 4052 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4053 | } finally { |
| 4054 | Binder.restoreCallingIdentity(identity); |
| 4055 | } |
| 4056 | } |
| 4057 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4058 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4059 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4060 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4061 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4062 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4063 | } |
| 4064 | return slotId; |
| 4065 | } |
| 4066 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4067 | private int getSlotIndex(int subId) { |
| 4068 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4069 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4070 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4071 | } |
| 4072 | return slotId; |
| 4073 | } |
| 4074 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4075 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4076 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4077 | */ |
| 4078 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4079 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4080 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4081 | final int targetSdk = getTargetSdk(callingPackage); |
| 4082 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4083 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4084 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4085 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4086 | mApp, subId, callingPackage, callingFeatureId, |
| 4087 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4088 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4089 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4090 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4091 | final long identity = Binder.clearCallingIdentity(); |
| 4092 | try { |
| 4093 | final Phone phone = getPhone(subId); |
| 4094 | if (phone != null) { |
| 4095 | return phone.getServiceState().getDataNetworkType(); |
| 4096 | } else { |
| 4097 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4098 | } |
| 4099 | } finally { |
| 4100 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4101 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4102 | } |
| 4103 | |
| 4104 | /** |
| 4105 | * Returns the data network type |
| 4106 | */ |
| 4107 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4108 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4109 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4110 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4111 | } |
| 4112 | |
| 4113 | /** |
| 4114 | * Returns the data network type for a subId |
| 4115 | */ |
| 4116 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4117 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4118 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4119 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4120 | mApp, subId, callingPackage, callingFeatureId, |
| 4121 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4122 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4123 | } |
| 4124 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4125 | final long identity = Binder.clearCallingIdentity(); |
| 4126 | try { |
| 4127 | final Phone phone = getPhone(subId); |
| 4128 | if (phone != null) { |
| 4129 | return phone.getServiceState().getDataNetworkType(); |
| 4130 | } else { |
| 4131 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4132 | } |
| 4133 | } finally { |
| 4134 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4135 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4136 | } |
| 4137 | |
| 4138 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4139 | * Returns the Voice network type for a subId |
| 4140 | */ |
| 4141 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4142 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4143 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4144 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4145 | mApp, subId, callingPackage, callingFeatureId, |
| 4146 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4147 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4148 | } |
| 4149 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4150 | final long identity = Binder.clearCallingIdentity(); |
| 4151 | try { |
| 4152 | final Phone phone = getPhone(subId); |
| 4153 | if (phone != null) { |
| 4154 | return phone.getServiceState().getVoiceNetworkType(); |
| 4155 | } else { |
| 4156 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4157 | } |
| 4158 | } finally { |
| 4159 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4160 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4161 | } |
| 4162 | |
| 4163 | /** |
| 4164 | * @return true if a ICC card is present |
| 4165 | */ |
| 4166 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4167 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4168 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4169 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4170 | } |
| 4171 | |
| 4172 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4173 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4174 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4175 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4176 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4177 | final long identity = Binder.clearCallingIdentity(); |
| 4178 | try { |
| 4179 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4180 | if (phone != null) { |
| 4181 | return phone.getIccCard().hasIccCard(); |
| 4182 | } else { |
| 4183 | return false; |
| 4184 | } |
| 4185 | } finally { |
| 4186 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4187 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4188 | } |
| 4189 | |
| 4190 | /** |
| 4191 | * Return if the current radio is LTE on CDMA. This |
| 4192 | * is a tri-state return value as for a period of time |
| 4193 | * the mode may be unknown. |
| 4194 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4195 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4196 | * @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] | 4197 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4198 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4199 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4200 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4201 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4202 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4203 | } |
| 4204 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4205 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4206 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4207 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4208 | try { |
| 4209 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4210 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4211 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4212 | } |
| 4213 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4214 | final long identity = Binder.clearCallingIdentity(); |
| 4215 | try { |
| 4216 | final Phone phone = getPhone(subId); |
| 4217 | if (phone == null) { |
| 4218 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4219 | } else { |
| 4220 | return phone.getLteOnCdmaMode(); |
| 4221 | } |
| 4222 | } finally { |
| 4223 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4224 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4225 | } |
| 4226 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4227 | /** |
| 4228 | * {@hide} |
| 4229 | * Returns Default subId, 0 in the case of single standby. |
| 4230 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4231 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4232 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4233 | } |
| 4234 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4235 | private int getSlotForDefaultSubscription() { |
| 4236 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4237 | } |
| 4238 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4239 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4240 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4241 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4242 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4243 | private boolean isActiveSubscription(int subId) { |
| 4244 | return mSubscriptionController.isActiveSubId(subId); |
| 4245 | } |
| 4246 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4247 | /** |
| 4248 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4249 | */ |
| 4250 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4251 | final long identity = Binder.clearCallingIdentity(); |
| 4252 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4253 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4254 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4255 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4256 | } finally { |
| 4257 | Binder.restoreCallingIdentity(identity); |
| 4258 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4259 | } |
| 4260 | |
| 4261 | /** |
| 4262 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4263 | */ |
| 4264 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4265 | final long identity = Binder.clearCallingIdentity(); |
| 4266 | try { |
| 4267 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4268 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4269 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4270 | } finally { |
| 4271 | Binder.restoreCallingIdentity(identity); |
| 4272 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4273 | } |
| 4274 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4275 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4276 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4277 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4278 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4279 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4280 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4281 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4282 | if (phoneId == -1) { |
| 4283 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4284 | + " does not correspond to an active phone"); |
| 4285 | } |
| 4286 | return PhoneFactory.getPhone(phoneId); |
| 4287 | } |
| 4288 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4289 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4290 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4291 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4292 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4293 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4294 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4295 | if (DBG) { |
| 4296 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4297 | } |
| 4298 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4299 | p2); |
| 4300 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4301 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4302 | |
| 4303 | @Override |
| 4304 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4305 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4306 | enforceModifyPermission(); |
| 4307 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4308 | if (DBG) { |
| 4309 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4310 | } |
| 4311 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4312 | callingPackage, aid, p2); |
| 4313 | } |
| 4314 | |
| 4315 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4316 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4317 | final long identity = Binder.clearCallingIdentity(); |
| 4318 | try { |
| 4319 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4320 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4321 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4322 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4323 | if (bestComponent == null |
| 4324 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4325 | loge("The calling package is not allowed to access ISD-R."); |
| 4326 | throw new SecurityException( |
| 4327 | "The calling package is not allowed to access ISD-R."); |
| 4328 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4329 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4330 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4331 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4332 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4333 | null /* workSource */); |
| 4334 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4335 | return response; |
| 4336 | } finally { |
| 4337 | Binder.restoreCallingIdentity(identity); |
| 4338 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4339 | } |
| 4340 | |
| 4341 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4342 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4343 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4344 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4345 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4346 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4347 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4348 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4349 | @Override |
| 4350 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4351 | enforceModifyPermission(); |
| 4352 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4353 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4354 | channel); |
| 4355 | } |
| 4356 | |
| 4357 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4358 | final long identity = Binder.clearCallingIdentity(); |
| 4359 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4360 | if (channel < 0) { |
| 4361 | return false; |
| 4362 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4363 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4364 | null /* workSource */); |
| 4365 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4366 | return success; |
| 4367 | } finally { |
| 4368 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4369 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4370 | } |
| 4371 | |
| 4372 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4373 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4374 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4375 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4376 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4377 | if (DBG) { |
| 4378 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4379 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4380 | + p3 + " data=" + data); |
| 4381 | } |
| 4382 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4383 | command, p1, p2, p3, data); |
| 4384 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4385 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4386 | @Override |
| 4387 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4388 | int command, int p1, int p2, int p3, String data) { |
| 4389 | enforceModifyPermission(); |
| 4390 | if (DBG) { |
| 4391 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4392 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4393 | + p3 + " data=" + data); |
| 4394 | } |
| 4395 | return iccTransmitApduLogicalChannelWithPermission( |
| 4396 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4397 | data); |
| 4398 | } |
| 4399 | |
| 4400 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4401 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4402 | final long identity = Binder.clearCallingIdentity(); |
| 4403 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4404 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4405 | return ""; |
| 4406 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4407 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4408 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4409 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4410 | null /* workSource */); |
| 4411 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4412 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4413 | // Append the returned status code to the end of the response payload. |
| 4414 | String s = Integer.toHexString( |
| 4415 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4416 | if (response.payload != null) { |
| 4417 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4418 | } |
| 4419 | return s; |
| 4420 | } finally { |
| 4421 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4422 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4423 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4424 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4425 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4426 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4427 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4428 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4429 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4430 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4431 | if (DBG) { |
| 4432 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4433 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4434 | } |
| 4435 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4436 | cla, command, p1, p2, p3, data); |
| 4437 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4438 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4439 | @Override |
| 4440 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4441 | int command, int p1, int p2, int p3, String data) { |
| 4442 | enforceModifyPermission(); |
| 4443 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4444 | if (DBG) { |
| 4445 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4446 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4447 | + " data=" + data); |
| 4448 | } |
| 4449 | |
| 4450 | return iccTransmitApduBasicChannelWithPermission( |
| 4451 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4452 | p2, p3, data); |
| 4453 | } |
| 4454 | |
| 4455 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4456 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4457 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4458 | final long identity = Binder.clearCallingIdentity(); |
| 4459 | try { |
| 4460 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4461 | && TextUtils.equals(ISDR_AID, data)) { |
| 4462 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4463 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4464 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4465 | if (bestComponent == null |
| 4466 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4467 | loge("The calling package is not allowed to select ISD-R."); |
| 4468 | throw new SecurityException( |
| 4469 | "The calling package is not allowed to select ISD-R."); |
| 4470 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4471 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4472 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4473 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4474 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4475 | null /* workSource */); |
| 4476 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4477 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4478 | // Append the returned status code to the end of the response payload. |
| 4479 | String s = Integer.toHexString( |
| 4480 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4481 | if (response.payload != null) { |
| 4482 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4483 | } |
| 4484 | return s; |
| 4485 | } finally { |
| 4486 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4487 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4491 | 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] | 4492 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4493 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4494 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4495 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4496 | final long identity = Binder.clearCallingIdentity(); |
| 4497 | try { |
| 4498 | if (DBG) { |
| 4499 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4500 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4501 | } |
| 4502 | |
| 4503 | IccIoResult response = |
| 4504 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4505 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4506 | subId); |
| 4507 | |
| 4508 | if (DBG) { |
| 4509 | log("Exchange SIM_IO [R]" + response); |
| 4510 | } |
| 4511 | |
| 4512 | byte[] result = null; |
| 4513 | int length = 2; |
| 4514 | if (response.payload != null) { |
| 4515 | length = 2 + response.payload.length; |
| 4516 | result = new byte[length]; |
| 4517 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4518 | } else { |
| 4519 | result = new byte[length]; |
| 4520 | } |
| 4521 | |
| 4522 | result[length - 1] = (byte) response.sw2; |
| 4523 | result[length - 2] = (byte) response.sw1; |
| 4524 | return result; |
| 4525 | } finally { |
| 4526 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4527 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4528 | } |
| 4529 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4530 | /** |
| 4531 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4532 | * on a particular subscription |
| 4533 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4534 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4535 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4536 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4537 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4538 | return null; |
| 4539 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4540 | |
| 4541 | final long identity = Binder.clearCallingIdentity(); |
| 4542 | try { |
| 4543 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4544 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4545 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4546 | return null; |
| 4547 | } |
| 4548 | Object response = sendRequest( |
| 4549 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4550 | if (response instanceof String[]) { |
| 4551 | return (String[]) response; |
| 4552 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4553 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4554 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4555 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4556 | } finally { |
| 4557 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4558 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4559 | } |
| 4560 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4561 | /** |
| 4562 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4563 | * subscription. |
| 4564 | * |
| 4565 | * @param subId the id of the subscription. |
| 4566 | * @param appType the uicc app type, must be USIM or SIM. |
| 4567 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4568 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4569 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4570 | * @return number of fplmns that is successfully written to the SIM. |
| 4571 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4572 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4573 | String callingFeatureId) { |
| 4574 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4575 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4576 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4577 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4578 | } |
| 4579 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4580 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4581 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4582 | } |
| 4583 | if (fplmns == null) { |
| 4584 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4585 | } |
| 4586 | for (String fplmn : fplmns) { |
| 4587 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4588 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4589 | } |
| 4590 | } |
| 4591 | final long identity = Binder.clearCallingIdentity(); |
| 4592 | try { |
| 4593 | Object response = sendRequest( |
| 4594 | CMD_SET_FORBIDDEN_PLMNS, |
| 4595 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4596 | subId); |
| 4597 | return (int) response; |
| 4598 | } finally { |
| 4599 | Binder.restoreCallingIdentity(identity); |
| 4600 | } |
| 4601 | } |
| 4602 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4603 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4604 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4605 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4606 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -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 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4611 | if (response.payload == null) { |
| 4612 | return ""; |
| 4613 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4614 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4615 | // Append the returned status code to the end of the response payload. |
| 4616 | String s = Integer.toHexString( |
| 4617 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4618 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4619 | return s; |
| 4620 | } finally { |
| 4621 | Binder.restoreCallingIdentity(identity); |
| 4622 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4623 | } |
| 4624 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4625 | /** |
| 4626 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4627 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4628 | * |
| 4629 | * @param itemID the ID of the item to read |
| 4630 | * @return the NV item as a String, or null on error. |
| 4631 | */ |
| 4632 | @Override |
| 4633 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4634 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4635 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4636 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4637 | |
| 4638 | final long identity = Binder.clearCallingIdentity(); |
| 4639 | try { |
| 4640 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4641 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4642 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4643 | return value; |
| 4644 | } finally { |
| 4645 | Binder.restoreCallingIdentity(identity); |
| 4646 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | /** |
| 4650 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4651 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4652 | * |
| 4653 | * @param itemID the ID of the item to read |
| 4654 | * @param itemValue the value to write, as a String |
| 4655 | * @return true on success; false on any failure |
| 4656 | */ |
| 4657 | @Override |
| 4658 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4659 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4660 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4661 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4662 | |
| 4663 | final long identity = Binder.clearCallingIdentity(); |
| 4664 | try { |
| 4665 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4666 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4667 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4668 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4669 | return success; |
| 4670 | } finally { |
| 4671 | Binder.restoreCallingIdentity(identity); |
| 4672 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4673 | } |
| 4674 | |
| 4675 | /** |
| 4676 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4677 | * Used for device configuration by some CDMA operators. |
| 4678 | * |
| 4679 | * @param preferredRoamingList byte array containing the new PRL |
| 4680 | * @return true on success; false on any failure |
| 4681 | */ |
| 4682 | @Override |
| 4683 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4684 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4685 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4686 | |
| 4687 | final long identity = Binder.clearCallingIdentity(); |
| 4688 | try { |
| 4689 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4690 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4691 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4692 | return success; |
| 4693 | } finally { |
| 4694 | Binder.restoreCallingIdentity(identity); |
| 4695 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4696 | } |
| 4697 | |
| 4698 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4699 | * 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] | 4700 | * Used for device configuration by some CDMA operators. |
| 4701 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4702 | * @param slotIndex - device slot. |
| 4703 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4704 | * @return true on success; false on any failure |
| 4705 | */ |
| 4706 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4707 | public boolean resetModemConfig(int slotIndex) { |
| 4708 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4709 | if (phone != null) { |
| 4710 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4711 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4712 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4713 | final long identity = Binder.clearCallingIdentity(); |
| 4714 | try { |
| 4715 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4716 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4717 | return success; |
| 4718 | } finally { |
| 4719 | Binder.restoreCallingIdentity(identity); |
| 4720 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4721 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4722 | return false; |
| 4723 | } |
| 4724 | |
| 4725 | /** |
| 4726 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4727 | * |
| 4728 | * @param slotIndex - device slot. |
| 4729 | * |
| 4730 | * @return true on success; false on any failure |
| 4731 | */ |
| 4732 | @Override |
| 4733 | public boolean rebootModem(int slotIndex) { |
| 4734 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4735 | if (phone != null) { |
| 4736 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4737 | mApp, phone.getSubId(), "rebootModem"); |
| 4738 | |
| 4739 | final long identity = Binder.clearCallingIdentity(); |
| 4740 | try { |
| 4741 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4742 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4743 | return success; |
| 4744 | } finally { |
| 4745 | Binder.restoreCallingIdentity(identity); |
| 4746 | } |
| 4747 | } |
| 4748 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4749 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4750 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4751 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4752 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4753 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4754 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4755 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4756 | return new String[0]; |
| 4757 | } |
| 4758 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4759 | final long identity = Binder.clearCallingIdentity(); |
| 4760 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4761 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4762 | } finally { |
| 4763 | Binder.restoreCallingIdentity(identity); |
| 4764 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4765 | } |
| 4766 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4767 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4768 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4769 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4770 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4771 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4772 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4773 | |
| 4774 | final long identity = Binder.clearCallingIdentity(); |
| 4775 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4776 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4777 | // may happen if the device does not support IMS. |
| 4778 | return; |
| 4779 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4780 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4781 | } finally { |
| 4782 | Binder.restoreCallingIdentity(identity); |
| 4783 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4784 | } |
| 4785 | |
| 4786 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4787 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4788 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4789 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4790 | public void disableIms(int slotId) { |
| 4791 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4792 | |
| 4793 | final long identity = Binder.clearCallingIdentity(); |
| 4794 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4795 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4796 | // may happen if the device does not support IMS. |
| 4797 | return; |
| 4798 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4799 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4800 | } finally { |
| 4801 | Binder.restoreCallingIdentity(identity); |
| 4802 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4803 | } |
| 4804 | |
| 4805 | /** |
| 4806 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4807 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4808 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4809 | */ |
| 4810 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4811 | IImsServiceFeatureCallback callback) { |
| 4812 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4813 | |
| 4814 | final long identity = Binder.clearCallingIdentity(); |
| 4815 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4816 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4817 | // may happen if the device does not support IMS. |
| 4818 | return null; |
| 4819 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4820 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4821 | } finally { |
| 4822 | Binder.restoreCallingIdentity(identity); |
| 4823 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4824 | } |
| 4825 | |
| 4826 | /** |
| 4827 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4828 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4829 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4830 | * listener for feature updates. |
| 4831 | */ |
| 4832 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4833 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4834 | |
| 4835 | final long identity = Binder.clearCallingIdentity(); |
| 4836 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4837 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4838 | // may happen if the device does not support IMS. |
| 4839 | return null; |
| 4840 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4841 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4842 | } finally { |
| 4843 | Binder.restoreCallingIdentity(identity); |
| 4844 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4845 | } |
| 4846 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4847 | /** |
| 4848 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4849 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4850 | */ |
| 4851 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4852 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4853 | |
| 4854 | final long identity = Binder.clearCallingIdentity(); |
| 4855 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4856 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4857 | // may happen if the device does not support IMS. |
| 4858 | return null; |
| 4859 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4860 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4861 | } finally { |
| 4862 | Binder.restoreCallingIdentity(identity); |
| 4863 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4864 | } |
| 4865 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4866 | /** |
| 4867 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4868 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4869 | */ |
| 4870 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4871 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4872 | |
| 4873 | final long identity = Binder.clearCallingIdentity(); |
| 4874 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4875 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4876 | // may happen if the device does not support IMS. |
| 4877 | return null; |
| 4878 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4879 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4880 | } finally { |
| 4881 | Binder.restoreCallingIdentity(identity); |
| 4882 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4883 | } |
| 4884 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4885 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4886 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4887 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4888 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 4889 | * @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] | 4890 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4891 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 4892 | * @param packageName The name of the package that the current configuration will be replaced |
| 4893 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4894 | * @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] | 4895 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4896 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 4897 | int[] featureTypes, String packageName) { |
| 4898 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 4899 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4900 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4901 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4902 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4903 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4904 | final long identity = Binder.clearCallingIdentity(); |
| 4905 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4906 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4907 | // may happen if the device does not support IMS. |
| 4908 | return false; |
| 4909 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4910 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 4911 | for (int featureType : featureTypes) { |
| 4912 | featureConfig.put(featureType, packageName); |
| 4913 | } |
| 4914 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 4915 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4916 | } finally { |
| 4917 | Binder.restoreCallingIdentity(identity); |
| 4918 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4919 | } |
| 4920 | |
| 4921 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4922 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4923 | * |
| 4924 | * @param slotId The slot that the ImsService is associated with. |
| 4925 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4926 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4927 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4928 | * @return the package name of the ImsService configuration. |
| 4929 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4930 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 4931 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4932 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4933 | TelephonyPermissions |
| 4934 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4935 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4936 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4937 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4938 | final long identity = Binder.clearCallingIdentity(); |
| 4939 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4940 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4941 | // may happen if the device does not support IMS. |
| 4942 | return ""; |
| 4943 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 4944 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4945 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 4946 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4947 | } finally { |
| 4948 | Binder.restoreCallingIdentity(identity); |
| 4949 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4950 | } |
| 4951 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4952 | /** |
| 4953 | * Get the MmTelFeature state associated with the requested subscription id. |
| 4954 | * @param subId The subscription that the MmTelFeature is associated with. |
| 4955 | * @param callback A callback with an integer containing the |
| 4956 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 4957 | */ |
| 4958 | @Override |
| 4959 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 4960 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 4961 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4962 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4963 | "IMS not available on device."); |
| 4964 | } |
| 4965 | final long token = Binder.clearCallingIdentity(); |
| 4966 | try { |
| 4967 | int slotId = getSlotIndex(subId); |
| 4968 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4969 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 4970 | + subId + "'"); |
| 4971 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4972 | } |
| 4973 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 4974 | try { |
| 4975 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 4976 | } catch (RemoteException e) { |
| 4977 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 4978 | + "Ignore"); |
| 4979 | } |
| 4980 | }); |
| 4981 | } finally { |
| 4982 | Binder.restoreCallingIdentity(token); |
| 4983 | } |
| 4984 | } |
| 4985 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4986 | public void setImsRegistrationState(boolean registered) { |
| 4987 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4988 | |
| 4989 | final long identity = Binder.clearCallingIdentity(); |
| 4990 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4991 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4992 | } finally { |
| 4993 | Binder.restoreCallingIdentity(identity); |
| 4994 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4995 | } |
| 4996 | |
| 4997 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4998 | * Set the network selection mode to automatic. |
| 4999 | * |
| 5000 | */ |
| 5001 | @Override |
| 5002 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5004 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5005 | |
| 5006 | final long identity = Binder.clearCallingIdentity(); |
| 5007 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5008 | if (!isActiveSubscription(subId)) { |
| 5009 | return; |
| 5010 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5011 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5012 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5013 | } finally { |
| 5014 | Binder.restoreCallingIdentity(identity); |
| 5015 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5016 | } |
| 5017 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5018 | /** |
| 5019 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5020 | * |
| 5021 | * @param subId the id of the subscription. |
| 5022 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5023 | * the operator to attach to. |
| 5024 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5025 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5026 | * normal network selection next time. |
| 5027 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5028 | */ |
| 5029 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5030 | public boolean setNetworkSelectionModeManual( |
| 5031 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5032 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5033 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5034 | |
| 5035 | if (!isActiveSubscription(subId)) { |
| 5036 | return false; |
| 5037 | } |
| 5038 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5039 | final long identity = Binder.clearCallingIdentity(); |
| 5040 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5041 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5042 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5043 | if (DBG) { |
| 5044 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5045 | + " operator: " + operatorInfo); |
| 5046 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5047 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5048 | } finally { |
| 5049 | Binder.restoreCallingIdentity(identity); |
| 5050 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5051 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5052 | /** |
| 5053 | * Get the manual network selection |
| 5054 | * |
| 5055 | * @param subId the id of the subscription. |
| 5056 | * |
| 5057 | * @return the previously saved user selected PLMN |
| 5058 | */ |
| 5059 | @Override |
| 5060 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5061 | TelephonyPermissions |
| 5062 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5063 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5064 | |
| 5065 | final long identity = Binder.clearCallingIdentity(); |
| 5066 | try { |
| 5067 | if (!isActiveSubscription(subId)) { |
| 5068 | return ""; |
| 5069 | } |
| 5070 | |
| 5071 | final Phone phone = getPhone(subId); |
| 5072 | if (phone == null) { |
| 5073 | return ""; |
| 5074 | } |
| 5075 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5076 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5077 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5078 | } finally { |
| 5079 | Binder.restoreCallingIdentity(identity); |
| 5080 | } |
| 5081 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5082 | |
| 5083 | /** |
| 5084 | * Scans for available networks. |
| 5085 | */ |
| 5086 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5087 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5088 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5089 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5090 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5091 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5092 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5093 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5094 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5095 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5096 | .setCallingPid(Binder.getCallingPid()) |
| 5097 | .setCallingUid(Binder.getCallingUid()) |
| 5098 | .setMethod("getCellNetworkScanResults") |
| 5099 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5100 | .build()); |
| 5101 | switch (locationResult) { |
| 5102 | case DENIED_HARD: |
| 5103 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5104 | case DENIED_SOFT: |
| 5105 | return null; |
| 5106 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5107 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5108 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5109 | try { |
| 5110 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5111 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5112 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5113 | } finally { |
| 5114 | Binder.restoreCallingIdentity(identity); |
| 5115 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5116 | } |
| 5117 | |
| 5118 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5119 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5120 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5121 | * @param subId id of the subscription |
| 5122 | * @param request contains the radio access networks with bands/channels to scan |
| 5123 | * @param messenger callback messenger for scan results or errors |
| 5124 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5125 | * @return the id of the requested scan which can be used to stop the scan. |
| 5126 | */ |
| 5127 | @Override |
| 5128 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5129 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5130 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5131 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5132 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5133 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5134 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5135 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5136 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5137 | .setCallingPid(Binder.getCallingPid()) |
| 5138 | .setCallingUid(Binder.getCallingUid()) |
| 5139 | .setMethod("requestNetworkScan") |
| 5140 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5141 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5142 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5143 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5144 | if (e != null) { |
| 5145 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5146 | throw e; |
| 5147 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5148 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5149 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5150 | } |
| 5151 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5152 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5153 | int callingUid = Binder.getCallingUid(); |
| 5154 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5155 | final long identity = Binder.clearCallingIdentity(); |
| 5156 | try { |
| 5157 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5158 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5159 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5160 | } finally { |
| 5161 | Binder.restoreCallingIdentity(identity); |
| 5162 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5163 | } |
| 5164 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5165 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5166 | NetworkScanRequest request, int subId) { |
| 5167 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5168 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5169 | boolean hasNetworkScanPermission = |
| 5170 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5171 | == PERMISSION_GRANTED; |
| 5172 | |
| 5173 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5174 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5175 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5176 | } |
| 5177 | |
| 5178 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5179 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5180 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5181 | return new SecurityException("Specific channels must not be" |
| 5182 | + " scanned without location access."); |
| 5183 | } |
| 5184 | } |
| 5185 | } |
| 5186 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5187 | return null; |
| 5188 | } |
| 5189 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5190 | /** |
| 5191 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5192 | * |
| 5193 | * @param subId id of the subscription |
| 5194 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5195 | */ |
| 5196 | @Override |
| 5197 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5198 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5199 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5200 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5201 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5202 | final long identity = Binder.clearCallingIdentity(); |
| 5203 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5204 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5205 | } finally { |
| 5206 | Binder.restoreCallingIdentity(identity); |
| 5207 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5208 | } |
| 5209 | |
| 5210 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5211 | * Get the calculated preferred network type. |
| 5212 | * Used for debugging incorrect network type. |
| 5213 | * |
| 5214 | * @return the preferred network type, defined in RILConstants.java. |
| 5215 | */ |
| 5216 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5217 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5218 | final Phone defaultPhone = getDefaultPhone(); |
| 5219 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5220 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5221 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5222 | } |
| 5223 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5224 | final long identity = Binder.clearCallingIdentity(); |
| 5225 | try { |
| 5226 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5227 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5228 | } finally { |
| 5229 | Binder.restoreCallingIdentity(identity); |
| 5230 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5231 | } |
| 5232 | |
| 5233 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5234 | * Get the preferred network type. |
| 5235 | * Used for device configuration by some CDMA operators. |
| 5236 | * |
| 5237 | * @return the preferred network type, defined in RILConstants.java. |
| 5238 | */ |
| 5239 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5240 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5241 | TelephonyPermissions |
| 5242 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5243 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5244 | |
| 5245 | final long identity = Binder.clearCallingIdentity(); |
| 5246 | try { |
| 5247 | if (DBG) log("getPreferredNetworkType"); |
| 5248 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5249 | int networkType = (result != null ? result[0] : -1); |
| 5250 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5251 | return networkType; |
| 5252 | } finally { |
| 5253 | Binder.restoreCallingIdentity(identity); |
| 5254 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5255 | } |
| 5256 | |
| 5257 | /** |
| 5258 | * Set the preferred network type. |
| 5259 | * Used for device configuration by some CDMA operators. |
| 5260 | * |
| 5261 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5262 | * @return true on success; false on any failure. |
| 5263 | */ |
| 5264 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5265 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5266 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5267 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5268 | |
| 5269 | final long identity = Binder.clearCallingIdentity(); |
| 5270 | try { |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5271 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5272 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5273 | return setPreferredNetworkTypesInternal(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5274 | } finally { |
| 5275 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5276 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5277 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5278 | |
| 5279 | /** |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5280 | * Get the allowed network types that store in the telephony provider. |
| 5281 | * |
| 5282 | * @param subId the id of the subscription. |
| 5283 | * @return allowedNetworkTypes the allowed network types. |
| 5284 | */ |
| 5285 | @Override |
| 5286 | public long getAllowedNetworkTypes(int subId) { |
| 5287 | TelephonyPermissions |
| 5288 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5289 | mApp, subId, "getAllowedNetworkTypes"); |
| 5290 | |
| 5291 | final long identity = Binder.clearCallingIdentity(); |
| 5292 | try { |
| 5293 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5294 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5295 | } finally { |
| 5296 | Binder.restoreCallingIdentity(identity); |
| 5297 | } |
| 5298 | } |
| 5299 | |
| 5300 | /** |
| 5301 | * Set the allowed network types. |
| 5302 | * |
| 5303 | * @param subId the id of the subscription. |
| 5304 | * @param allowedNetworkTypes the allowed network types. |
| 5305 | * @return true on success; false on any failure. |
| 5306 | */ |
| 5307 | @Override |
| 5308 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5309 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5310 | mApp, subId, "setAllowedNetworkTypes"); |
| 5311 | final long identity = Binder.clearCallingIdentity(); |
| 5312 | try { |
| 5313 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5314 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5315 | String.valueOf(allowedNetworkTypes)); |
| 5316 | return setPreferredNetworkTypesInternal(subId); |
| 5317 | } finally { |
| 5318 | Binder.restoreCallingIdentity(identity); |
| 5319 | } |
| 5320 | } |
| 5321 | |
| 5322 | private boolean setPreferredNetworkTypesInternal(int subId) { |
| 5323 | long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType( |
| 5324 | Settings.Global.getInt(mApp.getContentResolver(), |
| 5325 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5326 | RILConstants.PREFERRED_NETWORK_MODE)); |
| 5327 | long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty( |
| 5328 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5329 | int networkMode = RadioAccessFamily.getNetworkTypeFromRaf( |
| 5330 | (int) (networkTypeBitMask & allowedNetworkTypes)); |
| 5331 | |
| 5332 | if (DBG) { |
| 5333 | log("setPreferredNetworkTypesInternal: subId " + subId |
| 5334 | + " networkTypes " + networkTypeBitMask |
| 5335 | + " allowedNetworkTypes " + allowedNetworkTypes |
| 5336 | + " networkMode " + networkMode); |
| 5337 | } |
| 5338 | |
| 5339 | Boolean success = (Boolean) sendRequest( |
| 5340 | CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId); |
| 5341 | if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail")); |
| 5342 | return success; |
| 5343 | } |
| 5344 | |
| 5345 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5346 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5347 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5348 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5349 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5350 | * @hide |
| 5351 | */ |
| 5352 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5353 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5354 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5355 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5356 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5357 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5358 | if (phone != null) { |
| 5359 | return phone.hasMatchedTetherApnSetting(); |
| 5360 | } else { |
| 5361 | return false; |
| 5362 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5363 | } finally { |
| 5364 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5365 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5366 | } |
| 5367 | |
| 5368 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5369 | * Set mobile data enabled |
| 5370 | * Used by the user through settings etc to turn on/off mobile data |
| 5371 | * |
| 5372 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5373 | */ |
| 5374 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5375 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5376 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5377 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5378 | |
| 5379 | final long identity = Binder.clearCallingIdentity(); |
| 5380 | try { |
| 5381 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5382 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5383 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5384 | if (phone != null) { |
| 5385 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5386 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5387 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5388 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5389 | } |
| 5390 | } finally { |
| 5391 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5392 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5393 | } |
| 5394 | |
| 5395 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5396 | * Enable or disable always reporting signal strength changes from radio. |
| 5397 | * |
| 5398 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5399 | */ |
| 5400 | @Override |
| 5401 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5402 | enforceModifyPermission(); |
| 5403 | enforceSystemCaller(); |
| 5404 | |
| 5405 | final long identity = Binder.clearCallingIdentity(); |
| 5406 | final Phone phone = getPhone(subId); |
| 5407 | try { |
| 5408 | if (phone != null) { |
| 5409 | if (DBG) { |
| 5410 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5411 | + " isEnable=" + isEnable); |
| 5412 | } |
| 5413 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5414 | } else { |
| 5415 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5416 | + subId); |
| 5417 | } |
| 5418 | } finally { |
| 5419 | Binder.restoreCallingIdentity(identity); |
| 5420 | } |
| 5421 | } |
| 5422 | |
| 5423 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5424 | * Get the user enabled state of Mobile Data. |
| 5425 | * |
| 5426 | * TODO: remove and use isUserDataEnabled. |
| 5427 | * This can't be removed now because some vendor codes |
| 5428 | * calls through ITelephony directly while they should |
| 5429 | * use TelephonyManager. |
| 5430 | * |
| 5431 | * @return true on enabled |
| 5432 | */ |
| 5433 | @Override |
| 5434 | public boolean getDataEnabled(int subId) { |
| 5435 | return isUserDataEnabled(subId); |
| 5436 | } |
| 5437 | |
| 5438 | /** |
| 5439 | * Get whether mobile data is enabled per user setting. |
| 5440 | * |
| 5441 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5442 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5443 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5444 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5445 | * |
| 5446 | * @return {@code true} if data is enabled else {@code false} |
| 5447 | */ |
| 5448 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5449 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5450 | try { |
| 5451 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5452 | null); |
| 5453 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5454 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5455 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5456 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5457 | |
| 5458 | final long identity = Binder.clearCallingIdentity(); |
| 5459 | try { |
| 5460 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5461 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5462 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5463 | if (phone != null) { |
| 5464 | boolean retVal = phone.isUserDataEnabled(); |
| 5465 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5466 | return retVal; |
| 5467 | } else { |
| 5468 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5469 | return false; |
| 5470 | } |
| 5471 | } finally { |
| 5472 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5473 | } |
| 5474 | } |
| 5475 | |
| 5476 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5477 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5478 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5479 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5480 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5481 | * @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] | 5482 | */ |
| 5483 | @Override |
| 5484 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5485 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5486 | |
| 5487 | final long identity = Binder.clearCallingIdentity(); |
| 5488 | try { |
| 5489 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5490 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5491 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5492 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5493 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5494 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5495 | return retVal; |
| 5496 | } else { |
| 5497 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5498 | return false; |
| 5499 | } |
| 5500 | } finally { |
| 5501 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5502 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5503 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5504 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5505 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 5506 | Phone phone) { |
| 5507 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5508 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5509 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5510 | || subController == null) return privilegeFromSim; |
| 5511 | |
| 5512 | int uid = Binder.getCallingUid(); |
| 5513 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5514 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5515 | |
| 5516 | final long identity = Binder.clearCallingIdentity(); |
| 5517 | try { |
| 5518 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5519 | SubscriptionManager subManager = (SubscriptionManager) |
| 5520 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5521 | for (String pkg : packages) { |
| 5522 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5523 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5524 | } |
| 5525 | } |
| 5526 | return privilegeFromSim; |
| 5527 | } finally { |
| 5528 | Binder.restoreCallingIdentity(identity); |
| 5529 | } |
| 5530 | } |
| 5531 | |
| 5532 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5533 | String pkgName) { |
| 5534 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5535 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5536 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5537 | || subController == null) return privilegeFromSim; |
| 5538 | |
| 5539 | final long identity = Binder.clearCallingIdentity(); |
| 5540 | try { |
| 5541 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5542 | SubscriptionManager subManager = (SubscriptionManager) |
| 5543 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5544 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5545 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5546 | } finally { |
| 5547 | Binder.restoreCallingIdentity(identity); |
| 5548 | } |
| 5549 | } |
| 5550 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5551 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5552 | public int getCarrierPrivilegeStatus(int subId) { |
| 5553 | final Phone phone = getPhone(subId); |
| 5554 | if (phone == null) { |
| 5555 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5556 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5557 | } |
| 5558 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5559 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5560 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5561 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5562 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5563 | |
| 5564 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5565 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 5566 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5567 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5568 | |
| 5569 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5570 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5571 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5572 | final Phone phone = getPhone(subId); |
| 5573 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5574 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5575 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5576 | } |
| 5577 | UiccProfile profile = |
| 5578 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5579 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5580 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5581 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5582 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5583 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5584 | profile.getCarrierPrivilegeStatusForUid( |
| 5585 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5586 | } |
| 5587 | |
| 5588 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5589 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5590 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5591 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5592 | } |
| 5593 | |
| 5594 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5595 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5596 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5597 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5598 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5599 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5600 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5601 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5602 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5603 | } |
| 5604 | |
| 5605 | @Override |
| 5606 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5607 | if (TextUtils.isEmpty(pkgName)) |
| 5608 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5609 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5610 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5611 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5612 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5613 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5614 | continue; |
| 5615 | } |
| 5616 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5617 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5618 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5619 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5620 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5621 | break; |
| 5622 | } |
| 5623 | } |
| 5624 | |
| 5625 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5626 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5627 | |
| 5628 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5629 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5630 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5631 | loge("phoneId " + phoneId + " is not valid."); |
| 5632 | return null; |
| 5633 | } |
| 5634 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5635 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5636 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5637 | return null ; |
| 5638 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5639 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5640 | } |
| 5641 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5642 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5643 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5644 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5645 | List<String> privilegedPackages = new ArrayList<>(); |
| 5646 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5647 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5648 | // has UICC in that slot. |
| 5649 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5650 | if (card.hasCarrierPrivilegeRules()) { |
| 5651 | if (packages == null) { |
| 5652 | // Only check packages in user 0 for now |
| 5653 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5654 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5655 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5656 | | PackageManager.GET_SIGNING_CERTIFICATES, |
| 5657 | UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5658 | } |
| 5659 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5660 | PackageInfo pkgInfo = packages.get(p); |
| 5661 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5662 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5663 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5664 | privilegedPackages.add(pkgInfo.packageName); |
| 5665 | } |
| 5666 | } |
| 5667 | } |
| 5668 | } |
| 5669 | return privilegedPackages; |
| 5670 | } |
| 5671 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5672 | @Override |
| 5673 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5674 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5675 | |
| 5676 | final long identity = Binder.clearCallingIdentity(); |
| 5677 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5678 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5679 | try { |
| 5680 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5681 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5682 | } |
| 5683 | } finally { |
| 5684 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5685 | } |
| 5686 | return privilegedPackages; |
| 5687 | } |
| 5688 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5689 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5690 | final Phone phone = getPhone(subId); |
| 5691 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5692 | if (card == null) { |
| 5693 | loge("getIccId: No UICC"); |
| 5694 | return null; |
| 5695 | } |
| 5696 | String iccId = card.getIccId(); |
| 5697 | if (TextUtils.isEmpty(iccId)) { |
| 5698 | loge("getIccId: ICC ID is null or empty."); |
| 5699 | return null; |
| 5700 | } |
| 5701 | return iccId; |
| 5702 | } |
| 5703 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5704 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5705 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5706 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5707 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5708 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5709 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5710 | final long identity = Binder.clearCallingIdentity(); |
| 5711 | try { |
| 5712 | final String iccId = getIccId(subId); |
| 5713 | final Phone phone = getPhone(subId); |
| 5714 | if (phone == null) { |
| 5715 | return false; |
| 5716 | } |
| 5717 | final String subscriberId = phone.getSubscriberId(); |
| 5718 | |
| 5719 | if (DBG_MERGE) { |
| 5720 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 5721 | + subscriberId + " to " + number); |
| 5722 | } |
| 5723 | |
| 5724 | if (TextUtils.isEmpty(iccId)) { |
| 5725 | return false; |
| 5726 | } |
| 5727 | |
| 5728 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5729 | |
| 5730 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5731 | if (alphaTag == null) { |
| 5732 | editor.remove(alphaTagPrefKey); |
| 5733 | } else { |
| 5734 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5735 | } |
| 5736 | |
| 5737 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5738 | // track all merged IMSIs based on line number |
| 5739 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5740 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5741 | if (number == null) { |
| 5742 | editor.remove(numberPrefKey); |
| 5743 | editor.remove(subscriberPrefKey); |
| 5744 | } else { |
| 5745 | editor.putString(numberPrefKey, number); |
| 5746 | editor.putString(subscriberPrefKey, subscriberId); |
| 5747 | } |
| 5748 | |
| 5749 | editor.commit(); |
| 5750 | return true; |
| 5751 | } finally { |
| 5752 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5753 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5754 | } |
| 5755 | |
| 5756 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5757 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 5758 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5759 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5760 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5761 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5762 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5763 | return null; |
| 5764 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5765 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5766 | final long identity = Binder.clearCallingIdentity(); |
| 5767 | try { |
| 5768 | String iccId = getIccId(subId); |
| 5769 | if (iccId != null) { |
| 5770 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5771 | if (DBG_MERGE) { |
| 5772 | log("getLine1NumberForDisplay returning " |
| 5773 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5774 | } |
| 5775 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5776 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5777 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5778 | return null; |
| 5779 | } finally { |
| 5780 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5781 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5782 | } |
| 5783 | |
| 5784 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5785 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 5786 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5787 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5788 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5789 | return null; |
| 5790 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5791 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5792 | final long identity = Binder.clearCallingIdentity(); |
| 5793 | try { |
| 5794 | String iccId = getIccId(subId); |
| 5795 | if (iccId != null) { |
| 5796 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5797 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5798 | } |
| 5799 | return null; |
| 5800 | } finally { |
| 5801 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5802 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5803 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5804 | |
| 5805 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5806 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 5807 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5808 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5809 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5810 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5811 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5812 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5813 | return null; |
| 5814 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5815 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5816 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5817 | // the process, where TelephonyManager was instantiated. |
| 5818 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5819 | final long identity = Binder.clearCallingIdentity(); |
| 5820 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5821 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5822 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5823 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5824 | |
| 5825 | // Figure out what subscribers are currently active |
| 5826 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5827 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5828 | // Only consider subs which match the current subId |
| 5829 | // This logic can be simplified. See b/131189269 for progress. |
| 5830 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5831 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5832 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5833 | |
| 5834 | // First pass, find a number override for an active subscriber |
| 5835 | String mergeNumber = null; |
| 5836 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5837 | for (String key : prefs.keySet()) { |
| 5838 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5839 | final String subscriberId = (String) prefs.get(key); |
| 5840 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5841 | final String iccId = key.substring( |
| 5842 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5843 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5844 | mergeNumber = (String) prefs.get(numberKey); |
| 5845 | if (DBG_MERGE) { |
| 5846 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5847 | + " for active subscriber " + subscriberId); |
| 5848 | } |
| 5849 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5850 | break; |
| 5851 | } |
| 5852 | } |
| 5853 | } |
| 5854 | } |
| 5855 | |
| 5856 | // Shortcut when no active merged subscribers |
| 5857 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5858 | return null; |
| 5859 | } |
| 5860 | |
| 5861 | // Second pass, find all subscribers under that line override |
| 5862 | final ArraySet<String> result = new ArraySet<>(); |
| 5863 | for (String key : prefs.keySet()) { |
| 5864 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5865 | final String number = (String) prefs.get(key); |
| 5866 | if (mergeNumber.equals(number)) { |
| 5867 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5868 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5869 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5870 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5871 | result.add(subscriberId); |
| 5872 | } |
| 5873 | } |
| 5874 | } |
| 5875 | } |
| 5876 | |
| 5877 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5878 | Arrays.sort(resultArray); |
| 5879 | if (DBG_MERGE) { |
| 5880 | Slog.d(LOG_TAG, |
| 5881 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5882 | } |
| 5883 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5884 | } finally { |
| 5885 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5886 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5887 | } |
| 5888 | |
| 5889 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 5890 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 5891 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5892 | |
| 5893 | final long identity = Binder.clearCallingIdentity(); |
| 5894 | try { |
| 5895 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 5896 | TelephonyManager.class); |
| 5897 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 5898 | if (subscriberId == null) { |
| 5899 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 5900 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5901 | + subId); |
| 5902 | } |
| 5903 | return null; |
| 5904 | } |
| 5905 | |
| 5906 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 5907 | .getSubscriptionInfo(subId); |
| 5908 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 5909 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 5910 | if (groupUuid == null) { |
| 5911 | return new String[]{subscriberId}; |
| 5912 | } |
| 5913 | |
| 5914 | // Get all subscriberIds from the group. |
| 5915 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 5916 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5917 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 5918 | mApp.getFeatureId()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5919 | for (SubscriptionInfo subInfo : groupInfos) { |
| 5920 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 5921 | if (subscriberId != null) { |
| 5922 | mergedSubscriberIds.add(subscriberId); |
| 5923 | } |
| 5924 | } |
| 5925 | |
| 5926 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 5927 | } finally { |
| 5928 | Binder.restoreCallingIdentity(identity); |
| 5929 | |
| 5930 | } |
| 5931 | } |
| 5932 | |
| 5933 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5934 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5935 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5936 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5937 | |
| 5938 | final long identity = Binder.clearCallingIdentity(); |
| 5939 | try { |
| 5940 | final Phone phone = getPhone(subId); |
| 5941 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5942 | } finally { |
| 5943 | Binder.restoreCallingIdentity(identity); |
| 5944 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5945 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5946 | |
| 5947 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5948 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5949 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5950 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5951 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5952 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5953 | |
| 5954 | final long identity = Binder.clearCallingIdentity(); |
| 5955 | try { |
| 5956 | final Phone phone = getPhone(subId); |
| 5957 | if (phone == null) { |
| 5958 | return false; |
| 5959 | } |
| 5960 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5961 | cdmaNonRoamingList); |
| 5962 | } finally { |
| 5963 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5964 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5965 | } |
| 5966 | |
| 5967 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5968 | @Deprecated |
| 5969 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5970 | enforceModifyPermission(); |
| 5971 | |
| 5972 | int returnValue = 0; |
| 5973 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5974 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5975 | if(result.exception == null) { |
| 5976 | if (result.result != null) { |
| 5977 | byte[] responseData = (byte[])(result.result); |
| 5978 | if(responseData.length > oemResp.length) { |
| 5979 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5980 | responseData.length + "bytes. Buffer Size is " + |
| 5981 | oemResp.length + "bytes."); |
| 5982 | } |
| 5983 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5984 | returnValue = responseData.length; |
| 5985 | } |
| 5986 | } else { |
| 5987 | CommandException ex = (CommandException) result.exception; |
| 5988 | returnValue = ex.getCommandError().ordinal(); |
| 5989 | if(returnValue > 0) returnValue *= -1; |
| 5990 | } |
| 5991 | } catch (RuntimeException e) { |
| 5992 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5993 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5994 | if(returnValue > 0) returnValue *= -1; |
| 5995 | } |
| 5996 | |
| 5997 | return returnValue; |
| 5998 | } |
| 5999 | |
| 6000 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6001 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6002 | try { |
| 6003 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6004 | } catch (RuntimeException e) { |
| 6005 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6006 | } |
| 6007 | } |
| 6008 | |
| 6009 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6010 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6011 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6012 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6013 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6014 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6015 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6016 | final long identity = Binder.clearCallingIdentity(); |
| 6017 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6018 | TelephonyPermissions |
| 6019 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6020 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6021 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6022 | } finally { |
| 6023 | Binder.restoreCallingIdentity(identity); |
| 6024 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6025 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6026 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6027 | |
| 6028 | @Override |
| 6029 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6030 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6031 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6032 | |
| 6033 | final long identity = Binder.clearCallingIdentity(); |
| 6034 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6035 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6036 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6037 | } finally { |
| 6038 | Binder.restoreCallingIdentity(identity); |
| 6039 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6040 | } |
| 6041 | |
| 6042 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6043 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6044 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6045 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6046 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6047 | return false; |
| 6048 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6049 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6050 | final long identity = Binder.clearCallingIdentity(); |
| 6051 | try { |
| 6052 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6053 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6054 | // In the long run, we may instead need to check if there exists a connection service |
| 6055 | // which can support video calling. |
| 6056 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6057 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6058 | return imsManager.isVtEnabledByPlatform() |
| 6059 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6060 | && imsManager.isVtEnabledByUser(); |
| 6061 | } finally { |
| 6062 | Binder.restoreCallingIdentity(identity); |
| 6063 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6064 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6065 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6066 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6067 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6068 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6069 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6070 | mApp, subId, callingPackage, callingFeatureId, |
| 6071 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6072 | return false; |
| 6073 | } |
| 6074 | |
| 6075 | final long identity = Binder.clearCallingIdentity(); |
| 6076 | try { |
| 6077 | CarrierConfigManager configManager = |
| 6078 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6079 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6080 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6081 | } finally { |
| 6082 | Binder.restoreCallingIdentity(identity); |
| 6083 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6084 | } |
| 6085 | |
| 6086 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6087 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6088 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6089 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6090 | return false; |
| 6091 | } |
| 6092 | |
| 6093 | final long identity = Binder.clearCallingIdentity(); |
| 6094 | try { |
| 6095 | CarrierConfigManager configManager = |
| 6096 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6097 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6098 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6099 | } finally { |
| 6100 | Binder.restoreCallingIdentity(identity); |
| 6101 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6102 | } |
| 6103 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6104 | @Override |
| 6105 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6106 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6107 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6108 | } |
| 6109 | |
| 6110 | @Override |
| 6111 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6112 | final long identity = Binder.clearCallingIdentity(); |
| 6113 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6114 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6115 | } finally { |
| 6116 | Binder.restoreCallingIdentity(identity); |
| 6117 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6118 | } |
| 6119 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6120 | /** |
| 6121 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6122 | * support for the feature and device firmware support. |
| 6123 | * |
| 6124 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6125 | */ |
| 6126 | @Override |
| 6127 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6128 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6129 | final Phone phone = getPhone(subscriptionId); |
| 6130 | if (phone == null) { |
| 6131 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6132 | return false; |
| 6133 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6134 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6135 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6136 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6137 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6138 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6139 | return isCarrierSupported && isDeviceSupported; |
| 6140 | } finally { |
| 6141 | Binder.restoreCallingIdentity(identity); |
| 6142 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6143 | } |
| 6144 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6145 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6146 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6147 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6148 | * 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] | 6149 | */ |
| 6150 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6151 | final long identity = Binder.clearCallingIdentity(); |
| 6152 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6153 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6154 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6155 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6156 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6157 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6158 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6159 | } finally { |
| 6160 | Binder.restoreCallingIdentity(identity); |
| 6161 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6162 | } |
| 6163 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6164 | @Deprecated |
| 6165 | @Override |
| 6166 | public String getDeviceId(String callingPackage) { |
| 6167 | return getDeviceIdWithFeature(callingPackage, null); |
| 6168 | } |
| 6169 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6170 | /** |
| 6171 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6172 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6173 | * |
| 6174 | * <p>Requires Permission: |
| 6175 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6176 | */ |
| 6177 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6178 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6179 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6180 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6181 | return null; |
| 6182 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6183 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6184 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6185 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6186 | return null; |
| 6187 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6188 | |
| 6189 | final long identity = Binder.clearCallingIdentity(); |
| 6190 | try { |
| 6191 | return phone.getDeviceId(); |
| 6192 | } finally { |
| 6193 | Binder.restoreCallingIdentity(identity); |
| 6194 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6195 | } |
| 6196 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6197 | /** |
| 6198 | * {@hide} |
| 6199 | * Returns the IMS Registration Status on a particular subid |
| 6200 | * |
| 6201 | * @param subId |
| 6202 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6203 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6204 | Phone phone = getPhone(subId); |
| 6205 | if (phone != null) { |
| 6206 | return phone.isImsRegistered(); |
| 6207 | } else { |
| 6208 | return false; |
| 6209 | } |
| 6210 | } |
| 6211 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6212 | @Override |
| 6213 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6214 | final long identity = Binder.clearCallingIdentity(); |
| 6215 | try { |
| 6216 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6217 | } finally { |
| 6218 | Binder.restoreCallingIdentity(identity); |
| 6219 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6220 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6221 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6222 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6223 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6224 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6225 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6226 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6227 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6228 | } |
| 6229 | final long identity = Binder.clearCallingIdentity(); |
| 6230 | try { |
| 6231 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6232 | } finally { |
| 6233 | Binder.restoreCallingIdentity(identity); |
| 6234 | } |
| 6235 | } |
| 6236 | |
| 6237 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6238 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6239 | final long identity = Binder.clearCallingIdentity(); |
| 6240 | try { |
| 6241 | Phone phone = getPhone(subscriptionId); |
| 6242 | if (phone == null) { |
| 6243 | return null; |
| 6244 | } |
| 6245 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6246 | } finally { |
| 6247 | Binder.restoreCallingIdentity(identity); |
| 6248 | } |
| 6249 | } |
| 6250 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6251 | /** |
| 6252 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6253 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6254 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6255 | final long identity = Binder.clearCallingIdentity(); |
| 6256 | try { |
| 6257 | Phone phone = getPhone(subId); |
| 6258 | if (phone != null) { |
| 6259 | return phone.isWifiCallingEnabled(); |
| 6260 | } else { |
| 6261 | return false; |
| 6262 | } |
| 6263 | } finally { |
| 6264 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6265 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6266 | } |
| 6267 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6268 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6269 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6270 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6271 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6272 | final long identity = Binder.clearCallingIdentity(); |
| 6273 | try { |
| 6274 | Phone phone = getPhone(subId); |
| 6275 | if (phone != null) { |
| 6276 | return phone.isVideoEnabled(); |
| 6277 | } else { |
| 6278 | return false; |
| 6279 | } |
| 6280 | } finally { |
| 6281 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6282 | } |
| 6283 | } |
| 6284 | |
| 6285 | /** |
| 6286 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6287 | * defined in {@link ImsRegistrationImplBase}. |
| 6288 | */ |
| 6289 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6290 | final long identity = Binder.clearCallingIdentity(); |
| 6291 | try { |
| 6292 | Phone phone = getPhone(subId); |
| 6293 | if (phone != null) { |
| 6294 | return phone.getImsRegistrationTech(); |
| 6295 | } else { |
| 6296 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6297 | } |
| 6298 | } finally { |
| 6299 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6300 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6301 | } |
| 6302 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6303 | @Override |
| 6304 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6305 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6306 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6307 | return; |
| 6308 | } |
| 6309 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6310 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6311 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6312 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6313 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6314 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6315 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6316 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6317 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6318 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6319 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6320 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6321 | // There has been issues when Sms raw table somehow stores orphan |
| 6322 | // fragments. They lead to garbled message when new fragments come |
| 6323 | // in and combined with those stale ones. In case this happens again, |
| 6324 | // user can reset all network settings which will clean up this table. |
| 6325 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6326 | // Clean up IMS settings as well here. |
| 6327 | int slotId = getSlotIndex(subId); |
| 6328 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6329 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6330 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6331 | |
| 6332 | // Erase modem config if erase modem on network setting is enabled. |
| 6333 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6334 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6335 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6336 | sendEraseModemConfig(getDefaultPhone()); |
| 6337 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6338 | } finally { |
| 6339 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6340 | } |
| 6341 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6342 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6343 | private void cleanUpSmsRawTable(Context context) { |
| 6344 | ContentResolver resolver = context.getContentResolver(); |
| 6345 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6346 | resolver.delete(uri, null, null); |
| 6347 | } |
| 6348 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6349 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6350 | public String getSimLocaleForSubscriber(int subId) { |
| 6351 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6352 | final Phone phone = getPhone(subId); |
| 6353 | if (phone == null) { |
| 6354 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6355 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6356 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6357 | final long identity = Binder.clearCallingIdentity(); |
| 6358 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6359 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6360 | phone.getContext().getOpPackageName(), phone.getContext().getFeatureId()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6361 | if (info == null) { |
| 6362 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6363 | return null; |
| 6364 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6365 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6366 | // preferences (EF-PL and EF-LI)... |
| 6367 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6368 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6369 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6370 | if (localeFromDefaultSim != null) { |
| 6371 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6372 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6373 | + localeFromDefaultSim); |
| 6374 | return localeFromDefaultSim.toLanguageTag(); |
| 6375 | } else { |
| 6376 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6377 | } |
| 6378 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6379 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6380 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6381 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6382 | // the SIM and carrier preferences does not include a country we add the country |
| 6383 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6384 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6385 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6386 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6387 | return mccLocale.toLanguageTag(); |
| 6388 | } |
| 6389 | |
| 6390 | if (DBG) log("No locale found - returning null"); |
| 6391 | return null; |
| 6392 | } finally { |
| 6393 | Binder.restoreCallingIdentity(identity); |
| 6394 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6395 | } |
| 6396 | |
| 6397 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6398 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 6399 | mApp.getFeatureId()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6400 | } |
| 6401 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6402 | /** |
| 6403 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6404 | */ |
| 6405 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6406 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 6407 | mApp.getFeatureId()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6408 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6409 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6410 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6411 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6412 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6413 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6414 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6415 | * representing the state of the modem. |
| 6416 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6417 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6418 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6419 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6420 | */ |
| 6421 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6422 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6423 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6424 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6425 | |
| 6426 | final long identity = Binder.clearCallingIdentity(); |
| 6427 | try { |
| 6428 | ModemActivityInfo ret = null; |
| 6429 | synchronized (mLastModemActivityInfo) { |
| 6430 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 6431 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6432 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6433 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6434 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6435 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6436 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6437 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6438 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6439 | } |
| 6440 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6441 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 6442 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6443 | mLastModemActivityInfo.setIdleTimeMillis( |
| 6444 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6445 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 6446 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 6447 | info.getReceiveTimeMillis() + mLastModemActivityInfo |
| 6448 | .getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6449 | } |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6450 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6451 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 6452 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 6453 | mLastModemActivityInfo.getIdleTimeMillis(), |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6454 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 6455 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6456 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6457 | Bundle bundle = new Bundle(); |
| 6458 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 6459 | result.send(0, bundle); |
| 6460 | } finally { |
| 6461 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6462 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6463 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6464 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6465 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6466 | // less than total activity duration. |
| 6467 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6468 | if (info == null) { |
| 6469 | return false; |
| 6470 | } |
| 6471 | int activityDurationMs = |
| 6472 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6473 | int totalTxTimeMs = 0; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6474 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6475 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6476 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6477 | } |
| 6478 | return (info.isValid() |
| 6479 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6480 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6481 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6482 | && (totalTxTimeMs <= activityDurationMs)); |
| 6483 | } |
| 6484 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6485 | /** |
| 6486 | * {@hide} |
| 6487 | * Returns the service state information on specified subscription. |
| 6488 | */ |
| 6489 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6490 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6491 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6492 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6493 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6494 | return null; |
| 6495 | } |
| 6496 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6497 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6498 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6499 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6500 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6501 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6502 | .setCallingPid(Binder.getCallingPid()) |
| 6503 | .setCallingUid(Binder.getCallingUid()) |
| 6504 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6505 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6506 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6507 | .build()); |
| 6508 | |
| 6509 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6510 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6511 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6512 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6513 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6514 | .setCallingPid(Binder.getCallingPid()) |
| 6515 | .setCallingUid(Binder.getCallingUid()) |
| 6516 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6517 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6518 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6519 | .build()); |
| 6520 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6521 | boolean hasFinePermission = |
| 6522 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6523 | boolean hasCoarsePermission = |
| 6524 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6525 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6526 | final long identity = Binder.clearCallingIdentity(); |
| 6527 | try { |
| 6528 | final Phone phone = getPhone(subId); |
| 6529 | if (phone == null) { |
| 6530 | return null; |
| 6531 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6532 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6533 | ServiceState ss = phone.getServiceState(); |
| 6534 | |
| 6535 | // Scrub out the location info in ServiceState depending on what level of access |
| 6536 | // the caller has. |
| 6537 | if (hasFinePermission) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6538 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6539 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6540 | } finally { |
| 6541 | Binder.restoreCallingIdentity(identity); |
| 6542 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6543 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6544 | |
| 6545 | /** |
| 6546 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6547 | * |
| 6548 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6549 | * voicemail ringtone. |
| 6550 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6551 | * PhoneAccount. |
| 6552 | */ |
| 6553 | @Override |
| 6554 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6555 | final long identity = Binder.clearCallingIdentity(); |
| 6556 | try { |
| 6557 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6558 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6559 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6560 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6561 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6562 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6563 | } finally { |
| 6564 | Binder.restoreCallingIdentity(identity); |
| 6565 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6566 | } |
| 6567 | |
| 6568 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6569 | * Sets the per-account voicemail ringtone. |
| 6570 | * |
| 6571 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6572 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6573 | * |
| 6574 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6575 | * voicemail ringtone. |
| 6576 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6577 | * PhoneAccount. |
| 6578 | */ |
| 6579 | @Override |
| 6580 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6581 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6582 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6583 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6584 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6585 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6586 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6587 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6588 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6589 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6590 | |
| 6591 | final long identity = Binder.clearCallingIdentity(); |
| 6592 | try { |
| 6593 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6594 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6595 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6596 | } |
| 6597 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6598 | } finally { |
| 6599 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6600 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6601 | } |
| 6602 | |
| 6603 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6604 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6605 | * |
| 6606 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6607 | * voicemail vibration setting. |
| 6608 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6609 | */ |
| 6610 | @Override |
| 6611 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6612 | final long identity = Binder.clearCallingIdentity(); |
| 6613 | try { |
| 6614 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6615 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6616 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6617 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6618 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6619 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6620 | } finally { |
| 6621 | Binder.restoreCallingIdentity(identity); |
| 6622 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6623 | } |
| 6624 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6625 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6626 | * Sets the per-account voicemail vibration. |
| 6627 | * |
| 6628 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6629 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6630 | * |
| 6631 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6632 | * voicemail vibration setting. |
| 6633 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6634 | * specific PhoneAccount. |
| 6635 | */ |
| 6636 | @Override |
| 6637 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6638 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6639 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6640 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6641 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6642 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6643 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6644 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6645 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6646 | } |
| 6647 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6648 | final long identity = Binder.clearCallingIdentity(); |
| 6649 | try { |
| 6650 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6651 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6652 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6653 | } |
| 6654 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6655 | } finally { |
| 6656 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6657 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6658 | } |
| 6659 | |
| 6660 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6661 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6662 | * |
| 6663 | * @throws SecurityException if the caller does not have the required permission |
| 6664 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6665 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6666 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6667 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6668 | } |
| 6669 | |
| 6670 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6671 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6672 | * permission. |
| 6673 | * |
| 6674 | * @throws SecurityException if the caller does not have the required permission |
| 6675 | */ |
| 6676 | private void enforceSendSmsPermission() { |
| 6677 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6678 | } |
| 6679 | |
| 6680 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6681 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6682 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6683 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6684 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6685 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6686 | final long identity = Binder.clearCallingIdentity(); |
| 6687 | try { |
| 6688 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6689 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6690 | if (componentName == null) { |
| 6691 | throw new SecurityException( |
| 6692 | "Caller not current active visual voicemail package[null]"); |
| 6693 | } |
| 6694 | String vvmPackage = componentName.getPackageName(); |
| 6695 | if (!callingPackage.equals(vvmPackage)) { |
| 6696 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6697 | + vvmPackage + "]"); |
| 6698 | } |
| 6699 | } finally { |
| 6700 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6701 | } |
| 6702 | } |
| 6703 | |
| 6704 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6705 | * Return the application ID for the app type. |
| 6706 | * |
| 6707 | * @param subId the subscription ID that this request applies to. |
| 6708 | * @param appType the uicc app type. |
| 6709 | * @return Application ID for specificied app type, or null if no uicc. |
| 6710 | */ |
| 6711 | @Override |
| 6712 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6713 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6714 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6715 | |
| 6716 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6717 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6718 | if (phone == null) { |
| 6719 | return null; |
| 6720 | } |
| 6721 | String aid = null; |
| 6722 | try { |
| 6723 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6724 | .getApplicationByType(appType).getAid(); |
| 6725 | } catch (Exception e) { |
| 6726 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6727 | } |
| 6728 | return aid; |
| 6729 | } finally { |
| 6730 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6731 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6732 | } |
| 6733 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6734 | /** |
| 6735 | * Return the Electronic Serial Number. |
| 6736 | * |
| 6737 | * @param subId the subscription ID that this request applies to. |
| 6738 | * @return ESN or null if error. |
| 6739 | */ |
| 6740 | @Override |
| 6741 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6742 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6743 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6744 | |
| 6745 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6746 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6747 | if (phone == null) { |
| 6748 | return null; |
| 6749 | } |
| 6750 | String esn = null; |
| 6751 | try { |
| 6752 | esn = phone.getEsn(); |
| 6753 | } catch (Exception e) { |
| 6754 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6755 | } |
| 6756 | return esn; |
| 6757 | } finally { |
| 6758 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6759 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6760 | } |
| 6761 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6762 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6763 | * Return the Preferred Roaming List Version. |
| 6764 | * |
| 6765 | * @param subId the subscription ID that this request applies to. |
| 6766 | * @return PRLVersion or null if error. |
| 6767 | */ |
| 6768 | @Override |
| 6769 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6770 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6771 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6772 | |
| 6773 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6774 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6775 | if (phone == null) { |
| 6776 | return null; |
| 6777 | } |
| 6778 | String cdmaPrlVersion = null; |
| 6779 | try { |
| 6780 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6781 | } catch (Exception e) { |
| 6782 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6783 | } |
| 6784 | return cdmaPrlVersion; |
| 6785 | } finally { |
| 6786 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6787 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6788 | } |
| 6789 | |
| 6790 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6791 | * Get snapshot of Telephony histograms |
| 6792 | * @return List of Telephony histograms |
| 6793 | * @hide |
| 6794 | */ |
| 6795 | @Override |
| 6796 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6797 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6798 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6799 | |
| 6800 | final long identity = Binder.clearCallingIdentity(); |
| 6801 | try { |
| 6802 | return RIL.getTelephonyRILTimingHistograms(); |
| 6803 | } finally { |
| 6804 | Binder.restoreCallingIdentity(identity); |
| 6805 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6806 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6807 | |
| 6808 | /** |
| 6809 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6810 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6811 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6812 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6813 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6814 | * @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] | 6815 | */ |
| 6816 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6817 | @TelephonyManager.SetCarrierRestrictionResult |
| 6818 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6819 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6820 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6821 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6822 | if (carrierRestrictionRules == null) { |
| 6823 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6824 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6825 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6826 | final long identity = Binder.clearCallingIdentity(); |
| 6827 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6828 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6829 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6830 | } finally { |
| 6831 | Binder.restoreCallingIdentity(identity); |
| 6832 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6833 | } |
| 6834 | |
| 6835 | /** |
| 6836 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6837 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6838 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6839 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6840 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6841 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6842 | */ |
| 6843 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6844 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6845 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6846 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6847 | |
| 6848 | final long identity = Binder.clearCallingIdentity(); |
| 6849 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6850 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 6851 | if (response instanceof CarrierRestrictionRules) { |
| 6852 | return (CarrierRestrictionRules) response; |
| 6853 | } |
| 6854 | // Response is an Exception of some kind, |
| 6855 | // which is signalled to the user as a NULL retval |
| 6856 | return null; |
| 6857 | } catch (Exception e) { |
| 6858 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 6859 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6860 | } finally { |
| 6861 | Binder.restoreCallingIdentity(identity); |
| 6862 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6863 | } |
| 6864 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6865 | /** |
| 6866 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 6867 | * @param subId the subscription ID that this action applies to. |
| 6868 | * @param enabled control enable or disable metered apns. |
| 6869 | * {@hide} |
| 6870 | */ |
| 6871 | @Override |
| 6872 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 6873 | enforceModifyPermission(); |
| 6874 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6875 | |
| 6876 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6877 | if (phone == null) { |
| 6878 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 6879 | return; |
| 6880 | } |
| 6881 | try { |
| 6882 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 6883 | } catch (Exception e) { |
| 6884 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6885 | } finally { |
| 6886 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6887 | } |
| 6888 | } |
| 6889 | |
| 6890 | /** |
| 6891 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 6892 | * @param subId the subscription ID that this action applies to. |
| 6893 | * @param enabled control enable or disable radio. |
| 6894 | * {@hide} |
| 6895 | */ |
| 6896 | @Override |
| 6897 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 6898 | enforceModifyPermission(); |
| 6899 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6900 | |
| 6901 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6902 | if (phone == null) { |
| 6903 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 6904 | return; |
| 6905 | } |
| 6906 | try { |
| 6907 | phone.carrierActionSetRadioEnabled(enabled); |
| 6908 | } catch (Exception e) { |
| 6909 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6910 | } finally { |
| 6911 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6912 | } |
| 6913 | } |
| 6914 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6915 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6916 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6917 | * network status based on which carrier apps could apply actions accordingly, |
| 6918 | * enable/disable default url handler for example. |
| 6919 | * |
| 6920 | * @param subId the subscription ID that this action applies to. |
| 6921 | * @param report control start/stop reporting the default network status. |
| 6922 | * {@hide} |
| 6923 | */ |
| 6924 | @Override |
| 6925 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6926 | enforceModifyPermission(); |
| 6927 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6928 | |
| 6929 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6930 | if (phone == null) { |
| 6931 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6932 | return; |
| 6933 | } |
| 6934 | try { |
| 6935 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6936 | } catch (Exception e) { |
| 6937 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6938 | } finally { |
| 6939 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6940 | } |
| 6941 | } |
| 6942 | |
| 6943 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6944 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6945 | * @param subId the subscription ID that this action applies to. |
| 6946 | * {@hide} |
| 6947 | */ |
| 6948 | @Override |
| 6949 | public void carrierActionResetAll(int subId) { |
| 6950 | enforceModifyPermission(); |
| 6951 | final Phone phone = getPhone(subId); |
| 6952 | if (phone == null) { |
| 6953 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6954 | return; |
| 6955 | } |
| 6956 | try { |
| 6957 | phone.carrierActionResetAll(); |
| 6958 | } catch (Exception e) { |
| 6959 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6960 | } |
| 6961 | } |
| 6962 | |
| 6963 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6964 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6965 | * bug report is being generated. |
| 6966 | */ |
| 6967 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6968 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6969 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6970 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6971 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6972 | + Binder.getCallingPid() |
| 6973 | + ", uid=" + Binder.getCallingUid() |
| 6974 | + "without permission " |
| 6975 | + android.Manifest.permission.DUMP); |
| 6976 | return; |
| 6977 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6978 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6979 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6980 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6981 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 6982 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 6983 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 6984 | @NonNull String[] args) { |
| 6985 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 6986 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 6987 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6988 | } |
| 6989 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6990 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6991 | * Get aggregated video call data usage since boot. |
| 6992 | * |
| 6993 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6994 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6995 | * {@hide} |
| 6996 | */ |
| 6997 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6998 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6999 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 7000 | null); |
| 7001 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7002 | final long identity = Binder.clearCallingIdentity(); |
| 7003 | try { |
| 7004 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 7005 | // records the delta with the corresponding network identity. |
| 7006 | // We just return the total video call data usage snapshot since boot. |
| 7007 | Phone phone = getPhone(subId); |
| 7008 | if (phone != null) { |
| 7009 | return phone.getVtDataUsage(perUidStats); |
| 7010 | } |
| 7011 | return null; |
| 7012 | } finally { |
| 7013 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7014 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7015 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7016 | |
| 7017 | /** |
| 7018 | * Policy control of data connection. Usually used when data limit is passed. |
| 7019 | * @param enabled True if enabling the data, otherwise disabling. |
| 7020 | * @param subId Subscription index |
| 7021 | * {@hide} |
| 7022 | */ |
| 7023 | @Override |
| 7024 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 7025 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7026 | |
| 7027 | final long identity = Binder.clearCallingIdentity(); |
| 7028 | try { |
| 7029 | Phone phone = getPhone(subId); |
| 7030 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 7031 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7032 | } |
| 7033 | } finally { |
| 7034 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7035 | } |
| 7036 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7037 | |
| 7038 | /** |
| 7039 | * Get Client request stats |
| 7040 | * @return List of Client Request Stats |
| 7041 | * @hide |
| 7042 | */ |
| 7043 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7044 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7045 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7046 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7047 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7048 | return null; |
| 7049 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7050 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7051 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7052 | final long identity = Binder.clearCallingIdentity(); |
| 7053 | try { |
| 7054 | if (phone != null) { |
| 7055 | return phone.getClientRequestStats(); |
| 7056 | } |
| 7057 | |
| 7058 | return null; |
| 7059 | } finally { |
| 7060 | Binder.restoreCallingIdentity(identity); |
| 7061 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7062 | } |
| 7063 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7064 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7065 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7066 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7067 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7068 | |
| 7069 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7070 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7071 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7072 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7073 | * @param state State of SIM (power down, power up, pass through) |
| 7074 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7075 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7076 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7077 | * |
| 7078 | **/ |
| 7079 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7080 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7081 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7082 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7083 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7084 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7085 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7086 | final long identity = Binder.clearCallingIdentity(); |
| 7087 | try { |
| 7088 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7089 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7090 | } |
| 7091 | } finally { |
| 7092 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7093 | } |
| 7094 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7095 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7096 | private boolean isUssdApiAllowed(int subId) { |
| 7097 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7098 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7099 | if (configManager == null) { |
| 7100 | return false; |
| 7101 | } |
| 7102 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7103 | if (pb == null) { |
| 7104 | return false; |
| 7105 | } |
| 7106 | return pb.getBoolean( |
| 7107 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7108 | } |
| 7109 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7110 | /** |
| 7111 | * Check if phone is in emergency callback mode |
| 7112 | * @return true if phone is in emergency callback mode |
| 7113 | * @param subId sub id |
| 7114 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7115 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7116 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7117 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7118 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7119 | |
| 7120 | final long identity = Binder.clearCallingIdentity(); |
| 7121 | try { |
| 7122 | if (phone != null) { |
| 7123 | return phone.isInEcm(); |
| 7124 | } else { |
| 7125 | return false; |
| 7126 | } |
| 7127 | } finally { |
| 7128 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7129 | } |
| 7130 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7131 | |
| 7132 | /** |
| 7133 | * Get the current signal strength information for the given subscription. |
| 7134 | * Because this information is not updated when the device is in a low power state |
| 7135 | * it should not be relied-upon to be current. |
| 7136 | * @param subId Subscription index |
| 7137 | * @return the most recent cached signal strength info from the modem |
| 7138 | */ |
| 7139 | @Override |
| 7140 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7141 | final long identity = Binder.clearCallingIdentity(); |
| 7142 | try { |
| 7143 | Phone p = getPhone(subId); |
| 7144 | if (p == null) { |
| 7145 | return null; |
| 7146 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7147 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7148 | return p.getSignalStrength(); |
| 7149 | } finally { |
| 7150 | Binder.restoreCallingIdentity(identity); |
| 7151 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7152 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7153 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7154 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7155 | * Get the current modem radio state for the given slot. |
| 7156 | * @param slotIndex slot index. |
| 7157 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7158 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7159 | * @return the current radio power state from the modem |
| 7160 | */ |
| 7161 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7162 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7163 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7164 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7165 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7166 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7167 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7168 | } |
| 7169 | |
| 7170 | final long identity = Binder.clearCallingIdentity(); |
| 7171 | try { |
| 7172 | return phone.getRadioPowerState(); |
| 7173 | } finally { |
| 7174 | Binder.restoreCallingIdentity(identity); |
| 7175 | } |
| 7176 | } |
| 7177 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7178 | } |
| 7179 | |
| 7180 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7181 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7182 | * |
| 7183 | * <p>Requires one of the following permissions: |
| 7184 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7185 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7186 | * privileges. |
| 7187 | * |
| 7188 | * @param subId subscription id |
| 7189 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7190 | * {@code false}. |
| 7191 | */ |
| 7192 | @Override |
| 7193 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7194 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7195 | null /* message */); |
| 7196 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7197 | boolean isEnabled = false; |
| 7198 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7199 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7200 | Phone phone = getPhone(subId); |
| 7201 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7202 | } catch (Exception e) { |
| 7203 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7204 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7205 | } finally { |
| 7206 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7207 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7208 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7209 | } |
| 7210 | |
| 7211 | |
| 7212 | /** |
| 7213 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7214 | * |
| 7215 | * <p> Requires permission: |
| 7216 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7217 | * privileges. |
| 7218 | * |
| 7219 | * @param subId subscription id |
| 7220 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7221 | */ |
| 7222 | @Override |
| 7223 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7224 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7225 | mApp, subId, "setDataRoamingEnabled"); |
| 7226 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7227 | final long identity = Binder.clearCallingIdentity(); |
| 7228 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7229 | Phone phone = getPhone(subId); |
| 7230 | if (phone != null) { |
| 7231 | phone.setDataRoamingEnabled(isEnabled); |
| 7232 | } |
| 7233 | } finally { |
| 7234 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7235 | } |
| 7236 | } |
| 7237 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7238 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7239 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7240 | TelephonyPermissions |
| 7241 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7242 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7243 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7244 | boolean isAllowed = true; |
| 7245 | final long identity = Binder.clearCallingIdentity(); |
| 7246 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7247 | Phone phone = getPhone(subId); |
| 7248 | if (phone != null) { |
| 7249 | isAllowed = phone.isCspPlmnEnabled(); |
| 7250 | } |
| 7251 | } finally { |
| 7252 | Binder.restoreCallingIdentity(identity); |
| 7253 | } |
| 7254 | return isAllowed; |
| 7255 | } |
| 7256 | |
| 7257 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7258 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7259 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7260 | try { |
| 7261 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7262 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7263 | } catch (SecurityException e) { |
| 7264 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7265 | // has carrier privileges on an active UICC |
| 7266 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7267 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7268 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7269 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7270 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7271 | |
| 7272 | final long identity = Binder.clearCallingIdentity(); |
| 7273 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7274 | UiccController uiccController = UiccController.getInstance(); |
| 7275 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7276 | if (hasReadPermission) { |
| 7277 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7278 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7279 | |
| 7280 | // Remove private info if the caller doesn't have access |
| 7281 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7282 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7283 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7284 | // is available |
| 7285 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7286 | if (card == null || card.getUiccProfile() == null) { |
| 7287 | // assume no access if the card or profile is unavailable |
| 7288 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7289 | continue; |
| 7290 | } |
| 7291 | UiccProfile profile = card.getUiccProfile(); |
| 7292 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7293 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7294 | filteredInfos.add(cardInfo); |
| 7295 | } else { |
| 7296 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7297 | } |
| 7298 | } |
| 7299 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7300 | } finally { |
| 7301 | Binder.restoreCallingIdentity(identity); |
| 7302 | } |
| 7303 | } |
| 7304 | |
| 7305 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7306 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7307 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7308 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7309 | final long identity = Binder.clearCallingIdentity(); |
| 7310 | try { |
| 7311 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7312 | if (slots == null) { |
| 7313 | Rlog.i(LOG_TAG, "slots is null."); |
| 7314 | return null; |
| 7315 | } |
| 7316 | |
| 7317 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7318 | for (int i = 0; i < slots.length; i++) { |
| 7319 | UiccSlot slot = slots[i]; |
| 7320 | if (slot == null) { |
| 7321 | continue; |
| 7322 | } |
| 7323 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7324 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7325 | UiccCard card = slot.getUiccCard(); |
| 7326 | if (card != null) { |
| 7327 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7328 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7329 | cardId = slot.getEid(); |
| 7330 | if (TextUtils.isEmpty(cardId)) { |
| 7331 | cardId = slot.getIccId(); |
| 7332 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7333 | } |
| 7334 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7335 | if (cardId != null) { |
| 7336 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7337 | // if cardId is an EID, it's all digits so this is fine |
| 7338 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7339 | } |
| 7340 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7341 | int cardState = 0; |
| 7342 | switch (slot.getCardState()) { |
| 7343 | case CARDSTATE_ABSENT: |
| 7344 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7345 | break; |
| 7346 | case CARDSTATE_PRESENT: |
| 7347 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7348 | break; |
| 7349 | case CARDSTATE_ERROR: |
| 7350 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7351 | break; |
| 7352 | case CARDSTATE_RESTRICTED: |
| 7353 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7354 | break; |
| 7355 | default: |
| 7356 | break; |
| 7357 | |
| 7358 | } |
| 7359 | |
| 7360 | infos[i] = new UiccSlotInfo( |
| 7361 | slot.isActive(), |
| 7362 | slot.isEuicc(), |
| 7363 | cardId, |
| 7364 | cardState, |
| 7365 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7366 | slot.isExtendedApduSupported(), |
| 7367 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7368 | } |
| 7369 | return infos; |
| 7370 | } finally { |
| 7371 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7372 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7373 | } |
| 7374 | |
| 7375 | @Override |
| 7376 | public boolean switchSlots(int[] physicalSlots) { |
| 7377 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7378 | |
| 7379 | final long identity = Binder.clearCallingIdentity(); |
| 7380 | try { |
| 7381 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7382 | } finally { |
| 7383 | Binder.restoreCallingIdentity(identity); |
| 7384 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7385 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7386 | |
| 7387 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7388 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7389 | final long identity = Binder.clearCallingIdentity(); |
| 7390 | try { |
| 7391 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7392 | } finally { |
| 7393 | Binder.restoreCallingIdentity(identity); |
| 7394 | } |
| 7395 | } |
| 7396 | |
| 7397 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7398 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 7399 | enforceModifyPermission(); |
| 7400 | final Phone phone = getPhone(subId); |
| 7401 | if (phone == null) { |
| 7402 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 7403 | return; |
| 7404 | } |
| 7405 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7406 | final long identity = Binder.clearCallingIdentity(); |
| 7407 | try { |
| 7408 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 7409 | } finally { |
| 7410 | Binder.restoreCallingIdentity(identity); |
| 7411 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7412 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7413 | |
| 7414 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7415 | * A test API to reload the UICC profile. |
| 7416 | * |
| 7417 | * <p>Requires that the calling app has permission |
| 7418 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7419 | * @hide |
| 7420 | */ |
| 7421 | @Override |
| 7422 | public void refreshUiccProfile(int subId) { |
| 7423 | enforceModifyPermission(); |
| 7424 | |
| 7425 | final long identity = Binder.clearCallingIdentity(); |
| 7426 | try { |
| 7427 | Phone phone = getPhone(subId); |
| 7428 | if (phone == null) { |
| 7429 | return; |
| 7430 | } |
| 7431 | UiccCard uiccCard = phone.getUiccCard(); |
| 7432 | if (uiccCard == null) { |
| 7433 | return; |
| 7434 | } |
| 7435 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7436 | if (uiccProfile == null) { |
| 7437 | return; |
| 7438 | } |
| 7439 | uiccProfile.refresh(); |
| 7440 | } finally { |
| 7441 | Binder.restoreCallingIdentity(identity); |
| 7442 | } |
| 7443 | } |
| 7444 | |
| 7445 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7446 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7447 | */ |
| 7448 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7449 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7450 | } |
| 7451 | |
| 7452 | /** |
| 7453 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7454 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7455 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7456 | */ |
| 7457 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7458 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7459 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7460 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7461 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7462 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7463 | return isDataRoamingEnabled; |
| 7464 | } |
| 7465 | |
| 7466 | /** |
| 7467 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7468 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7469 | */ |
| 7470 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7471 | List<Integer> list = TelephonyProperties.default_network(); |
| 7472 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7473 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7474 | return list.get(phoneId); |
| 7475 | } |
| 7476 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7477 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7478 | |
| 7479 | @Override |
| 7480 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7481 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7482 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7483 | |
| 7484 | final long identity = Binder.clearCallingIdentity(); |
| 7485 | try { |
| 7486 | final Phone phone = getPhone(subId); |
| 7487 | if (phone == null) { |
| 7488 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7489 | return; |
| 7490 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7491 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7492 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7493 | } finally { |
| 7494 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7495 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7496 | } |
| 7497 | |
| 7498 | @Override |
| 7499 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7500 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7501 | |
| 7502 | final long identity = Binder.clearCallingIdentity(); |
| 7503 | try { |
| 7504 | final Phone phone = getPhone(subId); |
| 7505 | if (phone == null) { |
| 7506 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7507 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7508 | } |
| 7509 | return phone.getCarrierIdListVersion(); |
| 7510 | } finally { |
| 7511 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7512 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7513 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7514 | |
| 7515 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7516 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7517 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7518 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7519 | mApp, subId, callingPackage, callingFeatureId, |
| 7520 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7521 | return -1; |
| 7522 | } |
| 7523 | |
| 7524 | final long identity = Binder.clearCallingIdentity(); |
| 7525 | try { |
| 7526 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7527 | } finally { |
| 7528 | Binder.restoreCallingIdentity(identity); |
| 7529 | } |
| 7530 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7531 | |
| 7532 | @Override |
| 7533 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7534 | TelephonyPermissions |
| 7535 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7536 | mApp, subId, "getCdmaRoamingMode"); |
| 7537 | |
| 7538 | final long identity = Binder.clearCallingIdentity(); |
| 7539 | try { |
| 7540 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7541 | } finally { |
| 7542 | Binder.restoreCallingIdentity(identity); |
| 7543 | } |
| 7544 | } |
| 7545 | |
| 7546 | @Override |
| 7547 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7548 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7549 | mApp, subId, "setCdmaRoamingMode"); |
| 7550 | |
| 7551 | final long identity = Binder.clearCallingIdentity(); |
| 7552 | try { |
| 7553 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7554 | } finally { |
| 7555 | Binder.restoreCallingIdentity(identity); |
| 7556 | } |
| 7557 | } |
| 7558 | |
| 7559 | @Override |
| 7560 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7561 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7562 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7563 | |
| 7564 | final long identity = Binder.clearCallingIdentity(); |
| 7565 | try { |
| 7566 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7567 | } finally { |
| 7568 | Binder.restoreCallingIdentity(identity); |
| 7569 | } |
| 7570 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7571 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7572 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7573 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7574 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7575 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7576 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7577 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7578 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7579 | } |
| 7580 | final long identity = Binder.clearCallingIdentity(); |
| 7581 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7582 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7583 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7584 | if (phone.getEmergencyNumberTracker() != null |
| 7585 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7586 | emergencyNumberListInternal.put( |
| 7587 | phone.getSubId(), |
| 7588 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7589 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7590 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7591 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7592 | } finally { |
| 7593 | Binder.restoreCallingIdentity(identity); |
| 7594 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7595 | } |
| 7596 | |
| 7597 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7598 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7599 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7600 | if (!exactMatch) { |
| 7601 | TelephonyPermissions |
| 7602 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7603 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7604 | } |
| 7605 | final long identity = Binder.clearCallingIdentity(); |
| 7606 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7607 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7608 | if (phone.getEmergencyNumberTracker() != null |
| 7609 | && phone.getEmergencyNumberTracker() != null) { |
| 7610 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7611 | number, exactMatch)) { |
| 7612 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7613 | } |
| 7614 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7615 | } |
| 7616 | return false; |
| 7617 | } finally { |
| 7618 | Binder.restoreCallingIdentity(identity); |
| 7619 | } |
| 7620 | } |
| 7621 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7622 | /** |
| 7623 | * Update emergency number list for test mode. |
| 7624 | */ |
| 7625 | @Override |
| 7626 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7627 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7628 | "updateEmergencyNumberListTestMode"); |
| 7629 | |
| 7630 | final long identity = Binder.clearCallingIdentity(); |
| 7631 | try { |
| 7632 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7633 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7634 | if (tracker != null) { |
| 7635 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7636 | } |
| 7637 | } |
| 7638 | } finally { |
| 7639 | Binder.restoreCallingIdentity(identity); |
| 7640 | } |
| 7641 | } |
| 7642 | |
| 7643 | /** |
| 7644 | * Get the full emergency number list for test mode. |
| 7645 | */ |
| 7646 | @Override |
| 7647 | public List<String> getEmergencyNumberListTestMode() { |
| 7648 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7649 | "getEmergencyNumberListTestMode"); |
| 7650 | |
| 7651 | final long identity = Binder.clearCallingIdentity(); |
| 7652 | try { |
| 7653 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7654 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7655 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7656 | if (tracker != null) { |
| 7657 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7658 | emergencyNumbers.add(num.getNumber()); |
| 7659 | } |
| 7660 | } |
| 7661 | } |
| 7662 | return new ArrayList<>(emergencyNumbers); |
| 7663 | } finally { |
| 7664 | Binder.restoreCallingIdentity(identity); |
| 7665 | } |
| 7666 | } |
| 7667 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7668 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7669 | public int getEmergencyNumberDbVersion(int subId) { |
| 7670 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7671 | |
| 7672 | final long identity = Binder.clearCallingIdentity(); |
| 7673 | try { |
| 7674 | final Phone phone = getPhone(subId); |
| 7675 | if (phone == null) { |
| 7676 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7677 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7678 | } |
| 7679 | return phone.getEmergencyNumberDbVersion(); |
| 7680 | } finally { |
| 7681 | Binder.restoreCallingIdentity(identity); |
| 7682 | } |
| 7683 | } |
| 7684 | |
| 7685 | @Override |
| 7686 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7687 | enforceModifyPermission(); |
| 7688 | |
| 7689 | final long identity = Binder.clearCallingIdentity(); |
| 7690 | try { |
| 7691 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7692 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7693 | if (tracker != null) { |
| 7694 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7695 | } |
| 7696 | } |
| 7697 | } finally { |
| 7698 | Binder.restoreCallingIdentity(identity); |
| 7699 | } |
| 7700 | } |
| 7701 | |
| 7702 | @Override |
| 7703 | public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) { |
| 7704 | enforceActiveEmergencySessionPermission(); |
| 7705 | |
| 7706 | final long identity = Binder.clearCallingIdentity(); |
| 7707 | try { |
| 7708 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7709 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7710 | if (tracker != null) { |
| 7711 | tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath); |
| 7712 | } |
| 7713 | } |
| 7714 | } finally { |
| 7715 | Binder.restoreCallingIdentity(identity); |
| 7716 | } |
| 7717 | } |
| 7718 | |
| 7719 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7720 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7721 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7722 | Phone phone = getPhone(subId); |
| 7723 | if (phone == null) { |
| 7724 | return null; |
| 7725 | } |
| 7726 | final long identity = Binder.clearCallingIdentity(); |
| 7727 | try { |
| 7728 | UiccProfile profile = UiccController.getInstance() |
| 7729 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7730 | if (profile != null) { |
| 7731 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7732 | } |
| 7733 | } finally { |
| 7734 | Binder.restoreCallingIdentity(identity); |
| 7735 | } |
| 7736 | return null; |
| 7737 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7738 | |
| 7739 | /** |
| 7740 | * Enable or disable a modem stack. |
| 7741 | */ |
| 7742 | @Override |
| 7743 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7744 | enforceModifyPermission(); |
| 7745 | |
| 7746 | final long identity = Binder.clearCallingIdentity(); |
| 7747 | try { |
| 7748 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7749 | if (phone == null) { |
| 7750 | return false; |
| 7751 | } else { |
| 7752 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7753 | } |
| 7754 | } finally { |
| 7755 | Binder.restoreCallingIdentity(identity); |
| 7756 | } |
| 7757 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7758 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7759 | /** |
| 7760 | * Whether a modem stack is enabled or not. |
| 7761 | */ |
| 7762 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7763 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7764 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7765 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7766 | if (phone == null) return false; |
| 7767 | |
| 7768 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7769 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7770 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7771 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7772 | } |
| 7773 | |
| 7774 | final long identity = Binder.clearCallingIdentity(); |
| 7775 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7776 | try { |
| 7777 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7778 | } catch (NoSuchElementException ex) { |
| 7779 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7780 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7781 | } finally { |
| 7782 | Binder.restoreCallingIdentity(identity); |
| 7783 | } |
| 7784 | } |
| 7785 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7786 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7787 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7788 | enforceModifyPermission(); |
| 7789 | |
| 7790 | final long identity = Binder.clearCallingIdentity(); |
| 7791 | try { |
| 7792 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7793 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7794 | .commit(); |
| 7795 | } finally { |
| 7796 | Binder.restoreCallingIdentity(identity); |
| 7797 | } |
| 7798 | } |
| 7799 | |
| 7800 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7801 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7802 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7803 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7804 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 7805 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7806 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7807 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7808 | |
| 7809 | final long identity = Binder.clearCallingIdentity(); |
| 7810 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7811 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7812 | } finally { |
| 7813 | Binder.restoreCallingIdentity(identity); |
| 7814 | } |
| 7815 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7816 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7817 | @TelephonyManager.IsMultiSimSupportedResult |
| 7818 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7819 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7820 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7821 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7822 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7823 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7824 | } |
| 7825 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7826 | // supported by the modem, indicate that it is restricted. |
| 7827 | PhoneCapability staticCapability = |
| 7828 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7829 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7830 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7831 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7832 | } |
Sarah Chin | 0605abf | 2019-12-06 10:24:18 -0800 | [diff] [blame] | 7833 | if (staticCapability.getLogicalModemUuids().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7834 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7835 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7836 | } |
| 7837 | // Check if support of multiple SIMs is restricted by carrier |
| 7838 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7839 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7840 | } |
| 7841 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7842 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7843 | } |
| 7844 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7845 | /** |
| 7846 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7847 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7848 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7849 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7850 | * @param numOfSims number of active sims we want to switch to |
| 7851 | */ |
| 7852 | @Override |
| 7853 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7854 | if (numOfSims == 1) { |
| 7855 | enforceModifyPermission(); |
| 7856 | } else { |
| 7857 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7858 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7859 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7860 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7861 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7862 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7863 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7864 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7865 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7866 | return; |
| 7867 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7868 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7869 | } finally { |
| 7870 | Binder.restoreCallingIdentity(identity); |
| 7871 | } |
| 7872 | } |
| 7873 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 7874 | @Override |
| 7875 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 7876 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 7877 | Phone phone = getPhone(subId); |
| 7878 | if (phone == null) { |
| 7879 | return false; |
| 7880 | } |
| 7881 | final long identity = Binder.clearCallingIdentity(); |
| 7882 | try { |
| 7883 | UiccCard uiccCard = phone.getUiccCard(); |
| 7884 | if (uiccCard == null) { |
| 7885 | return false; |
| 7886 | } |
| 7887 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7888 | if (uiccProfile == null) { |
| 7889 | return false; |
| 7890 | } |
| 7891 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 7892 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 7893 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 7894 | } |
| 7895 | return false; |
| 7896 | } finally { |
| 7897 | Binder.restoreCallingIdentity(identity); |
| 7898 | } |
| 7899 | } |
| 7900 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7901 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7902 | * Get whether making changes to modem configurations will trigger reboot. |
| 7903 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7904 | */ |
| 7905 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7906 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 7907 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7908 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7909 | mApp, subId, callingPackage, callingFeatureId, |
| 7910 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7911 | return false; |
| 7912 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7913 | final long identity = Binder.clearCallingIdentity(); |
| 7914 | try { |
| 7915 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 7916 | } finally { |
| 7917 | Binder.restoreCallingIdentity(identity); |
| 7918 | } |
| 7919 | } |
| 7920 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 7921 | private void updateModemStateMetrics() { |
| 7922 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 7923 | // TODO: check the state for each modem if the api is ready. |
| 7924 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 7925 | } |
| 7926 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 7927 | @Override |
| 7928 | public int[] getSlotsMapping() { |
| 7929 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 7930 | |
| 7931 | final long identity = Binder.clearCallingIdentity(); |
| 7932 | try { |
| 7933 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 7934 | // All logical slots should have a mapping to a physical slot. |
| 7935 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 7936 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 7937 | for (int i = 0; i < slotInfos.length; i++) { |
| 7938 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 7939 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 7940 | } |
| 7941 | } |
| 7942 | return logicalSlotsMapping; |
| 7943 | } finally { |
| 7944 | Binder.restoreCallingIdentity(identity); |
| 7945 | } |
| 7946 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7947 | |
| 7948 | /** |
| 7949 | * Get the IRadio HAL Version |
| 7950 | */ |
| 7951 | @Override |
| 7952 | public int getRadioHalVersion() { |
| 7953 | Phone phone = getDefaultPhone(); |
| 7954 | if (phone == null) return -1; |
| 7955 | HalVersion hv = phone.getHalVersion(); |
| 7956 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7957 | return hv.major * 100 + hv.minor; |
| 7958 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7959 | |
| 7960 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 7961 | * Get the current calling package name. |
| 7962 | * @return the current calling package name |
| 7963 | */ |
| 7964 | @Override |
| 7965 | public String getCurrentPackageName() { |
| 7966 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 7967 | } |
| 7968 | |
| 7969 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7970 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7971 | * corresponding network requests on a subId. |
| 7972 | * |
| 7973 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7974 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7975 | * 2) APN is un-metered for this subscription, or |
| 7976 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 7977 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7978 | * |
| 7979 | * @return whether data is allowed for a apn type. |
| 7980 | * |
| 7981 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7982 | */ |
| 7983 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7984 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 7985 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 7986 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7987 | |
| 7988 | // Now that all security checks passes, perform the operation as ourselves. |
| 7989 | final long identity = Binder.clearCallingIdentity(); |
| 7990 | try { |
| 7991 | Phone phone = getPhone(subId); |
| 7992 | if (phone == null) return false; |
| 7993 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7994 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7995 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7996 | } finally { |
| 7997 | Binder.restoreCallingIdentity(identity); |
| 7998 | } |
| 7999 | } |
| 8000 | |
| 8001 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8002 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8003 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8004 | |
| 8005 | // Now that all security checks passes, perform the operation as ourselves. |
| 8006 | final long identity = Binder.clearCallingIdentity(); |
| 8007 | try { |
| 8008 | Phone phone = getPhone(subId); |
| 8009 | if (phone == null) return true; // By default return true. |
| 8010 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8011 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8012 | } finally { |
| 8013 | Binder.restoreCallingIdentity(identity); |
| 8014 | } |
| 8015 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8016 | |
| 8017 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8018 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8019 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8020 | enforceModifyPermission(); |
| 8021 | long token = Binder.clearCallingIdentity(); |
| 8022 | try { |
| 8023 | Phone phone = getPhone(subscriptionId); |
| 8024 | if (phone == null) { |
| 8025 | try { |
| 8026 | if (resultCallback != null) { |
| 8027 | resultCallback.accept(false); |
| 8028 | } |
| 8029 | } catch (RemoteException e) { |
| 8030 | // ignore |
| 8031 | } |
| 8032 | return; |
| 8033 | } |
| 8034 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8035 | Pair.create(specifiers, (x) -> { |
| 8036 | try { |
| 8037 | if (resultCallback != null) { |
| 8038 | resultCallback.accept(x); |
| 8039 | } |
| 8040 | } catch (RemoteException e) { |
| 8041 | // ignore |
| 8042 | } |
| 8043 | }); |
| 8044 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8045 | } finally { |
| 8046 | Binder.restoreCallingIdentity(token); |
| 8047 | } |
| 8048 | } |
| 8049 | |
| 8050 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8051 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
| 8052 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8053 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8054 | if (iccRecords == null) { |
| 8055 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8056 | return false; |
| 8057 | } |
| 8058 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8059 | } |
| 8060 | |
| 8061 | @Override |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8062 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8063 | if (callingPackage == null) { |
| 8064 | callingPackage = getCurrentPackageName(); |
| 8065 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8066 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8067 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 8068 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 8069 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8070 | } |
| 8071 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8072 | Intent intent = new Intent(); |
| 8073 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8074 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8075 | // Bring up choose default SMS subscription dialog right now |
| 8076 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8077 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8078 | mApp.startActivity(intent); |
| 8079 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8080 | |
| 8081 | @Override |
| 8082 | public String getMmsUAProfUrl(int subId) { |
| 8083 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8084 | final long identity = Binder.clearCallingIdentity(); |
| 8085 | try { |
| 8086 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8087 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 8088 | } finally { |
| 8089 | Binder.restoreCallingIdentity(identity); |
| 8090 | } |
| 8091 | } |
| 8092 | |
| 8093 | @Override |
| 8094 | public String getMmsUserAgent(int subId) { |
| 8095 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8096 | final long identity = Binder.clearCallingIdentity(); |
| 8097 | try { |
| 8098 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8099 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8100 | } finally { |
| 8101 | Binder.restoreCallingIdentity(identity); |
| 8102 | } |
| 8103 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8104 | |
| 8105 | @Override |
| 8106 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 8107 | enforceModifyPermission(); |
| 8108 | |
| 8109 | // Now that all security checks passes, perform the operation as ourselves. |
| 8110 | final long identity = Binder.clearCallingIdentity(); |
| 8111 | try { |
| 8112 | Phone phone = getPhone(subId); |
| 8113 | if (phone == null) return false; |
| 8114 | |
| 8115 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 8116 | } finally { |
| 8117 | Binder.restoreCallingIdentity(identity); |
| 8118 | } |
| 8119 | } |
| 8120 | |
| 8121 | @Override |
| 8122 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 8123 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 8124 | |
| 8125 | // Now that all security checks passes, perform the operation as ourselves. |
| 8126 | final long identity = Binder.clearCallingIdentity(); |
| 8127 | try { |
| 8128 | Phone phone = getPhone(subId); |
| 8129 | if (phone == null) return false; |
| 8130 | |
| 8131 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8132 | } finally { |
| 8133 | Binder.restoreCallingIdentity(identity); |
| 8134 | } |
| 8135 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8136 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8137 | @Override |
| 8138 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8139 | enforceModifyPermission(); |
| 8140 | |
| 8141 | // Now that all security checks passes, perform the operation as ourselves. |
| 8142 | final long identity = Binder.clearCallingIdentity(); |
| 8143 | try { |
| 8144 | Phone phone = getPhone(subId); |
| 8145 | if (phone == null) return false; |
| 8146 | |
| 8147 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8148 | } finally { |
| 8149 | Binder.restoreCallingIdentity(identity); |
| 8150 | } |
| 8151 | } |
| 8152 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8153 | /** |
| 8154 | * Updates whether conference event pacakge handling is enabled. |
| 8155 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8156 | * otherwise. |
| 8157 | */ |
| 8158 | @Override |
| 8159 | public void setCepEnabled(boolean isCepEnabled) { |
| 8160 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8161 | |
| 8162 | final long identity = Binder.clearCallingIdentity(); |
| 8163 | try { |
| 8164 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8165 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8166 | Phone defaultPhone = phone.getImsPhone(); |
| 8167 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8168 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8169 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8170 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8171 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8172 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8173 | + imsPhone.getMsisdn()); |
| 8174 | } |
| 8175 | } |
| 8176 | } finally { |
| 8177 | Binder.restoreCallingIdentity(identity); |
| 8178 | } |
| 8179 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8180 | |
| 8181 | /** |
| 8182 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8183 | * |
| 8184 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8185 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8186 | * before being read. |
| 8187 | */ |
| 8188 | @Override |
| 8189 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8190 | isCompressed) { |
| 8191 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8192 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8193 | try { |
| 8194 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8195 | if (configBinder == null) { |
| 8196 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8197 | } else { |
| 8198 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8199 | } |
| 8200 | } catch (RemoteException e) { |
| 8201 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8202 | } |
| 8203 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8204 | |
| 8205 | @Override |
| 8206 | public boolean isIccLockEnabled(int subId) { |
| 8207 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8208 | |
| 8209 | // Now that all security checks passes, perform the operation as ourselves. |
| 8210 | final long identity = Binder.clearCallingIdentity(); |
| 8211 | try { |
| 8212 | Phone phone = getPhone(subId); |
| 8213 | if (phone != null && phone.getIccCard() != null) { |
| 8214 | return phone.getIccCard().getIccLockEnabled(); |
| 8215 | } else { |
| 8216 | return false; |
| 8217 | } |
| 8218 | } finally { |
| 8219 | Binder.restoreCallingIdentity(identity); |
| 8220 | } |
| 8221 | } |
| 8222 | |
| 8223 | /** |
| 8224 | * Set the ICC pin lock enabled or disabled. |
| 8225 | * |
| 8226 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 8227 | * three cases: |
| 8228 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 8229 | * successfully. |
| 8230 | * - Positive number and zero for remaining password attempts. |
| 8231 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8232 | * |
| 8233 | */ |
| 8234 | @Override |
| 8235 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8236 | enforceModifyPermission(); |
| 8237 | |
| 8238 | Phone phone = getPhone(subId); |
| 8239 | if (phone == null) { |
| 8240 | return 0; |
| 8241 | } |
| 8242 | // Now that all security checks passes, perform the operation as ourselves. |
| 8243 | final long identity = Binder.clearCallingIdentity(); |
| 8244 | try { |
| 8245 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8246 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8247 | return attemptsRemaining; |
| 8248 | |
| 8249 | } catch (Exception e) { |
| 8250 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8251 | } finally { |
| 8252 | Binder.restoreCallingIdentity(identity); |
| 8253 | } |
| 8254 | return 0; |
| 8255 | } |
| 8256 | |
| 8257 | /** |
| 8258 | * Change the ICC password used in ICC pin lock. |
| 8259 | * |
| 8260 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 8261 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 8262 | * - Positive number and zero for remaining password attempts. |
| 8263 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8264 | * |
| 8265 | */ |
| 8266 | @Override |
| 8267 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8268 | enforceModifyPermission(); |
| 8269 | |
| 8270 | Phone phone = getPhone(subId); |
| 8271 | if (phone == null) { |
| 8272 | return 0; |
| 8273 | } |
| 8274 | // Now that all security checks passes, perform the operation as ourselves. |
| 8275 | final long identity = Binder.clearCallingIdentity(); |
| 8276 | try { |
| 8277 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8278 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8279 | return attemptsRemaining; |
| 8280 | |
| 8281 | } catch (Exception e) { |
| 8282 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8283 | } finally { |
| 8284 | Binder.restoreCallingIdentity(identity); |
| 8285 | } |
| 8286 | return 0; |
| 8287 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 8288 | |
| 8289 | /** |
| 8290 | * Request for receiving user activity notification |
| 8291 | */ |
| 8292 | @Override |
| 8293 | public void requestUserActivityNotification() { |
| 8294 | if (!mNotifyUserActivity.get() |
| 8295 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 8296 | mNotifyUserActivity.set(true); |
| 8297 | } |
| 8298 | } |
| 8299 | |
| 8300 | /** |
| 8301 | * Called when userActivity is signalled in the power manager. |
| 8302 | * This is safe to call from any thread, with any window manager locks held or not. |
| 8303 | */ |
| 8304 | @Override |
| 8305 | public void userActivity() { |
| 8306 | // *************************************** |
| 8307 | // * Inherited from PhoneWindowManager * |
| 8308 | // *************************************** |
| 8309 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 8310 | // WITH ITS LOCKS HELD. |
| 8311 | // |
| 8312 | // This code must be VERY careful about the locks |
| 8313 | // it acquires. |
| 8314 | // In fact, the current code acquires way too many, |
| 8315 | // and probably has lurking deadlocks. |
| 8316 | |
| 8317 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 8318 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 8319 | } |
| 8320 | |
| 8321 | if (mNotifyUserActivity.getAndSet(false)) { |
| 8322 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 8323 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 8324 | } |
| 8325 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8326 | } |