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; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 25 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 26 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 27 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 28 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 29 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 30 | import android.content.Context; |
| 31 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 32 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 33 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 34 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 35 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 36 | import android.content.pm.PackageManager; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 37 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 48 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 49 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 50 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 51 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | import android.os.ServiceManager; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 53 | import android.os.ServiceSpecificException; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 54 | import android.os.ShellCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 56 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 57 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 58 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 59 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 60 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 61 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 62 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 64 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 65 | import android.telephony.Annotation.ApnType; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 66 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 67 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 68 | import android.telephony.CellIdentity; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 69 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 70 | import android.telephony.CellInfoGsm; |
| 71 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 72 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 73 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 74 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 75 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 76 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 77 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 78 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 79 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 80 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 81 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 82 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 83 | import android.telephony.RadioAccessSpecifier; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 84 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 85 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 86 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 87 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 88 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 89 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 90 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 91 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 92 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 93 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 94 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 95 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 96 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 97 | import android.telephony.data.ApnSetting; |
| 98 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 99 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 100 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 101 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 102 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 103 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 107 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 108 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 109 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 110 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 111 | import android.telephony.ims.feature.MmTelFeature; |
| 112 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 113 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 114 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 115 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 116 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 117 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 118 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 119 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 120 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 121 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 125 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 129 | import com.android.internal.telephony.HalVersion; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 131 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 135 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 156 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.uicc.IccIoResult; |
| 160 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 168 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 169 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 170 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 171 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 172 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 173 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 174 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 175 | import java.io.FileDescriptor; |
| 176 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 177 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 178 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 179 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 180 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 181 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 182 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 183 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 184 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 185 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 186 | |
| 187 | /** |
| 188 | * Implementation of the ITelephony interface. |
| 189 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 190 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 191 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 192 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 193 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 194 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 195 | |
| 196 | // Message codes used with mMainThreadHandler |
| 197 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 198 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 199 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 200 | private static final int CMD_OPEN_CHANNEL = 9; |
| 201 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 202 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 203 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 204 | private static final int CMD_NV_READ_ITEM = 13; |
| 205 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 206 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 207 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 208 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 209 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 210 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 211 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 212 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 213 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 214 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 215 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 216 | private static final int CMD_SEND_ENVELOPE = 25; |
| 217 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 218 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 219 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 220 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 221 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 222 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 223 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 224 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 225 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 226 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 227 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 228 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 229 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 230 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 231 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 232 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 233 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 234 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 235 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 236 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 237 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 238 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 239 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 240 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 241 | private static final int CMD_SWITCH_SLOTS = 50; |
| 242 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 243 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 244 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 245 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 246 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 247 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 248 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 249 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 250 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 251 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 252 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 253 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 254 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 255 | private static final int CMD_MODEM_REBOOT = 64; |
| 256 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 257 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 258 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 259 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 260 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 261 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 262 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 263 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 264 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 265 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 266 | // Parameters of select command. |
| 267 | private static final int SELECT_COMMAND = 0xA4; |
| 268 | private static final int SELECT_P1 = 0x04; |
| 269 | private static final int SELECT_P2 = 0; |
| 270 | private static final int SELECT_P3 = 0x10; |
| 271 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 272 | /** The singleton instance. */ |
| 273 | private static PhoneInterfaceManager sInstance; |
| 274 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 275 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 276 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 277 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 278 | private AppOpsManager mAppOps; |
| 279 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 280 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 281 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 282 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 283 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 284 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 285 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 286 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 287 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 288 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 289 | // String to store multi SIM allowed |
| 290 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 291 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 292 | // The AID of ISD-R. |
| 293 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 294 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 295 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 296 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 297 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 298 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 299 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 300 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 301 | * A request object to use for transmitting data to an ICC. |
| 302 | */ |
| 303 | private static final class IccAPDUArgument { |
| 304 | public int channel, cla, command, p1, p2, p3; |
| 305 | public String data; |
| 306 | |
| 307 | public IccAPDUArgument(int channel, int cla, int command, |
| 308 | int p1, int p2, int p3, String data) { |
| 309 | this.channel = channel; |
| 310 | this.cla = cla; |
| 311 | this.command = command; |
| 312 | this.p1 = p1; |
| 313 | this.p2 = p2; |
| 314 | this.p3 = p3; |
| 315 | this.data = data; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 320 | * A request object to use for transmitting data to an ICC. |
| 321 | */ |
| 322 | private static final class ManualNetworkSelectionArgument { |
| 323 | public OperatorInfo operatorInfo; |
| 324 | public boolean persistSelection; |
| 325 | |
| 326 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 327 | this.operatorInfo = operatorInfo; |
| 328 | this.persistSelection = persistSelection; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 333 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 334 | * request after sending. The main thread will notify the request when it is complete. |
| 335 | */ |
| 336 | private static final class MainThreadRequest { |
| 337 | /** The argument to use for the request */ |
| 338 | public Object argument; |
| 339 | /** The result of the request that is run on the main thread */ |
| 340 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 341 | // The subscriber id that this request applies to. Defaults to |
| 342 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 343 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 344 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 345 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 346 | public Phone phone; |
| 347 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 348 | public WorkSource workSource; |
| 349 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 350 | public MainThreadRequest(Object argument) { |
| 351 | this.argument = argument; |
| 352 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 353 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 354 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 355 | this.argument = argument; |
| 356 | if (phone != null) { |
| 357 | this.phone = phone; |
| 358 | } |
| 359 | this.workSource = workSource; |
| 360 | } |
| 361 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 362 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 363 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 364 | if (subId != null) { |
| 365 | this.subId = subId; |
| 366 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 367 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 368 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 371 | private static final class IncomingThirdPartyCallArgs { |
| 372 | public final ComponentName component; |
| 373 | public final String callId; |
| 374 | public final String callerDisplayName; |
| 375 | |
| 376 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 377 | String callerDisplayName) { |
| 378 | this.component = component; |
| 379 | this.callId = callId; |
| 380 | this.callerDisplayName = callerDisplayName; |
| 381 | } |
| 382 | } |
| 383 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 384 | /** |
| 385 | * A handler that processes messages on the main thread in the phone process. Since many |
| 386 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 387 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 388 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 389 | * on, which will be notified when the operation completes and will contain the result of the |
| 390 | * request. |
| 391 | * |
| 392 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 393 | * note that request.result must be set to something non-null for the calling thread to |
| 394 | * unblock. |
| 395 | */ |
| 396 | private final class MainThreadHandler extends Handler { |
| 397 | @Override |
| 398 | public void handleMessage(Message msg) { |
| 399 | MainThreadRequest request; |
| 400 | Message onCompleted; |
| 401 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 402 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 403 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 404 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 405 | |
| 406 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 407 | case CMD_HANDLE_USSD_REQUEST: { |
| 408 | request = (MainThreadRequest) msg.obj; |
| 409 | final Phone phone = getPhoneFromRequest(request); |
| 410 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 411 | String ussdRequest = ussdObject.first; |
| 412 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 413 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 414 | if (!isUssdApiAllowed(request.subId)) { |
| 415 | // Carrier does not support use of this API, return failure. |
| 416 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 417 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 418 | Bundle returnData = new Bundle(); |
| 419 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 420 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 421 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 422 | request.result = true; |
| 423 | notifyRequester(request); |
| 424 | return; |
| 425 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 426 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 427 | try { |
| 428 | request.result = phone != null |
| 429 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 430 | } catch (CallStateException cse) { |
| 431 | request.result = false; |
| 432 | } |
| 433 | // Wake up the requesting thread |
| 434 | notifyRequester(request); |
| 435 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 438 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 439 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 440 | final Phone phone = getPhoneFromRequest(request); |
| 441 | request.result = phone != null ? |
| 442 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 443 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 444 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 445 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 446 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 447 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 448 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 449 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 450 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 451 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 452 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 453 | if (uiccCard == null) { |
| 454 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 455 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 456 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 457 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 458 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 459 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 460 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 461 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 462 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 463 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 464 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 465 | break; |
| 466 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 467 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 468 | ar = (AsyncResult) msg.obj; |
| 469 | request = (MainThreadRequest) ar.userObj; |
| 470 | if (ar.exception == null && ar.result != null) { |
| 471 | request.result = ar.result; |
| 472 | } else { |
| 473 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 474 | if (ar.result == null) { |
| 475 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 476 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 477 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 478 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 479 | } else { |
| 480 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 481 | } |
| 482 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 483 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 484 | break; |
| 485 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 486 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 487 | request = (MainThreadRequest) msg.obj; |
| 488 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 489 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 490 | if (uiccCard == null) { |
| 491 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 492 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 493 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 494 | } else { |
| 495 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 496 | request); |
| 497 | uiccCard.iccTransmitApduBasicChannel( |
| 498 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 499 | iccArgument.p3, iccArgument.data, onCompleted); |
| 500 | } |
| 501 | break; |
| 502 | |
| 503 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 504 | ar = (AsyncResult) msg.obj; |
| 505 | request = (MainThreadRequest) ar.userObj; |
| 506 | if (ar.exception == null && ar.result != null) { |
| 507 | request.result = ar.result; |
| 508 | } else { |
| 509 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 510 | if (ar.result == null) { |
| 511 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 512 | } else if (ar.exception instanceof CommandException) { |
| 513 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 514 | ar.exception); |
| 515 | } else { |
| 516 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 517 | } |
| 518 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 519 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 520 | break; |
| 521 | |
| 522 | case CMD_EXCHANGE_SIM_IO: |
| 523 | request = (MainThreadRequest) msg.obj; |
| 524 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 525 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 526 | if (uiccCard == null) { |
| 527 | loge("iccExchangeSimIO: No UICC"); |
| 528 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 529 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 530 | } else { |
| 531 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 532 | request); |
| 533 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 534 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 535 | iccArgument.data, onCompleted); |
| 536 | } |
| 537 | break; |
| 538 | |
| 539 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 540 | ar = (AsyncResult) msg.obj; |
| 541 | request = (MainThreadRequest) ar.userObj; |
| 542 | if (ar.exception == null && ar.result != null) { |
| 543 | request.result = ar.result; |
| 544 | } else { |
| 545 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 546 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 547 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 548 | break; |
| 549 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 550 | case CMD_SEND_ENVELOPE: |
| 551 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 552 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 553 | if (uiccCard == null) { |
| 554 | loge("sendEnvelopeWithStatus: No UICC"); |
| 555 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 556 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 557 | } else { |
| 558 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 559 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 560 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 561 | break; |
| 562 | |
| 563 | case EVENT_SEND_ENVELOPE_DONE: |
| 564 | ar = (AsyncResult) msg.obj; |
| 565 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 566 | if (ar.exception == null && ar.result != null) { |
| 567 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 568 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 569 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 570 | if (ar.result == null) { |
| 571 | loge("sendEnvelopeWithStatus: Empty response"); |
| 572 | } else if (ar.exception instanceof CommandException) { |
| 573 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 574 | ar.exception); |
| 575 | } else { |
| 576 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 577 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 578 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 579 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 580 | break; |
| 581 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 582 | case CMD_OPEN_CHANNEL: |
| 583 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 584 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 585 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 586 | if (uiccCard == null) { |
| 587 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 588 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 589 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 590 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 591 | } else { |
| 592 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 593 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 594 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 595 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 596 | break; |
| 597 | |
| 598 | case EVENT_OPEN_CHANNEL_DONE: |
| 599 | ar = (AsyncResult) msg.obj; |
| 600 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 601 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 602 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 603 | int[] result = (int[]) ar.result; |
| 604 | int channelId = result[0]; |
| 605 | byte[] selectResponse = null; |
| 606 | if (result.length > 1) { |
| 607 | selectResponse = new byte[result.length - 1]; |
| 608 | for (int i = 1; i < result.length; ++i) { |
| 609 | selectResponse[i - 1] = (byte) result[i]; |
| 610 | } |
| 611 | } |
| 612 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 613 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 614 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 615 | if (ar.result == null) { |
| 616 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 617 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 618 | if (ar.exception != null) { |
| 619 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 620 | } |
| 621 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 622 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 623 | if (ar.exception instanceof CommandException) { |
| 624 | CommandException.Error error = |
| 625 | ((CommandException) (ar.exception)).getCommandError(); |
| 626 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 627 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 628 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 629 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 630 | } |
| 631 | } |
| 632 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 633 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 634 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 635 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 636 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 637 | break; |
| 638 | |
| 639 | case CMD_CLOSE_CHANNEL: |
| 640 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 641 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 642 | if (uiccCard == null) { |
| 643 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 644 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 645 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 646 | } else { |
| 647 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 648 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 649 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 650 | break; |
| 651 | |
| 652 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 653 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 654 | break; |
| 655 | |
| 656 | case CMD_NV_READ_ITEM: |
| 657 | request = (MainThreadRequest) msg.obj; |
| 658 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 659 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 660 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 661 | break; |
| 662 | |
| 663 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 664 | ar = (AsyncResult) msg.obj; |
| 665 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 666 | if (ar.exception == null && ar.result != null) { |
| 667 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 668 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 669 | request.result = ""; |
| 670 | if (ar.result == null) { |
| 671 | loge("nvReadItem: Empty response"); |
| 672 | } else if (ar.exception instanceof CommandException) { |
| 673 | loge("nvReadItem: CommandException: " + |
| 674 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 675 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 676 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 677 | } |
| 678 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 679 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 680 | break; |
| 681 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 682 | case CMD_NV_WRITE_ITEM: |
| 683 | request = (MainThreadRequest) msg.obj; |
| 684 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 685 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 686 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 687 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 688 | break; |
| 689 | |
| 690 | case EVENT_NV_WRITE_ITEM_DONE: |
| 691 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 692 | break; |
| 693 | |
| 694 | case CMD_NV_WRITE_CDMA_PRL: |
| 695 | request = (MainThreadRequest) msg.obj; |
| 696 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 697 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 698 | break; |
| 699 | |
| 700 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 701 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 702 | break; |
| 703 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 704 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 705 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 706 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 707 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 708 | break; |
| 709 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 710 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 711 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 712 | break; |
| 713 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 714 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 715 | request = (MainThreadRequest) msg.obj; |
| 716 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 717 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 718 | break; |
| 719 | |
| 720 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 721 | ar = (AsyncResult) msg.obj; |
| 722 | request = (MainThreadRequest) ar.userObj; |
| 723 | if (ar.exception == null && ar.result != null) { |
| 724 | request.result = ar.result; // Integer |
| 725 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 726 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 727 | if (ar.result == null) { |
| 728 | loge("getPreferredNetworkType: Empty response"); |
| 729 | } else if (ar.exception instanceof CommandException) { |
| 730 | loge("getPreferredNetworkType: CommandException: " + |
| 731 | ar.exception); |
| 732 | } else { |
| 733 | loge("getPreferredNetworkType: Unknown exception"); |
| 734 | } |
| 735 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 736 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 737 | break; |
| 738 | |
| 739 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 740 | request = (MainThreadRequest) msg.obj; |
| 741 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 742 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 743 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 744 | break; |
| 745 | |
| 746 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 747 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 748 | break; |
| 749 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 750 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 751 | request = (MainThreadRequest)msg.obj; |
| 752 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 753 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 754 | break; |
| 755 | |
| 756 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 757 | ar = (AsyncResult)msg.obj; |
| 758 | request = (MainThreadRequest)ar.userObj; |
| 759 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 760 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 761 | break; |
| 762 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 763 | case CMD_SET_VOICEMAIL_NUMBER: |
| 764 | request = (MainThreadRequest) msg.obj; |
| 765 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 766 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 767 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 768 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 769 | break; |
| 770 | |
| 771 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 772 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 773 | break; |
| 774 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 775 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 776 | request = (MainThreadRequest) msg.obj; |
| 777 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 778 | request); |
| 779 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 780 | break; |
| 781 | |
| 782 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 783 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 784 | break; |
| 785 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 786 | case CMD_PERFORM_NETWORK_SCAN: |
| 787 | request = (MainThreadRequest) msg.obj; |
| 788 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 789 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 790 | break; |
| 791 | |
| 792 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 793 | ar = (AsyncResult) msg.obj; |
| 794 | request = (MainThreadRequest) ar.userObj; |
| 795 | CellNetworkScanResult cellScanResult; |
| 796 | if (ar.exception == null && ar.result != null) { |
| 797 | cellScanResult = new CellNetworkScanResult( |
| 798 | CellNetworkScanResult.STATUS_SUCCESS, |
| 799 | (List<OperatorInfo>) ar.result); |
| 800 | } else { |
| 801 | if (ar.result == null) { |
| 802 | loge("getCellNetworkScanResults: Empty response"); |
| 803 | } |
| 804 | if (ar.exception != null) { |
| 805 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 806 | } |
| 807 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 808 | if (ar.exception instanceof CommandException) { |
| 809 | CommandException.Error error = |
| 810 | ((CommandException) (ar.exception)).getCommandError(); |
| 811 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 812 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 813 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 814 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 815 | } |
| 816 | } |
| 817 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 818 | } |
| 819 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 820 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 821 | break; |
| 822 | |
| 823 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 824 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 825 | ManualNetworkSelectionArgument selArg = |
| 826 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 827 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 828 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 829 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 830 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 831 | break; |
| 832 | |
| 833 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 834 | ar = (AsyncResult) msg.obj; |
| 835 | request = (MainThreadRequest) ar.userObj; |
| 836 | if (ar.exception == null) { |
| 837 | request.result = true; |
| 838 | } else { |
| 839 | request.result = false; |
| 840 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 841 | } |
| 842 | notifyRequester(request); |
| 843 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 844 | break; |
| 845 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 846 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 847 | request = (MainThreadRequest) msg.obj; |
| 848 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 849 | if (defaultPhone != null) { |
| 850 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 851 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 852 | break; |
| 853 | |
| 854 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 855 | ar = (AsyncResult) msg.obj; |
| 856 | request = (MainThreadRequest) ar.userObj; |
| 857 | if (ar.exception == null && ar.result != null) { |
| 858 | request.result = ar.result; |
| 859 | } else { |
| 860 | if (ar.result == null) { |
| 861 | loge("queryModemActivityInfo: Empty response"); |
| 862 | } else if (ar.exception instanceof CommandException) { |
| 863 | loge("queryModemActivityInfo: CommandException: " + |
| 864 | ar.exception); |
| 865 | } else { |
| 866 | loge("queryModemActivityInfo: Unknown exception"); |
| 867 | } |
| 868 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 869 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 870 | if (request.result == null) { |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 871 | request.result = new ModemActivityInfo(0, 0, 0, null, 0); |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 872 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 873 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 874 | break; |
| 875 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 876 | case CMD_SET_ALLOWED_CARRIERS: |
| 877 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 878 | CarrierRestrictionRules argument = |
| 879 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 880 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 881 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 882 | break; |
| 883 | |
| 884 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 885 | ar = (AsyncResult) msg.obj; |
| 886 | request = (MainThreadRequest) ar.userObj; |
| 887 | if (ar.exception == null && ar.result != null) { |
| 888 | request.result = ar.result; |
| 889 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 890 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 891 | if (ar.exception instanceof CommandException) { |
| 892 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 893 | CommandException.Error error = |
| 894 | ((CommandException) (ar.exception)).getCommandError(); |
| 895 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 896 | request.result = |
| 897 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 898 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 899 | } else { |
| 900 | loge("setAllowedCarriers: Unknown exception"); |
| 901 | } |
| 902 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 903 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 904 | break; |
| 905 | |
| 906 | case CMD_GET_ALLOWED_CARRIERS: |
| 907 | request = (MainThreadRequest) msg.obj; |
| 908 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 909 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 910 | break; |
| 911 | |
| 912 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 913 | ar = (AsyncResult) msg.obj; |
| 914 | request = (MainThreadRequest) ar.userObj; |
| 915 | if (ar.exception == null && ar.result != null) { |
| 916 | request.result = ar.result; |
| 917 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 918 | request.result = new IllegalStateException( |
| 919 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 920 | if (ar.result == null) { |
| 921 | loge("getAllowedCarriers: Empty response"); |
| 922 | } else if (ar.exception instanceof CommandException) { |
| 923 | loge("getAllowedCarriers: CommandException: " + |
| 924 | ar.exception); |
| 925 | } else { |
| 926 | loge("getAllowedCarriers: Unknown exception"); |
| 927 | } |
| 928 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 929 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 930 | break; |
| 931 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 932 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 933 | ar = (AsyncResult) msg.obj; |
| 934 | request = (MainThreadRequest) ar.userObj; |
| 935 | if (ar.exception == null && ar.result != null) { |
| 936 | request.result = ar.result; |
| 937 | } else { |
| 938 | request.result = new IllegalArgumentException( |
| 939 | "Failed to retrieve Forbidden Plmns"); |
| 940 | if (ar.result == null) { |
| 941 | loge("getForbiddenPlmns: Empty response"); |
| 942 | } else { |
| 943 | loge("getForbiddenPlmns: Unknown exception"); |
| 944 | } |
| 945 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 946 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 947 | break; |
| 948 | |
| 949 | case CMD_GET_FORBIDDEN_PLMNS: |
| 950 | request = (MainThreadRequest) msg.obj; |
| 951 | uiccCard = getUiccCardFromRequest(request); |
| 952 | if (uiccCard == null) { |
| 953 | loge("getForbiddenPlmns() UiccCard is null"); |
| 954 | request.result = new IllegalArgumentException( |
| 955 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 956 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 957 | break; |
| 958 | } |
| 959 | Integer appType = (Integer) request.argument; |
| 960 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 961 | if (uiccApp == null) { |
| 962 | loge("getForbiddenPlmns() no app with specified type -- " |
| 963 | + appType); |
| 964 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 965 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 966 | break; |
| 967 | } else { |
| 968 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 969 | + " specified type -- " + appType); |
| 970 | } |
| 971 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 972 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 973 | onCompleted); |
| 974 | break; |
| 975 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 976 | case CMD_SWITCH_SLOTS: |
| 977 | request = (MainThreadRequest) msg.obj; |
| 978 | int[] physicalSlots = (int[]) request.argument; |
| 979 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 980 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 981 | break; |
| 982 | |
| 983 | case EVENT_SWITCH_SLOTS_DONE: |
| 984 | ar = (AsyncResult) msg.obj; |
| 985 | request = (MainThreadRequest) ar.userObj; |
| 986 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 987 | notifyRequester(request); |
| 988 | break; |
| 989 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 990 | request = (MainThreadRequest) msg.obj; |
| 991 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 992 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 993 | break; |
| 994 | |
| 995 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 996 | ar = (AsyncResult) msg.obj; |
| 997 | request = (MainThreadRequest) ar.userObj; |
| 998 | if (ar.exception != null) { |
| 999 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1000 | } else { |
| 1001 | int mode = ((int[]) ar.result)[0]; |
| 1002 | if (mode == 0) { |
| 1003 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1004 | } else { |
| 1005 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1006 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1007 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1008 | notifyRequester(request); |
| 1009 | break; |
| 1010 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1011 | request = (MainThreadRequest) msg.obj; |
| 1012 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1013 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1014 | break; |
| 1015 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1016 | ar = (AsyncResult) msg.obj; |
| 1017 | request = (MainThreadRequest) ar.userObj; |
| 1018 | if (ar.exception != null) { |
| 1019 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1020 | } else { |
| 1021 | request.result = ((int[]) ar.result)[0]; |
| 1022 | } |
| 1023 | notifyRequester(request); |
| 1024 | break; |
| 1025 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1026 | request = (MainThreadRequest) msg.obj; |
| 1027 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1028 | int mode = (int) request.argument; |
| 1029 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1030 | break; |
| 1031 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1032 | ar = (AsyncResult) msg.obj; |
| 1033 | request = (MainThreadRequest) ar.userObj; |
| 1034 | request.result = ar.exception == null; |
| 1035 | notifyRequester(request); |
| 1036 | break; |
| 1037 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1038 | request = (MainThreadRequest) msg.obj; |
| 1039 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1040 | int subscriptionMode = (int) request.argument; |
| 1041 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1042 | break; |
| 1043 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1044 | ar = (AsyncResult) msg.obj; |
| 1045 | request = (MainThreadRequest) ar.userObj; |
| 1046 | request.result = ar.exception == null; |
| 1047 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1048 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1049 | case CMD_GET_ALL_CELL_INFO: |
| 1050 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1051 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1052 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1053 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1054 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1055 | ar = (AsyncResult) msg.obj; |
| 1056 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1057 | // If a timeout occurs, the response will be null |
| 1058 | request.result = (ar.exception == null && ar.result != null) |
| 1059 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1060 | synchronized (request) { |
| 1061 | request.notifyAll(); |
| 1062 | } |
| 1063 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1064 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1065 | request = (MainThreadRequest) msg.obj; |
| 1066 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1067 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1068 | break; |
| 1069 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1070 | ar = (AsyncResult) msg.obj; |
| 1071 | request = (MainThreadRequest) ar.userObj; |
| 1072 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1073 | try { |
| 1074 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1075 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1076 | cb.onError( |
| 1077 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1078 | ar.exception.getClass().getName(), |
| 1079 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1080 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1081 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1082 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1083 | } else { |
| 1084 | // use the result as returned |
| 1085 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1086 | } |
| 1087 | } catch (RemoteException re) { |
| 1088 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1089 | } |
| 1090 | break; |
| 1091 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1092 | request = (MainThreadRequest) msg.obj; |
| 1093 | WorkSource ws = (WorkSource) request.argument; |
| 1094 | Phone phone = getPhoneFromRequest(request); |
| 1095 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1096 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1097 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1098 | ar = (AsyncResult) msg.obj; |
| 1099 | request = (MainThreadRequest) ar.userObj; |
| 1100 | if (ar.exception == null) { |
| 1101 | request.result = ar.result; |
| 1102 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1103 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1104 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1105 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1106 | } |
| 1107 | |
| 1108 | synchronized (request) { |
| 1109 | request.notifyAll(); |
| 1110 | } |
| 1111 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1112 | case CMD_MODEM_REBOOT: |
| 1113 | request = (MainThreadRequest) msg.obj; |
| 1114 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1115 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1116 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1117 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1118 | handleNullReturnEvent(msg, "rebootModem"); |
| 1119 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1120 | case CMD_REQUEST_ENABLE_MODEM: |
| 1121 | request = (MainThreadRequest) msg.obj; |
| 1122 | boolean enable = (boolean) request.argument; |
| 1123 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1124 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1125 | PhoneConfigurationManager.getInstance() |
| 1126 | .enablePhone(request.phone, enable, onCompleted); |
| 1127 | break; |
| 1128 | case EVENT_ENABLE_MODEM_DONE: |
| 1129 | ar = (AsyncResult) msg.obj; |
| 1130 | request = (MainThreadRequest) ar.userObj; |
| 1131 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1132 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1133 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1134 | if ((boolean) request.result) { |
| 1135 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1136 | updateModemStateMetrics(); |
| 1137 | } else { |
| 1138 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1139 | + ar.exception); |
| 1140 | } |
| 1141 | notifyRequester(request); |
| 1142 | break; |
| 1143 | case CMD_GET_MODEM_STATUS: |
| 1144 | request = (MainThreadRequest) msg.obj; |
| 1145 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1146 | PhoneConfigurationManager.getInstance() |
| 1147 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1148 | break; |
| 1149 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1150 | ar = (AsyncResult) msg.obj; |
| 1151 | request = (MainThreadRequest) ar.userObj; |
| 1152 | int id = request.phone.getPhoneId(); |
| 1153 | if (ar.exception == null && ar.result != null) { |
| 1154 | request.result = ar.result; |
| 1155 | //update the cache as modem status has changed |
| 1156 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1157 | (boolean) request.result); |
| 1158 | } else { |
| 1159 | // Return true if modem status cannot be retrieved. For most cases, |
| 1160 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1161 | // and disable modem are not supported. Modem is always on. |
| 1162 | // TODO: this should be fixed in R to support a third |
| 1163 | // status UNKNOWN b/131631629 |
| 1164 | request.result = true; |
| 1165 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1166 | + ar.exception); |
| 1167 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1168 | notifyRequester(request); |
| 1169 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1170 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1171 | ar = (AsyncResult) msg.obj; |
| 1172 | request = (MainThreadRequest) ar.userObj; |
| 1173 | if (ar.exception == null && ar.result != null) { |
| 1174 | request.result = ar.result; |
| 1175 | } else { |
| 1176 | request.result = -1; |
| 1177 | loge("Failed to set Forbidden Plmns"); |
| 1178 | if (ar.result == null) { |
| 1179 | loge("setForbidenPlmns: Empty response"); |
| 1180 | } else if (ar.exception != null) { |
| 1181 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1182 | request.result = -1; |
| 1183 | } else { |
| 1184 | loge("setForbiddenPlmns: Unknown exception"); |
| 1185 | } |
| 1186 | } |
| 1187 | notifyRequester(request); |
| 1188 | break; |
| 1189 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1190 | request = (MainThreadRequest) msg.obj; |
| 1191 | uiccCard = getUiccCardFromRequest(request); |
| 1192 | if (uiccCard == null) { |
| 1193 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1194 | request.result = -1; |
| 1195 | notifyRequester(request); |
| 1196 | break; |
| 1197 | } |
| 1198 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1199 | (Pair<Integer, List<String>>) request.argument; |
| 1200 | appType = setFplmnsArgs.first; |
| 1201 | List<String> fplmns = setFplmnsArgs.second; |
| 1202 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1203 | if (uiccApp == null) { |
| 1204 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1205 | request.result = -1; |
| 1206 | loge("Failed to get UICC App"); |
| 1207 | notifyRequester(request); |
| 1208 | } else { |
| 1209 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1210 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1211 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1212 | } |
| 1213 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1214 | default: |
| 1215 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1216 | break; |
| 1217 | } |
| 1218 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1219 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1220 | private void notifyRequester(MainThreadRequest request) { |
| 1221 | synchronized (request) { |
| 1222 | request.notifyAll(); |
| 1223 | } |
| 1224 | } |
| 1225 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1226 | private void handleNullReturnEvent(Message msg, String command) { |
| 1227 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1228 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1229 | if (ar.exception == null) { |
| 1230 | request.result = true; |
| 1231 | } else { |
| 1232 | request.result = false; |
| 1233 | if (ar.exception instanceof CommandException) { |
| 1234 | loge(command + ": CommandException: " + ar.exception); |
| 1235 | } else { |
| 1236 | loge(command + ": Unknown exception"); |
| 1237 | } |
| 1238 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1239 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1240 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | /** |
| 1244 | * Posts the specified command to be executed on the main thread, |
| 1245 | * waits for the request to complete, and returns the result. |
| 1246 | * @see #sendRequestAsync |
| 1247 | */ |
| 1248 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1249 | return sendRequest( |
| 1250 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | /** |
| 1254 | * Posts the specified command to be executed on the main thread, |
| 1255 | * waits for the request to complete, and returns the result. |
| 1256 | * @see #sendRequestAsync |
| 1257 | */ |
| 1258 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1259 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1260 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | /** |
| 1264 | * Posts the specified command to be executed on the main thread, |
| 1265 | * waits for the request to complete, and returns the result. |
| 1266 | * @see #sendRequestAsync |
| 1267 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1268 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1269 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | /** |
| 1273 | * Posts the specified command to be executed on the main thread, |
| 1274 | * waits for the request to complete, and returns the result. |
| 1275 | * @see #sendRequestAsync |
| 1276 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1277 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1278 | return sendRequest(command, argument, subId, null, workSource); |
| 1279 | } |
| 1280 | |
| 1281 | /** |
| 1282 | * Posts the specified command to be executed on the main thread, |
| 1283 | * waits for the request to complete, and returns the result. |
| 1284 | * @see #sendRequestAsync |
| 1285 | */ |
| 1286 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1287 | return sendRequest( |
| 1288 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1289 | } |
| 1290 | |
| 1291 | /** |
| 1292 | * Posts the specified command to be executed on the main thread, |
| 1293 | * waits for the request to complete, and returns the result. |
| 1294 | * @see #sendRequestAsync |
| 1295 | */ |
| 1296 | private Object sendRequest( |
| 1297 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1298 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1299 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1300 | } |
| 1301 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1302 | MainThreadRequest request = null; |
| 1303 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1304 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1305 | } else if (phone != null) { |
| 1306 | request = new MainThreadRequest(argument, phone, workSource); |
| 1307 | } else { |
| 1308 | request = new MainThreadRequest(argument, subId, workSource); |
| 1309 | } |
| 1310 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1311 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1312 | msg.sendToTarget(); |
| 1313 | |
| 1314 | // Wait for the request to complete |
| 1315 | synchronized (request) { |
| 1316 | while (request.result == null) { |
| 1317 | try { |
| 1318 | request.wait(); |
| 1319 | } catch (InterruptedException e) { |
| 1320 | // Do nothing, go back and wait until the request is complete |
| 1321 | } |
| 1322 | } |
| 1323 | } |
| 1324 | return request.result; |
| 1325 | } |
| 1326 | |
| 1327 | /** |
| 1328 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1329 | * Posts the specified command to be executed on the main thread, and |
| 1330 | * returns immediately. |
| 1331 | * @see #sendRequest |
| 1332 | */ |
| 1333 | private void sendRequestAsync(int command) { |
| 1334 | mMainThreadHandler.sendEmptyMessage(command); |
| 1335 | } |
| 1336 | |
| 1337 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1338 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1339 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1340 | */ |
| 1341 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1342 | sendRequestAsync(command, argument, null, null); |
| 1343 | } |
| 1344 | |
| 1345 | /** |
| 1346 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1347 | * @see {@link #sendRequest(int,Object)} |
| 1348 | */ |
| 1349 | private void sendRequestAsync( |
| 1350 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1351 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1352 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1353 | msg.sendToTarget(); |
| 1354 | } |
| 1355 | |
| 1356 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1357 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1358 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1359 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1360 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1361 | synchronized (PhoneInterfaceManager.class) { |
| 1362 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1363 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1364 | } else { |
| 1365 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1366 | } |
| 1367 | return sInstance; |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1372 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1373 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1374 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1375 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1376 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1377 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1378 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1379 | mTelephonySharedPreferences = |
| 1380 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1381 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1382 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1383 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1384 | publish(); |
| 1385 | } |
| 1386 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1387 | private Phone getDefaultPhone() { |
| 1388 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1389 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1390 | } |
| 1391 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1392 | private void publish() { |
| 1393 | if (DBG) log("publish: " + this); |
| 1394 | |
| 1395 | ServiceManager.addService("phone", this); |
| 1396 | } |
| 1397 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1398 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1399 | if (request.phone != null) { |
| 1400 | return request.phone; |
| 1401 | } else { |
| 1402 | return getPhoneFromSubId(request.subId); |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | private Phone getPhoneFromSubId(int subId) { |
| 1407 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1408 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1409 | } |
| 1410 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1411 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1412 | Phone phone = getPhoneFromRequest(request); |
| 1413 | return phone == null ? null : |
| 1414 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1415 | } |
| 1416 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1417 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1418 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1419 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1420 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1421 | |
| 1422 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1423 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1424 | } |
| 1425 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1426 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1427 | if (DBG) log("dial: " + number); |
| 1428 | // No permission check needed here: This is just a wrapper around the |
| 1429 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1430 | // the UI before it does anything. |
| 1431 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1432 | final long identity = Binder.clearCallingIdentity(); |
| 1433 | try { |
| 1434 | String url = createTelUrl(number); |
| 1435 | if (url == null) { |
| 1436 | return; |
| 1437 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1438 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1439 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1440 | PhoneConstants.State state = mCM.getState(subId); |
| 1441 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1442 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1443 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1444 | mApp.startActivity(intent); |
| 1445 | } |
| 1446 | } finally { |
| 1447 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1448 | } |
| 1449 | } |
| 1450 | |
| 1451 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1452 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1453 | } |
| 1454 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1455 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1456 | if (DBG) log("call: " + number); |
| 1457 | |
| 1458 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1459 | // need to do a permission check since we're calling startActivity() |
| 1460 | // from the context of the phone app. |
| 1461 | enforceCallPermission(); |
| 1462 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1463 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1464 | != AppOpsManager.MODE_ALLOWED) { |
| 1465 | return; |
| 1466 | } |
| 1467 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1468 | final long identity = Binder.clearCallingIdentity(); |
| 1469 | try { |
| 1470 | String url = createTelUrl(number); |
| 1471 | if (url == null) { |
| 1472 | return; |
| 1473 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1474 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1475 | boolean isValid = false; |
| 1476 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1477 | if (slist != null) { |
| 1478 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1479 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1480 | isValid = true; |
| 1481 | break; |
| 1482 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1483 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1484 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1485 | if (!isValid) { |
| 1486 | return; |
| 1487 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1488 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1489 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1490 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1491 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1492 | mApp.startActivity(intent); |
| 1493 | } finally { |
| 1494 | Binder.restoreCallingIdentity(identity); |
| 1495 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1496 | } |
| 1497 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1498 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1499 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1502 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1503 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1504 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1505 | } |
| 1506 | |
| 1507 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1508 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1511 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1512 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1513 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1514 | } |
| 1515 | |
| 1516 | /** {@hide} */ |
| 1517 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1518 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1521 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1522 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1523 | |
| 1524 | final long identity = Binder.clearCallingIdentity(); |
| 1525 | try { |
| 1526 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1527 | checkSimPin.start(); |
| 1528 | return checkSimPin.unlockSim(null, pin); |
| 1529 | } finally { |
| 1530 | Binder.restoreCallingIdentity(identity); |
| 1531 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1534 | /** {@hide} */ |
| 1535 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1536 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1537 | } |
| 1538 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1539 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1540 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1541 | |
| 1542 | final long identity = Binder.clearCallingIdentity(); |
| 1543 | try { |
| 1544 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1545 | checkSimPuk.start(); |
| 1546 | return checkSimPuk.unlockSim(puk, pin); |
| 1547 | } finally { |
| 1548 | Binder.restoreCallingIdentity(identity); |
| 1549 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1553 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1554 | * a synchronous one. |
| 1555 | */ |
| 1556 | private static class UnlockSim extends Thread { |
| 1557 | |
| 1558 | private final IccCard mSimCard; |
| 1559 | |
| 1560 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1561 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1562 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1563 | |
| 1564 | // For replies from SimCard interface |
| 1565 | private Handler mHandler; |
| 1566 | |
| 1567 | // For async handler to identify request type |
| 1568 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1569 | |
| 1570 | public UnlockSim(IccCard simCard) { |
| 1571 | mSimCard = simCard; |
| 1572 | } |
| 1573 | |
| 1574 | @Override |
| 1575 | public void run() { |
| 1576 | Looper.prepare(); |
| 1577 | synchronized (UnlockSim.this) { |
| 1578 | mHandler = new Handler() { |
| 1579 | @Override |
| 1580 | public void handleMessage(Message msg) { |
| 1581 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1582 | switch (msg.what) { |
| 1583 | case SUPPLY_PIN_COMPLETE: |
| 1584 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1585 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1586 | mRetryCount = msg.arg1; |
| 1587 | if (ar.exception != null) { |
| 1588 | if (ar.exception instanceof CommandException && |
| 1589 | ((CommandException)(ar.exception)).getCommandError() |
| 1590 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1591 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1592 | } else { |
| 1593 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1594 | } |
| 1595 | } else { |
| 1596 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1597 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1598 | mDone = true; |
| 1599 | UnlockSim.this.notifyAll(); |
| 1600 | } |
| 1601 | break; |
| 1602 | } |
| 1603 | } |
| 1604 | }; |
| 1605 | UnlockSim.this.notifyAll(); |
| 1606 | } |
| 1607 | Looper.loop(); |
| 1608 | } |
| 1609 | |
| 1610 | /* |
| 1611 | * Use PIN or PUK to unlock SIM card |
| 1612 | * |
| 1613 | * If PUK is null, unlock SIM card with PIN |
| 1614 | * |
| 1615 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1616 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1617 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1618 | |
| 1619 | while (mHandler == null) { |
| 1620 | try { |
| 1621 | wait(); |
| 1622 | } catch (InterruptedException e) { |
| 1623 | Thread.currentThread().interrupt(); |
| 1624 | } |
| 1625 | } |
| 1626 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1627 | |
| 1628 | if (puk == null) { |
| 1629 | mSimCard.supplyPin(pin, callback); |
| 1630 | } else { |
| 1631 | mSimCard.supplyPuk(puk, pin, callback); |
| 1632 | } |
| 1633 | |
| 1634 | while (!mDone) { |
| 1635 | try { |
| 1636 | Log.d(LOG_TAG, "wait for done"); |
| 1637 | wait(); |
| 1638 | } catch (InterruptedException e) { |
| 1639 | // Restore the interrupted status |
| 1640 | Thread.currentThread().interrupt(); |
| 1641 | } |
| 1642 | } |
| 1643 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1644 | int[] resultArray = new int[2]; |
| 1645 | resultArray[0] = mResult; |
| 1646 | resultArray[1] = mRetryCount; |
| 1647 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1648 | } |
| 1649 | } |
| 1650 | |
| 1651 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1652 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1653 | |
| 1654 | } |
| 1655 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1656 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1657 | // No permission check needed here: this call is harmless, and it's |
| 1658 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1659 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1660 | final long identity = Binder.clearCallingIdentity(); |
| 1661 | try { |
| 1662 | final Phone phone = getPhone(subId); |
| 1663 | if (phone != null) { |
| 1664 | phone.updateServiceLocation(); |
| 1665 | } |
| 1666 | } finally { |
| 1667 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1668 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1669 | } |
| 1670 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1671 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1672 | @Override |
| 1673 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1674 | return isRadioOnWithFeature(callingPackage, null); |
| 1675 | } |
| 1676 | |
| 1677 | |
| 1678 | @Override |
| 1679 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1680 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1681 | callingFeatureId); |
| 1682 | } |
| 1683 | |
| 1684 | @Deprecated |
| 1685 | @Override |
| 1686 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 1687 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1688 | } |
| 1689 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1690 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1691 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1692 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1693 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1694 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1695 | return false; |
| 1696 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1697 | |
| 1698 | final long identity = Binder.clearCallingIdentity(); |
| 1699 | try { |
| 1700 | return isRadioOnForSubscriber(subId); |
| 1701 | } finally { |
| 1702 | Binder.restoreCallingIdentity(identity); |
| 1703 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1707 | final long identity = Binder.clearCallingIdentity(); |
| 1708 | try { |
| 1709 | final Phone phone = getPhone(subId); |
| 1710 | if (phone != null) { |
| 1711 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1712 | } else { |
| 1713 | return false; |
| 1714 | } |
| 1715 | } finally { |
| 1716 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1717 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1721 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1722 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1723 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1724 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1725 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1726 | |
| 1727 | final long identity = Binder.clearCallingIdentity(); |
| 1728 | try { |
| 1729 | final Phone phone = getPhone(subId); |
| 1730 | if (phone != null) { |
| 1731 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1732 | } |
| 1733 | } finally { |
| 1734 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1735 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1739 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1742 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1743 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1744 | |
| 1745 | final long identity = Binder.clearCallingIdentity(); |
| 1746 | try { |
| 1747 | final Phone phone = getPhone(subId); |
| 1748 | if (phone == null) { |
| 1749 | return false; |
| 1750 | } |
| 1751 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1752 | toggleRadioOnOffForSubscriber(subId); |
| 1753 | } |
| 1754 | return true; |
| 1755 | } finally { |
| 1756 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1757 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1758 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1759 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1760 | public boolean needMobileRadioShutdown() { |
| 1761 | /* |
| 1762 | * If any of the Radios are available, it will need to be |
| 1763 | * shutdown. So return true if any Radio is available. |
| 1764 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1765 | final long identity = Binder.clearCallingIdentity(); |
| 1766 | try { |
| 1767 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1768 | Phone phone = PhoneFactory.getPhone(i); |
| 1769 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1770 | } |
| 1771 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1772 | return false; |
| 1773 | } finally { |
| 1774 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1775 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1776 | } |
| 1777 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1778 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1779 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1780 | enforceModifyPermission(); |
| 1781 | |
| 1782 | final long identity = Binder.clearCallingIdentity(); |
| 1783 | try { |
| 1784 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1785 | logv("Shutting down Phone " + i); |
| 1786 | shutdownRadioUsingPhoneId(i); |
| 1787 | } |
| 1788 | } finally { |
| 1789 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1790 | } |
| 1791 | } |
| 1792 | |
| 1793 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1794 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1795 | if (phone != null && phone.isRadioAvailable()) { |
| 1796 | phone.shutdownRadio(); |
| 1797 | } |
| 1798 | } |
| 1799 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1800 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1801 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1802 | |
| 1803 | final long identity = Binder.clearCallingIdentity(); |
| 1804 | try { |
| 1805 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1806 | if (defaultPhone != null) { |
| 1807 | defaultPhone.setRadioPower(turnOn); |
| 1808 | return true; |
| 1809 | } else { |
| 1810 | loge("There's no default phone."); |
| 1811 | return false; |
| 1812 | } |
| 1813 | } finally { |
| 1814 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1815 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1816 | } |
| 1817 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1818 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1819 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1820 | |
| 1821 | final long identity = Binder.clearCallingIdentity(); |
| 1822 | try { |
| 1823 | final Phone phone = getPhone(subId); |
| 1824 | if (phone != null) { |
| 1825 | phone.setRadioPower(turnOn); |
| 1826 | return true; |
| 1827 | } else { |
| 1828 | return false; |
| 1829 | } |
| 1830 | } finally { |
| 1831 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1832 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1835 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1836 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1837 | public boolean enableDataConnectivity() { |
| 1838 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1839 | |
| 1840 | final long identity = Binder.clearCallingIdentity(); |
| 1841 | try { |
| 1842 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1843 | final Phone phone = getPhone(subId); |
| 1844 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1845 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1846 | return true; |
| 1847 | } else { |
| 1848 | return false; |
| 1849 | } |
| 1850 | } finally { |
| 1851 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1852 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1853 | } |
| 1854 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1855 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1856 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1857 | public boolean disableDataConnectivity() { |
| 1858 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1859 | |
| 1860 | final long identity = Binder.clearCallingIdentity(); |
| 1861 | try { |
| 1862 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1863 | final Phone phone = getPhone(subId); |
| 1864 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1865 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1866 | return true; |
| 1867 | } else { |
| 1868 | return false; |
| 1869 | } |
| 1870 | } finally { |
| 1871 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1872 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1873 | } |
| 1874 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1875 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1876 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1877 | final long identity = Binder.clearCallingIdentity(); |
| 1878 | try { |
| 1879 | final Phone phone = getPhone(subId); |
| 1880 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1881 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1882 | } else { |
| 1883 | return false; |
| 1884 | } |
| 1885 | } finally { |
| 1886 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1887 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1891 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1892 | } |
| 1893 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1894 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1895 | enforceCallPermission(); |
| 1896 | |
| 1897 | final long identity = Binder.clearCallingIdentity(); |
| 1898 | try { |
| 1899 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1900 | return; |
| 1901 | } |
| 1902 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1903 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1904 | } finally { |
| 1905 | Binder.restoreCallingIdentity(identity); |
| 1906 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1907 | }; |
| 1908 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1909 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1910 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1911 | |
| 1912 | final long identity = Binder.clearCallingIdentity(); |
| 1913 | try { |
| 1914 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1915 | return false; |
| 1916 | } |
| 1917 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1918 | } finally { |
| 1919 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1920 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1921 | } |
| 1922 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1923 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1924 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1927 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1928 | final long identity = Binder.clearCallingIdentity(); |
| 1929 | try { |
| 1930 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1931 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1932 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1933 | } finally { |
| 1934 | Binder.restoreCallingIdentity(identity); |
| 1935 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1938 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1939 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1940 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1941 | } |
| 1942 | |
| 1943 | @Override |
| 1944 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1945 | final long identity = Binder.clearCallingIdentity(); |
| 1946 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1947 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1948 | if (phone != null) { |
| 1949 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1950 | } else { |
| 1951 | return PhoneConstantConversions.convertDataState( |
| 1952 | PhoneConstants.DataState.DISCONNECTED); |
| 1953 | } |
| 1954 | } finally { |
| 1955 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1956 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1959 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1960 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1961 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1962 | } |
| 1963 | |
| 1964 | @Override |
| 1965 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1966 | final long identity = Binder.clearCallingIdentity(); |
| 1967 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1968 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1969 | if (phone != null) { |
| 1970 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1971 | } else { |
| 1972 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1973 | } |
| 1974 | } finally { |
| 1975 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1976 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 1980 | public Bundle getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1981 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1982 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1983 | |
| 1984 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1985 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1986 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1987 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 1988 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1989 | .setCallingPid(Binder.getCallingPid()) |
| 1990 | .setCallingUid(Binder.getCallingUid()) |
| 1991 | .setMethod("getCellLocation") |
| 1992 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1993 | .build()); |
| 1994 | switch (locationResult) { |
| 1995 | case DENIED_HARD: |
| 1996 | throw new SecurityException("Not allowed to access cell location"); |
| 1997 | case DENIED_SOFT: |
| 1998 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2001 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2002 | final long identity = Binder.clearCallingIdentity(); |
| 2003 | try { |
| 2004 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 2005 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2006 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2007 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 2008 | cl.fillInNotifierBundle(data); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2009 | return data; |
| 2010 | } finally { |
| 2011 | Binder.restoreCallingIdentity(identity); |
| 2012 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2015 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2016 | public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage, |
| 2017 | String callingFeatureId) { |
Jack Yu | 1e81ccd | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2018 | if (!TextUtils.isEmpty(callingPackage)) { |
| 2019 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2020 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2021 | callingFeatureId, "getNetworkCountryIsoForPhone")) { |
Jack Yu | 1e81ccd | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2022 | return ""; |
| 2023 | } |
| 2024 | } |
| 2025 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2026 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2027 | // registered cell info, so return a NULL country instead. |
| 2028 | final long identity = Binder.clearCallingIdentity(); |
| 2029 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2030 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2031 | // Get default phone in this case. |
| 2032 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2033 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2034 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2035 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2036 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2037 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2038 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(), |
| 2039 | mApp.getFeatureId())) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2040 | return ""; |
| 2041 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2042 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2043 | if (phone != null) { |
| 2044 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2045 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2046 | if (sst != null) { |
| 2047 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2048 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2049 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2050 | return lt.getCurrentCountry(); |
| 2051 | } else if (emergencyNumberTracker != null) { |
| 2052 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2053 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2054 | } |
| 2055 | } |
| 2056 | } |
| 2057 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2058 | } finally { |
| 2059 | Binder.restoreCallingIdentity(identity); |
| 2060 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2064 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2065 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2068 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2069 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2070 | mApp.enforceCallingOrSelfPermission( |
| 2071 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2072 | |
| 2073 | final long identity = Binder.clearCallingIdentity(); |
| 2074 | try { |
| 2075 | final Phone phone = getPhone(subId); |
| 2076 | if (phone != null) { |
| 2077 | phone.enableLocationUpdates(); |
| 2078 | } |
| 2079 | } finally { |
| 2080 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2081 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2082 | } |
| 2083 | |
| 2084 | @Override |
| 2085 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2086 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2087 | } |
| 2088 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2089 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2090 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2091 | mApp.enforceCallingOrSelfPermission( |
| 2092 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2093 | |
| 2094 | final long identity = Binder.clearCallingIdentity(); |
| 2095 | try { |
| 2096 | final Phone phone = getPhone(subId); |
| 2097 | if (phone != null) { |
| 2098 | phone.disableLocationUpdates(); |
| 2099 | } |
| 2100 | } finally { |
| 2101 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2102 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2105 | /** |
| 2106 | * Returns the target SDK version number for a given package name. |
| 2107 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2108 | * This call MUST be invoked before clearing the calling UID. |
| 2109 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2110 | * @return target SDK if the package is found or INT_MAX. |
| 2111 | */ |
| 2112 | private int getTargetSdk(String packageName) { |
| 2113 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2114 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2115 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2116 | if (ai != null) return ai.targetSdkVersion; |
| 2117 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2118 | loge("Failed to get package info for pkg=" |
| 2119 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2120 | } |
| 2121 | return Integer.MAX_VALUE; |
| 2122 | } |
| 2123 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2124 | @Override |
| 2125 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2126 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2127 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2128 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2129 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2130 | throw new SecurityException( |
| 2131 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2132 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2133 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2134 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2135 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2136 | return null; |
| 2137 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2138 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2139 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2140 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2141 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2142 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2143 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2144 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2145 | for (CellInfo ci : info) { |
| 2146 | if (ci instanceof CellInfoGsm) { |
| 2147 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2148 | } else if (ci instanceof CellInfoWcdma) { |
| 2149 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2150 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2151 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2152 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2153 | } |
| 2154 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2155 | private List<CellInfo> getCachedCellInfo() { |
| 2156 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2157 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2158 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2159 | if (info != null) cellInfos.addAll(info); |
| 2160 | } |
| 2161 | return cellInfos; |
| 2162 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2163 | |
| 2164 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2165 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2166 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2167 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2168 | |
| 2169 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2170 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2171 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2172 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2173 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2174 | .setCallingPid(Binder.getCallingPid()) |
| 2175 | .setCallingUid(Binder.getCallingUid()) |
| 2176 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2177 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2178 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2179 | .build()); |
| 2180 | switch (locationResult) { |
| 2181 | case DENIED_HARD: |
| 2182 | throw new SecurityException("Not allowed to access cell info"); |
| 2183 | case DENIED_SOFT: |
| 2184 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2187 | final int targetSdk = getTargetSdk(callingPackage); |
| 2188 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2189 | return getCachedCellInfo(); |
| 2190 | } |
| 2191 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2192 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2193 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2194 | final long identity = Binder.clearCallingIdentity(); |
| 2195 | try { |
| 2196 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2197 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2198 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2199 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2200 | if (info != null) cellInfos.addAll(info); |
| 2201 | } |
| 2202 | return cellInfos; |
| 2203 | } finally { |
| 2204 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2208 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2209 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2210 | String callingFeatureId) { |
| 2211 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2212 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2216 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2217 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2218 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2219 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2220 | } |
| 2221 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2222 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2223 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2224 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2225 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2226 | |
| 2227 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2228 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2229 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2230 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2231 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2232 | .setCallingPid(Binder.getCallingPid()) |
| 2233 | .setCallingUid(Binder.getCallingUid()) |
| 2234 | .setMethod("requestCellInfoUpdate") |
| 2235 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2236 | .build()); |
| 2237 | switch (locationResult) { |
| 2238 | case DENIED_HARD: |
| 2239 | throw new SecurityException("Not allowed to access cell info"); |
| 2240 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2241 | try { |
| 2242 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2243 | } catch (RemoteException re) { |
| 2244 | // Drop without consequences |
| 2245 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2246 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2247 | } |
| 2248 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2249 | |
| 2250 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2251 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2252 | |
| 2253 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2254 | } |
| 2255 | |
| 2256 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2257 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2258 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2259 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2260 | |
| 2261 | final long identity = Binder.clearCallingIdentity(); |
| 2262 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2263 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2264 | } finally { |
| 2265 | Binder.restoreCallingIdentity(identity); |
| 2266 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2267 | } |
| 2268 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2269 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2270 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2271 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2272 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2273 | return null; |
| 2274 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2275 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2276 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2277 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2278 | return null; |
| 2279 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2280 | |
| 2281 | final long identity = Binder.clearCallingIdentity(); |
| 2282 | try { |
| 2283 | return phone.getImei(); |
| 2284 | } finally { |
| 2285 | Binder.restoreCallingIdentity(identity); |
| 2286 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2287 | } |
| 2288 | |
| 2289 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2290 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2291 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2292 | String tac = null; |
| 2293 | if (phone != null) { |
| 2294 | String imei = phone.getImei(); |
| 2295 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2296 | } |
| 2297 | return tac; |
| 2298 | } |
| 2299 | |
| 2300 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2301 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2302 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2303 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2304 | return null; |
| 2305 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2306 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2307 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2308 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2309 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2310 | return null; |
| 2311 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2312 | |
| 2313 | final long identity = Binder.clearCallingIdentity(); |
| 2314 | try { |
| 2315 | return phone.getMeid(); |
| 2316 | } finally { |
| 2317 | Binder.restoreCallingIdentity(identity); |
| 2318 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2322 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2323 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2324 | String manufacturerCode = null; |
| 2325 | if (phone != null) { |
| 2326 | String meid = phone.getMeid(); |
| 2327 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2328 | } |
| 2329 | return manufacturerCode; |
| 2330 | } |
| 2331 | |
| 2332 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2333 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2334 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2335 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2336 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2337 | return null; |
| 2338 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2339 | int subId = phone.getSubId(); |
| 2340 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2341 | mApp, subId, callingPackage, callingFeatureId, |
| 2342 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2343 | return null; |
| 2344 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2345 | |
| 2346 | final long identity = Binder.clearCallingIdentity(); |
| 2347 | try { |
| 2348 | return phone.getDeviceSvn(); |
| 2349 | } finally { |
| 2350 | Binder.restoreCallingIdentity(identity); |
| 2351 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2352 | } |
| 2353 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2354 | @Override |
| 2355 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2356 | final long identity = Binder.clearCallingIdentity(); |
| 2357 | try { |
| 2358 | final Phone phone = getPhone(subId); |
| 2359 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2360 | } finally { |
| 2361 | Binder.restoreCallingIdentity(identity); |
| 2362 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | @Override |
| 2366 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2367 | final long identity = Binder.clearCallingIdentity(); |
| 2368 | try { |
| 2369 | final Phone phone = getPhone(subId); |
| 2370 | return phone == null ? null : phone.getCarrierName(); |
| 2371 | } finally { |
| 2372 | Binder.restoreCallingIdentity(identity); |
| 2373 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2374 | } |
| 2375 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2376 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2377 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2378 | final long identity = Binder.clearCallingIdentity(); |
| 2379 | try { |
| 2380 | final Phone phone = getPhone(subId); |
| 2381 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2382 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2383 | } finally { |
| 2384 | Binder.restoreCallingIdentity(identity); |
| 2385 | } |
| 2386 | } |
| 2387 | |
| 2388 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2389 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2390 | final long identity = Binder.clearCallingIdentity(); |
| 2391 | try { |
| 2392 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2393 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2394 | } finally { |
| 2395 | Binder.restoreCallingIdentity(identity); |
| 2396 | } |
| 2397 | } |
| 2398 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2399 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2400 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2401 | if (!isSubscriptionMccMnc) { |
| 2402 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2403 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2404 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2405 | if (phone == null) { |
| 2406 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2407 | } |
| 2408 | final long identity = Binder.clearCallingIdentity(); |
| 2409 | try { |
| 2410 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2411 | } finally { |
| 2412 | Binder.restoreCallingIdentity(identity); |
| 2413 | } |
| 2414 | } |
| 2415 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2416 | // |
| 2417 | // Internal helper methods. |
| 2418 | // |
| 2419 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2420 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2421 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2422 | * |
| 2423 | * @throws SecurityException if the caller does not have the required permission |
| 2424 | */ |
| 2425 | private void enforceModifyPermission() { |
| 2426 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2427 | } |
| 2428 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame^] | 2429 | private void enforceActiveEmergencySessionPermission() { |
| 2430 | mApp.enforceCallingOrSelfPermission( |
| 2431 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2432 | } |
| 2433 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2434 | /** |
| 2435 | * Make sure the caller has the CALL_PHONE permission. |
| 2436 | * |
| 2437 | * @throws SecurityException if the caller does not have the required permission |
| 2438 | */ |
| 2439 | private void enforceCallPermission() { |
| 2440 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2441 | } |
| 2442 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2443 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2444 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2445 | "ConnectivityService"); |
| 2446 | } |
| 2447 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2448 | private String createTelUrl(String number) { |
| 2449 | if (TextUtils.isEmpty(number)) { |
| 2450 | return null; |
| 2451 | } |
| 2452 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2453 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2454 | } |
| 2455 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2456 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2457 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2458 | } |
| 2459 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2460 | private static void logv(String msg) { |
| 2461 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2462 | } |
| 2463 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2464 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2465 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2466 | } |
| 2467 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2468 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2469 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2470 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2471 | } |
| 2472 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2473 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2474 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2475 | final long identity = Binder.clearCallingIdentity(); |
| 2476 | try { |
| 2477 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2478 | if (phone == null) { |
| 2479 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2480 | } else { |
| 2481 | return phone.getPhoneType(); |
| 2482 | } |
| 2483 | } finally { |
| 2484 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2485 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | /** |
| 2489 | * Returns the CDMA ERI icon index to display |
| 2490 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2491 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2492 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2493 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2494 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2495 | } |
| 2496 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2497 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2498 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2499 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2500 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2501 | mApp, subId, callingPackage, callingFeatureId, |
| 2502 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2503 | return -1; |
| 2504 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2505 | |
| 2506 | final long identity = Binder.clearCallingIdentity(); |
| 2507 | try { |
| 2508 | final Phone phone = getPhone(subId); |
| 2509 | if (phone != null) { |
| 2510 | return phone.getCdmaEriIconIndex(); |
| 2511 | } else { |
| 2512 | return -1; |
| 2513 | } |
| 2514 | } finally { |
| 2515 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2516 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2517 | } |
| 2518 | |
| 2519 | /** |
| 2520 | * Returns the CDMA ERI icon mode, |
| 2521 | * 0 - ON |
| 2522 | * 1 - FLASHING |
| 2523 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2524 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2525 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2526 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2527 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2528 | } |
| 2529 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2530 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2531 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2532 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2533 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2534 | mApp, subId, callingPackage, callingFeatureId, |
| 2535 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2536 | return -1; |
| 2537 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2538 | |
| 2539 | final long identity = Binder.clearCallingIdentity(); |
| 2540 | try { |
| 2541 | final Phone phone = getPhone(subId); |
| 2542 | if (phone != null) { |
| 2543 | return phone.getCdmaEriIconMode(); |
| 2544 | } else { |
| 2545 | return -1; |
| 2546 | } |
| 2547 | } finally { |
| 2548 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2549 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | /** |
| 2553 | * Returns the CDMA ERI text, |
| 2554 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2555 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2556 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2557 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2558 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2559 | } |
| 2560 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2561 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2562 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2563 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2564 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2565 | mApp, subId, callingPackage, callingFeatureId, |
| 2566 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2567 | return null; |
| 2568 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2569 | |
| 2570 | final long identity = Binder.clearCallingIdentity(); |
| 2571 | try { |
| 2572 | final Phone phone = getPhone(subId); |
| 2573 | if (phone != null) { |
| 2574 | return phone.getCdmaEriText(); |
| 2575 | } else { |
| 2576 | return null; |
| 2577 | } |
| 2578 | } finally { |
| 2579 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2580 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2584 | * Returns the CDMA MDN. |
| 2585 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2586 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2587 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2588 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2589 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2590 | |
| 2591 | final long identity = Binder.clearCallingIdentity(); |
| 2592 | try { |
| 2593 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2594 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2595 | return phone.getLine1Number(); |
| 2596 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2597 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2598 | return null; |
| 2599 | } |
| 2600 | } finally { |
| 2601 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2602 | } |
| 2603 | } |
| 2604 | |
| 2605 | /** |
| 2606 | * Returns the CDMA MIN. |
| 2607 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2608 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2609 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2610 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2611 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2612 | |
| 2613 | final long identity = Binder.clearCallingIdentity(); |
| 2614 | try { |
| 2615 | final Phone phone = getPhone(subId); |
| 2616 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2617 | return phone.getCdmaMin(); |
| 2618 | } else { |
| 2619 | return null; |
| 2620 | } |
| 2621 | } finally { |
| 2622 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2623 | } |
| 2624 | } |
| 2625 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2626 | @Override |
| 2627 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2628 | INumberVerificationCallback callback, String callingPackage) { |
| 2629 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2630 | != PERMISSION_GRANTED) { |
| 2631 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2632 | } |
| 2633 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2634 | |
| 2635 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2636 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2637 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2638 | } |
| 2639 | |
| 2640 | if (range == null) { |
| 2641 | throw new NullPointerException("Range must be non-null"); |
| 2642 | } |
| 2643 | |
| 2644 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2645 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2646 | |
| 2647 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2648 | } |
| 2649 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2650 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2651 | * Returns true if CDMA provisioning needs to run. |
| 2652 | */ |
| 2653 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2654 | final long identity = Binder.clearCallingIdentity(); |
| 2655 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2656 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2657 | } finally { |
| 2658 | Binder.restoreCallingIdentity(identity); |
| 2659 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2663 | * Sets the voice mail number of a given subId. |
| 2664 | */ |
| 2665 | @Override |
| 2666 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2667 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2668 | |
| 2669 | final long identity = Binder.clearCallingIdentity(); |
| 2670 | try { |
| 2671 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2672 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2673 | return success; |
| 2674 | } finally { |
| 2675 | Binder.restoreCallingIdentity(identity); |
| 2676 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2677 | } |
| 2678 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2679 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2680 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2681 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2682 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2683 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2684 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2685 | throw new SecurityException("caller must be system dialer"); |
| 2686 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2687 | |
| 2688 | final long identity = Binder.clearCallingIdentity(); |
| 2689 | try { |
| 2690 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2691 | if (phoneAccountHandle == null) { |
| 2692 | return null; |
| 2693 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2694 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2695 | } finally { |
| 2696 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2697 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2698 | } |
| 2699 | |
| 2700 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2701 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2702 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2703 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2704 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2705 | mApp, subId, callingPackage, callingFeatureId, |
| 2706 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2707 | return null; |
| 2708 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2709 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2710 | final long identity = Binder.clearCallingIdentity(); |
| 2711 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2712 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2713 | } finally { |
| 2714 | Binder.restoreCallingIdentity(identity); |
| 2715 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2719 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2720 | VisualVoicemailSmsFilterSettings settings) { |
| 2721 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2722 | |
| 2723 | final long identity = Binder.clearCallingIdentity(); |
| 2724 | try { |
| 2725 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2726 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2727 | } finally { |
| 2728 | Binder.restoreCallingIdentity(identity); |
| 2729 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2730 | } |
| 2731 | |
| 2732 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2733 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2734 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2735 | |
| 2736 | final long identity = Binder.clearCallingIdentity(); |
| 2737 | try { |
| 2738 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2739 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2740 | } finally { |
| 2741 | Binder.restoreCallingIdentity(identity); |
| 2742 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2743 | } |
| 2744 | |
| 2745 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2746 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2747 | String callingPackage, int subId) { |
| 2748 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2749 | |
| 2750 | final long identity = Binder.clearCallingIdentity(); |
| 2751 | try { |
| 2752 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2753 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2754 | } finally { |
| 2755 | Binder.restoreCallingIdentity(identity); |
| 2756 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2757 | } |
| 2758 | |
| 2759 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2760 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2761 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2762 | |
| 2763 | final long identity = Binder.clearCallingIdentity(); |
| 2764 | try { |
| 2765 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2766 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2767 | } finally { |
| 2768 | Binder.restoreCallingIdentity(identity); |
| 2769 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2770 | } |
| 2771 | |
| 2772 | @Override |
| 2773 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2774 | String number, int port, String text, PendingIntent sentIntent) { |
| 2775 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2776 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2777 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2778 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2779 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2780 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2781 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2782 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2783 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2784 | * Sets the voice activation state of a given subId. |
| 2785 | */ |
| 2786 | @Override |
| 2787 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2788 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2789 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2790 | |
| 2791 | final long identity = Binder.clearCallingIdentity(); |
| 2792 | try { |
| 2793 | final Phone phone = getPhone(subId); |
| 2794 | if (phone != null) { |
| 2795 | phone.setVoiceActivationState(activationState); |
| 2796 | } else { |
| 2797 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2798 | } |
| 2799 | } finally { |
| 2800 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2801 | } |
| 2802 | } |
| 2803 | |
| 2804 | /** |
| 2805 | * Sets the data activation state of a given subId. |
| 2806 | */ |
| 2807 | @Override |
| 2808 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2809 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2810 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2811 | |
| 2812 | final long identity = Binder.clearCallingIdentity(); |
| 2813 | try { |
| 2814 | final Phone phone = getPhone(subId); |
| 2815 | if (phone != null) { |
| 2816 | phone.setDataActivationState(activationState); |
| 2817 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 2818 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2819 | } |
| 2820 | } finally { |
| 2821 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2822 | } |
| 2823 | } |
| 2824 | |
| 2825 | /** |
| 2826 | * Returns the voice activation state of a given subId. |
| 2827 | */ |
| 2828 | @Override |
| 2829 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2830 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2831 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2832 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2833 | final long identity = Binder.clearCallingIdentity(); |
| 2834 | try { |
| 2835 | if (phone != null) { |
| 2836 | return phone.getVoiceActivationState(); |
| 2837 | } else { |
| 2838 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2839 | } |
| 2840 | } finally { |
| 2841 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2842 | } |
| 2843 | } |
| 2844 | |
| 2845 | /** |
| 2846 | * Returns the data activation state of a given subId. |
| 2847 | */ |
| 2848 | @Override |
| 2849 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2850 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2851 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2852 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2853 | final long identity = Binder.clearCallingIdentity(); |
| 2854 | try { |
| 2855 | if (phone != null) { |
| 2856 | return phone.getDataActivationState(); |
| 2857 | } else { |
| 2858 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2859 | } |
| 2860 | } finally { |
| 2861 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2866 | * Returns the unread count of voicemails for a subId |
| 2867 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2868 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2869 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 2870 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2871 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2872 | mApp, subId, callingPackage, callingFeatureId, |
| 2873 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2874 | return 0; |
| 2875 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2876 | final long identity = Binder.clearCallingIdentity(); |
| 2877 | try { |
| 2878 | final Phone phone = getPhone(subId); |
| 2879 | if (phone != null) { |
| 2880 | return phone.getVoiceMessageCount(); |
| 2881 | } else { |
| 2882 | return 0; |
| 2883 | } |
| 2884 | } finally { |
| 2885 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2886 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2887 | } |
| 2888 | |
| 2889 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2890 | * returns true, if the device is in a state where both voice and data |
| 2891 | * are supported simultaneously. This can change based on location or network condition. |
| 2892 | */ |
| 2893 | @Override |
| 2894 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2895 | final long identity = Binder.clearCallingIdentity(); |
| 2896 | try { |
| 2897 | final Phone phone = getPhone(subId); |
| 2898 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2899 | } finally { |
| 2900 | Binder.restoreCallingIdentity(identity); |
| 2901 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2902 | } |
| 2903 | |
| 2904 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2905 | * Send the dialer code if called from the current default dialer or the caller has |
| 2906 | * carrier privilege. |
| 2907 | * @param inputCode The dialer code to send |
| 2908 | */ |
| 2909 | @Override |
| 2910 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2911 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2912 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2913 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 2914 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2915 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2916 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2917 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2918 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2919 | |
| 2920 | final long identity = Binder.clearCallingIdentity(); |
| 2921 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2922 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2923 | } finally { |
| 2924 | Binder.restoreCallingIdentity(identity); |
| 2925 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2926 | } |
| 2927 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2928 | @Override |
| 2929 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2930 | if (!isActiveSubscription(subId)) { |
| 2931 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2932 | } |
| 2933 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2934 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2935 | } |
| 2936 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2937 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2938 | public boolean isInEmergencySmsMode() { |
| 2939 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2940 | final long identity = Binder.clearCallingIdentity(); |
| 2941 | try { |
| 2942 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2943 | if (phone.isInEmergencySmsMode()) { |
| 2944 | return true; |
| 2945 | } |
| 2946 | } |
| 2947 | } finally { |
| 2948 | Binder.restoreCallingIdentity(identity); |
| 2949 | } |
| 2950 | return false; |
| 2951 | } |
| 2952 | |
| 2953 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2954 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2955 | throws RemoteException { |
| 2956 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 2957 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 2958 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 2959 | "IMS not available on device."); |
| 2960 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2961 | final long token = Binder.clearCallingIdentity(); |
| 2962 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2963 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2964 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2965 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2966 | } catch (ImsException e) { |
| 2967 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2968 | } finally { |
| 2969 | Binder.restoreCallingIdentity(token); |
| 2970 | } |
| 2971 | } |
| 2972 | |
| 2973 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2974 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2975 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2976 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2977 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2978 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 2979 | final long token = Binder.clearCallingIdentity(); |
| 2980 | try { |
| 2981 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 2982 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 2983 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2984 | } catch (ImsException e) { |
| 2985 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2986 | + "is inactive, ignoring unregister."); |
| 2987 | // If the subscription is no longer active, just return, since the callback |
| 2988 | // will already have been removed internally. |
| 2989 | } finally { |
| 2990 | Binder.restoreCallingIdentity(token); |
| 2991 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2992 | } |
| 2993 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 2994 | /** |
| 2995 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 2996 | */ |
| 2997 | @Override |
| 2998 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 2999 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3000 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3001 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3002 | "IMS not available on device."); |
| 3003 | } |
| 3004 | final long token = Binder.clearCallingIdentity(); |
| 3005 | try { |
| 3006 | Phone phone = getPhone(subId); |
| 3007 | if (phone == null) { |
| 3008 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3009 | + subId + "'"); |
| 3010 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3011 | } |
| 3012 | phone.getImsRegistrationState(regState -> { |
| 3013 | try { |
| 3014 | consumer.accept((regState == null) |
| 3015 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3016 | } catch (RemoteException e) { |
| 3017 | // Ignore if the remote process is no longer available to call back. |
| 3018 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3019 | } |
| 3020 | }); |
| 3021 | } finally { |
| 3022 | Binder.restoreCallingIdentity(token); |
| 3023 | } |
| 3024 | } |
| 3025 | |
| 3026 | /** |
| 3027 | * Get the transport type for the IMS service registration state. |
| 3028 | */ |
| 3029 | @Override |
| 3030 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
| 3031 | enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType"); |
| 3032 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3033 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3034 | "IMS not available on device."); |
| 3035 | } |
| 3036 | final long token = Binder.clearCallingIdentity(); |
| 3037 | try { |
| 3038 | Phone phone = getPhone(subId); |
| 3039 | if (phone == null) { |
| 3040 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3041 | + subId + "'"); |
| 3042 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3043 | } |
| 3044 | phone.getImsRegistrationTech(regTech -> { |
| 3045 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3046 | int regTechConverted = (regTech == null) |
| 3047 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3048 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3049 | regTechConverted); |
| 3050 | try { |
| 3051 | consumer.accept(regTechConverted); |
| 3052 | } catch (RemoteException e) { |
| 3053 | // Ignore if the remote process is no longer available to call back. |
| 3054 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3055 | } |
| 3056 | }); |
| 3057 | } finally { |
| 3058 | Binder.restoreCallingIdentity(token); |
| 3059 | } |
| 3060 | } |
| 3061 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3062 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3063 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3064 | throws RemoteException { |
| 3065 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3066 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3067 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3068 | "IMS not available on device."); |
| 3069 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3070 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3071 | final long token = Binder.clearCallingIdentity(); |
| 3072 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3073 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3074 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3075 | } catch (ImsException e) { |
| 3076 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3077 | } finally { |
| 3078 | Binder.restoreCallingIdentity(token); |
| 3079 | } |
| 3080 | } |
| 3081 | |
| 3082 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3083 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 3084 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3085 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3086 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3087 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3088 | |
| 3089 | final long token = Binder.clearCallingIdentity(); |
| 3090 | try { |
| 3091 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3092 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3093 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3094 | } catch (ImsException e) { |
| 3095 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3096 | + "is inactive, ignoring unregister."); |
| 3097 | // If the subscription is no longer active, just return, since the callback |
| 3098 | // will already have been removed internally. |
| 3099 | } finally { |
| 3100 | Binder.restoreCallingIdentity(token); |
| 3101 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3102 | } |
| 3103 | |
| 3104 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3105 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3106 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3107 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3108 | final long token = Binder.clearCallingIdentity(); |
| 3109 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3110 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3111 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3112 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3113 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3114 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3115 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3116 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3117 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3118 | } finally { |
| 3119 | Binder.restoreCallingIdentity(token); |
| 3120 | } |
| 3121 | } |
| 3122 | |
| 3123 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3124 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3125 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3126 | final long token = Binder.clearCallingIdentity(); |
| 3127 | try { |
| 3128 | Phone phone = getPhone(subId); |
| 3129 | if (phone == null) return false; |
| 3130 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3131 | } finally { |
| 3132 | Binder.restoreCallingIdentity(token); |
| 3133 | } |
| 3134 | } |
| 3135 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3136 | /** |
| 3137 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3138 | * subscription. |
| 3139 | * @param subId The subscription to use to check the configuration. |
| 3140 | * @param callback The callback that will be used to send the result. |
| 3141 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3142 | * @param transportType The transport type of the MmTelFeature capability. |
| 3143 | */ |
| 3144 | @Override |
| 3145 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3146 | int transportType) { |
| 3147 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3148 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3149 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3150 | "IMS not available on device."); |
| 3151 | } |
| 3152 | final long token = Binder.clearCallingIdentity(); |
| 3153 | try { |
| 3154 | int slotId = getSlotIndex(subId); |
| 3155 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3156 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3157 | + subId + "'"); |
| 3158 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3159 | } |
| 3160 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3161 | transportType, aBoolean -> { |
| 3162 | try { |
| 3163 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3164 | } catch (RemoteException e) { |
| 3165 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3166 | + "running. Ignore"); |
| 3167 | } |
| 3168 | }); |
| 3169 | } finally { |
| 3170 | Binder.restoreCallingIdentity(token); |
| 3171 | } |
| 3172 | } |
| 3173 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3174 | @Override |
| 3175 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 3176 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 3177 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3178 | final long token = Binder.clearCallingIdentity(); |
| 3179 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3180 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3181 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3182 | } catch (ImsException e) { |
| 3183 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3184 | } finally { |
| 3185 | Binder.restoreCallingIdentity(token); |
| 3186 | } |
| 3187 | } |
| 3188 | |
| 3189 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3190 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3191 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3192 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3193 | final long identity = Binder.clearCallingIdentity(); |
| 3194 | try { |
| 3195 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3196 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3197 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3198 | } catch (ImsException e) { |
| 3199 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3200 | } finally { |
| 3201 | Binder.restoreCallingIdentity(identity); |
| 3202 | } |
| 3203 | } |
| 3204 | |
| 3205 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3206 | public boolean isVtSettingEnabled(int subId) { |
| 3207 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3208 | final long identity = Binder.clearCallingIdentity(); |
| 3209 | try { |
| 3210 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3211 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3212 | } catch (ImsException e) { |
| 3213 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3214 | } finally { |
| 3215 | Binder.restoreCallingIdentity(identity); |
| 3216 | } |
| 3217 | } |
| 3218 | |
| 3219 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3220 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3221 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3222 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3223 | final long identity = Binder.clearCallingIdentity(); |
| 3224 | try { |
| 3225 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3226 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3227 | } catch (ImsException e) { |
| 3228 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3229 | } finally { |
| 3230 | Binder.restoreCallingIdentity(identity); |
| 3231 | } |
| 3232 | } |
| 3233 | |
| 3234 | @Override |
| 3235 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 3236 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3237 | final long identity = Binder.clearCallingIdentity(); |
| 3238 | try { |
| 3239 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3240 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3241 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3242 | } catch (ImsException e) { |
| 3243 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3244 | } finally { |
| 3245 | Binder.restoreCallingIdentity(identity); |
| 3246 | } |
| 3247 | } |
| 3248 | |
| 3249 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3250 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3251 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3252 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3253 | final long identity = Binder.clearCallingIdentity(); |
| 3254 | try { |
| 3255 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3256 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3257 | } catch (ImsException e) { |
| 3258 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3259 | } finally { |
| 3260 | Binder.restoreCallingIdentity(identity); |
| 3261 | } |
| 3262 | } |
| 3263 | |
| 3264 | @Override |
| 3265 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 3266 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3267 | final long identity = Binder.clearCallingIdentity(); |
| 3268 | try { |
| 3269 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3270 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3271 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3272 | } catch (ImsException e) { |
| 3273 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3274 | } finally { |
| 3275 | Binder.restoreCallingIdentity(identity); |
| 3276 | } |
| 3277 | } |
| 3278 | |
| 3279 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3280 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3281 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3282 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3283 | final long identity = Binder.clearCallingIdentity(); |
| 3284 | try { |
| 3285 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3286 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3287 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3288 | } catch (ImsException e) { |
| 3289 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3290 | } finally { |
| 3291 | Binder.restoreCallingIdentity(identity); |
| 3292 | } |
| 3293 | } |
| 3294 | |
| 3295 | @Override |
| 3296 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3297 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3298 | "setVoWiFiNonPersistent"); |
| 3299 | final long identity = Binder.clearCallingIdentity(); |
| 3300 | try { |
| 3301 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3302 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3303 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3304 | } catch (ImsException e) { |
| 3305 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3306 | } finally { |
| 3307 | Binder.restoreCallingIdentity(identity); |
| 3308 | } |
| 3309 | } |
| 3310 | |
| 3311 | @Override |
| 3312 | public int getVoWiFiModeSetting(int subId) { |
| 3313 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3314 | final long identity = Binder.clearCallingIdentity(); |
| 3315 | try { |
| 3316 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3317 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3318 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3319 | } catch (ImsException e) { |
| 3320 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3321 | } finally { |
| 3322 | Binder.restoreCallingIdentity(identity); |
| 3323 | } |
| 3324 | } |
| 3325 | |
| 3326 | @Override |
| 3327 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3328 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3329 | "setVoWiFiModeSetting"); |
| 3330 | final long identity = Binder.clearCallingIdentity(); |
| 3331 | try { |
| 3332 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3333 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3334 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3335 | } catch (ImsException e) { |
| 3336 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3337 | } finally { |
| 3338 | Binder.restoreCallingIdentity(identity); |
| 3339 | } |
| 3340 | } |
| 3341 | |
| 3342 | @Override |
| 3343 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3344 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3345 | final long identity = Binder.clearCallingIdentity(); |
| 3346 | try { |
| 3347 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3348 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3349 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3350 | } catch (ImsException e) { |
| 3351 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3352 | } finally { |
| 3353 | Binder.restoreCallingIdentity(identity); |
| 3354 | } |
| 3355 | } |
| 3356 | |
| 3357 | @Override |
| 3358 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3359 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3360 | "setVoWiFiRoamingModeSetting"); |
| 3361 | final long identity = Binder.clearCallingIdentity(); |
| 3362 | try { |
| 3363 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3364 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3365 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3366 | } catch (ImsException e) { |
| 3367 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3368 | } finally { |
| 3369 | Binder.restoreCallingIdentity(identity); |
| 3370 | } |
| 3371 | } |
| 3372 | |
| 3373 | @Override |
| 3374 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3375 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3376 | "setRttCapabilityEnabled"); |
| 3377 | final long identity = Binder.clearCallingIdentity(); |
| 3378 | try { |
| 3379 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3380 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3381 | } catch (ImsException e) { |
| 3382 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3383 | } finally { |
| 3384 | Binder.restoreCallingIdentity(identity); |
| 3385 | } |
| 3386 | } |
| 3387 | |
| 3388 | @Override |
| 3389 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3390 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3391 | final long identity = Binder.clearCallingIdentity(); |
| 3392 | try { |
| 3393 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3394 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3395 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3396 | } catch (ImsException e) { |
| 3397 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3398 | } finally { |
| 3399 | Binder.restoreCallingIdentity(identity); |
| 3400 | } |
| 3401 | } |
| 3402 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3403 | @Override |
| 3404 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3405 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3406 | final long identity = Binder.clearCallingIdentity(); |
| 3407 | try { |
| 3408 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3409 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3410 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3411 | } catch (ImsException e) { |
| 3412 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3413 | } finally { |
| 3414 | Binder.restoreCallingIdentity(identity); |
| 3415 | } |
| 3416 | } |
| 3417 | |
| 3418 | @Override |
| 3419 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3420 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3421 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3422 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3423 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3424 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3425 | try { |
| 3426 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3427 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3428 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3429 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3430 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3431 | + "is inactive, ignoring unregister."); |
| 3432 | // If the subscription is no longer active, just return, since the callback will already |
| 3433 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3434 | } finally { |
| 3435 | Binder.restoreCallingIdentity(identity); |
| 3436 | } |
| 3437 | } |
| 3438 | |
| 3439 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3440 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3441 | boolean isProvisioned) { |
| 3442 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3443 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3444 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3445 | } |
| 3446 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3447 | "setProvisioningStatusForCapability"); |
| 3448 | final long identity = Binder.clearCallingIdentity(); |
| 3449 | try { |
| 3450 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3451 | Phone phone = getPhone(subId); |
| 3452 | if (phone == null) { |
| 3453 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3454 | + subId); |
| 3455 | return; |
| 3456 | } |
| 3457 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3458 | return; |
| 3459 | } |
| 3460 | |
| 3461 | // this capability requires provisioning, route to the correct API. |
| 3462 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3463 | switch (capability) { |
| 3464 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3465 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3466 | ims.setVolteProvisioned(isProvisioned); |
| 3467 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3468 | ims.setWfcProvisioned(isProvisioned); |
| 3469 | } |
| 3470 | break; |
| 3471 | } |
| 3472 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3473 | // There is currently no difference in VT provisioning type. |
| 3474 | ims.setVtProvisioned(isProvisioned); |
| 3475 | break; |
| 3476 | } |
| 3477 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3478 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3479 | // change the capability of the feature instead if needed. |
| 3480 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3481 | == isProvisioned) { |
| 3482 | // No change in provisioning. |
| 3483 | return; |
| 3484 | } |
| 3485 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3486 | try { |
| 3487 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3488 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3489 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3490 | + ", Exception" + e.getMessage()); |
| 3491 | } |
| 3492 | break; |
| 3493 | } |
| 3494 | default: { |
| 3495 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3496 | + capability + "', which does not require provisioning."); |
| 3497 | } |
| 3498 | } |
| 3499 | |
| 3500 | } finally { |
| 3501 | Binder.restoreCallingIdentity(identity); |
| 3502 | } |
| 3503 | } |
| 3504 | |
| 3505 | @Override |
| 3506 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3507 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3508 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3509 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3510 | } |
| 3511 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3512 | final long identity = Binder.clearCallingIdentity(); |
| 3513 | try { |
| 3514 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3515 | Phone phone = getPhone(subId); |
| 3516 | if (phone == null) { |
| 3517 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3518 | + subId); |
| 3519 | // We will fail with "true" as the provisioning status because this is the default |
| 3520 | // if we do not require provisioning. |
| 3521 | return true; |
| 3522 | } |
| 3523 | |
| 3524 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3525 | return true; |
| 3526 | } |
| 3527 | |
| 3528 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3529 | switch (capability) { |
| 3530 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3531 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3532 | return ims.isVolteProvisionedOnDevice(); |
| 3533 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3534 | return ims.isWfcProvisionedOnDevice(); |
| 3535 | } |
| 3536 | // This should never happen, since we are checking tech above to make sure it |
| 3537 | // is either LTE or IWLAN. |
| 3538 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3539 | + "capability."); |
| 3540 | } |
| 3541 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3542 | // There is currently no difference in VT provisioning type. |
| 3543 | return ims.isVtProvisionedOnDevice(); |
| 3544 | } |
| 3545 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3546 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3547 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3548 | } |
| 3549 | default: { |
| 3550 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3551 | + capability + "', which does not require provisioning."); |
| 3552 | } |
| 3553 | } |
| 3554 | |
| 3555 | } finally { |
| 3556 | Binder.restoreCallingIdentity(identity); |
| 3557 | } |
| 3558 | } |
| 3559 | |
| 3560 | @Override |
| 3561 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3562 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3563 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3564 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3565 | } |
| 3566 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3567 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3568 | return (provisionedBits & capability) > 0; |
| 3569 | } |
| 3570 | |
| 3571 | @Override |
| 3572 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3573 | boolean isProvisioned) { |
| 3574 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3575 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3576 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3577 | } |
| 3578 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3579 | "setProvisioningStatusForCapability"); |
| 3580 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3581 | // If the current provisioning status for capability already matches isProvisioned, |
| 3582 | // do nothing. |
| 3583 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3584 | return; |
| 3585 | } |
| 3586 | if (isProvisioned) { |
| 3587 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3588 | } else { |
| 3589 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3590 | } |
| 3591 | } |
| 3592 | |
| 3593 | /** |
| 3594 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3595 | * technology. The bitfield should mirror the bitfield defined by |
| 3596 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3597 | */ |
| 3598 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3599 | String key = getMmTelProvisioningKey(subId, tech); |
| 3600 | // Default is no capabilities are provisioned. |
| 3601 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3602 | } |
| 3603 | |
| 3604 | /** |
| 3605 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3606 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3607 | * technology specified. |
| 3608 | * |
| 3609 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3610 | */ |
| 3611 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3612 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3613 | String key = getMmTelProvisioningKey(subId, tech); |
| 3614 | editor.putInt(key, newField); |
| 3615 | editor.commit(); |
| 3616 | } |
| 3617 | |
| 3618 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3619 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3620 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3621 | } |
| 3622 | |
| 3623 | /** |
| 3624 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3625 | * carrier associated with the subscription id. |
| 3626 | */ |
| 3627 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3628 | int capability) { |
| 3629 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3630 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3631 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 3632 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3633 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3634 | false); |
| 3635 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3636 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3637 | |
| 3638 | // First check to make sure that the capability requires provisioning. |
| 3639 | switch (capability) { |
| 3640 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3641 | // intentional fallthrough |
| 3642 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3643 | if (requireVoiceVtProvisioning) { |
| 3644 | // Voice and Video requires provisioning |
| 3645 | return true; |
| 3646 | } |
| 3647 | break; |
| 3648 | } |
| 3649 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3650 | if (requireUtProvisioning) { |
| 3651 | // UT requires provisioning |
| 3652 | return true; |
| 3653 | } |
| 3654 | break; |
| 3655 | } |
| 3656 | } |
| 3657 | return false; |
| 3658 | } |
| 3659 | |
| 3660 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3661 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3662 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3663 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3664 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3665 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3666 | final long identity = Binder.clearCallingIdentity(); |
| 3667 | try { |
| 3668 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3669 | int slotId = getSlotIndex(subId); |
| 3670 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3671 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3672 | + subId + "' for key:" + key); |
| 3673 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3674 | } |
| 3675 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3676 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3677 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3678 | + subId + "' for key:" + key); |
| 3679 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3680 | } finally { |
| 3681 | Binder.restoreCallingIdentity(identity); |
| 3682 | } |
| 3683 | } |
| 3684 | |
| 3685 | @Override |
| 3686 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3687 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3688 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3689 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3690 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3691 | final long identity = Binder.clearCallingIdentity(); |
| 3692 | try { |
| 3693 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3694 | int slotId = getSlotIndex(subId); |
| 3695 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3696 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3697 | + subId + "' for key:" + key); |
| 3698 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3699 | } |
| 3700 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3701 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3702 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3703 | + subId + "' for key:" + key); |
| 3704 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3705 | } finally { |
| 3706 | Binder.restoreCallingIdentity(identity); |
| 3707 | } |
| 3708 | } |
| 3709 | |
| 3710 | @Override |
| 3711 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3712 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3713 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3714 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3715 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3716 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3717 | final long identity = Binder.clearCallingIdentity(); |
| 3718 | try { |
| 3719 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3720 | int slotId = getSlotIndex(subId); |
| 3721 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3722 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3723 | + subId + "' for key:" + key); |
| 3724 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3725 | } |
| 3726 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3727 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3728 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3729 | + "' for key:" + key); |
| 3730 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3731 | } finally { |
| 3732 | Binder.restoreCallingIdentity(identity); |
| 3733 | } |
| 3734 | } |
| 3735 | |
| 3736 | @Override |
| 3737 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3738 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3739 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3740 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3741 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3742 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3743 | final long identity = Binder.clearCallingIdentity(); |
| 3744 | try { |
| 3745 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3746 | int slotId = getSlotIndex(subId); |
| 3747 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3748 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3749 | + subId + "' for key:" + key); |
| 3750 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3751 | } |
| 3752 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3753 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3754 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3755 | + "' for key:" + key); |
| 3756 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3757 | } finally { |
| 3758 | Binder.restoreCallingIdentity(identity); |
| 3759 | } |
| 3760 | } |
| 3761 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3762 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3763 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3764 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3765 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 3766 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3767 | } |
| 3768 | return slotId; |
| 3769 | } |
| 3770 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3771 | private int getSlotIndex(int subId) { |
| 3772 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3773 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3774 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3775 | } |
| 3776 | return slotId; |
| 3777 | } |
| 3778 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3779 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3780 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3781 | */ |
| 3782 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3783 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 3784 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 3785 | final int targetSdk = getTargetSdk(callingPackage); |
| 3786 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3787 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 3788 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3789 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3790 | mApp, subId, callingPackage, callingFeatureId, |
| 3791 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3792 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3793 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3794 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3795 | final long identity = Binder.clearCallingIdentity(); |
| 3796 | try { |
| 3797 | final Phone phone = getPhone(subId); |
| 3798 | if (phone != null) { |
| 3799 | return phone.getServiceState().getDataNetworkType(); |
| 3800 | } else { |
| 3801 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3802 | } |
| 3803 | } finally { |
| 3804 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3805 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3806 | } |
| 3807 | |
| 3808 | /** |
| 3809 | * Returns the data network type |
| 3810 | */ |
| 3811 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3812 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 3813 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3814 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3815 | } |
| 3816 | |
| 3817 | /** |
| 3818 | * Returns the data network type for a subId |
| 3819 | */ |
| 3820 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3821 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 3822 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3823 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3824 | mApp, subId, callingPackage, callingFeatureId, |
| 3825 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3826 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3827 | } |
| 3828 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3829 | final long identity = Binder.clearCallingIdentity(); |
| 3830 | try { |
| 3831 | final Phone phone = getPhone(subId); |
| 3832 | if (phone != null) { |
| 3833 | return phone.getServiceState().getDataNetworkType(); |
| 3834 | } else { |
| 3835 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3836 | } |
| 3837 | } finally { |
| 3838 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3839 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3840 | } |
| 3841 | |
| 3842 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3843 | * Returns the Voice network type for a subId |
| 3844 | */ |
| 3845 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3846 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 3847 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3848 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3849 | mApp, subId, callingPackage, callingFeatureId, |
| 3850 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3851 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3852 | } |
| 3853 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3854 | final long identity = Binder.clearCallingIdentity(); |
| 3855 | try { |
| 3856 | final Phone phone = getPhone(subId); |
| 3857 | if (phone != null) { |
| 3858 | return phone.getServiceState().getVoiceNetworkType(); |
| 3859 | } else { |
| 3860 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3861 | } |
| 3862 | } finally { |
| 3863 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3864 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | /** |
| 3868 | * @return true if a ICC card is present |
| 3869 | */ |
| 3870 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3871 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3872 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3873 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3874 | } |
| 3875 | |
| 3876 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3877 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3878 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3879 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3880 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3881 | final long identity = Binder.clearCallingIdentity(); |
| 3882 | try { |
| 3883 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3884 | if (phone != null) { |
| 3885 | return phone.getIccCard().hasIccCard(); |
| 3886 | } else { |
| 3887 | return false; |
| 3888 | } |
| 3889 | } finally { |
| 3890 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3891 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3892 | } |
| 3893 | |
| 3894 | /** |
| 3895 | * Return if the current radio is LTE on CDMA. This |
| 3896 | * is a tri-state return value as for a period of time |
| 3897 | * the mode may be unknown. |
| 3898 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3899 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3900 | * @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] | 3901 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3902 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3903 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3904 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 3905 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3906 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3907 | } |
| 3908 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3909 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3910 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 3911 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3912 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3913 | mApp, subId, callingPackage, callingFeatureId, |
| 3914 | "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3915 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3916 | } |
| 3917 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3918 | final long identity = Binder.clearCallingIdentity(); |
| 3919 | try { |
| 3920 | final Phone phone = getPhone(subId); |
| 3921 | if (phone == null) { |
| 3922 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3923 | } else { |
| 3924 | return phone.getLteOnCdmaMode(); |
| 3925 | } |
| 3926 | } finally { |
| 3927 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3928 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3929 | } |
| 3930 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3931 | /** |
| 3932 | * {@hide} |
| 3933 | * Returns Default subId, 0 in the case of single standby. |
| 3934 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3935 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3936 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3937 | } |
| 3938 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3939 | private int getSlotForDefaultSubscription() { |
| 3940 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3941 | } |
| 3942 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3943 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3944 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3945 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3946 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3947 | private boolean isActiveSubscription(int subId) { |
| 3948 | return mSubscriptionController.isActiveSubId(subId); |
| 3949 | } |
| 3950 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3951 | /** |
| 3952 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3953 | */ |
| 3954 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3955 | final long identity = Binder.clearCallingIdentity(); |
| 3956 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3957 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3958 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3959 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3960 | } finally { |
| 3961 | Binder.restoreCallingIdentity(identity); |
| 3962 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3963 | } |
| 3964 | |
| 3965 | /** |
| 3966 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3967 | */ |
| 3968 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3969 | final long identity = Binder.clearCallingIdentity(); |
| 3970 | try { |
| 3971 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3972 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3973 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3974 | } finally { |
| 3975 | Binder.restoreCallingIdentity(identity); |
| 3976 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3977 | } |
| 3978 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3979 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3980 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3981 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3982 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3983 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3984 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3985 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3986 | if (phoneId == -1) { |
| 3987 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3988 | + " does not correspond to an active phone"); |
| 3989 | } |
| 3990 | return PhoneFactory.getPhone(phoneId); |
| 3991 | } |
| 3992 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3993 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3994 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3995 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3996 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3997 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3998 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3999 | if (DBG) { |
| 4000 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4001 | } |
| 4002 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4003 | p2); |
| 4004 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4005 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4006 | |
| 4007 | @Override |
| 4008 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4009 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4010 | enforceModifyPermission(); |
| 4011 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4012 | if (DBG) { |
| 4013 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4014 | } |
| 4015 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4016 | callingPackage, aid, p2); |
| 4017 | } |
| 4018 | |
| 4019 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4020 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4021 | final long identity = Binder.clearCallingIdentity(); |
| 4022 | try { |
| 4023 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4024 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4025 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4026 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4027 | if (bestComponent == null |
| 4028 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4029 | loge("The calling package is not allowed to access ISD-R."); |
| 4030 | throw new SecurityException( |
| 4031 | "The calling package is not allowed to access ISD-R."); |
| 4032 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4033 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4034 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4035 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4036 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4037 | null /* workSource */); |
| 4038 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4039 | return response; |
| 4040 | } finally { |
| 4041 | Binder.restoreCallingIdentity(identity); |
| 4042 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4043 | } |
| 4044 | |
| 4045 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4046 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4047 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4048 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4049 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4050 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4051 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4052 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4053 | @Override |
| 4054 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4055 | enforceModifyPermission(); |
| 4056 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4057 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4058 | channel); |
| 4059 | } |
| 4060 | |
| 4061 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4062 | final long identity = Binder.clearCallingIdentity(); |
| 4063 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4064 | if (channel < 0) { |
| 4065 | return false; |
| 4066 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4067 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4068 | null /* workSource */); |
| 4069 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4070 | return success; |
| 4071 | } finally { |
| 4072 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4073 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4074 | } |
| 4075 | |
| 4076 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4077 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4078 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4079 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4080 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4081 | if (DBG) { |
| 4082 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4083 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4084 | + p3 + " data=" + data); |
| 4085 | } |
| 4086 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4087 | command, p1, p2, p3, data); |
| 4088 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4089 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4090 | @Override |
| 4091 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4092 | int command, int p1, int p2, int p3, String data) { |
| 4093 | enforceModifyPermission(); |
| 4094 | if (DBG) { |
| 4095 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4096 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4097 | + p3 + " data=" + data); |
| 4098 | } |
| 4099 | return iccTransmitApduLogicalChannelWithPermission( |
| 4100 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4101 | data); |
| 4102 | } |
| 4103 | |
| 4104 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4105 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4106 | final long identity = Binder.clearCallingIdentity(); |
| 4107 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4108 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4109 | return ""; |
| 4110 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4111 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4112 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4113 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4114 | null /* workSource */); |
| 4115 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4116 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4117 | // Append the returned status code to the end of the response payload. |
| 4118 | String s = Integer.toHexString( |
| 4119 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4120 | if (response.payload != null) { |
| 4121 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4122 | } |
| 4123 | return s; |
| 4124 | } finally { |
| 4125 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4126 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4127 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4128 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4129 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4130 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4131 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4132 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4133 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4134 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4135 | if (DBG) { |
| 4136 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4137 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4138 | } |
| 4139 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4140 | cla, command, p1, p2, p3, data); |
| 4141 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4142 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4143 | @Override |
| 4144 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4145 | int command, int p1, int p2, int p3, String data) { |
| 4146 | enforceModifyPermission(); |
| 4147 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4148 | if (DBG) { |
| 4149 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4150 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4151 | + " data=" + data); |
| 4152 | } |
| 4153 | |
| 4154 | return iccTransmitApduBasicChannelWithPermission( |
| 4155 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4156 | p2, p3, data); |
| 4157 | } |
| 4158 | |
| 4159 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4160 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4161 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4162 | final long identity = Binder.clearCallingIdentity(); |
| 4163 | try { |
| 4164 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4165 | && TextUtils.equals(ISDR_AID, data)) { |
| 4166 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4167 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4168 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4169 | if (bestComponent == null |
| 4170 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4171 | loge("The calling package is not allowed to select ISD-R."); |
| 4172 | throw new SecurityException( |
| 4173 | "The calling package is not allowed to select ISD-R."); |
| 4174 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4175 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4176 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4177 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4178 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4179 | null /* workSource */); |
| 4180 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4181 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4182 | // Append the returned status code to the end of the response payload. |
| 4183 | String s = Integer.toHexString( |
| 4184 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4185 | if (response.payload != null) { |
| 4186 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4187 | } |
| 4188 | return s; |
| 4189 | } finally { |
| 4190 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4191 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4192 | } |
| 4193 | |
| 4194 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4195 | 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] | 4196 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4197 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4198 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4199 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4200 | final long identity = Binder.clearCallingIdentity(); |
| 4201 | try { |
| 4202 | if (DBG) { |
| 4203 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4204 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4205 | } |
| 4206 | |
| 4207 | IccIoResult response = |
| 4208 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4209 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4210 | subId); |
| 4211 | |
| 4212 | if (DBG) { |
| 4213 | log("Exchange SIM_IO [R]" + response); |
| 4214 | } |
| 4215 | |
| 4216 | byte[] result = null; |
| 4217 | int length = 2; |
| 4218 | if (response.payload != null) { |
| 4219 | length = 2 + response.payload.length; |
| 4220 | result = new byte[length]; |
| 4221 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4222 | } else { |
| 4223 | result = new byte[length]; |
| 4224 | } |
| 4225 | |
| 4226 | result[length - 1] = (byte) response.sw2; |
| 4227 | result[length - 2] = (byte) response.sw1; |
| 4228 | return result; |
| 4229 | } finally { |
| 4230 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4231 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4232 | } |
| 4233 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4234 | /** |
| 4235 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4236 | * on a particular subscription |
| 4237 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4238 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4239 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4240 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4241 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4242 | return null; |
| 4243 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4244 | |
| 4245 | final long identity = Binder.clearCallingIdentity(); |
| 4246 | try { |
| 4247 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4248 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4249 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4250 | return null; |
| 4251 | } |
| 4252 | Object response = sendRequest( |
| 4253 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4254 | if (response instanceof String[]) { |
| 4255 | return (String[]) response; |
| 4256 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4257 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4258 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4259 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4260 | } finally { |
| 4261 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4262 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4263 | } |
| 4264 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4265 | /** |
| 4266 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4267 | * subscription. |
| 4268 | * |
| 4269 | * @param subId the id of the subscription. |
| 4270 | * @param appType the uicc app type, must be USIM or SIM. |
| 4271 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4272 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4273 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4274 | * @return number of fplmns that is successfully written to the SIM. |
| 4275 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4276 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4277 | String callingFeatureId) { |
| 4278 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4279 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4280 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4281 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4282 | } |
| 4283 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4284 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4285 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4286 | } |
| 4287 | if (fplmns == null) { |
| 4288 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4289 | } |
| 4290 | for (String fplmn : fplmns) { |
| 4291 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4292 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4293 | } |
| 4294 | } |
| 4295 | final long identity = Binder.clearCallingIdentity(); |
| 4296 | try { |
| 4297 | Object response = sendRequest( |
| 4298 | CMD_SET_FORBIDDEN_PLMNS, |
| 4299 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4300 | subId); |
| 4301 | return (int) response; |
| 4302 | } finally { |
| 4303 | Binder.restoreCallingIdentity(identity); |
| 4304 | } |
| 4305 | } |
| 4306 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4307 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4308 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4309 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4310 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4311 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4312 | final long identity = Binder.clearCallingIdentity(); |
| 4313 | try { |
| 4314 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4315 | if (response.payload == null) { |
| 4316 | return ""; |
| 4317 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4318 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4319 | // Append the returned status code to the end of the response payload. |
| 4320 | String s = Integer.toHexString( |
| 4321 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4322 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4323 | return s; |
| 4324 | } finally { |
| 4325 | Binder.restoreCallingIdentity(identity); |
| 4326 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4327 | } |
| 4328 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4329 | /** |
| 4330 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4331 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4332 | * |
| 4333 | * @param itemID the ID of the item to read |
| 4334 | * @return the NV item as a String, or null on error. |
| 4335 | */ |
| 4336 | @Override |
| 4337 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4338 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4339 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4340 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4341 | |
| 4342 | final long identity = Binder.clearCallingIdentity(); |
| 4343 | try { |
| 4344 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4345 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4346 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4347 | return value; |
| 4348 | } finally { |
| 4349 | Binder.restoreCallingIdentity(identity); |
| 4350 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4351 | } |
| 4352 | |
| 4353 | /** |
| 4354 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4355 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4356 | * |
| 4357 | * @param itemID the ID of the item to read |
| 4358 | * @param itemValue the value to write, as a String |
| 4359 | * @return true on success; false on any failure |
| 4360 | */ |
| 4361 | @Override |
| 4362 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4363 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4364 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4365 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4366 | |
| 4367 | final long identity = Binder.clearCallingIdentity(); |
| 4368 | try { |
| 4369 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4370 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4371 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4372 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4373 | return success; |
| 4374 | } finally { |
| 4375 | Binder.restoreCallingIdentity(identity); |
| 4376 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4377 | } |
| 4378 | |
| 4379 | /** |
| 4380 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4381 | * Used for device configuration by some CDMA operators. |
| 4382 | * |
| 4383 | * @param preferredRoamingList byte array containing the new PRL |
| 4384 | * @return true on success; false on any failure |
| 4385 | */ |
| 4386 | @Override |
| 4387 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4388 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4389 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4390 | |
| 4391 | final long identity = Binder.clearCallingIdentity(); |
| 4392 | try { |
| 4393 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4394 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4395 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4396 | return success; |
| 4397 | } finally { |
| 4398 | Binder.restoreCallingIdentity(identity); |
| 4399 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4400 | } |
| 4401 | |
| 4402 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4403 | * 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] | 4404 | * Used for device configuration by some CDMA operators. |
| 4405 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4406 | * @param slotIndex - device slot. |
| 4407 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4408 | * @return true on success; false on any failure |
| 4409 | */ |
| 4410 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4411 | public boolean resetModemConfig(int slotIndex) { |
| 4412 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4413 | if (phone != null) { |
| 4414 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4415 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4416 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4417 | final long identity = Binder.clearCallingIdentity(); |
| 4418 | try { |
| 4419 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4420 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4421 | return success; |
| 4422 | } finally { |
| 4423 | Binder.restoreCallingIdentity(identity); |
| 4424 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4425 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4426 | return false; |
| 4427 | } |
| 4428 | |
| 4429 | /** |
| 4430 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4431 | * |
| 4432 | * @param slotIndex - device slot. |
| 4433 | * |
| 4434 | * @return true on success; false on any failure |
| 4435 | */ |
| 4436 | @Override |
| 4437 | public boolean rebootModem(int slotIndex) { |
| 4438 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4439 | if (phone != null) { |
| 4440 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4441 | mApp, phone.getSubId(), "rebootModem"); |
| 4442 | |
| 4443 | final long identity = Binder.clearCallingIdentity(); |
| 4444 | try { |
| 4445 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4446 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4447 | return success; |
| 4448 | } finally { |
| 4449 | Binder.restoreCallingIdentity(identity); |
| 4450 | } |
| 4451 | } |
| 4452 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4453 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4454 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4455 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4456 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4457 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4458 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4459 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4460 | return new String[0]; |
| 4461 | } |
| 4462 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4463 | final long identity = Binder.clearCallingIdentity(); |
| 4464 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4465 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4466 | } finally { |
| 4467 | Binder.restoreCallingIdentity(identity); |
| 4468 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4469 | } |
| 4470 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4471 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4472 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4473 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4474 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4475 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4476 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4477 | |
| 4478 | final long identity = Binder.clearCallingIdentity(); |
| 4479 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4480 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4481 | if (resolver == null) { |
| 4482 | // may happen if the device does not support IMS. |
| 4483 | return; |
| 4484 | } |
| 4485 | resolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4486 | } finally { |
| 4487 | Binder.restoreCallingIdentity(identity); |
| 4488 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4489 | } |
| 4490 | |
| 4491 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4492 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4493 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4494 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4495 | public void disableIms(int slotId) { |
| 4496 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4497 | |
| 4498 | final long identity = Binder.clearCallingIdentity(); |
| 4499 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4500 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4501 | if (resolver == null) { |
| 4502 | // may happen if the device does not support IMS. |
| 4503 | return; |
| 4504 | } |
| 4505 | resolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4506 | } finally { |
| 4507 | Binder.restoreCallingIdentity(identity); |
| 4508 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4509 | } |
| 4510 | |
| 4511 | /** |
| 4512 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4513 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4514 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4515 | */ |
| 4516 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4517 | IImsServiceFeatureCallback callback) { |
| 4518 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4519 | |
| 4520 | final long identity = Binder.clearCallingIdentity(); |
| 4521 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4522 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4523 | if (resolver == null) { |
| 4524 | // may happen if the device does not support IMS. |
| 4525 | return null; |
| 4526 | } |
| 4527 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4528 | } finally { |
| 4529 | Binder.restoreCallingIdentity(identity); |
| 4530 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4531 | } |
| 4532 | |
| 4533 | /** |
| 4534 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4535 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4536 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4537 | * listener for feature updates. |
| 4538 | */ |
| 4539 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4540 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4541 | |
| 4542 | final long identity = Binder.clearCallingIdentity(); |
| 4543 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4544 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4545 | if (resolver == null) { |
| 4546 | // may happen if the device does not support IMS. |
| 4547 | return null; |
| 4548 | } |
| 4549 | return resolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4550 | } finally { |
| 4551 | Binder.restoreCallingIdentity(identity); |
| 4552 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4553 | } |
| 4554 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4555 | /** |
| 4556 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4557 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4558 | */ |
| 4559 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4560 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4561 | |
| 4562 | final long identity = Binder.clearCallingIdentity(); |
| 4563 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4564 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4565 | if (resolver == null) { |
| 4566 | // may happen if the device does not support IMS. |
| 4567 | return null; |
| 4568 | } |
| 4569 | return resolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4570 | } finally { |
| 4571 | Binder.restoreCallingIdentity(identity); |
| 4572 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4573 | } |
| 4574 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4575 | /** |
| 4576 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4577 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4578 | */ |
| 4579 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4580 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4581 | |
| 4582 | final long identity = Binder.clearCallingIdentity(); |
| 4583 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4584 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4585 | if (resolver == null) { |
| 4586 | // may happen if the device does not support IMS. |
| 4587 | return null; |
| 4588 | } |
| 4589 | return resolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4590 | } finally { |
| 4591 | Binder.restoreCallingIdentity(identity); |
| 4592 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4593 | } |
| 4594 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4595 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4596 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4597 | * |
| 4598 | * @param slotId the slot ID that the ImsService should bind for. |
| 4599 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4600 | * ImsService is the device default ImsService. |
| 4601 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4602 | * to. |
| 4603 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4604 | * @hide |
| 4605 | */ |
| 4606 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4607 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4608 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4609 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4610 | "setImsService"); |
| 4611 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4612 | final long identity = Binder.clearCallingIdentity(); |
| 4613 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4614 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4615 | if (resolver == null) { |
| 4616 | // may happen if the device does not support IMS. |
| 4617 | return false; |
| 4618 | } |
| 4619 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4620 | packageName); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4621 | } finally { |
| 4622 | Binder.restoreCallingIdentity(identity); |
| 4623 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4624 | } |
| 4625 | |
| 4626 | /** |
| 4627 | * Return the ImsService configuration. |
| 4628 | * |
| 4629 | * @param slotId The slot that the ImsService is associated with. |
| 4630 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4631 | * the device default. |
| 4632 | * @return the package name of the ImsService configuration. |
| 4633 | */ |
| 4634 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4635 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4636 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4637 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4638 | "getImsService"); |
| 4639 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4640 | final long identity = Binder.clearCallingIdentity(); |
| 4641 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4642 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4643 | if (resolver == null) { |
| 4644 | // may happen if the device does not support IMS. |
| 4645 | return ""; |
| 4646 | } |
| 4647 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4648 | } finally { |
| 4649 | Binder.restoreCallingIdentity(identity); |
| 4650 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4651 | } |
| 4652 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4653 | /** |
| 4654 | * Get the MmTelFeature state associated with the requested subscription id. |
| 4655 | * @param subId The subscription that the MmTelFeature is associated with. |
| 4656 | * @param callback A callback with an integer containing the |
| 4657 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 4658 | */ |
| 4659 | @Override |
| 4660 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 4661 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 4662 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4663 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4664 | "IMS not available on device."); |
| 4665 | } |
| 4666 | final long token = Binder.clearCallingIdentity(); |
| 4667 | try { |
| 4668 | int slotId = getSlotIndex(subId); |
| 4669 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4670 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 4671 | + subId + "'"); |
| 4672 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4673 | } |
| 4674 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 4675 | try { |
| 4676 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 4677 | } catch (RemoteException e) { |
| 4678 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 4679 | + "Ignore"); |
| 4680 | } |
| 4681 | }); |
| 4682 | } finally { |
| 4683 | Binder.restoreCallingIdentity(token); |
| 4684 | } |
| 4685 | } |
| 4686 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4687 | public void setImsRegistrationState(boolean registered) { |
| 4688 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4689 | |
| 4690 | final long identity = Binder.clearCallingIdentity(); |
| 4691 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4692 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4693 | } finally { |
| 4694 | Binder.restoreCallingIdentity(identity); |
| 4695 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4696 | } |
| 4697 | |
| 4698 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4699 | * Set the network selection mode to automatic. |
| 4700 | * |
| 4701 | */ |
| 4702 | @Override |
| 4703 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4704 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4705 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4706 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4707 | if (!isActiveSubscription(subId)) { |
| 4708 | return; |
| 4709 | } |
| 4710 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4711 | final long identity = Binder.clearCallingIdentity(); |
| 4712 | try { |
| 4713 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4714 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4715 | } finally { |
| 4716 | Binder.restoreCallingIdentity(identity); |
| 4717 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4718 | } |
| 4719 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4720 | /** |
| 4721 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4722 | * |
| 4723 | * @param subId the id of the subscription. |
| 4724 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4725 | * the operator to attach to. |
| 4726 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4727 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4728 | * normal network selection next time. |
| 4729 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4730 | */ |
| 4731 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4732 | public boolean setNetworkSelectionModeManual( |
| 4733 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4734 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4735 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4736 | |
| 4737 | if (!isActiveSubscription(subId)) { |
| 4738 | return false; |
| 4739 | } |
| 4740 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4741 | final long identity = Binder.clearCallingIdentity(); |
| 4742 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4743 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4744 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4745 | if (DBG) { |
| 4746 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4747 | + " operator: " + operatorInfo); |
| 4748 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4749 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4750 | } finally { |
| 4751 | Binder.restoreCallingIdentity(identity); |
| 4752 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4753 | } |
| 4754 | |
| 4755 | /** |
| 4756 | * Scans for available networks. |
| 4757 | */ |
| 4758 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 4759 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 4760 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4761 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4762 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4763 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4764 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4765 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4766 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 4767 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4768 | .setCallingPid(Binder.getCallingPid()) |
| 4769 | .setCallingUid(Binder.getCallingUid()) |
| 4770 | .setMethod("getCellNetworkScanResults") |
| 4771 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4772 | .build()); |
| 4773 | switch (locationResult) { |
| 4774 | case DENIED_HARD: |
| 4775 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4776 | case DENIED_SOFT: |
| 4777 | return null; |
| 4778 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4779 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4780 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4781 | try { |
| 4782 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4783 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4784 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4785 | } finally { |
| 4786 | Binder.restoreCallingIdentity(identity); |
| 4787 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4788 | } |
| 4789 | |
| 4790 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4791 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4792 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4793 | * @param subId id of the subscription |
| 4794 | * @param request contains the radio access networks with bands/channels to scan |
| 4795 | * @param messenger callback messenger for scan results or errors |
| 4796 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4797 | * @return the id of the requested scan which can be used to stop the scan. |
| 4798 | */ |
| 4799 | @Override |
| 4800 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 4801 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4802 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4803 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4804 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4805 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4806 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4807 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 4808 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4809 | .setCallingPid(Binder.getCallingPid()) |
| 4810 | .setCallingUid(Binder.getCallingUid()) |
| 4811 | .setMethod("requestNetworkScan") |
| 4812 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4813 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4814 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4815 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4816 | if (e != null) { |
| 4817 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 4818 | throw e; |
| 4819 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 4820 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4821 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 4822 | } |
| 4823 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4824 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4825 | int callingUid = Binder.getCallingUid(); |
| 4826 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4827 | final long identity = Binder.clearCallingIdentity(); |
| 4828 | try { |
| 4829 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4830 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4831 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4832 | } finally { |
| 4833 | Binder.restoreCallingIdentity(identity); |
| 4834 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4835 | } |
| 4836 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4837 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4838 | NetworkScanRequest request, int subId) { |
| 4839 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 4840 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4841 | boolean hasNetworkScanPermission = |
| 4842 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 4843 | == PERMISSION_GRANTED; |
| 4844 | |
| 4845 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 4846 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 4847 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4848 | } |
| 4849 | |
| 4850 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 4851 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4852 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 4853 | return new SecurityException("Specific channels must not be" |
| 4854 | + " scanned without location access."); |
| 4855 | } |
| 4856 | } |
| 4857 | } |
| 4858 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4859 | return null; |
| 4860 | } |
| 4861 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4862 | /** |
| 4863 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4864 | * |
| 4865 | * @param subId id of the subscription |
| 4866 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4867 | */ |
| 4868 | @Override |
| 4869 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4870 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4871 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4872 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4873 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4874 | final long identity = Binder.clearCallingIdentity(); |
| 4875 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4876 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4877 | } finally { |
| 4878 | Binder.restoreCallingIdentity(identity); |
| 4879 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4880 | } |
| 4881 | |
| 4882 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4883 | * Get the calculated preferred network type. |
| 4884 | * Used for debugging incorrect network type. |
| 4885 | * |
| 4886 | * @return the preferred network type, defined in RILConstants.java. |
| 4887 | */ |
| 4888 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4889 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4890 | final Phone defaultPhone = getDefaultPhone(); |
| 4891 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4892 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4893 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4894 | } |
| 4895 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4896 | final long identity = Binder.clearCallingIdentity(); |
| 4897 | try { |
| 4898 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4899 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4900 | } finally { |
| 4901 | Binder.restoreCallingIdentity(identity); |
| 4902 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4903 | } |
| 4904 | |
| 4905 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4906 | * Get the preferred network type. |
| 4907 | * Used for device configuration by some CDMA operators. |
| 4908 | * |
| 4909 | * @return the preferred network type, defined in RILConstants.java. |
| 4910 | */ |
| 4911 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4912 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4913 | TelephonyPermissions |
| 4914 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4915 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4916 | |
| 4917 | final long identity = Binder.clearCallingIdentity(); |
| 4918 | try { |
| 4919 | if (DBG) log("getPreferredNetworkType"); |
| 4920 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4921 | int networkType = (result != null ? result[0] : -1); |
| 4922 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4923 | return networkType; |
| 4924 | } finally { |
| 4925 | Binder.restoreCallingIdentity(identity); |
| 4926 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4927 | } |
| 4928 | |
| 4929 | /** |
| 4930 | * Set the preferred network type. |
| 4931 | * Used for device configuration by some CDMA operators. |
| 4932 | * |
| 4933 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4934 | * @return true on success; false on any failure. |
| 4935 | */ |
| 4936 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4937 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4938 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4939 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4940 | |
| 4941 | final long identity = Binder.clearCallingIdentity(); |
| 4942 | try { |
| 4943 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4944 | Boolean success = (Boolean) sendRequest( |
| 4945 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4946 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4947 | if (success) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4948 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4949 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4950 | } |
| 4951 | return success; |
| 4952 | } finally { |
| 4953 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4954 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4955 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4956 | |
| 4957 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4958 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4959 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4960 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4961 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4962 | * @hide |
| 4963 | */ |
| 4964 | @Override |
SongFerngWang | f3c7bf8 | 2019-11-07 17:27:26 +0800 | [diff] [blame] | 4965 | public boolean isTetherApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4966 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4967 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4968 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4969 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4970 | if (phone != null) { |
| 4971 | return phone.hasMatchedTetherApnSetting(); |
| 4972 | } else { |
| 4973 | return false; |
| 4974 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4975 | } finally { |
| 4976 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4977 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4981 | * Set mobile data enabled |
| 4982 | * Used by the user through settings etc to turn on/off mobile data |
| 4983 | * |
| 4984 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4985 | */ |
| 4986 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4987 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4988 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4989 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4990 | |
| 4991 | final long identity = Binder.clearCallingIdentity(); |
| 4992 | try { |
| 4993 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4994 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4995 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4996 | if (phone != null) { |
| 4997 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4998 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4999 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5000 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5001 | } |
| 5002 | } finally { |
| 5003 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5004 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5005 | } |
| 5006 | |
| 5007 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5008 | * Get the user enabled state of Mobile Data. |
| 5009 | * |
| 5010 | * TODO: remove and use isUserDataEnabled. |
| 5011 | * This can't be removed now because some vendor codes |
| 5012 | * calls through ITelephony directly while they should |
| 5013 | * use TelephonyManager. |
| 5014 | * |
| 5015 | * @return true on enabled |
| 5016 | */ |
| 5017 | @Override |
| 5018 | public boolean getDataEnabled(int subId) { |
| 5019 | return isUserDataEnabled(subId); |
| 5020 | } |
| 5021 | |
| 5022 | /** |
| 5023 | * Get whether mobile data is enabled per user setting. |
| 5024 | * |
| 5025 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5026 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5027 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5028 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5029 | * |
| 5030 | * @return {@code true} if data is enabled else {@code false} |
| 5031 | */ |
| 5032 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5033 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5034 | try { |
| 5035 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5036 | null); |
| 5037 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5038 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5039 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5040 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5041 | |
| 5042 | final long identity = Binder.clearCallingIdentity(); |
| 5043 | try { |
| 5044 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5045 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5046 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5047 | if (phone != null) { |
| 5048 | boolean retVal = phone.isUserDataEnabled(); |
| 5049 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5050 | return retVal; |
| 5051 | } else { |
| 5052 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5053 | return false; |
| 5054 | } |
| 5055 | } finally { |
| 5056 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5057 | } |
| 5058 | } |
| 5059 | |
| 5060 | /** |
| 5061 | * Get whether mobile data is enabled. |
| 5062 | * |
| 5063 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 5064 | * whether mobile data is actually enabled. |
| 5065 | * |
| 5066 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 5067 | * |
| 5068 | * @return {@code true} if data is enabled else {@code false} |
| 5069 | */ |
| 5070 | @Override |
| 5071 | public boolean isDataEnabled(int subId) { |
| 5072 | try { |
| 5073 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5074 | null); |
| 5075 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5076 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5077 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5078 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5079 | |
| 5080 | final long identity = Binder.clearCallingIdentity(); |
| 5081 | try { |
| 5082 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5083 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5084 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5085 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5086 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5087 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5088 | return retVal; |
| 5089 | } else { |
| 5090 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5091 | return false; |
| 5092 | } |
| 5093 | } finally { |
| 5094 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5095 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5096 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5097 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5098 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 5099 | Phone phone) { |
| 5100 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5101 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5102 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5103 | || subController == null) return privilegeFromSim; |
| 5104 | |
| 5105 | int uid = Binder.getCallingUid(); |
| 5106 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5107 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5108 | |
| 5109 | final long identity = Binder.clearCallingIdentity(); |
| 5110 | try { |
| 5111 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5112 | SubscriptionManager subManager = (SubscriptionManager) |
| 5113 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5114 | for (String pkg : packages) { |
| 5115 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5116 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5117 | } |
| 5118 | } |
| 5119 | return privilegeFromSim; |
| 5120 | } finally { |
| 5121 | Binder.restoreCallingIdentity(identity); |
| 5122 | } |
| 5123 | } |
| 5124 | |
| 5125 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5126 | String pkgName) { |
| 5127 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5128 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5129 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5130 | || subController == null) return privilegeFromSim; |
| 5131 | |
| 5132 | final long identity = Binder.clearCallingIdentity(); |
| 5133 | try { |
| 5134 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5135 | SubscriptionManager subManager = (SubscriptionManager) |
| 5136 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5137 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5138 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5139 | } finally { |
| 5140 | Binder.restoreCallingIdentity(identity); |
| 5141 | } |
| 5142 | } |
| 5143 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5144 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5145 | public int getCarrierPrivilegeStatus(int subId) { |
| 5146 | final Phone phone = getPhone(subId); |
| 5147 | if (phone == null) { |
| 5148 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5149 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5150 | } |
| 5151 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5152 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5153 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5154 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5155 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5156 | |
| 5157 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5158 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 5159 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5160 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5161 | |
| 5162 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5163 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 5164 | final Phone phone = getPhone(subId); |
| 5165 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5166 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5167 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5168 | } |
| 5169 | UiccProfile profile = |
| 5170 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5171 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5172 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5173 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5174 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5175 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5176 | profile.getCarrierPrivilegeStatusForUid( |
| 5177 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5178 | } |
| 5179 | |
| 5180 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5181 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5182 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5183 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5184 | } |
| 5185 | |
| 5186 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5187 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5188 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5189 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5190 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5191 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5192 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5193 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5194 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5195 | } |
| 5196 | |
| 5197 | @Override |
| 5198 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5199 | if (TextUtils.isEmpty(pkgName)) |
| 5200 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5201 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5202 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5203 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5204 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5205 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5206 | continue; |
| 5207 | } |
| 5208 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5209 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5210 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5211 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5212 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5213 | break; |
| 5214 | } |
| 5215 | } |
| 5216 | |
| 5217 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5218 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5219 | |
| 5220 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5221 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5222 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5223 | loge("phoneId " + phoneId + " is not valid."); |
| 5224 | return null; |
| 5225 | } |
| 5226 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5227 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5228 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5229 | return null ; |
| 5230 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5231 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5232 | } |
| 5233 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5234 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5235 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5236 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5237 | List<String> privilegedPackages = new ArrayList<>(); |
| 5238 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5239 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5240 | // has UICC in that slot. |
| 5241 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5242 | if (card.hasCarrierPrivilegeRules()) { |
| 5243 | if (packages == null) { |
| 5244 | // Only check packages in user 0 for now |
| 5245 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5246 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5247 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5248 | | PackageManager.GET_SIGNING_CERTIFICATES, |
| 5249 | UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5250 | } |
| 5251 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5252 | PackageInfo pkgInfo = packages.get(p); |
| 5253 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5254 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5255 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5256 | privilegedPackages.add(pkgInfo.packageName); |
| 5257 | } |
| 5258 | } |
| 5259 | } |
| 5260 | } |
| 5261 | return privilegedPackages; |
| 5262 | } |
| 5263 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5264 | @Override |
| 5265 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
| 5266 | List<String> privilegedPackages = new ArrayList<>(); |
| 5267 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5268 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5269 | } |
| 5270 | return privilegedPackages; |
| 5271 | } |
| 5272 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5273 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5274 | final Phone phone = getPhone(subId); |
| 5275 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5276 | if (card == null) { |
| 5277 | loge("getIccId: No UICC"); |
| 5278 | return null; |
| 5279 | } |
| 5280 | String iccId = card.getIccId(); |
| 5281 | if (TextUtils.isEmpty(iccId)) { |
| 5282 | loge("getIccId: ICC ID is null or empty."); |
| 5283 | return null; |
| 5284 | } |
| 5285 | return iccId; |
| 5286 | } |
| 5287 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5288 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5289 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5290 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5291 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5292 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5293 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5294 | final long identity = Binder.clearCallingIdentity(); |
| 5295 | try { |
| 5296 | final String iccId = getIccId(subId); |
| 5297 | final Phone phone = getPhone(subId); |
| 5298 | if (phone == null) { |
| 5299 | return false; |
| 5300 | } |
| 5301 | final String subscriberId = phone.getSubscriberId(); |
| 5302 | |
| 5303 | if (DBG_MERGE) { |
| 5304 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 5305 | + subscriberId + " to " + number); |
| 5306 | } |
| 5307 | |
| 5308 | if (TextUtils.isEmpty(iccId)) { |
| 5309 | return false; |
| 5310 | } |
| 5311 | |
| 5312 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5313 | |
| 5314 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5315 | if (alphaTag == null) { |
| 5316 | editor.remove(alphaTagPrefKey); |
| 5317 | } else { |
| 5318 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5319 | } |
| 5320 | |
| 5321 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5322 | // track all merged IMSIs based on line number |
| 5323 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5324 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5325 | if (number == null) { |
| 5326 | editor.remove(numberPrefKey); |
| 5327 | editor.remove(subscriberPrefKey); |
| 5328 | } else { |
| 5329 | editor.putString(numberPrefKey, number); |
| 5330 | editor.putString(subscriberPrefKey, subscriberId); |
| 5331 | } |
| 5332 | |
| 5333 | editor.commit(); |
| 5334 | return true; |
| 5335 | } finally { |
| 5336 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5337 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5338 | } |
| 5339 | |
| 5340 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5341 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 5342 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5343 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5344 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5345 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5346 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5347 | return null; |
| 5348 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5349 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5350 | final long identity = Binder.clearCallingIdentity(); |
| 5351 | try { |
| 5352 | String iccId = getIccId(subId); |
| 5353 | if (iccId != null) { |
| 5354 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5355 | if (DBG_MERGE) { |
| 5356 | log("getLine1NumberForDisplay returning " |
| 5357 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5358 | } |
| 5359 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5360 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5361 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5362 | return null; |
| 5363 | } finally { |
| 5364 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5365 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5366 | } |
| 5367 | |
| 5368 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5369 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 5370 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5371 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5372 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5373 | return null; |
| 5374 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5375 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5376 | final long identity = Binder.clearCallingIdentity(); |
| 5377 | try { |
| 5378 | String iccId = getIccId(subId); |
| 5379 | if (iccId != null) { |
| 5380 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5381 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5382 | } |
| 5383 | return null; |
| 5384 | } finally { |
| 5385 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5386 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5387 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5388 | |
| 5389 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5390 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 5391 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5392 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5393 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5394 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5395 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5396 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5397 | return null; |
| 5398 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5399 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5400 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5401 | // the process, where TelephonyManager was instantiated. |
| 5402 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5403 | final long identity = Binder.clearCallingIdentity(); |
| 5404 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5405 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5406 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5407 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5408 | |
| 5409 | // Figure out what subscribers are currently active |
| 5410 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5411 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5412 | // Only consider subs which match the current subId |
| 5413 | // This logic can be simplified. See b/131189269 for progress. |
| 5414 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5415 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5416 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5417 | |
| 5418 | // First pass, find a number override for an active subscriber |
| 5419 | String mergeNumber = null; |
| 5420 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5421 | for (String key : prefs.keySet()) { |
| 5422 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5423 | final String subscriberId = (String) prefs.get(key); |
| 5424 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5425 | final String iccId = key.substring( |
| 5426 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5427 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5428 | mergeNumber = (String) prefs.get(numberKey); |
| 5429 | if (DBG_MERGE) { |
| 5430 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5431 | + " for active subscriber " + subscriberId); |
| 5432 | } |
| 5433 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5434 | break; |
| 5435 | } |
| 5436 | } |
| 5437 | } |
| 5438 | } |
| 5439 | |
| 5440 | // Shortcut when no active merged subscribers |
| 5441 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5442 | return null; |
| 5443 | } |
| 5444 | |
| 5445 | // Second pass, find all subscribers under that line override |
| 5446 | final ArraySet<String> result = new ArraySet<>(); |
| 5447 | for (String key : prefs.keySet()) { |
| 5448 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5449 | final String number = (String) prefs.get(key); |
| 5450 | if (mergeNumber.equals(number)) { |
| 5451 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5452 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5453 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5454 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5455 | result.add(subscriberId); |
| 5456 | } |
| 5457 | } |
| 5458 | } |
| 5459 | } |
| 5460 | |
| 5461 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5462 | Arrays.sort(resultArray); |
| 5463 | if (DBG_MERGE) { |
| 5464 | Slog.d(LOG_TAG, |
| 5465 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5466 | } |
| 5467 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5468 | } finally { |
| 5469 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5470 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5471 | } |
| 5472 | |
| 5473 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5474 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 5475 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 5476 | |
| 5477 | final long identity = Binder.clearCallingIdentity(); |
| 5478 | try { |
| 5479 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 5480 | TelephonyManager.class); |
| 5481 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 5482 | if (subscriberId == null) { |
| 5483 | if (DBG) { |
| 5484 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 5485 | + subId); |
| 5486 | } |
| 5487 | return null; |
| 5488 | } |
| 5489 | |
| 5490 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 5491 | .getSubscriptionInfo(subId); |
| 5492 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 5493 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 5494 | if (groupUuid == null) { |
| 5495 | return new String[]{subscriberId}; |
| 5496 | } |
| 5497 | |
| 5498 | // Get all subscriberIds from the group. |
| 5499 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 5500 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5501 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 5502 | mApp.getFeatureId()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5503 | for (SubscriptionInfo subInfo : groupInfos) { |
| 5504 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 5505 | if (subscriberId != null) { |
| 5506 | mergedSubscriberIds.add(subscriberId); |
| 5507 | } |
| 5508 | } |
| 5509 | |
| 5510 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 5511 | } finally { |
| 5512 | Binder.restoreCallingIdentity(identity); |
| 5513 | |
| 5514 | } |
| 5515 | } |
| 5516 | |
| 5517 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5518 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5519 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5520 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5521 | |
| 5522 | final long identity = Binder.clearCallingIdentity(); |
| 5523 | try { |
| 5524 | final Phone phone = getPhone(subId); |
| 5525 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5526 | } finally { |
| 5527 | Binder.restoreCallingIdentity(identity); |
| 5528 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5529 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5530 | |
| 5531 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5532 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5533 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5534 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5535 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5536 | |
| 5537 | final long identity = Binder.clearCallingIdentity(); |
| 5538 | try { |
| 5539 | final Phone phone = getPhone(subId); |
| 5540 | if (phone == null) { |
| 5541 | return false; |
| 5542 | } |
| 5543 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5544 | cdmaNonRoamingList); |
| 5545 | } finally { |
| 5546 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5547 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5548 | } |
| 5549 | |
| 5550 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5551 | @Deprecated |
| 5552 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5553 | enforceModifyPermission(); |
| 5554 | |
| 5555 | int returnValue = 0; |
| 5556 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5557 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5558 | if(result.exception == null) { |
| 5559 | if (result.result != null) { |
| 5560 | byte[] responseData = (byte[])(result.result); |
| 5561 | if(responseData.length > oemResp.length) { |
| 5562 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5563 | responseData.length + "bytes. Buffer Size is " + |
| 5564 | oemResp.length + "bytes."); |
| 5565 | } |
| 5566 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5567 | returnValue = responseData.length; |
| 5568 | } |
| 5569 | } else { |
| 5570 | CommandException ex = (CommandException) result.exception; |
| 5571 | returnValue = ex.getCommandError().ordinal(); |
| 5572 | if(returnValue > 0) returnValue *= -1; |
| 5573 | } |
| 5574 | } catch (RuntimeException e) { |
| 5575 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5576 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5577 | if(returnValue > 0) returnValue *= -1; |
| 5578 | } |
| 5579 | |
| 5580 | return returnValue; |
| 5581 | } |
| 5582 | |
| 5583 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5584 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5585 | try { |
| 5586 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5587 | } catch (RuntimeException e) { |
| 5588 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5589 | } |
| 5590 | } |
| 5591 | |
| 5592 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5593 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5594 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5595 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5596 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5597 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5598 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5599 | final long identity = Binder.clearCallingIdentity(); |
| 5600 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5601 | TelephonyPermissions |
| 5602 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5603 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5604 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5605 | } finally { |
| 5606 | Binder.restoreCallingIdentity(identity); |
| 5607 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5608 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5609 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5610 | |
| 5611 | @Override |
| 5612 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5613 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5614 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5615 | |
| 5616 | final long identity = Binder.clearCallingIdentity(); |
| 5617 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5618 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5619 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5620 | } finally { |
| 5621 | Binder.restoreCallingIdentity(identity); |
| 5622 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5623 | } |
| 5624 | |
| 5625 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5626 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5627 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5628 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5629 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5630 | return false; |
| 5631 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5632 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5633 | final long identity = Binder.clearCallingIdentity(); |
| 5634 | try { |
| 5635 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5636 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5637 | // In the long run, we may instead need to check if there exists a connection service |
| 5638 | // which can support video calling. |
| 5639 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5640 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5641 | return imsManager.isVtEnabledByPlatform() |
| 5642 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5643 | && imsManager.isVtEnabledByUser(); |
| 5644 | } finally { |
| 5645 | Binder.restoreCallingIdentity(identity); |
| 5646 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5647 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5648 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5649 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5650 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 5651 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5652 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5653 | mApp, subId, callingPackage, callingFeatureId, |
| 5654 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5655 | return false; |
| 5656 | } |
| 5657 | |
| 5658 | final long identity = Binder.clearCallingIdentity(); |
| 5659 | try { |
| 5660 | CarrierConfigManager configManager = |
| 5661 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5662 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5663 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5664 | } finally { |
| 5665 | Binder.restoreCallingIdentity(identity); |
| 5666 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5667 | } |
| 5668 | |
| 5669 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5670 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5671 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5672 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5673 | return false; |
| 5674 | } |
| 5675 | |
| 5676 | final long identity = Binder.clearCallingIdentity(); |
| 5677 | try { |
| 5678 | CarrierConfigManager configManager = |
| 5679 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5680 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5681 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5682 | } finally { |
| 5683 | Binder.restoreCallingIdentity(identity); |
| 5684 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5685 | } |
| 5686 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5687 | @Override |
| 5688 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 5689 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5690 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5691 | } |
| 5692 | |
| 5693 | @Override |
| 5694 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5695 | final long identity = Binder.clearCallingIdentity(); |
| 5696 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5697 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5698 | } finally { |
| 5699 | Binder.restoreCallingIdentity(identity); |
| 5700 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5701 | } |
| 5702 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5703 | /** |
| 5704 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5705 | * support for the feature and device firmware support. |
| 5706 | * |
| 5707 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5708 | */ |
| 5709 | @Override |
| 5710 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5711 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5712 | final Phone phone = getPhone(subscriptionId); |
| 5713 | if (phone == null) { |
| 5714 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5715 | return false; |
| 5716 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5717 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5718 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5719 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5720 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5721 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5722 | return isCarrierSupported && isDeviceSupported; |
| 5723 | } finally { |
| 5724 | Binder.restoreCallingIdentity(identity); |
| 5725 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5726 | } |
| 5727 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5728 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5729 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 5730 | * RTT setting, will return true if the device and carrier both support RTT. |
| 5731 | * 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] | 5732 | */ |
| 5733 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5734 | final long identity = Binder.clearCallingIdentity(); |
| 5735 | try { |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5736 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 5737 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5738 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5739 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 5740 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 5741 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5742 | } finally { |
| 5743 | Binder.restoreCallingIdentity(identity); |
| 5744 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5745 | } |
| 5746 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5747 | @Deprecated |
| 5748 | @Override |
| 5749 | public String getDeviceId(String callingPackage) { |
| 5750 | return getDeviceIdWithFeature(callingPackage, null); |
| 5751 | } |
| 5752 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5753 | /** |
| 5754 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5755 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5756 | * |
| 5757 | * <p>Requires Permission: |
| 5758 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5759 | */ |
| 5760 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5761 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5762 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5763 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5764 | return null; |
| 5765 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5766 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 5767 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5768 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5769 | return null; |
| 5770 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5771 | |
| 5772 | final long identity = Binder.clearCallingIdentity(); |
| 5773 | try { |
| 5774 | return phone.getDeviceId(); |
| 5775 | } finally { |
| 5776 | Binder.restoreCallingIdentity(identity); |
| 5777 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5778 | } |
| 5779 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5780 | /** |
| 5781 | * {@hide} |
| 5782 | * Returns the IMS Registration Status on a particular subid |
| 5783 | * |
| 5784 | * @param subId |
| 5785 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5786 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5787 | Phone phone = getPhone(subId); |
| 5788 | if (phone != null) { |
| 5789 | return phone.isImsRegistered(); |
| 5790 | } else { |
| 5791 | return false; |
| 5792 | } |
| 5793 | } |
| 5794 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5795 | @Override |
| 5796 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5797 | final long identity = Binder.clearCallingIdentity(); |
| 5798 | try { |
| 5799 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5800 | } finally { |
| 5801 | Binder.restoreCallingIdentity(identity); |
| 5802 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5803 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5804 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5805 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 5806 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5807 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 5808 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5809 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 5810 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 5811 | } |
| 5812 | final long identity = Binder.clearCallingIdentity(); |
| 5813 | try { |
| 5814 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 5815 | } finally { |
| 5816 | Binder.restoreCallingIdentity(identity); |
| 5817 | } |
| 5818 | } |
| 5819 | |
| 5820 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5821 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5822 | final long identity = Binder.clearCallingIdentity(); |
| 5823 | try { |
| 5824 | Phone phone = getPhone(subscriptionId); |
| 5825 | if (phone == null) { |
| 5826 | return null; |
| 5827 | } |
| 5828 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5829 | } finally { |
| 5830 | Binder.restoreCallingIdentity(identity); |
| 5831 | } |
| 5832 | } |
| 5833 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5834 | /** |
| 5835 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5836 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5837 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5838 | final long identity = Binder.clearCallingIdentity(); |
| 5839 | try { |
| 5840 | Phone phone = getPhone(subId); |
| 5841 | if (phone != null) { |
| 5842 | return phone.isWifiCallingEnabled(); |
| 5843 | } else { |
| 5844 | return false; |
| 5845 | } |
| 5846 | } finally { |
| 5847 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5848 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5849 | } |
| 5850 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5851 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5852 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5853 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5854 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5855 | final long identity = Binder.clearCallingIdentity(); |
| 5856 | try { |
| 5857 | Phone phone = getPhone(subId); |
| 5858 | if (phone != null) { |
| 5859 | return phone.isVideoEnabled(); |
| 5860 | } else { |
| 5861 | return false; |
| 5862 | } |
| 5863 | } finally { |
| 5864 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5865 | } |
| 5866 | } |
| 5867 | |
| 5868 | /** |
| 5869 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5870 | * defined in {@link ImsRegistrationImplBase}. |
| 5871 | */ |
| 5872 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5873 | final long identity = Binder.clearCallingIdentity(); |
| 5874 | try { |
| 5875 | Phone phone = getPhone(subId); |
| 5876 | if (phone != null) { |
| 5877 | return phone.getImsRegistrationTech(); |
| 5878 | } else { |
| 5879 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5880 | } |
| 5881 | } finally { |
| 5882 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5883 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5884 | } |
| 5885 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5886 | @Override |
| 5887 | public void factoryReset(int subId) { |
| 5888 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5889 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5890 | return; |
| 5891 | } |
| 5892 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5893 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5894 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5895 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5896 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5897 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5898 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5899 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5900 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5901 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5902 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5903 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5904 | // There has been issues when Sms raw table somehow stores orphan |
| 5905 | // fragments. They lead to garbled message when new fragments come |
| 5906 | // in and combined with those stale ones. In case this happens again, |
| 5907 | // user can reset all network settings which will clean up this table. |
| 5908 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5909 | // Clean up IMS settings as well here. |
| 5910 | int slotId = getSlotIndex(subId); |
| 5911 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5912 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 5913 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5914 | } finally { |
| 5915 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5916 | } |
| 5917 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5918 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5919 | private void cleanUpSmsRawTable(Context context) { |
| 5920 | ContentResolver resolver = context.getContentResolver(); |
| 5921 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5922 | resolver.delete(uri, null, null); |
| 5923 | } |
| 5924 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5925 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5926 | public String getSimLocaleForSubscriber(int subId) { |
| 5927 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5928 | final Phone phone = getPhone(subId); |
| 5929 | if (phone == null) { |
| 5930 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 5931 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5932 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5933 | final long identity = Binder.clearCallingIdentity(); |
| 5934 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5935 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5936 | phone.getContext().getOpPackageName(), phone.getContext().getFeatureId()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 5937 | if (info == null) { |
| 5938 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 5939 | return null; |
| 5940 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5941 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5942 | // preferences (EF-PL and EF-LI)... |
| 5943 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5944 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5945 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5946 | if (localeFromDefaultSim != null) { |
| 5947 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5948 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5949 | + localeFromDefaultSim); |
| 5950 | return localeFromDefaultSim.toLanguageTag(); |
| 5951 | } else { |
| 5952 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5953 | } |
| 5954 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5955 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5956 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5957 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5958 | // the SIM and carrier preferences does not include a country we add the country |
| 5959 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5960 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5961 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5962 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5963 | return mccLocale.toLanguageTag(); |
| 5964 | } |
| 5965 | |
| 5966 | if (DBG) log("No locale found - returning null"); |
| 5967 | return null; |
| 5968 | } finally { |
| 5969 | Binder.restoreCallingIdentity(identity); |
| 5970 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5971 | } |
| 5972 | |
| 5973 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5974 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 5975 | mApp.getFeatureId()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5976 | } |
| 5977 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5978 | /** |
| 5979 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5980 | */ |
| 5981 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5982 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 5983 | mApp.getFeatureId()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5984 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5985 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5986 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5987 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5988 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5989 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5990 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5991 | * representing the state of the modem. |
| 5992 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5993 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5994 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5995 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5996 | */ |
| 5997 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5998 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5999 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6000 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6001 | |
| 6002 | final long identity = Binder.clearCallingIdentity(); |
| 6003 | try { |
| 6004 | ModemActivityInfo ret = null; |
| 6005 | synchronized (mLastModemActivityInfo) { |
| 6006 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 6007 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6008 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6009 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6010 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6011 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6012 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6013 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6014 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6015 | } |
| 6016 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6017 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 6018 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6019 | mLastModemActivityInfo.setIdleTimeMillis( |
| 6020 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6021 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 6022 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 6023 | info.getReceiveTimeMillis() + mLastModemActivityInfo |
| 6024 | .getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6025 | } |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6026 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6027 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 6028 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 6029 | mLastModemActivityInfo.getIdleTimeMillis(), |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6030 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 6031 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6032 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6033 | Bundle bundle = new Bundle(); |
| 6034 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 6035 | result.send(0, bundle); |
| 6036 | } finally { |
| 6037 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6038 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6039 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6040 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6041 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6042 | // less than total activity duration. |
| 6043 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6044 | if (info == null) { |
| 6045 | return false; |
| 6046 | } |
| 6047 | int activityDurationMs = |
| 6048 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6049 | int totalTxTimeMs = 0; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6050 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6051 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6052 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6053 | } |
| 6054 | return (info.isValid() |
| 6055 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6056 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6057 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6058 | && (totalTxTimeMs <= activityDurationMs)); |
| 6059 | } |
| 6060 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6061 | /** |
| 6062 | * {@hide} |
| 6063 | * Returns the service state information on specified subscription. |
| 6064 | */ |
| 6065 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6066 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6067 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6068 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6069 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6070 | return null; |
| 6071 | } |
| 6072 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6073 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6074 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6075 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6076 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6077 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6078 | .setCallingPid(Binder.getCallingPid()) |
| 6079 | .setCallingUid(Binder.getCallingUid()) |
| 6080 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6081 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6082 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6083 | .build()); |
| 6084 | |
| 6085 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6086 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6087 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6088 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6089 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6090 | .setCallingPid(Binder.getCallingPid()) |
| 6091 | .setCallingUid(Binder.getCallingUid()) |
| 6092 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6093 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6094 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6095 | .build()); |
| 6096 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6097 | boolean hasFinePermission = |
| 6098 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6099 | boolean hasCoarsePermission = |
| 6100 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6101 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6102 | final long identity = Binder.clearCallingIdentity(); |
| 6103 | try { |
| 6104 | final Phone phone = getPhone(subId); |
| 6105 | if (phone == null) { |
| 6106 | return null; |
| 6107 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6108 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6109 | ServiceState ss = phone.getServiceState(); |
| 6110 | |
| 6111 | // Scrub out the location info in ServiceState depending on what level of access |
| 6112 | // the caller has. |
| 6113 | if (hasFinePermission) return ss; |
| 6114 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 6115 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6116 | } finally { |
| 6117 | Binder.restoreCallingIdentity(identity); |
| 6118 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6119 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6120 | |
| 6121 | /** |
| 6122 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6123 | * |
| 6124 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6125 | * voicemail ringtone. |
| 6126 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6127 | * PhoneAccount. |
| 6128 | */ |
| 6129 | @Override |
| 6130 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6131 | final long identity = Binder.clearCallingIdentity(); |
| 6132 | try { |
| 6133 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6134 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6135 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6136 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6137 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6138 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6139 | } finally { |
| 6140 | Binder.restoreCallingIdentity(identity); |
| 6141 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6142 | } |
| 6143 | |
| 6144 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6145 | * Sets the per-account voicemail ringtone. |
| 6146 | * |
| 6147 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6148 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6149 | * |
| 6150 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6151 | * voicemail ringtone. |
| 6152 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6153 | * PhoneAccount. |
| 6154 | */ |
| 6155 | @Override |
| 6156 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6157 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6158 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6159 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6160 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6161 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6162 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6163 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6164 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6165 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6166 | |
| 6167 | final long identity = Binder.clearCallingIdentity(); |
| 6168 | try { |
| 6169 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6170 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6171 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6172 | } |
| 6173 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6174 | } finally { |
| 6175 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6176 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6177 | } |
| 6178 | |
| 6179 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6180 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6181 | * |
| 6182 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6183 | * voicemail vibration setting. |
| 6184 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6185 | */ |
| 6186 | @Override |
| 6187 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6188 | final long identity = Binder.clearCallingIdentity(); |
| 6189 | try { |
| 6190 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6191 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6192 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6193 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6194 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6195 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6196 | } finally { |
| 6197 | Binder.restoreCallingIdentity(identity); |
| 6198 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6199 | } |
| 6200 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6201 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6202 | * Sets the per-account voicemail vibration. |
| 6203 | * |
| 6204 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6205 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6206 | * |
| 6207 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6208 | * voicemail vibration setting. |
| 6209 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6210 | * specific PhoneAccount. |
| 6211 | */ |
| 6212 | @Override |
| 6213 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6214 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6215 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6216 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6217 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6218 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6219 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6220 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6221 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6222 | } |
| 6223 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6224 | final long identity = Binder.clearCallingIdentity(); |
| 6225 | try { |
| 6226 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6227 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6228 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6229 | } |
| 6230 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6231 | } finally { |
| 6232 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6233 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6234 | } |
| 6235 | |
| 6236 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6237 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6238 | * |
| 6239 | * @throws SecurityException if the caller does not have the required permission |
| 6240 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6241 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6242 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6243 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6244 | } |
| 6245 | |
| 6246 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6247 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6248 | * permission. |
| 6249 | * |
| 6250 | * @throws SecurityException if the caller does not have the required permission |
| 6251 | */ |
| 6252 | private void enforceSendSmsPermission() { |
| 6253 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6254 | } |
| 6255 | |
| 6256 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6257 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6258 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6259 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6260 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6261 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6262 | final long identity = Binder.clearCallingIdentity(); |
| 6263 | try { |
| 6264 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6265 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6266 | if (componentName == null) { |
| 6267 | throw new SecurityException( |
| 6268 | "Caller not current active visual voicemail package[null]"); |
| 6269 | } |
| 6270 | String vvmPackage = componentName.getPackageName(); |
| 6271 | if (!callingPackage.equals(vvmPackage)) { |
| 6272 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6273 | + vvmPackage + "]"); |
| 6274 | } |
| 6275 | } finally { |
| 6276 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6277 | } |
| 6278 | } |
| 6279 | |
| 6280 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6281 | * Return the application ID for the app type. |
| 6282 | * |
| 6283 | * @param subId the subscription ID that this request applies to. |
| 6284 | * @param appType the uicc app type. |
| 6285 | * @return Application ID for specificied app type, or null if no uicc. |
| 6286 | */ |
| 6287 | @Override |
| 6288 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6289 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6290 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6291 | |
| 6292 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6293 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6294 | if (phone == null) { |
| 6295 | return null; |
| 6296 | } |
| 6297 | String aid = null; |
| 6298 | try { |
| 6299 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6300 | .getApplicationByType(appType).getAid(); |
| 6301 | } catch (Exception e) { |
| 6302 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6303 | } |
| 6304 | return aid; |
| 6305 | } finally { |
| 6306 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6307 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6308 | } |
| 6309 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6310 | /** |
| 6311 | * Return the Electronic Serial Number. |
| 6312 | * |
| 6313 | * @param subId the subscription ID that this request applies to. |
| 6314 | * @return ESN or null if error. |
| 6315 | */ |
| 6316 | @Override |
| 6317 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6318 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6319 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6320 | |
| 6321 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6322 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6323 | if (phone == null) { |
| 6324 | return null; |
| 6325 | } |
| 6326 | String esn = null; |
| 6327 | try { |
| 6328 | esn = phone.getEsn(); |
| 6329 | } catch (Exception e) { |
| 6330 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6331 | } |
| 6332 | return esn; |
| 6333 | } finally { |
| 6334 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6335 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6336 | } |
| 6337 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6338 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6339 | * Return the Preferred Roaming List Version. |
| 6340 | * |
| 6341 | * @param subId the subscription ID that this request applies to. |
| 6342 | * @return PRLVersion or null if error. |
| 6343 | */ |
| 6344 | @Override |
| 6345 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6346 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6347 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6348 | |
| 6349 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6350 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6351 | if (phone == null) { |
| 6352 | return null; |
| 6353 | } |
| 6354 | String cdmaPrlVersion = null; |
| 6355 | try { |
| 6356 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6357 | } catch (Exception e) { |
| 6358 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6359 | } |
| 6360 | return cdmaPrlVersion; |
| 6361 | } finally { |
| 6362 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6363 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6364 | } |
| 6365 | |
| 6366 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6367 | * Get snapshot of Telephony histograms |
| 6368 | * @return List of Telephony histograms |
| 6369 | * @hide |
| 6370 | */ |
| 6371 | @Override |
| 6372 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6373 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6374 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6375 | |
| 6376 | final long identity = Binder.clearCallingIdentity(); |
| 6377 | try { |
| 6378 | return RIL.getTelephonyRILTimingHistograms(); |
| 6379 | } finally { |
| 6380 | Binder.restoreCallingIdentity(identity); |
| 6381 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6382 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6383 | |
| 6384 | /** |
| 6385 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6386 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6387 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6388 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6389 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6390 | * @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] | 6391 | */ |
| 6392 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6393 | @TelephonyManager.SetCarrierRestrictionResult |
| 6394 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6395 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6396 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6397 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6398 | if (carrierRestrictionRules == null) { |
| 6399 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6400 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6401 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6402 | final long identity = Binder.clearCallingIdentity(); |
| 6403 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6404 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6405 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6406 | } finally { |
| 6407 | Binder.restoreCallingIdentity(identity); |
| 6408 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6409 | } |
| 6410 | |
| 6411 | /** |
| 6412 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6413 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6414 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6415 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6416 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6417 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6418 | */ |
| 6419 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6420 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6421 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6422 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6423 | |
| 6424 | final long identity = Binder.clearCallingIdentity(); |
| 6425 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6426 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 6427 | if (response instanceof CarrierRestrictionRules) { |
| 6428 | return (CarrierRestrictionRules) response; |
| 6429 | } |
| 6430 | // Response is an Exception of some kind, |
| 6431 | // which is signalled to the user as a NULL retval |
| 6432 | return null; |
| 6433 | } catch (Exception e) { |
| 6434 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 6435 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6436 | } finally { |
| 6437 | Binder.restoreCallingIdentity(identity); |
| 6438 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6439 | } |
| 6440 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6441 | /** |
| 6442 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 6443 | * @param subId the subscription ID that this action applies to. |
| 6444 | * @param enabled control enable or disable metered apns. |
| 6445 | * {@hide} |
| 6446 | */ |
| 6447 | @Override |
| 6448 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 6449 | enforceModifyPermission(); |
| 6450 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6451 | |
| 6452 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6453 | if (phone == null) { |
| 6454 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 6455 | return; |
| 6456 | } |
| 6457 | try { |
| 6458 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 6459 | } catch (Exception e) { |
| 6460 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6461 | } finally { |
| 6462 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6463 | } |
| 6464 | } |
| 6465 | |
| 6466 | /** |
| 6467 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 6468 | * @param subId the subscription ID that this action applies to. |
| 6469 | * @param enabled control enable or disable radio. |
| 6470 | * {@hide} |
| 6471 | */ |
| 6472 | @Override |
| 6473 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 6474 | enforceModifyPermission(); |
| 6475 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6476 | |
| 6477 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6478 | if (phone == null) { |
| 6479 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 6480 | return; |
| 6481 | } |
| 6482 | try { |
| 6483 | phone.carrierActionSetRadioEnabled(enabled); |
| 6484 | } catch (Exception e) { |
| 6485 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6486 | } finally { |
| 6487 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6488 | } |
| 6489 | } |
| 6490 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6491 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6492 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6493 | * network status based on which carrier apps could apply actions accordingly, |
| 6494 | * enable/disable default url handler for example. |
| 6495 | * |
| 6496 | * @param subId the subscription ID that this action applies to. |
| 6497 | * @param report control start/stop reporting the default network status. |
| 6498 | * {@hide} |
| 6499 | */ |
| 6500 | @Override |
| 6501 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6502 | enforceModifyPermission(); |
| 6503 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6504 | |
| 6505 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6506 | if (phone == null) { |
| 6507 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6508 | return; |
| 6509 | } |
| 6510 | try { |
| 6511 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6512 | } catch (Exception e) { |
| 6513 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6514 | } finally { |
| 6515 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6516 | } |
| 6517 | } |
| 6518 | |
| 6519 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6520 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6521 | * @param subId the subscription ID that this action applies to. |
| 6522 | * {@hide} |
| 6523 | */ |
| 6524 | @Override |
| 6525 | public void carrierActionResetAll(int subId) { |
| 6526 | enforceModifyPermission(); |
| 6527 | final Phone phone = getPhone(subId); |
| 6528 | if (phone == null) { |
| 6529 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6530 | return; |
| 6531 | } |
| 6532 | try { |
| 6533 | phone.carrierActionResetAll(); |
| 6534 | } catch (Exception e) { |
| 6535 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6536 | } |
| 6537 | } |
| 6538 | |
| 6539 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6540 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6541 | * bug report is being generated. |
| 6542 | */ |
| 6543 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6544 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6545 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6546 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6547 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6548 | + Binder.getCallingPid() |
| 6549 | + ", uid=" + Binder.getCallingUid() |
| 6550 | + "without permission " |
| 6551 | + android.Manifest.permission.DUMP); |
| 6552 | return; |
| 6553 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6554 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6555 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6556 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6557 | @Override |
| 6558 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 6559 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 6560 | throws RemoteException { |
Torbjorn Eklund | 1050cb0 | 2018-11-16 14:05:38 +0100 | [diff] [blame] | 6561 | (new TelephonyShellCommand(this, getDefaultPhone().getContext())) |
| 6562 | .exec(this, in, out, err, args, callback, resultReceiver); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6563 | } |
| 6564 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6565 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6566 | * Get aggregated video call data usage since boot. |
| 6567 | * |
| 6568 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6569 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6570 | * {@hide} |
| 6571 | */ |
| 6572 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6573 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6574 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6575 | null); |
| 6576 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6577 | final long identity = Binder.clearCallingIdentity(); |
| 6578 | try { |
| 6579 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6580 | // records the delta with the corresponding network identity. |
| 6581 | // We just return the total video call data usage snapshot since boot. |
| 6582 | Phone phone = getPhone(subId); |
| 6583 | if (phone != null) { |
| 6584 | return phone.getVtDataUsage(perUidStats); |
| 6585 | } |
| 6586 | return null; |
| 6587 | } finally { |
| 6588 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6589 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6590 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6591 | |
| 6592 | /** |
| 6593 | * Policy control of data connection. Usually used when data limit is passed. |
| 6594 | * @param enabled True if enabling the data, otherwise disabling. |
| 6595 | * @param subId Subscription index |
| 6596 | * {@hide} |
| 6597 | */ |
| 6598 | @Override |
| 6599 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6600 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6601 | |
| 6602 | final long identity = Binder.clearCallingIdentity(); |
| 6603 | try { |
| 6604 | Phone phone = getPhone(subId); |
| 6605 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6606 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6607 | } |
| 6608 | } finally { |
| 6609 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6610 | } |
| 6611 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6612 | |
| 6613 | /** |
| 6614 | * Get Client request stats |
| 6615 | * @return List of Client Request Stats |
| 6616 | * @hide |
| 6617 | */ |
| 6618 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6619 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 6620 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6621 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6622 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6623 | return null; |
| 6624 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6625 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6626 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6627 | final long identity = Binder.clearCallingIdentity(); |
| 6628 | try { |
| 6629 | if (phone != null) { |
| 6630 | return phone.getClientRequestStats(); |
| 6631 | } |
| 6632 | |
| 6633 | return null; |
| 6634 | } finally { |
| 6635 | Binder.restoreCallingIdentity(identity); |
| 6636 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6637 | } |
| 6638 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6639 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6640 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6641 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6642 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6643 | |
| 6644 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6645 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6646 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6647 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6648 | * @param state State of SIM (power down, power up, pass through) |
| 6649 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6650 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6651 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6652 | * |
| 6653 | **/ |
| 6654 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6655 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6656 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6657 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6658 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6659 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6660 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6661 | final long identity = Binder.clearCallingIdentity(); |
| 6662 | try { |
| 6663 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6664 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6665 | } |
| 6666 | } finally { |
| 6667 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6668 | } |
| 6669 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6670 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6671 | private boolean isUssdApiAllowed(int subId) { |
| 6672 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6673 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6674 | if (configManager == null) { |
| 6675 | return false; |
| 6676 | } |
| 6677 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6678 | if (pb == null) { |
| 6679 | return false; |
| 6680 | } |
| 6681 | return pb.getBoolean( |
| 6682 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6683 | } |
| 6684 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6685 | /** |
| 6686 | * Check if phone is in emergency callback mode |
| 6687 | * @return true if phone is in emergency callback mode |
| 6688 | * @param subId sub id |
| 6689 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6690 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6691 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6692 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6693 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6694 | |
| 6695 | final long identity = Binder.clearCallingIdentity(); |
| 6696 | try { |
| 6697 | if (phone != null) { |
| 6698 | return phone.isInEcm(); |
| 6699 | } else { |
| 6700 | return false; |
| 6701 | } |
| 6702 | } finally { |
| 6703 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6704 | } |
| 6705 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6706 | |
| 6707 | /** |
| 6708 | * Get the current signal strength information for the given subscription. |
| 6709 | * Because this information is not updated when the device is in a low power state |
| 6710 | * it should not be relied-upon to be current. |
| 6711 | * @param subId Subscription index |
| 6712 | * @return the most recent cached signal strength info from the modem |
| 6713 | */ |
| 6714 | @Override |
| 6715 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6716 | final long identity = Binder.clearCallingIdentity(); |
| 6717 | try { |
| 6718 | Phone p = getPhone(subId); |
| 6719 | if (p == null) { |
| 6720 | return null; |
| 6721 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6722 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6723 | return p.getSignalStrength(); |
| 6724 | } finally { |
| 6725 | Binder.restoreCallingIdentity(identity); |
| 6726 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6727 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6728 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6729 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6730 | * Get the current modem radio state for the given slot. |
| 6731 | * @param slotIndex slot index. |
| 6732 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6733 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6734 | * @return the current radio power state from the modem |
| 6735 | */ |
| 6736 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6737 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6738 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6739 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6740 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 6741 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6742 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6743 | } |
| 6744 | |
| 6745 | final long identity = Binder.clearCallingIdentity(); |
| 6746 | try { |
| 6747 | return phone.getRadioPowerState(); |
| 6748 | } finally { |
| 6749 | Binder.restoreCallingIdentity(identity); |
| 6750 | } |
| 6751 | } |
| 6752 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6753 | } |
| 6754 | |
| 6755 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6756 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6757 | * |
| 6758 | * <p>Requires one of the following permissions: |
| 6759 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6760 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6761 | * privileges. |
| 6762 | * |
| 6763 | * @param subId subscription id |
| 6764 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6765 | * {@code false}. |
| 6766 | */ |
| 6767 | @Override |
| 6768 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6769 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6770 | null /* message */); |
| 6771 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6772 | boolean isEnabled = false; |
| 6773 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6774 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6775 | Phone phone = getPhone(subId); |
| 6776 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6777 | } catch (Exception e) { |
| 6778 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6779 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6780 | } finally { |
| 6781 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6782 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6783 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6784 | } |
| 6785 | |
| 6786 | |
| 6787 | /** |
| 6788 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6789 | * |
| 6790 | * <p> Requires permission: |
| 6791 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6792 | * privileges. |
| 6793 | * |
| 6794 | * @param subId subscription id |
| 6795 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6796 | */ |
| 6797 | @Override |
| 6798 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6799 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6800 | mApp, subId, "setDataRoamingEnabled"); |
| 6801 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6802 | final long identity = Binder.clearCallingIdentity(); |
| 6803 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6804 | Phone phone = getPhone(subId); |
| 6805 | if (phone != null) { |
| 6806 | phone.setDataRoamingEnabled(isEnabled); |
| 6807 | } |
| 6808 | } finally { |
| 6809 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6810 | } |
| 6811 | } |
| 6812 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6813 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6814 | public boolean isManualNetworkSelectionAllowed(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6815 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6816 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6817 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6818 | boolean isAllowed = true; |
| 6819 | final long identity = Binder.clearCallingIdentity(); |
| 6820 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6821 | Phone phone = getPhone(subId); |
| 6822 | if (phone != null) { |
| 6823 | isAllowed = phone.isCspPlmnEnabled(); |
| 6824 | } |
| 6825 | } finally { |
| 6826 | Binder.restoreCallingIdentity(identity); |
| 6827 | } |
| 6828 | return isAllowed; |
| 6829 | } |
| 6830 | |
| 6831 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6832 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6833 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6834 | try { |
| 6835 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6836 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6837 | } catch (SecurityException e) { |
| 6838 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6839 | // has carrier privileges on an active UICC |
| 6840 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6841 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6842 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6843 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6844 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6845 | |
| 6846 | final long identity = Binder.clearCallingIdentity(); |
| 6847 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6848 | UiccController uiccController = UiccController.getInstance(); |
| 6849 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6850 | if (hasReadPermission) { |
| 6851 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6852 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6853 | |
| 6854 | // Remove private info if the caller doesn't have access |
| 6855 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6856 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6857 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 6858 | // is available |
| 6859 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 6860 | if (card == null || card.getUiccProfile() == null) { |
| 6861 | // assume no access if the card or profile is unavailable |
| 6862 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6863 | continue; |
| 6864 | } |
| 6865 | UiccProfile profile = card.getUiccProfile(); |
| 6866 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6867 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6868 | filteredInfos.add(cardInfo); |
| 6869 | } else { |
| 6870 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6871 | } |
| 6872 | } |
| 6873 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6874 | } finally { |
| 6875 | Binder.restoreCallingIdentity(identity); |
| 6876 | } |
| 6877 | } |
| 6878 | |
| 6879 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6880 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6881 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6882 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6883 | final long identity = Binder.clearCallingIdentity(); |
| 6884 | try { |
| 6885 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6886 | if (slots == null) { |
| 6887 | Rlog.i(LOG_TAG, "slots is null."); |
| 6888 | return null; |
| 6889 | } |
| 6890 | |
| 6891 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6892 | for (int i = 0; i < slots.length; i++) { |
| 6893 | UiccSlot slot = slots[i]; |
| 6894 | if (slot == null) { |
| 6895 | continue; |
| 6896 | } |
| 6897 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6898 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6899 | UiccCard card = slot.getUiccCard(); |
| 6900 | if (card != null) { |
| 6901 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6902 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 6903 | cardId = slot.getEid(); |
| 6904 | if (TextUtils.isEmpty(cardId)) { |
| 6905 | cardId = slot.getIccId(); |
| 6906 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6907 | } |
| 6908 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 6909 | if (cardId != null) { |
| 6910 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 6911 | // if cardId is an EID, it's all digits so this is fine |
| 6912 | cardId = IccUtils.stripTrailingFs(cardId); |
| 6913 | } |
| 6914 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6915 | int cardState = 0; |
| 6916 | switch (slot.getCardState()) { |
| 6917 | case CARDSTATE_ABSENT: |
| 6918 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6919 | break; |
| 6920 | case CARDSTATE_PRESENT: |
| 6921 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6922 | break; |
| 6923 | case CARDSTATE_ERROR: |
| 6924 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6925 | break; |
| 6926 | case CARDSTATE_RESTRICTED: |
| 6927 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6928 | break; |
| 6929 | default: |
| 6930 | break; |
| 6931 | |
| 6932 | } |
| 6933 | |
| 6934 | infos[i] = new UiccSlotInfo( |
| 6935 | slot.isActive(), |
| 6936 | slot.isEuicc(), |
| 6937 | cardId, |
| 6938 | cardState, |
| 6939 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6940 | slot.isExtendedApduSupported(), |
| 6941 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6942 | } |
| 6943 | return infos; |
| 6944 | } finally { |
| 6945 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6946 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6947 | } |
| 6948 | |
| 6949 | @Override |
| 6950 | public boolean switchSlots(int[] physicalSlots) { |
| 6951 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6952 | |
| 6953 | final long identity = Binder.clearCallingIdentity(); |
| 6954 | try { |
| 6955 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6956 | } finally { |
| 6957 | Binder.restoreCallingIdentity(identity); |
| 6958 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6959 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6960 | |
| 6961 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6962 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6963 | final long identity = Binder.clearCallingIdentity(); |
| 6964 | try { |
| 6965 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6966 | } finally { |
| 6967 | Binder.restoreCallingIdentity(identity); |
| 6968 | } |
| 6969 | } |
| 6970 | |
| 6971 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6972 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6973 | enforceModifyPermission(); |
| 6974 | final Phone phone = getPhone(subId); |
| 6975 | if (phone == null) { |
| 6976 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6977 | return; |
| 6978 | } |
| 6979 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6980 | final long identity = Binder.clearCallingIdentity(); |
| 6981 | try { |
| 6982 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6983 | } finally { |
| 6984 | Binder.restoreCallingIdentity(identity); |
| 6985 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6986 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6987 | |
| 6988 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6989 | * A test API to reload the UICC profile. |
| 6990 | * |
| 6991 | * <p>Requires that the calling app has permission |
| 6992 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6993 | * @hide |
| 6994 | */ |
| 6995 | @Override |
| 6996 | public void refreshUiccProfile(int subId) { |
| 6997 | enforceModifyPermission(); |
| 6998 | |
| 6999 | final long identity = Binder.clearCallingIdentity(); |
| 7000 | try { |
| 7001 | Phone phone = getPhone(subId); |
| 7002 | if (phone == null) { |
| 7003 | return; |
| 7004 | } |
| 7005 | UiccCard uiccCard = phone.getUiccCard(); |
| 7006 | if (uiccCard == null) { |
| 7007 | return; |
| 7008 | } |
| 7009 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7010 | if (uiccProfile == null) { |
| 7011 | return; |
| 7012 | } |
| 7013 | uiccProfile.refresh(); |
| 7014 | } finally { |
| 7015 | Binder.restoreCallingIdentity(identity); |
| 7016 | } |
| 7017 | } |
| 7018 | |
| 7019 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7020 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7021 | */ |
| 7022 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7023 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7024 | } |
| 7025 | |
| 7026 | /** |
| 7027 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7028 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7029 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7030 | */ |
| 7031 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7032 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7033 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7034 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7035 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7036 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7037 | return isDataRoamingEnabled; |
| 7038 | } |
| 7039 | |
| 7040 | /** |
| 7041 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7042 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7043 | */ |
| 7044 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7045 | List<Integer> list = TelephonyProperties.default_network(); |
| 7046 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7047 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7048 | return list.get(phoneId); |
| 7049 | } |
| 7050 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7051 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7052 | |
| 7053 | @Override |
| 7054 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7055 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7056 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7057 | |
| 7058 | final long identity = Binder.clearCallingIdentity(); |
| 7059 | try { |
| 7060 | final Phone phone = getPhone(subId); |
| 7061 | if (phone == null) { |
| 7062 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7063 | return; |
| 7064 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7065 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7066 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7067 | } finally { |
| 7068 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7069 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7070 | } |
| 7071 | |
| 7072 | @Override |
| 7073 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7074 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7075 | |
| 7076 | final long identity = Binder.clearCallingIdentity(); |
| 7077 | try { |
| 7078 | final Phone phone = getPhone(subId); |
| 7079 | if (phone == null) { |
| 7080 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7081 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7082 | } |
| 7083 | return phone.getCarrierIdListVersion(); |
| 7084 | } finally { |
| 7085 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7086 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7087 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7088 | |
| 7089 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7090 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7091 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7092 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7093 | mApp, subId, callingPackage, callingFeatureId, |
| 7094 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7095 | return -1; |
| 7096 | } |
| 7097 | |
| 7098 | final long identity = Binder.clearCallingIdentity(); |
| 7099 | try { |
| 7100 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7101 | } finally { |
| 7102 | Binder.restoreCallingIdentity(identity); |
| 7103 | } |
| 7104 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7105 | |
| 7106 | @Override |
| 7107 | public int getCdmaRoamingMode(int subId) { |
| 7108 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7109 | mApp, subId, "getCdmaRoamingMode"); |
| 7110 | |
| 7111 | final long identity = Binder.clearCallingIdentity(); |
| 7112 | try { |
| 7113 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7114 | } finally { |
| 7115 | Binder.restoreCallingIdentity(identity); |
| 7116 | } |
| 7117 | } |
| 7118 | |
| 7119 | @Override |
| 7120 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7121 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7122 | mApp, subId, "setCdmaRoamingMode"); |
| 7123 | |
| 7124 | final long identity = Binder.clearCallingIdentity(); |
| 7125 | try { |
| 7126 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7127 | } finally { |
| 7128 | Binder.restoreCallingIdentity(identity); |
| 7129 | } |
| 7130 | } |
| 7131 | |
| 7132 | @Override |
| 7133 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7134 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7135 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7136 | |
| 7137 | final long identity = Binder.clearCallingIdentity(); |
| 7138 | try { |
| 7139 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7140 | } finally { |
| 7141 | Binder.restoreCallingIdentity(identity); |
| 7142 | } |
| 7143 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7144 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7145 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7146 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7147 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7148 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7149 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7150 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7151 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7152 | } |
| 7153 | final long identity = Binder.clearCallingIdentity(); |
| 7154 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7155 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7156 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7157 | if (phone.getEmergencyNumberTracker() != null |
| 7158 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7159 | emergencyNumberListInternal.put( |
| 7160 | phone.getSubId(), |
| 7161 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7162 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7163 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7164 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7165 | } finally { |
| 7166 | Binder.restoreCallingIdentity(identity); |
| 7167 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7168 | } |
| 7169 | |
| 7170 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7171 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7172 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7173 | if (!exactMatch) { |
| 7174 | TelephonyPermissions |
| 7175 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7176 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7177 | } |
| 7178 | final long identity = Binder.clearCallingIdentity(); |
| 7179 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7180 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7181 | if (phone.getEmergencyNumberTracker() != null |
| 7182 | && phone.getEmergencyNumberTracker() != null) { |
| 7183 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7184 | number, exactMatch)) { |
| 7185 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7186 | } |
| 7187 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7188 | } |
| 7189 | return false; |
| 7190 | } finally { |
| 7191 | Binder.restoreCallingIdentity(identity); |
| 7192 | } |
| 7193 | } |
| 7194 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7195 | /** |
| 7196 | * Update emergency number list for test mode. |
| 7197 | */ |
| 7198 | @Override |
| 7199 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7200 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7201 | "updateEmergencyNumberListTestMode"); |
| 7202 | |
| 7203 | final long identity = Binder.clearCallingIdentity(); |
| 7204 | try { |
| 7205 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7206 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7207 | if (tracker != null) { |
| 7208 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7209 | } |
| 7210 | } |
| 7211 | } finally { |
| 7212 | Binder.restoreCallingIdentity(identity); |
| 7213 | } |
| 7214 | } |
| 7215 | |
| 7216 | /** |
| 7217 | * Get the full emergency number list for test mode. |
| 7218 | */ |
| 7219 | @Override |
| 7220 | public List<String> getEmergencyNumberListTestMode() { |
| 7221 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7222 | "getEmergencyNumberListTestMode"); |
| 7223 | |
| 7224 | final long identity = Binder.clearCallingIdentity(); |
| 7225 | try { |
| 7226 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7227 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7228 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7229 | if (tracker != null) { |
| 7230 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7231 | emergencyNumbers.add(num.getNumber()); |
| 7232 | } |
| 7233 | } |
| 7234 | } |
| 7235 | return new ArrayList<>(emergencyNumbers); |
| 7236 | } finally { |
| 7237 | Binder.restoreCallingIdentity(identity); |
| 7238 | } |
| 7239 | } |
| 7240 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7241 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame^] | 7242 | public int getEmergencyNumberDbVersion(int subId) { |
| 7243 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7244 | |
| 7245 | final long identity = Binder.clearCallingIdentity(); |
| 7246 | try { |
| 7247 | final Phone phone = getPhone(subId); |
| 7248 | if (phone == null) { |
| 7249 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7250 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7251 | } |
| 7252 | return phone.getEmergencyNumberDbVersion(); |
| 7253 | } finally { |
| 7254 | Binder.restoreCallingIdentity(identity); |
| 7255 | } |
| 7256 | } |
| 7257 | |
| 7258 | @Override |
| 7259 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7260 | enforceModifyPermission(); |
| 7261 | |
| 7262 | final long identity = Binder.clearCallingIdentity(); |
| 7263 | try { |
| 7264 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7265 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7266 | if (tracker != null) { |
| 7267 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7268 | } |
| 7269 | } |
| 7270 | } finally { |
| 7271 | Binder.restoreCallingIdentity(identity); |
| 7272 | } |
| 7273 | } |
| 7274 | |
| 7275 | @Override |
| 7276 | public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) { |
| 7277 | enforceActiveEmergencySessionPermission(); |
| 7278 | |
| 7279 | final long identity = Binder.clearCallingIdentity(); |
| 7280 | try { |
| 7281 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7282 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7283 | if (tracker != null) { |
| 7284 | tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath); |
| 7285 | } |
| 7286 | } |
| 7287 | } finally { |
| 7288 | Binder.restoreCallingIdentity(identity); |
| 7289 | } |
| 7290 | } |
| 7291 | |
| 7292 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7293 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7294 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7295 | Phone phone = getPhone(subId); |
| 7296 | if (phone == null) { |
| 7297 | return null; |
| 7298 | } |
| 7299 | final long identity = Binder.clearCallingIdentity(); |
| 7300 | try { |
| 7301 | UiccProfile profile = UiccController.getInstance() |
| 7302 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7303 | if (profile != null) { |
| 7304 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7305 | } |
| 7306 | } finally { |
| 7307 | Binder.restoreCallingIdentity(identity); |
| 7308 | } |
| 7309 | return null; |
| 7310 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7311 | |
| 7312 | /** |
| 7313 | * Enable or disable a modem stack. |
| 7314 | */ |
| 7315 | @Override |
| 7316 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7317 | enforceModifyPermission(); |
| 7318 | |
| 7319 | final long identity = Binder.clearCallingIdentity(); |
| 7320 | try { |
| 7321 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7322 | if (phone == null) { |
| 7323 | return false; |
| 7324 | } else { |
| 7325 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7326 | } |
| 7327 | } finally { |
| 7328 | Binder.restoreCallingIdentity(identity); |
| 7329 | } |
| 7330 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7331 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7332 | /** |
| 7333 | * Whether a modem stack is enabled or not. |
| 7334 | */ |
| 7335 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7336 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7337 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7338 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7339 | if (phone == null) return false; |
| 7340 | |
| 7341 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7342 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7343 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7344 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7345 | } |
| 7346 | |
| 7347 | final long identity = Binder.clearCallingIdentity(); |
| 7348 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7349 | try { |
| 7350 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7351 | } catch (NoSuchElementException ex) { |
| 7352 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7353 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7354 | } finally { |
| 7355 | Binder.restoreCallingIdentity(identity); |
| 7356 | } |
| 7357 | } |
| 7358 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7359 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7360 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7361 | enforceModifyPermission(); |
| 7362 | |
| 7363 | final long identity = Binder.clearCallingIdentity(); |
| 7364 | try { |
| 7365 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7366 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7367 | .commit(); |
| 7368 | } finally { |
| 7369 | Binder.restoreCallingIdentity(identity); |
| 7370 | } |
| 7371 | } |
| 7372 | |
| 7373 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7374 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7375 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7376 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7377 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 7378 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7379 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7380 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7381 | |
| 7382 | final long identity = Binder.clearCallingIdentity(); |
| 7383 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7384 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7385 | } finally { |
| 7386 | Binder.restoreCallingIdentity(identity); |
| 7387 | } |
| 7388 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7389 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7390 | @TelephonyManager.IsMultiSimSupportedResult |
| 7391 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7392 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7393 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7394 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7395 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7396 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7397 | } |
| 7398 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7399 | // supported by the modem, indicate that it is restricted. |
| 7400 | PhoneCapability staticCapability = |
| 7401 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7402 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7403 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7404 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7405 | } |
| 7406 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7407 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7408 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7409 | } |
| 7410 | // Check if support of multiple SIMs is restricted by carrier |
| 7411 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7412 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7413 | } |
| 7414 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7415 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7416 | } |
| 7417 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7418 | /** |
| 7419 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7420 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7421 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7422 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7423 | * @param numOfSims number of active sims we want to switch to |
| 7424 | */ |
| 7425 | @Override |
| 7426 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7427 | if (numOfSims == 1) { |
| 7428 | enforceModifyPermission(); |
| 7429 | } else { |
| 7430 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7431 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7432 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7433 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7434 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7435 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7436 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7437 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7438 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7439 | return; |
| 7440 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7441 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7442 | } finally { |
| 7443 | Binder.restoreCallingIdentity(identity); |
| 7444 | } |
| 7445 | } |
| 7446 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 7447 | @Override |
| 7448 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 7449 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 7450 | Phone phone = getPhone(subId); |
| 7451 | if (phone == null) { |
| 7452 | return false; |
| 7453 | } |
| 7454 | final long identity = Binder.clearCallingIdentity(); |
| 7455 | try { |
| 7456 | UiccCard uiccCard = phone.getUiccCard(); |
| 7457 | if (uiccCard == null) { |
| 7458 | return false; |
| 7459 | } |
| 7460 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7461 | if (uiccProfile == null) { |
| 7462 | return false; |
| 7463 | } |
| 7464 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 7465 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 7466 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 7467 | } |
| 7468 | return false; |
| 7469 | } finally { |
| 7470 | Binder.restoreCallingIdentity(identity); |
| 7471 | } |
| 7472 | } |
| 7473 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7474 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7475 | * Get whether making changes to modem configurations will trigger reboot. |
| 7476 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7477 | */ |
| 7478 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7479 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 7480 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7481 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7482 | mApp, subId, callingPackage, callingFeatureId, |
| 7483 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7484 | return false; |
| 7485 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7486 | final long identity = Binder.clearCallingIdentity(); |
| 7487 | try { |
| 7488 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 7489 | } finally { |
| 7490 | Binder.restoreCallingIdentity(identity); |
| 7491 | } |
| 7492 | } |
| 7493 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 7494 | private void updateModemStateMetrics() { |
| 7495 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 7496 | // TODO: check the state for each modem if the api is ready. |
| 7497 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 7498 | } |
| 7499 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 7500 | @Override |
| 7501 | public int[] getSlotsMapping() { |
| 7502 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 7503 | |
| 7504 | final long identity = Binder.clearCallingIdentity(); |
| 7505 | try { |
| 7506 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 7507 | // All logical slots should have a mapping to a physical slot. |
| 7508 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 7509 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 7510 | for (int i = 0; i < slotInfos.length; i++) { |
| 7511 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 7512 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 7513 | } |
| 7514 | } |
| 7515 | return logicalSlotsMapping; |
| 7516 | } finally { |
| 7517 | Binder.restoreCallingIdentity(identity); |
| 7518 | } |
| 7519 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7520 | |
| 7521 | /** |
| 7522 | * Get the IRadio HAL Version |
| 7523 | */ |
| 7524 | @Override |
| 7525 | public int getRadioHalVersion() { |
| 7526 | Phone phone = getDefaultPhone(); |
| 7527 | if (phone == null) return -1; |
| 7528 | HalVersion hv = phone.getHalVersion(); |
| 7529 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7530 | return hv.major * 100 + hv.minor; |
| 7531 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7532 | |
| 7533 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7534 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7535 | * corresponding network requests on a subId. |
| 7536 | * |
| 7537 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7538 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7539 | * 2) APN is un-metered for this subscription, or |
| 7540 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
| 7541 | * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. |
| 7542 | * |
| 7543 | * @return whether data is allowed for a apn type. |
| 7544 | * |
| 7545 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7546 | */ |
| 7547 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7548 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 7549 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 7550 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7551 | |
| 7552 | // Now that all security checks passes, perform the operation as ourselves. |
| 7553 | final long identity = Binder.clearCallingIdentity(); |
| 7554 | try { |
| 7555 | Phone phone = getPhone(subId); |
| 7556 | if (phone == null) return false; |
| 7557 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7558 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7559 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7560 | } finally { |
| 7561 | Binder.restoreCallingIdentity(identity); |
| 7562 | } |
| 7563 | } |
| 7564 | |
| 7565 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7566 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7567 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7568 | |
| 7569 | // Now that all security checks passes, perform the operation as ourselves. |
| 7570 | final long identity = Binder.clearCallingIdentity(); |
| 7571 | try { |
| 7572 | Phone phone = getPhone(subId); |
| 7573 | if (phone == null) return true; // By default return true. |
| 7574 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7575 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7576 | } finally { |
| 7577 | Binder.restoreCallingIdentity(identity); |
| 7578 | } |
| 7579 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7580 | |
| 7581 | @Override |
| 7582 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
| 7583 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 7584 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 7585 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 7586 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 7587 | } |
| 7588 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 7589 | Intent intent = new Intent(); |
| 7590 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 7591 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 7592 | // Bring up choose default SMS subscription dialog right now |
| 7593 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 7594 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 7595 | mApp.startActivity(intent); |
| 7596 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 7597 | |
| 7598 | @Override |
| 7599 | public String getMmsUAProfUrl(int subId) { |
| 7600 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7601 | final long identity = Binder.clearCallingIdentity(); |
| 7602 | try { |
| 7603 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7604 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 7605 | } finally { |
| 7606 | Binder.restoreCallingIdentity(identity); |
| 7607 | } |
| 7608 | } |
| 7609 | |
| 7610 | @Override |
| 7611 | public String getMmsUserAgent(int subId) { |
| 7612 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7613 | final long identity = Binder.clearCallingIdentity(); |
| 7614 | try { |
| 7615 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7616 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 7617 | } finally { |
| 7618 | Binder.restoreCallingIdentity(identity); |
| 7619 | } |
| 7620 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 7621 | |
| 7622 | @Override |
| 7623 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 7624 | enforceModifyPermission(); |
| 7625 | |
| 7626 | // Now that all security checks passes, perform the operation as ourselves. |
| 7627 | final long identity = Binder.clearCallingIdentity(); |
| 7628 | try { |
| 7629 | Phone phone = getPhone(subId); |
| 7630 | if (phone == null) return false; |
| 7631 | |
| 7632 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 7633 | } finally { |
| 7634 | Binder.restoreCallingIdentity(identity); |
| 7635 | } |
| 7636 | } |
| 7637 | |
| 7638 | @Override |
| 7639 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 7640 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 7641 | |
| 7642 | // Now that all security checks passes, perform the operation as ourselves. |
| 7643 | final long identity = Binder.clearCallingIdentity(); |
| 7644 | try { |
| 7645 | Phone phone = getPhone(subId); |
| 7646 | if (phone == null) return false; |
| 7647 | |
| 7648 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 7649 | } finally { |
| 7650 | Binder.restoreCallingIdentity(identity); |
| 7651 | } |
| 7652 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 7653 | |
| 7654 | /** |
| 7655 | * Updates whether conference event pacakge handling is enabled. |
| 7656 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 7657 | * otherwise. |
| 7658 | */ |
| 7659 | @Override |
| 7660 | public void setCepEnabled(boolean isCepEnabled) { |
| 7661 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 7662 | |
| 7663 | final long identity = Binder.clearCallingIdentity(); |
| 7664 | try { |
| 7665 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 7666 | for (Phone phone : PhoneFactory.getPhones()) { |
| 7667 | Phone defaultPhone = phone.getImsPhone(); |
| 7668 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7669 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7670 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 7671 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 7672 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 7673 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 7674 | + imsPhone.getMsisdn()); |
| 7675 | } |
| 7676 | } |
| 7677 | } finally { |
| 7678 | Binder.restoreCallingIdentity(identity); |
| 7679 | } |
| 7680 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 7681 | } |