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; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 55 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 57 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 58 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 59 | import android.preference.PreferenceManager; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 60 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 61 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 62 | import android.provider.Telephony; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 65 | import android.telecom.TelecomManager; |
Chen Xu | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 66 | import android.telephony.Annotation.ApnType; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 67 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 68 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 69 | import android.telephony.CellIdentity; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 70 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 71 | import android.telephony.CellInfoGsm; |
| 72 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 73 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 74 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 75 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 76 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 77 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 78 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 79 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 80 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 81 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 82 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 83 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 84 | import android.telephony.RadioAccessSpecifier; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 85 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 86 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 87 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 88 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 89 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 90 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 91 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 92 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 93 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 94 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 95 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 96 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 97 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 98 | import android.telephony.data.ApnSetting; |
| 99 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 100 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 101 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 102 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 103 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 108 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 109 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 110 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 111 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 112 | import android.telephony.ims.feature.MmTelFeature; |
| 113 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 114 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 115 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 116 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 117 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 118 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 119 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 120 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 121 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 122 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 126 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.HalVersion; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 136 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 157 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 159 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.uicc.IccIoResult; |
| 161 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 169 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 170 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 171 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 172 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 173 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 174 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 175 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 176 | import java.io.FileDescriptor; |
| 177 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 178 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 179 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 180 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 181 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 182 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 183 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 184 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 185 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 186 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 187 | |
| 188 | /** |
| 189 | * Implementation of the ITelephony interface. |
| 190 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 191 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 192 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 193 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 194 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 195 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 196 | |
| 197 | // Message codes used with mMainThreadHandler |
| 198 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 199 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 200 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 201 | private static final int CMD_OPEN_CHANNEL = 9; |
| 202 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 203 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 204 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 205 | private static final int CMD_NV_READ_ITEM = 13; |
| 206 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 207 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 208 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 209 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 210 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 211 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 212 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 213 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 214 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 215 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 216 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 217 | private static final int CMD_SEND_ENVELOPE = 25; |
| 218 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 219 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 220 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 221 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 222 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 223 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 224 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 225 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 226 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 227 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 228 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 229 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 230 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 231 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 232 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 233 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 234 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 235 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 236 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 237 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 238 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 239 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 240 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 241 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 242 | private static final int CMD_SWITCH_SLOTS = 50; |
| 243 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 244 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 245 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 246 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 247 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 248 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 249 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 250 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 251 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 252 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 253 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 254 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 255 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 256 | private static final int CMD_MODEM_REBOOT = 64; |
| 257 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 258 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 259 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 260 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 261 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 262 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 263 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 264 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 265 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 266 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 267 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 268 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 269 | // Parameters of select command. |
| 270 | private static final int SELECT_COMMAND = 0xA4; |
| 271 | private static final int SELECT_P1 = 0x04; |
| 272 | private static final int SELECT_P2 = 0; |
| 273 | private static final int SELECT_P3 = 0x10; |
| 274 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 275 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 276 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 277 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 278 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 279 | /** The singleton instance. */ |
| 280 | private static PhoneInterfaceManager sInstance; |
| 281 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 282 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 283 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 284 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 285 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 286 | private AppOpsManager mAppOps; |
| 287 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 288 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 289 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 290 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 291 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 292 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 293 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 294 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 295 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 296 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 297 | // String to store multi SIM allowed |
| 298 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 299 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 300 | // The AID of ISD-R. |
| 301 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 302 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 303 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 304 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 305 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 306 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 307 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 308 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 309 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 310 | */ |
| 311 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 312 | "reset_network_erase_modem_config_enabled"; |
| 313 | |
| 314 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 315 | * A request object to use for transmitting data to an ICC. |
| 316 | */ |
| 317 | private static final class IccAPDUArgument { |
| 318 | public int channel, cla, command, p1, p2, p3; |
| 319 | public String data; |
| 320 | |
| 321 | public IccAPDUArgument(int channel, int cla, int command, |
| 322 | int p1, int p2, int p3, String data) { |
| 323 | this.channel = channel; |
| 324 | this.cla = cla; |
| 325 | this.command = command; |
| 326 | this.p1 = p1; |
| 327 | this.p2 = p2; |
| 328 | this.p3 = p3; |
| 329 | this.data = data; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 334 | * A request object to use for transmitting data to an ICC. |
| 335 | */ |
| 336 | private static final class ManualNetworkSelectionArgument { |
| 337 | public OperatorInfo operatorInfo; |
| 338 | public boolean persistSelection; |
| 339 | |
| 340 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 341 | this.operatorInfo = operatorInfo; |
| 342 | this.persistSelection = persistSelection; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 347 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 348 | * request after sending. The main thread will notify the request when it is complete. |
| 349 | */ |
| 350 | private static final class MainThreadRequest { |
| 351 | /** The argument to use for the request */ |
| 352 | public Object argument; |
| 353 | /** The result of the request that is run on the main thread */ |
| 354 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 355 | // The subscriber id that this request applies to. Defaults to |
| 356 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 357 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 358 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 359 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 360 | public Phone phone; |
| 361 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 362 | public WorkSource workSource; |
| 363 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 364 | public MainThreadRequest(Object argument) { |
| 365 | this.argument = argument; |
| 366 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 367 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 368 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 369 | this.argument = argument; |
| 370 | if (phone != null) { |
| 371 | this.phone = phone; |
| 372 | } |
| 373 | this.workSource = workSource; |
| 374 | } |
| 375 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 376 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 377 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 378 | if (subId != null) { |
| 379 | this.subId = subId; |
| 380 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 381 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 382 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 385 | private static final class IncomingThirdPartyCallArgs { |
| 386 | public final ComponentName component; |
| 387 | public final String callId; |
| 388 | public final String callerDisplayName; |
| 389 | |
| 390 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 391 | String callerDisplayName) { |
| 392 | this.component = component; |
| 393 | this.callId = callId; |
| 394 | this.callerDisplayName = callerDisplayName; |
| 395 | } |
| 396 | } |
| 397 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 398 | /** |
| 399 | * A handler that processes messages on the main thread in the phone process. Since many |
| 400 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 401 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 402 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 403 | * on, which will be notified when the operation completes and will contain the result of the |
| 404 | * request. |
| 405 | * |
| 406 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 407 | * note that request.result must be set to something non-null for the calling thread to |
| 408 | * unblock. |
| 409 | */ |
| 410 | private final class MainThreadHandler extends Handler { |
| 411 | @Override |
| 412 | public void handleMessage(Message msg) { |
| 413 | MainThreadRequest request; |
| 414 | Message onCompleted; |
| 415 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 416 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 417 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 418 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 419 | |
| 420 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 421 | case CMD_HANDLE_USSD_REQUEST: { |
| 422 | request = (MainThreadRequest) msg.obj; |
| 423 | final Phone phone = getPhoneFromRequest(request); |
| 424 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 425 | String ussdRequest = ussdObject.first; |
| 426 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 427 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 428 | if (!isUssdApiAllowed(request.subId)) { |
| 429 | // Carrier does not support use of this API, return failure. |
| 430 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 431 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 432 | Bundle returnData = new Bundle(); |
| 433 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 434 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 435 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 436 | request.result = true; |
| 437 | notifyRequester(request); |
| 438 | return; |
| 439 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 440 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 441 | try { |
| 442 | request.result = phone != null |
| 443 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 444 | } catch (CallStateException cse) { |
| 445 | request.result = false; |
| 446 | } |
| 447 | // Wake up the requesting thread |
| 448 | notifyRequester(request); |
| 449 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 452 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 453 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 454 | final Phone phone = getPhoneFromRequest(request); |
| 455 | request.result = phone != null ? |
| 456 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 457 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 458 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 459 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 460 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 461 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 462 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 463 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 464 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 465 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 466 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 467 | if (uiccCard == null) { |
| 468 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 469 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 470 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 471 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 472 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 473 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 474 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 475 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 476 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 477 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 478 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 479 | break; |
| 480 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 481 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 482 | ar = (AsyncResult) msg.obj; |
| 483 | request = (MainThreadRequest) ar.userObj; |
| 484 | if (ar.exception == null && ar.result != null) { |
| 485 | request.result = ar.result; |
| 486 | } else { |
| 487 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 488 | if (ar.result == null) { |
| 489 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 490 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 491 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 492 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 493 | } else { |
| 494 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 495 | } |
| 496 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 497 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 498 | break; |
| 499 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 500 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 501 | request = (MainThreadRequest) msg.obj; |
| 502 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 503 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 504 | if (uiccCard == null) { |
| 505 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 506 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 507 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 508 | } else { |
| 509 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 510 | request); |
| 511 | uiccCard.iccTransmitApduBasicChannel( |
| 512 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 513 | iccArgument.p3, iccArgument.data, onCompleted); |
| 514 | } |
| 515 | break; |
| 516 | |
| 517 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 518 | ar = (AsyncResult) msg.obj; |
| 519 | request = (MainThreadRequest) ar.userObj; |
| 520 | if (ar.exception == null && ar.result != null) { |
| 521 | request.result = ar.result; |
| 522 | } else { |
| 523 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 524 | if (ar.result == null) { |
| 525 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 526 | } else if (ar.exception instanceof CommandException) { |
| 527 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 528 | ar.exception); |
| 529 | } else { |
| 530 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 531 | } |
| 532 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 533 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 534 | break; |
| 535 | |
| 536 | case CMD_EXCHANGE_SIM_IO: |
| 537 | request = (MainThreadRequest) msg.obj; |
| 538 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 539 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 540 | if (uiccCard == null) { |
| 541 | loge("iccExchangeSimIO: No UICC"); |
| 542 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 543 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 544 | } else { |
| 545 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 546 | request); |
| 547 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 548 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 549 | iccArgument.data, onCompleted); |
| 550 | } |
| 551 | break; |
| 552 | |
| 553 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 554 | ar = (AsyncResult) msg.obj; |
| 555 | request = (MainThreadRequest) ar.userObj; |
| 556 | if (ar.exception == null && ar.result != null) { |
| 557 | request.result = ar.result; |
| 558 | } else { |
| 559 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 560 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 561 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 562 | break; |
| 563 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 564 | case CMD_SEND_ENVELOPE: |
| 565 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 566 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 567 | if (uiccCard == null) { |
| 568 | loge("sendEnvelopeWithStatus: No UICC"); |
| 569 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 570 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 571 | } else { |
| 572 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 573 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 574 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 575 | break; |
| 576 | |
| 577 | case EVENT_SEND_ENVELOPE_DONE: |
| 578 | ar = (AsyncResult) msg.obj; |
| 579 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 580 | if (ar.exception == null && ar.result != null) { |
| 581 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 582 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 583 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 584 | if (ar.result == null) { |
| 585 | loge("sendEnvelopeWithStatus: Empty response"); |
| 586 | } else if (ar.exception instanceof CommandException) { |
| 587 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 588 | ar.exception); |
| 589 | } else { |
| 590 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 591 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 592 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 593 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 594 | break; |
| 595 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 596 | case CMD_OPEN_CHANNEL: |
| 597 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 598 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 599 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 600 | if (uiccCard == null) { |
| 601 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 602 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 603 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 604 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 605 | } else { |
| 606 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 607 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 608 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 609 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 610 | break; |
| 611 | |
| 612 | case EVENT_OPEN_CHANNEL_DONE: |
| 613 | ar = (AsyncResult) msg.obj; |
| 614 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 615 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 616 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 617 | int[] result = (int[]) ar.result; |
| 618 | int channelId = result[0]; |
| 619 | byte[] selectResponse = null; |
| 620 | if (result.length > 1) { |
| 621 | selectResponse = new byte[result.length - 1]; |
| 622 | for (int i = 1; i < result.length; ++i) { |
| 623 | selectResponse[i - 1] = (byte) result[i]; |
| 624 | } |
| 625 | } |
| 626 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 627 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 628 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 629 | if (ar.result == null) { |
| 630 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 631 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 632 | if (ar.exception != null) { |
| 633 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 634 | } |
| 635 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 636 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 637 | if (ar.exception instanceof CommandException) { |
| 638 | CommandException.Error error = |
| 639 | ((CommandException) (ar.exception)).getCommandError(); |
| 640 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 641 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 642 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 643 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 644 | } |
| 645 | } |
| 646 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 647 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 648 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 649 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 650 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 651 | break; |
| 652 | |
| 653 | case CMD_CLOSE_CHANNEL: |
| 654 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 655 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 656 | if (uiccCard == null) { |
| 657 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 658 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 659 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 660 | } else { |
| 661 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 662 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 663 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 664 | break; |
| 665 | |
| 666 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 667 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 668 | break; |
| 669 | |
| 670 | case CMD_NV_READ_ITEM: |
| 671 | request = (MainThreadRequest) msg.obj; |
| 672 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 673 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 674 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 675 | break; |
| 676 | |
| 677 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 678 | ar = (AsyncResult) msg.obj; |
| 679 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 680 | if (ar.exception == null && ar.result != null) { |
| 681 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 682 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 683 | request.result = ""; |
| 684 | if (ar.result == null) { |
| 685 | loge("nvReadItem: Empty response"); |
| 686 | } else if (ar.exception instanceof CommandException) { |
| 687 | loge("nvReadItem: CommandException: " + |
| 688 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 689 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 690 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 691 | } |
| 692 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 693 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 694 | break; |
| 695 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 696 | case CMD_NV_WRITE_ITEM: |
| 697 | request = (MainThreadRequest) msg.obj; |
| 698 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 699 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 700 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 701 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 702 | break; |
| 703 | |
| 704 | case EVENT_NV_WRITE_ITEM_DONE: |
| 705 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 706 | break; |
| 707 | |
| 708 | case CMD_NV_WRITE_CDMA_PRL: |
| 709 | request = (MainThreadRequest) msg.obj; |
| 710 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 711 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 712 | break; |
| 713 | |
| 714 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 715 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 716 | break; |
| 717 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 718 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 719 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 720 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 721 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 722 | break; |
| 723 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 724 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 725 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 726 | break; |
| 727 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 728 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 729 | request = (MainThreadRequest) msg.obj; |
| 730 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 731 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 732 | break; |
| 733 | |
| 734 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 735 | ar = (AsyncResult) msg.obj; |
| 736 | request = (MainThreadRequest) ar.userObj; |
| 737 | if (ar.exception == null && ar.result != null) { |
| 738 | request.result = ar.result; // Integer |
| 739 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 740 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 741 | if (ar.result == null) { |
| 742 | loge("getPreferredNetworkType: Empty response"); |
| 743 | } else if (ar.exception instanceof CommandException) { |
| 744 | loge("getPreferredNetworkType: CommandException: " + |
| 745 | ar.exception); |
| 746 | } else { |
| 747 | loge("getPreferredNetworkType: Unknown exception"); |
| 748 | } |
| 749 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 750 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 751 | break; |
| 752 | |
| 753 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 754 | request = (MainThreadRequest) msg.obj; |
| 755 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 756 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 757 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 758 | break; |
| 759 | |
| 760 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 761 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 762 | break; |
| 763 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 764 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 765 | request = (MainThreadRequest)msg.obj; |
| 766 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 767 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 768 | break; |
| 769 | |
| 770 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 771 | ar = (AsyncResult)msg.obj; |
| 772 | request = (MainThreadRequest)ar.userObj; |
| 773 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 774 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 775 | break; |
| 776 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 777 | case CMD_SET_VOICEMAIL_NUMBER: |
| 778 | request = (MainThreadRequest) msg.obj; |
| 779 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 780 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 781 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 782 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 783 | break; |
| 784 | |
| 785 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 786 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 787 | break; |
| 788 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 789 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 790 | request = (MainThreadRequest) msg.obj; |
| 791 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 792 | request); |
| 793 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 794 | break; |
| 795 | |
| 796 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 797 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 798 | break; |
| 799 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 800 | case CMD_PERFORM_NETWORK_SCAN: |
| 801 | request = (MainThreadRequest) msg.obj; |
| 802 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 803 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 804 | break; |
| 805 | |
| 806 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 807 | ar = (AsyncResult) msg.obj; |
| 808 | request = (MainThreadRequest) ar.userObj; |
| 809 | CellNetworkScanResult cellScanResult; |
| 810 | if (ar.exception == null && ar.result != null) { |
| 811 | cellScanResult = new CellNetworkScanResult( |
| 812 | CellNetworkScanResult.STATUS_SUCCESS, |
| 813 | (List<OperatorInfo>) ar.result); |
| 814 | } else { |
| 815 | if (ar.result == null) { |
| 816 | loge("getCellNetworkScanResults: Empty response"); |
| 817 | } |
| 818 | if (ar.exception != null) { |
| 819 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 820 | } |
| 821 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 822 | if (ar.exception instanceof CommandException) { |
| 823 | CommandException.Error error = |
| 824 | ((CommandException) (ar.exception)).getCommandError(); |
| 825 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 826 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 827 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 828 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 829 | } |
| 830 | } |
| 831 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 832 | } |
| 833 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 834 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 835 | break; |
| 836 | |
| 837 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 838 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 839 | ManualNetworkSelectionArgument selArg = |
| 840 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 841 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 842 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 843 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 844 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 845 | break; |
| 846 | |
| 847 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 848 | ar = (AsyncResult) msg.obj; |
| 849 | request = (MainThreadRequest) ar.userObj; |
| 850 | if (ar.exception == null) { |
| 851 | request.result = true; |
| 852 | } else { |
| 853 | request.result = false; |
| 854 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 855 | } |
| 856 | notifyRequester(request); |
| 857 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 858 | break; |
| 859 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 860 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 861 | request = (MainThreadRequest) msg.obj; |
| 862 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 863 | if (defaultPhone != null) { |
| 864 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 865 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 866 | break; |
| 867 | |
| 868 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 869 | ar = (AsyncResult) msg.obj; |
| 870 | request = (MainThreadRequest) ar.userObj; |
| 871 | if (ar.exception == null && ar.result != null) { |
| 872 | request.result = ar.result; |
| 873 | } else { |
| 874 | if (ar.result == null) { |
| 875 | loge("queryModemActivityInfo: Empty response"); |
| 876 | } else if (ar.exception instanceof CommandException) { |
| 877 | loge("queryModemActivityInfo: CommandException: " + |
| 878 | ar.exception); |
| 879 | } else { |
| 880 | loge("queryModemActivityInfo: Unknown exception"); |
| 881 | } |
| 882 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 883 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 884 | if (request.result == null) { |
| 885 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 886 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 887 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 888 | break; |
| 889 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 890 | case CMD_SET_ALLOWED_CARRIERS: |
| 891 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 892 | CarrierRestrictionRules argument = |
| 893 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 894 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 895 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 896 | break; |
| 897 | |
| 898 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 899 | ar = (AsyncResult) msg.obj; |
| 900 | request = (MainThreadRequest) ar.userObj; |
| 901 | if (ar.exception == null && ar.result != null) { |
| 902 | request.result = ar.result; |
| 903 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 904 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 905 | if (ar.exception instanceof CommandException) { |
| 906 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 907 | CommandException.Error error = |
| 908 | ((CommandException) (ar.exception)).getCommandError(); |
| 909 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 910 | request.result = |
| 911 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 912 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 913 | } else { |
| 914 | loge("setAllowedCarriers: Unknown exception"); |
| 915 | } |
| 916 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 917 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 918 | break; |
| 919 | |
| 920 | case CMD_GET_ALLOWED_CARRIERS: |
| 921 | request = (MainThreadRequest) msg.obj; |
| 922 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 923 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 924 | break; |
| 925 | |
| 926 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 927 | ar = (AsyncResult) msg.obj; |
| 928 | request = (MainThreadRequest) ar.userObj; |
| 929 | if (ar.exception == null && ar.result != null) { |
| 930 | request.result = ar.result; |
| 931 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 932 | request.result = new IllegalStateException( |
| 933 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 934 | if (ar.result == null) { |
| 935 | loge("getAllowedCarriers: Empty response"); |
| 936 | } else if (ar.exception instanceof CommandException) { |
| 937 | loge("getAllowedCarriers: CommandException: " + |
| 938 | ar.exception); |
| 939 | } else { |
| 940 | loge("getAllowedCarriers: Unknown exception"); |
| 941 | } |
| 942 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 943 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 944 | break; |
| 945 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 946 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 947 | ar = (AsyncResult) msg.obj; |
| 948 | request = (MainThreadRequest) ar.userObj; |
| 949 | if (ar.exception == null && ar.result != null) { |
| 950 | request.result = ar.result; |
| 951 | } else { |
| 952 | request.result = new IllegalArgumentException( |
| 953 | "Failed to retrieve Forbidden Plmns"); |
| 954 | if (ar.result == null) { |
| 955 | loge("getForbiddenPlmns: Empty response"); |
| 956 | } else { |
| 957 | loge("getForbiddenPlmns: Unknown exception"); |
| 958 | } |
| 959 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 960 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 961 | break; |
| 962 | |
| 963 | case CMD_GET_FORBIDDEN_PLMNS: |
| 964 | request = (MainThreadRequest) msg.obj; |
| 965 | uiccCard = getUiccCardFromRequest(request); |
| 966 | if (uiccCard == null) { |
| 967 | loge("getForbiddenPlmns() UiccCard is null"); |
| 968 | request.result = new IllegalArgumentException( |
| 969 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 970 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 971 | break; |
| 972 | } |
| 973 | Integer appType = (Integer) request.argument; |
| 974 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 975 | if (uiccApp == null) { |
| 976 | loge("getForbiddenPlmns() no app with specified type -- " |
| 977 | + appType); |
| 978 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 979 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 980 | break; |
| 981 | } else { |
| 982 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 983 | + " specified type -- " + appType); |
| 984 | } |
| 985 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 986 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 987 | onCompleted); |
| 988 | break; |
| 989 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 990 | case CMD_SWITCH_SLOTS: |
| 991 | request = (MainThreadRequest) msg.obj; |
| 992 | int[] physicalSlots = (int[]) request.argument; |
| 993 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 994 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 995 | break; |
| 996 | |
| 997 | case EVENT_SWITCH_SLOTS_DONE: |
| 998 | ar = (AsyncResult) msg.obj; |
| 999 | request = (MainThreadRequest) ar.userObj; |
| 1000 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1001 | notifyRequester(request); |
| 1002 | break; |
| 1003 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1004 | request = (MainThreadRequest) msg.obj; |
| 1005 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1006 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1007 | break; |
| 1008 | |
| 1009 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1010 | ar = (AsyncResult) msg.obj; |
| 1011 | request = (MainThreadRequest) ar.userObj; |
| 1012 | if (ar.exception != null) { |
| 1013 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1014 | } else { |
| 1015 | int mode = ((int[]) ar.result)[0]; |
| 1016 | if (mode == 0) { |
| 1017 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1018 | } else { |
| 1019 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1020 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1021 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1022 | notifyRequester(request); |
| 1023 | break; |
| 1024 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1025 | request = (MainThreadRequest) msg.obj; |
| 1026 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1027 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1028 | break; |
| 1029 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1030 | ar = (AsyncResult) msg.obj; |
| 1031 | request = (MainThreadRequest) ar.userObj; |
| 1032 | if (ar.exception != null) { |
| 1033 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1034 | } else { |
| 1035 | request.result = ((int[]) ar.result)[0]; |
| 1036 | } |
| 1037 | notifyRequester(request); |
| 1038 | break; |
| 1039 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1040 | request = (MainThreadRequest) msg.obj; |
| 1041 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1042 | int mode = (int) request.argument; |
| 1043 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1044 | break; |
| 1045 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1046 | ar = (AsyncResult) msg.obj; |
| 1047 | request = (MainThreadRequest) ar.userObj; |
| 1048 | request.result = ar.exception == null; |
| 1049 | notifyRequester(request); |
| 1050 | break; |
| 1051 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1052 | request = (MainThreadRequest) msg.obj; |
| 1053 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1054 | int subscriptionMode = (int) request.argument; |
| 1055 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1056 | break; |
| 1057 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1058 | ar = (AsyncResult) msg.obj; |
| 1059 | request = (MainThreadRequest) ar.userObj; |
| 1060 | request.result = ar.exception == null; |
| 1061 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1062 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1063 | case CMD_GET_ALL_CELL_INFO: |
| 1064 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1065 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1066 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1067 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1068 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1069 | ar = (AsyncResult) msg.obj; |
| 1070 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1071 | // If a timeout occurs, the response will be null |
| 1072 | request.result = (ar.exception == null && ar.result != null) |
| 1073 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1074 | synchronized (request) { |
| 1075 | request.notifyAll(); |
| 1076 | } |
| 1077 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1078 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1079 | request = (MainThreadRequest) msg.obj; |
| 1080 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1081 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1082 | break; |
| 1083 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1084 | ar = (AsyncResult) msg.obj; |
| 1085 | request = (MainThreadRequest) ar.userObj; |
| 1086 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1087 | try { |
| 1088 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1089 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1090 | cb.onError( |
| 1091 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1092 | ar.exception.getClass().getName(), |
| 1093 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1094 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1095 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1096 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1097 | } else { |
| 1098 | // use the result as returned |
| 1099 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1100 | } |
| 1101 | } catch (RemoteException re) { |
| 1102 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1103 | } |
| 1104 | break; |
| 1105 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1106 | request = (MainThreadRequest) msg.obj; |
| 1107 | WorkSource ws = (WorkSource) request.argument; |
| 1108 | Phone phone = getPhoneFromRequest(request); |
| 1109 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1110 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1111 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1112 | ar = (AsyncResult) msg.obj; |
| 1113 | request = (MainThreadRequest) ar.userObj; |
| 1114 | if (ar.exception == null) { |
| 1115 | request.result = ar.result; |
| 1116 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1117 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1118 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1119 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1120 | } |
| 1121 | |
| 1122 | synchronized (request) { |
| 1123 | request.notifyAll(); |
| 1124 | } |
| 1125 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1126 | case CMD_MODEM_REBOOT: |
| 1127 | request = (MainThreadRequest) msg.obj; |
| 1128 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1129 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1130 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1131 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1132 | handleNullReturnEvent(msg, "rebootModem"); |
| 1133 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1134 | case CMD_REQUEST_ENABLE_MODEM: |
| 1135 | request = (MainThreadRequest) msg.obj; |
| 1136 | boolean enable = (boolean) request.argument; |
| 1137 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1138 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1139 | PhoneConfigurationManager.getInstance() |
| 1140 | .enablePhone(request.phone, enable, onCompleted); |
| 1141 | break; |
| 1142 | case EVENT_ENABLE_MODEM_DONE: |
| 1143 | ar = (AsyncResult) msg.obj; |
| 1144 | request = (MainThreadRequest) ar.userObj; |
| 1145 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1146 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1147 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1148 | if ((boolean) request.result) { |
| 1149 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1150 | updateModemStateMetrics(); |
| 1151 | } else { |
| 1152 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1153 | + ar.exception); |
| 1154 | } |
| 1155 | notifyRequester(request); |
| 1156 | break; |
| 1157 | case CMD_GET_MODEM_STATUS: |
| 1158 | request = (MainThreadRequest) msg.obj; |
| 1159 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1160 | PhoneConfigurationManager.getInstance() |
| 1161 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1162 | break; |
| 1163 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1164 | ar = (AsyncResult) msg.obj; |
| 1165 | request = (MainThreadRequest) ar.userObj; |
| 1166 | int id = request.phone.getPhoneId(); |
| 1167 | if (ar.exception == null && ar.result != null) { |
| 1168 | request.result = ar.result; |
| 1169 | //update the cache as modem status has changed |
| 1170 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1171 | (boolean) request.result); |
| 1172 | } else { |
| 1173 | // Return true if modem status cannot be retrieved. For most cases, |
| 1174 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1175 | // and disable modem are not supported. Modem is always on. |
| 1176 | // TODO: this should be fixed in R to support a third |
| 1177 | // status UNKNOWN b/131631629 |
| 1178 | request.result = true; |
| 1179 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1180 | + ar.exception); |
| 1181 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1182 | notifyRequester(request); |
| 1183 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1184 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1185 | ar = (AsyncResult) msg.obj; |
| 1186 | request = (MainThreadRequest) ar.userObj; |
| 1187 | if (ar.exception == null && ar.result != null) { |
| 1188 | request.result = ar.result; |
| 1189 | } else { |
| 1190 | request.result = -1; |
| 1191 | loge("Failed to set Forbidden Plmns"); |
| 1192 | if (ar.result == null) { |
| 1193 | loge("setForbidenPlmns: Empty response"); |
| 1194 | } else if (ar.exception != null) { |
| 1195 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1196 | request.result = -1; |
| 1197 | } else { |
| 1198 | loge("setForbiddenPlmns: Unknown exception"); |
| 1199 | } |
| 1200 | } |
| 1201 | notifyRequester(request); |
| 1202 | break; |
| 1203 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1204 | request = (MainThreadRequest) msg.obj; |
| 1205 | uiccCard = getUiccCardFromRequest(request); |
| 1206 | if (uiccCard == null) { |
| 1207 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1208 | request.result = -1; |
| 1209 | notifyRequester(request); |
| 1210 | break; |
| 1211 | } |
| 1212 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1213 | (Pair<Integer, List<String>>) request.argument; |
| 1214 | appType = setFplmnsArgs.first; |
| 1215 | List<String> fplmns = setFplmnsArgs.second; |
| 1216 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1217 | if (uiccApp == null) { |
| 1218 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1219 | request.result = -1; |
| 1220 | loge("Failed to get UICC App"); |
| 1221 | notifyRequester(request); |
| 1222 | } else { |
| 1223 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1224 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1225 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1226 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1227 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1228 | case CMD_ERASE_MODEM_CONFIG: |
| 1229 | request = (MainThreadRequest) msg.obj; |
| 1230 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1231 | defaultPhone.eraseModemConfig(onCompleted); |
| 1232 | break; |
| 1233 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1234 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1235 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1236 | default: |
| 1237 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1238 | break; |
| 1239 | } |
| 1240 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1241 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1242 | private void notifyRequester(MainThreadRequest request) { |
| 1243 | synchronized (request) { |
| 1244 | request.notifyAll(); |
| 1245 | } |
| 1246 | } |
| 1247 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1248 | private void handleNullReturnEvent(Message msg, String command) { |
| 1249 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1250 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1251 | if (ar.exception == null) { |
| 1252 | request.result = true; |
| 1253 | } else { |
| 1254 | request.result = false; |
| 1255 | if (ar.exception instanceof CommandException) { |
| 1256 | loge(command + ": CommandException: " + ar.exception); |
| 1257 | } else { |
| 1258 | loge(command + ": Unknown exception"); |
| 1259 | } |
| 1260 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1261 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1262 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | /** |
| 1266 | * Posts the specified command to be executed on the main thread, |
| 1267 | * waits for the request to complete, and returns the result. |
| 1268 | * @see #sendRequestAsync |
| 1269 | */ |
| 1270 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1271 | return sendRequest( |
| 1272 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | /** |
| 1276 | * Posts the specified command to be executed on the main thread, |
| 1277 | * waits for the request to complete, and returns the result. |
| 1278 | * @see #sendRequestAsync |
| 1279 | */ |
| 1280 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1281 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1282 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | /** |
| 1286 | * Posts the specified command to be executed on the main thread, |
| 1287 | * waits for the request to complete, and returns the result. |
| 1288 | * @see #sendRequestAsync |
| 1289 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1290 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1291 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | /** |
| 1295 | * Posts the specified command to be executed on the main thread, |
| 1296 | * waits for the request to complete, and returns the result. |
| 1297 | * @see #sendRequestAsync |
| 1298 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1299 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1300 | return sendRequest(command, argument, subId, null, workSource); |
| 1301 | } |
| 1302 | |
| 1303 | /** |
| 1304 | * Posts the specified command to be executed on the main thread, |
| 1305 | * waits for the request to complete, and returns the result. |
| 1306 | * @see #sendRequestAsync |
| 1307 | */ |
| 1308 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1309 | return sendRequest( |
| 1310 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1311 | } |
| 1312 | |
| 1313 | /** |
| 1314 | * Posts the specified command to be executed on the main thread, |
| 1315 | * waits for the request to complete, and returns the result. |
| 1316 | * @see #sendRequestAsync |
| 1317 | */ |
| 1318 | private Object sendRequest( |
| 1319 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1320 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1321 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1322 | } |
| 1323 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1324 | MainThreadRequest request = null; |
| 1325 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1326 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1327 | } else if (phone != null) { |
| 1328 | request = new MainThreadRequest(argument, phone, workSource); |
| 1329 | } else { |
| 1330 | request = new MainThreadRequest(argument, subId, workSource); |
| 1331 | } |
| 1332 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1333 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1334 | msg.sendToTarget(); |
| 1335 | |
| 1336 | // Wait for the request to complete |
| 1337 | synchronized (request) { |
| 1338 | while (request.result == null) { |
| 1339 | try { |
| 1340 | request.wait(); |
| 1341 | } catch (InterruptedException e) { |
| 1342 | // Do nothing, go back and wait until the request is complete |
| 1343 | } |
| 1344 | } |
| 1345 | } |
| 1346 | return request.result; |
| 1347 | } |
| 1348 | |
| 1349 | /** |
| 1350 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1351 | * Posts the specified command to be executed on the main thread, and |
| 1352 | * returns immediately. |
| 1353 | * @see #sendRequest |
| 1354 | */ |
| 1355 | private void sendRequestAsync(int command) { |
| 1356 | mMainThreadHandler.sendEmptyMessage(command); |
| 1357 | } |
| 1358 | |
| 1359 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1360 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1361 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1362 | */ |
| 1363 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1364 | sendRequestAsync(command, argument, null, null); |
| 1365 | } |
| 1366 | |
| 1367 | /** |
| 1368 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1369 | * @see {@link #sendRequest(int,Object)} |
| 1370 | */ |
| 1371 | private void sendRequestAsync( |
| 1372 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1373 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1374 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1375 | msg.sendToTarget(); |
| 1376 | } |
| 1377 | |
| 1378 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1379 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1380 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1381 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1382 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1383 | synchronized (PhoneInterfaceManager.class) { |
| 1384 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1385 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1386 | } else { |
| 1387 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1388 | } |
| 1389 | return sInstance; |
| 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1394 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1395 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1396 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 1397 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1398 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1399 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1400 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1401 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1402 | mTelephonySharedPreferences = |
| 1403 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1404 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1405 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1406 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1407 | publish(); |
| 1408 | } |
| 1409 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1410 | private Phone getDefaultPhone() { |
| 1411 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1412 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1413 | } |
| 1414 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1415 | private void publish() { |
| 1416 | if (DBG) log("publish: " + this); |
| 1417 | |
| 1418 | ServiceManager.addService("phone", this); |
| 1419 | } |
| 1420 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1421 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1422 | if (request.phone != null) { |
| 1423 | return request.phone; |
| 1424 | } else { |
| 1425 | return getPhoneFromSubId(request.subId); |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | private Phone getPhoneFromSubId(int subId) { |
| 1430 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1431 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1432 | } |
| 1433 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1434 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1435 | Phone phone = getPhoneFromRequest(request); |
| 1436 | return phone == null ? null : |
| 1437 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1438 | } |
| 1439 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1440 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1441 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1442 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1443 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1444 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1445 | private void sendEraseModemConfig(Phone phone) { |
| 1446 | if (phone != null) { |
| 1447 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1448 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1449 | final long identity = Binder.clearCallingIdentity(); |
| 1450 | try { |
| 1451 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1452 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1453 | } finally { |
| 1454 | Binder.restoreCallingIdentity(identity); |
| 1455 | } |
| 1456 | } |
| 1457 | } |
| 1458 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1459 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1460 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1461 | } |
| 1462 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1463 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1464 | if (DBG) log("dial: " + number); |
| 1465 | // No permission check needed here: This is just a wrapper around the |
| 1466 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1467 | // the UI before it does anything. |
| 1468 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1469 | final long identity = Binder.clearCallingIdentity(); |
| 1470 | try { |
| 1471 | String url = createTelUrl(number); |
| 1472 | if (url == null) { |
| 1473 | return; |
| 1474 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1475 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1476 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1477 | PhoneConstants.State state = mCM.getState(subId); |
| 1478 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1479 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1480 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1481 | mApp.startActivity(intent); |
| 1482 | } |
| 1483 | } finally { |
| 1484 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1485 | } |
| 1486 | } |
| 1487 | |
| 1488 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1489 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1490 | } |
| 1491 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1492 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1493 | if (DBG) log("call: " + number); |
| 1494 | |
| 1495 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1496 | // need to do a permission check since we're calling startActivity() |
| 1497 | // from the context of the phone app. |
| 1498 | enforceCallPermission(); |
| 1499 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1500 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1501 | != AppOpsManager.MODE_ALLOWED) { |
| 1502 | return; |
| 1503 | } |
| 1504 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1505 | final long identity = Binder.clearCallingIdentity(); |
| 1506 | try { |
| 1507 | String url = createTelUrl(number); |
| 1508 | if (url == null) { |
| 1509 | return; |
| 1510 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1511 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1512 | boolean isValid = false; |
| 1513 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1514 | if (slist != null) { |
| 1515 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1516 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1517 | isValid = true; |
| 1518 | break; |
| 1519 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1520 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1521 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1522 | if (!isValid) { |
| 1523 | return; |
| 1524 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1525 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1526 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1527 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1528 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1529 | mApp.startActivity(intent); |
| 1530 | } finally { |
| 1531 | Binder.restoreCallingIdentity(identity); |
| 1532 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1535 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1536 | return supplyPinForSubscriber(getDefaultSubscription(), 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 boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1540 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1541 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1542 | } |
| 1543 | |
| 1544 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1545 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1546 | } |
| 1547 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1548 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1549 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1550 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1551 | } |
| 1552 | |
| 1553 | /** {@hide} */ |
| 1554 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1555 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1556 | } |
| 1557 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1558 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1559 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1560 | |
| 1561 | final long identity = Binder.clearCallingIdentity(); |
| 1562 | try { |
| 1563 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1564 | checkSimPin.start(); |
| 1565 | return checkSimPin.unlockSim(null, pin); |
| 1566 | } finally { |
| 1567 | Binder.restoreCallingIdentity(identity); |
| 1568 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1571 | /** {@hide} */ |
| 1572 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1573 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1574 | } |
| 1575 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1576 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1577 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1578 | |
| 1579 | final long identity = Binder.clearCallingIdentity(); |
| 1580 | try { |
| 1581 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1582 | checkSimPuk.start(); |
| 1583 | return checkSimPuk.unlockSim(puk, pin); |
| 1584 | } finally { |
| 1585 | Binder.restoreCallingIdentity(identity); |
| 1586 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1590 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1591 | * a synchronous one. |
| 1592 | */ |
| 1593 | private static class UnlockSim extends Thread { |
| 1594 | |
| 1595 | private final IccCard mSimCard; |
| 1596 | |
| 1597 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1598 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1599 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1600 | |
| 1601 | // For replies from SimCard interface |
| 1602 | private Handler mHandler; |
| 1603 | |
| 1604 | // For async handler to identify request type |
| 1605 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1606 | |
| 1607 | public UnlockSim(IccCard simCard) { |
| 1608 | mSimCard = simCard; |
| 1609 | } |
| 1610 | |
| 1611 | @Override |
| 1612 | public void run() { |
| 1613 | Looper.prepare(); |
| 1614 | synchronized (UnlockSim.this) { |
| 1615 | mHandler = new Handler() { |
| 1616 | @Override |
| 1617 | public void handleMessage(Message msg) { |
| 1618 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1619 | switch (msg.what) { |
| 1620 | case SUPPLY_PIN_COMPLETE: |
| 1621 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1622 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1623 | mRetryCount = msg.arg1; |
| 1624 | if (ar.exception != null) { |
| 1625 | if (ar.exception instanceof CommandException && |
| 1626 | ((CommandException)(ar.exception)).getCommandError() |
| 1627 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1628 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1629 | } else { |
| 1630 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1631 | } |
| 1632 | } else { |
| 1633 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1634 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1635 | mDone = true; |
| 1636 | UnlockSim.this.notifyAll(); |
| 1637 | } |
| 1638 | break; |
| 1639 | } |
| 1640 | } |
| 1641 | }; |
| 1642 | UnlockSim.this.notifyAll(); |
| 1643 | } |
| 1644 | Looper.loop(); |
| 1645 | } |
| 1646 | |
| 1647 | /* |
| 1648 | * Use PIN or PUK to unlock SIM card |
| 1649 | * |
| 1650 | * If PUK is null, unlock SIM card with PIN |
| 1651 | * |
| 1652 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1653 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1654 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1655 | |
| 1656 | while (mHandler == null) { |
| 1657 | try { |
| 1658 | wait(); |
| 1659 | } catch (InterruptedException e) { |
| 1660 | Thread.currentThread().interrupt(); |
| 1661 | } |
| 1662 | } |
| 1663 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1664 | |
| 1665 | if (puk == null) { |
| 1666 | mSimCard.supplyPin(pin, callback); |
| 1667 | } else { |
| 1668 | mSimCard.supplyPuk(puk, pin, callback); |
| 1669 | } |
| 1670 | |
| 1671 | while (!mDone) { |
| 1672 | try { |
| 1673 | Log.d(LOG_TAG, "wait for done"); |
| 1674 | wait(); |
| 1675 | } catch (InterruptedException e) { |
| 1676 | // Restore the interrupted status |
| 1677 | Thread.currentThread().interrupt(); |
| 1678 | } |
| 1679 | } |
| 1680 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1681 | int[] resultArray = new int[2]; |
| 1682 | resultArray[0] = mResult; |
| 1683 | resultArray[1] = mRetryCount; |
| 1684 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1685 | } |
| 1686 | } |
| 1687 | |
| 1688 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1689 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1690 | |
| 1691 | } |
| 1692 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1693 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1694 | // No permission check needed here: this call is harmless, and it's |
| 1695 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1696 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1697 | final long identity = Binder.clearCallingIdentity(); |
| 1698 | try { |
| 1699 | final Phone phone = getPhone(subId); |
| 1700 | if (phone != null) { |
| 1701 | phone.updateServiceLocation(); |
| 1702 | } |
| 1703 | } finally { |
| 1704 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1705 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1706 | } |
| 1707 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1708 | @Override |
| 1709 | public boolean isRadioOn(String callingPackage) { |
| 1710 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1711 | } |
| 1712 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1713 | @Override |
| 1714 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1715 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1716 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1717 | return false; |
| 1718 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1719 | |
| 1720 | final long identity = Binder.clearCallingIdentity(); |
| 1721 | try { |
| 1722 | return isRadioOnForSubscriber(subId); |
| 1723 | } finally { |
| 1724 | Binder.restoreCallingIdentity(identity); |
| 1725 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1729 | final long identity = Binder.clearCallingIdentity(); |
| 1730 | try { |
| 1731 | final Phone phone = getPhone(subId); |
| 1732 | if (phone != null) { |
| 1733 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1734 | } else { |
| 1735 | return false; |
| 1736 | } |
| 1737 | } finally { |
| 1738 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1739 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1743 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1744 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1745 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1746 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1747 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1748 | |
| 1749 | final long identity = Binder.clearCallingIdentity(); |
| 1750 | try { |
| 1751 | final Phone phone = getPhone(subId); |
| 1752 | if (phone != null) { |
| 1753 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1754 | } |
| 1755 | } finally { |
| 1756 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1757 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1761 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1762 | } |
| 1763 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1764 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1765 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1766 | |
| 1767 | final long identity = Binder.clearCallingIdentity(); |
| 1768 | try { |
| 1769 | final Phone phone = getPhone(subId); |
| 1770 | if (phone == null) { |
| 1771 | return false; |
| 1772 | } |
| 1773 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1774 | toggleRadioOnOffForSubscriber(subId); |
| 1775 | } |
| 1776 | return true; |
| 1777 | } finally { |
| 1778 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1779 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1780 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1781 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1782 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 1783 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1784 | /* |
| 1785 | * If any of the Radios are available, it will need to be |
| 1786 | * shutdown. So return true if any Radio is available. |
| 1787 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1788 | final long identity = Binder.clearCallingIdentity(); |
| 1789 | try { |
| 1790 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1791 | Phone phone = PhoneFactory.getPhone(i); |
| 1792 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1793 | } |
| 1794 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1795 | return false; |
| 1796 | } finally { |
| 1797 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1798 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1801 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1802 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1803 | enforceModifyPermission(); |
| 1804 | |
| 1805 | final long identity = Binder.clearCallingIdentity(); |
| 1806 | try { |
| 1807 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1808 | logv("Shutting down Phone " + i); |
| 1809 | shutdownRadioUsingPhoneId(i); |
| 1810 | } |
| 1811 | } finally { |
| 1812 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1813 | } |
| 1814 | } |
| 1815 | |
| 1816 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1817 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1818 | if (phone != null && phone.isRadioAvailable()) { |
| 1819 | phone.shutdownRadio(); |
| 1820 | } |
| 1821 | } |
| 1822 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1823 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1824 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1825 | |
| 1826 | final long identity = Binder.clearCallingIdentity(); |
| 1827 | try { |
| 1828 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1829 | if (defaultPhone != null) { |
| 1830 | defaultPhone.setRadioPower(turnOn); |
| 1831 | return true; |
| 1832 | } else { |
| 1833 | loge("There's no default phone."); |
| 1834 | return false; |
| 1835 | } |
| 1836 | } finally { |
| 1837 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1838 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1839 | } |
| 1840 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1841 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1842 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1843 | |
| 1844 | final long identity = Binder.clearCallingIdentity(); |
| 1845 | try { |
| 1846 | final Phone phone = getPhone(subId); |
| 1847 | if (phone != null) { |
| 1848 | phone.setRadioPower(turnOn); |
| 1849 | return true; |
| 1850 | } else { |
| 1851 | return false; |
| 1852 | } |
| 1853 | } finally { |
| 1854 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1855 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1856 | } |
| 1857 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1858 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1859 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1860 | public boolean enableDataConnectivity() { |
| 1861 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1862 | |
| 1863 | final long identity = Binder.clearCallingIdentity(); |
| 1864 | try { |
| 1865 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1866 | final Phone phone = getPhone(subId); |
| 1867 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1868 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1869 | return true; |
| 1870 | } else { |
| 1871 | return false; |
| 1872 | } |
| 1873 | } finally { |
| 1874 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1875 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1876 | } |
| 1877 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1878 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1879 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1880 | public boolean disableDataConnectivity() { |
| 1881 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1882 | |
| 1883 | final long identity = Binder.clearCallingIdentity(); |
| 1884 | try { |
| 1885 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1886 | final Phone phone = getPhone(subId); |
| 1887 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1888 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1889 | return true; |
| 1890 | } else { |
| 1891 | return false; |
| 1892 | } |
| 1893 | } finally { |
| 1894 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1895 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1896 | } |
| 1897 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1898 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1899 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1900 | final long identity = Binder.clearCallingIdentity(); |
| 1901 | try { |
| 1902 | final Phone phone = getPhone(subId); |
| 1903 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1904 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1905 | } else { |
| 1906 | return false; |
| 1907 | } |
| 1908 | } finally { |
| 1909 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1910 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1914 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1915 | } |
| 1916 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1917 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1918 | enforceCallPermission(); |
| 1919 | |
| 1920 | final long identity = Binder.clearCallingIdentity(); |
| 1921 | try { |
| 1922 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1923 | return; |
| 1924 | } |
| 1925 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1926 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1927 | } finally { |
| 1928 | Binder.restoreCallingIdentity(identity); |
| 1929 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1930 | }; |
| 1931 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1932 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1933 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1934 | |
| 1935 | final long identity = Binder.clearCallingIdentity(); |
| 1936 | try { |
| 1937 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1938 | return false; |
| 1939 | } |
| 1940 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1941 | } finally { |
| 1942 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1943 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1946 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1947 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1950 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1951 | final long identity = Binder.clearCallingIdentity(); |
| 1952 | try { |
| 1953 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1954 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1955 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1956 | } finally { |
| 1957 | Binder.restoreCallingIdentity(identity); |
| 1958 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1961 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1962 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1963 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1964 | } |
| 1965 | |
| 1966 | @Override |
| 1967 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1968 | final long identity = Binder.clearCallingIdentity(); |
| 1969 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1970 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1971 | if (phone != null) { |
| 1972 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1973 | } else { |
| 1974 | return PhoneConstantConversions.convertDataState( |
| 1975 | PhoneConstants.DataState.DISCONNECTED); |
| 1976 | } |
| 1977 | } finally { |
| 1978 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1979 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1982 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1983 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1984 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1985 | } |
| 1986 | |
| 1987 | @Override |
| 1988 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1989 | final long identity = Binder.clearCallingIdentity(); |
| 1990 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1991 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1992 | if (phone != null) { |
| 1993 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1994 | } else { |
| 1995 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1996 | } |
| 1997 | } finally { |
| 1998 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1999 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2003 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2004 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2005 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2006 | |
| 2007 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2008 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2009 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2010 | .setCallingPackage(callingPackage) |
| 2011 | .setCallingPid(Binder.getCallingPid()) |
| 2012 | .setCallingUid(Binder.getCallingUid()) |
| 2013 | .setMethod("getCellLocation") |
| 2014 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2015 | .build()); |
| 2016 | switch (locationResult) { |
| 2017 | case DENIED_HARD: |
| 2018 | throw new SecurityException("Not allowed to access cell location"); |
| 2019 | case DENIED_SOFT: |
| 2020 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2023 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2024 | final long identity = Binder.clearCallingIdentity(); |
| 2025 | try { |
| 2026 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 2027 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2028 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2029 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 2030 | cl.fillInNotifierBundle(data); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2031 | return data; |
| 2032 | } finally { |
| 2033 | Binder.restoreCallingIdentity(identity); |
| 2034 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2035 | } |
| 2036 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2037 | @Override |
Jack Yu | 7c5d91a | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2038 | public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) { |
| 2039 | if (!TextUtils.isEmpty(callingPackage)) { |
| 2040 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
| 2041 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2042 | mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) { |
| 2043 | return ""; |
| 2044 | } |
| 2045 | } |
| 2046 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2047 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2048 | // registered cell info, so return a NULL country instead. |
| 2049 | final long identity = Binder.clearCallingIdentity(); |
| 2050 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2051 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2052 | // Get default phone in this case. |
| 2053 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2054 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2055 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2056 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2057 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2058 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 2059 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 2060 | return ""; |
| 2061 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2062 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2063 | if (phone != null) { |
| 2064 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2065 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2066 | if (sst != null) { |
| 2067 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2068 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2069 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2070 | return lt.getCurrentCountry(); |
| 2071 | } else if (emergencyNumberTracker != null) { |
| 2072 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2073 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2074 | } |
| 2075 | } |
| 2076 | } |
| 2077 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2078 | } finally { |
| 2079 | Binder.restoreCallingIdentity(identity); |
| 2080 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2084 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2085 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2086 | } |
| 2087 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2088 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2089 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2090 | mApp.enforceCallingOrSelfPermission( |
| 2091 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2092 | |
| 2093 | final long identity = Binder.clearCallingIdentity(); |
| 2094 | try { |
| 2095 | final Phone phone = getPhone(subId); |
| 2096 | if (phone != null) { |
| 2097 | phone.enableLocationUpdates(); |
| 2098 | } |
| 2099 | } finally { |
| 2100 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2101 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | @Override |
| 2105 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2106 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2107 | } |
| 2108 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2109 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2110 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2111 | mApp.enforceCallingOrSelfPermission( |
| 2112 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2113 | |
| 2114 | final long identity = Binder.clearCallingIdentity(); |
| 2115 | try { |
| 2116 | final Phone phone = getPhone(subId); |
| 2117 | if (phone != null) { |
| 2118 | phone.disableLocationUpdates(); |
| 2119 | } |
| 2120 | } finally { |
| 2121 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2122 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2123 | } |
| 2124 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2125 | /** |
| 2126 | * Returns the target SDK version number for a given package name. |
| 2127 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2128 | * This call MUST be invoked before clearing the calling UID. |
| 2129 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2130 | * @return target SDK if the package is found or INT_MAX. |
| 2131 | */ |
| 2132 | private int getTargetSdk(String packageName) { |
| 2133 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2134 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2135 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2136 | if (ai != null) return ai.targetSdkVersion; |
| 2137 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2138 | loge("Failed to get package info for pkg=" |
| 2139 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2140 | } |
| 2141 | return Integer.MAX_VALUE; |
| 2142 | } |
| 2143 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2144 | @Override |
| 2145 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2146 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 2147 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2148 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2149 | throw new SecurityException( |
| 2150 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2151 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2152 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2153 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2154 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2155 | return null; |
| 2156 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2157 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2158 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2159 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2160 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 2161 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2162 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2163 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2164 | for (CellInfo ci : info) { |
| 2165 | if (ci instanceof CellInfoGsm) { |
| 2166 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2167 | } else if (ci instanceof CellInfoWcdma) { |
| 2168 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2169 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2170 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2171 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2172 | } |
| 2173 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2174 | private List<CellInfo> getCachedCellInfo() { |
| 2175 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2176 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2177 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2178 | if (info != null) cellInfos.addAll(info); |
| 2179 | } |
| 2180 | return cellInfos; |
| 2181 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2182 | |
| 2183 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2184 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2185 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2186 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2187 | |
| 2188 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2189 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2190 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2191 | .setCallingPackage(callingPackage) |
| 2192 | .setCallingPid(Binder.getCallingPid()) |
| 2193 | .setCallingUid(Binder.getCallingUid()) |
| 2194 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2195 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2196 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2197 | .build()); |
| 2198 | switch (locationResult) { |
| 2199 | case DENIED_HARD: |
| 2200 | throw new SecurityException("Not allowed to access cell info"); |
| 2201 | case DENIED_SOFT: |
| 2202 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2203 | } |
| 2204 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2205 | final int targetSdk = getTargetSdk(callingPackage); |
| 2206 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2207 | return getCachedCellInfo(); |
| 2208 | } |
| 2209 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2210 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2211 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2212 | final long identity = Binder.clearCallingIdentity(); |
| 2213 | try { |
| 2214 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2215 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2216 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2217 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2218 | if (info != null) cellInfos.addAll(info); |
| 2219 | } |
| 2220 | return cellInfos; |
| 2221 | } finally { |
| 2222 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2223 | } |
| 2224 | } |
| 2225 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2226 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2227 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2228 | requestCellInfoUpdateInternal( |
| 2229 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2230 | } |
| 2231 | |
| 2232 | @Override |
| 2233 | public void requestCellInfoUpdateWithWorkSource( |
| 2234 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2235 | enforceModifyPermission(); |
| 2236 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2237 | } |
| 2238 | |
| 2239 | private void requestCellInfoUpdateInternal( |
| 2240 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2241 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2242 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2243 | |
| 2244 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2245 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2246 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2247 | .setCallingPackage(callingPackage) |
| 2248 | .setCallingPid(Binder.getCallingPid()) |
| 2249 | .setCallingUid(Binder.getCallingUid()) |
| 2250 | .setMethod("requestCellInfoUpdate") |
| 2251 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2252 | .build()); |
| 2253 | switch (locationResult) { |
| 2254 | case DENIED_HARD: |
| 2255 | throw new SecurityException("Not allowed to access cell info"); |
| 2256 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2257 | try { |
| 2258 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2259 | } catch (RemoteException re) { |
| 2260 | // Drop without consequences |
| 2261 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2262 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2265 | |
| 2266 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2267 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2268 | |
| 2269 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2270 | } |
| 2271 | |
| 2272 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2273 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2274 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2275 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2276 | |
| 2277 | final long identity = Binder.clearCallingIdentity(); |
| 2278 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2279 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2280 | } finally { |
| 2281 | Binder.restoreCallingIdentity(identity); |
| 2282 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2283 | } |
| 2284 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2285 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2286 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2287 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2288 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2289 | return null; |
| 2290 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2291 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2292 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2293 | callingPackage, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2294 | return null; |
| 2295 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2296 | |
| 2297 | final long identity = Binder.clearCallingIdentity(); |
| 2298 | try { |
| 2299 | return phone.getImei(); |
| 2300 | } finally { |
| 2301 | Binder.restoreCallingIdentity(identity); |
| 2302 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2303 | } |
| 2304 | |
| 2305 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2306 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2307 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2308 | String tac = null; |
| 2309 | if (phone != null) { |
| 2310 | String imei = phone.getImei(); |
| 2311 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2312 | } |
| 2313 | return tac; |
| 2314 | } |
| 2315 | |
| 2316 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2317 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2318 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2319 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2320 | return null; |
| 2321 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2322 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2323 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2324 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2325 | callingPackage, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2326 | return null; |
| 2327 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2328 | |
| 2329 | final long identity = Binder.clearCallingIdentity(); |
| 2330 | try { |
| 2331 | return phone.getMeid(); |
| 2332 | } finally { |
| 2333 | Binder.restoreCallingIdentity(identity); |
| 2334 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2338 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2339 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2340 | String manufacturerCode = null; |
| 2341 | if (phone != null) { |
| 2342 | String meid = phone.getMeid(); |
| 2343 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2344 | } |
| 2345 | return manufacturerCode; |
| 2346 | } |
| 2347 | |
| 2348 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2349 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2350 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2351 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2352 | return null; |
| 2353 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2354 | int subId = phone.getSubId(); |
| 2355 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2356 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2357 | return null; |
| 2358 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2359 | |
| 2360 | final long identity = Binder.clearCallingIdentity(); |
| 2361 | try { |
| 2362 | return phone.getDeviceSvn(); |
| 2363 | } finally { |
| 2364 | Binder.restoreCallingIdentity(identity); |
| 2365 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2366 | } |
| 2367 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2368 | @Override |
| 2369 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2370 | final long identity = Binder.clearCallingIdentity(); |
| 2371 | try { |
| 2372 | final Phone phone = getPhone(subId); |
| 2373 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2374 | } finally { |
| 2375 | Binder.restoreCallingIdentity(identity); |
| 2376 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2377 | } |
| 2378 | |
| 2379 | @Override |
| 2380 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2381 | final long identity = Binder.clearCallingIdentity(); |
| 2382 | try { |
| 2383 | final Phone phone = getPhone(subId); |
| 2384 | return phone == null ? null : phone.getCarrierName(); |
| 2385 | } finally { |
| 2386 | Binder.restoreCallingIdentity(identity); |
| 2387 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2388 | } |
| 2389 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2390 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2391 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2392 | final long identity = Binder.clearCallingIdentity(); |
| 2393 | try { |
| 2394 | final Phone phone = getPhone(subId); |
| 2395 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2396 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2397 | } finally { |
| 2398 | Binder.restoreCallingIdentity(identity); |
| 2399 | } |
| 2400 | } |
| 2401 | |
| 2402 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2403 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2404 | final long identity = Binder.clearCallingIdentity(); |
| 2405 | try { |
| 2406 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2407 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2408 | } finally { |
| 2409 | Binder.restoreCallingIdentity(identity); |
| 2410 | } |
| 2411 | } |
| 2412 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2413 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2414 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2415 | if (!isSubscriptionMccMnc) { |
| 2416 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2417 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2418 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2419 | if (phone == null) { |
| 2420 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2421 | } |
| 2422 | final long identity = Binder.clearCallingIdentity(); |
| 2423 | try { |
| 2424 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2425 | } finally { |
| 2426 | Binder.restoreCallingIdentity(identity); |
| 2427 | } |
| 2428 | } |
| 2429 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2430 | // |
| 2431 | // Internal helper methods. |
| 2432 | // |
| 2433 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2434 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2435 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2436 | * |
| 2437 | * @throws SecurityException if the caller does not have the required permission |
| 2438 | */ |
| 2439 | private void enforceModifyPermission() { |
| 2440 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2441 | } |
| 2442 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2443 | private void enforceActiveEmergencySessionPermission() { |
| 2444 | mApp.enforceCallingOrSelfPermission( |
| 2445 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2446 | } |
| 2447 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2448 | /** |
| 2449 | * Make sure the caller has the CALL_PHONE permission. |
| 2450 | * |
| 2451 | * @throws SecurityException if the caller does not have the required permission |
| 2452 | */ |
| 2453 | private void enforceCallPermission() { |
| 2454 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2455 | } |
| 2456 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2457 | private void enforceSettingsPermission() { |
| 2458 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2459 | } |
| 2460 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2461 | private String createTelUrl(String number) { |
| 2462 | if (TextUtils.isEmpty(number)) { |
| 2463 | return null; |
| 2464 | } |
| 2465 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2466 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2467 | } |
| 2468 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2469 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2470 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2471 | } |
| 2472 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2473 | private static void logv(String msg) { |
| 2474 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2475 | } |
| 2476 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2477 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2478 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2479 | } |
| 2480 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2481 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2482 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2483 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2484 | } |
| 2485 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2486 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2487 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2488 | final long identity = Binder.clearCallingIdentity(); |
| 2489 | try { |
| 2490 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2491 | if (phone == null) { |
| 2492 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2493 | } else { |
| 2494 | return phone.getPhoneType(); |
| 2495 | } |
| 2496 | } finally { |
| 2497 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2498 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2499 | } |
| 2500 | |
| 2501 | /** |
| 2502 | * Returns the CDMA ERI icon index to display |
| 2503 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2504 | @Override |
| 2505 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2506 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2507 | } |
| 2508 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2509 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2510 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2511 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2512 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2513 | return -1; |
| 2514 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2515 | |
| 2516 | final long identity = Binder.clearCallingIdentity(); |
| 2517 | try { |
| 2518 | final Phone phone = getPhone(subId); |
| 2519 | if (phone != null) { |
| 2520 | return phone.getCdmaEriIconIndex(); |
| 2521 | } else { |
| 2522 | return -1; |
| 2523 | } |
| 2524 | } finally { |
| 2525 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2526 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2527 | } |
| 2528 | |
| 2529 | /** |
| 2530 | * Returns the CDMA ERI icon mode, |
| 2531 | * 0 - ON |
| 2532 | * 1 - FLASHING |
| 2533 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2534 | @Override |
| 2535 | public int getCdmaEriIconMode(String callingPackage) { |
| 2536 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2537 | } |
| 2538 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2539 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2540 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2541 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2542 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2543 | return -1; |
| 2544 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2545 | |
| 2546 | final long identity = Binder.clearCallingIdentity(); |
| 2547 | try { |
| 2548 | final Phone phone = getPhone(subId); |
| 2549 | if (phone != null) { |
| 2550 | return phone.getCdmaEriIconMode(); |
| 2551 | } else { |
| 2552 | return -1; |
| 2553 | } |
| 2554 | } finally { |
| 2555 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2556 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | /** |
| 2560 | * Returns the CDMA ERI text, |
| 2561 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2562 | @Override |
| 2563 | public String getCdmaEriText(String callingPackage) { |
| 2564 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2565 | } |
| 2566 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2567 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2568 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2569 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2570 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2571 | return null; |
| 2572 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2573 | |
| 2574 | final long identity = Binder.clearCallingIdentity(); |
| 2575 | try { |
| 2576 | final Phone phone = getPhone(subId); |
| 2577 | if (phone != null) { |
| 2578 | return phone.getCdmaEriText(); |
| 2579 | } else { |
| 2580 | return null; |
| 2581 | } |
| 2582 | } finally { |
| 2583 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2584 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2585 | } |
| 2586 | |
| 2587 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2588 | * Returns the CDMA MDN. |
| 2589 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2590 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2591 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2592 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2593 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2594 | |
| 2595 | final long identity = Binder.clearCallingIdentity(); |
| 2596 | try { |
| 2597 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2598 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2599 | return phone.getLine1Number(); |
| 2600 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2601 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2602 | return null; |
| 2603 | } |
| 2604 | } finally { |
| 2605 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2606 | } |
| 2607 | } |
| 2608 | |
| 2609 | /** |
| 2610 | * Returns the CDMA MIN. |
| 2611 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2612 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2613 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2614 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2615 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2616 | |
| 2617 | final long identity = Binder.clearCallingIdentity(); |
| 2618 | try { |
| 2619 | final Phone phone = getPhone(subId); |
| 2620 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2621 | return phone.getCdmaMin(); |
| 2622 | } else { |
| 2623 | return null; |
| 2624 | } |
| 2625 | } finally { |
| 2626 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2627 | } |
| 2628 | } |
| 2629 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2630 | @Override |
| 2631 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2632 | INumberVerificationCallback callback, String callingPackage) { |
| 2633 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2634 | != PERMISSION_GRANTED) { |
| 2635 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2636 | } |
| 2637 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2638 | |
| 2639 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2640 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2641 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2642 | } |
| 2643 | |
| 2644 | if (range == null) { |
| 2645 | throw new NullPointerException("Range must be non-null"); |
| 2646 | } |
| 2647 | |
| 2648 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2649 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2650 | |
| 2651 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2652 | } |
| 2653 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2654 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2655 | * Returns true if CDMA provisioning needs to run. |
| 2656 | */ |
| 2657 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2658 | final long identity = Binder.clearCallingIdentity(); |
| 2659 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2660 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2661 | } finally { |
| 2662 | Binder.restoreCallingIdentity(identity); |
| 2663 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2667 | * Sets the voice mail number of a given subId. |
| 2668 | */ |
| 2669 | @Override |
| 2670 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2671 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2672 | |
| 2673 | final long identity = Binder.clearCallingIdentity(); |
| 2674 | try { |
| 2675 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2676 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2677 | return success; |
| 2678 | } finally { |
| 2679 | Binder.restoreCallingIdentity(identity); |
| 2680 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2681 | } |
| 2682 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2683 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2684 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2685 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2686 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2687 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2688 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2689 | throw new SecurityException("caller must be system dialer"); |
| 2690 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2691 | |
| 2692 | final long identity = Binder.clearCallingIdentity(); |
| 2693 | try { |
| 2694 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2695 | if (phoneAccountHandle == null) { |
| 2696 | return null; |
| 2697 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2698 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2699 | } finally { |
| 2700 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2701 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2702 | } |
| 2703 | |
| 2704 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2705 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2706 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2707 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2708 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2709 | return null; |
| 2710 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2711 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2712 | final long identity = Binder.clearCallingIdentity(); |
| 2713 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2714 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2715 | } finally { |
| 2716 | Binder.restoreCallingIdentity(identity); |
| 2717 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2718 | } |
| 2719 | |
| 2720 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2721 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2722 | VisualVoicemailSmsFilterSettings settings) { |
| 2723 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2724 | |
| 2725 | final long identity = Binder.clearCallingIdentity(); |
| 2726 | try { |
| 2727 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2728 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2729 | } finally { |
| 2730 | Binder.restoreCallingIdentity(identity); |
| 2731 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2735 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2736 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2737 | |
| 2738 | final long identity = Binder.clearCallingIdentity(); |
| 2739 | try { |
| 2740 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2741 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2742 | } finally { |
| 2743 | Binder.restoreCallingIdentity(identity); |
| 2744 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2745 | } |
| 2746 | |
| 2747 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2748 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2749 | String callingPackage, int subId) { |
| 2750 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2751 | |
| 2752 | final long identity = Binder.clearCallingIdentity(); |
| 2753 | try { |
| 2754 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2755 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2756 | } finally { |
| 2757 | Binder.restoreCallingIdentity(identity); |
| 2758 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2762 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2763 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2764 | |
| 2765 | final long identity = Binder.clearCallingIdentity(); |
| 2766 | try { |
| 2767 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2768 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2769 | } finally { |
| 2770 | Binder.restoreCallingIdentity(identity); |
| 2771 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2772 | } |
| 2773 | |
| 2774 | @Override |
| 2775 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2776 | String number, int port, String text, PendingIntent sentIntent) { |
| 2777 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2778 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2779 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2780 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2781 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2782 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2783 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2784 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2785 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2786 | * Sets the voice activation state of a given subId. |
| 2787 | */ |
| 2788 | @Override |
| 2789 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2790 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2791 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2792 | |
| 2793 | final long identity = Binder.clearCallingIdentity(); |
| 2794 | try { |
| 2795 | final Phone phone = getPhone(subId); |
| 2796 | if (phone != null) { |
| 2797 | phone.setVoiceActivationState(activationState); |
| 2798 | } else { |
| 2799 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2800 | } |
| 2801 | } finally { |
| 2802 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2803 | } |
| 2804 | } |
| 2805 | |
| 2806 | /** |
| 2807 | * Sets the data activation state of a given subId. |
| 2808 | */ |
| 2809 | @Override |
| 2810 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2811 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2812 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2813 | |
| 2814 | final long identity = Binder.clearCallingIdentity(); |
| 2815 | try { |
| 2816 | final Phone phone = getPhone(subId); |
| 2817 | if (phone != null) { |
| 2818 | phone.setDataActivationState(activationState); |
| 2819 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 2820 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2821 | } |
| 2822 | } finally { |
| 2823 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2824 | } |
| 2825 | } |
| 2826 | |
| 2827 | /** |
| 2828 | * Returns the voice activation state of a given subId. |
| 2829 | */ |
| 2830 | @Override |
| 2831 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2832 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2833 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2834 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2835 | final long identity = Binder.clearCallingIdentity(); |
| 2836 | try { |
| 2837 | if (phone != null) { |
| 2838 | return phone.getVoiceActivationState(); |
| 2839 | } else { |
| 2840 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2841 | } |
| 2842 | } finally { |
| 2843 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2844 | } |
| 2845 | } |
| 2846 | |
| 2847 | /** |
| 2848 | * Returns the data activation state of a given subId. |
| 2849 | */ |
| 2850 | @Override |
| 2851 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2852 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2853 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2854 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2855 | final long identity = Binder.clearCallingIdentity(); |
| 2856 | try { |
| 2857 | if (phone != null) { |
| 2858 | return phone.getDataActivationState(); |
| 2859 | } else { |
| 2860 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2861 | } |
| 2862 | } finally { |
| 2863 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2864 | } |
| 2865 | } |
| 2866 | |
| 2867 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2868 | * Returns the unread count of voicemails for a subId |
| 2869 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2870 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2871 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2872 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2873 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 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 | 77ee938 | 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 | 77b832e | 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 | d20ad6b | 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 | 774ba36 | 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 | 77b832e | 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 | d20ad6b | 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 | d20ad6b | 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 | 77b832e | 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 |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3783 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 3784 | final int targetSdk = getTargetSdk(callingPackage); |
| 3785 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
| 3786 | return getDataNetworkTypeForSubscriber(subId, callingPackage); |
| 3787 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3788 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
| 3789 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3790 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3791 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3792 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3793 | final long identity = Binder.clearCallingIdentity(); |
| 3794 | try { |
| 3795 | final Phone phone = getPhone(subId); |
| 3796 | if (phone != null) { |
| 3797 | return phone.getServiceState().getDataNetworkType(); |
| 3798 | } else { |
| 3799 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3800 | } |
| 3801 | } finally { |
| 3802 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3803 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3804 | } |
| 3805 | |
| 3806 | /** |
| 3807 | * Returns the data network type |
| 3808 | */ |
| 3809 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3810 | public int getDataNetworkType(String callingPackage) { |
| 3811 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3812 | } |
| 3813 | |
| 3814 | /** |
| 3815 | * Returns the data network type for a subId |
| 3816 | */ |
| 3817 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3818 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3819 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3820 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3821 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3822 | } |
| 3823 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3824 | final long identity = Binder.clearCallingIdentity(); |
| 3825 | try { |
| 3826 | final Phone phone = getPhone(subId); |
| 3827 | if (phone != null) { |
| 3828 | return phone.getServiceState().getDataNetworkType(); |
| 3829 | } else { |
| 3830 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3831 | } |
| 3832 | } finally { |
| 3833 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3834 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3835 | } |
| 3836 | |
| 3837 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3838 | * Returns the Voice network type for a subId |
| 3839 | */ |
| 3840 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3841 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3842 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3843 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3844 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3845 | } |
| 3846 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3847 | final long identity = Binder.clearCallingIdentity(); |
| 3848 | try { |
| 3849 | final Phone phone = getPhone(subId); |
| 3850 | if (phone != null) { |
| 3851 | return phone.getServiceState().getVoiceNetworkType(); |
| 3852 | } else { |
| 3853 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3854 | } |
| 3855 | } finally { |
| 3856 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3857 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3858 | } |
| 3859 | |
| 3860 | /** |
| 3861 | * @return true if a ICC card is present |
| 3862 | */ |
| 3863 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3864 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3865 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3866 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3870 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3871 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3872 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3873 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3874 | final long identity = Binder.clearCallingIdentity(); |
| 3875 | try { |
| 3876 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3877 | if (phone != null) { |
| 3878 | return phone.getIccCard().hasIccCard(); |
| 3879 | } else { |
| 3880 | return false; |
| 3881 | } |
| 3882 | } finally { |
| 3883 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3884 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3885 | } |
| 3886 | |
| 3887 | /** |
| 3888 | * Return if the current radio is LTE on CDMA. This |
| 3889 | * is a tri-state return value as for a period of time |
| 3890 | * the mode may be unknown. |
| 3891 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3892 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3893 | * @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] | 3894 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3895 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3896 | @Override |
| 3897 | public int getLteOnCdmaMode(String callingPackage) { |
| 3898 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3899 | } |
| 3900 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3901 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3902 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3903 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3904 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3905 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3906 | } |
| 3907 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3908 | final long identity = Binder.clearCallingIdentity(); |
| 3909 | try { |
| 3910 | final Phone phone = getPhone(subId); |
| 3911 | if (phone == null) { |
| 3912 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3913 | } else { |
| 3914 | return phone.getLteOnCdmaMode(); |
| 3915 | } |
| 3916 | } finally { |
| 3917 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3918 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3919 | } |
| 3920 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3921 | /** |
| 3922 | * {@hide} |
| 3923 | * Returns Default subId, 0 in the case of single standby. |
| 3924 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3925 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3926 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3927 | } |
| 3928 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3929 | private int getSlotForDefaultSubscription() { |
| 3930 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3931 | } |
| 3932 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3933 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3934 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3935 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3936 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3937 | private boolean isActiveSubscription(int subId) { |
| 3938 | return mSubscriptionController.isActiveSubId(subId); |
| 3939 | } |
| 3940 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3941 | /** |
| 3942 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3943 | */ |
| 3944 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3945 | final long identity = Binder.clearCallingIdentity(); |
| 3946 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3947 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3948 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3949 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3950 | } finally { |
| 3951 | Binder.restoreCallingIdentity(identity); |
| 3952 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | /** |
| 3956 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3957 | */ |
| 3958 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3959 | final long identity = Binder.clearCallingIdentity(); |
| 3960 | try { |
| 3961 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3962 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3963 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3964 | } finally { |
| 3965 | Binder.restoreCallingIdentity(identity); |
| 3966 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3967 | } |
| 3968 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3969 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3970 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3971 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3972 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3973 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3974 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3975 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3976 | if (phoneId == -1) { |
| 3977 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3978 | + " does not correspond to an active phone"); |
| 3979 | } |
| 3980 | return PhoneFactory.getPhone(phoneId); |
| 3981 | } |
| 3982 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3983 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3984 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3985 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3986 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3987 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3988 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3989 | if (DBG) { |
| 3990 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3991 | } |
| 3992 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3993 | p2); |
| 3994 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3995 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3996 | |
| 3997 | @Override |
| 3998 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3999 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4000 | enforceModifyPermission(); |
| 4001 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4002 | if (DBG) { |
| 4003 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4004 | } |
| 4005 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4006 | callingPackage, aid, p2); |
| 4007 | } |
| 4008 | |
| 4009 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4010 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4011 | final long identity = Binder.clearCallingIdentity(); |
| 4012 | try { |
| 4013 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4014 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4015 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4016 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4017 | if (bestComponent == null |
| 4018 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4019 | loge("The calling package is not allowed to access ISD-R."); |
| 4020 | throw new SecurityException( |
| 4021 | "The calling package is not allowed to access ISD-R."); |
| 4022 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4023 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4024 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4025 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4026 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4027 | null /* workSource */); |
| 4028 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4029 | return response; |
| 4030 | } finally { |
| 4031 | Binder.restoreCallingIdentity(identity); |
| 4032 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4033 | } |
| 4034 | |
| 4035 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4036 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4037 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4038 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4039 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4040 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4041 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4042 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4043 | @Override |
| 4044 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4045 | enforceModifyPermission(); |
| 4046 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4047 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4048 | channel); |
| 4049 | } |
| 4050 | |
| 4051 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4052 | final long identity = Binder.clearCallingIdentity(); |
| 4053 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4054 | if (channel < 0) { |
| 4055 | return false; |
| 4056 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4057 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4058 | null /* workSource */); |
| 4059 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4060 | return success; |
| 4061 | } finally { |
| 4062 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4063 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4067 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4068 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4069 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4070 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4071 | if (DBG) { |
| 4072 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4073 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4074 | + p3 + " data=" + data); |
| 4075 | } |
| 4076 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4077 | command, p1, p2, p3, data); |
| 4078 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4079 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4080 | @Override |
| 4081 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4082 | int command, int p1, int p2, int p3, String data) { |
| 4083 | enforceModifyPermission(); |
| 4084 | if (DBG) { |
| 4085 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4086 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4087 | + p3 + " data=" + data); |
| 4088 | } |
| 4089 | return iccTransmitApduLogicalChannelWithPermission( |
| 4090 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4091 | data); |
| 4092 | } |
| 4093 | |
| 4094 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4095 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4096 | final long identity = Binder.clearCallingIdentity(); |
| 4097 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4098 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4099 | return ""; |
| 4100 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4101 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4102 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4103 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4104 | null /* workSource */); |
| 4105 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4106 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4107 | // Append the returned status code to the end of the response payload. |
| 4108 | String s = Integer.toHexString( |
| 4109 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4110 | if (response.payload != null) { |
| 4111 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4112 | } |
| 4113 | return s; |
| 4114 | } finally { |
| 4115 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4116 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4117 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4118 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4119 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4120 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4121 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4122 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4123 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4124 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4125 | if (DBG) { |
| 4126 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4127 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4128 | } |
| 4129 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4130 | cla, command, p1, p2, p3, data); |
| 4131 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4132 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4133 | @Override |
| 4134 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4135 | int command, int p1, int p2, int p3, String data) { |
| 4136 | enforceModifyPermission(); |
| 4137 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4138 | if (DBG) { |
| 4139 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4140 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4141 | + " data=" + data); |
| 4142 | } |
| 4143 | |
| 4144 | return iccTransmitApduBasicChannelWithPermission( |
| 4145 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4146 | p2, p3, data); |
| 4147 | } |
| 4148 | |
| 4149 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4150 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4151 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4152 | final long identity = Binder.clearCallingIdentity(); |
| 4153 | try { |
| 4154 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4155 | && TextUtils.equals(ISDR_AID, data)) { |
| 4156 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4157 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4158 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4159 | if (bestComponent == null |
| 4160 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4161 | loge("The calling package is not allowed to select ISD-R."); |
| 4162 | throw new SecurityException( |
| 4163 | "The calling package is not allowed to select ISD-R."); |
| 4164 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4165 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4166 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4167 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4168 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4169 | null /* workSource */); |
| 4170 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4171 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4172 | // Append the returned status code to the end of the response payload. |
| 4173 | String s = Integer.toHexString( |
| 4174 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4175 | if (response.payload != null) { |
| 4176 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4177 | } |
| 4178 | return s; |
| 4179 | } finally { |
| 4180 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4181 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4182 | } |
| 4183 | |
| 4184 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4185 | 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] | 4186 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4187 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4188 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4189 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4190 | final long identity = Binder.clearCallingIdentity(); |
| 4191 | try { |
| 4192 | if (DBG) { |
| 4193 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4194 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4195 | } |
| 4196 | |
| 4197 | IccIoResult response = |
| 4198 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4199 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4200 | subId); |
| 4201 | |
| 4202 | if (DBG) { |
| 4203 | log("Exchange SIM_IO [R]" + response); |
| 4204 | } |
| 4205 | |
| 4206 | byte[] result = null; |
| 4207 | int length = 2; |
| 4208 | if (response.payload != null) { |
| 4209 | length = 2 + response.payload.length; |
| 4210 | result = new byte[length]; |
| 4211 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4212 | } else { |
| 4213 | result = new byte[length]; |
| 4214 | } |
| 4215 | |
| 4216 | result[length - 1] = (byte) response.sw2; |
| 4217 | result[length - 2] = (byte) response.sw1; |
| 4218 | return result; |
| 4219 | } finally { |
| 4220 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4221 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4222 | } |
| 4223 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4224 | /** |
| 4225 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4226 | * on a particular subscription |
| 4227 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4228 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 4229 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4230 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 4231 | return null; |
| 4232 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4233 | |
| 4234 | final long identity = Binder.clearCallingIdentity(); |
| 4235 | try { |
| 4236 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4237 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4238 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4239 | return null; |
| 4240 | } |
| 4241 | Object response = sendRequest( |
| 4242 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4243 | if (response instanceof String[]) { |
| 4244 | return (String[]) response; |
| 4245 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4246 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4247 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4248 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4249 | } finally { |
| 4250 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4251 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4252 | } |
| 4253 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4254 | /** |
| 4255 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4256 | * subscription. |
| 4257 | * |
| 4258 | * @param subId the id of the subscription. |
| 4259 | * @param appType the uicc app type, must be USIM or SIM. |
| 4260 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4261 | * @param callingPackage the op Package name. |
| 4262 | * @return number of fplmns that is successfully written to the SIM. |
| 4263 | */ |
| 4264 | public int setForbiddenPlmns( |
| 4265 | int subId, int appType, List<String> fplmns, String callingPackage) { |
| 4266 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4267 | mApp, subId, callingPackage, "setForbiddenPlmns")) { |
| 4268 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4269 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4270 | } |
| 4271 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4272 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4273 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4274 | } |
| 4275 | if (fplmns == null) { |
| 4276 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4277 | } |
| 4278 | for (String fplmn : fplmns) { |
| 4279 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4280 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4281 | } |
| 4282 | } |
| 4283 | final long identity = Binder.clearCallingIdentity(); |
| 4284 | try { |
| 4285 | Object response = sendRequest( |
| 4286 | CMD_SET_FORBIDDEN_PLMNS, |
| 4287 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4288 | subId); |
| 4289 | return (int) response; |
| 4290 | } finally { |
| 4291 | Binder.restoreCallingIdentity(identity); |
| 4292 | } |
| 4293 | } |
| 4294 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4295 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4296 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4297 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4298 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4299 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4300 | final long identity = Binder.clearCallingIdentity(); |
| 4301 | try { |
| 4302 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4303 | if (response.payload == null) { |
| 4304 | return ""; |
| 4305 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4306 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4307 | // Append the returned status code to the end of the response payload. |
| 4308 | String s = Integer.toHexString( |
| 4309 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4310 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4311 | return s; |
| 4312 | } finally { |
| 4313 | Binder.restoreCallingIdentity(identity); |
| 4314 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4315 | } |
| 4316 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4317 | /** |
| 4318 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4319 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4320 | * |
| 4321 | * @param itemID the ID of the item to read |
| 4322 | * @return the NV item as a String, or null on error. |
| 4323 | */ |
| 4324 | @Override |
| 4325 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4326 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4327 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4328 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4329 | |
| 4330 | final long identity = Binder.clearCallingIdentity(); |
| 4331 | try { |
| 4332 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4333 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4334 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4335 | return value; |
| 4336 | } finally { |
| 4337 | Binder.restoreCallingIdentity(identity); |
| 4338 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4339 | } |
| 4340 | |
| 4341 | /** |
| 4342 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4343 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4344 | * |
| 4345 | * @param itemID the ID of the item to read |
| 4346 | * @param itemValue the value to write, as a String |
| 4347 | * @return true on success; false on any failure |
| 4348 | */ |
| 4349 | @Override |
| 4350 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4351 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4352 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4353 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4354 | |
| 4355 | final long identity = Binder.clearCallingIdentity(); |
| 4356 | try { |
| 4357 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4358 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4359 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4360 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4361 | return success; |
| 4362 | } finally { |
| 4363 | Binder.restoreCallingIdentity(identity); |
| 4364 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4365 | } |
| 4366 | |
| 4367 | /** |
| 4368 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4369 | * Used for device configuration by some CDMA operators. |
| 4370 | * |
| 4371 | * @param preferredRoamingList byte array containing the new PRL |
| 4372 | * @return true on success; false on any failure |
| 4373 | */ |
| 4374 | @Override |
| 4375 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4376 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4377 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4378 | |
| 4379 | final long identity = Binder.clearCallingIdentity(); |
| 4380 | try { |
| 4381 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4382 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4383 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4384 | return success; |
| 4385 | } finally { |
| 4386 | Binder.restoreCallingIdentity(identity); |
| 4387 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4388 | } |
| 4389 | |
| 4390 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4391 | * 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] | 4392 | * Used for device configuration by some CDMA operators. |
| 4393 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4394 | * @param slotIndex - device slot. |
| 4395 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4396 | * @return true on success; false on any failure |
| 4397 | */ |
| 4398 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4399 | public boolean resetModemConfig(int slotIndex) { |
| 4400 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4401 | if (phone != null) { |
| 4402 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4403 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4404 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4405 | final long identity = Binder.clearCallingIdentity(); |
| 4406 | try { |
| 4407 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4408 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4409 | return success; |
| 4410 | } finally { |
| 4411 | Binder.restoreCallingIdentity(identity); |
| 4412 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4413 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4414 | return false; |
| 4415 | } |
| 4416 | |
| 4417 | /** |
| 4418 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4419 | * |
| 4420 | * @param slotIndex - device slot. |
| 4421 | * |
| 4422 | * @return true on success; false on any failure |
| 4423 | */ |
| 4424 | @Override |
| 4425 | public boolean rebootModem(int slotIndex) { |
| 4426 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4427 | if (phone != null) { |
| 4428 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4429 | mApp, phone.getSubId(), "rebootModem"); |
| 4430 | |
| 4431 | final long identity = Binder.clearCallingIdentity(); |
| 4432 | try { |
| 4433 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4434 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4435 | return success; |
| 4436 | } finally { |
| 4437 | Binder.restoreCallingIdentity(identity); |
| 4438 | } |
| 4439 | } |
| 4440 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4441 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4442 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4443 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4444 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4445 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4446 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4447 | return new String[0]; |
| 4448 | } |
| 4449 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4450 | final long identity = Binder.clearCallingIdentity(); |
| 4451 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4452 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4453 | } finally { |
| 4454 | Binder.restoreCallingIdentity(identity); |
| 4455 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4456 | } |
| 4457 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4458 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4459 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4460 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4461 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4462 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4463 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4464 | |
| 4465 | final long identity = Binder.clearCallingIdentity(); |
| 4466 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4467 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4468 | // may happen if the device does not support IMS. |
| 4469 | return; |
| 4470 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4471 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4472 | } finally { |
| 4473 | Binder.restoreCallingIdentity(identity); |
| 4474 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4475 | } |
| 4476 | |
| 4477 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4478 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4479 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4480 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4481 | public void disableIms(int slotId) { |
| 4482 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4483 | |
| 4484 | final long identity = Binder.clearCallingIdentity(); |
| 4485 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4486 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4487 | // may happen if the device does not support IMS. |
| 4488 | return; |
| 4489 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4490 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4491 | } finally { |
| 4492 | Binder.restoreCallingIdentity(identity); |
| 4493 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4494 | } |
| 4495 | |
| 4496 | /** |
| 4497 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4498 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4499 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4500 | */ |
| 4501 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4502 | IImsServiceFeatureCallback callback) { |
| 4503 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4504 | |
| 4505 | final long identity = Binder.clearCallingIdentity(); |
| 4506 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4507 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4508 | // may happen if the device does not support IMS. |
| 4509 | return null; |
| 4510 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4511 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4512 | } finally { |
| 4513 | Binder.restoreCallingIdentity(identity); |
| 4514 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4515 | } |
| 4516 | |
| 4517 | /** |
| 4518 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4519 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4520 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4521 | * listener for feature updates. |
| 4522 | */ |
| 4523 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4524 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4525 | |
| 4526 | final long identity = Binder.clearCallingIdentity(); |
| 4527 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4528 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4529 | // may happen if the device does not support IMS. |
| 4530 | return null; |
| 4531 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4532 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4533 | } finally { |
| 4534 | Binder.restoreCallingIdentity(identity); |
| 4535 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4536 | } |
| 4537 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4538 | /** |
| 4539 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4540 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4541 | */ |
| 4542 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4543 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4544 | |
| 4545 | final long identity = Binder.clearCallingIdentity(); |
| 4546 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4547 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4548 | // may happen if the device does not support IMS. |
| 4549 | return null; |
| 4550 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4551 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4552 | } finally { |
| 4553 | Binder.restoreCallingIdentity(identity); |
| 4554 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4555 | } |
| 4556 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4557 | /** |
| 4558 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4559 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4560 | */ |
| 4561 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4562 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4563 | |
| 4564 | final long identity = Binder.clearCallingIdentity(); |
| 4565 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4566 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4567 | // may happen if the device does not support IMS. |
| 4568 | return null; |
| 4569 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4570 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4571 | } finally { |
| 4572 | Binder.restoreCallingIdentity(identity); |
| 4573 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4574 | } |
| 4575 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4576 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4577 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4578 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4579 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 4580 | * @param isCarrierService true if the ImsService is the carrier override, false if the |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4581 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4582 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 4583 | * @param packageName The name of the package that the current configuration will be replaced |
| 4584 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4585 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4586 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4587 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 4588 | int[] featureTypes, String packageName) { |
| 4589 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 4590 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4591 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4592 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4593 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4594 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4595 | final long identity = Binder.clearCallingIdentity(); |
| 4596 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4597 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4598 | // may happen if the device does not support IMS. |
| 4599 | return false; |
| 4600 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4601 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 4602 | for (int featureType : featureTypes) { |
| 4603 | featureConfig.put(featureType, packageName); |
| 4604 | } |
| 4605 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 4606 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4607 | } finally { |
| 4608 | Binder.restoreCallingIdentity(identity); |
| 4609 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4610 | } |
| 4611 | |
| 4612 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4613 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4614 | * |
| 4615 | * @param slotId The slot that the ImsService is associated with. |
| 4616 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4617 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4618 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4619 | * @return the package name of the ImsService configuration. |
| 4620 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4621 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 4622 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4623 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4624 | TelephonyPermissions |
| 4625 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4626 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4627 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4628 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4629 | final long identity = Binder.clearCallingIdentity(); |
| 4630 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4631 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4632 | // may happen if the device does not support IMS. |
| 4633 | return ""; |
| 4634 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 4635 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame^] | 4636 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 4637 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4638 | } finally { |
| 4639 | Binder.restoreCallingIdentity(identity); |
| 4640 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4641 | } |
| 4642 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4643 | /** |
| 4644 | * Get the MmTelFeature state associated with the requested subscription id. |
| 4645 | * @param subId The subscription that the MmTelFeature is associated with. |
| 4646 | * @param callback A callback with an integer containing the |
| 4647 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 4648 | */ |
| 4649 | @Override |
| 4650 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 4651 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 4652 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4653 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4654 | "IMS not available on device."); |
| 4655 | } |
| 4656 | final long token = Binder.clearCallingIdentity(); |
| 4657 | try { |
| 4658 | int slotId = getSlotIndex(subId); |
| 4659 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4660 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 4661 | + subId + "'"); |
| 4662 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4663 | } |
| 4664 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 4665 | try { |
| 4666 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 4667 | } catch (RemoteException e) { |
| 4668 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 4669 | + "Ignore"); |
| 4670 | } |
| 4671 | }); |
| 4672 | } finally { |
| 4673 | Binder.restoreCallingIdentity(token); |
| 4674 | } |
| 4675 | } |
| 4676 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4677 | public void setImsRegistrationState(boolean registered) { |
| 4678 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4679 | |
| 4680 | final long identity = Binder.clearCallingIdentity(); |
| 4681 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4682 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4683 | } finally { |
| 4684 | Binder.restoreCallingIdentity(identity); |
| 4685 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4686 | } |
| 4687 | |
| 4688 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4689 | * Set the network selection mode to automatic. |
| 4690 | * |
| 4691 | */ |
| 4692 | @Override |
| 4693 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4694 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4695 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4696 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4697 | if (!isActiveSubscription(subId)) { |
| 4698 | return; |
| 4699 | } |
| 4700 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4701 | final long identity = Binder.clearCallingIdentity(); |
| 4702 | try { |
| 4703 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4704 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4705 | } finally { |
| 4706 | Binder.restoreCallingIdentity(identity); |
| 4707 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4708 | } |
| 4709 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4710 | /** |
| 4711 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4712 | * |
| 4713 | * @param subId the id of the subscription. |
| 4714 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4715 | * the operator to attach to. |
| 4716 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4717 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4718 | * normal network selection next time. |
| 4719 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4720 | */ |
| 4721 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4722 | public boolean setNetworkSelectionModeManual( |
| 4723 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4724 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4725 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4726 | |
| 4727 | if (!isActiveSubscription(subId)) { |
| 4728 | return false; |
| 4729 | } |
| 4730 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4731 | final long identity = Binder.clearCallingIdentity(); |
| 4732 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4733 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4734 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4735 | if (DBG) { |
| 4736 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4737 | + " operator: " + operatorInfo); |
| 4738 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4739 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4740 | } finally { |
| 4741 | Binder.restoreCallingIdentity(identity); |
| 4742 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4743 | } |
| 4744 | |
| 4745 | /** |
| 4746 | * Scans for available networks. |
| 4747 | */ |
| 4748 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4749 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4750 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4751 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4752 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4753 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4754 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4755 | .setCallingPackage(callingPackage) |
| 4756 | .setCallingPid(Binder.getCallingPid()) |
| 4757 | .setCallingUid(Binder.getCallingUid()) |
| 4758 | .setMethod("getCellNetworkScanResults") |
| 4759 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4760 | .build()); |
| 4761 | switch (locationResult) { |
| 4762 | case DENIED_HARD: |
| 4763 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4764 | case DENIED_SOFT: |
| 4765 | return null; |
| 4766 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4767 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4768 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4769 | try { |
| 4770 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4771 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4772 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4773 | } finally { |
| 4774 | Binder.restoreCallingIdentity(identity); |
| 4775 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4776 | } |
| 4777 | |
| 4778 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4779 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4780 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4781 | * @param subId id of the subscription |
| 4782 | * @param request contains the radio access networks with bands/channels to scan |
| 4783 | * @param messenger callback messenger for scan results or errors |
| 4784 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4785 | * @return the id of the requested scan which can be used to stop the scan. |
| 4786 | */ |
| 4787 | @Override |
| 4788 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4789 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4790 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4791 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4792 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4793 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4794 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4795 | .setCallingPackage(callingPackage) |
| 4796 | .setCallingPid(Binder.getCallingPid()) |
| 4797 | .setCallingUid(Binder.getCallingUid()) |
| 4798 | .setMethod("requestNetworkScan") |
| 4799 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4800 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4801 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4802 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4803 | if (e != null) { |
| 4804 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 4805 | throw e; |
| 4806 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 4807 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4808 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 4809 | } |
| 4810 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4811 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4812 | int callingUid = Binder.getCallingUid(); |
| 4813 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4814 | final long identity = Binder.clearCallingIdentity(); |
| 4815 | try { |
| 4816 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4817 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4818 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4819 | } finally { |
| 4820 | Binder.restoreCallingIdentity(identity); |
| 4821 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4822 | } |
| 4823 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4824 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4825 | NetworkScanRequest request, int subId) { |
| 4826 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 4827 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4828 | boolean hasNetworkScanPermission = |
| 4829 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 4830 | == PERMISSION_GRANTED; |
| 4831 | |
| 4832 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 4833 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 4834 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4835 | } |
| 4836 | |
| 4837 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 4838 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4839 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 4840 | return new SecurityException("Specific channels must not be" |
| 4841 | + " scanned without location access."); |
| 4842 | } |
| 4843 | } |
| 4844 | } |
| 4845 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4846 | return null; |
| 4847 | } |
| 4848 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4849 | /** |
| 4850 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4851 | * |
| 4852 | * @param subId id of the subscription |
| 4853 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4854 | */ |
| 4855 | @Override |
| 4856 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4857 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4858 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4859 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4860 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4861 | final long identity = Binder.clearCallingIdentity(); |
| 4862 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4863 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4864 | } finally { |
| 4865 | Binder.restoreCallingIdentity(identity); |
| 4866 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4867 | } |
| 4868 | |
| 4869 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4870 | * Get the calculated preferred network type. |
| 4871 | * Used for debugging incorrect network type. |
| 4872 | * |
| 4873 | * @return the preferred network type, defined in RILConstants.java. |
| 4874 | */ |
| 4875 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4876 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4877 | final Phone defaultPhone = getDefaultPhone(); |
| 4878 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4879 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4880 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4881 | } |
| 4882 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4883 | final long identity = Binder.clearCallingIdentity(); |
| 4884 | try { |
| 4885 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4886 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4887 | } finally { |
| 4888 | Binder.restoreCallingIdentity(identity); |
| 4889 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4890 | } |
| 4891 | |
| 4892 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4893 | * Get the preferred network type. |
| 4894 | * Used for device configuration by some CDMA operators. |
| 4895 | * |
| 4896 | * @return the preferred network type, defined in RILConstants.java. |
| 4897 | */ |
| 4898 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4899 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4900 | TelephonyPermissions |
| 4901 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4902 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4903 | |
| 4904 | final long identity = Binder.clearCallingIdentity(); |
| 4905 | try { |
| 4906 | if (DBG) log("getPreferredNetworkType"); |
| 4907 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4908 | int networkType = (result != null ? result[0] : -1); |
| 4909 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4910 | return networkType; |
| 4911 | } finally { |
| 4912 | Binder.restoreCallingIdentity(identity); |
| 4913 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4914 | } |
| 4915 | |
| 4916 | /** |
| 4917 | * Set the preferred network type. |
| 4918 | * Used for device configuration by some CDMA operators. |
| 4919 | * |
| 4920 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4921 | * @return true on success; false on any failure. |
| 4922 | */ |
| 4923 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4924 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4925 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4926 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4927 | |
| 4928 | final long identity = Binder.clearCallingIdentity(); |
| 4929 | try { |
| 4930 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4931 | Boolean success = (Boolean) sendRequest( |
| 4932 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4933 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4934 | if (success) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4935 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4936 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4937 | } |
| 4938 | return success; |
| 4939 | } finally { |
| 4940 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4941 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4942 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4943 | |
| 4944 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4945 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4946 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4947 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4948 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4949 | * @hide |
| 4950 | */ |
| 4951 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 4952 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4953 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4954 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4955 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4956 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4957 | if (phone != null) { |
| 4958 | return phone.hasMatchedTetherApnSetting(); |
| 4959 | } else { |
| 4960 | return false; |
| 4961 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4962 | } finally { |
| 4963 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4964 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4965 | } |
| 4966 | |
| 4967 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4968 | * Set mobile data enabled |
| 4969 | * Used by the user through settings etc to turn on/off mobile data |
| 4970 | * |
| 4971 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4972 | */ |
| 4973 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4974 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4975 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4976 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4977 | |
| 4978 | final long identity = Binder.clearCallingIdentity(); |
| 4979 | try { |
| 4980 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4981 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4982 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4983 | if (phone != null) { |
| 4984 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4985 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4986 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4987 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4988 | } |
| 4989 | } finally { |
| 4990 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4991 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4992 | } |
| 4993 | |
| 4994 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4995 | * Get the user enabled state of Mobile Data. |
| 4996 | * |
| 4997 | * TODO: remove and use isUserDataEnabled. |
| 4998 | * This can't be removed now because some vendor codes |
| 4999 | * calls through ITelephony directly while they should |
| 5000 | * use TelephonyManager. |
| 5001 | * |
| 5002 | * @return true on enabled |
| 5003 | */ |
| 5004 | @Override |
| 5005 | public boolean getDataEnabled(int subId) { |
| 5006 | return isUserDataEnabled(subId); |
| 5007 | } |
| 5008 | |
| 5009 | /** |
| 5010 | * Get whether mobile data is enabled per user setting. |
| 5011 | * |
| 5012 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5013 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5014 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5015 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5016 | * |
| 5017 | * @return {@code true} if data is enabled else {@code false} |
| 5018 | */ |
| 5019 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5020 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5021 | try { |
| 5022 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5023 | null); |
| 5024 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5025 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5026 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5027 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5028 | |
| 5029 | final long identity = Binder.clearCallingIdentity(); |
| 5030 | try { |
| 5031 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5032 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5033 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5034 | if (phone != null) { |
| 5035 | boolean retVal = phone.isUserDataEnabled(); |
| 5036 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5037 | return retVal; |
| 5038 | } else { |
| 5039 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5040 | return false; |
| 5041 | } |
| 5042 | } finally { |
| 5043 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5044 | } |
| 5045 | } |
| 5046 | |
| 5047 | /** |
| 5048 | * Get whether mobile data is enabled. |
| 5049 | * |
| 5050 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 5051 | * whether mobile data is actually enabled. |
| 5052 | * |
| 5053 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 5054 | * |
| 5055 | * @return {@code true} if data is enabled else {@code false} |
| 5056 | */ |
| 5057 | @Override |
| 5058 | public boolean isDataEnabled(int subId) { |
| 5059 | try { |
| 5060 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5061 | null); |
| 5062 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5063 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5064 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5065 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5066 | |
| 5067 | final long identity = Binder.clearCallingIdentity(); |
| 5068 | try { |
| 5069 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5070 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5071 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5072 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5073 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5074 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5075 | return retVal; |
| 5076 | } else { |
| 5077 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5078 | return false; |
| 5079 | } |
| 5080 | } finally { |
| 5081 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5082 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5083 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5084 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5085 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 5086 | Phone phone) { |
| 5087 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5088 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5089 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5090 | || subController == null) return privilegeFromSim; |
| 5091 | |
| 5092 | int uid = Binder.getCallingUid(); |
| 5093 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5094 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5095 | |
| 5096 | final long identity = Binder.clearCallingIdentity(); |
| 5097 | try { |
| 5098 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5099 | SubscriptionManager subManager = (SubscriptionManager) |
| 5100 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5101 | for (String pkg : packages) { |
| 5102 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5103 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5104 | } |
| 5105 | } |
| 5106 | return privilegeFromSim; |
| 5107 | } finally { |
| 5108 | Binder.restoreCallingIdentity(identity); |
| 5109 | } |
| 5110 | } |
| 5111 | |
| 5112 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5113 | String pkgName) { |
| 5114 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5115 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5116 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5117 | || subController == null) return privilegeFromSim; |
| 5118 | |
| 5119 | final long identity = Binder.clearCallingIdentity(); |
| 5120 | try { |
| 5121 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5122 | SubscriptionManager subManager = (SubscriptionManager) |
| 5123 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5124 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5125 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5126 | } finally { |
| 5127 | Binder.restoreCallingIdentity(identity); |
| 5128 | } |
| 5129 | } |
| 5130 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5131 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5132 | public int getCarrierPrivilegeStatus(int subId) { |
| 5133 | final Phone phone = getPhone(subId); |
| 5134 | if (phone == null) { |
| 5135 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5136 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5137 | } |
| 5138 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5139 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5140 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5141 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5142 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5143 | |
| 5144 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5145 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 5146 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5147 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5148 | |
| 5149 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5150 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 5151 | final Phone phone = getPhone(subId); |
| 5152 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5153 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5154 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5155 | } |
| 5156 | UiccProfile profile = |
| 5157 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5158 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5159 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5160 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5161 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5162 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5163 | profile.getCarrierPrivilegeStatusForUid( |
| 5164 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5165 | } |
| 5166 | |
| 5167 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5168 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5169 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5170 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5171 | } |
| 5172 | |
| 5173 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5174 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5175 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5176 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5177 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5178 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5179 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5180 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5181 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5182 | } |
| 5183 | |
| 5184 | @Override |
| 5185 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5186 | if (TextUtils.isEmpty(pkgName)) |
| 5187 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5188 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5189 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5190 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5191 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5192 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5193 | continue; |
| 5194 | } |
| 5195 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5196 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5197 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5198 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5199 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5200 | break; |
| 5201 | } |
| 5202 | } |
| 5203 | |
| 5204 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5205 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5206 | |
| 5207 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5208 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5209 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5210 | loge("phoneId " + phoneId + " is not valid."); |
| 5211 | return null; |
| 5212 | } |
| 5213 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5214 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5215 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5216 | return null ; |
| 5217 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5218 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5219 | } |
| 5220 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5221 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5222 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5223 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5224 | List<String> privilegedPackages = new ArrayList<>(); |
| 5225 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5226 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5227 | // has UICC in that slot. |
| 5228 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5229 | if (card.hasCarrierPrivilegeRules()) { |
| 5230 | if (packages == null) { |
| 5231 | // Only check packages in user 0 for now |
| 5232 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5233 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5234 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5235 | | PackageManager.GET_SIGNING_CERTIFICATES, |
| 5236 | UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5237 | } |
| 5238 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5239 | PackageInfo pkgInfo = packages.get(p); |
| 5240 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5241 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5242 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5243 | privilegedPackages.add(pkgInfo.packageName); |
| 5244 | } |
| 5245 | } |
| 5246 | } |
| 5247 | } |
| 5248 | return privilegedPackages; |
| 5249 | } |
| 5250 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5251 | @Override |
| 5252 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5253 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5254 | |
| 5255 | final long identity = Binder.clearCallingIdentity(); |
| 5256 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5257 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5258 | try { |
| 5259 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5260 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5261 | } |
| 5262 | } finally { |
| 5263 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5264 | } |
| 5265 | return privilegedPackages; |
| 5266 | } |
| 5267 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5268 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5269 | final Phone phone = getPhone(subId); |
| 5270 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5271 | if (card == null) { |
| 5272 | loge("getIccId: No UICC"); |
| 5273 | return null; |
| 5274 | } |
| 5275 | String iccId = card.getIccId(); |
| 5276 | if (TextUtils.isEmpty(iccId)) { |
| 5277 | loge("getIccId: ICC ID is null or empty."); |
| 5278 | return null; |
| 5279 | } |
| 5280 | return iccId; |
| 5281 | } |
| 5282 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5283 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5284 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5285 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5286 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5287 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5288 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5289 | final long identity = Binder.clearCallingIdentity(); |
| 5290 | try { |
| 5291 | final String iccId = getIccId(subId); |
| 5292 | final Phone phone = getPhone(subId); |
| 5293 | if (phone == null) { |
| 5294 | return false; |
| 5295 | } |
| 5296 | final String subscriberId = phone.getSubscriberId(); |
| 5297 | |
| 5298 | if (DBG_MERGE) { |
| 5299 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 5300 | + subscriberId + " to " + number); |
| 5301 | } |
| 5302 | |
| 5303 | if (TextUtils.isEmpty(iccId)) { |
| 5304 | return false; |
| 5305 | } |
| 5306 | |
| 5307 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5308 | |
| 5309 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5310 | if (alphaTag == null) { |
| 5311 | editor.remove(alphaTagPrefKey); |
| 5312 | } else { |
| 5313 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5314 | } |
| 5315 | |
| 5316 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5317 | // track all merged IMSIs based on line number |
| 5318 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5319 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5320 | if (number == null) { |
| 5321 | editor.remove(numberPrefKey); |
| 5322 | editor.remove(subscriberPrefKey); |
| 5323 | } else { |
| 5324 | editor.putString(numberPrefKey, number); |
| 5325 | editor.putString(subscriberPrefKey, subscriberId); |
| 5326 | } |
| 5327 | |
| 5328 | editor.commit(); |
| 5329 | return true; |
| 5330 | } finally { |
| 5331 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5332 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5333 | } |
| 5334 | |
| 5335 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5336 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5337 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5338 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5339 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5340 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5341 | return null; |
| 5342 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5343 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5344 | final long identity = Binder.clearCallingIdentity(); |
| 5345 | try { |
| 5346 | String iccId = getIccId(subId); |
| 5347 | if (iccId != null) { |
| 5348 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5349 | if (DBG_MERGE) { |
| 5350 | log("getLine1NumberForDisplay returning " |
| 5351 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5352 | } |
| 5353 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5354 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5355 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5356 | return null; |
| 5357 | } finally { |
| 5358 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5359 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5360 | } |
| 5361 | |
| 5362 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5363 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5364 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5365 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5366 | return null; |
| 5367 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5368 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5369 | final long identity = Binder.clearCallingIdentity(); |
| 5370 | try { |
| 5371 | String iccId = getIccId(subId); |
| 5372 | if (iccId != null) { |
| 5373 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5374 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5375 | } |
| 5376 | return null; |
| 5377 | } finally { |
| 5378 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5379 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5380 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5381 | |
| 5382 | @Override |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5383 | public String[] getMergedSubscriberIds(int subId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5384 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5385 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5386 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5387 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 5388 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5389 | return null; |
| 5390 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5391 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5392 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5393 | // the process, where TelephonyManager was instantiated. |
| 5394 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5395 | final long identity = Binder.clearCallingIdentity(); |
| 5396 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5397 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5398 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5399 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5400 | |
| 5401 | // Figure out what subscribers are currently active |
| 5402 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5403 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5404 | // Only consider subs which match the current subId |
| 5405 | // This logic can be simplified. See b/131189269 for progress. |
| 5406 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5407 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5408 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5409 | |
| 5410 | // First pass, find a number override for an active subscriber |
| 5411 | String mergeNumber = null; |
| 5412 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5413 | for (String key : prefs.keySet()) { |
| 5414 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5415 | final String subscriberId = (String) prefs.get(key); |
| 5416 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5417 | final String iccId = key.substring( |
| 5418 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5419 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5420 | mergeNumber = (String) prefs.get(numberKey); |
| 5421 | if (DBG_MERGE) { |
| 5422 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5423 | + " for active subscriber " + subscriberId); |
| 5424 | } |
| 5425 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5426 | break; |
| 5427 | } |
| 5428 | } |
| 5429 | } |
| 5430 | } |
| 5431 | |
| 5432 | // Shortcut when no active merged subscribers |
| 5433 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5434 | return null; |
| 5435 | } |
| 5436 | |
| 5437 | // Second pass, find all subscribers under that line override |
| 5438 | final ArraySet<String> result = new ArraySet<>(); |
| 5439 | for (String key : prefs.keySet()) { |
| 5440 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5441 | final String number = (String) prefs.get(key); |
| 5442 | if (mergeNumber.equals(number)) { |
| 5443 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5444 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5445 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5446 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5447 | result.add(subscriberId); |
| 5448 | } |
| 5449 | } |
| 5450 | } |
| 5451 | } |
| 5452 | |
| 5453 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5454 | Arrays.sort(resultArray); |
| 5455 | if (DBG_MERGE) { |
| 5456 | Slog.d(LOG_TAG, |
| 5457 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5458 | } |
| 5459 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5460 | } finally { |
| 5461 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5462 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5463 | } |
| 5464 | |
| 5465 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5466 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 5467 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 5468 | |
| 5469 | final long identity = Binder.clearCallingIdentity(); |
| 5470 | try { |
| 5471 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 5472 | TelephonyManager.class); |
| 5473 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 5474 | if (subscriberId == null) { |
| 5475 | if (DBG) { |
| 5476 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 5477 | + subId); |
| 5478 | } |
| 5479 | return null; |
| 5480 | } |
| 5481 | |
| 5482 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 5483 | .getSubscriptionInfo(subId); |
| 5484 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 5485 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 5486 | if (groupUuid == null) { |
| 5487 | return new String[]{subscriberId}; |
| 5488 | } |
| 5489 | |
| 5490 | // Get all subscriberIds from the group. |
| 5491 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 5492 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
| 5493 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName()); |
| 5494 | for (SubscriptionInfo subInfo : groupInfos) { |
| 5495 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 5496 | if (subscriberId != null) { |
| 5497 | mergedSubscriberIds.add(subscriberId); |
| 5498 | } |
| 5499 | } |
| 5500 | |
| 5501 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 5502 | } finally { |
| 5503 | Binder.restoreCallingIdentity(identity); |
| 5504 | |
| 5505 | } |
| 5506 | } |
| 5507 | |
| 5508 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5509 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5510 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5511 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5512 | |
| 5513 | final long identity = Binder.clearCallingIdentity(); |
| 5514 | try { |
| 5515 | final Phone phone = getPhone(subId); |
| 5516 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5517 | } finally { |
| 5518 | Binder.restoreCallingIdentity(identity); |
| 5519 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5520 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5521 | |
| 5522 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5523 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5524 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5525 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5526 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5527 | |
| 5528 | final long identity = Binder.clearCallingIdentity(); |
| 5529 | try { |
| 5530 | final Phone phone = getPhone(subId); |
| 5531 | if (phone == null) { |
| 5532 | return false; |
| 5533 | } |
| 5534 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5535 | cdmaNonRoamingList); |
| 5536 | } finally { |
| 5537 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5538 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5539 | } |
| 5540 | |
| 5541 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5542 | @Deprecated |
| 5543 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5544 | enforceModifyPermission(); |
| 5545 | |
| 5546 | int returnValue = 0; |
| 5547 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5548 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5549 | if(result.exception == null) { |
| 5550 | if (result.result != null) { |
| 5551 | byte[] responseData = (byte[])(result.result); |
| 5552 | if(responseData.length > oemResp.length) { |
| 5553 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5554 | responseData.length + "bytes. Buffer Size is " + |
| 5555 | oemResp.length + "bytes."); |
| 5556 | } |
| 5557 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5558 | returnValue = responseData.length; |
| 5559 | } |
| 5560 | } else { |
| 5561 | CommandException ex = (CommandException) result.exception; |
| 5562 | returnValue = ex.getCommandError().ordinal(); |
| 5563 | if(returnValue > 0) returnValue *= -1; |
| 5564 | } |
| 5565 | } catch (RuntimeException e) { |
| 5566 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5567 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5568 | if(returnValue > 0) returnValue *= -1; |
| 5569 | } |
| 5570 | |
| 5571 | return returnValue; |
| 5572 | } |
| 5573 | |
| 5574 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5575 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5576 | try { |
| 5577 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5578 | } catch (RuntimeException e) { |
| 5579 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5580 | } |
| 5581 | } |
| 5582 | |
| 5583 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5584 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5585 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5586 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5587 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5588 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5589 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5590 | final long identity = Binder.clearCallingIdentity(); |
| 5591 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5592 | TelephonyPermissions |
| 5593 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5594 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5595 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5596 | } finally { |
| 5597 | Binder.restoreCallingIdentity(identity); |
| 5598 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5599 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5600 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5601 | |
| 5602 | @Override |
| 5603 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5604 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5605 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5606 | |
| 5607 | final long identity = Binder.clearCallingIdentity(); |
| 5608 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5609 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5610 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5611 | } finally { |
| 5612 | Binder.restoreCallingIdentity(identity); |
| 5613 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5614 | } |
| 5615 | |
| 5616 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5617 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5618 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5619 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5620 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5621 | return false; |
| 5622 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5623 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5624 | final long identity = Binder.clearCallingIdentity(); |
| 5625 | try { |
| 5626 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5627 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5628 | // In the long run, we may instead need to check if there exists a connection service |
| 5629 | // which can support video calling. |
| 5630 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5631 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5632 | return imsManager.isVtEnabledByPlatform() |
| 5633 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5634 | && imsManager.isVtEnabledByUser(); |
| 5635 | } finally { |
| 5636 | Binder.restoreCallingIdentity(identity); |
| 5637 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5638 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5639 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5640 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5641 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5642 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5643 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5644 | return false; |
| 5645 | } |
| 5646 | |
| 5647 | final long identity = Binder.clearCallingIdentity(); |
| 5648 | try { |
| 5649 | CarrierConfigManager configManager = |
| 5650 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5651 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5652 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5653 | } finally { |
| 5654 | Binder.restoreCallingIdentity(identity); |
| 5655 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5656 | } |
| 5657 | |
| 5658 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5659 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5660 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5661 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5662 | return false; |
| 5663 | } |
| 5664 | |
| 5665 | final long identity = Binder.clearCallingIdentity(); |
| 5666 | try { |
| 5667 | CarrierConfigManager configManager = |
| 5668 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5669 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5670 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5671 | } finally { |
| 5672 | Binder.restoreCallingIdentity(identity); |
| 5673 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5674 | } |
| 5675 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5676 | @Override |
| 5677 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 5678 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5679 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5680 | } |
| 5681 | |
| 5682 | @Override |
| 5683 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5684 | final long identity = Binder.clearCallingIdentity(); |
| 5685 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5686 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5687 | } finally { |
| 5688 | Binder.restoreCallingIdentity(identity); |
| 5689 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5690 | } |
| 5691 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5692 | /** |
| 5693 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5694 | * support for the feature and device firmware support. |
| 5695 | * |
| 5696 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5697 | */ |
| 5698 | @Override |
| 5699 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5700 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5701 | final Phone phone = getPhone(subscriptionId); |
| 5702 | if (phone == null) { |
| 5703 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5704 | return false; |
| 5705 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5706 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5707 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5708 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5709 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5710 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5711 | return isCarrierSupported && isDeviceSupported; |
| 5712 | } finally { |
| 5713 | Binder.restoreCallingIdentity(identity); |
| 5714 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5715 | } |
| 5716 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5717 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5718 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 5719 | * RTT setting, will return true if the device and carrier both support RTT. |
| 5720 | * 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] | 5721 | */ |
| 5722 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5723 | final long identity = Binder.clearCallingIdentity(); |
| 5724 | try { |
Hall Liu | 81eb08c | 2019-10-29 16:50:20 -0700 | [diff] [blame] | 5725 | return isRttSupported(subscriptionId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5726 | } finally { |
| 5727 | Binder.restoreCallingIdentity(identity); |
| 5728 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5729 | } |
| 5730 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5731 | /** |
| 5732 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5733 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5734 | * |
| 5735 | * <p>Requires Permission: |
| 5736 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5737 | */ |
| 5738 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5739 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5740 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5741 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5742 | return null; |
| 5743 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5744 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 5745 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 5746 | callingPackage, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5747 | return null; |
| 5748 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5749 | |
| 5750 | final long identity = Binder.clearCallingIdentity(); |
| 5751 | try { |
| 5752 | return phone.getDeviceId(); |
| 5753 | } finally { |
| 5754 | Binder.restoreCallingIdentity(identity); |
| 5755 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5756 | } |
| 5757 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5758 | /** |
| 5759 | * {@hide} |
| 5760 | * Returns the IMS Registration Status on a particular subid |
| 5761 | * |
| 5762 | * @param subId |
| 5763 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5764 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5765 | Phone phone = getPhone(subId); |
| 5766 | if (phone != null) { |
| 5767 | return phone.isImsRegistered(); |
| 5768 | } else { |
| 5769 | return false; |
| 5770 | } |
| 5771 | } |
| 5772 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5773 | @Override |
| 5774 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5775 | final long identity = Binder.clearCallingIdentity(); |
| 5776 | try { |
| 5777 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5778 | } finally { |
| 5779 | Binder.restoreCallingIdentity(identity); |
| 5780 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5781 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5782 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5783 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 5784 | public int getSubIdForPhoneAccountHandle( |
| 5785 | PhoneAccountHandle phoneAccountHandle, String callingPackage) { |
| 5786 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
| 5787 | callingPackage, "getSubIdForPhoneAccountHandle")) { |
| 5788 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 5789 | } |
| 5790 | final long identity = Binder.clearCallingIdentity(); |
| 5791 | try { |
| 5792 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 5793 | } finally { |
| 5794 | Binder.restoreCallingIdentity(identity); |
| 5795 | } |
| 5796 | } |
| 5797 | |
| 5798 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5799 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5800 | final long identity = Binder.clearCallingIdentity(); |
| 5801 | try { |
| 5802 | Phone phone = getPhone(subscriptionId); |
| 5803 | if (phone == null) { |
| 5804 | return null; |
| 5805 | } |
| 5806 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5807 | } finally { |
| 5808 | Binder.restoreCallingIdentity(identity); |
| 5809 | } |
| 5810 | } |
| 5811 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5812 | /** |
| 5813 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5814 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5815 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5816 | final long identity = Binder.clearCallingIdentity(); |
| 5817 | try { |
| 5818 | Phone phone = getPhone(subId); |
| 5819 | if (phone != null) { |
| 5820 | return phone.isWifiCallingEnabled(); |
| 5821 | } else { |
| 5822 | return false; |
| 5823 | } |
| 5824 | } finally { |
| 5825 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5826 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5827 | } |
| 5828 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5829 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5830 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5831 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5832 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5833 | final long identity = Binder.clearCallingIdentity(); |
| 5834 | try { |
| 5835 | Phone phone = getPhone(subId); |
| 5836 | if (phone != null) { |
| 5837 | return phone.isVideoEnabled(); |
| 5838 | } else { |
| 5839 | return false; |
| 5840 | } |
| 5841 | } finally { |
| 5842 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5843 | } |
| 5844 | } |
| 5845 | |
| 5846 | /** |
| 5847 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5848 | * defined in {@link ImsRegistrationImplBase}. |
| 5849 | */ |
| 5850 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5851 | final long identity = Binder.clearCallingIdentity(); |
| 5852 | try { |
| 5853 | Phone phone = getPhone(subId); |
| 5854 | if (phone != null) { |
| 5855 | return phone.getImsRegistrationTech(); |
| 5856 | } else { |
| 5857 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5858 | } |
| 5859 | } finally { |
| 5860 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5861 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5862 | } |
| 5863 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5864 | @Override |
| 5865 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 5866 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5867 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5868 | return; |
| 5869 | } |
| 5870 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5871 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5872 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5873 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5874 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5875 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5876 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5877 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5878 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5879 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5880 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5881 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5882 | // There has been issues when Sms raw table somehow stores orphan |
| 5883 | // fragments. They lead to garbled message when new fragments come |
| 5884 | // in and combined with those stale ones. In case this happens again, |
| 5885 | // user can reset all network settings which will clean up this table. |
| 5886 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5887 | // Clean up IMS settings as well here. |
| 5888 | int slotId = getSlotIndex(subId); |
| 5889 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5890 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 5891 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 5892 | |
| 5893 | // Erase modem config if erase modem on network setting is enabled. |
| 5894 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 5895 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 5896 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 5897 | sendEraseModemConfig(getDefaultPhone()); |
| 5898 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5899 | } finally { |
| 5900 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5901 | } |
| 5902 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5903 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5904 | private void cleanUpSmsRawTable(Context context) { |
| 5905 | ContentResolver resolver = context.getContentResolver(); |
| 5906 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5907 | resolver.delete(uri, null, null); |
| 5908 | } |
| 5909 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5910 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5911 | public String getSimLocaleForSubscriber(int subId) { |
| 5912 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5913 | final Phone phone = getPhone(subId); |
| 5914 | if (phone == null) { |
| 5915 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 5916 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5917 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5918 | final long identity = Binder.clearCallingIdentity(); |
| 5919 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5920 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5921 | phone.getContext().getOpPackageName()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 5922 | if (info == null) { |
| 5923 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 5924 | return null; |
| 5925 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5926 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5927 | // preferences (EF-PL and EF-LI)... |
| 5928 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5929 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5930 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5931 | if (localeFromDefaultSim != null) { |
| 5932 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5933 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5934 | + localeFromDefaultSim); |
| 5935 | return localeFromDefaultSim.toLanguageTag(); |
| 5936 | } else { |
| 5937 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5938 | } |
| 5939 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5940 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5941 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5942 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5943 | // the SIM and carrier preferences does not include a country we add the country |
| 5944 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5945 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5946 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5947 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5948 | return mccLocale.toLanguageTag(); |
| 5949 | } |
| 5950 | |
| 5951 | if (DBG) log("No locale found - returning null"); |
| 5952 | return null; |
| 5953 | } finally { |
| 5954 | Binder.restoreCallingIdentity(identity); |
| 5955 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5956 | } |
| 5957 | |
| 5958 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5959 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5960 | } |
| 5961 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5962 | /** |
| 5963 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5964 | */ |
| 5965 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5966 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5967 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5968 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5969 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5970 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5971 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5972 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5973 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5974 | * representing the state of the modem. |
| 5975 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5976 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5977 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5978 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5979 | */ |
| 5980 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5981 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5982 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5983 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5984 | |
| 5985 | final long identity = Binder.clearCallingIdentity(); |
| 5986 | try { |
| 5987 | ModemActivityInfo ret = null; |
| 5988 | synchronized (mLastModemActivityInfo) { |
| 5989 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5990 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5991 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5992 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5993 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5994 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5995 | mergedTxTimeMs[i] = info.getTxTimeMillis()[i] |
| 5996 | + mLastModemActivityInfo.getTxTimeMillis()[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5997 | } |
| 5998 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5999 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 6000 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6001 | mLastModemActivityInfo.setIdleTimeMillis( |
| 6002 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 6003 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 6004 | mLastModemActivityInfo.setRxTimeMillis( |
| 6005 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 6006 | mLastModemActivityInfo.setEnergyUsed( |
| 6007 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6008 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6009 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 6010 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 6011 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 6012 | mLastModemActivityInfo.getTxTimeMillis(), |
| 6013 | mLastModemActivityInfo.getRxTimeMillis(), |
| 6014 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6015 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6016 | Bundle bundle = new Bundle(); |
| 6017 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 6018 | result.send(0, bundle); |
| 6019 | } finally { |
| 6020 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6021 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6022 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6023 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6024 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6025 | // less than total activity duration. |
| 6026 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6027 | if (info == null) { |
| 6028 | return false; |
| 6029 | } |
| 6030 | int activityDurationMs = |
| 6031 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6032 | int totalTxTimeMs = 0; |
| 6033 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 6034 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 6035 | } |
| 6036 | return (info.isValid() |
| 6037 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6038 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 6039 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 6040 | && (totalTxTimeMs <= activityDurationMs)); |
| 6041 | } |
| 6042 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6043 | /** |
| 6044 | * {@hide} |
| 6045 | * Returns the service state information on specified subscription. |
| 6046 | */ |
| 6047 | @Override |
| 6048 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6049 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6050 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6051 | return null; |
| 6052 | } |
| 6053 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6054 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6055 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6056 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6057 | .setCallingPackage(callingPackage) |
| 6058 | .setCallingPid(Binder.getCallingPid()) |
| 6059 | .setCallingUid(Binder.getCallingUid()) |
| 6060 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6061 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6062 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6063 | .build()); |
| 6064 | |
| 6065 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6066 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6067 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6068 | .setCallingPackage(callingPackage) |
| 6069 | .setCallingPid(Binder.getCallingPid()) |
| 6070 | .setCallingUid(Binder.getCallingUid()) |
| 6071 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6072 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6073 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6074 | .build()); |
| 6075 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6076 | boolean hasFinePermission = |
| 6077 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6078 | boolean hasCoarsePermission = |
| 6079 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6080 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6081 | final long identity = Binder.clearCallingIdentity(); |
| 6082 | try { |
| 6083 | final Phone phone = getPhone(subId); |
| 6084 | if (phone == null) { |
| 6085 | return null; |
| 6086 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6087 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6088 | ServiceState ss = phone.getServiceState(); |
| 6089 | |
| 6090 | // Scrub out the location info in ServiceState depending on what level of access |
| 6091 | // the caller has. |
| 6092 | if (hasFinePermission) return ss; |
| 6093 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 6094 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6095 | } finally { |
| 6096 | Binder.restoreCallingIdentity(identity); |
| 6097 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6098 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6099 | |
| 6100 | /** |
| 6101 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6102 | * |
| 6103 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6104 | * voicemail ringtone. |
| 6105 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6106 | * PhoneAccount. |
| 6107 | */ |
| 6108 | @Override |
| 6109 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6110 | final long identity = Binder.clearCallingIdentity(); |
| 6111 | try { |
| 6112 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6113 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6114 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6115 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6116 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6117 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6118 | } finally { |
| 6119 | Binder.restoreCallingIdentity(identity); |
| 6120 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6121 | } |
| 6122 | |
| 6123 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6124 | * Sets the per-account voicemail ringtone. |
| 6125 | * |
| 6126 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6127 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6128 | * |
| 6129 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6130 | * voicemail ringtone. |
| 6131 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6132 | * PhoneAccount. |
| 6133 | */ |
| 6134 | @Override |
| 6135 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6136 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6137 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6138 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6139 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6140 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6141 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6142 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6143 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6144 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6145 | |
| 6146 | final long identity = Binder.clearCallingIdentity(); |
| 6147 | try { |
| 6148 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6149 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6150 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6151 | } |
| 6152 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6153 | } finally { |
| 6154 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6155 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6156 | } |
| 6157 | |
| 6158 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6159 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6160 | * |
| 6161 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6162 | * voicemail vibration setting. |
| 6163 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6164 | */ |
| 6165 | @Override |
| 6166 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6167 | final long identity = Binder.clearCallingIdentity(); |
| 6168 | try { |
| 6169 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6170 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6171 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6172 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6173 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6174 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6175 | } finally { |
| 6176 | Binder.restoreCallingIdentity(identity); |
| 6177 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6178 | } |
| 6179 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6180 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6181 | * Sets the per-account voicemail vibration. |
| 6182 | * |
| 6183 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6184 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6185 | * |
| 6186 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6187 | * voicemail vibration setting. |
| 6188 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6189 | * specific PhoneAccount. |
| 6190 | */ |
| 6191 | @Override |
| 6192 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6193 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6194 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6195 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6196 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6197 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6198 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6199 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6200 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6201 | } |
| 6202 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6203 | final long identity = Binder.clearCallingIdentity(); |
| 6204 | try { |
| 6205 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6206 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6207 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6208 | } |
| 6209 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6210 | } finally { |
| 6211 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6212 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6213 | } |
| 6214 | |
| 6215 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6216 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6217 | * |
| 6218 | * @throws SecurityException if the caller does not have the required permission |
| 6219 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6220 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6221 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6222 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6226 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6227 | * permission. |
| 6228 | * |
| 6229 | * @throws SecurityException if the caller does not have the required permission |
| 6230 | */ |
| 6231 | private void enforceSendSmsPermission() { |
| 6232 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6233 | } |
| 6234 | |
| 6235 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6236 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6237 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6238 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6239 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6240 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6241 | final long identity = Binder.clearCallingIdentity(); |
| 6242 | try { |
| 6243 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6244 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6245 | if (componentName == null) { |
| 6246 | throw new SecurityException( |
| 6247 | "Caller not current active visual voicemail package[null]"); |
| 6248 | } |
| 6249 | String vvmPackage = componentName.getPackageName(); |
| 6250 | if (!callingPackage.equals(vvmPackage)) { |
| 6251 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6252 | + vvmPackage + "]"); |
| 6253 | } |
| 6254 | } finally { |
| 6255 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6256 | } |
| 6257 | } |
| 6258 | |
| 6259 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6260 | * Return the application ID for the app type. |
| 6261 | * |
| 6262 | * @param subId the subscription ID that this request applies to. |
| 6263 | * @param appType the uicc app type. |
| 6264 | * @return Application ID for specificied app type, or null if no uicc. |
| 6265 | */ |
| 6266 | @Override |
| 6267 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6268 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6269 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6270 | |
| 6271 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6272 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6273 | if (phone == null) { |
| 6274 | return null; |
| 6275 | } |
| 6276 | String aid = null; |
| 6277 | try { |
| 6278 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6279 | .getApplicationByType(appType).getAid(); |
| 6280 | } catch (Exception e) { |
| 6281 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6282 | } |
| 6283 | return aid; |
| 6284 | } finally { |
| 6285 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6286 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6287 | } |
| 6288 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6289 | /** |
| 6290 | * Return the Electronic Serial Number. |
| 6291 | * |
| 6292 | * @param subId the subscription ID that this request applies to. |
| 6293 | * @return ESN or null if error. |
| 6294 | */ |
| 6295 | @Override |
| 6296 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6297 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6298 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6299 | |
| 6300 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6301 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6302 | if (phone == null) { |
| 6303 | return null; |
| 6304 | } |
| 6305 | String esn = null; |
| 6306 | try { |
| 6307 | esn = phone.getEsn(); |
| 6308 | } catch (Exception e) { |
| 6309 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6310 | } |
| 6311 | return esn; |
| 6312 | } finally { |
| 6313 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6314 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6315 | } |
| 6316 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6317 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6318 | * Return the Preferred Roaming List Version. |
| 6319 | * |
| 6320 | * @param subId the subscription ID that this request applies to. |
| 6321 | * @return PRLVersion or null if error. |
| 6322 | */ |
| 6323 | @Override |
| 6324 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6325 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6326 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6327 | |
| 6328 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6329 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6330 | if (phone == null) { |
| 6331 | return null; |
| 6332 | } |
| 6333 | String cdmaPrlVersion = null; |
| 6334 | try { |
| 6335 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6336 | } catch (Exception e) { |
| 6337 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6338 | } |
| 6339 | return cdmaPrlVersion; |
| 6340 | } finally { |
| 6341 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6342 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6343 | } |
| 6344 | |
| 6345 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6346 | * Get snapshot of Telephony histograms |
| 6347 | * @return List of Telephony histograms |
| 6348 | * @hide |
| 6349 | */ |
| 6350 | @Override |
| 6351 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6352 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6353 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6354 | |
| 6355 | final long identity = Binder.clearCallingIdentity(); |
| 6356 | try { |
| 6357 | return RIL.getTelephonyRILTimingHistograms(); |
| 6358 | } finally { |
| 6359 | Binder.restoreCallingIdentity(identity); |
| 6360 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6361 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6362 | |
| 6363 | /** |
| 6364 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6365 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6366 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6367 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6368 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6369 | * @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] | 6370 | */ |
| 6371 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6372 | @TelephonyManager.SetCarrierRestrictionResult |
| 6373 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6374 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6375 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6376 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6377 | if (carrierRestrictionRules == null) { |
| 6378 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6379 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6380 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6381 | final long identity = Binder.clearCallingIdentity(); |
| 6382 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6383 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6384 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6385 | } finally { |
| 6386 | Binder.restoreCallingIdentity(identity); |
| 6387 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6388 | } |
| 6389 | |
| 6390 | /** |
| 6391 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6392 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6393 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6394 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6395 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6396 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6397 | */ |
| 6398 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6399 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6400 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6401 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6402 | |
| 6403 | final long identity = Binder.clearCallingIdentity(); |
| 6404 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6405 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 6406 | if (response instanceof CarrierRestrictionRules) { |
| 6407 | return (CarrierRestrictionRules) response; |
| 6408 | } |
| 6409 | // Response is an Exception of some kind, |
| 6410 | // which is signalled to the user as a NULL retval |
| 6411 | return null; |
| 6412 | } catch (Exception e) { |
| 6413 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 6414 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6415 | } finally { |
| 6416 | Binder.restoreCallingIdentity(identity); |
| 6417 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6418 | } |
| 6419 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6420 | /** |
| 6421 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 6422 | * @param subId the subscription ID that this action applies to. |
| 6423 | * @param enabled control enable or disable metered apns. |
| 6424 | * {@hide} |
| 6425 | */ |
| 6426 | @Override |
| 6427 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 6428 | enforceModifyPermission(); |
| 6429 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6430 | |
| 6431 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6432 | if (phone == null) { |
| 6433 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 6434 | return; |
| 6435 | } |
| 6436 | try { |
| 6437 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 6438 | } catch (Exception e) { |
| 6439 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6440 | } finally { |
| 6441 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6442 | } |
| 6443 | } |
| 6444 | |
| 6445 | /** |
| 6446 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 6447 | * @param subId the subscription ID that this action applies to. |
| 6448 | * @param enabled control enable or disable radio. |
| 6449 | * {@hide} |
| 6450 | */ |
| 6451 | @Override |
| 6452 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 6453 | enforceModifyPermission(); |
| 6454 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6455 | |
| 6456 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6457 | if (phone == null) { |
| 6458 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 6459 | return; |
| 6460 | } |
| 6461 | try { |
| 6462 | phone.carrierActionSetRadioEnabled(enabled); |
| 6463 | } catch (Exception e) { |
| 6464 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6465 | } finally { |
| 6466 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6467 | } |
| 6468 | } |
| 6469 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6470 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6471 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6472 | * network status based on which carrier apps could apply actions accordingly, |
| 6473 | * enable/disable default url handler for example. |
| 6474 | * |
| 6475 | * @param subId the subscription ID that this action applies to. |
| 6476 | * @param report control start/stop reporting the default network status. |
| 6477 | * {@hide} |
| 6478 | */ |
| 6479 | @Override |
| 6480 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6481 | enforceModifyPermission(); |
| 6482 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6483 | |
| 6484 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6485 | if (phone == null) { |
| 6486 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6487 | return; |
| 6488 | } |
| 6489 | try { |
| 6490 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6491 | } catch (Exception e) { |
| 6492 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6493 | } finally { |
| 6494 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6495 | } |
| 6496 | } |
| 6497 | |
| 6498 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6499 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6500 | * @param subId the subscription ID that this action applies to. |
| 6501 | * {@hide} |
| 6502 | */ |
| 6503 | @Override |
| 6504 | public void carrierActionResetAll(int subId) { |
| 6505 | enforceModifyPermission(); |
| 6506 | final Phone phone = getPhone(subId); |
| 6507 | if (phone == null) { |
| 6508 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6509 | return; |
| 6510 | } |
| 6511 | try { |
| 6512 | phone.carrierActionResetAll(); |
| 6513 | } catch (Exception e) { |
| 6514 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6515 | } |
| 6516 | } |
| 6517 | |
| 6518 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6519 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6520 | * bug report is being generated. |
| 6521 | */ |
| 6522 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6523 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6524 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6525 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6526 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6527 | + Binder.getCallingPid() |
| 6528 | + ", uid=" + Binder.getCallingUid() |
| 6529 | + "without permission " |
| 6530 | + android.Manifest.permission.DUMP); |
| 6531 | return; |
| 6532 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6533 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6534 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6535 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6536 | @Override |
| 6537 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 6538 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 6539 | throws RemoteException { |
Torbjorn Eklund | 1050cb0 | 2018-11-16 14:05:38 +0100 | [diff] [blame] | 6540 | (new TelephonyShellCommand(this, getDefaultPhone().getContext())) |
| 6541 | .exec(this, in, out, err, args, callback, resultReceiver); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6542 | } |
| 6543 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6544 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6545 | * Get aggregated video call data usage since boot. |
| 6546 | * |
| 6547 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6548 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6549 | * {@hide} |
| 6550 | */ |
| 6551 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6552 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6553 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6554 | null); |
| 6555 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6556 | final long identity = Binder.clearCallingIdentity(); |
| 6557 | try { |
| 6558 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6559 | // records the delta with the corresponding network identity. |
| 6560 | // We just return the total video call data usage snapshot since boot. |
| 6561 | Phone phone = getPhone(subId); |
| 6562 | if (phone != null) { |
| 6563 | return phone.getVtDataUsage(perUidStats); |
| 6564 | } |
| 6565 | return null; |
| 6566 | } finally { |
| 6567 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6568 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6569 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6570 | |
| 6571 | /** |
| 6572 | * Policy control of data connection. Usually used when data limit is passed. |
| 6573 | * @param enabled True if enabling the data, otherwise disabling. |
| 6574 | * @param subId Subscription index |
| 6575 | * {@hide} |
| 6576 | */ |
| 6577 | @Override |
| 6578 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6579 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6580 | |
| 6581 | final long identity = Binder.clearCallingIdentity(); |
| 6582 | try { |
| 6583 | Phone phone = getPhone(subId); |
| 6584 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6585 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6586 | } |
| 6587 | } finally { |
| 6588 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6589 | } |
| 6590 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6591 | |
| 6592 | /** |
| 6593 | * Get Client request stats |
| 6594 | * @return List of Client Request Stats |
| 6595 | * @hide |
| 6596 | */ |
| 6597 | @Override |
| 6598 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6599 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6600 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6601 | return null; |
| 6602 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6603 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6604 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6605 | final long identity = Binder.clearCallingIdentity(); |
| 6606 | try { |
| 6607 | if (phone != null) { |
| 6608 | return phone.getClientRequestStats(); |
| 6609 | } |
| 6610 | |
| 6611 | return null; |
| 6612 | } finally { |
| 6613 | Binder.restoreCallingIdentity(identity); |
| 6614 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6615 | } |
| 6616 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6617 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6618 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6619 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6620 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6621 | |
| 6622 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6623 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6624 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6625 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6626 | * @param state State of SIM (power down, power up, pass through) |
| 6627 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6628 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6629 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6630 | * |
| 6631 | **/ |
| 6632 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6633 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6634 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6635 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6636 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6637 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6638 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6639 | final long identity = Binder.clearCallingIdentity(); |
| 6640 | try { |
| 6641 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6642 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6643 | } |
| 6644 | } finally { |
| 6645 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6646 | } |
| 6647 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6648 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6649 | private boolean isUssdApiAllowed(int subId) { |
| 6650 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6651 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6652 | if (configManager == null) { |
| 6653 | return false; |
| 6654 | } |
| 6655 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6656 | if (pb == null) { |
| 6657 | return false; |
| 6658 | } |
| 6659 | return pb.getBoolean( |
| 6660 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6661 | } |
| 6662 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6663 | /** |
| 6664 | * Check if phone is in emergency callback mode |
| 6665 | * @return true if phone is in emergency callback mode |
| 6666 | * @param subId sub id |
| 6667 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6668 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6669 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6670 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6671 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6672 | |
| 6673 | final long identity = Binder.clearCallingIdentity(); |
| 6674 | try { |
| 6675 | if (phone != null) { |
| 6676 | return phone.isInEcm(); |
| 6677 | } else { |
| 6678 | return false; |
| 6679 | } |
| 6680 | } finally { |
| 6681 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6682 | } |
| 6683 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6684 | |
| 6685 | /** |
| 6686 | * Get the current signal strength information for the given subscription. |
| 6687 | * Because this information is not updated when the device is in a low power state |
| 6688 | * it should not be relied-upon to be current. |
| 6689 | * @param subId Subscription index |
| 6690 | * @return the most recent cached signal strength info from the modem |
| 6691 | */ |
| 6692 | @Override |
| 6693 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6694 | final long identity = Binder.clearCallingIdentity(); |
| 6695 | try { |
| 6696 | Phone p = getPhone(subId); |
| 6697 | if (p == null) { |
| 6698 | return null; |
| 6699 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6700 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6701 | return p.getSignalStrength(); |
| 6702 | } finally { |
| 6703 | Binder.restoreCallingIdentity(identity); |
| 6704 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6705 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6706 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6707 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6708 | * Get the current modem radio state for the given slot. |
| 6709 | * @param slotIndex slot index. |
| 6710 | * @param callingPackage the name of the package making the call. |
| 6711 | * @return the current radio power state from the modem |
| 6712 | */ |
| 6713 | @Override |
| 6714 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6715 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6716 | if (phone != null) { |
| 6717 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6718 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6719 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6720 | } |
| 6721 | |
| 6722 | final long identity = Binder.clearCallingIdentity(); |
| 6723 | try { |
| 6724 | return phone.getRadioPowerState(); |
| 6725 | } finally { |
| 6726 | Binder.restoreCallingIdentity(identity); |
| 6727 | } |
| 6728 | } |
| 6729 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6730 | } |
| 6731 | |
| 6732 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6733 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6734 | * |
| 6735 | * <p>Requires one of the following permissions: |
| 6736 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6737 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6738 | * privileges. |
| 6739 | * |
| 6740 | * @param subId subscription id |
| 6741 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6742 | * {@code false}. |
| 6743 | */ |
| 6744 | @Override |
| 6745 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6746 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6747 | null /* message */); |
| 6748 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6749 | boolean isEnabled = false; |
| 6750 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6751 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6752 | Phone phone = getPhone(subId); |
| 6753 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6754 | } catch (Exception e) { |
| 6755 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6756 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6757 | } finally { |
| 6758 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6759 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6760 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6761 | } |
| 6762 | |
| 6763 | |
| 6764 | /** |
| 6765 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6766 | * |
| 6767 | * <p> Requires permission: |
| 6768 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6769 | * privileges. |
| 6770 | * |
| 6771 | * @param subId subscription id |
| 6772 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6773 | */ |
| 6774 | @Override |
| 6775 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6776 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6777 | mApp, subId, "setDataRoamingEnabled"); |
| 6778 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6779 | final long identity = Binder.clearCallingIdentity(); |
| 6780 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6781 | Phone phone = getPhone(subId); |
| 6782 | if (phone != null) { |
| 6783 | phone.setDataRoamingEnabled(isEnabled); |
| 6784 | } |
| 6785 | } finally { |
| 6786 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6787 | } |
| 6788 | } |
| 6789 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6790 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6791 | public boolean isManualNetworkSelectionAllowed(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6792 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6793 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6794 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6795 | boolean isAllowed = true; |
| 6796 | final long identity = Binder.clearCallingIdentity(); |
| 6797 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6798 | Phone phone = getPhone(subId); |
| 6799 | if (phone != null) { |
| 6800 | isAllowed = phone.isCspPlmnEnabled(); |
| 6801 | } |
| 6802 | } finally { |
| 6803 | Binder.restoreCallingIdentity(identity); |
| 6804 | } |
| 6805 | return isAllowed; |
| 6806 | } |
| 6807 | |
| 6808 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6809 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6810 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6811 | try { |
| 6812 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6813 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6814 | } catch (SecurityException e) { |
| 6815 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6816 | // has carrier privileges on an active UICC |
| 6817 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6818 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6819 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6820 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6821 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6822 | |
| 6823 | final long identity = Binder.clearCallingIdentity(); |
| 6824 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6825 | UiccController uiccController = UiccController.getInstance(); |
| 6826 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6827 | if (hasReadPermission) { |
| 6828 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6829 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6830 | |
| 6831 | // Remove private info if the caller doesn't have access |
| 6832 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6833 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6834 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 6835 | // is available |
| 6836 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 6837 | if (card == null || card.getUiccProfile() == null) { |
| 6838 | // assume no access if the card or profile is unavailable |
| 6839 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6840 | continue; |
| 6841 | } |
| 6842 | UiccProfile profile = card.getUiccProfile(); |
| 6843 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6844 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6845 | filteredInfos.add(cardInfo); |
| 6846 | } else { |
| 6847 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6848 | } |
| 6849 | } |
| 6850 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6851 | } finally { |
| 6852 | Binder.restoreCallingIdentity(identity); |
| 6853 | } |
| 6854 | } |
| 6855 | |
| 6856 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6857 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6858 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6859 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6860 | final long identity = Binder.clearCallingIdentity(); |
| 6861 | try { |
| 6862 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6863 | if (slots == null) { |
| 6864 | Rlog.i(LOG_TAG, "slots is null."); |
| 6865 | return null; |
| 6866 | } |
| 6867 | |
| 6868 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6869 | for (int i = 0; i < slots.length; i++) { |
| 6870 | UiccSlot slot = slots[i]; |
| 6871 | if (slot == null) { |
| 6872 | continue; |
| 6873 | } |
| 6874 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6875 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6876 | UiccCard card = slot.getUiccCard(); |
| 6877 | if (card != null) { |
| 6878 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6879 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 6880 | cardId = slot.getEid(); |
| 6881 | if (TextUtils.isEmpty(cardId)) { |
| 6882 | cardId = slot.getIccId(); |
| 6883 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6884 | } |
| 6885 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 6886 | if (cardId != null) { |
| 6887 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 6888 | // if cardId is an EID, it's all digits so this is fine |
| 6889 | cardId = IccUtils.stripTrailingFs(cardId); |
| 6890 | } |
| 6891 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6892 | int cardState = 0; |
| 6893 | switch (slot.getCardState()) { |
| 6894 | case CARDSTATE_ABSENT: |
| 6895 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6896 | break; |
| 6897 | case CARDSTATE_PRESENT: |
| 6898 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6899 | break; |
| 6900 | case CARDSTATE_ERROR: |
| 6901 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6902 | break; |
| 6903 | case CARDSTATE_RESTRICTED: |
| 6904 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6905 | break; |
| 6906 | default: |
| 6907 | break; |
| 6908 | |
| 6909 | } |
| 6910 | |
| 6911 | infos[i] = new UiccSlotInfo( |
| 6912 | slot.isActive(), |
| 6913 | slot.isEuicc(), |
| 6914 | cardId, |
| 6915 | cardState, |
| 6916 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6917 | slot.isExtendedApduSupported(), |
| 6918 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6919 | } |
| 6920 | return infos; |
| 6921 | } finally { |
| 6922 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6923 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6924 | } |
| 6925 | |
| 6926 | @Override |
| 6927 | public boolean switchSlots(int[] physicalSlots) { |
| 6928 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6929 | |
| 6930 | final long identity = Binder.clearCallingIdentity(); |
| 6931 | try { |
| 6932 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6933 | } finally { |
| 6934 | Binder.restoreCallingIdentity(identity); |
| 6935 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6936 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6937 | |
| 6938 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6939 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6940 | final long identity = Binder.clearCallingIdentity(); |
| 6941 | try { |
| 6942 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6943 | } finally { |
| 6944 | Binder.restoreCallingIdentity(identity); |
| 6945 | } |
| 6946 | } |
| 6947 | |
| 6948 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6949 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6950 | enforceModifyPermission(); |
| 6951 | final Phone phone = getPhone(subId); |
| 6952 | if (phone == null) { |
| 6953 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6954 | return; |
| 6955 | } |
| 6956 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6957 | final long identity = Binder.clearCallingIdentity(); |
| 6958 | try { |
| 6959 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6960 | } finally { |
| 6961 | Binder.restoreCallingIdentity(identity); |
| 6962 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6963 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6964 | |
| 6965 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6966 | * A test API to reload the UICC profile. |
| 6967 | * |
| 6968 | * <p>Requires that the calling app has permission |
| 6969 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6970 | * @hide |
| 6971 | */ |
| 6972 | @Override |
| 6973 | public void refreshUiccProfile(int subId) { |
| 6974 | enforceModifyPermission(); |
| 6975 | |
| 6976 | final long identity = Binder.clearCallingIdentity(); |
| 6977 | try { |
| 6978 | Phone phone = getPhone(subId); |
| 6979 | if (phone == null) { |
| 6980 | return; |
| 6981 | } |
| 6982 | UiccCard uiccCard = phone.getUiccCard(); |
| 6983 | if (uiccCard == null) { |
| 6984 | return; |
| 6985 | } |
| 6986 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6987 | if (uiccProfile == null) { |
| 6988 | return; |
| 6989 | } |
| 6990 | uiccProfile.refresh(); |
| 6991 | } finally { |
| 6992 | Binder.restoreCallingIdentity(identity); |
| 6993 | } |
| 6994 | } |
| 6995 | |
| 6996 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6997 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6998 | */ |
| 6999 | private boolean getDefaultDataEnabled() { |
| 7000 | return "true".equalsIgnoreCase( |
| 7001 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 7002 | } |
| 7003 | |
| 7004 | /** |
| 7005 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7006 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7007 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7008 | */ |
| 7009 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7010 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7011 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7012 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 7013 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 7014 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7015 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7016 | return isDataRoamingEnabled; |
| 7017 | } |
| 7018 | |
| 7019 | /** |
| 7020 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7021 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7022 | */ |
| 7023 | private int getDefaultNetworkType(int subId) { |
| 7024 | return Integer.parseInt( |
| 7025 | TelephonyManager.getTelephonyProperty( |
| 7026 | mSubscriptionController.getPhoneId(subId), |
| 7027 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 7028 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 7029 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7030 | |
| 7031 | @Override |
| 7032 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7033 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7034 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7035 | |
| 7036 | final long identity = Binder.clearCallingIdentity(); |
| 7037 | try { |
| 7038 | final Phone phone = getPhone(subId); |
| 7039 | if (phone == null) { |
| 7040 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7041 | return; |
| 7042 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7043 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7044 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7045 | } finally { |
| 7046 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7047 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7048 | } |
| 7049 | |
| 7050 | @Override |
| 7051 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7052 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7053 | |
| 7054 | final long identity = Binder.clearCallingIdentity(); |
| 7055 | try { |
| 7056 | final Phone phone = getPhone(subId); |
| 7057 | if (phone == null) { |
| 7058 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7059 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7060 | } |
| 7061 | return phone.getCarrierIdListVersion(); |
| 7062 | } finally { |
| 7063 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7064 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7065 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7066 | |
| 7067 | @Override |
| 7068 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 7069 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7070 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 7071 | return -1; |
| 7072 | } |
| 7073 | |
| 7074 | final long identity = Binder.clearCallingIdentity(); |
| 7075 | try { |
| 7076 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7077 | } finally { |
| 7078 | Binder.restoreCallingIdentity(identity); |
| 7079 | } |
| 7080 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7081 | |
| 7082 | @Override |
| 7083 | public int getCdmaRoamingMode(int subId) { |
| 7084 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7085 | mApp, subId, "getCdmaRoamingMode"); |
| 7086 | |
| 7087 | final long identity = Binder.clearCallingIdentity(); |
| 7088 | try { |
| 7089 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7090 | } finally { |
| 7091 | Binder.restoreCallingIdentity(identity); |
| 7092 | } |
| 7093 | } |
| 7094 | |
| 7095 | @Override |
| 7096 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7097 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7098 | mApp, subId, "setCdmaRoamingMode"); |
| 7099 | |
| 7100 | final long identity = Binder.clearCallingIdentity(); |
| 7101 | try { |
| 7102 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7103 | } finally { |
| 7104 | Binder.restoreCallingIdentity(identity); |
| 7105 | } |
| 7106 | } |
| 7107 | |
| 7108 | @Override |
| 7109 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7110 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7111 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7112 | |
| 7113 | final long identity = Binder.clearCallingIdentity(); |
| 7114 | try { |
| 7115 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7116 | } finally { |
| 7117 | Binder.restoreCallingIdentity(identity); |
| 7118 | } |
| 7119 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7120 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7121 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7122 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7123 | String callingPackage) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7124 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7125 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7126 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7127 | } |
| 7128 | final long identity = Binder.clearCallingIdentity(); |
| 7129 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7130 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7131 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7132 | if (phone.getEmergencyNumberTracker() != null |
| 7133 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7134 | emergencyNumberListInternal.put( |
| 7135 | phone.getSubId(), |
| 7136 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7137 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7138 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7139 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7140 | } finally { |
| 7141 | Binder.restoreCallingIdentity(identity); |
| 7142 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7143 | } |
| 7144 | |
| 7145 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7146 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7147 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7148 | if (!exactMatch) { |
| 7149 | TelephonyPermissions |
| 7150 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7151 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7152 | } |
| 7153 | final long identity = Binder.clearCallingIdentity(); |
| 7154 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7155 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7156 | if (phone.getEmergencyNumberTracker() != null |
| 7157 | && phone.getEmergencyNumberTracker() != null) { |
| 7158 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7159 | number, exactMatch)) { |
| 7160 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7161 | } |
| 7162 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7163 | } |
| 7164 | return false; |
| 7165 | } finally { |
| 7166 | Binder.restoreCallingIdentity(identity); |
| 7167 | } |
| 7168 | } |
| 7169 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7170 | /** |
| 7171 | * Update emergency number list for test mode. |
| 7172 | */ |
| 7173 | @Override |
| 7174 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7175 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7176 | "updateEmergencyNumberListTestMode"); |
| 7177 | |
| 7178 | final long identity = Binder.clearCallingIdentity(); |
| 7179 | try { |
| 7180 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7181 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7182 | if (tracker != null) { |
| 7183 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7184 | } |
| 7185 | } |
| 7186 | } finally { |
| 7187 | Binder.restoreCallingIdentity(identity); |
| 7188 | } |
| 7189 | } |
| 7190 | |
| 7191 | /** |
| 7192 | * Get the full emergency number list for test mode. |
| 7193 | */ |
| 7194 | @Override |
| 7195 | public List<String> getEmergencyNumberListTestMode() { |
| 7196 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7197 | "getEmergencyNumberListTestMode"); |
| 7198 | |
| 7199 | final long identity = Binder.clearCallingIdentity(); |
| 7200 | try { |
| 7201 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7202 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7203 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7204 | if (tracker != null) { |
| 7205 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7206 | emergencyNumbers.add(num.getNumber()); |
| 7207 | } |
| 7208 | } |
| 7209 | } |
| 7210 | return new ArrayList<>(emergencyNumbers); |
| 7211 | } finally { |
| 7212 | Binder.restoreCallingIdentity(identity); |
| 7213 | } |
| 7214 | } |
| 7215 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7216 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7217 | public int getEmergencyNumberDbVersion(int subId) { |
| 7218 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7219 | |
| 7220 | final long identity = Binder.clearCallingIdentity(); |
| 7221 | try { |
| 7222 | final Phone phone = getPhone(subId); |
| 7223 | if (phone == null) { |
| 7224 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7225 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7226 | } |
| 7227 | return phone.getEmergencyNumberDbVersion(); |
| 7228 | } finally { |
| 7229 | Binder.restoreCallingIdentity(identity); |
| 7230 | } |
| 7231 | } |
| 7232 | |
| 7233 | @Override |
| 7234 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7235 | enforceModifyPermission(); |
| 7236 | |
| 7237 | final long identity = Binder.clearCallingIdentity(); |
| 7238 | try { |
| 7239 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7240 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7241 | if (tracker != null) { |
| 7242 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7243 | } |
| 7244 | } |
| 7245 | } finally { |
| 7246 | Binder.restoreCallingIdentity(identity); |
| 7247 | } |
| 7248 | } |
| 7249 | |
| 7250 | @Override |
| 7251 | public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) { |
| 7252 | enforceActiveEmergencySessionPermission(); |
| 7253 | |
| 7254 | final long identity = Binder.clearCallingIdentity(); |
| 7255 | try { |
| 7256 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7257 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7258 | if (tracker != null) { |
| 7259 | tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath); |
| 7260 | } |
| 7261 | } |
| 7262 | } finally { |
| 7263 | Binder.restoreCallingIdentity(identity); |
| 7264 | } |
| 7265 | } |
| 7266 | |
| 7267 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7268 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7269 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7270 | Phone phone = getPhone(subId); |
| 7271 | if (phone == null) { |
| 7272 | return null; |
| 7273 | } |
| 7274 | final long identity = Binder.clearCallingIdentity(); |
| 7275 | try { |
| 7276 | UiccProfile profile = UiccController.getInstance() |
| 7277 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7278 | if (profile != null) { |
| 7279 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7280 | } |
| 7281 | } finally { |
| 7282 | Binder.restoreCallingIdentity(identity); |
| 7283 | } |
| 7284 | return null; |
| 7285 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7286 | |
| 7287 | /** |
| 7288 | * Enable or disable a modem stack. |
| 7289 | */ |
| 7290 | @Override |
| 7291 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7292 | enforceModifyPermission(); |
| 7293 | |
| 7294 | final long identity = Binder.clearCallingIdentity(); |
| 7295 | try { |
| 7296 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7297 | if (phone == null) { |
| 7298 | return false; |
| 7299 | } else { |
| 7300 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7301 | } |
| 7302 | } finally { |
| 7303 | Binder.restoreCallingIdentity(identity); |
| 7304 | } |
| 7305 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7306 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7307 | /** |
| 7308 | * Whether a modem stack is enabled or not. |
| 7309 | */ |
| 7310 | @Override |
| 7311 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) { |
| 7312 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7313 | if (phone == null) return false; |
| 7314 | |
| 7315 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7316 | mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) { |
| 7317 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7318 | } |
| 7319 | |
| 7320 | final long identity = Binder.clearCallingIdentity(); |
| 7321 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7322 | try { |
| 7323 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7324 | } catch (NoSuchElementException ex) { |
| 7325 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7326 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7327 | } finally { |
| 7328 | Binder.restoreCallingIdentity(identity); |
| 7329 | } |
| 7330 | } |
| 7331 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7332 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7333 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7334 | enforceModifyPermission(); |
| 7335 | |
| 7336 | final long identity = Binder.clearCallingIdentity(); |
| 7337 | try { |
| 7338 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7339 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7340 | .commit(); |
| 7341 | } finally { |
| 7342 | Binder.restoreCallingIdentity(identity); |
| 7343 | } |
| 7344 | } |
| 7345 | |
| 7346 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7347 | @TelephonyManager.IsMultiSimSupportedResult |
| 7348 | public int isMultiSimSupported(String callingPackage) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7349 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7350 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { |
| 7351 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7352 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7353 | |
| 7354 | final long identity = Binder.clearCallingIdentity(); |
| 7355 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7356 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7357 | } finally { |
| 7358 | Binder.restoreCallingIdentity(identity); |
| 7359 | } |
| 7360 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7361 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7362 | @TelephonyManager.IsMultiSimSupportedResult |
| 7363 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7364 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7365 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7366 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7367 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7368 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7369 | } |
| 7370 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7371 | // supported by the modem, indicate that it is restricted. |
| 7372 | PhoneCapability staticCapability = |
| 7373 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7374 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7375 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7376 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7377 | } |
| 7378 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7379 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7380 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7381 | } |
| 7382 | // Check if support of multiple SIMs is restricted by carrier |
| 7383 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7384 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7385 | } |
| 7386 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7387 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7388 | } |
| 7389 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7390 | /** |
| 7391 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7392 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7393 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7394 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7395 | * @param numOfSims number of active sims we want to switch to |
| 7396 | */ |
| 7397 | @Override |
| 7398 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7399 | if (numOfSims == 1) { |
| 7400 | enforceModifyPermission(); |
| 7401 | } else { |
| 7402 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7403 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7404 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7405 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7406 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7407 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7408 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7409 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7410 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7411 | return; |
| 7412 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7413 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7414 | } finally { |
| 7415 | Binder.restoreCallingIdentity(identity); |
| 7416 | } |
| 7417 | } |
| 7418 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 7419 | @Override |
| 7420 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 7421 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 7422 | Phone phone = getPhone(subId); |
| 7423 | if (phone == null) { |
| 7424 | return false; |
| 7425 | } |
| 7426 | final long identity = Binder.clearCallingIdentity(); |
| 7427 | try { |
| 7428 | UiccCard uiccCard = phone.getUiccCard(); |
| 7429 | if (uiccCard == null) { |
| 7430 | return false; |
| 7431 | } |
| 7432 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7433 | if (uiccProfile == null) { |
| 7434 | return false; |
| 7435 | } |
| 7436 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 7437 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 7438 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 7439 | } |
| 7440 | return false; |
| 7441 | } finally { |
| 7442 | Binder.restoreCallingIdentity(identity); |
| 7443 | } |
| 7444 | } |
| 7445 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7446 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7447 | * Get whether making changes to modem configurations will trigger reboot. |
| 7448 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7449 | */ |
| 7450 | @Override |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7451 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) { |
| 7452 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7453 | mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) { |
| 7454 | return false; |
| 7455 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7456 | final long identity = Binder.clearCallingIdentity(); |
| 7457 | try { |
| 7458 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 7459 | } finally { |
| 7460 | Binder.restoreCallingIdentity(identity); |
| 7461 | } |
| 7462 | } |
| 7463 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 7464 | private void updateModemStateMetrics() { |
| 7465 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 7466 | // TODO: check the state for each modem if the api is ready. |
| 7467 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 7468 | } |
| 7469 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 7470 | @Override |
| 7471 | public int[] getSlotsMapping() { |
| 7472 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 7473 | |
| 7474 | final long identity = Binder.clearCallingIdentity(); |
| 7475 | try { |
| 7476 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 7477 | // All logical slots should have a mapping to a physical slot. |
| 7478 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 7479 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 7480 | for (int i = 0; i < slotInfos.length; i++) { |
| 7481 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 7482 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 7483 | } |
| 7484 | } |
| 7485 | return logicalSlotsMapping; |
| 7486 | } finally { |
| 7487 | Binder.restoreCallingIdentity(identity); |
| 7488 | } |
| 7489 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7490 | |
| 7491 | /** |
| 7492 | * Get the IRadio HAL Version |
| 7493 | */ |
| 7494 | @Override |
| 7495 | public int getRadioHalVersion() { |
| 7496 | Phone phone = getDefaultPhone(); |
| 7497 | if (phone == null) return -1; |
| 7498 | HalVersion hv = phone.getHalVersion(); |
| 7499 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7500 | return hv.major * 100 + hv.minor; |
| 7501 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7502 | |
| 7503 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7504 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7505 | * corresponding network requests on a subId. |
| 7506 | * |
| 7507 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7508 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7509 | * 2) APN is un-metered for this subscription, or |
| 7510 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
| 7511 | * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. |
| 7512 | * |
| 7513 | * @return whether data is allowed for a apn type. |
| 7514 | * |
| 7515 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7516 | */ |
| 7517 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7518 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 7519 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 7520 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7521 | |
| 7522 | // Now that all security checks passes, perform the operation as ourselves. |
| 7523 | final long identity = Binder.clearCallingIdentity(); |
| 7524 | try { |
| 7525 | Phone phone = getPhone(subId); |
| 7526 | if (phone == null) return false; |
| 7527 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7528 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7529 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7530 | } finally { |
| 7531 | Binder.restoreCallingIdentity(identity); |
| 7532 | } |
| 7533 | } |
| 7534 | |
| 7535 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7536 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7537 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7538 | |
| 7539 | // Now that all security checks passes, perform the operation as ourselves. |
| 7540 | final long identity = Binder.clearCallingIdentity(); |
| 7541 | try { |
| 7542 | Phone phone = getPhone(subId); |
| 7543 | if (phone == null) return true; // By default return true. |
| 7544 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7545 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7546 | } finally { |
| 7547 | Binder.restoreCallingIdentity(identity); |
| 7548 | } |
| 7549 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7550 | |
| 7551 | @Override |
| 7552 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
| 7553 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 7554 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 7555 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 7556 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 7557 | } |
| 7558 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 7559 | Intent intent = new Intent(); |
| 7560 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 7561 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 7562 | // Bring up choose default SMS subscription dialog right now |
| 7563 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 7564 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 7565 | mApp.startActivity(intent); |
| 7566 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 7567 | |
| 7568 | @Override |
| 7569 | public String getMmsUAProfUrl(int subId) { |
| 7570 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7571 | final long identity = Binder.clearCallingIdentity(); |
| 7572 | try { |
| 7573 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7574 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 7575 | } finally { |
| 7576 | Binder.restoreCallingIdentity(identity); |
| 7577 | } |
| 7578 | } |
| 7579 | |
| 7580 | @Override |
| 7581 | public String getMmsUserAgent(int subId) { |
| 7582 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7583 | final long identity = Binder.clearCallingIdentity(); |
| 7584 | try { |
| 7585 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7586 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 7587 | } finally { |
| 7588 | Binder.restoreCallingIdentity(identity); |
| 7589 | } |
| 7590 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 7591 | |
| 7592 | @Override |
| 7593 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 7594 | enforceModifyPermission(); |
| 7595 | |
| 7596 | // Now that all security checks passes, perform the operation as ourselves. |
| 7597 | final long identity = Binder.clearCallingIdentity(); |
| 7598 | try { |
| 7599 | Phone phone = getPhone(subId); |
| 7600 | if (phone == null) return false; |
| 7601 | |
| 7602 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 7603 | } finally { |
| 7604 | Binder.restoreCallingIdentity(identity); |
| 7605 | } |
| 7606 | } |
| 7607 | |
| 7608 | @Override |
| 7609 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 7610 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 7611 | |
| 7612 | // Now that all security checks passes, perform the operation as ourselves. |
| 7613 | final long identity = Binder.clearCallingIdentity(); |
| 7614 | try { |
| 7615 | Phone phone = getPhone(subId); |
| 7616 | if (phone == null) return false; |
| 7617 | |
| 7618 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 7619 | } finally { |
| 7620 | Binder.restoreCallingIdentity(identity); |
| 7621 | } |
| 7622 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 7623 | |
| 7624 | /** |
| 7625 | * Updates whether conference event pacakge handling is enabled. |
| 7626 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 7627 | * otherwise. |
| 7628 | */ |
| 7629 | @Override |
| 7630 | public void setCepEnabled(boolean isCepEnabled) { |
| 7631 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 7632 | |
| 7633 | final long identity = Binder.clearCallingIdentity(); |
| 7634 | try { |
| 7635 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 7636 | for (Phone phone : PhoneFactory.getPhones()) { |
| 7637 | Phone defaultPhone = phone.getImsPhone(); |
| 7638 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7639 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7640 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 7641 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 7642 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 7643 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 7644 | + imsPhone.getMsisdn()); |
| 7645 | } |
| 7646 | } |
| 7647 | } finally { |
| 7648 | Binder.restoreCallingIdentity(identity); |
| 7649 | } |
| 7650 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 7651 | } |