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; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame^] | 68 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 69 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 70 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 71 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 72 | import android.telephony.CellIdentityCdma; |
| 73 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfoGsm; |
| 76 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 77 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 78 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 79 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 80 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 81 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 82 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 83 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 84 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 85 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 86 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 87 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 88 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 89 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 90 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 91 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 92 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 93 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 94 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 95 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 96 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 97 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 98 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 99 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 100 | import android.telephony.data.ApnSetting; |
| 101 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 102 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 103 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 104 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 108 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 109 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 110 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 111 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 112 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 113 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 114 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 115 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 116 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 117 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 118 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 119 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 120 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 121 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 122 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 123 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 124 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame^] | 125 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 129 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame^] | 132 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 135 | import com.android.internal.telephony.IBooleanConsumer; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 161 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 172 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 173 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 175 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 176 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 177 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 178 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 179 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 180 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 181 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 182 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 183 | import java.io.FileDescriptor; |
| 184 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 185 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 186 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 187 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 188 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 189 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 190 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 191 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 192 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 193 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 194 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 195 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 196 | |
| 197 | /** |
| 198 | * Implementation of the ITelephony interface. |
| 199 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 200 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 201 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 202 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 203 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 204 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 205 | |
| 206 | // Message codes used with mMainThreadHandler |
| 207 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 208 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 209 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 210 | private static final int CMD_OPEN_CHANNEL = 9; |
| 211 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 212 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 213 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 214 | private static final int CMD_NV_READ_ITEM = 13; |
| 215 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 216 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 217 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 218 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 219 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 220 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 221 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 222 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 223 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 224 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 225 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 226 | private static final int CMD_SEND_ENVELOPE = 25; |
| 227 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 228 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 229 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 230 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 231 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 232 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 233 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 234 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 235 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 236 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 237 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 238 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 239 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 240 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 241 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 242 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 243 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 244 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 245 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 246 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 247 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 248 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 249 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 250 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 251 | private static final int CMD_SWITCH_SLOTS = 50; |
| 252 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 253 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 254 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 255 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 256 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 257 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 258 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 259 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 260 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 261 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 262 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 263 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 264 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 265 | private static final int CMD_MODEM_REBOOT = 64; |
| 266 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 267 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 268 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 269 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 270 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 271 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 272 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 273 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 274 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 275 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 276 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 277 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 278 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 279 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 280 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 281 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 282 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 283 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame^] | 284 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 285 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 286 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 287 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 288 | private static final int CMD_GET_CALL_WAITING = 87; |
| 289 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 290 | private static final int CMD_SET_CALL_WAITING = 89; |
| 291 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 292 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 293 | // Parameters of select command. |
| 294 | private static final int SELECT_COMMAND = 0xA4; |
| 295 | private static final int SELECT_P1 = 0x04; |
| 296 | private static final int SELECT_P2 = 0; |
| 297 | private static final int SELECT_P3 = 0x10; |
| 298 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 299 | /** The singleton instance. */ |
| 300 | private static PhoneInterfaceManager sInstance; |
| 301 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 302 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 303 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 304 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 305 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 306 | private AppOpsManager mAppOps; |
| 307 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 308 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 309 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 310 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 311 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 312 | /** User Activity */ |
| 313 | private AtomicBoolean mNotifyUserActivity; |
| 314 | private static final String ACTION_USER_ACTIVITY_NOTIFICATION = |
| 315 | "android.intent.action.USER_ACTIVITY_NOTIFICATION"; |
| 316 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 317 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 318 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 319 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 320 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 321 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 322 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 323 | // String to store multi SIM allowed |
| 324 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 325 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 326 | // The AID of ISD-R. |
| 327 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 328 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 329 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 330 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 331 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 332 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 333 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 334 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 335 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 336 | */ |
| 337 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 338 | "reset_network_erase_modem_config_enabled"; |
| 339 | |
| 340 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 341 | * A request object to use for transmitting data to an ICC. |
| 342 | */ |
| 343 | private static final class IccAPDUArgument { |
| 344 | public int channel, cla, command, p1, p2, p3; |
| 345 | public String data; |
| 346 | |
| 347 | public IccAPDUArgument(int channel, int cla, int command, |
| 348 | int p1, int p2, int p3, String data) { |
| 349 | this.channel = channel; |
| 350 | this.cla = cla; |
| 351 | this.command = command; |
| 352 | this.p1 = p1; |
| 353 | this.p2 = p2; |
| 354 | this.p3 = p3; |
| 355 | this.data = data; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 360 | * A request object to use for transmitting data to an ICC. |
| 361 | */ |
| 362 | private static final class ManualNetworkSelectionArgument { |
| 363 | public OperatorInfo operatorInfo; |
| 364 | public boolean persistSelection; |
| 365 | |
| 366 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 367 | this.operatorInfo = operatorInfo; |
| 368 | this.persistSelection = persistSelection; |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 373 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 374 | * request after sending. The main thread will notify the request when it is complete. |
| 375 | */ |
| 376 | private static final class MainThreadRequest { |
| 377 | /** The argument to use for the request */ |
| 378 | public Object argument; |
| 379 | /** The result of the request that is run on the main thread */ |
| 380 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 381 | // The subscriber id that this request applies to. Defaults to |
| 382 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 383 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 384 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 385 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 386 | public Phone phone; |
| 387 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 388 | public WorkSource workSource; |
| 389 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 390 | public MainThreadRequest(Object argument) { |
| 391 | this.argument = argument; |
| 392 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 393 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 394 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 395 | this.argument = argument; |
| 396 | if (phone != null) { |
| 397 | this.phone = phone; |
| 398 | } |
| 399 | this.workSource = workSource; |
| 400 | } |
| 401 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 402 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 403 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 404 | if (subId != null) { |
| 405 | this.subId = subId; |
| 406 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 407 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 408 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 411 | private static final class IncomingThirdPartyCallArgs { |
| 412 | public final ComponentName component; |
| 413 | public final String callId; |
| 414 | public final String callerDisplayName; |
| 415 | |
| 416 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 417 | String callerDisplayName) { |
| 418 | this.component = component; |
| 419 | this.callId = callId; |
| 420 | this.callerDisplayName = callerDisplayName; |
| 421 | } |
| 422 | } |
| 423 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 424 | /** |
| 425 | * A handler that processes messages on the main thread in the phone process. Since many |
| 426 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 427 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 428 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 429 | * on, which will be notified when the operation completes and will contain the result of the |
| 430 | * request. |
| 431 | * |
| 432 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 433 | * note that request.result must be set to something non-null for the calling thread to |
| 434 | * unblock. |
| 435 | */ |
| 436 | private final class MainThreadHandler extends Handler { |
| 437 | @Override |
| 438 | public void handleMessage(Message msg) { |
| 439 | MainThreadRequest request; |
| 440 | Message onCompleted; |
| 441 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 442 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 443 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 444 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 445 | |
| 446 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 447 | case CMD_HANDLE_USSD_REQUEST: { |
| 448 | request = (MainThreadRequest) msg.obj; |
| 449 | final Phone phone = getPhoneFromRequest(request); |
| 450 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 451 | String ussdRequest = ussdObject.first; |
| 452 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 453 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 454 | if (!isUssdApiAllowed(request.subId)) { |
| 455 | // Carrier does not support use of this API, return failure. |
| 456 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 457 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 458 | Bundle returnData = new Bundle(); |
| 459 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 460 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 461 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 462 | request.result = true; |
| 463 | notifyRequester(request); |
| 464 | return; |
| 465 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 466 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 467 | try { |
| 468 | request.result = phone != null |
| 469 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 470 | } catch (CallStateException cse) { |
| 471 | request.result = false; |
| 472 | } |
| 473 | // Wake up the requesting thread |
| 474 | notifyRequester(request); |
| 475 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 478 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 479 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 480 | final Phone phone = getPhoneFromRequest(request); |
| 481 | request.result = phone != null ? |
| 482 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 483 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 484 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 485 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 486 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 487 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 488 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 489 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 490 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 491 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 492 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 493 | if (uiccCard == null) { |
| 494 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 495 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 496 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 497 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 498 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 499 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 500 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 501 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 502 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 503 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 504 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 505 | break; |
| 506 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 507 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 508 | ar = (AsyncResult) msg.obj; |
| 509 | request = (MainThreadRequest) ar.userObj; |
| 510 | if (ar.exception == null && ar.result != null) { |
| 511 | request.result = ar.result; |
| 512 | } else { |
| 513 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 514 | if (ar.result == null) { |
| 515 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 516 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 517 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 518 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 519 | } else { |
| 520 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 521 | } |
| 522 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 523 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 524 | break; |
| 525 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 526 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 527 | request = (MainThreadRequest) msg.obj; |
| 528 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 529 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 530 | if (uiccCard == null) { |
| 531 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 532 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 533 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 534 | } else { |
| 535 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 536 | request); |
| 537 | uiccCard.iccTransmitApduBasicChannel( |
| 538 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 539 | iccArgument.p3, iccArgument.data, onCompleted); |
| 540 | } |
| 541 | break; |
| 542 | |
| 543 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 544 | ar = (AsyncResult) msg.obj; |
| 545 | request = (MainThreadRequest) ar.userObj; |
| 546 | if (ar.exception == null && ar.result != null) { |
| 547 | request.result = ar.result; |
| 548 | } else { |
| 549 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 550 | if (ar.result == null) { |
| 551 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 552 | } else if (ar.exception instanceof CommandException) { |
| 553 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 554 | ar.exception); |
| 555 | } else { |
| 556 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 557 | } |
| 558 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 559 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 560 | break; |
| 561 | |
| 562 | case CMD_EXCHANGE_SIM_IO: |
| 563 | request = (MainThreadRequest) msg.obj; |
| 564 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 565 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 566 | if (uiccCard == null) { |
| 567 | loge("iccExchangeSimIO: No UICC"); |
| 568 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 569 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 570 | } else { |
| 571 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 572 | request); |
| 573 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 574 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 575 | iccArgument.data, onCompleted); |
| 576 | } |
| 577 | break; |
| 578 | |
| 579 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 580 | ar = (AsyncResult) msg.obj; |
| 581 | request = (MainThreadRequest) ar.userObj; |
| 582 | if (ar.exception == null && ar.result != null) { |
| 583 | request.result = ar.result; |
| 584 | } else { |
| 585 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 586 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 587 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 588 | break; |
| 589 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 590 | case CMD_SEND_ENVELOPE: |
| 591 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 592 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 593 | if (uiccCard == null) { |
| 594 | loge("sendEnvelopeWithStatus: No UICC"); |
| 595 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 596 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 597 | } else { |
| 598 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 599 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 600 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 601 | break; |
| 602 | |
| 603 | case EVENT_SEND_ENVELOPE_DONE: |
| 604 | ar = (AsyncResult) msg.obj; |
| 605 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 606 | if (ar.exception == null && ar.result != null) { |
| 607 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 608 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 609 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 610 | if (ar.result == null) { |
| 611 | loge("sendEnvelopeWithStatus: Empty response"); |
| 612 | } else if (ar.exception instanceof CommandException) { |
| 613 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 614 | ar.exception); |
| 615 | } else { |
| 616 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 617 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 618 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 619 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 620 | break; |
| 621 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 622 | case CMD_OPEN_CHANNEL: |
| 623 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 624 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 625 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 626 | if (uiccCard == null) { |
| 627 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 628 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 629 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 630 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 631 | } else { |
| 632 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 633 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 634 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 635 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 636 | break; |
| 637 | |
| 638 | case EVENT_OPEN_CHANNEL_DONE: |
| 639 | ar = (AsyncResult) msg.obj; |
| 640 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 641 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 642 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 643 | int[] result = (int[]) ar.result; |
| 644 | int channelId = result[0]; |
| 645 | byte[] selectResponse = null; |
| 646 | if (result.length > 1) { |
| 647 | selectResponse = new byte[result.length - 1]; |
| 648 | for (int i = 1; i < result.length; ++i) { |
| 649 | selectResponse[i - 1] = (byte) result[i]; |
| 650 | } |
| 651 | } |
| 652 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 653 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 654 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 655 | if (ar.result == null) { |
| 656 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 657 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 658 | if (ar.exception != null) { |
| 659 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 660 | } |
| 661 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 662 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 663 | if (ar.exception instanceof CommandException) { |
| 664 | CommandException.Error error = |
| 665 | ((CommandException) (ar.exception)).getCommandError(); |
| 666 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 667 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 668 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 669 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 673 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 674 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 675 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 676 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 677 | break; |
| 678 | |
| 679 | case CMD_CLOSE_CHANNEL: |
| 680 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 681 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 682 | if (uiccCard == null) { |
| 683 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 684 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 685 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 686 | } else { |
| 687 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 688 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 689 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 690 | break; |
| 691 | |
| 692 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 693 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 694 | break; |
| 695 | |
| 696 | case CMD_NV_READ_ITEM: |
| 697 | request = (MainThreadRequest) msg.obj; |
| 698 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 699 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 700 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 701 | break; |
| 702 | |
| 703 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 704 | ar = (AsyncResult) msg.obj; |
| 705 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 706 | if (ar.exception == null && ar.result != null) { |
| 707 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 708 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 709 | request.result = ""; |
| 710 | if (ar.result == null) { |
| 711 | loge("nvReadItem: Empty response"); |
| 712 | } else if (ar.exception instanceof CommandException) { |
| 713 | loge("nvReadItem: CommandException: " + |
| 714 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 715 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 716 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 717 | } |
| 718 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 719 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 720 | break; |
| 721 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 722 | case CMD_NV_WRITE_ITEM: |
| 723 | request = (MainThreadRequest) msg.obj; |
| 724 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 725 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 726 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 727 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 728 | break; |
| 729 | |
| 730 | case EVENT_NV_WRITE_ITEM_DONE: |
| 731 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 732 | break; |
| 733 | |
| 734 | case CMD_NV_WRITE_CDMA_PRL: |
| 735 | request = (MainThreadRequest) msg.obj; |
| 736 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 737 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 738 | break; |
| 739 | |
| 740 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 741 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 742 | break; |
| 743 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 744 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 745 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 746 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 747 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 748 | break; |
| 749 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 750 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 751 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 752 | break; |
| 753 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 754 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 755 | request = (MainThreadRequest) msg.obj; |
| 756 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 757 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 758 | break; |
| 759 | |
| 760 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 761 | ar = (AsyncResult) msg.obj; |
| 762 | request = (MainThreadRequest) ar.userObj; |
| 763 | if (ar.exception == null && ar.result != null) { |
| 764 | request.result = ar.result; // Integer |
| 765 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 766 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 767 | if (ar.result == null) { |
| 768 | loge("getPreferredNetworkType: Empty response"); |
| 769 | } else if (ar.exception instanceof CommandException) { |
| 770 | loge("getPreferredNetworkType: CommandException: " + |
| 771 | ar.exception); |
| 772 | } else { |
| 773 | loge("getPreferredNetworkType: Unknown exception"); |
| 774 | } |
| 775 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 776 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 777 | break; |
| 778 | |
| 779 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 780 | request = (MainThreadRequest) msg.obj; |
| 781 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 782 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 783 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 784 | break; |
| 785 | |
| 786 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 787 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 788 | break; |
| 789 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 790 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 791 | request = (MainThreadRequest)msg.obj; |
| 792 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 793 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 794 | break; |
| 795 | |
| 796 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 797 | ar = (AsyncResult)msg.obj; |
| 798 | request = (MainThreadRequest)ar.userObj; |
| 799 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 800 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 801 | break; |
| 802 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 803 | case CMD_SET_VOICEMAIL_NUMBER: |
| 804 | request = (MainThreadRequest) msg.obj; |
| 805 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 806 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 807 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 808 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 809 | break; |
| 810 | |
| 811 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 812 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 813 | break; |
| 814 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 815 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 816 | request = (MainThreadRequest) msg.obj; |
| 817 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 818 | request); |
| 819 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 820 | break; |
| 821 | |
| 822 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 823 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 824 | break; |
| 825 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 826 | case CMD_PERFORM_NETWORK_SCAN: |
| 827 | request = (MainThreadRequest) msg.obj; |
| 828 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 829 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 830 | break; |
| 831 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame^] | 832 | case CMD_GET_CALL_FORWARDING: |
| 833 | request = (MainThreadRequest) msg.obj; |
| 834 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
| 835 | int callForwardingReason = (Integer) request.argument; |
| 836 | getPhoneFromRequest(request).getCallForwardingOption( |
| 837 | callForwardingReason, onCompleted); |
| 838 | break; |
| 839 | |
| 840 | case EVENT_GET_CALL_FORWARDING_DONE: |
| 841 | ar = (AsyncResult) msg.obj; |
| 842 | request = (MainThreadRequest) ar.userObj; |
| 843 | CallForwardingInfo callForwardingInfo = null; |
| 844 | if (ar.exception == null && ar.result != null) { |
| 845 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 846 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 847 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 848 | // any service for voice call. |
| 849 | if ((callForwardInfo.serviceClass |
| 850 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
| 851 | callForwardingInfo = new CallForwardingInfo( |
| 852 | callForwardInfo.serviceClass, callForwardInfo.reason, |
| 853 | callForwardInfo.number, |
| 854 | callForwardInfo.timeSeconds); |
| 855 | break; |
| 856 | } |
| 857 | } |
| 858 | // Didn't find a call forward info for voice call. |
| 859 | if (callForwardingInfo == null) { |
| 860 | callForwardingInfo = new CallForwardingInfo( |
| 861 | CallForwardingInfo.STATUS_UNKNOWN_ERROR, |
| 862 | 0 /* reason */, null /* number */, 0 /* timeout */); |
| 863 | } |
| 864 | } else { |
| 865 | if (ar.result == null) { |
| 866 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 867 | } |
| 868 | if (ar.exception != null) { |
| 869 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 870 | } |
| 871 | int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR; |
| 872 | if (ar.exception instanceof CommandException) { |
| 873 | CommandException.Error error = |
| 874 | ((CommandException) (ar.exception)).getCommandError(); |
| 875 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 876 | errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE; |
| 877 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 878 | errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED; |
| 879 | } |
| 880 | } |
| 881 | callForwardingInfo = new CallForwardingInfo( |
| 882 | errorCode, 0 /* reason */, null /* number */, 0 /* timeout */); |
| 883 | } |
| 884 | request.result = callForwardingInfo; |
| 885 | notifyRequester(request); |
| 886 | break; |
| 887 | |
| 888 | case CMD_SET_CALL_FORWARDING: |
| 889 | request = (MainThreadRequest) msg.obj; |
| 890 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
| 891 | CallForwardingInfo callForwardingInfoToSet = |
| 892 | (CallForwardingInfo) request.argument; |
| 893 | getPhoneFromRequest(request).setCallForwardingOption( |
| 894 | callForwardingInfoToSet.getStatus(), |
| 895 | callForwardingInfoToSet.getReason(), |
| 896 | callForwardingInfoToSet.getNumber(), |
| 897 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 898 | break; |
| 899 | |
| 900 | case EVENT_SET_CALL_FORWARDING_DONE: |
| 901 | ar = (AsyncResult) msg.obj; |
| 902 | request = (MainThreadRequest) ar.userObj; |
| 903 | if (ar.exception == null) { |
| 904 | request.result = true; |
| 905 | } else { |
| 906 | request.result = false; |
| 907 | loge("setCallForwarding exception: " + ar.exception); |
| 908 | } |
| 909 | notifyRequester(request); |
| 910 | break; |
| 911 | |
| 912 | case CMD_GET_CALL_WAITING: |
| 913 | request = (MainThreadRequest) msg.obj; |
| 914 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 915 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 916 | break; |
| 917 | |
| 918 | case EVENT_GET_CALL_WAITING_DONE: |
| 919 | ar = (AsyncResult) msg.obj; |
| 920 | request = (MainThreadRequest) ar.userObj; |
| 921 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 922 | if (ar.exception == null && ar.result != null) { |
| 923 | ArrayList<Integer> callForwardResults = (ArrayList<Integer>) ar.result; |
| 924 | // Service Class is a bit mask per 3gpp 27.007. |
| 925 | // Search for any service for voice call. |
| 926 | if ((callForwardResults.get(1) |
| 927 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
| 928 | callForwardingStatus = callForwardResults.get(0) == 0 |
| 929 | ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE |
| 930 | : TelephonyManager.CALL_WAITING_STATUS_ACTIVE; |
| 931 | } else { |
| 932 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE; |
| 933 | } |
| 934 | } else { |
| 935 | if (ar.result == null) { |
| 936 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 937 | } |
| 938 | if (ar.exception != null) { |
| 939 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 940 | } |
| 941 | if (ar.exception instanceof CommandException) { |
| 942 | CommandException.Error error = |
| 943 | ((CommandException) (ar.exception)).getCommandError(); |
| 944 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 945 | callForwardingStatus = |
| 946 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 947 | } |
| 948 | } |
| 949 | } |
| 950 | request.result = callForwardingStatus; |
| 951 | notifyRequester(request); |
| 952 | break; |
| 953 | |
| 954 | case CMD_SET_CALL_WAITING: |
| 955 | request = (MainThreadRequest) msg.obj; |
| 956 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
| 957 | boolean isEnable = (Boolean) request.argument; |
| 958 | getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted); |
| 959 | break; |
| 960 | |
| 961 | case EVENT_SET_CALL_WAITING_DONE: |
| 962 | ar = (AsyncResult) msg.obj; |
| 963 | request = (MainThreadRequest) ar.userObj; |
| 964 | if (ar.exception == null) { |
| 965 | request.result = true; |
| 966 | } else { |
| 967 | request.result = false; |
| 968 | loge("setCallWaiting exception: " + ar.exception); |
| 969 | } |
| 970 | notifyRequester(request); |
| 971 | break; |
| 972 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 973 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 974 | ar = (AsyncResult) msg.obj; |
| 975 | request = (MainThreadRequest) ar.userObj; |
| 976 | CellNetworkScanResult cellScanResult; |
| 977 | if (ar.exception == null && ar.result != null) { |
| 978 | cellScanResult = new CellNetworkScanResult( |
| 979 | CellNetworkScanResult.STATUS_SUCCESS, |
| 980 | (List<OperatorInfo>) ar.result); |
| 981 | } else { |
| 982 | if (ar.result == null) { |
| 983 | loge("getCellNetworkScanResults: Empty response"); |
| 984 | } |
| 985 | if (ar.exception != null) { |
| 986 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 987 | } |
| 988 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 989 | if (ar.exception instanceof CommandException) { |
| 990 | CommandException.Error error = |
| 991 | ((CommandException) (ar.exception)).getCommandError(); |
| 992 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 993 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 994 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 995 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 996 | } |
| 997 | } |
| 998 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 999 | } |
| 1000 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1001 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1002 | break; |
| 1003 | |
| 1004 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1005 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1006 | ManualNetworkSelectionArgument selArg = |
| 1007 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1008 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1009 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1010 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1011 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1012 | break; |
| 1013 | |
| 1014 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1015 | ar = (AsyncResult) msg.obj; |
| 1016 | request = (MainThreadRequest) ar.userObj; |
| 1017 | if (ar.exception == null) { |
| 1018 | request.result = true; |
| 1019 | } else { |
| 1020 | request.result = false; |
| 1021 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1022 | } |
| 1023 | notifyRequester(request); |
| 1024 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1025 | break; |
| 1026 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1027 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1028 | request = (MainThreadRequest) msg.obj; |
| 1029 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1030 | if (defaultPhone != null) { |
| 1031 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 1032 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1033 | break; |
| 1034 | |
| 1035 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1036 | ar = (AsyncResult) msg.obj; |
| 1037 | request = (MainThreadRequest) ar.userObj; |
| 1038 | if (ar.exception == null && ar.result != null) { |
| 1039 | request.result = ar.result; |
| 1040 | } else { |
| 1041 | if (ar.result == null) { |
| 1042 | loge("queryModemActivityInfo: Empty response"); |
| 1043 | } else if (ar.exception instanceof CommandException) { |
| 1044 | loge("queryModemActivityInfo: CommandException: " + |
| 1045 | ar.exception); |
| 1046 | } else { |
| 1047 | loge("queryModemActivityInfo: Unknown exception"); |
| 1048 | } |
| 1049 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 1050 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 1051 | if (request.result == null) { |
Peter Collingbourne | c00e902 | 2019-11-26 09:56:26 -0800 | [diff] [blame] | 1052 | request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 1053 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1054 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1055 | break; |
| 1056 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1057 | case CMD_SET_ALLOWED_CARRIERS: |
| 1058 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1059 | CarrierRestrictionRules argument = |
| 1060 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1061 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1062 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1063 | break; |
| 1064 | |
| 1065 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1066 | ar = (AsyncResult) msg.obj; |
| 1067 | request = (MainThreadRequest) ar.userObj; |
| 1068 | if (ar.exception == null && ar.result != null) { |
| 1069 | request.result = ar.result; |
| 1070 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1071 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1072 | if (ar.exception instanceof CommandException) { |
| 1073 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1074 | CommandException.Error error = |
| 1075 | ((CommandException) (ar.exception)).getCommandError(); |
| 1076 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1077 | request.result = |
| 1078 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1079 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1080 | } else { |
| 1081 | loge("setAllowedCarriers: Unknown exception"); |
| 1082 | } |
| 1083 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1084 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1085 | break; |
| 1086 | |
| 1087 | case CMD_GET_ALLOWED_CARRIERS: |
| 1088 | request = (MainThreadRequest) msg.obj; |
| 1089 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1090 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1091 | break; |
| 1092 | |
| 1093 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1094 | ar = (AsyncResult) msg.obj; |
| 1095 | request = (MainThreadRequest) ar.userObj; |
| 1096 | if (ar.exception == null && ar.result != null) { |
| 1097 | request.result = ar.result; |
| 1098 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1099 | request.result = new IllegalStateException( |
| 1100 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1101 | if (ar.result == null) { |
| 1102 | loge("getAllowedCarriers: Empty response"); |
| 1103 | } else if (ar.exception instanceof CommandException) { |
| 1104 | loge("getAllowedCarriers: CommandException: " + |
| 1105 | ar.exception); |
| 1106 | } else { |
| 1107 | loge("getAllowedCarriers: Unknown exception"); |
| 1108 | } |
| 1109 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1110 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1111 | break; |
| 1112 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1113 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1114 | ar = (AsyncResult) msg.obj; |
| 1115 | request = (MainThreadRequest) ar.userObj; |
| 1116 | if (ar.exception == null && ar.result != null) { |
| 1117 | request.result = ar.result; |
| 1118 | } else { |
| 1119 | request.result = new IllegalArgumentException( |
| 1120 | "Failed to retrieve Forbidden Plmns"); |
| 1121 | if (ar.result == null) { |
| 1122 | loge("getForbiddenPlmns: Empty response"); |
| 1123 | } else { |
| 1124 | loge("getForbiddenPlmns: Unknown exception"); |
| 1125 | } |
| 1126 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1127 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1128 | break; |
| 1129 | |
| 1130 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1131 | request = (MainThreadRequest) msg.obj; |
| 1132 | uiccCard = getUiccCardFromRequest(request); |
| 1133 | if (uiccCard == null) { |
| 1134 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1135 | request.result = new IllegalArgumentException( |
| 1136 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1137 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1138 | break; |
| 1139 | } |
| 1140 | Integer appType = (Integer) request.argument; |
| 1141 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1142 | if (uiccApp == null) { |
| 1143 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1144 | + appType); |
| 1145 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1146 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1147 | break; |
| 1148 | } else { |
| 1149 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1150 | + " specified type -- " + appType); |
| 1151 | } |
| 1152 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1153 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1154 | onCompleted); |
| 1155 | break; |
| 1156 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1157 | case CMD_SWITCH_SLOTS: |
| 1158 | request = (MainThreadRequest) msg.obj; |
| 1159 | int[] physicalSlots = (int[]) request.argument; |
| 1160 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1161 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1162 | break; |
| 1163 | |
| 1164 | case EVENT_SWITCH_SLOTS_DONE: |
| 1165 | ar = (AsyncResult) msg.obj; |
| 1166 | request = (MainThreadRequest) ar.userObj; |
| 1167 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1168 | notifyRequester(request); |
| 1169 | break; |
| 1170 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1171 | request = (MainThreadRequest) msg.obj; |
| 1172 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1173 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1174 | break; |
| 1175 | |
| 1176 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1177 | ar = (AsyncResult) msg.obj; |
| 1178 | request = (MainThreadRequest) ar.userObj; |
| 1179 | if (ar.exception != null) { |
| 1180 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1181 | } else { |
| 1182 | int mode = ((int[]) ar.result)[0]; |
| 1183 | if (mode == 0) { |
| 1184 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1185 | } else { |
| 1186 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1187 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1188 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1189 | notifyRequester(request); |
| 1190 | break; |
| 1191 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1192 | request = (MainThreadRequest) msg.obj; |
| 1193 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1194 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1195 | break; |
| 1196 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1197 | ar = (AsyncResult) msg.obj; |
| 1198 | request = (MainThreadRequest) ar.userObj; |
| 1199 | if (ar.exception != null) { |
| 1200 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1201 | } else { |
| 1202 | request.result = ((int[]) ar.result)[0]; |
| 1203 | } |
| 1204 | notifyRequester(request); |
| 1205 | break; |
| 1206 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1207 | request = (MainThreadRequest) msg.obj; |
| 1208 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1209 | int mode = (int) request.argument; |
| 1210 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1211 | break; |
| 1212 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1213 | ar = (AsyncResult) msg.obj; |
| 1214 | request = (MainThreadRequest) ar.userObj; |
| 1215 | request.result = ar.exception == null; |
| 1216 | notifyRequester(request); |
| 1217 | break; |
| 1218 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1219 | request = (MainThreadRequest) msg.obj; |
| 1220 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1221 | int subscriptionMode = (int) request.argument; |
| 1222 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1223 | break; |
| 1224 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1225 | ar = (AsyncResult) msg.obj; |
| 1226 | request = (MainThreadRequest) ar.userObj; |
| 1227 | request.result = ar.exception == null; |
| 1228 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1229 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1230 | case CMD_GET_ALL_CELL_INFO: |
| 1231 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1232 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1233 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1234 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1235 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1236 | ar = (AsyncResult) msg.obj; |
| 1237 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1238 | // If a timeout occurs, the response will be null |
| 1239 | request.result = (ar.exception == null && ar.result != null) |
| 1240 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1241 | synchronized (request) { |
| 1242 | request.notifyAll(); |
| 1243 | } |
| 1244 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1245 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1246 | request = (MainThreadRequest) msg.obj; |
| 1247 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1248 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1249 | break; |
| 1250 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1251 | ar = (AsyncResult) msg.obj; |
| 1252 | request = (MainThreadRequest) ar.userObj; |
| 1253 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1254 | try { |
| 1255 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1256 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1257 | cb.onError( |
| 1258 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1259 | ar.exception.getClass().getName(), |
| 1260 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1261 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1262 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1263 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1264 | } else { |
| 1265 | // use the result as returned |
| 1266 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1267 | } |
| 1268 | } catch (RemoteException re) { |
| 1269 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1270 | } |
| 1271 | break; |
| 1272 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1273 | request = (MainThreadRequest) msg.obj; |
| 1274 | WorkSource ws = (WorkSource) request.argument; |
| 1275 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1276 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1277 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1278 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1279 | ar = (AsyncResult) msg.obj; |
| 1280 | request = (MainThreadRequest) ar.userObj; |
| 1281 | if (ar.exception == null) { |
| 1282 | request.result = ar.result; |
| 1283 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1284 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1285 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1286 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | synchronized (request) { |
| 1290 | request.notifyAll(); |
| 1291 | } |
| 1292 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1293 | case CMD_MODEM_REBOOT: |
| 1294 | request = (MainThreadRequest) msg.obj; |
| 1295 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1296 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1297 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1298 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1299 | handleNullReturnEvent(msg, "rebootModem"); |
| 1300 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1301 | case CMD_REQUEST_ENABLE_MODEM: |
| 1302 | request = (MainThreadRequest) msg.obj; |
| 1303 | boolean enable = (boolean) request.argument; |
| 1304 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1305 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1306 | PhoneConfigurationManager.getInstance() |
| 1307 | .enablePhone(request.phone, enable, onCompleted); |
| 1308 | break; |
| 1309 | case EVENT_ENABLE_MODEM_DONE: |
| 1310 | ar = (AsyncResult) msg.obj; |
| 1311 | request = (MainThreadRequest) ar.userObj; |
| 1312 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1313 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1314 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1315 | if ((boolean) request.result) { |
| 1316 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1317 | updateModemStateMetrics(); |
| 1318 | } else { |
| 1319 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1320 | + ar.exception); |
| 1321 | } |
| 1322 | notifyRequester(request); |
| 1323 | break; |
| 1324 | case CMD_GET_MODEM_STATUS: |
| 1325 | request = (MainThreadRequest) msg.obj; |
| 1326 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1327 | PhoneConfigurationManager.getInstance() |
| 1328 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1329 | break; |
| 1330 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1331 | ar = (AsyncResult) msg.obj; |
| 1332 | request = (MainThreadRequest) ar.userObj; |
| 1333 | int id = request.phone.getPhoneId(); |
| 1334 | if (ar.exception == null && ar.result != null) { |
| 1335 | request.result = ar.result; |
| 1336 | //update the cache as modem status has changed |
| 1337 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1338 | (boolean) request.result); |
| 1339 | } else { |
| 1340 | // Return true if modem status cannot be retrieved. For most cases, |
| 1341 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1342 | // and disable modem are not supported. Modem is always on. |
| 1343 | // TODO: this should be fixed in R to support a third |
| 1344 | // status UNKNOWN b/131631629 |
| 1345 | request.result = true; |
| 1346 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1347 | + ar.exception); |
| 1348 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1349 | notifyRequester(request); |
| 1350 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1351 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1352 | request = (MainThreadRequest) msg.obj; |
| 1353 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1354 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1355 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1356 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1357 | break; |
| 1358 | } |
| 1359 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1360 | ar = (AsyncResult) msg.obj; |
| 1361 | request = (MainThreadRequest) ar.userObj; |
| 1362 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1363 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1364 | args.second.accept(ar.exception == null); |
| 1365 | notifyRequester(request); |
| 1366 | break; |
| 1367 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1368 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1369 | ar = (AsyncResult) msg.obj; |
| 1370 | request = (MainThreadRequest) ar.userObj; |
| 1371 | if (ar.exception == null && ar.result != null) { |
| 1372 | request.result = ar.result; |
| 1373 | } else { |
| 1374 | request.result = -1; |
| 1375 | loge("Failed to set Forbidden Plmns"); |
| 1376 | if (ar.result == null) { |
| 1377 | loge("setForbidenPlmns: Empty response"); |
| 1378 | } else if (ar.exception != null) { |
| 1379 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1380 | request.result = -1; |
| 1381 | } else { |
| 1382 | loge("setForbiddenPlmns: Unknown exception"); |
| 1383 | } |
| 1384 | } |
| 1385 | notifyRequester(request); |
| 1386 | break; |
| 1387 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1388 | request = (MainThreadRequest) msg.obj; |
| 1389 | uiccCard = getUiccCardFromRequest(request); |
| 1390 | if (uiccCard == null) { |
| 1391 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1392 | request.result = -1; |
| 1393 | notifyRequester(request); |
| 1394 | break; |
| 1395 | } |
| 1396 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1397 | (Pair<Integer, List<String>>) request.argument; |
| 1398 | appType = setFplmnsArgs.first; |
| 1399 | List<String> fplmns = setFplmnsArgs.second; |
| 1400 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1401 | if (uiccApp == null) { |
| 1402 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1403 | request.result = -1; |
| 1404 | loge("Failed to get UICC App"); |
| 1405 | notifyRequester(request); |
| 1406 | } else { |
| 1407 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1408 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1409 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1410 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1411 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1412 | case CMD_ERASE_MODEM_CONFIG: |
| 1413 | request = (MainThreadRequest) msg.obj; |
| 1414 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1415 | defaultPhone.eraseModemConfig(onCompleted); |
| 1416 | break; |
| 1417 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1418 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1419 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1420 | |
| 1421 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1422 | request = (MainThreadRequest) msg.obj; |
| 1423 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1424 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1425 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1426 | changed.first, changed.second, onCompleted); |
| 1427 | break; |
| 1428 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1429 | ar = (AsyncResult) msg.obj; |
| 1430 | request = (MainThreadRequest) ar.userObj; |
| 1431 | if (ar.exception == null) { |
| 1432 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1433 | } else { |
| 1434 | request.result = msg.arg1; |
| 1435 | } |
| 1436 | notifyRequester(request); |
| 1437 | break; |
| 1438 | |
| 1439 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1440 | request = (MainThreadRequest) msg.obj; |
| 1441 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1442 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1443 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1444 | enabled.first, enabled.second, onCompleted); |
| 1445 | break; |
| 1446 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1447 | ar = (AsyncResult) msg.obj; |
| 1448 | request = (MainThreadRequest) ar.userObj; |
| 1449 | if (ar.exception == null) { |
| 1450 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1451 | } else { |
| 1452 | request.result = msg.arg1; |
| 1453 | } |
| 1454 | notifyRequester(request); |
| 1455 | break; |
| 1456 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1457 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1458 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
| 1459 | Intent intent = new Intent(ACTION_USER_ACTIVITY_NOTIFICATION); |
| 1460 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1461 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1462 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1463 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1464 | default: |
| 1465 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1466 | break; |
| 1467 | } |
| 1468 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1469 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1470 | private void notifyRequester(MainThreadRequest request) { |
| 1471 | synchronized (request) { |
| 1472 | request.notifyAll(); |
| 1473 | } |
| 1474 | } |
| 1475 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1476 | private void handleNullReturnEvent(Message msg, String command) { |
| 1477 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1478 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1479 | if (ar.exception == null) { |
| 1480 | request.result = true; |
| 1481 | } else { |
| 1482 | request.result = false; |
| 1483 | if (ar.exception instanceof CommandException) { |
| 1484 | loge(command + ": CommandException: " + ar.exception); |
| 1485 | } else { |
| 1486 | loge(command + ": Unknown exception"); |
| 1487 | } |
| 1488 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1489 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1490 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | /** |
| 1494 | * Posts the specified command to be executed on the main thread, |
| 1495 | * waits for the request to complete, and returns the result. |
| 1496 | * @see #sendRequestAsync |
| 1497 | */ |
| 1498 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1499 | return sendRequest( |
| 1500 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | /** |
| 1504 | * Posts the specified command to be executed on the main thread, |
| 1505 | * waits for the request to complete, and returns the result. |
| 1506 | * @see #sendRequestAsync |
| 1507 | */ |
| 1508 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1509 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1510 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | /** |
| 1514 | * Posts the specified command to be executed on the main thread, |
| 1515 | * waits for the request to complete, and returns the result. |
| 1516 | * @see #sendRequestAsync |
| 1517 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1518 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1519 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | /** |
| 1523 | * Posts the specified command to be executed on the main thread, |
| 1524 | * waits for the request to complete, and returns the result. |
| 1525 | * @see #sendRequestAsync |
| 1526 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1527 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1528 | return sendRequest(command, argument, subId, null, workSource); |
| 1529 | } |
| 1530 | |
| 1531 | /** |
| 1532 | * Posts the specified command to be executed on the main thread, |
| 1533 | * waits for the request to complete, and returns the result. |
| 1534 | * @see #sendRequestAsync |
| 1535 | */ |
| 1536 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1537 | return sendRequest( |
| 1538 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1539 | } |
| 1540 | |
| 1541 | /** |
| 1542 | * Posts the specified command to be executed on the main thread, |
| 1543 | * waits for the request to complete, and returns the result. |
| 1544 | * @see #sendRequestAsync |
| 1545 | */ |
| 1546 | private Object sendRequest( |
| 1547 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1548 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1549 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1550 | } |
| 1551 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1552 | MainThreadRequest request = null; |
| 1553 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1554 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1555 | } else if (phone != null) { |
| 1556 | request = new MainThreadRequest(argument, phone, workSource); |
| 1557 | } else { |
| 1558 | request = new MainThreadRequest(argument, subId, workSource); |
| 1559 | } |
| 1560 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1561 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1562 | msg.sendToTarget(); |
| 1563 | |
| 1564 | // Wait for the request to complete |
| 1565 | synchronized (request) { |
| 1566 | while (request.result == null) { |
| 1567 | try { |
| 1568 | request.wait(); |
| 1569 | } catch (InterruptedException e) { |
| 1570 | // Do nothing, go back and wait until the request is complete |
| 1571 | } |
| 1572 | } |
| 1573 | } |
| 1574 | return request.result; |
| 1575 | } |
| 1576 | |
| 1577 | /** |
| 1578 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1579 | * Posts the specified command to be executed on the main thread, and |
| 1580 | * returns immediately. |
| 1581 | * @see #sendRequest |
| 1582 | */ |
| 1583 | private void sendRequestAsync(int command) { |
| 1584 | mMainThreadHandler.sendEmptyMessage(command); |
| 1585 | } |
| 1586 | |
| 1587 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1588 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1589 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1590 | */ |
| 1591 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1592 | sendRequestAsync(command, argument, null, null); |
| 1593 | } |
| 1594 | |
| 1595 | /** |
| 1596 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1597 | * @see {@link #sendRequest(int,Object)} |
| 1598 | */ |
| 1599 | private void sendRequestAsync( |
| 1600 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1601 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1602 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1603 | msg.sendToTarget(); |
| 1604 | } |
| 1605 | |
| 1606 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1607 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1608 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1609 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1610 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1611 | synchronized (PhoneInterfaceManager.class) { |
| 1612 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1613 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1614 | } else { |
| 1615 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1616 | } |
| 1617 | return sInstance; |
| 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1622 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1623 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1624 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1625 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1626 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1627 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1628 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1629 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1630 | mTelephonySharedPreferences = |
| 1631 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1632 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1633 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1634 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1635 | publish(); |
| 1636 | } |
| 1637 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1638 | private Phone getDefaultPhone() { |
| 1639 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1640 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1641 | } |
| 1642 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1643 | private void publish() { |
| 1644 | if (DBG) log("publish: " + this); |
| 1645 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1646 | TelephonyFrameworkInitializer |
| 1647 | .getTelephonyServiceManager() |
| 1648 | .getTelephonyServiceRegisterer() |
| 1649 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1650 | } |
| 1651 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1652 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1653 | if (request.phone != null) { |
| 1654 | return request.phone; |
| 1655 | } else { |
| 1656 | return getPhoneFromSubId(request.subId); |
| 1657 | } |
| 1658 | } |
| 1659 | |
| 1660 | private Phone getPhoneFromSubId(int subId) { |
| 1661 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1662 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1663 | } |
| 1664 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1665 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1666 | Phone phone = getPhoneFromRequest(request); |
| 1667 | return phone == null ? null : |
| 1668 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1669 | } |
| 1670 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1671 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1672 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1673 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1674 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1675 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1676 | private void sendEraseModemConfig(Phone phone) { |
| 1677 | if (phone != null) { |
| 1678 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1679 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1680 | final long identity = Binder.clearCallingIdentity(); |
| 1681 | try { |
| 1682 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1683 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1684 | } finally { |
| 1685 | Binder.restoreCallingIdentity(identity); |
| 1686 | } |
| 1687 | } |
| 1688 | } |
| 1689 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1690 | private boolean isImsAvailableOnDevice() { |
| 1691 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1692 | if (pm == null) { |
| 1693 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1694 | // so do not throw error and allow. |
| 1695 | return true; |
| 1696 | } |
| 1697 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1698 | } |
| 1699 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1700 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1701 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1702 | } |
| 1703 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1704 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1705 | if (DBG) log("dial: " + number); |
| 1706 | // No permission check needed here: This is just a wrapper around the |
| 1707 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1708 | // the UI before it does anything. |
| 1709 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1710 | final long identity = Binder.clearCallingIdentity(); |
| 1711 | try { |
| 1712 | String url = createTelUrl(number); |
| 1713 | if (url == null) { |
| 1714 | return; |
| 1715 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1716 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1717 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1718 | PhoneConstants.State state = mCM.getState(subId); |
| 1719 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1720 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1721 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1722 | mApp.startActivity(intent); |
| 1723 | } |
| 1724 | } finally { |
| 1725 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1730 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1731 | } |
| 1732 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1733 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1734 | if (DBG) log("call: " + number); |
| 1735 | |
| 1736 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1737 | // need to do a permission check since we're calling startActivity() |
| 1738 | // from the context of the phone app. |
| 1739 | enforceCallPermission(); |
| 1740 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1741 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1742 | != AppOpsManager.MODE_ALLOWED) { |
| 1743 | return; |
| 1744 | } |
| 1745 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1746 | final long identity = Binder.clearCallingIdentity(); |
| 1747 | try { |
| 1748 | String url = createTelUrl(number); |
| 1749 | if (url == null) { |
| 1750 | return; |
| 1751 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1752 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1753 | boolean isValid = false; |
| 1754 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1755 | if (slist != null) { |
| 1756 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1757 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1758 | isValid = true; |
| 1759 | break; |
| 1760 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1761 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1762 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1763 | if (!isValid) { |
| 1764 | return; |
| 1765 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1766 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1767 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1768 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1769 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1770 | mApp.startActivity(intent); |
| 1771 | } finally { |
| 1772 | Binder.restoreCallingIdentity(identity); |
| 1773 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1776 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1777 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1778 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1779 | } |
| 1780 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1781 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1782 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1783 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1784 | } |
| 1785 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1786 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1787 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1788 | |
| 1789 | final long identity = Binder.clearCallingIdentity(); |
| 1790 | try { |
| 1791 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1792 | checkSimPin.start(); |
| 1793 | return checkSimPin.unlockSim(null, pin); |
| 1794 | } finally { |
| 1795 | Binder.restoreCallingIdentity(identity); |
| 1796 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1797 | } |
| 1798 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1799 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1800 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1801 | |
| 1802 | final long identity = Binder.clearCallingIdentity(); |
| 1803 | try { |
| 1804 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1805 | checkSimPuk.start(); |
| 1806 | return checkSimPuk.unlockSim(puk, pin); |
| 1807 | } finally { |
| 1808 | Binder.restoreCallingIdentity(identity); |
| 1809 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1813 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1814 | * a synchronous one. |
| 1815 | */ |
| 1816 | private static class UnlockSim extends Thread { |
| 1817 | |
| 1818 | private final IccCard mSimCard; |
| 1819 | |
| 1820 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1821 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1822 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1823 | |
| 1824 | // For replies from SimCard interface |
| 1825 | private Handler mHandler; |
| 1826 | |
| 1827 | // For async handler to identify request type |
| 1828 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1829 | |
| 1830 | public UnlockSim(IccCard simCard) { |
| 1831 | mSimCard = simCard; |
| 1832 | } |
| 1833 | |
| 1834 | @Override |
| 1835 | public void run() { |
| 1836 | Looper.prepare(); |
| 1837 | synchronized (UnlockSim.this) { |
| 1838 | mHandler = new Handler() { |
| 1839 | @Override |
| 1840 | public void handleMessage(Message msg) { |
| 1841 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1842 | switch (msg.what) { |
| 1843 | case SUPPLY_PIN_COMPLETE: |
| 1844 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1845 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1846 | mRetryCount = msg.arg1; |
| 1847 | if (ar.exception != null) { |
| 1848 | if (ar.exception instanceof CommandException && |
| 1849 | ((CommandException)(ar.exception)).getCommandError() |
| 1850 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1851 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1852 | } else { |
| 1853 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1854 | } |
| 1855 | } else { |
| 1856 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1857 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1858 | mDone = true; |
| 1859 | UnlockSim.this.notifyAll(); |
| 1860 | } |
| 1861 | break; |
| 1862 | } |
| 1863 | } |
| 1864 | }; |
| 1865 | UnlockSim.this.notifyAll(); |
| 1866 | } |
| 1867 | Looper.loop(); |
| 1868 | } |
| 1869 | |
| 1870 | /* |
| 1871 | * Use PIN or PUK to unlock SIM card |
| 1872 | * |
| 1873 | * If PUK is null, unlock SIM card with PIN |
| 1874 | * |
| 1875 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1876 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1877 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1878 | |
| 1879 | while (mHandler == null) { |
| 1880 | try { |
| 1881 | wait(); |
| 1882 | } catch (InterruptedException e) { |
| 1883 | Thread.currentThread().interrupt(); |
| 1884 | } |
| 1885 | } |
| 1886 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1887 | |
| 1888 | if (puk == null) { |
| 1889 | mSimCard.supplyPin(pin, callback); |
| 1890 | } else { |
| 1891 | mSimCard.supplyPuk(puk, pin, callback); |
| 1892 | } |
| 1893 | |
| 1894 | while (!mDone) { |
| 1895 | try { |
| 1896 | Log.d(LOG_TAG, "wait for done"); |
| 1897 | wait(); |
| 1898 | } catch (InterruptedException e) { |
| 1899 | // Restore the interrupted status |
| 1900 | Thread.currentThread().interrupt(); |
| 1901 | } |
| 1902 | } |
| 1903 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1904 | int[] resultArray = new int[2]; |
| 1905 | resultArray[0] = mResult; |
| 1906 | resultArray[1] = mRetryCount; |
| 1907 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1908 | } |
| 1909 | } |
| 1910 | |
| 1911 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1912 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1913 | |
| 1914 | } |
| 1915 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1916 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1917 | // No permission check needed here: this call is harmless, and it's |
| 1918 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1919 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1920 | final long identity = Binder.clearCallingIdentity(); |
| 1921 | try { |
| 1922 | final Phone phone = getPhone(subId); |
| 1923 | if (phone != null) { |
| 1924 | phone.updateServiceLocation(); |
| 1925 | } |
| 1926 | } finally { |
| 1927 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1928 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1929 | } |
| 1930 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1931 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1932 | @Override |
| 1933 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1934 | return isRadioOnWithFeature(callingPackage, null); |
| 1935 | } |
| 1936 | |
| 1937 | |
| 1938 | @Override |
| 1939 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1940 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1941 | callingFeatureId); |
| 1942 | } |
| 1943 | |
| 1944 | @Deprecated |
| 1945 | @Override |
| 1946 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 1947 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1950 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1951 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1952 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1953 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1954 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1955 | return false; |
| 1956 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1957 | |
| 1958 | final long identity = Binder.clearCallingIdentity(); |
| 1959 | try { |
| 1960 | return isRadioOnForSubscriber(subId); |
| 1961 | } finally { |
| 1962 | Binder.restoreCallingIdentity(identity); |
| 1963 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1967 | final long identity = Binder.clearCallingIdentity(); |
| 1968 | try { |
| 1969 | final Phone phone = getPhone(subId); |
| 1970 | if (phone != null) { |
| 1971 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1972 | } else { |
| 1973 | return false; |
| 1974 | } |
| 1975 | } finally { |
| 1976 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1977 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1981 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1982 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1983 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1984 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1985 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1986 | |
| 1987 | final long identity = Binder.clearCallingIdentity(); |
| 1988 | try { |
| 1989 | final Phone phone = getPhone(subId); |
| 1990 | if (phone != null) { |
| 1991 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1992 | } |
| 1993 | } finally { |
| 1994 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1995 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1999 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2000 | } |
| 2001 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2002 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2003 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2004 | |
| 2005 | final long identity = Binder.clearCallingIdentity(); |
| 2006 | try { |
| 2007 | final Phone phone = getPhone(subId); |
| 2008 | if (phone == null) { |
| 2009 | return false; |
| 2010 | } |
| 2011 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2012 | toggleRadioOnOffForSubscriber(subId); |
| 2013 | } |
| 2014 | return true; |
| 2015 | } finally { |
| 2016 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2017 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2018 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2019 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2020 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2021 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2022 | /* |
| 2023 | * If any of the Radios are available, it will need to be |
| 2024 | * shutdown. So return true if any Radio is available. |
| 2025 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2026 | final long identity = Binder.clearCallingIdentity(); |
| 2027 | try { |
| 2028 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2029 | Phone phone = PhoneFactory.getPhone(i); |
| 2030 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2031 | } |
| 2032 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2033 | return false; |
| 2034 | } finally { |
| 2035 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2036 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2037 | } |
| 2038 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2039 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2040 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2041 | enforceModifyPermission(); |
| 2042 | |
| 2043 | final long identity = Binder.clearCallingIdentity(); |
| 2044 | try { |
| 2045 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2046 | logv("Shutting down Phone " + i); |
| 2047 | shutdownRadioUsingPhoneId(i); |
| 2048 | } |
| 2049 | } finally { |
| 2050 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2055 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2056 | if (phone != null && phone.isRadioAvailable()) { |
| 2057 | phone.shutdownRadio(); |
| 2058 | } |
| 2059 | } |
| 2060 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2061 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2062 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2063 | |
| 2064 | final long identity = Binder.clearCallingIdentity(); |
| 2065 | try { |
| 2066 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2067 | if (defaultPhone != null) { |
| 2068 | defaultPhone.setRadioPower(turnOn); |
| 2069 | return true; |
| 2070 | } else { |
| 2071 | loge("There's no default phone."); |
| 2072 | return false; |
| 2073 | } |
| 2074 | } finally { |
| 2075 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2076 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2077 | } |
| 2078 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2079 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2080 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2081 | |
| 2082 | final long identity = Binder.clearCallingIdentity(); |
| 2083 | try { |
| 2084 | final Phone phone = getPhone(subId); |
| 2085 | if (phone != null) { |
| 2086 | phone.setRadioPower(turnOn); |
| 2087 | return true; |
| 2088 | } else { |
| 2089 | return false; |
| 2090 | } |
| 2091 | } finally { |
| 2092 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2093 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2094 | } |
| 2095 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2096 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2097 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2098 | public boolean enableDataConnectivity() { |
| 2099 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2100 | |
| 2101 | final long identity = Binder.clearCallingIdentity(); |
| 2102 | try { |
| 2103 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2104 | final Phone phone = getPhone(subId); |
| 2105 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2106 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2107 | return true; |
| 2108 | } else { |
| 2109 | return false; |
| 2110 | } |
| 2111 | } finally { |
| 2112 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2113 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2114 | } |
| 2115 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2116 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2117 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2118 | public boolean disableDataConnectivity() { |
| 2119 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2120 | |
| 2121 | final long identity = Binder.clearCallingIdentity(); |
| 2122 | try { |
| 2123 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2124 | final Phone phone = getPhone(subId); |
| 2125 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2126 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2127 | return true; |
| 2128 | } else { |
| 2129 | return false; |
| 2130 | } |
| 2131 | } finally { |
| 2132 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2133 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2134 | } |
| 2135 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2136 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2137 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2138 | final long identity = Binder.clearCallingIdentity(); |
| 2139 | try { |
| 2140 | final Phone phone = getPhone(subId); |
| 2141 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2142 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2143 | } else { |
| 2144 | return false; |
| 2145 | } |
| 2146 | } finally { |
| 2147 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2148 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2149 | } |
| 2150 | |
| 2151 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2152 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2153 | } |
| 2154 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2155 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2156 | enforceCallPermission(); |
| 2157 | |
| 2158 | final long identity = Binder.clearCallingIdentity(); |
| 2159 | try { |
| 2160 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2161 | return; |
| 2162 | } |
| 2163 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2164 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2165 | } finally { |
| 2166 | Binder.restoreCallingIdentity(identity); |
| 2167 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2168 | }; |
| 2169 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2170 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2171 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2172 | |
| 2173 | final long identity = Binder.clearCallingIdentity(); |
| 2174 | try { |
| 2175 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2176 | return false; |
| 2177 | } |
| 2178 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2179 | } finally { |
| 2180 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2181 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2182 | } |
| 2183 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2184 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2185 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2186 | } |
| 2187 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2188 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2189 | final long identity = Binder.clearCallingIdentity(); |
| 2190 | try { |
| 2191 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2192 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2193 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2194 | } finally { |
| 2195 | Binder.restoreCallingIdentity(identity); |
| 2196 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2197 | } |
| 2198 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2199 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2200 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2201 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2202 | } |
| 2203 | |
| 2204 | @Override |
| 2205 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2206 | final long identity = Binder.clearCallingIdentity(); |
| 2207 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2208 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2209 | if (phone != null) { |
| 2210 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2211 | } else { |
| 2212 | return PhoneConstantConversions.convertDataState( |
| 2213 | PhoneConstants.DataState.DISCONNECTED); |
| 2214 | } |
| 2215 | } finally { |
| 2216 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2217 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2218 | } |
| 2219 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2220 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2221 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2222 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2223 | } |
| 2224 | |
| 2225 | @Override |
| 2226 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2227 | final long identity = Binder.clearCallingIdentity(); |
| 2228 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2229 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2230 | if (phone != null) { |
| 2231 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2232 | } else { |
| 2233 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2234 | } |
| 2235 | } finally { |
| 2236 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2237 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2241 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2242 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2243 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2244 | |
| 2245 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2246 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2247 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2248 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2249 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2250 | .setCallingPid(Binder.getCallingPid()) |
| 2251 | .setCallingUid(Binder.getCallingUid()) |
| 2252 | .setMethod("getCellLocation") |
| 2253 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2254 | .build()); |
| 2255 | switch (locationResult) { |
| 2256 | case DENIED_HARD: |
| 2257 | throw new SecurityException("Not allowed to access cell location"); |
| 2258 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2259 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2260 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2263 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2264 | final long identity = Binder.clearCallingIdentity(); |
| 2265 | try { |
| 2266 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2267 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2268 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2269 | } finally { |
| 2270 | Binder.restoreCallingIdentity(identity); |
| 2271 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2272 | } |
| 2273 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2274 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2275 | public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage, |
| 2276 | String callingFeatureId) { |
Jack Yu | 1e81ccd | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2277 | if (!TextUtils.isEmpty(callingPackage)) { |
| 2278 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2279 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2280 | callingFeatureId, "getNetworkCountryIsoForPhone")) { |
Jack Yu | 1e81ccd | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2281 | return ""; |
| 2282 | } |
| 2283 | } |
| 2284 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2285 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2286 | // registered cell info, so return a NULL country instead. |
| 2287 | final long identity = Binder.clearCallingIdentity(); |
| 2288 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2289 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2290 | // Get default phone in this case. |
| 2291 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2292 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2293 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2294 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2295 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2296 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2297 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(), |
| 2298 | mApp.getFeatureId())) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2299 | return ""; |
| 2300 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2301 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2302 | if (phone != null) { |
| 2303 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2304 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2305 | if (sst != null) { |
| 2306 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2307 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2308 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2309 | return lt.getCurrentCountry(); |
| 2310 | } else if (emergencyNumberTracker != null) { |
| 2311 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2312 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2313 | } |
| 2314 | } |
| 2315 | } |
| 2316 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2317 | } finally { |
| 2318 | Binder.restoreCallingIdentity(identity); |
| 2319 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2323 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2324 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2325 | } |
| 2326 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2327 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2328 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2329 | mApp.enforceCallingOrSelfPermission( |
| 2330 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2331 | |
| 2332 | final long identity = Binder.clearCallingIdentity(); |
| 2333 | try { |
| 2334 | final Phone phone = getPhone(subId); |
| 2335 | if (phone != null) { |
| 2336 | phone.enableLocationUpdates(); |
| 2337 | } |
| 2338 | } finally { |
| 2339 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2340 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | @Override |
| 2344 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2345 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2346 | } |
| 2347 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2348 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2349 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2350 | mApp.enforceCallingOrSelfPermission( |
| 2351 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2352 | |
| 2353 | final long identity = Binder.clearCallingIdentity(); |
| 2354 | try { |
| 2355 | final Phone phone = getPhone(subId); |
| 2356 | if (phone != null) { |
| 2357 | phone.disableLocationUpdates(); |
| 2358 | } |
| 2359 | } finally { |
| 2360 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2361 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2364 | /** |
| 2365 | * Returns the target SDK version number for a given package name. |
| 2366 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2367 | * This call MUST be invoked before clearing the calling UID. |
| 2368 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2369 | * @return target SDK if the package is found or INT_MAX. |
| 2370 | */ |
| 2371 | private int getTargetSdk(String packageName) { |
| 2372 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2373 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2374 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2375 | if (ai != null) return ai.targetSdkVersion; |
| 2376 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2377 | loge("Failed to get package info for pkg=" |
| 2378 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2379 | } |
| 2380 | return Integer.MAX_VALUE; |
| 2381 | } |
| 2382 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2383 | @Override |
| 2384 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2385 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2386 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2387 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2388 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2389 | throw new SecurityException( |
| 2390 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2391 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2392 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2393 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2394 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2395 | return null; |
| 2396 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2397 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2398 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2399 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2400 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2401 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2402 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2403 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2404 | for (CellInfo ci : info) { |
| 2405 | if (ci instanceof CellInfoGsm) { |
| 2406 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2407 | } else if (ci instanceof CellInfoWcdma) { |
| 2408 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2409 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2410 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2411 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2412 | } |
| 2413 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2414 | private List<CellInfo> getCachedCellInfo() { |
| 2415 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2416 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2417 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2418 | if (info != null) cellInfos.addAll(info); |
| 2419 | } |
| 2420 | return cellInfos; |
| 2421 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2422 | |
| 2423 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2424 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2425 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2426 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2427 | |
| 2428 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2429 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2430 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2431 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2432 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2433 | .setCallingPid(Binder.getCallingPid()) |
| 2434 | .setCallingUid(Binder.getCallingUid()) |
| 2435 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2436 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2437 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2438 | .build()); |
| 2439 | switch (locationResult) { |
| 2440 | case DENIED_HARD: |
| 2441 | throw new SecurityException("Not allowed to access cell info"); |
| 2442 | case DENIED_SOFT: |
| 2443 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2444 | } |
| 2445 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2446 | final int targetSdk = getTargetSdk(callingPackage); |
| 2447 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2448 | return getCachedCellInfo(); |
| 2449 | } |
| 2450 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2451 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2452 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2453 | final long identity = Binder.clearCallingIdentity(); |
| 2454 | try { |
| 2455 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2456 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2457 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2458 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2459 | if (info != null) cellInfos.addAll(info); |
| 2460 | } |
| 2461 | return cellInfos; |
| 2462 | } finally { |
| 2463 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2464 | } |
| 2465 | } |
| 2466 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2467 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2468 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2469 | String callingFeatureId) { |
| 2470 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2471 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2472 | } |
| 2473 | |
| 2474 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2475 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2476 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2477 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2478 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2479 | } |
| 2480 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2481 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2482 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2483 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2484 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2485 | |
| 2486 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2487 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2488 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2489 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2490 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2491 | .setCallingPid(Binder.getCallingPid()) |
| 2492 | .setCallingUid(Binder.getCallingUid()) |
| 2493 | .setMethod("requestCellInfoUpdate") |
| 2494 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2495 | .build()); |
| 2496 | switch (locationResult) { |
| 2497 | case DENIED_HARD: |
| 2498 | throw new SecurityException("Not allowed to access cell info"); |
| 2499 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2500 | try { |
| 2501 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2502 | } catch (RemoteException re) { |
| 2503 | // Drop without consequences |
| 2504 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2505 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2506 | } |
| 2507 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2508 | |
| 2509 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2510 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2511 | |
| 2512 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2513 | } |
| 2514 | |
| 2515 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2516 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2517 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2518 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2519 | |
| 2520 | final long identity = Binder.clearCallingIdentity(); |
| 2521 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2522 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2523 | } finally { |
| 2524 | Binder.restoreCallingIdentity(identity); |
| 2525 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2526 | } |
| 2527 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2528 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2529 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2530 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2531 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2532 | return null; |
| 2533 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2534 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2535 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2536 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2537 | return null; |
| 2538 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2539 | |
| 2540 | final long identity = Binder.clearCallingIdentity(); |
| 2541 | try { |
| 2542 | return phone.getImei(); |
| 2543 | } finally { |
| 2544 | Binder.restoreCallingIdentity(identity); |
| 2545 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2546 | } |
| 2547 | |
| 2548 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2549 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2550 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2551 | String tac = null; |
| 2552 | if (phone != null) { |
| 2553 | String imei = phone.getImei(); |
| 2554 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2555 | } |
| 2556 | return tac; |
| 2557 | } |
| 2558 | |
| 2559 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2560 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2561 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2562 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2563 | return null; |
| 2564 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2565 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2566 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2567 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2568 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2569 | return null; |
| 2570 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2571 | |
| 2572 | final long identity = Binder.clearCallingIdentity(); |
| 2573 | try { |
| 2574 | return phone.getMeid(); |
| 2575 | } finally { |
| 2576 | Binder.restoreCallingIdentity(identity); |
| 2577 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2581 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2582 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2583 | String manufacturerCode = null; |
| 2584 | if (phone != null) { |
| 2585 | String meid = phone.getMeid(); |
| 2586 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2587 | } |
| 2588 | return manufacturerCode; |
| 2589 | } |
| 2590 | |
| 2591 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2592 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2593 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2594 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2595 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2596 | return null; |
| 2597 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2598 | int subId = phone.getSubId(); |
| 2599 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2600 | mApp, subId, callingPackage, callingFeatureId, |
| 2601 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2602 | return null; |
| 2603 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2604 | |
| 2605 | final long identity = Binder.clearCallingIdentity(); |
| 2606 | try { |
| 2607 | return phone.getDeviceSvn(); |
| 2608 | } finally { |
| 2609 | Binder.restoreCallingIdentity(identity); |
| 2610 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2611 | } |
| 2612 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2613 | @Override |
| 2614 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2615 | final long identity = Binder.clearCallingIdentity(); |
| 2616 | try { |
| 2617 | final Phone phone = getPhone(subId); |
| 2618 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2619 | } finally { |
| 2620 | Binder.restoreCallingIdentity(identity); |
| 2621 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | @Override |
| 2625 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2626 | final long identity = Binder.clearCallingIdentity(); |
| 2627 | try { |
| 2628 | final Phone phone = getPhone(subId); |
| 2629 | return phone == null ? null : phone.getCarrierName(); |
| 2630 | } finally { |
| 2631 | Binder.restoreCallingIdentity(identity); |
| 2632 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2633 | } |
| 2634 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2635 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2636 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2637 | final long identity = Binder.clearCallingIdentity(); |
| 2638 | try { |
| 2639 | final Phone phone = getPhone(subId); |
| 2640 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2641 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2642 | } finally { |
| 2643 | Binder.restoreCallingIdentity(identity); |
| 2644 | } |
| 2645 | } |
| 2646 | |
| 2647 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2648 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2649 | final long identity = Binder.clearCallingIdentity(); |
| 2650 | try { |
| 2651 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2652 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2653 | } finally { |
| 2654 | Binder.restoreCallingIdentity(identity); |
| 2655 | } |
| 2656 | } |
| 2657 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2658 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2659 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2660 | if (!isSubscriptionMccMnc) { |
| 2661 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2662 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2663 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2664 | if (phone == null) { |
| 2665 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2666 | } |
| 2667 | final long identity = Binder.clearCallingIdentity(); |
| 2668 | try { |
| 2669 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2670 | } finally { |
| 2671 | Binder.restoreCallingIdentity(identity); |
| 2672 | } |
| 2673 | } |
| 2674 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2675 | // |
| 2676 | // Internal helper methods. |
| 2677 | // |
| 2678 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2679 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2680 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2681 | * |
| 2682 | * @throws SecurityException if the caller does not have the required permission |
| 2683 | */ |
| 2684 | private void enforceModifyPermission() { |
| 2685 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2686 | } |
| 2687 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2688 | /** |
| 2689 | * Make sure the caller is system. |
| 2690 | * |
| 2691 | * @throws SecurityException if the caller is not system. |
| 2692 | */ |
| 2693 | private void enforceSystemCaller() { |
| 2694 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2695 | throw new SecurityException("Caller must be system"); |
| 2696 | } |
| 2697 | } |
| 2698 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2699 | private void enforceActiveEmergencySessionPermission() { |
| 2700 | mApp.enforceCallingOrSelfPermission( |
| 2701 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2702 | } |
| 2703 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2704 | /** |
| 2705 | * Make sure the caller has the CALL_PHONE permission. |
| 2706 | * |
| 2707 | * @throws SecurityException if the caller does not have the required permission |
| 2708 | */ |
| 2709 | private void enforceCallPermission() { |
| 2710 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2711 | } |
| 2712 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2713 | private void enforceSettingsPermission() { |
| 2714 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2715 | } |
| 2716 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2717 | private String createTelUrl(String number) { |
| 2718 | if (TextUtils.isEmpty(number)) { |
| 2719 | return null; |
| 2720 | } |
| 2721 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2722 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2723 | } |
| 2724 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2725 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2726 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2727 | } |
| 2728 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2729 | private static void logv(String msg) { |
| 2730 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2731 | } |
| 2732 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2733 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2734 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2735 | } |
| 2736 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2737 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2738 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2739 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2740 | } |
| 2741 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2742 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2743 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2744 | final long identity = Binder.clearCallingIdentity(); |
| 2745 | try { |
| 2746 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2747 | if (phone == null) { |
| 2748 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2749 | } else { |
| 2750 | return phone.getPhoneType(); |
| 2751 | } |
| 2752 | } finally { |
| 2753 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2754 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2755 | } |
| 2756 | |
| 2757 | /** |
| 2758 | * Returns the CDMA ERI icon index to display |
| 2759 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2760 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2761 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2762 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2763 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2764 | } |
| 2765 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2766 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2767 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2768 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2769 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2770 | mApp, subId, callingPackage, callingFeatureId, |
| 2771 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2772 | return -1; |
| 2773 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2774 | |
| 2775 | final long identity = Binder.clearCallingIdentity(); |
| 2776 | try { |
| 2777 | final Phone phone = getPhone(subId); |
| 2778 | if (phone != null) { |
| 2779 | return phone.getCdmaEriIconIndex(); |
| 2780 | } else { |
| 2781 | return -1; |
| 2782 | } |
| 2783 | } finally { |
| 2784 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2785 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | /** |
| 2789 | * Returns the CDMA ERI icon mode, |
| 2790 | * 0 - ON |
| 2791 | * 1 - FLASHING |
| 2792 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2793 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2794 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2795 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2796 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2797 | } |
| 2798 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2799 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2800 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2801 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2802 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2803 | mApp, subId, callingPackage, callingFeatureId, |
| 2804 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2805 | return -1; |
| 2806 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2807 | |
| 2808 | final long identity = Binder.clearCallingIdentity(); |
| 2809 | try { |
| 2810 | final Phone phone = getPhone(subId); |
| 2811 | if (phone != null) { |
| 2812 | return phone.getCdmaEriIconMode(); |
| 2813 | } else { |
| 2814 | return -1; |
| 2815 | } |
| 2816 | } finally { |
| 2817 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2818 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2819 | } |
| 2820 | |
| 2821 | /** |
| 2822 | * Returns the CDMA ERI text, |
| 2823 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2824 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2825 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2826 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2827 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2828 | } |
| 2829 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2830 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2831 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2832 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2833 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2834 | mApp, subId, callingPackage, callingFeatureId, |
| 2835 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2836 | return null; |
| 2837 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2838 | |
| 2839 | final long identity = Binder.clearCallingIdentity(); |
| 2840 | try { |
| 2841 | final Phone phone = getPhone(subId); |
| 2842 | if (phone != null) { |
| 2843 | return phone.getCdmaEriText(); |
| 2844 | } else { |
| 2845 | return null; |
| 2846 | } |
| 2847 | } finally { |
| 2848 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2849 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2850 | } |
| 2851 | |
| 2852 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2853 | * Returns the CDMA MDN. |
| 2854 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2855 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2856 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2857 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2858 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2859 | |
| 2860 | final long identity = Binder.clearCallingIdentity(); |
| 2861 | try { |
| 2862 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2863 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2864 | return phone.getLine1Number(); |
| 2865 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2866 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2867 | return null; |
| 2868 | } |
| 2869 | } finally { |
| 2870 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2871 | } |
| 2872 | } |
| 2873 | |
| 2874 | /** |
| 2875 | * Returns the CDMA MIN. |
| 2876 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2877 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2878 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2879 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2880 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2881 | |
| 2882 | final long identity = Binder.clearCallingIdentity(); |
| 2883 | try { |
| 2884 | final Phone phone = getPhone(subId); |
| 2885 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2886 | return phone.getCdmaMin(); |
| 2887 | } else { |
| 2888 | return null; |
| 2889 | } |
| 2890 | } finally { |
| 2891 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2892 | } |
| 2893 | } |
| 2894 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2895 | @Override |
| 2896 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2897 | INumberVerificationCallback callback, String callingPackage) { |
| 2898 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2899 | != PERMISSION_GRANTED) { |
| 2900 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2901 | } |
| 2902 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2903 | |
| 2904 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2905 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2906 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2907 | } |
| 2908 | |
| 2909 | if (range == null) { |
| 2910 | throw new NullPointerException("Range must be non-null"); |
| 2911 | } |
| 2912 | |
| 2913 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2914 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2915 | |
| 2916 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2917 | } |
| 2918 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2919 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2920 | * Returns true if CDMA provisioning needs to run. |
| 2921 | */ |
| 2922 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2923 | final long identity = Binder.clearCallingIdentity(); |
| 2924 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2925 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2926 | } finally { |
| 2927 | Binder.restoreCallingIdentity(identity); |
| 2928 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2932 | * Sets the voice mail number of a given subId. |
| 2933 | */ |
| 2934 | @Override |
| 2935 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2936 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2937 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2938 | |
| 2939 | final long identity = Binder.clearCallingIdentity(); |
| 2940 | try { |
| 2941 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2942 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2943 | return success; |
| 2944 | } finally { |
| 2945 | Binder.restoreCallingIdentity(identity); |
| 2946 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2947 | } |
| 2948 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2949 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2950 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2951 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2952 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2953 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2954 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2955 | throw new SecurityException("caller must be system dialer"); |
| 2956 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2957 | |
| 2958 | final long identity = Binder.clearCallingIdentity(); |
| 2959 | try { |
| 2960 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2961 | if (phoneAccountHandle == null) { |
| 2962 | return null; |
| 2963 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2964 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2965 | } finally { |
| 2966 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2967 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2971 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2972 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2973 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2974 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2975 | mApp, subId, callingPackage, callingFeatureId, |
| 2976 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2977 | return null; |
| 2978 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2979 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2980 | final long identity = Binder.clearCallingIdentity(); |
| 2981 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2982 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2983 | } finally { |
| 2984 | Binder.restoreCallingIdentity(identity); |
| 2985 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2989 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2990 | VisualVoicemailSmsFilterSettings settings) { |
| 2991 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2992 | |
| 2993 | final long identity = Binder.clearCallingIdentity(); |
| 2994 | try { |
| 2995 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2996 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2997 | } finally { |
| 2998 | Binder.restoreCallingIdentity(identity); |
| 2999 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3000 | } |
| 3001 | |
| 3002 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3003 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3004 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3005 | |
| 3006 | final long identity = Binder.clearCallingIdentity(); |
| 3007 | try { |
| 3008 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3009 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3010 | } finally { |
| 3011 | Binder.restoreCallingIdentity(identity); |
| 3012 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3016 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3017 | String callingPackage, int subId) { |
| 3018 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3019 | |
| 3020 | final long identity = Binder.clearCallingIdentity(); |
| 3021 | try { |
| 3022 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3023 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3024 | } finally { |
| 3025 | Binder.restoreCallingIdentity(identity); |
| 3026 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3027 | } |
| 3028 | |
| 3029 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3030 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3031 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3032 | |
| 3033 | final long identity = Binder.clearCallingIdentity(); |
| 3034 | try { |
| 3035 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3036 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3037 | } finally { |
| 3038 | Binder.restoreCallingIdentity(identity); |
| 3039 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | @Override |
| 3043 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 3044 | String number, int port, String text, PendingIntent sentIntent) { |
| 3045 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3046 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3047 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3048 | SmsController smsController = PhoneFactory.getSmsController(); |
| 3049 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 3050 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3051 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3052 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3053 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3054 | * Sets the voice activation state of a given subId. |
| 3055 | */ |
| 3056 | @Override |
| 3057 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3058 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3059 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3060 | |
| 3061 | final long identity = Binder.clearCallingIdentity(); |
| 3062 | try { |
| 3063 | final Phone phone = getPhone(subId); |
| 3064 | if (phone != null) { |
| 3065 | phone.setVoiceActivationState(activationState); |
| 3066 | } else { |
| 3067 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3068 | } |
| 3069 | } finally { |
| 3070 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3071 | } |
| 3072 | } |
| 3073 | |
| 3074 | /** |
| 3075 | * Sets the data activation state of a given subId. |
| 3076 | */ |
| 3077 | @Override |
| 3078 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3079 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3080 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3081 | |
| 3082 | final long identity = Binder.clearCallingIdentity(); |
| 3083 | try { |
| 3084 | final Phone phone = getPhone(subId); |
| 3085 | if (phone != null) { |
| 3086 | phone.setDataActivationState(activationState); |
| 3087 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3088 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3089 | } |
| 3090 | } finally { |
| 3091 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3092 | } |
| 3093 | } |
| 3094 | |
| 3095 | /** |
| 3096 | * Returns the voice activation state of a given subId. |
| 3097 | */ |
| 3098 | @Override |
| 3099 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3100 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3101 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3102 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3103 | final long identity = Binder.clearCallingIdentity(); |
| 3104 | try { |
| 3105 | if (phone != null) { |
| 3106 | return phone.getVoiceActivationState(); |
| 3107 | } else { |
| 3108 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3109 | } |
| 3110 | } finally { |
| 3111 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3112 | } |
| 3113 | } |
| 3114 | |
| 3115 | /** |
| 3116 | * Returns the data activation state of a given subId. |
| 3117 | */ |
| 3118 | @Override |
| 3119 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3120 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3121 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3122 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3123 | final long identity = Binder.clearCallingIdentity(); |
| 3124 | try { |
| 3125 | if (phone != null) { |
| 3126 | return phone.getDataActivationState(); |
| 3127 | } else { |
| 3128 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3129 | } |
| 3130 | } finally { |
| 3131 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3132 | } |
| 3133 | } |
| 3134 | |
| 3135 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3136 | * Returns the unread count of voicemails for a subId |
| 3137 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3138 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3139 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3140 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3141 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3142 | mApp, subId, callingPackage, callingFeatureId, |
| 3143 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3144 | return 0; |
| 3145 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3146 | final long identity = Binder.clearCallingIdentity(); |
| 3147 | try { |
| 3148 | final Phone phone = getPhone(subId); |
| 3149 | if (phone != null) { |
| 3150 | return phone.getVoiceMessageCount(); |
| 3151 | } else { |
| 3152 | return 0; |
| 3153 | } |
| 3154 | } finally { |
| 3155 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3156 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3157 | } |
| 3158 | |
| 3159 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3160 | * returns true, if the device is in a state where both voice and data |
| 3161 | * are supported simultaneously. This can change based on location or network condition. |
| 3162 | */ |
| 3163 | @Override |
| 3164 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3165 | final long identity = Binder.clearCallingIdentity(); |
| 3166 | try { |
| 3167 | final Phone phone = getPhone(subId); |
| 3168 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3169 | } finally { |
| 3170 | Binder.restoreCallingIdentity(identity); |
| 3171 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3172 | } |
| 3173 | |
| 3174 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3175 | * Send the dialer code if called from the current default dialer or the caller has |
| 3176 | * carrier privilege. |
| 3177 | * @param inputCode The dialer code to send |
| 3178 | */ |
| 3179 | @Override |
| 3180 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3181 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3182 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3183 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3184 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3185 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3186 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3187 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3188 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3189 | |
| 3190 | final long identity = Binder.clearCallingIdentity(); |
| 3191 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3192 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3193 | } finally { |
| 3194 | Binder.restoreCallingIdentity(identity); |
| 3195 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3196 | } |
| 3197 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3198 | @Override |
| 3199 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3200 | TelephonyPermissions |
| 3201 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3202 | mApp, subId, "getNetworkSelectionMode"); |
| 3203 | final long identity = Binder.clearCallingIdentity(); |
| 3204 | try { |
| 3205 | if (!isActiveSubscription(subId)) { |
| 3206 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3207 | } |
| 3208 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3209 | } finally { |
| 3210 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3211 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3212 | } |
| 3213 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3214 | @Override |
Sarah Chin | 0605abf | 2019-12-06 10:24:18 -0800 | [diff] [blame] | 3215 | public PhoneCapability getPhoneCapability(int subId, String callingPackage, |
| 3216 | String callingFeatureId) { |
| 3217 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3218 | mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) { |
| 3219 | return null; |
| 3220 | } |
| 3221 | final long identity = Binder.clearCallingIdentity(); |
| 3222 | try { |
| 3223 | return mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 3224 | } finally { |
| 3225 | Binder.restoreCallingIdentity(identity); |
| 3226 | } |
| 3227 | } |
| 3228 | |
| 3229 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3230 | public boolean isInEmergencySmsMode() { |
| 3231 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3232 | final long identity = Binder.clearCallingIdentity(); |
| 3233 | try { |
| 3234 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3235 | if (phone.isInEmergencySmsMode()) { |
| 3236 | return true; |
| 3237 | } |
| 3238 | } |
| 3239 | } finally { |
| 3240 | Binder.restoreCallingIdentity(identity); |
| 3241 | } |
| 3242 | return false; |
| 3243 | } |
| 3244 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3245 | /** |
| 3246 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3247 | * @param subId The subscription to use to check the configuration. |
| 3248 | * @param c The callback that will be used to send the result. |
| 3249 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3250 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3251 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3252 | throws RemoteException { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3253 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3254 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3255 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3256 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3257 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3258 | "IMS not available on device."); |
| 3259 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3260 | final long token = Binder.clearCallingIdentity(); |
| 3261 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3262 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3263 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3264 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3265 | } catch (ImsException e) { |
| 3266 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3267 | } finally { |
| 3268 | Binder.restoreCallingIdentity(token); |
| 3269 | } |
| 3270 | } |
| 3271 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3272 | /** |
| 3273 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3274 | * @param subId The subscription to use to check the configuration. |
| 3275 | * @param c The callback that will be used to send the result. |
| 3276 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3277 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3278 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3279 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3280 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3281 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3282 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3283 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3284 | final long token = Binder.clearCallingIdentity(); |
| 3285 | try { |
| 3286 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3287 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3288 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3289 | } catch (ImsException e) { |
| 3290 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3291 | + "is inactive, ignoring unregister."); |
| 3292 | // If the subscription is no longer active, just return, since the callback |
| 3293 | // will already have been removed internally. |
| 3294 | } finally { |
| 3295 | Binder.restoreCallingIdentity(token); |
| 3296 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3297 | } |
| 3298 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3299 | /** |
| 3300 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3301 | */ |
| 3302 | @Override |
| 3303 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3304 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3305 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3306 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3307 | "IMS not available on device."); |
| 3308 | } |
| 3309 | final long token = Binder.clearCallingIdentity(); |
| 3310 | try { |
| 3311 | Phone phone = getPhone(subId); |
| 3312 | if (phone == null) { |
| 3313 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3314 | + subId + "'"); |
| 3315 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3316 | } |
| 3317 | phone.getImsRegistrationState(regState -> { |
| 3318 | try { |
| 3319 | consumer.accept((regState == null) |
| 3320 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3321 | } catch (RemoteException e) { |
| 3322 | // Ignore if the remote process is no longer available to call back. |
| 3323 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3324 | } |
| 3325 | }); |
| 3326 | } finally { |
| 3327 | Binder.restoreCallingIdentity(token); |
| 3328 | } |
| 3329 | } |
| 3330 | |
| 3331 | /** |
| 3332 | * Get the transport type for the IMS service registration state. |
| 3333 | */ |
| 3334 | @Override |
| 3335 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3336 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3337 | enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType"); |
| 3338 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3339 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3340 | "IMS not available on device."); |
| 3341 | } |
| 3342 | final long token = Binder.clearCallingIdentity(); |
| 3343 | try { |
| 3344 | Phone phone = getPhone(subId); |
| 3345 | if (phone == null) { |
| 3346 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3347 | + subId + "'"); |
| 3348 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3349 | } |
| 3350 | phone.getImsRegistrationTech(regTech -> { |
| 3351 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3352 | int regTechConverted = (regTech == null) |
| 3353 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3354 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3355 | regTechConverted); |
| 3356 | try { |
| 3357 | consumer.accept(regTechConverted); |
| 3358 | } catch (RemoteException e) { |
| 3359 | // Ignore if the remote process is no longer available to call back. |
| 3360 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3361 | } |
| 3362 | }); |
| 3363 | } finally { |
| 3364 | Binder.restoreCallingIdentity(token); |
| 3365 | } |
| 3366 | } |
| 3367 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3368 | /** |
| 3369 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3370 | * @param subId The subscription to use to check the configuration. |
| 3371 | * @param c The callback that will be used to send the result. |
| 3372 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3373 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3374 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3375 | throws RemoteException { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3376 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3377 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3378 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3379 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3380 | "IMS not available on device."); |
| 3381 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3382 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3383 | final long token = Binder.clearCallingIdentity(); |
| 3384 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3385 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3386 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3387 | } catch (ImsException e) { |
| 3388 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3389 | } finally { |
| 3390 | Binder.restoreCallingIdentity(token); |
| 3391 | } |
| 3392 | } |
| 3393 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3394 | /** |
| 3395 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3396 | * @param subId The subscription to use to check the configuration. |
| 3397 | * @param c The callback that will be used to send the result. |
| 3398 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3399 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3400 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3401 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3402 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3403 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3404 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3405 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3406 | |
| 3407 | final long token = Binder.clearCallingIdentity(); |
| 3408 | try { |
| 3409 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3410 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3411 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3412 | } catch (ImsException e) { |
| 3413 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3414 | + "is inactive, ignoring unregister."); |
| 3415 | // If the subscription is no longer active, just return, since the callback |
| 3416 | // will already have been removed internally. |
| 3417 | } finally { |
| 3418 | Binder.restoreCallingIdentity(token); |
| 3419 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3420 | } |
| 3421 | |
| 3422 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3423 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3424 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3425 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3426 | final long token = Binder.clearCallingIdentity(); |
| 3427 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3428 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3429 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3430 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3431 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3432 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3433 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3434 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3435 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3436 | } finally { |
| 3437 | Binder.restoreCallingIdentity(token); |
| 3438 | } |
| 3439 | } |
| 3440 | |
| 3441 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3442 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3443 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3444 | final long token = Binder.clearCallingIdentity(); |
| 3445 | try { |
| 3446 | Phone phone = getPhone(subId); |
| 3447 | if (phone == null) return false; |
| 3448 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3449 | } finally { |
| 3450 | Binder.restoreCallingIdentity(token); |
| 3451 | } |
| 3452 | } |
| 3453 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3454 | /** |
| 3455 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3456 | * subscription. |
| 3457 | * @param subId The subscription to use to check the configuration. |
| 3458 | * @param callback The callback that will be used to send the result. |
| 3459 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3460 | * @param transportType The transport type of the MmTelFeature capability. |
| 3461 | */ |
| 3462 | @Override |
| 3463 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3464 | int transportType) { |
| 3465 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3466 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3467 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3468 | "IMS not available on device."); |
| 3469 | } |
| 3470 | final long token = Binder.clearCallingIdentity(); |
| 3471 | try { |
| 3472 | int slotId = getSlotIndex(subId); |
| 3473 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3474 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3475 | + subId + "'"); |
| 3476 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3477 | } |
| 3478 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3479 | transportType, aBoolean -> { |
| 3480 | try { |
| 3481 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3482 | } catch (RemoteException e) { |
| 3483 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3484 | + "running. Ignore"); |
| 3485 | } |
| 3486 | }); |
| 3487 | } finally { |
| 3488 | Binder.restoreCallingIdentity(token); |
| 3489 | } |
| 3490 | } |
| 3491 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3492 | /** |
| 3493 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3494 | * @param subId The subscription to use to check the configuration. |
| 3495 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3496 | @Override |
| 3497 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3498 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
| 3499 | enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled"); |
| 3500 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3501 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3502 | final long token = Binder.clearCallingIdentity(); |
| 3503 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3504 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3505 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3506 | } catch (ImsException e) { |
| 3507 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3508 | } finally { |
| 3509 | Binder.restoreCallingIdentity(token); |
| 3510 | } |
| 3511 | } |
| 3512 | |
| 3513 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3514 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3515 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3516 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3517 | final long identity = Binder.clearCallingIdentity(); |
| 3518 | try { |
| 3519 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3520 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3521 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3522 | } catch (ImsException e) { |
| 3523 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3524 | } finally { |
| 3525 | Binder.restoreCallingIdentity(identity); |
| 3526 | } |
| 3527 | } |
| 3528 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3529 | /** |
| 3530 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3531 | * @param subId The subscription to use to check the configuration. |
| 3532 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3533 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3534 | public boolean isVtSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3535 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3536 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3537 | final long identity = Binder.clearCallingIdentity(); |
| 3538 | try { |
| 3539 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3540 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3541 | } catch (ImsException e) { |
| 3542 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3543 | } finally { |
| 3544 | Binder.restoreCallingIdentity(identity); |
| 3545 | } |
| 3546 | } |
| 3547 | |
| 3548 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3549 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3550 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3551 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3552 | final long identity = Binder.clearCallingIdentity(); |
| 3553 | try { |
| 3554 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3555 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3556 | } catch (ImsException e) { |
| 3557 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3558 | } finally { |
| 3559 | Binder.restoreCallingIdentity(identity); |
| 3560 | } |
| 3561 | } |
| 3562 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3563 | /** |
| 3564 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3565 | * @param subId The subscription to use to check the configuration. |
| 3566 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3567 | @Override |
| 3568 | public boolean isVoWiFiSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3569 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3570 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3571 | final long identity = Binder.clearCallingIdentity(); |
| 3572 | try { |
| 3573 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3574 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3575 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3576 | } catch (ImsException e) { |
| 3577 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3578 | } finally { |
| 3579 | Binder.restoreCallingIdentity(identity); |
| 3580 | } |
| 3581 | } |
| 3582 | |
| 3583 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3584 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3585 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3586 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3587 | final long identity = Binder.clearCallingIdentity(); |
| 3588 | try { |
| 3589 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3590 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3591 | } catch (ImsException e) { |
| 3592 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3593 | } finally { |
| 3594 | Binder.restoreCallingIdentity(identity); |
| 3595 | } |
| 3596 | } |
| 3597 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3598 | /** |
| 3599 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3600 | * @param subId The subscription to use to check the configuration. |
| 3601 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3602 | @Override |
| 3603 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3604 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3605 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3606 | final long identity = Binder.clearCallingIdentity(); |
| 3607 | try { |
| 3608 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3609 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3610 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3611 | } catch (ImsException e) { |
| 3612 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3613 | } finally { |
| 3614 | Binder.restoreCallingIdentity(identity); |
| 3615 | } |
| 3616 | } |
| 3617 | |
| 3618 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3619 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3620 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3621 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3622 | final long identity = Binder.clearCallingIdentity(); |
| 3623 | try { |
| 3624 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3625 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3626 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3627 | } catch (ImsException e) { |
| 3628 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3629 | } finally { |
| 3630 | Binder.restoreCallingIdentity(identity); |
| 3631 | } |
| 3632 | } |
| 3633 | |
| 3634 | @Override |
| 3635 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3636 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3637 | "setVoWiFiNonPersistent"); |
| 3638 | final long identity = Binder.clearCallingIdentity(); |
| 3639 | try { |
| 3640 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3641 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3642 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3643 | } catch (ImsException e) { |
| 3644 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3645 | } finally { |
| 3646 | Binder.restoreCallingIdentity(identity); |
| 3647 | } |
| 3648 | } |
| 3649 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3650 | /** |
| 3651 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3652 | * @param subId The subscription to use to check the configuration. |
| 3653 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3654 | @Override |
| 3655 | public int getVoWiFiModeSetting(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3656 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3657 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3658 | final long identity = Binder.clearCallingIdentity(); |
| 3659 | try { |
| 3660 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3661 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3662 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3663 | } catch (ImsException e) { |
| 3664 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3665 | } finally { |
| 3666 | Binder.restoreCallingIdentity(identity); |
| 3667 | } |
| 3668 | } |
| 3669 | |
| 3670 | @Override |
| 3671 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3672 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3673 | "setVoWiFiModeSetting"); |
| 3674 | final long identity = Binder.clearCallingIdentity(); |
| 3675 | try { |
| 3676 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3677 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3678 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3679 | } catch (ImsException e) { |
| 3680 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3681 | } finally { |
| 3682 | Binder.restoreCallingIdentity(identity); |
| 3683 | } |
| 3684 | } |
| 3685 | |
| 3686 | @Override |
| 3687 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3688 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3689 | final long identity = Binder.clearCallingIdentity(); |
| 3690 | try { |
| 3691 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3692 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3693 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3694 | } catch (ImsException e) { |
| 3695 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3696 | } finally { |
| 3697 | Binder.restoreCallingIdentity(identity); |
| 3698 | } |
| 3699 | } |
| 3700 | |
| 3701 | @Override |
| 3702 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3703 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3704 | "setVoWiFiRoamingModeSetting"); |
| 3705 | final long identity = Binder.clearCallingIdentity(); |
| 3706 | try { |
| 3707 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3708 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3709 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3710 | } catch (ImsException e) { |
| 3711 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3712 | } finally { |
| 3713 | Binder.restoreCallingIdentity(identity); |
| 3714 | } |
| 3715 | } |
| 3716 | |
| 3717 | @Override |
| 3718 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3719 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3720 | "setRttCapabilityEnabled"); |
| 3721 | final long identity = Binder.clearCallingIdentity(); |
| 3722 | try { |
| 3723 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3724 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3725 | } catch (ImsException e) { |
| 3726 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3727 | } finally { |
| 3728 | Binder.restoreCallingIdentity(identity); |
| 3729 | } |
| 3730 | } |
| 3731 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3732 | /** |
| 3733 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3734 | * @param subId The subscription to use to check the configuration. |
| 3735 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3736 | @Override |
| 3737 | public boolean isTtyOverVolteEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3738 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3739 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3740 | final long identity = Binder.clearCallingIdentity(); |
| 3741 | try { |
| 3742 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3743 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3744 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3745 | } catch (ImsException e) { |
| 3746 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3747 | } finally { |
| 3748 | Binder.restoreCallingIdentity(identity); |
| 3749 | } |
| 3750 | } |
| 3751 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3752 | @Override |
| 3753 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3754 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3755 | final long identity = Binder.clearCallingIdentity(); |
| 3756 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3757 | if (!isImsAvailableOnDevice()) { |
| 3758 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3759 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3760 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3761 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3762 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3763 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3764 | } catch (ImsException e) { |
| 3765 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3766 | } finally { |
| 3767 | Binder.restoreCallingIdentity(identity); |
| 3768 | } |
| 3769 | } |
| 3770 | |
| 3771 | @Override |
| 3772 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3773 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3774 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3775 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3776 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3777 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3778 | try { |
| 3779 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3780 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3781 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3782 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3783 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3784 | + "is inactive, ignoring unregister."); |
| 3785 | // If the subscription is no longer active, just return, since the callback will already |
| 3786 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3787 | } finally { |
| 3788 | Binder.restoreCallingIdentity(identity); |
| 3789 | } |
| 3790 | } |
| 3791 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3792 | |
| 3793 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3794 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3795 | message); |
| 3796 | } |
| 3797 | |
| 3798 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3799 | boolean isMmtelCapability) { |
| 3800 | Phone phone = getPhone(subId); |
| 3801 | if (phone == null) { |
| 3802 | loge("phone instance null for subid " + subId); |
| 3803 | return false; |
| 3804 | } |
| 3805 | if (isMmtelCapability) { |
| 3806 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3807 | return false; |
| 3808 | } |
| 3809 | } else { |
| 3810 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3811 | return false; |
| 3812 | } |
| 3813 | } |
| 3814 | return true; |
| 3815 | } |
| 3816 | |
| 3817 | @Override |
| 3818 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3819 | boolean isProvisioned) { |
| 3820 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3821 | |
| 3822 | final long identity = Binder.clearCallingIdentity(); |
| 3823 | try { |
| 3824 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3825 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3826 | return; |
| 3827 | } |
| 3828 | |
| 3829 | // this capability requires provisioning, route to the correct API. |
| 3830 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3831 | switch (capability) { |
| 3832 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3833 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3834 | ims.setEabProvisioned(isProvisioned); |
| 3835 | break; |
| 3836 | default: { |
| 3837 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3838 | + "rcs capability '" + capability + "', which does not require " |
| 3839 | + "provisioning."); |
| 3840 | } |
| 3841 | } |
| 3842 | } finally { |
| 3843 | Binder.restoreCallingIdentity(identity); |
| 3844 | } |
| 3845 | |
| 3846 | } |
| 3847 | |
| 3848 | |
| 3849 | @Override |
| 3850 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3851 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3852 | final long identity = Binder.clearCallingIdentity(); |
| 3853 | try { |
| 3854 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3855 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3856 | return true; |
| 3857 | } |
| 3858 | |
| 3859 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3860 | switch (capability) { |
| 3861 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3862 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3863 | return ims.isEabProvisionedOnDevice(); |
| 3864 | |
| 3865 | default: { |
| 3866 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3867 | + "capability '" + capability + "', which does not require " |
| 3868 | + "provisioning."); |
| 3869 | } |
| 3870 | } |
| 3871 | |
| 3872 | } finally { |
| 3873 | Binder.restoreCallingIdentity(identity); |
| 3874 | } |
| 3875 | } |
| 3876 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3877 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3878 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3879 | boolean isProvisioned) { |
| 3880 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3881 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3882 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3883 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3884 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3885 | final long identity = Binder.clearCallingIdentity(); |
| 3886 | try { |
| 3887 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3888 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3889 | return; |
| 3890 | } |
| 3891 | |
| 3892 | // this capability requires provisioning, route to the correct API. |
| 3893 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3894 | switch (capability) { |
| 3895 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3896 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3897 | ims.setVolteProvisioned(isProvisioned); |
| 3898 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3899 | ims.setWfcProvisioned(isProvisioned); |
| 3900 | } |
| 3901 | break; |
| 3902 | } |
| 3903 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3904 | // There is currently no difference in VT provisioning type. |
| 3905 | ims.setVtProvisioned(isProvisioned); |
| 3906 | break; |
| 3907 | } |
| 3908 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3909 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3910 | // change the capability of the feature instead if needed. |
| 3911 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3912 | == isProvisioned) { |
| 3913 | // No change in provisioning. |
| 3914 | return; |
| 3915 | } |
| 3916 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3917 | try { |
| 3918 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3919 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3920 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3921 | + ", Exception" + e.getMessage()); |
| 3922 | } |
| 3923 | break; |
| 3924 | } |
| 3925 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3926 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3927 | + "MmTel capability '" + capability + "', which does not require " |
| 3928 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3929 | } |
| 3930 | } |
| 3931 | |
| 3932 | } finally { |
| 3933 | Binder.restoreCallingIdentity(identity); |
| 3934 | } |
| 3935 | } |
| 3936 | |
| 3937 | @Override |
| 3938 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3939 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3940 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3941 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3942 | } |
| 3943 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3944 | final long identity = Binder.clearCallingIdentity(); |
| 3945 | try { |
| 3946 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3947 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3948 | return true; |
| 3949 | } |
| 3950 | |
| 3951 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3952 | switch (capability) { |
| 3953 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3954 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3955 | return ims.isVolteProvisionedOnDevice(); |
| 3956 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3957 | return ims.isWfcProvisionedOnDevice(); |
| 3958 | } |
| 3959 | // This should never happen, since we are checking tech above to make sure it |
| 3960 | // is either LTE or IWLAN. |
| 3961 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3962 | + "capability."); |
| 3963 | } |
| 3964 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3965 | // There is currently no difference in VT provisioning type. |
| 3966 | return ims.isVtProvisionedOnDevice(); |
| 3967 | } |
| 3968 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3969 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3970 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3971 | } |
| 3972 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3973 | throw new IllegalArgumentException( |
| 3974 | "Tried to get provisioning for MmTel capability '" + capability |
| 3975 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3976 | } |
| 3977 | } |
| 3978 | |
| 3979 | } finally { |
| 3980 | Binder.restoreCallingIdentity(identity); |
| 3981 | } |
| 3982 | } |
| 3983 | |
| 3984 | @Override |
| 3985 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3986 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3987 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3988 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3989 | } |
| 3990 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3991 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3992 | return (provisionedBits & capability) > 0; |
| 3993 | } |
| 3994 | |
| 3995 | @Override |
| 3996 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3997 | boolean isProvisioned) { |
| 3998 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3999 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4000 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4001 | } |
| 4002 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4003 | "setProvisioningStatusForCapability"); |
| 4004 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4005 | // If the current provisioning status for capability already matches isProvisioned, |
| 4006 | // do nothing. |
| 4007 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4008 | return; |
| 4009 | } |
| 4010 | if (isProvisioned) { |
| 4011 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4012 | } else { |
| 4013 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4014 | } |
| 4015 | } |
| 4016 | |
| 4017 | /** |
| 4018 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4019 | * technology. The bitfield should mirror the bitfield defined by |
| 4020 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4021 | */ |
| 4022 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4023 | String key = getMmTelProvisioningKey(subId, tech); |
| 4024 | // Default is no capabilities are provisioned. |
| 4025 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4026 | } |
| 4027 | |
| 4028 | /** |
| 4029 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4030 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4031 | * technology specified. |
| 4032 | * |
| 4033 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4034 | */ |
| 4035 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4036 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4037 | String key = getMmTelProvisioningKey(subId, tech); |
| 4038 | editor.putInt(key, newField); |
| 4039 | editor.commit(); |
| 4040 | } |
| 4041 | |
| 4042 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4043 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4044 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4045 | } |
| 4046 | |
| 4047 | /** |
| 4048 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4049 | * carrier associated with the subscription id. |
| 4050 | */ |
| 4051 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4052 | int capability) { |
| 4053 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4054 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4055 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4056 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4057 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4058 | false); |
| 4059 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4060 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4061 | |
| 4062 | // First check to make sure that the capability requires provisioning. |
| 4063 | switch (capability) { |
| 4064 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4065 | // intentional fallthrough |
| 4066 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4067 | if (requireVoiceVtProvisioning) { |
| 4068 | // Voice and Video requires provisioning |
| 4069 | return true; |
| 4070 | } |
| 4071 | break; |
| 4072 | } |
| 4073 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4074 | if (requireUtProvisioning) { |
| 4075 | // UT requires provisioning |
| 4076 | return true; |
| 4077 | } |
| 4078 | break; |
| 4079 | } |
| 4080 | } |
| 4081 | return false; |
| 4082 | } |
| 4083 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4084 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4085 | int capability) { |
| 4086 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4087 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4088 | |
| 4089 | boolean requireRcsProvisioning = c.getBoolean( |
| 4090 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4091 | |
| 4092 | // First check to make sure that the capability requires provisioning. |
| 4093 | switch (capability) { |
| 4094 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4095 | // intentional fallthrough |
| 4096 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4097 | if (requireRcsProvisioning) { |
| 4098 | // OPTION or PRESENCE requires provisioning |
| 4099 | return true; |
| 4100 | } |
| 4101 | break; |
| 4102 | } |
| 4103 | } |
| 4104 | return false; |
| 4105 | } |
| 4106 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4107 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4108 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4109 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4110 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4111 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4112 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4113 | final long identity = Binder.clearCallingIdentity(); |
| 4114 | try { |
| 4115 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4116 | int slotId = getSlotIndex(subId); |
| 4117 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4118 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4119 | + subId + "' for key:" + key); |
| 4120 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4121 | } |
| 4122 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4123 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4124 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4125 | + subId + "' for key:" + key); |
| 4126 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4127 | } finally { |
| 4128 | Binder.restoreCallingIdentity(identity); |
| 4129 | } |
| 4130 | } |
| 4131 | |
| 4132 | @Override |
| 4133 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4134 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4135 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4136 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4137 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4138 | final long identity = Binder.clearCallingIdentity(); |
| 4139 | try { |
| 4140 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4141 | int slotId = getSlotIndex(subId); |
| 4142 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4143 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4144 | + subId + "' for key:" + key); |
| 4145 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4146 | } |
| 4147 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4148 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4149 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4150 | + subId + "' for key:" + key); |
| 4151 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4152 | } finally { |
| 4153 | Binder.restoreCallingIdentity(identity); |
| 4154 | } |
| 4155 | } |
| 4156 | |
| 4157 | @Override |
| 4158 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4159 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4160 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4161 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4162 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4163 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4164 | final long identity = Binder.clearCallingIdentity(); |
| 4165 | try { |
| 4166 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4167 | int slotId = getSlotIndex(subId); |
| 4168 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4169 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4170 | + subId + "' for key:" + key); |
| 4171 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4172 | } |
| 4173 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4174 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4175 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4176 | + "' for key:" + key); |
| 4177 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4178 | } finally { |
| 4179 | Binder.restoreCallingIdentity(identity); |
| 4180 | } |
| 4181 | } |
| 4182 | |
| 4183 | @Override |
| 4184 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4185 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4186 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4187 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4188 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4189 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4190 | final long identity = Binder.clearCallingIdentity(); |
| 4191 | try { |
| 4192 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4193 | int slotId = getSlotIndex(subId); |
| 4194 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4195 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4196 | + subId + "' for key:" + key); |
| 4197 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4198 | } |
| 4199 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4200 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4201 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4202 | + "' for key:" + key); |
| 4203 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4204 | } finally { |
| 4205 | Binder.restoreCallingIdentity(identity); |
| 4206 | } |
| 4207 | } |
| 4208 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4209 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4210 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4211 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4212 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4213 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4214 | } |
| 4215 | return slotId; |
| 4216 | } |
| 4217 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4218 | private int getSlotIndex(int subId) { |
| 4219 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4220 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4221 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4222 | } |
| 4223 | return slotId; |
| 4224 | } |
| 4225 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4226 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4227 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4228 | */ |
| 4229 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4230 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4231 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4232 | final int targetSdk = getTargetSdk(callingPackage); |
| 4233 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4234 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4235 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4236 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4237 | mApp, subId, callingPackage, callingFeatureId, |
| 4238 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4239 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4240 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4241 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4242 | final long identity = Binder.clearCallingIdentity(); |
| 4243 | try { |
| 4244 | final Phone phone = getPhone(subId); |
| 4245 | if (phone != null) { |
| 4246 | return phone.getServiceState().getDataNetworkType(); |
| 4247 | } else { |
| 4248 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4249 | } |
| 4250 | } finally { |
| 4251 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4252 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | /** |
| 4256 | * Returns the data network type |
| 4257 | */ |
| 4258 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4259 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4260 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4261 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | /** |
| 4265 | * Returns the data network type for a subId |
| 4266 | */ |
| 4267 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4268 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4269 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4270 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4271 | mApp, subId, callingPackage, callingFeatureId, |
| 4272 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4273 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4274 | } |
| 4275 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4276 | final long identity = Binder.clearCallingIdentity(); |
| 4277 | try { |
| 4278 | final Phone phone = getPhone(subId); |
| 4279 | if (phone != null) { |
| 4280 | return phone.getServiceState().getDataNetworkType(); |
| 4281 | } else { |
| 4282 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4283 | } |
| 4284 | } finally { |
| 4285 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4286 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4287 | } |
| 4288 | |
| 4289 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4290 | * Returns the Voice network type for a subId |
| 4291 | */ |
| 4292 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4293 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4294 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4295 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4296 | mApp, subId, callingPackage, callingFeatureId, |
| 4297 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4298 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4299 | } |
| 4300 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4301 | final long identity = Binder.clearCallingIdentity(); |
| 4302 | try { |
| 4303 | final Phone phone = getPhone(subId); |
| 4304 | if (phone != null) { |
| 4305 | return phone.getServiceState().getVoiceNetworkType(); |
| 4306 | } else { |
| 4307 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4308 | } |
| 4309 | } finally { |
| 4310 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4311 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4312 | } |
| 4313 | |
| 4314 | /** |
| 4315 | * @return true if a ICC card is present |
| 4316 | */ |
| 4317 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4318 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4319 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4320 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4321 | } |
| 4322 | |
| 4323 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4324 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4325 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4326 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4327 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4328 | final long identity = Binder.clearCallingIdentity(); |
| 4329 | try { |
| 4330 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4331 | if (phone != null) { |
| 4332 | return phone.getIccCard().hasIccCard(); |
| 4333 | } else { |
| 4334 | return false; |
| 4335 | } |
| 4336 | } finally { |
| 4337 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4338 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4339 | } |
| 4340 | |
| 4341 | /** |
| 4342 | * Return if the current radio is LTE on CDMA. This |
| 4343 | * is a tri-state return value as for a period of time |
| 4344 | * the mode may be unknown. |
| 4345 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4346 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4347 | * @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] | 4348 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4349 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4350 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4351 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4352 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4353 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4354 | } |
| 4355 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4356 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4357 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4358 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4359 | try { |
| 4360 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4361 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4362 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4363 | } |
| 4364 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4365 | final long identity = Binder.clearCallingIdentity(); |
| 4366 | try { |
| 4367 | final Phone phone = getPhone(subId); |
| 4368 | if (phone == null) { |
| 4369 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4370 | } else { |
| 4371 | return phone.getLteOnCdmaMode(); |
| 4372 | } |
| 4373 | } finally { |
| 4374 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4375 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4376 | } |
| 4377 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4378 | /** |
| 4379 | * {@hide} |
| 4380 | * Returns Default subId, 0 in the case of single standby. |
| 4381 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4382 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4383 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4384 | } |
| 4385 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4386 | private int getSlotForDefaultSubscription() { |
| 4387 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4388 | } |
| 4389 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4390 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4391 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4392 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4393 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4394 | private boolean isActiveSubscription(int subId) { |
| 4395 | return mSubscriptionController.isActiveSubId(subId); |
| 4396 | } |
| 4397 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4398 | /** |
| 4399 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4400 | */ |
| 4401 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4402 | final long identity = Binder.clearCallingIdentity(); |
| 4403 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4404 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4405 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4406 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4407 | } finally { |
| 4408 | Binder.restoreCallingIdentity(identity); |
| 4409 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4410 | } |
| 4411 | |
| 4412 | /** |
| 4413 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4414 | */ |
| 4415 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4416 | final long identity = Binder.clearCallingIdentity(); |
| 4417 | try { |
| 4418 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4419 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4420 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4421 | } finally { |
| 4422 | Binder.restoreCallingIdentity(identity); |
| 4423 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4424 | } |
| 4425 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4426 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4427 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4428 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4429 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4430 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4431 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4432 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4433 | if (phoneId == -1) { |
| 4434 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4435 | + " does not correspond to an active phone"); |
| 4436 | } |
| 4437 | return PhoneFactory.getPhone(phoneId); |
| 4438 | } |
| 4439 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4440 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4441 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4442 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4443 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4444 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4445 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4446 | if (DBG) { |
| 4447 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4448 | } |
| 4449 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4450 | p2); |
| 4451 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4452 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4453 | |
| 4454 | @Override |
| 4455 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4456 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4457 | enforceModifyPermission(); |
| 4458 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4459 | if (DBG) { |
| 4460 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4461 | } |
| 4462 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4463 | callingPackage, aid, p2); |
| 4464 | } |
| 4465 | |
| 4466 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4467 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4468 | final long identity = Binder.clearCallingIdentity(); |
| 4469 | try { |
| 4470 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4471 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4472 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4473 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4474 | if (bestComponent == null |
| 4475 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4476 | loge("The calling package is not allowed to access ISD-R."); |
| 4477 | throw new SecurityException( |
| 4478 | "The calling package is not allowed to access ISD-R."); |
| 4479 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4480 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4481 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4482 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4483 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4484 | null /* workSource */); |
| 4485 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4486 | return response; |
| 4487 | } finally { |
| 4488 | Binder.restoreCallingIdentity(identity); |
| 4489 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4490 | } |
| 4491 | |
| 4492 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4493 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4494 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4495 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4496 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4497 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4498 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4499 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4500 | @Override |
| 4501 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4502 | enforceModifyPermission(); |
| 4503 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4504 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4505 | channel); |
| 4506 | } |
| 4507 | |
| 4508 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4509 | final long identity = Binder.clearCallingIdentity(); |
| 4510 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4511 | if (channel < 0) { |
| 4512 | return false; |
| 4513 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4514 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4515 | null /* workSource */); |
| 4516 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4517 | return success; |
| 4518 | } finally { |
| 4519 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4520 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4521 | } |
| 4522 | |
| 4523 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4524 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4525 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4526 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4527 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4528 | if (DBG) { |
| 4529 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4530 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4531 | + p3 + " data=" + data); |
| 4532 | } |
| 4533 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4534 | command, p1, p2, p3, data); |
| 4535 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4536 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4537 | @Override |
| 4538 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4539 | int command, int p1, int p2, int p3, String data) { |
| 4540 | enforceModifyPermission(); |
| 4541 | if (DBG) { |
| 4542 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4543 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4544 | + p3 + " data=" + data); |
| 4545 | } |
| 4546 | return iccTransmitApduLogicalChannelWithPermission( |
| 4547 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4548 | data); |
| 4549 | } |
| 4550 | |
| 4551 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4552 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4553 | final long identity = Binder.clearCallingIdentity(); |
| 4554 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4555 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4556 | return ""; |
| 4557 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4558 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4559 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4560 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4561 | null /* workSource */); |
| 4562 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4563 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4564 | // Append the returned status code to the end of the response payload. |
| 4565 | String s = Integer.toHexString( |
| 4566 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4567 | if (response.payload != null) { |
| 4568 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4569 | } |
| 4570 | return s; |
| 4571 | } finally { |
| 4572 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4573 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4574 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4575 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4576 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4577 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4578 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4579 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4580 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4581 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4582 | if (DBG) { |
| 4583 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4584 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4585 | } |
| 4586 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4587 | cla, command, p1, p2, p3, data); |
| 4588 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4589 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4590 | @Override |
| 4591 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4592 | int command, int p1, int p2, int p3, String data) { |
| 4593 | enforceModifyPermission(); |
| 4594 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4595 | if (DBG) { |
| 4596 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4597 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4598 | + " data=" + data); |
| 4599 | } |
| 4600 | |
| 4601 | return iccTransmitApduBasicChannelWithPermission( |
| 4602 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4603 | p2, p3, data); |
| 4604 | } |
| 4605 | |
| 4606 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4607 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4608 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4609 | final long identity = Binder.clearCallingIdentity(); |
| 4610 | try { |
| 4611 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4612 | && TextUtils.equals(ISDR_AID, data)) { |
| 4613 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4614 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4615 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4616 | if (bestComponent == null |
| 4617 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4618 | loge("The calling package is not allowed to select ISD-R."); |
| 4619 | throw new SecurityException( |
| 4620 | "The calling package is not allowed to select ISD-R."); |
| 4621 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4622 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4623 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4624 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4625 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4626 | null /* workSource */); |
| 4627 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4628 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4629 | // Append the returned status code to the end of the response payload. |
| 4630 | String s = Integer.toHexString( |
| 4631 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4632 | if (response.payload != null) { |
| 4633 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4634 | } |
| 4635 | return s; |
| 4636 | } finally { |
| 4637 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4638 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4639 | } |
| 4640 | |
| 4641 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4642 | 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] | 4643 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4644 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4645 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4646 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4647 | final long identity = Binder.clearCallingIdentity(); |
| 4648 | try { |
| 4649 | if (DBG) { |
| 4650 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4651 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4652 | } |
| 4653 | |
| 4654 | IccIoResult response = |
| 4655 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4656 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4657 | subId); |
| 4658 | |
| 4659 | if (DBG) { |
| 4660 | log("Exchange SIM_IO [R]" + response); |
| 4661 | } |
| 4662 | |
| 4663 | byte[] result = null; |
| 4664 | int length = 2; |
| 4665 | if (response.payload != null) { |
| 4666 | length = 2 + response.payload.length; |
| 4667 | result = new byte[length]; |
| 4668 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4669 | } else { |
| 4670 | result = new byte[length]; |
| 4671 | } |
| 4672 | |
| 4673 | result[length - 1] = (byte) response.sw2; |
| 4674 | result[length - 2] = (byte) response.sw1; |
| 4675 | return result; |
| 4676 | } finally { |
| 4677 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4678 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4679 | } |
| 4680 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4681 | /** |
| 4682 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4683 | * on a particular subscription |
| 4684 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4685 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4686 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4687 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4688 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4689 | return null; |
| 4690 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4691 | |
| 4692 | final long identity = Binder.clearCallingIdentity(); |
| 4693 | try { |
| 4694 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4695 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4696 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4697 | return null; |
| 4698 | } |
| 4699 | Object response = sendRequest( |
| 4700 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4701 | if (response instanceof String[]) { |
| 4702 | return (String[]) response; |
| 4703 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4704 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4705 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4706 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4707 | } finally { |
| 4708 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4709 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4710 | } |
| 4711 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4712 | /** |
| 4713 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4714 | * subscription. |
| 4715 | * |
| 4716 | * @param subId the id of the subscription. |
| 4717 | * @param appType the uicc app type, must be USIM or SIM. |
| 4718 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4719 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4720 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4721 | * @return number of fplmns that is successfully written to the SIM. |
| 4722 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4723 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4724 | String callingFeatureId) { |
| 4725 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4726 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4727 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4728 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4729 | } |
| 4730 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4731 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4732 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4733 | } |
| 4734 | if (fplmns == null) { |
| 4735 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4736 | } |
| 4737 | for (String fplmn : fplmns) { |
| 4738 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4739 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4740 | } |
| 4741 | } |
| 4742 | final long identity = Binder.clearCallingIdentity(); |
| 4743 | try { |
| 4744 | Object response = sendRequest( |
| 4745 | CMD_SET_FORBIDDEN_PLMNS, |
| 4746 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4747 | subId); |
| 4748 | return (int) response; |
| 4749 | } finally { |
| 4750 | Binder.restoreCallingIdentity(identity); |
| 4751 | } |
| 4752 | } |
| 4753 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4754 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4755 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4756 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4757 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4758 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4759 | final long identity = Binder.clearCallingIdentity(); |
| 4760 | try { |
| 4761 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4762 | if (response.payload == null) { |
| 4763 | return ""; |
| 4764 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4765 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4766 | // Append the returned status code to the end of the response payload. |
| 4767 | String s = Integer.toHexString( |
| 4768 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4769 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4770 | return s; |
| 4771 | } finally { |
| 4772 | Binder.restoreCallingIdentity(identity); |
| 4773 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4774 | } |
| 4775 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4776 | /** |
| 4777 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4778 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4779 | * |
| 4780 | * @param itemID the ID of the item to read |
| 4781 | * @return the NV item as a String, or null on error. |
| 4782 | */ |
| 4783 | @Override |
| 4784 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4785 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4786 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4787 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4788 | |
| 4789 | final long identity = Binder.clearCallingIdentity(); |
| 4790 | try { |
| 4791 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4792 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4793 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4794 | return value; |
| 4795 | } finally { |
| 4796 | Binder.restoreCallingIdentity(identity); |
| 4797 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4798 | } |
| 4799 | |
| 4800 | /** |
| 4801 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4802 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4803 | * |
| 4804 | * @param itemID the ID of the item to read |
| 4805 | * @param itemValue the value to write, as a String |
| 4806 | * @return true on success; false on any failure |
| 4807 | */ |
| 4808 | @Override |
| 4809 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4810 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4811 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4812 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4813 | |
| 4814 | final long identity = Binder.clearCallingIdentity(); |
| 4815 | try { |
| 4816 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4817 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4818 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4819 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4820 | return success; |
| 4821 | } finally { |
| 4822 | Binder.restoreCallingIdentity(identity); |
| 4823 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4824 | } |
| 4825 | |
| 4826 | /** |
| 4827 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4828 | * Used for device configuration by some CDMA operators. |
| 4829 | * |
| 4830 | * @param preferredRoamingList byte array containing the new PRL |
| 4831 | * @return true on success; false on any failure |
| 4832 | */ |
| 4833 | @Override |
| 4834 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4835 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4836 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4837 | |
| 4838 | final long identity = Binder.clearCallingIdentity(); |
| 4839 | try { |
| 4840 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4841 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4842 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4843 | return success; |
| 4844 | } finally { |
| 4845 | Binder.restoreCallingIdentity(identity); |
| 4846 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4847 | } |
| 4848 | |
| 4849 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4850 | * 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] | 4851 | * Used for device configuration by some CDMA operators. |
| 4852 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4853 | * @param slotIndex - device slot. |
| 4854 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4855 | * @return true on success; false on any failure |
| 4856 | */ |
| 4857 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4858 | public boolean resetModemConfig(int slotIndex) { |
| 4859 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4860 | if (phone != null) { |
| 4861 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4862 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4863 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4864 | final long identity = Binder.clearCallingIdentity(); |
| 4865 | try { |
| 4866 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4867 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4868 | return success; |
| 4869 | } finally { |
| 4870 | Binder.restoreCallingIdentity(identity); |
| 4871 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4872 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4873 | return false; |
| 4874 | } |
| 4875 | |
| 4876 | /** |
| 4877 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4878 | * |
| 4879 | * @param slotIndex - device slot. |
| 4880 | * |
| 4881 | * @return true on success; false on any failure |
| 4882 | */ |
| 4883 | @Override |
| 4884 | public boolean rebootModem(int slotIndex) { |
| 4885 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4886 | if (phone != null) { |
| 4887 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4888 | mApp, phone.getSubId(), "rebootModem"); |
| 4889 | |
| 4890 | final long identity = Binder.clearCallingIdentity(); |
| 4891 | try { |
| 4892 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4893 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4894 | return success; |
| 4895 | } finally { |
| 4896 | Binder.restoreCallingIdentity(identity); |
| 4897 | } |
| 4898 | } |
| 4899 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4900 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4901 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4902 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4903 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4904 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4905 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4906 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4907 | return new String[0]; |
| 4908 | } |
| 4909 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4910 | final long identity = Binder.clearCallingIdentity(); |
| 4911 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4912 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4913 | } finally { |
| 4914 | Binder.restoreCallingIdentity(identity); |
| 4915 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4916 | } |
| 4917 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4918 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4919 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4920 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4921 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4922 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4923 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4924 | |
| 4925 | final long identity = Binder.clearCallingIdentity(); |
| 4926 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4927 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4928 | // may happen if the device does not support IMS. |
| 4929 | return; |
| 4930 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4931 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4932 | } finally { |
| 4933 | Binder.restoreCallingIdentity(identity); |
| 4934 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4935 | } |
| 4936 | |
| 4937 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4938 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4939 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4940 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4941 | public void disableIms(int slotId) { |
| 4942 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4943 | |
| 4944 | final long identity = Binder.clearCallingIdentity(); |
| 4945 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4946 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4947 | // may happen if the device does not support IMS. |
| 4948 | return; |
| 4949 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4950 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4951 | } finally { |
| 4952 | Binder.restoreCallingIdentity(identity); |
| 4953 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4954 | } |
| 4955 | |
| 4956 | /** |
| 4957 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4958 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4959 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4960 | */ |
| 4961 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4962 | IImsServiceFeatureCallback callback) { |
| 4963 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4964 | |
| 4965 | final long identity = Binder.clearCallingIdentity(); |
| 4966 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4967 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4968 | // may happen if the device does not support IMS. |
| 4969 | return null; |
| 4970 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4971 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4972 | } finally { |
| 4973 | Binder.restoreCallingIdentity(identity); |
| 4974 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4975 | } |
| 4976 | |
| 4977 | /** |
| 4978 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4979 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4980 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4981 | * listener for feature updates. |
| 4982 | */ |
| 4983 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4984 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4985 | |
| 4986 | final long identity = Binder.clearCallingIdentity(); |
| 4987 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4988 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4989 | // may happen if the device does not support IMS. |
| 4990 | return null; |
| 4991 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4992 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4993 | } finally { |
| 4994 | Binder.restoreCallingIdentity(identity); |
| 4995 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4996 | } |
| 4997 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4998 | /** |
| 4999 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5000 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5001 | */ |
| 5002 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5003 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5004 | |
| 5005 | final long identity = Binder.clearCallingIdentity(); |
| 5006 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5007 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5008 | // may happen if the device does not support IMS. |
| 5009 | return null; |
| 5010 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5011 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5012 | } finally { |
| 5013 | Binder.restoreCallingIdentity(identity); |
| 5014 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5015 | } |
| 5016 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5017 | /** |
| 5018 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5019 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5020 | */ |
| 5021 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5022 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5023 | |
| 5024 | final long identity = Binder.clearCallingIdentity(); |
| 5025 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5026 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5027 | // may happen if the device does not support IMS. |
| 5028 | return null; |
| 5029 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5030 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5031 | } finally { |
| 5032 | Binder.restoreCallingIdentity(identity); |
| 5033 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5034 | } |
| 5035 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5036 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5037 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5038 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5039 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5040 | * @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] | 5041 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5042 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5043 | * @param packageName The name of the package that the current configuration will be replaced |
| 5044 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5045 | * @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] | 5046 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5047 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5048 | int[] featureTypes, String packageName) { |
| 5049 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5050 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5051 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5052 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5053 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5054 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5055 | final long identity = Binder.clearCallingIdentity(); |
| 5056 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5057 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5058 | // may happen if the device does not support IMS. |
| 5059 | return false; |
| 5060 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5061 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5062 | for (int featureType : featureTypes) { |
| 5063 | featureConfig.put(featureType, packageName); |
| 5064 | } |
| 5065 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5066 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5067 | } finally { |
| 5068 | Binder.restoreCallingIdentity(identity); |
| 5069 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5070 | } |
| 5071 | |
| 5072 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5073 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5074 | * |
| 5075 | * @param slotId The slot that the ImsService is associated with. |
| 5076 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5077 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5078 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5079 | * @return the package name of the ImsService configuration. |
| 5080 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5081 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5082 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5083 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5084 | TelephonyPermissions |
| 5085 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5086 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5087 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5088 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5089 | final long identity = Binder.clearCallingIdentity(); |
| 5090 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5091 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5092 | // may happen if the device does not support IMS. |
| 5093 | return ""; |
| 5094 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5095 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5096 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5097 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5098 | } finally { |
| 5099 | Binder.restoreCallingIdentity(identity); |
| 5100 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5101 | } |
| 5102 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5103 | /** |
| 5104 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5105 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5106 | * @param callback A callback with an integer containing the |
| 5107 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5108 | */ |
| 5109 | @Override |
| 5110 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5111 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5112 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5113 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5114 | "IMS not available on device."); |
| 5115 | } |
| 5116 | final long token = Binder.clearCallingIdentity(); |
| 5117 | try { |
| 5118 | int slotId = getSlotIndex(subId); |
| 5119 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5120 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5121 | + subId + "'"); |
| 5122 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5123 | } |
| 5124 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5125 | try { |
| 5126 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5127 | } catch (RemoteException e) { |
| 5128 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5129 | + "Ignore"); |
| 5130 | } |
| 5131 | }); |
| 5132 | } finally { |
| 5133 | Binder.restoreCallingIdentity(token); |
| 5134 | } |
| 5135 | } |
| 5136 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5137 | public void setImsRegistrationState(boolean registered) { |
| 5138 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5139 | |
| 5140 | final long identity = Binder.clearCallingIdentity(); |
| 5141 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5142 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5143 | } finally { |
| 5144 | Binder.restoreCallingIdentity(identity); |
| 5145 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5146 | } |
| 5147 | |
| 5148 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5149 | * Set the network selection mode to automatic. |
| 5150 | * |
| 5151 | */ |
| 5152 | @Override |
| 5153 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5154 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5155 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5156 | |
| 5157 | final long identity = Binder.clearCallingIdentity(); |
| 5158 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5159 | if (!isActiveSubscription(subId)) { |
| 5160 | return; |
| 5161 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5162 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5163 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5164 | } finally { |
| 5165 | Binder.restoreCallingIdentity(identity); |
| 5166 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5167 | } |
| 5168 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5169 | /** |
| 5170 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5171 | * |
| 5172 | * @param subId the id of the subscription. |
| 5173 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5174 | * the operator to attach to. |
| 5175 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5176 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5177 | * normal network selection next time. |
| 5178 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5179 | */ |
| 5180 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5181 | public boolean setNetworkSelectionModeManual( |
| 5182 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5183 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5184 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5185 | |
| 5186 | if (!isActiveSubscription(subId)) { |
| 5187 | return false; |
| 5188 | } |
| 5189 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5190 | final long identity = Binder.clearCallingIdentity(); |
| 5191 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5192 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5193 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5194 | if (DBG) { |
| 5195 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5196 | + " operator: " + operatorInfo); |
| 5197 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5198 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5199 | } finally { |
| 5200 | Binder.restoreCallingIdentity(identity); |
| 5201 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5202 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5203 | /** |
| 5204 | * Get the manual network selection |
| 5205 | * |
| 5206 | * @param subId the id of the subscription. |
| 5207 | * |
| 5208 | * @return the previously saved user selected PLMN |
| 5209 | */ |
| 5210 | @Override |
| 5211 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5212 | TelephonyPermissions |
| 5213 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5214 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5215 | |
| 5216 | final long identity = Binder.clearCallingIdentity(); |
| 5217 | try { |
| 5218 | if (!isActiveSubscription(subId)) { |
| 5219 | return ""; |
| 5220 | } |
| 5221 | |
| 5222 | final Phone phone = getPhone(subId); |
| 5223 | if (phone == null) { |
| 5224 | return ""; |
| 5225 | } |
| 5226 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5227 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5228 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5229 | } finally { |
| 5230 | Binder.restoreCallingIdentity(identity); |
| 5231 | } |
| 5232 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5233 | |
| 5234 | /** |
| 5235 | * Scans for available networks. |
| 5236 | */ |
| 5237 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5238 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5239 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5240 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5241 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5242 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5243 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5244 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5245 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5246 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5247 | .setCallingPid(Binder.getCallingPid()) |
| 5248 | .setCallingUid(Binder.getCallingUid()) |
| 5249 | .setMethod("getCellNetworkScanResults") |
| 5250 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5251 | .build()); |
| 5252 | switch (locationResult) { |
| 5253 | case DENIED_HARD: |
| 5254 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5255 | case DENIED_SOFT: |
| 5256 | return null; |
| 5257 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5258 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5259 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5260 | try { |
| 5261 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5262 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5263 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5264 | } finally { |
| 5265 | Binder.restoreCallingIdentity(identity); |
| 5266 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5267 | } |
| 5268 | |
| 5269 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame^] | 5270 | * Get the call forwarding info, given the call forwarding reason. |
| 5271 | */ |
| 5272 | @Override |
| 5273 | public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) { |
| 5274 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5275 | long identity = Binder.clearCallingIdentity(); |
| 5276 | try { |
| 5277 | if (DBG) { |
| 5278 | log("getCallForwarding: subId " + subId |
| 5279 | + " callForwardingReason" + callForwardingReason); |
| 5280 | } |
| 5281 | return (CallForwardingInfo) sendRequest( |
| 5282 | CMD_GET_CALL_FORWARDING, callForwardingReason, subId); |
| 5283 | } finally { |
| 5284 | Binder.restoreCallingIdentity(identity); |
| 5285 | } |
| 5286 | } |
| 5287 | |
| 5288 | /** |
| 5289 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5290 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5291 | */ |
| 5292 | @Override |
| 5293 | public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) { |
| 5294 | enforceModifyPermission(); |
| 5295 | long identity = Binder.clearCallingIdentity(); |
| 5296 | try { |
| 5297 | if (DBG) { |
| 5298 | log("setCallForwarding: subId " + subId |
| 5299 | + " callForwardingInfo" + callForwardingInfo); |
| 5300 | } |
| 5301 | return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId); |
| 5302 | } finally { |
| 5303 | Binder.restoreCallingIdentity(identity); |
| 5304 | } |
| 5305 | } |
| 5306 | |
| 5307 | /** |
| 5308 | * Get the call forwarding info, given the call forwarding reason. |
| 5309 | */ |
| 5310 | @Override |
| 5311 | public int getCallWaitingStatus(int subId) { |
| 5312 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5313 | long identity = Binder.clearCallingIdentity(); |
| 5314 | try { |
| 5315 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 5316 | return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId); |
| 5317 | } finally { |
| 5318 | Binder.restoreCallingIdentity(identity); |
| 5319 | } |
| 5320 | } |
| 5321 | |
| 5322 | /** |
| 5323 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5324 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5325 | */ |
| 5326 | @Override |
| 5327 | public boolean setCallWaitingStatus(int subId, boolean isEnable) { |
| 5328 | enforceModifyPermission(); |
| 5329 | long identity = Binder.clearCallingIdentity(); |
| 5330 | try { |
| 5331 | if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable); |
| 5332 | return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId); |
| 5333 | } finally { |
| 5334 | Binder.restoreCallingIdentity(identity); |
| 5335 | } |
| 5336 | } |
| 5337 | |
| 5338 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5339 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5340 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5341 | * @param subId id of the subscription |
| 5342 | * @param request contains the radio access networks with bands/channels to scan |
| 5343 | * @param messenger callback messenger for scan results or errors |
| 5344 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5345 | * @return the id of the requested scan which can be used to stop the scan. |
| 5346 | */ |
| 5347 | @Override |
| 5348 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5349 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5350 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5351 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5352 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5353 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5354 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5355 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5356 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5357 | .setCallingPid(Binder.getCallingPid()) |
| 5358 | .setCallingUid(Binder.getCallingUid()) |
| 5359 | .setMethod("requestNetworkScan") |
| 5360 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5361 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5362 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5363 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5364 | if (e != null) { |
| 5365 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5366 | throw e; |
| 5367 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5368 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5369 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5370 | } |
| 5371 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5372 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5373 | int callingUid = Binder.getCallingUid(); |
| 5374 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5375 | final long identity = Binder.clearCallingIdentity(); |
| 5376 | try { |
| 5377 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5378 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5379 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5380 | } finally { |
| 5381 | Binder.restoreCallingIdentity(identity); |
| 5382 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5383 | } |
| 5384 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5385 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5386 | NetworkScanRequest request, int subId) { |
| 5387 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5388 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5389 | boolean hasNetworkScanPermission = |
| 5390 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5391 | == PERMISSION_GRANTED; |
| 5392 | |
| 5393 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5394 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5395 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5396 | } |
| 5397 | |
| 5398 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5399 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5400 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5401 | return new SecurityException("Specific channels must not be" |
| 5402 | + " scanned without location access."); |
| 5403 | } |
| 5404 | } |
| 5405 | } |
| 5406 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5407 | return null; |
| 5408 | } |
| 5409 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5410 | /** |
| 5411 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5412 | * |
| 5413 | * @param subId id of the subscription |
| 5414 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5415 | */ |
| 5416 | @Override |
| 5417 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5418 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5419 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5420 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5421 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5422 | final long identity = Binder.clearCallingIdentity(); |
| 5423 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5424 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5425 | } finally { |
| 5426 | Binder.restoreCallingIdentity(identity); |
| 5427 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5428 | } |
| 5429 | |
| 5430 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5431 | * Get the calculated preferred network type. |
| 5432 | * Used for debugging incorrect network type. |
| 5433 | * |
| 5434 | * @return the preferred network type, defined in RILConstants.java. |
| 5435 | */ |
| 5436 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5437 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5438 | final Phone defaultPhone = getDefaultPhone(); |
| 5439 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5440 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5441 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5442 | } |
| 5443 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5444 | final long identity = Binder.clearCallingIdentity(); |
| 5445 | try { |
| 5446 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5447 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5448 | } finally { |
| 5449 | Binder.restoreCallingIdentity(identity); |
| 5450 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5451 | } |
| 5452 | |
| 5453 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5454 | * Get the preferred network type. |
| 5455 | * Used for device configuration by some CDMA operators. |
| 5456 | * |
| 5457 | * @return the preferred network type, defined in RILConstants.java. |
| 5458 | */ |
| 5459 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5460 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5461 | TelephonyPermissions |
| 5462 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5463 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5464 | |
| 5465 | final long identity = Binder.clearCallingIdentity(); |
| 5466 | try { |
| 5467 | if (DBG) log("getPreferredNetworkType"); |
| 5468 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5469 | int networkType = (result != null ? result[0] : -1); |
| 5470 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5471 | return networkType; |
| 5472 | } finally { |
| 5473 | Binder.restoreCallingIdentity(identity); |
| 5474 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5475 | } |
| 5476 | |
| 5477 | /** |
| 5478 | * Set the preferred network type. |
| 5479 | * Used for device configuration by some CDMA operators. |
| 5480 | * |
| 5481 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5482 | * @return true on success; false on any failure. |
| 5483 | */ |
| 5484 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5485 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5486 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5487 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5488 | |
| 5489 | final long identity = Binder.clearCallingIdentity(); |
| 5490 | try { |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5491 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5492 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5493 | return setPreferredNetworkTypesInternal(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5494 | } finally { |
| 5495 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5496 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5497 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5498 | |
| 5499 | /** |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5500 | * Get the allowed network types that store in the telephony provider. |
| 5501 | * |
| 5502 | * @param subId the id of the subscription. |
| 5503 | * @return allowedNetworkTypes the allowed network types. |
| 5504 | */ |
| 5505 | @Override |
| 5506 | public long getAllowedNetworkTypes(int subId) { |
| 5507 | TelephonyPermissions |
| 5508 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5509 | mApp, subId, "getAllowedNetworkTypes"); |
| 5510 | |
| 5511 | final long identity = Binder.clearCallingIdentity(); |
| 5512 | try { |
| 5513 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5514 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5515 | } finally { |
| 5516 | Binder.restoreCallingIdentity(identity); |
| 5517 | } |
| 5518 | } |
| 5519 | |
| 5520 | /** |
| 5521 | * Set the allowed network types. |
| 5522 | * |
| 5523 | * @param subId the id of the subscription. |
| 5524 | * @param allowedNetworkTypes the allowed network types. |
| 5525 | * @return true on success; false on any failure. |
| 5526 | */ |
| 5527 | @Override |
| 5528 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5529 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5530 | mApp, subId, "setAllowedNetworkTypes"); |
| 5531 | final long identity = Binder.clearCallingIdentity(); |
| 5532 | try { |
| 5533 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5534 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5535 | String.valueOf(allowedNetworkTypes)); |
| 5536 | return setPreferredNetworkTypesInternal(subId); |
| 5537 | } finally { |
| 5538 | Binder.restoreCallingIdentity(identity); |
| 5539 | } |
| 5540 | } |
| 5541 | |
| 5542 | private boolean setPreferredNetworkTypesInternal(int subId) { |
| 5543 | long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType( |
| 5544 | Settings.Global.getInt(mApp.getContentResolver(), |
| 5545 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5546 | RILConstants.PREFERRED_NETWORK_MODE)); |
| 5547 | long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty( |
| 5548 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5549 | int networkMode = RadioAccessFamily.getNetworkTypeFromRaf( |
| 5550 | (int) (networkTypeBitMask & allowedNetworkTypes)); |
| 5551 | |
| 5552 | if (DBG) { |
| 5553 | log("setPreferredNetworkTypesInternal: subId " + subId |
| 5554 | + " networkTypes " + networkTypeBitMask |
| 5555 | + " allowedNetworkTypes " + allowedNetworkTypes |
| 5556 | + " networkMode " + networkMode); |
| 5557 | } |
| 5558 | |
| 5559 | Boolean success = (Boolean) sendRequest( |
| 5560 | CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId); |
| 5561 | if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail")); |
| 5562 | return success; |
| 5563 | } |
| 5564 | |
| 5565 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5566 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5567 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5568 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5569 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5570 | * @hide |
| 5571 | */ |
| 5572 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5573 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5574 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5575 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5576 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5577 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5578 | if (phone != null) { |
| 5579 | return phone.hasMatchedTetherApnSetting(); |
| 5580 | } else { |
| 5581 | return false; |
| 5582 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5583 | } finally { |
| 5584 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5585 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5586 | } |
| 5587 | |
| 5588 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5589 | * Set mobile data enabled |
| 5590 | * Used by the user through settings etc to turn on/off mobile data |
| 5591 | * |
| 5592 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5593 | */ |
| 5594 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5595 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5596 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5597 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5598 | |
| 5599 | final long identity = Binder.clearCallingIdentity(); |
| 5600 | try { |
| 5601 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5602 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5603 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5604 | if (phone != null) { |
| 5605 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5606 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5607 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5608 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5609 | } |
| 5610 | } finally { |
| 5611 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5612 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5613 | } |
| 5614 | |
| 5615 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5616 | * Enable or disable always reporting signal strength changes from radio. |
| 5617 | * |
| 5618 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5619 | */ |
| 5620 | @Override |
| 5621 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5622 | enforceModifyPermission(); |
| 5623 | enforceSystemCaller(); |
| 5624 | |
| 5625 | final long identity = Binder.clearCallingIdentity(); |
| 5626 | final Phone phone = getPhone(subId); |
| 5627 | try { |
| 5628 | if (phone != null) { |
| 5629 | if (DBG) { |
| 5630 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5631 | + " isEnable=" + isEnable); |
| 5632 | } |
| 5633 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5634 | } else { |
| 5635 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5636 | + subId); |
| 5637 | } |
| 5638 | } finally { |
| 5639 | Binder.restoreCallingIdentity(identity); |
| 5640 | } |
| 5641 | } |
| 5642 | |
| 5643 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5644 | * Get the user enabled state of Mobile Data. |
| 5645 | * |
| 5646 | * TODO: remove and use isUserDataEnabled. |
| 5647 | * This can't be removed now because some vendor codes |
| 5648 | * calls through ITelephony directly while they should |
| 5649 | * use TelephonyManager. |
| 5650 | * |
| 5651 | * @return true on enabled |
| 5652 | */ |
| 5653 | @Override |
| 5654 | public boolean getDataEnabled(int subId) { |
| 5655 | return isUserDataEnabled(subId); |
| 5656 | } |
| 5657 | |
| 5658 | /** |
| 5659 | * Get whether mobile data is enabled per user setting. |
| 5660 | * |
| 5661 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5662 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5663 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5664 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5665 | * |
| 5666 | * @return {@code true} if data is enabled else {@code false} |
| 5667 | */ |
| 5668 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5669 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5670 | try { |
| 5671 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5672 | null); |
| 5673 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5674 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5675 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5676 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5677 | |
| 5678 | final long identity = Binder.clearCallingIdentity(); |
| 5679 | try { |
| 5680 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5681 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5682 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5683 | if (phone != null) { |
| 5684 | boolean retVal = phone.isUserDataEnabled(); |
| 5685 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5686 | return retVal; |
| 5687 | } else { |
| 5688 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5689 | return false; |
| 5690 | } |
| 5691 | } finally { |
| 5692 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5693 | } |
| 5694 | } |
| 5695 | |
| 5696 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5697 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5698 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5699 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5700 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5701 | * @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] | 5702 | */ |
| 5703 | @Override |
| 5704 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5705 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5706 | |
| 5707 | final long identity = Binder.clearCallingIdentity(); |
| 5708 | try { |
| 5709 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5710 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5711 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5712 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5713 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5714 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5715 | return retVal; |
| 5716 | } else { |
| 5717 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5718 | return false; |
| 5719 | } |
| 5720 | } finally { |
| 5721 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5722 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5723 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5724 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5725 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 5726 | Phone phone) { |
| 5727 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5728 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5729 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5730 | || subController == null) return privilegeFromSim; |
| 5731 | |
| 5732 | int uid = Binder.getCallingUid(); |
| 5733 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5734 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5735 | |
| 5736 | final long identity = Binder.clearCallingIdentity(); |
| 5737 | try { |
| 5738 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5739 | SubscriptionManager subManager = (SubscriptionManager) |
| 5740 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5741 | for (String pkg : packages) { |
| 5742 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5743 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5744 | } |
| 5745 | } |
| 5746 | return privilegeFromSim; |
| 5747 | } finally { |
| 5748 | Binder.restoreCallingIdentity(identity); |
| 5749 | } |
| 5750 | } |
| 5751 | |
| 5752 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5753 | String pkgName) { |
| 5754 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5755 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5756 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5757 | || subController == null) return privilegeFromSim; |
| 5758 | |
| 5759 | final long identity = Binder.clearCallingIdentity(); |
| 5760 | try { |
| 5761 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5762 | SubscriptionManager subManager = (SubscriptionManager) |
| 5763 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5764 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5765 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5766 | } finally { |
| 5767 | Binder.restoreCallingIdentity(identity); |
| 5768 | } |
| 5769 | } |
| 5770 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5771 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5772 | public int getCarrierPrivilegeStatus(int subId) { |
| 5773 | final Phone phone = getPhone(subId); |
| 5774 | if (phone == null) { |
| 5775 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5776 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5777 | } |
| 5778 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5779 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5780 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5781 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5782 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5783 | |
| 5784 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5785 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 5786 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5787 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5788 | |
| 5789 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5790 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5791 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5792 | final Phone phone = getPhone(subId); |
| 5793 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5794 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5795 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5796 | } |
| 5797 | UiccProfile profile = |
| 5798 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5799 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5800 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5801 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5802 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5803 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5804 | profile.getCarrierPrivilegeStatusForUid( |
| 5805 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5806 | } |
| 5807 | |
| 5808 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5809 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5810 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5811 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5812 | } |
| 5813 | |
| 5814 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5815 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5816 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5817 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5818 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5819 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5820 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5821 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5822 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5823 | } |
| 5824 | |
| 5825 | @Override |
| 5826 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5827 | if (TextUtils.isEmpty(pkgName)) |
| 5828 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5829 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5830 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5831 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5832 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5833 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5834 | continue; |
| 5835 | } |
| 5836 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5837 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5838 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5839 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5840 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5841 | break; |
| 5842 | } |
| 5843 | } |
| 5844 | |
| 5845 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5846 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5847 | |
| 5848 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5849 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5850 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5851 | loge("phoneId " + phoneId + " is not valid."); |
| 5852 | return null; |
| 5853 | } |
| 5854 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5855 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5856 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5857 | return null ; |
| 5858 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5859 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5860 | } |
| 5861 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5862 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5863 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5864 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5865 | List<String> privilegedPackages = new ArrayList<>(); |
| 5866 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5867 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5868 | // has UICC in that slot. |
| 5869 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5870 | if (card.hasCarrierPrivilegeRules()) { |
| 5871 | if (packages == null) { |
| 5872 | // Only check packages in user 0 for now |
| 5873 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5874 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5875 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5876 | | PackageManager.GET_SIGNING_CERTIFICATES, |
| 5877 | UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5878 | } |
| 5879 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5880 | PackageInfo pkgInfo = packages.get(p); |
| 5881 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5882 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5883 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5884 | privilegedPackages.add(pkgInfo.packageName); |
| 5885 | } |
| 5886 | } |
| 5887 | } |
| 5888 | } |
| 5889 | return privilegedPackages; |
| 5890 | } |
| 5891 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5892 | @Override |
| 5893 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5894 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5895 | |
| 5896 | final long identity = Binder.clearCallingIdentity(); |
| 5897 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5898 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5899 | try { |
| 5900 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5901 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5902 | } |
| 5903 | } finally { |
| 5904 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5905 | } |
| 5906 | return privilegedPackages; |
| 5907 | } |
| 5908 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5909 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5910 | final Phone phone = getPhone(subId); |
| 5911 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5912 | if (card == null) { |
| 5913 | loge("getIccId: No UICC"); |
| 5914 | return null; |
| 5915 | } |
| 5916 | String iccId = card.getIccId(); |
| 5917 | if (TextUtils.isEmpty(iccId)) { |
| 5918 | loge("getIccId: ICC ID is null or empty."); |
| 5919 | return null; |
| 5920 | } |
| 5921 | return iccId; |
| 5922 | } |
| 5923 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5924 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5925 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5926 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5927 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5928 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5929 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5930 | final long identity = Binder.clearCallingIdentity(); |
| 5931 | try { |
| 5932 | final String iccId = getIccId(subId); |
| 5933 | final Phone phone = getPhone(subId); |
| 5934 | if (phone == null) { |
| 5935 | return false; |
| 5936 | } |
| 5937 | final String subscriberId = phone.getSubscriberId(); |
| 5938 | |
| 5939 | if (DBG_MERGE) { |
| 5940 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 5941 | + subscriberId + " to " + number); |
| 5942 | } |
| 5943 | |
| 5944 | if (TextUtils.isEmpty(iccId)) { |
| 5945 | return false; |
| 5946 | } |
| 5947 | |
| 5948 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5949 | |
| 5950 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5951 | if (alphaTag == null) { |
| 5952 | editor.remove(alphaTagPrefKey); |
| 5953 | } else { |
| 5954 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5955 | } |
| 5956 | |
| 5957 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5958 | // track all merged IMSIs based on line number |
| 5959 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5960 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5961 | if (number == null) { |
| 5962 | editor.remove(numberPrefKey); |
| 5963 | editor.remove(subscriberPrefKey); |
| 5964 | } else { |
| 5965 | editor.putString(numberPrefKey, number); |
| 5966 | editor.putString(subscriberPrefKey, subscriberId); |
| 5967 | } |
| 5968 | |
| 5969 | editor.commit(); |
| 5970 | return true; |
| 5971 | } finally { |
| 5972 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5973 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5974 | } |
| 5975 | |
| 5976 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5977 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 5978 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5979 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5980 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5981 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5982 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5983 | return null; |
| 5984 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5985 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5986 | final long identity = Binder.clearCallingIdentity(); |
| 5987 | try { |
| 5988 | String iccId = getIccId(subId); |
| 5989 | if (iccId != null) { |
| 5990 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5991 | if (DBG_MERGE) { |
| 5992 | log("getLine1NumberForDisplay returning " |
| 5993 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5994 | } |
| 5995 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5996 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5997 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5998 | return null; |
| 5999 | } finally { |
| 6000 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6001 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6002 | } |
| 6003 | |
| 6004 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6005 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6006 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6007 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6008 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6009 | return null; |
| 6010 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6011 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6012 | final long identity = Binder.clearCallingIdentity(); |
| 6013 | try { |
| 6014 | String iccId = getIccId(subId); |
| 6015 | if (iccId != null) { |
| 6016 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6017 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6018 | } |
| 6019 | return null; |
| 6020 | } finally { |
| 6021 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6022 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6023 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6024 | |
| 6025 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6026 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6027 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6028 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6029 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6030 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6031 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6032 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6033 | return null; |
| 6034 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6035 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6036 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6037 | // the process, where TelephonyManager was instantiated. |
| 6038 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6039 | final long identity = Binder.clearCallingIdentity(); |
| 6040 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6041 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6042 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6043 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6044 | |
| 6045 | // Figure out what subscribers are currently active |
| 6046 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6047 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6048 | // Only consider subs which match the current subId |
| 6049 | // This logic can be simplified. See b/131189269 for progress. |
| 6050 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6051 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6052 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6053 | |
| 6054 | // First pass, find a number override for an active subscriber |
| 6055 | String mergeNumber = null; |
| 6056 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6057 | for (String key : prefs.keySet()) { |
| 6058 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6059 | final String subscriberId = (String) prefs.get(key); |
| 6060 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6061 | final String iccId = key.substring( |
| 6062 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6063 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6064 | mergeNumber = (String) prefs.get(numberKey); |
| 6065 | if (DBG_MERGE) { |
| 6066 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 6067 | + " for active subscriber " + subscriberId); |
| 6068 | } |
| 6069 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6070 | break; |
| 6071 | } |
| 6072 | } |
| 6073 | } |
| 6074 | } |
| 6075 | |
| 6076 | // Shortcut when no active merged subscribers |
| 6077 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6078 | return null; |
| 6079 | } |
| 6080 | |
| 6081 | // Second pass, find all subscribers under that line override |
| 6082 | final ArraySet<String> result = new ArraySet<>(); |
| 6083 | for (String key : prefs.keySet()) { |
| 6084 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6085 | final String number = (String) prefs.get(key); |
| 6086 | if (mergeNumber.equals(number)) { |
| 6087 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6088 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6089 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6090 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6091 | result.add(subscriberId); |
| 6092 | } |
| 6093 | } |
| 6094 | } |
| 6095 | } |
| 6096 | |
| 6097 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6098 | Arrays.sort(resultArray); |
| 6099 | if (DBG_MERGE) { |
| 6100 | Slog.d(LOG_TAG, |
| 6101 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6102 | } |
| 6103 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6104 | } finally { |
| 6105 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6106 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6107 | } |
| 6108 | |
| 6109 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6110 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6111 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6112 | |
| 6113 | final long identity = Binder.clearCallingIdentity(); |
| 6114 | try { |
| 6115 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6116 | TelephonyManager.class); |
| 6117 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6118 | if (subscriberId == null) { |
| 6119 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6120 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6121 | + subId); |
| 6122 | } |
| 6123 | return null; |
| 6124 | } |
| 6125 | |
| 6126 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6127 | .getSubscriptionInfo(subId); |
| 6128 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6129 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6130 | if (groupUuid == null) { |
| 6131 | return new String[]{subscriberId}; |
| 6132 | } |
| 6133 | |
| 6134 | // Get all subscriberIds from the group. |
| 6135 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6136 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6137 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 6138 | mApp.getFeatureId()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6139 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6140 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6141 | if (subscriberId != null) { |
| 6142 | mergedSubscriberIds.add(subscriberId); |
| 6143 | } |
| 6144 | } |
| 6145 | |
| 6146 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6147 | } finally { |
| 6148 | Binder.restoreCallingIdentity(identity); |
| 6149 | |
| 6150 | } |
| 6151 | } |
| 6152 | |
| 6153 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6154 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6155 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6156 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6157 | |
| 6158 | final long identity = Binder.clearCallingIdentity(); |
| 6159 | try { |
| 6160 | final Phone phone = getPhone(subId); |
| 6161 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6162 | } finally { |
| 6163 | Binder.restoreCallingIdentity(identity); |
| 6164 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6165 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6166 | |
| 6167 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6168 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6169 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6170 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6171 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6172 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6173 | |
| 6174 | final long identity = Binder.clearCallingIdentity(); |
| 6175 | try { |
| 6176 | final Phone phone = getPhone(subId); |
| 6177 | if (phone == null) { |
| 6178 | return false; |
| 6179 | } |
| 6180 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6181 | cdmaNonRoamingList); |
| 6182 | } finally { |
| 6183 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6184 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6185 | } |
| 6186 | |
| 6187 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6188 | @Deprecated |
| 6189 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6190 | enforceModifyPermission(); |
| 6191 | |
| 6192 | int returnValue = 0; |
| 6193 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6194 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6195 | if(result.exception == null) { |
| 6196 | if (result.result != null) { |
| 6197 | byte[] responseData = (byte[])(result.result); |
| 6198 | if(responseData.length > oemResp.length) { |
| 6199 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6200 | responseData.length + "bytes. Buffer Size is " + |
| 6201 | oemResp.length + "bytes."); |
| 6202 | } |
| 6203 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6204 | returnValue = responseData.length; |
| 6205 | } |
| 6206 | } else { |
| 6207 | CommandException ex = (CommandException) result.exception; |
| 6208 | returnValue = ex.getCommandError().ordinal(); |
| 6209 | if(returnValue > 0) returnValue *= -1; |
| 6210 | } |
| 6211 | } catch (RuntimeException e) { |
| 6212 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6213 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6214 | if(returnValue > 0) returnValue *= -1; |
| 6215 | } |
| 6216 | |
| 6217 | return returnValue; |
| 6218 | } |
| 6219 | |
| 6220 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6221 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6222 | try { |
| 6223 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6224 | } catch (RuntimeException e) { |
| 6225 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6226 | } |
| 6227 | } |
| 6228 | |
| 6229 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6230 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6231 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6232 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6233 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6234 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6235 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6236 | final long identity = Binder.clearCallingIdentity(); |
| 6237 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6238 | TelephonyPermissions |
| 6239 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6240 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6241 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6242 | } finally { |
| 6243 | Binder.restoreCallingIdentity(identity); |
| 6244 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6245 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6246 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6247 | |
| 6248 | @Override |
| 6249 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6250 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6251 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6252 | |
| 6253 | final long identity = Binder.clearCallingIdentity(); |
| 6254 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6255 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6256 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6257 | } finally { |
| 6258 | Binder.restoreCallingIdentity(identity); |
| 6259 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6260 | } |
| 6261 | |
| 6262 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6263 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6264 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6265 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6266 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6267 | return false; |
| 6268 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6269 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6270 | final long identity = Binder.clearCallingIdentity(); |
| 6271 | try { |
| 6272 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6273 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6274 | // In the long run, we may instead need to check if there exists a connection service |
| 6275 | // which can support video calling. |
| 6276 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6277 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6278 | return imsManager.isVtEnabledByPlatform() |
| 6279 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6280 | && imsManager.isVtEnabledByUser(); |
| 6281 | } finally { |
| 6282 | Binder.restoreCallingIdentity(identity); |
| 6283 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6284 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6285 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6286 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6287 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6288 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6289 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6290 | mApp, subId, callingPackage, callingFeatureId, |
| 6291 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6292 | return false; |
| 6293 | } |
| 6294 | |
| 6295 | final long identity = Binder.clearCallingIdentity(); |
| 6296 | try { |
| 6297 | CarrierConfigManager configManager = |
| 6298 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6299 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6300 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6301 | } finally { |
| 6302 | Binder.restoreCallingIdentity(identity); |
| 6303 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6304 | } |
| 6305 | |
| 6306 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6307 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6308 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6309 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6310 | return false; |
| 6311 | } |
| 6312 | |
| 6313 | final long identity = Binder.clearCallingIdentity(); |
| 6314 | try { |
| 6315 | CarrierConfigManager configManager = |
| 6316 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6317 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6318 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6319 | } finally { |
| 6320 | Binder.restoreCallingIdentity(identity); |
| 6321 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6322 | } |
| 6323 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6324 | @Override |
| 6325 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6326 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6327 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6328 | } |
| 6329 | |
| 6330 | @Override |
| 6331 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6332 | final long identity = Binder.clearCallingIdentity(); |
| 6333 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6334 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6335 | } finally { |
| 6336 | Binder.restoreCallingIdentity(identity); |
| 6337 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6338 | } |
| 6339 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6340 | /** |
| 6341 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6342 | * support for the feature and device firmware support. |
| 6343 | * |
| 6344 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6345 | */ |
| 6346 | @Override |
| 6347 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6348 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6349 | final Phone phone = getPhone(subscriptionId); |
| 6350 | if (phone == null) { |
| 6351 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6352 | return false; |
| 6353 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6354 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6355 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6356 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6357 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6358 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6359 | return isCarrierSupported && isDeviceSupported; |
| 6360 | } finally { |
| 6361 | Binder.restoreCallingIdentity(identity); |
| 6362 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6363 | } |
| 6364 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6365 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6366 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6367 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6368 | * 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] | 6369 | */ |
| 6370 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6371 | final long identity = Binder.clearCallingIdentity(); |
| 6372 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6373 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6374 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6375 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6376 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6377 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6378 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6379 | } finally { |
| 6380 | Binder.restoreCallingIdentity(identity); |
| 6381 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6382 | } |
| 6383 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6384 | @Deprecated |
| 6385 | @Override |
| 6386 | public String getDeviceId(String callingPackage) { |
| 6387 | return getDeviceIdWithFeature(callingPackage, null); |
| 6388 | } |
| 6389 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6390 | /** |
| 6391 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6392 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6393 | * |
| 6394 | * <p>Requires Permission: |
| 6395 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6396 | */ |
| 6397 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6398 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6399 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6400 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6401 | return null; |
| 6402 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6403 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6404 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6405 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6406 | return null; |
| 6407 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6408 | |
| 6409 | final long identity = Binder.clearCallingIdentity(); |
| 6410 | try { |
| 6411 | return phone.getDeviceId(); |
| 6412 | } finally { |
| 6413 | Binder.restoreCallingIdentity(identity); |
| 6414 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6415 | } |
| 6416 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6417 | /** |
| 6418 | * {@hide} |
| 6419 | * Returns the IMS Registration Status on a particular subid |
| 6420 | * |
| 6421 | * @param subId |
| 6422 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6423 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6424 | Phone phone = getPhone(subId); |
| 6425 | if (phone != null) { |
| 6426 | return phone.isImsRegistered(); |
| 6427 | } else { |
| 6428 | return false; |
| 6429 | } |
| 6430 | } |
| 6431 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6432 | @Override |
| 6433 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6434 | final long identity = Binder.clearCallingIdentity(); |
| 6435 | try { |
| 6436 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6437 | } finally { |
| 6438 | Binder.restoreCallingIdentity(identity); |
| 6439 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6440 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6441 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6442 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6443 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6444 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6445 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6446 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6447 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6448 | } |
| 6449 | final long identity = Binder.clearCallingIdentity(); |
| 6450 | try { |
| 6451 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6452 | } finally { |
| 6453 | Binder.restoreCallingIdentity(identity); |
| 6454 | } |
| 6455 | } |
| 6456 | |
| 6457 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6458 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6459 | final long identity = Binder.clearCallingIdentity(); |
| 6460 | try { |
| 6461 | Phone phone = getPhone(subscriptionId); |
| 6462 | if (phone == null) { |
| 6463 | return null; |
| 6464 | } |
| 6465 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6466 | } finally { |
| 6467 | Binder.restoreCallingIdentity(identity); |
| 6468 | } |
| 6469 | } |
| 6470 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6471 | /** |
| 6472 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6473 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6474 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6475 | final long identity = Binder.clearCallingIdentity(); |
| 6476 | try { |
| 6477 | Phone phone = getPhone(subId); |
| 6478 | if (phone != null) { |
| 6479 | return phone.isWifiCallingEnabled(); |
| 6480 | } else { |
| 6481 | return false; |
| 6482 | } |
| 6483 | } finally { |
| 6484 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6485 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6486 | } |
| 6487 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6488 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6489 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6490 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6491 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6492 | final long identity = Binder.clearCallingIdentity(); |
| 6493 | try { |
| 6494 | Phone phone = getPhone(subId); |
| 6495 | if (phone != null) { |
| 6496 | return phone.isVideoEnabled(); |
| 6497 | } else { |
| 6498 | return false; |
| 6499 | } |
| 6500 | } finally { |
| 6501 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6502 | } |
| 6503 | } |
| 6504 | |
| 6505 | /** |
| 6506 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6507 | * defined in {@link ImsRegistrationImplBase}. |
| 6508 | */ |
| 6509 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6510 | final long identity = Binder.clearCallingIdentity(); |
| 6511 | try { |
| 6512 | Phone phone = getPhone(subId); |
| 6513 | if (phone != null) { |
| 6514 | return phone.getImsRegistrationTech(); |
| 6515 | } else { |
| 6516 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6517 | } |
| 6518 | } finally { |
| 6519 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6520 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6521 | } |
| 6522 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6523 | @Override |
| 6524 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6525 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6526 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6527 | return; |
| 6528 | } |
| 6529 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6530 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6531 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6532 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6533 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6534 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6535 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6536 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6537 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6538 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6539 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6540 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6541 | // There has been issues when Sms raw table somehow stores orphan |
| 6542 | // fragments. They lead to garbled message when new fragments come |
| 6543 | // in and combined with those stale ones. In case this happens again, |
| 6544 | // user can reset all network settings which will clean up this table. |
| 6545 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6546 | // Clean up IMS settings as well here. |
| 6547 | int slotId = getSlotIndex(subId); |
| 6548 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6549 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6550 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6551 | |
| 6552 | // Erase modem config if erase modem on network setting is enabled. |
| 6553 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6554 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6555 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6556 | sendEraseModemConfig(getDefaultPhone()); |
| 6557 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6558 | } finally { |
| 6559 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6560 | } |
| 6561 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6562 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6563 | private void cleanUpSmsRawTable(Context context) { |
| 6564 | ContentResolver resolver = context.getContentResolver(); |
| 6565 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6566 | resolver.delete(uri, null, null); |
| 6567 | } |
| 6568 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6569 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6570 | public String getSimLocaleForSubscriber(int subId) { |
| 6571 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6572 | final Phone phone = getPhone(subId); |
| 6573 | if (phone == null) { |
| 6574 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6575 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6576 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6577 | final long identity = Binder.clearCallingIdentity(); |
| 6578 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6579 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6580 | phone.getContext().getOpPackageName(), phone.getContext().getFeatureId()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6581 | if (info == null) { |
| 6582 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6583 | return null; |
| 6584 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6585 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6586 | // preferences (EF-PL and EF-LI)... |
| 6587 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6588 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6589 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6590 | if (localeFromDefaultSim != null) { |
| 6591 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6592 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6593 | + localeFromDefaultSim); |
| 6594 | return localeFromDefaultSim.toLanguageTag(); |
| 6595 | } else { |
| 6596 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6597 | } |
| 6598 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6599 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6600 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6601 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6602 | // the SIM and carrier preferences does not include a country we add the country |
| 6603 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6604 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6605 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6606 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6607 | return mccLocale.toLanguageTag(); |
| 6608 | } |
| 6609 | |
| 6610 | if (DBG) log("No locale found - returning null"); |
| 6611 | return null; |
| 6612 | } finally { |
| 6613 | Binder.restoreCallingIdentity(identity); |
| 6614 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6615 | } |
| 6616 | |
| 6617 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6618 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 6619 | mApp.getFeatureId()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6620 | } |
| 6621 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6622 | /** |
| 6623 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6624 | */ |
| 6625 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6626 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 6627 | mApp.getFeatureId()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6628 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6629 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6630 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6631 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6632 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6633 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6634 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6635 | * representing the state of the modem. |
| 6636 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6637 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6638 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6639 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6640 | */ |
| 6641 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6642 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6643 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6644 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6645 | |
| 6646 | final long identity = Binder.clearCallingIdentity(); |
| 6647 | try { |
| 6648 | ModemActivityInfo ret = null; |
| 6649 | synchronized (mLastModemActivityInfo) { |
| 6650 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 6651 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6652 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6653 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6654 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6655 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6656 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6657 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6658 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6659 | } |
| 6660 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6661 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 6662 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6663 | mLastModemActivityInfo.setIdleTimeMillis( |
| 6664 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6665 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 6666 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 6667 | info.getReceiveTimeMillis() + mLastModemActivityInfo |
| 6668 | .getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6669 | } |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6670 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6671 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 6672 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 6673 | mLastModemActivityInfo.getIdleTimeMillis(), |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6674 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 6675 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6676 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6677 | Bundle bundle = new Bundle(); |
| 6678 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 6679 | result.send(0, bundle); |
| 6680 | } finally { |
| 6681 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6682 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6683 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6684 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6685 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6686 | // less than total activity duration. |
| 6687 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6688 | if (info == null) { |
| 6689 | return false; |
| 6690 | } |
| 6691 | int activityDurationMs = |
| 6692 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6693 | int totalTxTimeMs = 0; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6694 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6695 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6696 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6697 | } |
| 6698 | return (info.isValid() |
| 6699 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6700 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6701 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6702 | && (totalTxTimeMs <= activityDurationMs)); |
| 6703 | } |
| 6704 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6705 | /** |
| 6706 | * {@hide} |
| 6707 | * Returns the service state information on specified subscription. |
| 6708 | */ |
| 6709 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6710 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6711 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6712 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6713 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6714 | return null; |
| 6715 | } |
| 6716 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6717 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6718 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6719 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6720 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6721 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6722 | .setCallingPid(Binder.getCallingPid()) |
| 6723 | .setCallingUid(Binder.getCallingUid()) |
| 6724 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6725 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6726 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6727 | .build()); |
| 6728 | |
| 6729 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6730 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6731 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6732 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6733 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6734 | .setCallingPid(Binder.getCallingPid()) |
| 6735 | .setCallingUid(Binder.getCallingUid()) |
| 6736 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6737 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6738 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6739 | .build()); |
| 6740 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6741 | boolean hasFinePermission = |
| 6742 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6743 | boolean hasCoarsePermission = |
| 6744 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6745 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6746 | final long identity = Binder.clearCallingIdentity(); |
| 6747 | try { |
| 6748 | final Phone phone = getPhone(subId); |
| 6749 | if (phone == null) { |
| 6750 | return null; |
| 6751 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6752 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6753 | ServiceState ss = phone.getServiceState(); |
| 6754 | |
| 6755 | // Scrub out the location info in ServiceState depending on what level of access |
| 6756 | // the caller has. |
| 6757 | if (hasFinePermission) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6758 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6759 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6760 | } finally { |
| 6761 | Binder.restoreCallingIdentity(identity); |
| 6762 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6763 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6764 | |
| 6765 | /** |
| 6766 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6767 | * |
| 6768 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6769 | * voicemail ringtone. |
| 6770 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6771 | * PhoneAccount. |
| 6772 | */ |
| 6773 | @Override |
| 6774 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6775 | final long identity = Binder.clearCallingIdentity(); |
| 6776 | try { |
| 6777 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6778 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6779 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6780 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6781 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6782 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6783 | } finally { |
| 6784 | Binder.restoreCallingIdentity(identity); |
| 6785 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6786 | } |
| 6787 | |
| 6788 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6789 | * Sets the per-account voicemail ringtone. |
| 6790 | * |
| 6791 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6792 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6793 | * |
| 6794 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6795 | * voicemail ringtone. |
| 6796 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6797 | * PhoneAccount. |
| 6798 | */ |
| 6799 | @Override |
| 6800 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6801 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6802 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6803 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6804 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6805 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6806 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6807 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6808 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6809 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6810 | |
| 6811 | final long identity = Binder.clearCallingIdentity(); |
| 6812 | try { |
| 6813 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6814 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6815 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6816 | } |
| 6817 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6818 | } finally { |
| 6819 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6820 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6821 | } |
| 6822 | |
| 6823 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6824 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6825 | * |
| 6826 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6827 | * voicemail vibration setting. |
| 6828 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6829 | */ |
| 6830 | @Override |
| 6831 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6832 | final long identity = Binder.clearCallingIdentity(); |
| 6833 | try { |
| 6834 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6835 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6836 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6837 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6838 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6839 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6840 | } finally { |
| 6841 | Binder.restoreCallingIdentity(identity); |
| 6842 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6843 | } |
| 6844 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6845 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6846 | * Sets the per-account voicemail vibration. |
| 6847 | * |
| 6848 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6849 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6850 | * |
| 6851 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6852 | * voicemail vibration setting. |
| 6853 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6854 | * specific PhoneAccount. |
| 6855 | */ |
| 6856 | @Override |
| 6857 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6858 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6859 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6860 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6861 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6862 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6863 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6864 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6865 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6866 | } |
| 6867 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6868 | final long identity = Binder.clearCallingIdentity(); |
| 6869 | try { |
| 6870 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6871 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6872 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6873 | } |
| 6874 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6875 | } finally { |
| 6876 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6877 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6878 | } |
| 6879 | |
| 6880 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6881 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6882 | * |
| 6883 | * @throws SecurityException if the caller does not have the required permission |
| 6884 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6885 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6886 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6887 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6888 | } |
| 6889 | |
| 6890 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6891 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6892 | * permission. |
| 6893 | * |
| 6894 | * @throws SecurityException if the caller does not have the required permission |
| 6895 | */ |
| 6896 | private void enforceSendSmsPermission() { |
| 6897 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6898 | } |
| 6899 | |
| 6900 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6901 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6902 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6903 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6904 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6905 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6906 | final long identity = Binder.clearCallingIdentity(); |
| 6907 | try { |
| 6908 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6909 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6910 | if (componentName == null) { |
| 6911 | throw new SecurityException( |
| 6912 | "Caller not current active visual voicemail package[null]"); |
| 6913 | } |
| 6914 | String vvmPackage = componentName.getPackageName(); |
| 6915 | if (!callingPackage.equals(vvmPackage)) { |
| 6916 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6917 | + vvmPackage + "]"); |
| 6918 | } |
| 6919 | } finally { |
| 6920 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6921 | } |
| 6922 | } |
| 6923 | |
| 6924 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6925 | * Return the application ID for the app type. |
| 6926 | * |
| 6927 | * @param subId the subscription ID that this request applies to. |
| 6928 | * @param appType the uicc app type. |
| 6929 | * @return Application ID for specificied app type, or null if no uicc. |
| 6930 | */ |
| 6931 | @Override |
| 6932 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6933 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6934 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6935 | |
| 6936 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6937 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6938 | if (phone == null) { |
| 6939 | return null; |
| 6940 | } |
| 6941 | String aid = null; |
| 6942 | try { |
| 6943 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6944 | .getApplicationByType(appType).getAid(); |
| 6945 | } catch (Exception e) { |
| 6946 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6947 | } |
| 6948 | return aid; |
| 6949 | } finally { |
| 6950 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6951 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6952 | } |
| 6953 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6954 | /** |
| 6955 | * Return the Electronic Serial Number. |
| 6956 | * |
| 6957 | * @param subId the subscription ID that this request applies to. |
| 6958 | * @return ESN or null if error. |
| 6959 | */ |
| 6960 | @Override |
| 6961 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6962 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6963 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6964 | |
| 6965 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6966 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6967 | if (phone == null) { |
| 6968 | return null; |
| 6969 | } |
| 6970 | String esn = null; |
| 6971 | try { |
| 6972 | esn = phone.getEsn(); |
| 6973 | } catch (Exception e) { |
| 6974 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6975 | } |
| 6976 | return esn; |
| 6977 | } finally { |
| 6978 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6979 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6980 | } |
| 6981 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6982 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6983 | * Return the Preferred Roaming List Version. |
| 6984 | * |
| 6985 | * @param subId the subscription ID that this request applies to. |
| 6986 | * @return PRLVersion or null if error. |
| 6987 | */ |
| 6988 | @Override |
| 6989 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6990 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6991 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6992 | |
| 6993 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6994 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6995 | if (phone == null) { |
| 6996 | return null; |
| 6997 | } |
| 6998 | String cdmaPrlVersion = null; |
| 6999 | try { |
| 7000 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7001 | } catch (Exception e) { |
| 7002 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7003 | } |
| 7004 | return cdmaPrlVersion; |
| 7005 | } finally { |
| 7006 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7007 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7008 | } |
| 7009 | |
| 7010 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7011 | * Get snapshot of Telephony histograms |
| 7012 | * @return List of Telephony histograms |
| 7013 | * @hide |
| 7014 | */ |
| 7015 | @Override |
| 7016 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7017 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7018 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7019 | |
| 7020 | final long identity = Binder.clearCallingIdentity(); |
| 7021 | try { |
| 7022 | return RIL.getTelephonyRILTimingHistograms(); |
| 7023 | } finally { |
| 7024 | Binder.restoreCallingIdentity(identity); |
| 7025 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7026 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7027 | |
| 7028 | /** |
| 7029 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7030 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7031 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7032 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7033 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7034 | * @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] | 7035 | */ |
| 7036 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7037 | @TelephonyManager.SetCarrierRestrictionResult |
| 7038 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7039 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7040 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7041 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7042 | if (carrierRestrictionRules == null) { |
| 7043 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7044 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7045 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7046 | final long identity = Binder.clearCallingIdentity(); |
| 7047 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7048 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7049 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7050 | } finally { |
| 7051 | Binder.restoreCallingIdentity(identity); |
| 7052 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7053 | } |
| 7054 | |
| 7055 | /** |
| 7056 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7057 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7058 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7059 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7060 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7061 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7062 | */ |
| 7063 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7064 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7065 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7066 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7067 | |
| 7068 | final long identity = Binder.clearCallingIdentity(); |
| 7069 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7070 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7071 | if (response instanceof CarrierRestrictionRules) { |
| 7072 | return (CarrierRestrictionRules) response; |
| 7073 | } |
| 7074 | // Response is an Exception of some kind, |
| 7075 | // which is signalled to the user as a NULL retval |
| 7076 | return null; |
| 7077 | } catch (Exception e) { |
| 7078 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7079 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7080 | } finally { |
| 7081 | Binder.restoreCallingIdentity(identity); |
| 7082 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7083 | } |
| 7084 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7085 | /** |
| 7086 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 7087 | * @param subId the subscription ID that this action applies to. |
| 7088 | * @param enabled control enable or disable metered apns. |
| 7089 | * {@hide} |
| 7090 | */ |
| 7091 | @Override |
| 7092 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 7093 | enforceModifyPermission(); |
| 7094 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7095 | |
| 7096 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7097 | if (phone == null) { |
| 7098 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 7099 | return; |
| 7100 | } |
| 7101 | try { |
| 7102 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7103 | } catch (Exception e) { |
| 7104 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7105 | } finally { |
| 7106 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7107 | } |
| 7108 | } |
| 7109 | |
| 7110 | /** |
| 7111 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7112 | * @param subId the subscription ID that this action applies to. |
| 7113 | * @param enabled control enable or disable radio. |
| 7114 | * {@hide} |
| 7115 | */ |
| 7116 | @Override |
| 7117 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7118 | enforceModifyPermission(); |
| 7119 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7120 | |
| 7121 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7122 | if (phone == null) { |
| 7123 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7124 | return; |
| 7125 | } |
| 7126 | try { |
| 7127 | phone.carrierActionSetRadioEnabled(enabled); |
| 7128 | } catch (Exception e) { |
| 7129 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7130 | } finally { |
| 7131 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7132 | } |
| 7133 | } |
| 7134 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7135 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7136 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7137 | * network status based on which carrier apps could apply actions accordingly, |
| 7138 | * enable/disable default url handler for example. |
| 7139 | * |
| 7140 | * @param subId the subscription ID that this action applies to. |
| 7141 | * @param report control start/stop reporting the default network status. |
| 7142 | * {@hide} |
| 7143 | */ |
| 7144 | @Override |
| 7145 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7146 | enforceModifyPermission(); |
| 7147 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7148 | |
| 7149 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7150 | if (phone == null) { |
| 7151 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7152 | return; |
| 7153 | } |
| 7154 | try { |
| 7155 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7156 | } catch (Exception e) { |
| 7157 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7158 | } finally { |
| 7159 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7160 | } |
| 7161 | } |
| 7162 | |
| 7163 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7164 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7165 | * @param subId the subscription ID that this action applies to. |
| 7166 | * {@hide} |
| 7167 | */ |
| 7168 | @Override |
| 7169 | public void carrierActionResetAll(int subId) { |
| 7170 | enforceModifyPermission(); |
| 7171 | final Phone phone = getPhone(subId); |
| 7172 | if (phone == null) { |
| 7173 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7174 | return; |
| 7175 | } |
| 7176 | try { |
| 7177 | phone.carrierActionResetAll(); |
| 7178 | } catch (Exception e) { |
| 7179 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7180 | } |
| 7181 | } |
| 7182 | |
| 7183 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7184 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7185 | * bug report is being generated. |
| 7186 | */ |
| 7187 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7188 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7189 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7190 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7191 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7192 | + Binder.getCallingPid() |
| 7193 | + ", uid=" + Binder.getCallingUid() |
| 7194 | + "without permission " |
| 7195 | + android.Manifest.permission.DUMP); |
| 7196 | return; |
| 7197 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7198 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7199 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7200 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7201 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7202 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7203 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7204 | @NonNull String[] args) { |
| 7205 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7206 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7207 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7208 | } |
| 7209 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7210 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 7211 | * Get aggregated video call data usage since boot. |
| 7212 | * |
| 7213 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 7214 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7215 | * {@hide} |
| 7216 | */ |
| 7217 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 7218 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7219 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 7220 | null); |
| 7221 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7222 | final long identity = Binder.clearCallingIdentity(); |
| 7223 | try { |
| 7224 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 7225 | // records the delta with the corresponding network identity. |
| 7226 | // We just return the total video call data usage snapshot since boot. |
| 7227 | Phone phone = getPhone(subId); |
| 7228 | if (phone != null) { |
| 7229 | return phone.getVtDataUsage(perUidStats); |
| 7230 | } |
| 7231 | return null; |
| 7232 | } finally { |
| 7233 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7234 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7235 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7236 | |
| 7237 | /** |
| 7238 | * Policy control of data connection. Usually used when data limit is passed. |
| 7239 | * @param enabled True if enabling the data, otherwise disabling. |
| 7240 | * @param subId Subscription index |
| 7241 | * {@hide} |
| 7242 | */ |
| 7243 | @Override |
| 7244 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 7245 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7246 | |
| 7247 | final long identity = Binder.clearCallingIdentity(); |
| 7248 | try { |
| 7249 | Phone phone = getPhone(subId); |
| 7250 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 7251 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7252 | } |
| 7253 | } finally { |
| 7254 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7255 | } |
| 7256 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7257 | |
| 7258 | /** |
| 7259 | * Get Client request stats |
| 7260 | * @return List of Client Request Stats |
| 7261 | * @hide |
| 7262 | */ |
| 7263 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7264 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7265 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7266 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7267 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7268 | return null; |
| 7269 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7270 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7271 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7272 | final long identity = Binder.clearCallingIdentity(); |
| 7273 | try { |
| 7274 | if (phone != null) { |
| 7275 | return phone.getClientRequestStats(); |
| 7276 | } |
| 7277 | |
| 7278 | return null; |
| 7279 | } finally { |
| 7280 | Binder.restoreCallingIdentity(identity); |
| 7281 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7282 | } |
| 7283 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7284 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7285 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7286 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7287 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7288 | |
| 7289 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7290 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7291 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7292 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7293 | * @param state State of SIM (power down, power up, pass through) |
| 7294 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7295 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7296 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7297 | * |
| 7298 | **/ |
| 7299 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7300 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7301 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7302 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7303 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7304 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7305 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7306 | final long identity = Binder.clearCallingIdentity(); |
| 7307 | try { |
| 7308 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7309 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7310 | } |
| 7311 | } finally { |
| 7312 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7313 | } |
| 7314 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7315 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7316 | private boolean isUssdApiAllowed(int subId) { |
| 7317 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7318 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7319 | if (configManager == null) { |
| 7320 | return false; |
| 7321 | } |
| 7322 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7323 | if (pb == null) { |
| 7324 | return false; |
| 7325 | } |
| 7326 | return pb.getBoolean( |
| 7327 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7328 | } |
| 7329 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7330 | /** |
| 7331 | * Check if phone is in emergency callback mode |
| 7332 | * @return true if phone is in emergency callback mode |
| 7333 | * @param subId sub id |
| 7334 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7335 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7336 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7337 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7338 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7339 | |
| 7340 | final long identity = Binder.clearCallingIdentity(); |
| 7341 | try { |
| 7342 | if (phone != null) { |
| 7343 | return phone.isInEcm(); |
| 7344 | } else { |
| 7345 | return false; |
| 7346 | } |
| 7347 | } finally { |
| 7348 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7349 | } |
| 7350 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7351 | |
| 7352 | /** |
| 7353 | * Get the current signal strength information for the given subscription. |
| 7354 | * Because this information is not updated when the device is in a low power state |
| 7355 | * it should not be relied-upon to be current. |
| 7356 | * @param subId Subscription index |
| 7357 | * @return the most recent cached signal strength info from the modem |
| 7358 | */ |
| 7359 | @Override |
| 7360 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7361 | final long identity = Binder.clearCallingIdentity(); |
| 7362 | try { |
| 7363 | Phone p = getPhone(subId); |
| 7364 | if (p == null) { |
| 7365 | return null; |
| 7366 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7367 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7368 | return p.getSignalStrength(); |
| 7369 | } finally { |
| 7370 | Binder.restoreCallingIdentity(identity); |
| 7371 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7372 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7373 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7374 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7375 | * Get the current modem radio state for the given slot. |
| 7376 | * @param slotIndex slot index. |
| 7377 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7378 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7379 | * @return the current radio power state from the modem |
| 7380 | */ |
| 7381 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7382 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7383 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7384 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7385 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7386 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7387 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7388 | } |
| 7389 | |
| 7390 | final long identity = Binder.clearCallingIdentity(); |
| 7391 | try { |
| 7392 | return phone.getRadioPowerState(); |
| 7393 | } finally { |
| 7394 | Binder.restoreCallingIdentity(identity); |
| 7395 | } |
| 7396 | } |
| 7397 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7398 | } |
| 7399 | |
| 7400 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7401 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7402 | * |
| 7403 | * <p>Requires one of the following permissions: |
| 7404 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7405 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7406 | * privileges. |
| 7407 | * |
| 7408 | * @param subId subscription id |
| 7409 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7410 | * {@code false}. |
| 7411 | */ |
| 7412 | @Override |
| 7413 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7414 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7415 | null /* message */); |
| 7416 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7417 | boolean isEnabled = false; |
| 7418 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7419 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7420 | Phone phone = getPhone(subId); |
| 7421 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7422 | } catch (Exception e) { |
| 7423 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7424 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7425 | } finally { |
| 7426 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7427 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7428 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7429 | } |
| 7430 | |
| 7431 | |
| 7432 | /** |
| 7433 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7434 | * |
| 7435 | * <p> Requires permission: |
| 7436 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7437 | * privileges. |
| 7438 | * |
| 7439 | * @param subId subscription id |
| 7440 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7441 | */ |
| 7442 | @Override |
| 7443 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7444 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7445 | mApp, subId, "setDataRoamingEnabled"); |
| 7446 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7447 | final long identity = Binder.clearCallingIdentity(); |
| 7448 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7449 | Phone phone = getPhone(subId); |
| 7450 | if (phone != null) { |
| 7451 | phone.setDataRoamingEnabled(isEnabled); |
| 7452 | } |
| 7453 | } finally { |
| 7454 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7455 | } |
| 7456 | } |
| 7457 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7458 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7459 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7460 | TelephonyPermissions |
| 7461 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7462 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7463 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7464 | boolean isAllowed = true; |
| 7465 | final long identity = Binder.clearCallingIdentity(); |
| 7466 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7467 | Phone phone = getPhone(subId); |
| 7468 | if (phone != null) { |
| 7469 | isAllowed = phone.isCspPlmnEnabled(); |
| 7470 | } |
| 7471 | } finally { |
| 7472 | Binder.restoreCallingIdentity(identity); |
| 7473 | } |
| 7474 | return isAllowed; |
| 7475 | } |
| 7476 | |
| 7477 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7478 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7479 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7480 | try { |
| 7481 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7482 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7483 | } catch (SecurityException e) { |
| 7484 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7485 | // has carrier privileges on an active UICC |
| 7486 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7487 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7488 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7489 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7490 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7491 | |
| 7492 | final long identity = Binder.clearCallingIdentity(); |
| 7493 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7494 | UiccController uiccController = UiccController.getInstance(); |
| 7495 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7496 | if (hasReadPermission) { |
| 7497 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7498 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7499 | |
| 7500 | // Remove private info if the caller doesn't have access |
| 7501 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7502 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7503 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7504 | // is available |
| 7505 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7506 | if (card == null || card.getUiccProfile() == null) { |
| 7507 | // assume no access if the card or profile is unavailable |
| 7508 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7509 | continue; |
| 7510 | } |
| 7511 | UiccProfile profile = card.getUiccProfile(); |
| 7512 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7513 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7514 | filteredInfos.add(cardInfo); |
| 7515 | } else { |
| 7516 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7517 | } |
| 7518 | } |
| 7519 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7520 | } finally { |
| 7521 | Binder.restoreCallingIdentity(identity); |
| 7522 | } |
| 7523 | } |
| 7524 | |
| 7525 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7526 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7527 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7528 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7529 | final long identity = Binder.clearCallingIdentity(); |
| 7530 | try { |
| 7531 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7532 | if (slots == null) { |
| 7533 | Rlog.i(LOG_TAG, "slots is null."); |
| 7534 | return null; |
| 7535 | } |
| 7536 | |
| 7537 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7538 | for (int i = 0; i < slots.length; i++) { |
| 7539 | UiccSlot slot = slots[i]; |
| 7540 | if (slot == null) { |
| 7541 | continue; |
| 7542 | } |
| 7543 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7544 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7545 | UiccCard card = slot.getUiccCard(); |
| 7546 | if (card != null) { |
| 7547 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7548 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7549 | cardId = slot.getEid(); |
| 7550 | if (TextUtils.isEmpty(cardId)) { |
| 7551 | cardId = slot.getIccId(); |
| 7552 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7553 | } |
| 7554 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7555 | if (cardId != null) { |
| 7556 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7557 | // if cardId is an EID, it's all digits so this is fine |
| 7558 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7559 | } |
| 7560 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7561 | int cardState = 0; |
| 7562 | switch (slot.getCardState()) { |
| 7563 | case CARDSTATE_ABSENT: |
| 7564 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7565 | break; |
| 7566 | case CARDSTATE_PRESENT: |
| 7567 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7568 | break; |
| 7569 | case CARDSTATE_ERROR: |
| 7570 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7571 | break; |
| 7572 | case CARDSTATE_RESTRICTED: |
| 7573 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7574 | break; |
| 7575 | default: |
| 7576 | break; |
| 7577 | |
| 7578 | } |
| 7579 | |
| 7580 | infos[i] = new UiccSlotInfo( |
| 7581 | slot.isActive(), |
| 7582 | slot.isEuicc(), |
| 7583 | cardId, |
| 7584 | cardState, |
| 7585 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7586 | slot.isExtendedApduSupported(), |
| 7587 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7588 | } |
| 7589 | return infos; |
| 7590 | } finally { |
| 7591 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7592 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7593 | } |
| 7594 | |
| 7595 | @Override |
| 7596 | public boolean switchSlots(int[] physicalSlots) { |
| 7597 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7598 | |
| 7599 | final long identity = Binder.clearCallingIdentity(); |
| 7600 | try { |
| 7601 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7602 | } finally { |
| 7603 | Binder.restoreCallingIdentity(identity); |
| 7604 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7605 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7606 | |
| 7607 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7608 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7609 | final long identity = Binder.clearCallingIdentity(); |
| 7610 | try { |
| 7611 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7612 | } finally { |
| 7613 | Binder.restoreCallingIdentity(identity); |
| 7614 | } |
| 7615 | } |
| 7616 | |
| 7617 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7618 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 7619 | enforceModifyPermission(); |
| 7620 | final Phone phone = getPhone(subId); |
| 7621 | if (phone == null) { |
| 7622 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 7623 | return; |
| 7624 | } |
| 7625 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7626 | final long identity = Binder.clearCallingIdentity(); |
| 7627 | try { |
| 7628 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 7629 | } finally { |
| 7630 | Binder.restoreCallingIdentity(identity); |
| 7631 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7632 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7633 | |
| 7634 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7635 | * A test API to reload the UICC profile. |
| 7636 | * |
| 7637 | * <p>Requires that the calling app has permission |
| 7638 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7639 | * @hide |
| 7640 | */ |
| 7641 | @Override |
| 7642 | public void refreshUiccProfile(int subId) { |
| 7643 | enforceModifyPermission(); |
| 7644 | |
| 7645 | final long identity = Binder.clearCallingIdentity(); |
| 7646 | try { |
| 7647 | Phone phone = getPhone(subId); |
| 7648 | if (phone == null) { |
| 7649 | return; |
| 7650 | } |
| 7651 | UiccCard uiccCard = phone.getUiccCard(); |
| 7652 | if (uiccCard == null) { |
| 7653 | return; |
| 7654 | } |
| 7655 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7656 | if (uiccProfile == null) { |
| 7657 | return; |
| 7658 | } |
| 7659 | uiccProfile.refresh(); |
| 7660 | } finally { |
| 7661 | Binder.restoreCallingIdentity(identity); |
| 7662 | } |
| 7663 | } |
| 7664 | |
| 7665 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7666 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7667 | */ |
| 7668 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7669 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7670 | } |
| 7671 | |
| 7672 | /** |
| 7673 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7674 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7675 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7676 | */ |
| 7677 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7678 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7679 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7680 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7681 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7682 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7683 | return isDataRoamingEnabled; |
| 7684 | } |
| 7685 | |
| 7686 | /** |
| 7687 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7688 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7689 | */ |
| 7690 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7691 | List<Integer> list = TelephonyProperties.default_network(); |
| 7692 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7693 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7694 | return list.get(phoneId); |
| 7695 | } |
| 7696 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7697 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7698 | |
| 7699 | @Override |
| 7700 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7701 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7702 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7703 | |
| 7704 | final long identity = Binder.clearCallingIdentity(); |
| 7705 | try { |
| 7706 | final Phone phone = getPhone(subId); |
| 7707 | if (phone == null) { |
| 7708 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7709 | return; |
| 7710 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7711 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7712 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7713 | } finally { |
| 7714 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7715 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7716 | } |
| 7717 | |
| 7718 | @Override |
| 7719 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7720 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7721 | |
| 7722 | final long identity = Binder.clearCallingIdentity(); |
| 7723 | try { |
| 7724 | final Phone phone = getPhone(subId); |
| 7725 | if (phone == null) { |
| 7726 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7727 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7728 | } |
| 7729 | return phone.getCarrierIdListVersion(); |
| 7730 | } finally { |
| 7731 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7732 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7733 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7734 | |
| 7735 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7736 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7737 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7738 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7739 | mApp, subId, callingPackage, callingFeatureId, |
| 7740 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7741 | return -1; |
| 7742 | } |
| 7743 | |
| 7744 | final long identity = Binder.clearCallingIdentity(); |
| 7745 | try { |
| 7746 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7747 | } finally { |
| 7748 | Binder.restoreCallingIdentity(identity); |
| 7749 | } |
| 7750 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7751 | |
| 7752 | @Override |
| 7753 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7754 | TelephonyPermissions |
| 7755 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7756 | mApp, subId, "getCdmaRoamingMode"); |
| 7757 | |
| 7758 | final long identity = Binder.clearCallingIdentity(); |
| 7759 | try { |
| 7760 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7761 | } finally { |
| 7762 | Binder.restoreCallingIdentity(identity); |
| 7763 | } |
| 7764 | } |
| 7765 | |
| 7766 | @Override |
| 7767 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7768 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7769 | mApp, subId, "setCdmaRoamingMode"); |
| 7770 | |
| 7771 | final long identity = Binder.clearCallingIdentity(); |
| 7772 | try { |
| 7773 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7774 | } finally { |
| 7775 | Binder.restoreCallingIdentity(identity); |
| 7776 | } |
| 7777 | } |
| 7778 | |
| 7779 | @Override |
| 7780 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7781 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7782 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7783 | |
| 7784 | final long identity = Binder.clearCallingIdentity(); |
| 7785 | try { |
| 7786 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7787 | } finally { |
| 7788 | Binder.restoreCallingIdentity(identity); |
| 7789 | } |
| 7790 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7791 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7792 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7793 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7794 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7795 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7796 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7797 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7798 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7799 | } |
| 7800 | final long identity = Binder.clearCallingIdentity(); |
| 7801 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7802 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7803 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7804 | if (phone.getEmergencyNumberTracker() != null |
| 7805 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7806 | emergencyNumberListInternal.put( |
| 7807 | phone.getSubId(), |
| 7808 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7809 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7810 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7811 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7812 | } finally { |
| 7813 | Binder.restoreCallingIdentity(identity); |
| 7814 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7815 | } |
| 7816 | |
| 7817 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7818 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7819 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7820 | if (!exactMatch) { |
| 7821 | TelephonyPermissions |
| 7822 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7823 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7824 | } |
| 7825 | final long identity = Binder.clearCallingIdentity(); |
| 7826 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7827 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7828 | if (phone.getEmergencyNumberTracker() != null |
| 7829 | && phone.getEmergencyNumberTracker() != null) { |
| 7830 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7831 | number, exactMatch)) { |
| 7832 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7833 | } |
| 7834 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7835 | } |
| 7836 | return false; |
| 7837 | } finally { |
| 7838 | Binder.restoreCallingIdentity(identity); |
| 7839 | } |
| 7840 | } |
| 7841 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7842 | /** |
| 7843 | * Update emergency number list for test mode. |
| 7844 | */ |
| 7845 | @Override |
| 7846 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7847 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7848 | "updateEmergencyNumberListTestMode"); |
| 7849 | |
| 7850 | final long identity = Binder.clearCallingIdentity(); |
| 7851 | try { |
| 7852 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7853 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7854 | if (tracker != null) { |
| 7855 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7856 | } |
| 7857 | } |
| 7858 | } finally { |
| 7859 | Binder.restoreCallingIdentity(identity); |
| 7860 | } |
| 7861 | } |
| 7862 | |
| 7863 | /** |
| 7864 | * Get the full emergency number list for test mode. |
| 7865 | */ |
| 7866 | @Override |
| 7867 | public List<String> getEmergencyNumberListTestMode() { |
| 7868 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7869 | "getEmergencyNumberListTestMode"); |
| 7870 | |
| 7871 | final long identity = Binder.clearCallingIdentity(); |
| 7872 | try { |
| 7873 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7874 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7875 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7876 | if (tracker != null) { |
| 7877 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7878 | emergencyNumbers.add(num.getNumber()); |
| 7879 | } |
| 7880 | } |
| 7881 | } |
| 7882 | return new ArrayList<>(emergencyNumbers); |
| 7883 | } finally { |
| 7884 | Binder.restoreCallingIdentity(identity); |
| 7885 | } |
| 7886 | } |
| 7887 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7888 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7889 | public int getEmergencyNumberDbVersion(int subId) { |
| 7890 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7891 | |
| 7892 | final long identity = Binder.clearCallingIdentity(); |
| 7893 | try { |
| 7894 | final Phone phone = getPhone(subId); |
| 7895 | if (phone == null) { |
| 7896 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7897 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7898 | } |
| 7899 | return phone.getEmergencyNumberDbVersion(); |
| 7900 | } finally { |
| 7901 | Binder.restoreCallingIdentity(identity); |
| 7902 | } |
| 7903 | } |
| 7904 | |
| 7905 | @Override |
| 7906 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7907 | enforceModifyPermission(); |
| 7908 | |
| 7909 | final long identity = Binder.clearCallingIdentity(); |
| 7910 | try { |
| 7911 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7912 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7913 | if (tracker != null) { |
| 7914 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7915 | } |
| 7916 | } |
| 7917 | } finally { |
| 7918 | Binder.restoreCallingIdentity(identity); |
| 7919 | } |
| 7920 | } |
| 7921 | |
| 7922 | @Override |
| 7923 | public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) { |
| 7924 | enforceActiveEmergencySessionPermission(); |
| 7925 | |
| 7926 | final long identity = Binder.clearCallingIdentity(); |
| 7927 | try { |
| 7928 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7929 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7930 | if (tracker != null) { |
| 7931 | tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath); |
| 7932 | } |
| 7933 | } |
| 7934 | } finally { |
| 7935 | Binder.restoreCallingIdentity(identity); |
| 7936 | } |
| 7937 | } |
| 7938 | |
| 7939 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7940 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7941 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7942 | Phone phone = getPhone(subId); |
| 7943 | if (phone == null) { |
| 7944 | return null; |
| 7945 | } |
| 7946 | final long identity = Binder.clearCallingIdentity(); |
| 7947 | try { |
| 7948 | UiccProfile profile = UiccController.getInstance() |
| 7949 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7950 | if (profile != null) { |
| 7951 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7952 | } |
| 7953 | } finally { |
| 7954 | Binder.restoreCallingIdentity(identity); |
| 7955 | } |
| 7956 | return null; |
| 7957 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7958 | |
| 7959 | /** |
| 7960 | * Enable or disable a modem stack. |
| 7961 | */ |
| 7962 | @Override |
| 7963 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7964 | enforceModifyPermission(); |
| 7965 | |
| 7966 | final long identity = Binder.clearCallingIdentity(); |
| 7967 | try { |
| 7968 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7969 | if (phone == null) { |
| 7970 | return false; |
| 7971 | } else { |
| 7972 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7973 | } |
| 7974 | } finally { |
| 7975 | Binder.restoreCallingIdentity(identity); |
| 7976 | } |
| 7977 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7978 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7979 | /** |
| 7980 | * Whether a modem stack is enabled or not. |
| 7981 | */ |
| 7982 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7983 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7984 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7985 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7986 | if (phone == null) return false; |
| 7987 | |
| 7988 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7989 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7990 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7991 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7992 | } |
| 7993 | |
| 7994 | final long identity = Binder.clearCallingIdentity(); |
| 7995 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7996 | try { |
| 7997 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7998 | } catch (NoSuchElementException ex) { |
| 7999 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8000 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8001 | } finally { |
| 8002 | Binder.restoreCallingIdentity(identity); |
| 8003 | } |
| 8004 | } |
| 8005 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8006 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8007 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8008 | enforceModifyPermission(); |
| 8009 | |
| 8010 | final long identity = Binder.clearCallingIdentity(); |
| 8011 | try { |
| 8012 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8013 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8014 | .commit(); |
| 8015 | } finally { |
| 8016 | Binder.restoreCallingIdentity(identity); |
| 8017 | } |
| 8018 | } |
| 8019 | |
| 8020 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8021 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8022 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8023 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8024 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8025 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8026 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8027 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8028 | |
| 8029 | final long identity = Binder.clearCallingIdentity(); |
| 8030 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8031 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8032 | } finally { |
| 8033 | Binder.restoreCallingIdentity(identity); |
| 8034 | } |
| 8035 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8036 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8037 | @TelephonyManager.IsMultiSimSupportedResult |
| 8038 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8039 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8040 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8041 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8042 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8043 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8044 | } |
| 8045 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8046 | // supported by the modem, indicate that it is restricted. |
| 8047 | PhoneCapability staticCapability = |
| 8048 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8049 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8050 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8051 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8052 | } |
Sarah Chin | 0605abf | 2019-12-06 10:24:18 -0800 | [diff] [blame] | 8053 | if (staticCapability.getLogicalModemUuids().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8054 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8055 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8056 | } |
| 8057 | // Check if support of multiple SIMs is restricted by carrier |
| 8058 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8059 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8060 | } |
| 8061 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8062 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8063 | } |
| 8064 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8065 | /** |
| 8066 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8067 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8068 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8069 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8070 | * @param numOfSims number of active sims we want to switch to |
| 8071 | */ |
| 8072 | @Override |
| 8073 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8074 | if (numOfSims == 1) { |
| 8075 | enforceModifyPermission(); |
| 8076 | } else { |
| 8077 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8078 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8079 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8080 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8081 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8082 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8083 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8084 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8085 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8086 | return; |
| 8087 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8088 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8089 | } finally { |
| 8090 | Binder.restoreCallingIdentity(identity); |
| 8091 | } |
| 8092 | } |
| 8093 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8094 | @Override |
| 8095 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8096 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8097 | Phone phone = getPhone(subId); |
| 8098 | if (phone == null) { |
| 8099 | return false; |
| 8100 | } |
| 8101 | final long identity = Binder.clearCallingIdentity(); |
| 8102 | try { |
| 8103 | UiccCard uiccCard = phone.getUiccCard(); |
| 8104 | if (uiccCard == null) { |
| 8105 | return false; |
| 8106 | } |
| 8107 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8108 | if (uiccProfile == null) { |
| 8109 | return false; |
| 8110 | } |
| 8111 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8112 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8113 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8114 | } |
| 8115 | return false; |
| 8116 | } finally { |
| 8117 | Binder.restoreCallingIdentity(identity); |
| 8118 | } |
| 8119 | } |
| 8120 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8121 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8122 | * Get whether making changes to modem configurations will trigger reboot. |
| 8123 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8124 | */ |
| 8125 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8126 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8127 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8128 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8129 | mApp, subId, callingPackage, callingFeatureId, |
| 8130 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8131 | return false; |
| 8132 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8133 | final long identity = Binder.clearCallingIdentity(); |
| 8134 | try { |
| 8135 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8136 | } finally { |
| 8137 | Binder.restoreCallingIdentity(identity); |
| 8138 | } |
| 8139 | } |
| 8140 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8141 | private void updateModemStateMetrics() { |
| 8142 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8143 | // TODO: check the state for each modem if the api is ready. |
| 8144 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8145 | } |
| 8146 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8147 | @Override |
| 8148 | public int[] getSlotsMapping() { |
| 8149 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8150 | |
| 8151 | final long identity = Binder.clearCallingIdentity(); |
| 8152 | try { |
| 8153 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8154 | // All logical slots should have a mapping to a physical slot. |
| 8155 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8156 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8157 | for (int i = 0; i < slotInfos.length; i++) { |
| 8158 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8159 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8160 | } |
| 8161 | } |
| 8162 | return logicalSlotsMapping; |
| 8163 | } finally { |
| 8164 | Binder.restoreCallingIdentity(identity); |
| 8165 | } |
| 8166 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8167 | |
| 8168 | /** |
| 8169 | * Get the IRadio HAL Version |
| 8170 | */ |
| 8171 | @Override |
| 8172 | public int getRadioHalVersion() { |
| 8173 | Phone phone = getDefaultPhone(); |
| 8174 | if (phone == null) return -1; |
| 8175 | HalVersion hv = phone.getHalVersion(); |
| 8176 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8177 | return hv.major * 100 + hv.minor; |
| 8178 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8179 | |
| 8180 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8181 | * Get the current calling package name. |
| 8182 | * @return the current calling package name |
| 8183 | */ |
| 8184 | @Override |
| 8185 | public String getCurrentPackageName() { |
| 8186 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8187 | } |
| 8188 | |
| 8189 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8190 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8191 | * corresponding network requests on a subId. |
| 8192 | * |
| 8193 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8194 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8195 | * 2) APN is un-metered for this subscription, or |
| 8196 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8197 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8198 | * |
| 8199 | * @return whether data is allowed for a apn type. |
| 8200 | * |
| 8201 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8202 | */ |
| 8203 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8204 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8205 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8206 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8207 | |
| 8208 | // Now that all security checks passes, perform the operation as ourselves. |
| 8209 | final long identity = Binder.clearCallingIdentity(); |
| 8210 | try { |
| 8211 | Phone phone = getPhone(subId); |
| 8212 | if (phone == null) return false; |
| 8213 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8214 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8215 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8216 | } finally { |
| 8217 | Binder.restoreCallingIdentity(identity); |
| 8218 | } |
| 8219 | } |
| 8220 | |
| 8221 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8222 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8223 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8224 | |
| 8225 | // Now that all security checks passes, perform the operation as ourselves. |
| 8226 | final long identity = Binder.clearCallingIdentity(); |
| 8227 | try { |
| 8228 | Phone phone = getPhone(subId); |
| 8229 | if (phone == null) return true; // By default return true. |
| 8230 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8231 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8232 | } finally { |
| 8233 | Binder.restoreCallingIdentity(identity); |
| 8234 | } |
| 8235 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8236 | |
| 8237 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8238 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8239 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8240 | enforceModifyPermission(); |
| 8241 | long token = Binder.clearCallingIdentity(); |
| 8242 | try { |
| 8243 | Phone phone = getPhone(subscriptionId); |
| 8244 | if (phone == null) { |
| 8245 | try { |
| 8246 | if (resultCallback != null) { |
| 8247 | resultCallback.accept(false); |
| 8248 | } |
| 8249 | } catch (RemoteException e) { |
| 8250 | // ignore |
| 8251 | } |
| 8252 | return; |
| 8253 | } |
| 8254 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8255 | Pair.create(specifiers, (x) -> { |
| 8256 | try { |
| 8257 | if (resultCallback != null) { |
| 8258 | resultCallback.accept(x); |
| 8259 | } |
| 8260 | } catch (RemoteException e) { |
| 8261 | // ignore |
| 8262 | } |
| 8263 | }); |
| 8264 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8265 | } finally { |
| 8266 | Binder.restoreCallingIdentity(token); |
| 8267 | } |
| 8268 | } |
| 8269 | |
| 8270 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8271 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
| 8272 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8273 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8274 | if (iccRecords == null) { |
| 8275 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8276 | return false; |
| 8277 | } |
| 8278 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8279 | } |
| 8280 | |
| 8281 | @Override |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8282 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8283 | if (callingPackage == null) { |
| 8284 | callingPackage = getCurrentPackageName(); |
| 8285 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8286 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8287 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 8288 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 8289 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8290 | } |
| 8291 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8292 | Intent intent = new Intent(); |
| 8293 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8294 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8295 | // Bring up choose default SMS subscription dialog right now |
| 8296 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8297 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8298 | mApp.startActivity(intent); |
| 8299 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8300 | |
| 8301 | @Override |
| 8302 | public String getMmsUAProfUrl(int subId) { |
| 8303 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8304 | final long identity = Binder.clearCallingIdentity(); |
| 8305 | try { |
| 8306 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8307 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 8308 | } finally { |
| 8309 | Binder.restoreCallingIdentity(identity); |
| 8310 | } |
| 8311 | } |
| 8312 | |
| 8313 | @Override |
| 8314 | public String getMmsUserAgent(int subId) { |
| 8315 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8316 | final long identity = Binder.clearCallingIdentity(); |
| 8317 | try { |
| 8318 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8319 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8320 | } finally { |
| 8321 | Binder.restoreCallingIdentity(identity); |
| 8322 | } |
| 8323 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8324 | |
| 8325 | @Override |
| 8326 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 8327 | enforceModifyPermission(); |
| 8328 | |
| 8329 | // Now that all security checks passes, perform the operation as ourselves. |
| 8330 | final long identity = Binder.clearCallingIdentity(); |
| 8331 | try { |
| 8332 | Phone phone = getPhone(subId); |
| 8333 | if (phone == null) return false; |
| 8334 | |
| 8335 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 8336 | } finally { |
| 8337 | Binder.restoreCallingIdentity(identity); |
| 8338 | } |
| 8339 | } |
| 8340 | |
| 8341 | @Override |
| 8342 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 8343 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 8344 | |
| 8345 | // Now that all security checks passes, perform the operation as ourselves. |
| 8346 | final long identity = Binder.clearCallingIdentity(); |
| 8347 | try { |
| 8348 | Phone phone = getPhone(subId); |
| 8349 | if (phone == null) return false; |
| 8350 | |
| 8351 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8352 | } finally { |
| 8353 | Binder.restoreCallingIdentity(identity); |
| 8354 | } |
| 8355 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8356 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8357 | @Override |
| 8358 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8359 | enforceModifyPermission(); |
| 8360 | |
| 8361 | // Now that all security checks passes, perform the operation as ourselves. |
| 8362 | final long identity = Binder.clearCallingIdentity(); |
| 8363 | try { |
| 8364 | Phone phone = getPhone(subId); |
| 8365 | if (phone == null) return false; |
| 8366 | |
| 8367 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8368 | } finally { |
| 8369 | Binder.restoreCallingIdentity(identity); |
| 8370 | } |
| 8371 | } |
| 8372 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8373 | /** |
| 8374 | * Updates whether conference event pacakge handling is enabled. |
| 8375 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8376 | * otherwise. |
| 8377 | */ |
| 8378 | @Override |
| 8379 | public void setCepEnabled(boolean isCepEnabled) { |
| 8380 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8381 | |
| 8382 | final long identity = Binder.clearCallingIdentity(); |
| 8383 | try { |
| 8384 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8385 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8386 | Phone defaultPhone = phone.getImsPhone(); |
| 8387 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8388 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8389 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8390 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8391 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8392 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8393 | + imsPhone.getMsisdn()); |
| 8394 | } |
| 8395 | } |
| 8396 | } finally { |
| 8397 | Binder.restoreCallingIdentity(identity); |
| 8398 | } |
| 8399 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8400 | |
| 8401 | /** |
| 8402 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8403 | * |
| 8404 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8405 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8406 | * before being read. |
| 8407 | */ |
| 8408 | @Override |
| 8409 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8410 | isCompressed) { |
| 8411 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8412 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8413 | try { |
| 8414 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8415 | if (configBinder == null) { |
| 8416 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8417 | } else { |
| 8418 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8419 | } |
| 8420 | } catch (RemoteException e) { |
| 8421 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8422 | } |
| 8423 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8424 | |
| 8425 | @Override |
| 8426 | public boolean isIccLockEnabled(int subId) { |
| 8427 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8428 | |
| 8429 | // Now that all security checks passes, perform the operation as ourselves. |
| 8430 | final long identity = Binder.clearCallingIdentity(); |
| 8431 | try { |
| 8432 | Phone phone = getPhone(subId); |
| 8433 | if (phone != null && phone.getIccCard() != null) { |
| 8434 | return phone.getIccCard().getIccLockEnabled(); |
| 8435 | } else { |
| 8436 | return false; |
| 8437 | } |
| 8438 | } finally { |
| 8439 | Binder.restoreCallingIdentity(identity); |
| 8440 | } |
| 8441 | } |
| 8442 | |
| 8443 | /** |
| 8444 | * Set the ICC pin lock enabled or disabled. |
| 8445 | * |
| 8446 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 8447 | * three cases: |
| 8448 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 8449 | * successfully. |
| 8450 | * - Positive number and zero for remaining password attempts. |
| 8451 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8452 | * |
| 8453 | */ |
| 8454 | @Override |
| 8455 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8456 | enforceModifyPermission(); |
| 8457 | |
| 8458 | Phone phone = getPhone(subId); |
| 8459 | if (phone == null) { |
| 8460 | return 0; |
| 8461 | } |
| 8462 | // Now that all security checks passes, perform the operation as ourselves. |
| 8463 | final long identity = Binder.clearCallingIdentity(); |
| 8464 | try { |
| 8465 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8466 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8467 | return attemptsRemaining; |
| 8468 | |
| 8469 | } catch (Exception e) { |
| 8470 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8471 | } finally { |
| 8472 | Binder.restoreCallingIdentity(identity); |
| 8473 | } |
| 8474 | return 0; |
| 8475 | } |
| 8476 | |
| 8477 | /** |
| 8478 | * Change the ICC password used in ICC pin lock. |
| 8479 | * |
| 8480 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 8481 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 8482 | * - Positive number and zero for remaining password attempts. |
| 8483 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8484 | * |
| 8485 | */ |
| 8486 | @Override |
| 8487 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8488 | enforceModifyPermission(); |
| 8489 | |
| 8490 | Phone phone = getPhone(subId); |
| 8491 | if (phone == null) { |
| 8492 | return 0; |
| 8493 | } |
| 8494 | // Now that all security checks passes, perform the operation as ourselves. |
| 8495 | final long identity = Binder.clearCallingIdentity(); |
| 8496 | try { |
| 8497 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8498 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8499 | return attemptsRemaining; |
| 8500 | |
| 8501 | } catch (Exception e) { |
| 8502 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8503 | } finally { |
| 8504 | Binder.restoreCallingIdentity(identity); |
| 8505 | } |
| 8506 | return 0; |
| 8507 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 8508 | |
| 8509 | /** |
| 8510 | * Request for receiving user activity notification |
| 8511 | */ |
| 8512 | @Override |
| 8513 | public void requestUserActivityNotification() { |
| 8514 | if (!mNotifyUserActivity.get() |
| 8515 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 8516 | mNotifyUserActivity.set(true); |
| 8517 | } |
| 8518 | } |
| 8519 | |
| 8520 | /** |
| 8521 | * Called when userActivity is signalled in the power manager. |
| 8522 | * This is safe to call from any thread, with any window manager locks held or not. |
| 8523 | */ |
| 8524 | @Override |
| 8525 | public void userActivity() { |
| 8526 | // *************************************** |
| 8527 | // * Inherited from PhoneWindowManager * |
| 8528 | // *************************************** |
| 8529 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 8530 | // WITH ITS LOCKS HELD. |
| 8531 | // |
| 8532 | // This code must be VERY careful about the locks |
| 8533 | // it acquires. |
| 8534 | // In fact, the current code acquires way too many, |
| 8535 | // and probably has lurking deadlocks. |
| 8536 | |
| 8537 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 8538 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 8539 | } |
| 8540 | |
| 8541 | if (mNotifyUserActivity.getAndSet(false)) { |
| 8542 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 8543 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 8544 | } |
| 8545 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8546 | } |